diff --git a/main.cpp b/main.cpp index f04d18b..b7ffad3 100644 --- a/main.cpp +++ b/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "he853.h" int main(int argc, char **argv) @@ -9,8 +10,8 @@ int main(int argc, char **argv) char protocol = 'E'; // Check arguments - if (argc != 1 && argc != 3 && !(argc == 4 && strlen(argv[3]) == 1) ) { - printf("Usage: %s [ []]\n", argv[0]); + if (argc != 1 && argc != 3 && !(argc >= 4 && strlen(argv[3]) == 1) ) { + printf("Usage: %s [ [] []]\n", argv[0]); printf(" DeviceID - ID of the device to act on\n"); printf(" Command - 0=OFF, 1=ON\n"); printf(" NOTE: AnBan has also values > 1\n"); @@ -19,6 +20,7 @@ int main(int argc, char **argv) printf(" Default protocol is '%c'\n", protocol); printf(" NOTE: KAKU ID is device + group * 16\n"); printf(" NOTE: Protocol ALL is meant for tests and sends out with all protocols!\n"); + printf(" Repeats: Repeat this number of times. Sometimes needed for more distant or slower devices (default: 1)\n"); printf(" Without parameters the device status will be shown\n"); return 1; } @@ -40,39 +42,53 @@ int main(int argc, char **argv) int command = atoi(argv[2]); // Protocol parameter requested? - if (argc == 4) { + if (argc >= 4) { protocol = argv[3][0]; } - switch(protocol) - { - case 'A': - printf("Sending command[%i] to deviceId[%i] with protocol AnBan\n", command, deviceId); - remote->sendAnBan((uint16_t)deviceId, (uint8_t)command); - break; - case 'E': - printf("Sending command[%i] to deviceId[%i] with protocol EU\n", command, deviceId); - remote->sendEU((uint16_t)deviceId, (uint8_t)command); - break; - case 'U': - printf("Sending command[%i] to deviceId[%i] with protocol UK\n", command, deviceId); - remote->sendUK((uint16_t)deviceId, (uint8_t)command); - break; - case 'K': - printf("Sending command[%i] to deviceId[%i] with protocol KAKU\n", command, deviceId); - remote->sendKaku((uint16_t)deviceId, (uint8_t)command); - break; - // case 'N': - // printf("Sending command[%i] to deviceId[%i] with protocol KAKUNEW\n", command, deviceId); - // remote->sendKakuNew((uint16_t)deviceId, (uint8_t)command); - // break; - case 'L': - printf("Sending command[%i] to deviceId[%i] with ALL protocols\n", command, deviceId); - remote->sendAll((uint16_t)deviceId, (uint8_t)command); - break; - default: - printf("Unknown protocol\n"); - return 1; + int repeats = 1; + if (argc >= 5) + repeats = atoi(argv[4]); + + for( int i = 0; i < repeats; i++ ) { + if( i > 0 ) { + struct timespec time = { + .tv_sec = 0, + .tv_nsec = 100000000, + }; + nanosleep( &time, NULL ); + } + + switch(protocol) + { + case 'A': + printf("Sending command[%i] to deviceId[%i] with protocol AnBan\n", command, deviceId); + remote->sendAnBan((uint16_t)deviceId, (uint8_t)command); + break; + case 'E': + printf("Sending command[%i] to deviceId[%i] with protocol EU\n", command, deviceId); + remote->sendEU((uint16_t)deviceId, (uint8_t)command); + break; + case 'U': + printf("Sending command[%i] to deviceId[%i] with protocol UK\n", command, deviceId); + remote->sendUK((uint16_t)deviceId, (uint8_t)command); + break; + case 'K': + printf("Sending command[%i] to deviceId[%i] with protocol KAKU\n", command, deviceId); + remote->sendKaku((uint16_t)deviceId, (uint8_t)command); + break; + // case 'N': + // printf("Sending command[%i] to deviceId[%i] with protocol KAKUNEW\n", command, deviceId); + // remote->sendKakuNew((uint16_t)deviceId, (uint8_t)command); + // break; + case 'L': + printf("Sending command[%i] to deviceId[%i] with ALL protocols\n", command, deviceId); + remote->sendAll((uint16_t)deviceId, (uint8_t)command); + break; + default: + printf("Unknown protocol\n"); + return 1; + } } return 0;