diff --git a/send.cpp b/send.cpp index 076e77c..cc6180f 100644 --- a/send.cpp +++ b/send.cpp @@ -1,11 +1,26 @@ /* - Usage: ./send - Command is 0 for OFF and 1 for ON + Usage: see printUsage() */ #include "RCSwitch.h" #include #include +#include +#include + +void printUsage() +{ + std::cout << " Usage: sudo ./send \n"; + std::cout << " e.g. sudo ./send 01011 3 1\n"; + std::cout << " sudo ./send \n"; + std::cout << " e.g. sudo ./send 4 3 0\n"; + std::cout << " sudo ./send \n"; + std::cout << " e.g. sudo ./send c 2 3 1\n"; + std::cout << "\n"; + std::cout << " Command is 0 for OFF and 1 for ON\n"; + std::cout << "\n"; + std::cout << " See http://code.google.com/p/rc-switch/wiki/HowTo_OperateLowCostOutlets for more information about supported switches\n"; +} int main(int argc, char *argv[]) { @@ -15,25 +30,82 @@ int main(int argc, char *argv[]) { for pin mapping of the raspberry pi GPIO connector */ int PIN = 0; - char* systemCode = argv[1]; - int unitCode = atoi(argv[2]); - int command = atoi(argv[3]); - - if (wiringPiSetup () == -1) return 1; - printf("sending systemCode[%s] unitCode[%i] command[%i]\n", systemCode, unitCode, command); + if (wiringPiSetup () == -1) return 1; RCSwitch mySwitch = RCSwitch(); mySwitch.enableTransmit(PIN); + + if(argc == 4) + { + char* sGroup = argv[1]; + int nSwitchNumber = atoi(argv[2]); + + int command = atoi(argv[3]); + + if(strlen(sGroup) > 2) + { + //Type A: 10 pole DIP switches + printf("sending [Type A] groupCode[%s] switchNumber[%i] command[%i]\n", sGroup, nSwitchNumber, command); + + switch(command) { + case 1: + mySwitch.switchOn(sGroup, nSwitchNumber); + break; + case 0: + mySwitch.switchOff(sGroup, nSwitchNumber); + break; + default: + printf("command[%i] is unsupported\n", command); + printUsage(); + return -1; + } + return 0; + } else { + //Type B: Two rotary/sliding switches + int nGroupNumber = atoi(sGroup); + printf("sending [Type B] groupNumber[%i] switchNumber[%i] command[%i]\n", nGroupNumber, nSwitchNumber, command); + switch(command) { + case 1: + mySwitch.switchOn(nGroupNumber, nSwitchNumber); + break; + case 0: + mySwitch.switchOff(nGroupNumber, nSwitchNumber); + break; + default: + printf("command[%i] is unsupported\n", command); + printUsage(); + return -1; + } + return 0; + } + } + else if(argc == 5) + { + //Type C: Intertechno + char* sFamily = argv[1]; + int nGroup = atoi(argv[2]); + int nDevice = atoi(argv[3]); + + int command = atoi(argv[4]); - switch(command) { - case 1: - mySwitch.switchOn(systemCode, unitCode); - break; - case 0: - mySwitch.switchOff(systemCode, unitCode); - break; - default: - printf("command[%i] is unsupported\n", command); - return -1; - } - return 0; -} + printf("sending [Type C] family[%s] groupNumber[%i] switchNumber[%i] command[%i]\n", sFamily, nGroup, nDevice, command); + + switch(command) { + case 1: + mySwitch.switchOn(sFamily[0], nGroup, nDevice); + break; + case 0: + mySwitch.switchOff(sFamily[0], nGroup, nDevice); + break; + default: + printf("command[%i] is unsupported\n", command); + printUsage(); + return -1; + } + return 0; + } + else + { + printUsage(); + } + return 1; +} \ No newline at end of file