Skip to content

Commit

Permalink
Added return codes for error conditions such as missing relays
Browse files Browse the repository at this point in the history
  • Loading branch information
Bond, Darryl committed Aug 28, 2016
1 parent b7395d8 commit 190a25a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions usbrelay.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ int main( int argc, char *argv[]) {
unsigned short vendor_id = 0x16c0;
unsigned short product_id = 0x05df;
char *vendor, *product;
int exit_code = 0;

/* allocate the memeory for all the relays */
if (argc > 1) {
Expand Down Expand Up @@ -128,7 +129,8 @@ int main( int argc, char *argv[]) {
if (!strcmp(relays[i].this_serial, (const char *) buf)) {
fprintf(stderr,"%d HID Serial: %s ", i, buf);
fprintf(stderr,"Serial: %s, Relay: %d State: %x\n",relays[i].this_serial,relays[i].relay_num,relays[i].state);
operate_relay(handle,relays[i].relay_num,relays[i].state);
if (operate_relay(handle,relays[i].relay_num,relays[i].state) < 0 )
exit_code++;
relays[i].found = 1;
}
}
Expand All @@ -145,13 +147,15 @@ int main( int argc, char *argv[]) {
fprintf(stderr,"Serial: %s, Relay: %d State: %x ",relays[i].this_serial,relays[i].relay_num,relays[i].state);
if (relays[i].found )
fprintf(stderr,"--- Found\n");
else
else {
fprintf(stderr,"--- Not Found\n");
exit_code++;
}
}

if (relays)
free(relays);
exit(0);
exit(exit_code);
}

int operate_relay(hid_device *handle,unsigned char relay, unsigned char state){
Expand Down

0 comments on commit 190a25a

Please sign in to comment.