X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftestclient%2Fmain.cpp;h=813e22b4cd193501dd0f7447d26041e1f690c7e7;hb=c751d00a6c8c911b3365380088468c1225c66e52;hp=90158edbec031ac5fb0ef0dc4fefe28d9b27e4eb;hpb=2abe74ebbd27d8c30060b3eebb363e10d3fbfd80;p=deb_libcec.git diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index 90158ed..813e22b 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -31,19 +31,72 @@ */ #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 + +inline bool HexStrToInt(const std::string& data, uint8_t& value) +{ + int iTmp(0); + if (sscanf(data.c_str(), "%x", &iTmp) == 1) + { + if (iTmp > 256) + value = 255; + else if (iTmp < 0) + value = 0; + else + value = (uint8_t) iTmp; + + return true; + } + + return false; +} + +//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; @@ -187,7 +240,6 @@ int main (int argc, char *argv[]) } cout << "cec device opened" << endl; - usleep(CEC_SETTLE_DOWN_TIME); parser->PowerOnDevices(CECDEVICE_TV); flush_log(parser); @@ -213,7 +265,7 @@ int main (int argc, char *argv[]) if (command == "tx") { string strvalue; - int ivalue; + uint8_t ivalue; vector bytes; while (GetWord(input, strvalue) && HexStrToInt(strvalue, ivalue)) bytes.push_back(ivalue); @@ -236,6 +288,12 @@ int main (int argc, char *argv[]) { parser->StartBootloader(); } + else if (command == "r") + { + parser->Close(); + parser->Open(strPort.c_str()); + parser->SetActiveView(); + } else if (command == "h" || command == "help") { show_console_help();