Skip to content

Commit

Permalink
Fix intertechno address calculation and verification
Browse files Browse the repository at this point in the history
  • Loading branch information
FooDeas authored and xkonni committed Feb 26, 2017
1 parent 8a5b705 commit c1fa6e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
21 changes: 14 additions & 7 deletions daemon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int main(int argc, char* argv[]) {
mySwitch.setPulseLength(300);
usleep(50000);
mySwitch.enableTransmit(0);
nPlugs=1024;
nPlugs=1280;
int nState[nPlugs];
nTimeout=0;
memset(nState, 0, sizeof(nState));
Expand Down Expand Up @@ -138,11 +138,11 @@ int main(int argc, char* argv[]) {
/**
* handle messages
*/
int nAddr = getAddr(nGroup, nSwitchNumber);
int nAddr = getAddrElro(nGroup, nSwitchNumber);
printf("nAddr: %i\n", nAddr);
printf("nPlugs: %i\n", nPlugs);
char msg[13];
if (nAddr > 1023 || nAddr < 1) {
if (nAddr > 1023 || nAddr < 0) {
printf("Switch out of range: %s:%d\n", nGroup, nSwitchNumber);
n = write(newsockfd,"2",1);
}
Expand Down Expand Up @@ -193,11 +193,11 @@ int main(int argc, char* argv[]) {
printf("nGroup: %s\n", nGroup);
printf("nSwitchNumber: %i\n", nSwitchNumber);
printf("nAction: %i\n", nAction);
int nAddr = getAddr(nGroup, nSwitchNumber);
int nAddr = getAddrInt(nGroup, nSwitchNumber);
printf("nAddr: %i\n", nAddr);
printf("nPlugs: %i\n", nPlugs);
char msg[13];
if (nAddr > 16 || nAddr < 1) {
if (nAddr > 1279 || nAddr < 1024) {
printf("Switch out of range: %s:%d\n", nGroup, nSwitchNumber);
n = write(newsockfd,"2",1);
}
Expand Down Expand Up @@ -318,9 +318,9 @@ void error(const char *msg) {
}

/**
* calculate the array address of the power state
* calculate the array address of the power state for elro
*/
int getAddr(const char* nGroup, int nSwitchNumber) {
int getAddrElro(const char* nGroup, int nSwitchNumber) {
int tempgroup = atoi(nGroup);
int group = 0;
for (int i = 0; i < 5; i++) {
Expand All @@ -335,6 +335,13 @@ int getAddr(const char* nGroup, int nSwitchNumber) {
return result;
}

/**
* calculate the array address of the power state for intertechno
*/
int getAddrInt(const char* nGroup, int nSwitchNumber) {
return ((atoi(nGroup) - 1) * 16) + (nSwitchNumber - 1) + 1024;
}

PI_THREAD(switchOn) {
printf("switchOnThread: %d\n", nTimeout);
char tGroup[6];
Expand Down
3 changes: 2 additions & 1 deletion daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ int nTimeout;
int PORT = 11337;

void error(const char *msg);
int getAddr(const char* nGroup, int nSwitchNumber);
int getAddrElro(const char* nGroup, int nSwitchNumber);
int getAddrInt(const char* nGroup, int nSwitchNumber);

PI_THREAD(switchOn);
PI_THREAD(switchOff);

0 comments on commit c1fa6e3

Please sign in to comment.