Skip to content

Commit c1fa6e3

Browse files
FooDeasxkonni
authored andcommitted
Fix intertechno address calculation and verification
1 parent 8a5b705 commit c1fa6e3

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

daemon.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int main(int argc, char* argv[]) {
6161
mySwitch.setPulseLength(300);
6262
usleep(50000);
6363
mySwitch.enableTransmit(0);
64-
nPlugs=1024;
64+
nPlugs=1280;
6565
int nState[nPlugs];
6666
nTimeout=0;
6767
memset(nState, 0, sizeof(nState));
@@ -138,11 +138,11 @@ int main(int argc, char* argv[]) {
138138
/**
139139
* handle messages
140140
*/
141-
int nAddr = getAddr(nGroup, nSwitchNumber);
141+
int nAddr = getAddrElro(nGroup, nSwitchNumber);
142142
printf("nAddr: %i\n", nAddr);
143143
printf("nPlugs: %i\n", nPlugs);
144144
char msg[13];
145-
if (nAddr > 1023 || nAddr < 1) {
145+
if (nAddr > 1023 || nAddr < 0) {
146146
printf("Switch out of range: %s:%d\n", nGroup, nSwitchNumber);
147147
n = write(newsockfd,"2",1);
148148
}
@@ -193,11 +193,11 @@ int main(int argc, char* argv[]) {
193193
printf("nGroup: %s\n", nGroup);
194194
printf("nSwitchNumber: %i\n", nSwitchNumber);
195195
printf("nAction: %i\n", nAction);
196-
int nAddr = getAddr(nGroup, nSwitchNumber);
196+
int nAddr = getAddrInt(nGroup, nSwitchNumber);
197197
printf("nAddr: %i\n", nAddr);
198198
printf("nPlugs: %i\n", nPlugs);
199199
char msg[13];
200-
if (nAddr > 16 || nAddr < 1) {
200+
if (nAddr > 1279 || nAddr < 1024) {
201201
printf("Switch out of range: %s:%d\n", nGroup, nSwitchNumber);
202202
n = write(newsockfd,"2",1);
203203
}
@@ -318,9 +318,9 @@ void error(const char *msg) {
318318
}
319319

320320
/**
321-
* calculate the array address of the power state
321+
* calculate the array address of the power state for elro
322322
*/
323-
int getAddr(const char* nGroup, int nSwitchNumber) {
323+
int getAddrElro(const char* nGroup, int nSwitchNumber) {
324324
int tempgroup = atoi(nGroup);
325325
int group = 0;
326326
for (int i = 0; i < 5; i++) {
@@ -335,6 +335,13 @@ int getAddr(const char* nGroup, int nSwitchNumber) {
335335
return result;
336336
}
337337

338+
/**
339+
* calculate the array address of the power state for intertechno
340+
*/
341+
int getAddrInt(const char* nGroup, int nSwitchNumber) {
342+
return ((atoi(nGroup) - 1) * 16) + (nSwitchNumber - 1) + 1024;
343+
}
344+
338345
PI_THREAD(switchOn) {
339346
printf("switchOnThread: %d\n", nTimeout);
340347
char tGroup[6];

daemon.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ int nTimeout;
99
int PORT = 11337;
1010

1111
void error(const char *msg);
12-
int getAddr(const char* nGroup, int nSwitchNumber);
12+
int getAddrElro(const char* nGroup, int nSwitchNumber);
13+
int getAddrInt(const char* nGroup, int nSwitchNumber);
1314

1415
PI_THREAD(switchOn);
1516
PI_THREAD(switchOff);

0 commit comments

Comments
 (0)