X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Ftestclient%2Fmain.cpp;h=f2f2bf3e0a9678338fc8b347b38d6afc853b0006;hb=c7e9549276e43503fce28a80a0576e586b9975b4;hp=37df94d41ac49f79c095672dcb7890806e481616;hpb=390b42d67f9c62486ee6d1b9fb57927c9cd4dafc;p=deb_libcec.git diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index 37df94d..f2f2bf3 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -31,20 +31,61 @@ */ #include "../../include/CECExports.h" -#include "../lib/util/threads.h" -#include "../lib/util/misc.h" +#include "../lib/platform/threads.h" #include "../lib/util/StdString.h" #include #include #include #include +#include using namespace CEC; using namespace std; #define CEC_TEST_CLIENT_VERSION 3 -void flush_log(ICECDevice *cecParser) + +inline bool HexStrToInt(const std::string& data, int& value) +{ + return sscanf(data.c_str(), "%x", &value) == 1; +} + + +//get the first word (separated by whitespace) from string data and place that in word +//then remove that word from string data +bool GetWord(string& data, string& word) +{ + stringstream datastream(data); + string end; + + datastream >> word; + if (datastream.fail()) + { + data.clear(); + return false; + } + + size_t pos = data.find(word) + word.length(); + + if (pos >= data.length()) + { + data.clear(); + return true; + } + + data = data.substr(pos); + + datastream.clear(); + datastream.str(data); + + datastream >> end; + if (datastream.fail()) + data.clear(); + + return true; +} + +void flush_log(ICECAdapter *cecParser) { cec_log_message message; while (cecParser && cecParser->GetNextLogMessage(&message)) @@ -67,11 +108,11 @@ void flush_log(ICECDevice *cecParser) } } -void list_devices(ICECDevice *parser) +void list_devices(ICECAdapter *parser) { cout << "Found devices: "; - vector devices; - int iDevicesFound = parser->FindDevices(devices); + vector devices; + int iDevicesFound = parser->FindAdapters(devices); if (iDevicesFound <= 0) { #ifdef __WINDOWS__ @@ -114,9 +155,6 @@ void show_console_help(void) "tx {bytes} transfer bytes over the CEC line." << endl << "[tx 40 00 FF 11 22 33] sends bytes 0x40 0x00 0xFF 0x11 0x22 0x33" << endl << endl << - "am {ackmack} change the ackmask of the CEC adapter." << endl << - "[am 10] ackmask 0x10 (logical address 4)" << endl << - endl << "la {logical_address} change the logical address of the CEC adapter." << endl << "[la 4] logical address 4" << endl << endl << @@ -129,7 +167,7 @@ void show_console_help(void) int main (int argc, char *argv[]) { - ICECDevice *parser = LoadLibCec("CEC Tester"); + ICECAdapter *parser = LoadLibCec("CEC Tester"); if (!parser && parser->GetMinVersion() > CEC_TEST_CLIENT_VERSION) { cout << "Unable to create parser. Is libcec.dll present?" << endl; @@ -150,8 +188,8 @@ int main (int argc, char *argv[]) if (argc < 2) { cout << "no serial port given. trying autodetect: "; - vector devices; - int iDevicesFound = parser->FindDevices(devices); + vector devices; + int iDevicesFound = parser->FindAdapters(devices); if (iDevicesFound <= 0) { cout << "FAILED" << endl; @@ -223,15 +261,6 @@ int main (int argc, char *argv[]) parser->Transmit(bytes); } - else if (command == "am") - { - string strvalue; - int ackmask; - if (GetWord(input, strvalue) && HexStrToInt(strvalue, ackmask)) - { - parser->SetAckMask(ackmask); - } - } else if (command == "la") { string strvalue; @@ -242,7 +271,7 @@ int main (int argc, char *argv[]) } else if (command == "ping") { - parser->Ping(); + parser->PingAdapter(); } else if (command == "bl") { @@ -263,7 +292,8 @@ int main (int argc, char *argv[]) CCondition::Sleep(50); } - parser->PowerOffDevices(CECDEVICE_TV); + parser->StandbyDevices(CECDEVICE_BROADCAST); + parser->Close(); flush_log(parser); UnloadLibCec(parser); return 0;