*/
#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 <cstdio>
#include <fcntl.h>
#include <iostream>
#include <string>
+#include <sstream>
using namespace CEC;
using namespace std;
-#define CEC_TEST_CLIENT_VERSION 2
+#define CEC_TEST_CLIENT_VERSION 3
-void flush_log(ICECDevice *cecParser)
+
+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;
while (cecParser && cecParser->GetNextLogMessage(&message))
}
}
-void list_devices(ICECDevice *parser)
+void list_devices(ICECAdapter *parser)
{
cout << "Found devices: ";
- vector<cec_device> devices;
- int iDevicesFound = parser->FindDevices(devices);
+ vector<cec_adapter> devices;
+ int iDevicesFound = parser->FindAdapters(devices);
if (iDevicesFound <= 0)
{
#ifdef __WINDOWS__
"parameters:" << endl <<
"\t-h --help Shows this help text" << endl <<
"\t-l --list-devices List all devices on this system" << endl <<
- "\t[COM PORT] The com port to connect to. If no COM port is given, the client tries to connect to the first device that is detected" << endl;
+ "\t[COM PORT] The com port to connect to. If no COM port is given, the client tries to connect to the first device that is detected" << endl <<
+ endl <<
+ "Type 'h' or 'help' and press enter after starting the client to display all available commands" << endl;
+}
+
+void show_console_help(void)
+{
+ cout << endl <<
+ "================================================================================" << endl <<
+ "Available commands:" << endl <<
+ endl <<
+ "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 <<
+ "la {logical_address} change the logical address of the CEC adapter." << endl <<
+ "[la 4] logical address 4" << endl <<
+ endl <<
+ "[ping] send a ping command to the CEC adapter." << endl <<
+ "[bl] to let the adapter enter the bootloader, to upgrade the flash rom." << endl <<
+ "[h] or [help] show this help." << endl <<
+ "[q] or [quit] to quit the CEC test client and switch off all connected CEC devices." << endl <<
+ "================================================================================" << endl;
}
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;
if (argc < 2)
{
cout << "no serial port given. trying autodetect: ";
- vector<cec_device> devices;
- int iDevicesFound = parser->FindDevices(devices);
+ vector<cec_adapter> devices;
+ int iDevicesFound = parser->FindAdapters(devices);
if (iDevicesFound <= 0)
{
cout << "FAILED" << endl;
}
cout << "cec device opened" << endl;
- usleep(CEC_SETTLE_DOWN_TIME);
- parser->PowerOnDevices();
+ parser->PowerOnDevices(CECDEVICE_TV);
flush_log(parser);
parser->SetActiveView();
if (command == "tx")
{
string strvalue;
- int ivalue;
+ uint8_t ivalue;
vector<uint8_t> bytes;
while (GetWord(input, strvalue) && HexStrToInt(strvalue, ivalue))
bytes.push_back(ivalue);
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;
- int iLogicalAddress;
if (GetWord(input, strvalue))
{
parser->SetLogicalAddress((cec_logical_address) atoi(strvalue.c_str()));
}
else if (command == "ping")
{
- parser->Ping();
+ parser->PingAdapter();
}
else if (command == "bl")
{
parser->StartBootloader();
}
+ else if (command == "r")
+ {
+ parser->Close();
+ parser->Open(strPort.c_str());
+ parser->SetActiveView();
+ }
+ else if (command == "h" || command == "help")
+ {
+ show_console_help();
+ }
else if (command == "q" || command == "quit")
{
bContinue = false;
CCondition::Sleep(50);
}
- parser->PowerOffDevices();
+ parser->StandbyDevices(CECDEVICE_BROADCAST);
+ parser->Close();
flush_log(parser);
UnloadLibCec(parser);
return 0;