Commit | Line | Data |
---|---|---|
abbca718 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
4 | * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. | |
5 | * libCEC(R) is an original work, containing original code. | |
6 | * | |
7 | * libCEC(R) is a trademark of Pulse-Eight Limited. | |
8 | * | |
9 | * This program is dual-licensed; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
22 | * | |
23 | * | |
24 | * Alternatively, you can license this library under a commercial license, | |
25 | * please contact Pulse-Eight Licensing for more information. | |
26 | * | |
27 | * For more information contact: | |
28 | * Pulse-Eight Licensing <license@pulse-eight.com> | |
29 | * http://www.pulse-eight.com/ | |
30 | * http://www.pulse-eight.net/ | |
31 | */ | |
32 | ||
761dcc45 | 33 | #include <cec.h> |
acec5f48 | 34 | |
abbca718 LOK |
35 | #include <cstdio> |
36 | #include <fcntl.h> | |
37 | #include <iostream> | |
e6d2161b | 38 | #include <fstream> |
abbca718 | 39 | #include <string> |
b9187cc6 | 40 | #include <sstream> |
acec5f48 LOK |
41 | #include "../lib/platform/threads.h" |
42 | #include "../lib/util/StdString.h" | |
abbca718 LOK |
43 | |
44 | using namespace CEC; | |
45 | using namespace std; | |
46 | ||
d75be19b | 47 | #define CEC_TEST_CLIENT_VERSION 1 |
abbca718 | 48 | |
761dcc45 | 49 | #include <cecloader.h> |
8bc45476 | 50 | |
3d0dca16 LOK |
51 | int g_cecLogLevel = CEC_LOG_ALL; |
52 | ofstream g_logOutput; | |
53 | bool g_bShortLog = false; | |
54 | CStdString g_strPort; | |
b9187cc6 | 55 | |
8bca69de | 56 | inline bool HexStrToInt(const std::string& data, uint8_t& value) |
b9187cc6 | 57 | { |
8bca69de LOK |
58 | int iTmp(0); |
59 | if (sscanf(data.c_str(), "%x", &iTmp) == 1) | |
60 | { | |
61 | if (iTmp > 256) | |
62 | value = 255; | |
63 | else if (iTmp < 0) | |
64 | value = 0; | |
65 | else | |
66 | value = (uint8_t) iTmp; | |
b9187cc6 | 67 | |
8bca69de LOK |
68 | return true; |
69 | } | |
70 | ||
71 | return false; | |
72 | } | |
b9187cc6 LOK |
73 | |
74 | //get the first word (separated by whitespace) from string data and place that in word | |
75 | //then remove that word from string data | |
76 | bool GetWord(string& data, string& word) | |
77 | { | |
78 | stringstream datastream(data); | |
79 | string end; | |
80 | ||
81 | datastream >> word; | |
82 | if (datastream.fail()) | |
83 | { | |
84 | data.clear(); | |
85 | return false; | |
86 | } | |
87 | ||
88 | size_t pos = data.find(word) + word.length(); | |
89 | ||
90 | if (pos >= data.length()) | |
91 | { | |
92 | data.clear(); | |
93 | return true; | |
94 | } | |
95 | ||
96 | data = data.substr(pos); | |
97 | ||
98 | datastream.clear(); | |
99 | datastream.str(data); | |
100 | ||
101 | datastream >> end; | |
102 | if (datastream.fail()) | |
103 | data.clear(); | |
104 | ||
105 | return true; | |
106 | } | |
107 | ||
d5f66c28 | 108 | void FlushLog(ICECAdapter *cecParser) |
abbca718 LOK |
109 | { |
110 | cec_log_message message; | |
111 | while (cecParser && cecParser->GetNextLogMessage(&message)) | |
112 | { | |
bdd433cb | 113 | if ((message.level & g_cecLogLevel) == message.level) |
abbca718 | 114 | { |
e6d2161b | 115 | CStdString strLevel; |
bdd433cb LOK |
116 | switch (message.level) |
117 | { | |
118 | case CEC_LOG_ERROR: | |
e6d2161b | 119 | strLevel = "ERROR: "; |
bdd433cb LOK |
120 | break; |
121 | case CEC_LOG_WARNING: | |
e6d2161b | 122 | strLevel = "WARNING: "; |
bdd433cb LOK |
123 | break; |
124 | case CEC_LOG_NOTICE: | |
e6d2161b | 125 | strLevel = "NOTICE: "; |
bdd433cb LOK |
126 | break; |
127 | case CEC_LOG_TRAFFIC: | |
e6d2161b | 128 | strLevel = "TRAFFIC: "; |
bdd433cb LOK |
129 | break; |
130 | case CEC_LOG_DEBUG: | |
e6d2161b | 131 | strLevel = "DEBUG: "; |
bdd433cb LOK |
132 | break; |
133 | default: | |
134 | break; | |
135 | } | |
40339852 | 136 | |
8bc45476 LOK |
137 | CStdString strFullLog; |
138 | strFullLog.Format("%s[%16lld]\t%s", strLevel.c_str(), message.time, message.message); | |
139 | cout << strFullLog.c_str() << endl; | |
e6d2161b LOK |
140 | |
141 | if (g_logOutput.is_open()) | |
8bc45476 LOK |
142 | { |
143 | if (g_bShortLog) | |
144 | g_logOutput << message.message << endl; | |
145 | else | |
146 | g_logOutput << strFullLog.c_str() << endl; | |
147 | } | |
bdd433cb | 148 | } |
abbca718 LOK |
149 | } |
150 | } | |
151 | ||
d5f66c28 | 152 | void ListDevices(ICECAdapter *parser) |
abbca718 | 153 | { |
25701fa6 LOK |
154 | cec_adapter *devices = new cec_adapter[10]; |
155 | uint8_t iDevicesFound = parser->FindAdapters(devices, 10, NULL); | |
abbca718 LOK |
156 | if (iDevicesFound <= 0) |
157 | { | |
25701fa6 | 158 | cout << "Found devices: NONE" << endl; |
abbca718 LOK |
159 | } |
160 | else | |
161 | { | |
25701fa6 LOK |
162 | CStdString strLog; |
163 | strLog.Format("Found devices: %d", iDevicesFound); | |
164 | cout << strLog.c_str() << endl; | |
165 | for (unsigned int iDevicePtr = 0; iDevicePtr < iDevicesFound; iDevicePtr++) | |
abbca718 LOK |
166 | { |
167 | CStdString strDevice; | |
25701fa6 | 168 | strDevice.Format("device: %d\npath: %s\ncom port: %s", iDevicePtr + 1, devices[iDevicePtr].path, devices[iDevicePtr].comm); |
abbca718 LOK |
169 | cout << endl << strDevice.c_str() << endl; |
170 | } | |
171 | } | |
172 | } | |
173 | ||
d5f66c28 | 174 | void ShowHelpCommandLine(const char* strExec) |
abbca718 LOK |
175 | { |
176 | cout << endl << | |
177 | strExec << " {-h|--help|-l|--list-devices|[COM PORT]}" << endl << | |
178 | endl << | |
179 | "parameters:" << endl << | |
8bc45476 LOK |
180 | " -h --help Shows this help text" << endl << |
181 | " -l --list-devices List all devices on this system" << endl << | |
f8513317 | 182 | " -t --type {p|r|t|a} The device type to use. More than one is possible." << endl << |
8bc45476 LOK |
183 | " -f --log-file {file} Writes all libCEC log message to a file" << endl << |
184 | " -sf --short-log-file {file} Writes all libCEC log message without timestamps" << endl << | |
185 | " and log levels to a file." << endl << | |
606034b6 | 186 | " -d --log-level {level} Sets the log level. See cectypes.h for values." << endl << |
5ad0ea13 LOK |
187 | " -s --single-command Execute a single command and exit. Does not power" << endl << |
188 | " on devices on startup and power them off on exit." << endl << | |
8bc45476 LOK |
189 | " [COM PORT] The com port to connect to. If no COM" << endl << |
190 | " port is given, the client tries to connect to the" << endl << | |
191 | " first device that is detected." << endl << | |
825ddb96 | 192 | endl << |
8bc45476 LOK |
193 | "Type 'h' or 'help' and press enter after starting the client to display all " << endl << |
194 | "available commands" << endl; | |
825ddb96 LOK |
195 | } |
196 | ||
d5f66c28 | 197 | ICECAdapter *CreateParser(cec_device_type_list typeList) |
f8513317 LOK |
198 | { |
199 | ICECAdapter *parser = LibCecInit("CECTester", typeList); | |
200 | if (!parser || parser->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION) | |
201 | { | |
202 | #ifdef __WINDOWS__ | |
203 | cout << "Cannot load libcec.dll" << endl; | |
204 | #else | |
205 | cout << "Cannot load libcec.so" << endl; | |
206 | #endif | |
207 | return NULL; | |
208 | } | |
209 | ||
210 | CStdString strLog; | |
211 | strLog.Format("CEC Parser created - libcec version %d.%d", parser->GetLibVersionMajor(), parser->GetLibVersionMinor()); | |
212 | cout << strLog.c_str() << endl; | |
213 | ||
214 | return parser; | |
215 | } | |
216 | ||
d5f66c28 | 217 | void ShowHelpConsole(void) |
825ddb96 LOK |
218 | { |
219 | cout << endl << | |
220 | "================================================================================" << endl << | |
221 | "Available commands:" << endl << | |
222 | endl << | |
223 | "tx {bytes} transfer bytes over the CEC line." << endl << | |
1f0e9e0f | 224 | "txn {bytes} transfer bytes but don't wait for transmission ACK." << endl << |
825ddb96 LOK |
225 | "[tx 40 00 FF 11 22 33] sends bytes 0x40 0x00 0xFF 0x11 0x22 0x33" << endl << |
226 | endl << | |
88f45c9b LOK |
227 | "on {address} power on the device with the given logical address." << endl << |
228 | "[on 5] power on a connected audio system" << endl << | |
229 | endl << | |
230 | "standby {address} put the device with the given address in standby mode." << endl << | |
231 | "[standby 0] powers off the TV" << endl << | |
232 | endl << | |
825ddb96 LOK |
233 | "la {logical_address} change the logical address of the CEC adapter." << endl << |
234 | "[la 4] logical address 4" << endl << | |
235 | endl << | |
a424ebac LOK |
236 | "pa {physical_address} change the physical address of the CEC adapter." << endl << |
237 | "[pa 10 00] physical address 1.0.0.0" << endl << | |
238 | endl << | |
1969b140 LOK |
239 | "osd {addr} {string} set OSD message on the specified device." << endl << |
240 | "[osd 0 Test Message] displays 'Test Message' on the TV" << endl << | |
241 | endl << | |
6a1c0009 LOK |
242 | "ver {addr} get the CEC version of the specified device." << endl << |
243 | "[ver 0] get the CEC version of the TV" << endl << | |
244 | endl << | |
44c74256 LOK |
245 | "ven {addr} get the vendor ID of the specified device." << endl << |
246 | "[ven 0] get the vendor ID of the TV" << endl << | |
247 | endl << | |
248 | "lang {addr} get the menu language of the specified device." << endl << | |
a3269a0a LOK |
249 | "[lang 0] get the menu language of the TV" << endl << |
250 | endl << | |
e55f3f70 LOK |
251 | "pow {addr} get the power status of the specified device." << endl << |
252 | "[pow 0] get the power status of the TV" << endl << | |
253 | endl << | |
57f45e6c LOK |
254 | "poll {addr} poll the specified device." << endl << |
255 | "[poll 0] sends a poll message to the TV" << endl << | |
256 | endl << | |
8b7e5ff6 | 257 | "[mon] {1|0} enable or disable CEC bus monitoring." << endl << |
bdd433cb | 258 | "[log] {1 - 31} change the log level. see cectypes.h for values." << endl << |
825ddb96 | 259 | "[ping] send a ping command to the CEC adapter." << endl << |
88f45c9b LOK |
260 | "[bl] to let the adapter enter the bootloader, to upgrade" << endl << |
261 | " the flash rom." << endl << | |
262 | "[r] reconnect to the CEC adapter." << endl << | |
825ddb96 | 263 | "[h] or [help] show this help." << endl << |
88f45c9b LOK |
264 | "[q] or [quit] to quit the CEC test client and switch off all" << endl << |
265 | " connected CEC devices." << endl << | |
825ddb96 | 266 | "================================================================================" << endl; |
abbca718 LOK |
267 | } |
268 | ||
269 | int main (int argc, char *argv[]) | |
270 | { | |
f8513317 | 271 | cec_device_type_list typeList; |
ab1469a0 | 272 | typeList.Clear(); |
abbca718 | 273 | |
3d0dca16 | 274 | int iArgPtr = 1; |
5ad0ea13 | 275 | bool bSingleCommand(false); |
3d0dca16 | 276 | while (iArgPtr < argc) |
e6d2161b | 277 | { |
3d0dca16 | 278 | if (argc >= iArgPtr + 1) |
e6d2161b | 279 | { |
3d0dca16 LOK |
280 | if (!strcmp(argv[iArgPtr], "-f") || |
281 | !strcmp(argv[iArgPtr], "--log-file") || | |
282 | !strcmp(argv[iArgPtr], "-sf") || | |
283 | !strcmp(argv[iArgPtr], "--short-log-file")) | |
284 | { | |
285 | if (argc >= iArgPtr + 2) | |
286 | { | |
287 | g_logOutput.open(argv[iArgPtr + 1]); | |
288 | g_bShortLog = (!strcmp(argv[iArgPtr], "-sf") || !strcmp(argv[iArgPtr], "--short-log-file")); | |
289 | iArgPtr += 2; | |
290 | } | |
291 | else | |
292 | { | |
606034b6 LOK |
293 | cout << "== skipped log-file parameter: no file given ==" << endl; |
294 | ++iArgPtr; | |
295 | } | |
296 | } | |
297 | else if (!strcmp(argv[iArgPtr], "-d") || | |
298 | !strcmp(argv[iArgPtr], "--log-level")) | |
299 | { | |
300 | if (argc >= iArgPtr + 2) | |
301 | { | |
302 | int iNewLevel = atoi(argv[iArgPtr + 1]); | |
303 | if (iNewLevel >= CEC_LOG_ERROR && iNewLevel <= CEC_LOG_ALL) | |
304 | { | |
305 | g_cecLogLevel = iNewLevel; | |
5ad0ea13 LOK |
306 | if (!bSingleCommand) |
307 | cout << "log level set to " << argv[iArgPtr + 1] << endl; | |
606034b6 LOK |
308 | } |
309 | else | |
310 | { | |
311 | cout << "== skipped log-level parameter: invalid level '" << argv[iArgPtr + 1] << "' ==" << endl; | |
312 | } | |
313 | iArgPtr += 2; | |
314 | } | |
315 | else | |
316 | { | |
317 | cout << "== skipped log-level parameter: no level given ==" << endl; | |
3d0dca16 LOK |
318 | ++iArgPtr; |
319 | } | |
320 | } | |
f8513317 LOK |
321 | else if (!strcmp(argv[iArgPtr], "-t") || |
322 | !strcmp(argv[iArgPtr], "--type")) | |
d6cc5f60 LOK |
323 | { |
324 | if (argc >= iArgPtr + 2) | |
325 | { | |
f8513317 LOK |
326 | if (!strcmp(argv[iArgPtr + 1], "p")) |
327 | { | |
5ad0ea13 LOK |
328 | if (!bSingleCommand) |
329 | cout << "== using device type 'playback device'" << endl; | |
ab1469a0 | 330 | typeList.Add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); |
f8513317 LOK |
331 | } |
332 | else if (!strcmp(argv[iArgPtr + 1], "r")) | |
d6cc5f60 | 333 | { |
5ad0ea13 LOK |
334 | if (!bSingleCommand) |
335 | cout << "== using device type 'recording device'" << endl; | |
ab1469a0 | 336 | typeList.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE); |
f8513317 LOK |
337 | } |
338 | else if (!strcmp(argv[iArgPtr + 1], "t")) | |
339 | { | |
5ad0ea13 LOK |
340 | if (!bSingleCommand) |
341 | cout << "== using device type 'tuner'" << endl; | |
ab1469a0 | 342 | typeList.Add(CEC_DEVICE_TYPE_TUNER); |
f8513317 LOK |
343 | } |
344 | else if (!strcmp(argv[iArgPtr + 1], "a")) | |
345 | { | |
5ad0ea13 LOK |
346 | if (!bSingleCommand) |
347 | cout << "== using device type 'audio system'" << endl; | |
ab1469a0 | 348 | typeList.Add(CEC_DEVICE_TYPE_AUDIO_SYSTEM); |
d6cc5f60 LOK |
349 | } |
350 | else | |
351 | { | |
f8513317 | 352 | cout << "== skipped invalid device type '" << argv[iArgPtr + 1] << "'" << endl; |
d6cc5f60 | 353 | } |
d6cc5f60 LOK |
354 | ++iArgPtr; |
355 | } | |
f8513317 | 356 | ++iArgPtr; |
d6cc5f60 | 357 | } |
3d0dca16 LOK |
358 | else if (!strcmp(argv[iArgPtr], "--list-devices") || |
359 | !strcmp(argv[iArgPtr], "-l")) | |
360 | { | |
d5f66c28 | 361 | ICECAdapter *parser = CreateParser(typeList); |
f8513317 LOK |
362 | if (parser) |
363 | { | |
d5f66c28 | 364 | ListDevices(parser); |
f8513317 LOK |
365 | UnloadLibCec(parser); |
366 | } | |
3d0dca16 LOK |
367 | return 0; |
368 | } | |
5ad0ea13 LOK |
369 | else if (!strcmp(argv[iArgPtr], "--single-command") || |
370 | !strcmp(argv[iArgPtr], "-s")) | |
371 | { | |
372 | bSingleCommand = true; | |
373 | ++iArgPtr; | |
374 | } | |
3d0dca16 LOK |
375 | else if (!strcmp(argv[iArgPtr], "--help") || |
376 | !strcmp(argv[iArgPtr], "-h")) | |
377 | { | |
d5f66c28 | 378 | ShowHelpCommandLine(argv[0]); |
3d0dca16 LOK |
379 | return 0; |
380 | } | |
381 | else | |
382 | { | |
383 | g_strPort = argv[iArgPtr++]; | |
384 | } | |
e6d2161b LOK |
385 | } |
386 | } | |
387 | ||
ab1469a0 | 388 | if (typeList.IsEmpty()) |
f8513317 | 389 | { |
5ad0ea13 LOK |
390 | if (!bSingleCommand) |
391 | cout << "No device type given. Using 'playback device'" << endl; | |
ab1469a0 | 392 | typeList.Add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); |
f8513317 LOK |
393 | } |
394 | ||
395 | ICECAdapter *parser = LibCecInit("CECTester", typeList); | |
396 | if (!parser || parser->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION) | |
397 | { | |
398 | #ifdef __WINDOWS__ | |
399 | cout << "Cannot load libcec.dll" << endl; | |
400 | #else | |
401 | cout << "Cannot load libcec.so" << endl; | |
402 | #endif | |
403 | return 1; | |
404 | } | |
f8513317 | 405 | |
5ad0ea13 LOK |
406 | if (!bSingleCommand) |
407 | { | |
408 | CStdString strLog; | |
409 | strLog.Format("CEC Parser created - libcec version %d.%d", parser->GetLibVersionMajor(), parser->GetLibVersionMinor()); | |
410 | cout << strLog.c_str() << endl; | |
411 | ||
412 | //make stdin non-blocking | |
413 | #ifndef __WINDOWS__ | |
414 | int flags = fcntl(0, F_GETFL, 0); | |
415 | flags |= O_NONBLOCK; | |
416 | fcntl(0, F_SETFL, flags); | |
417 | #endif | |
418 | } | |
f8513317 | 419 | |
3d0dca16 | 420 | if (g_strPort.IsEmpty()) |
abbca718 | 421 | { |
5ad0ea13 LOK |
422 | if (!bSingleCommand) |
423 | cout << "no serial port given. trying autodetect: "; | |
25701fa6 LOK |
424 | cec_adapter devices[10]; |
425 | uint8_t iDevicesFound = parser->FindAdapters(devices, 10, NULL); | |
abbca718 LOK |
426 | if (iDevicesFound <= 0) |
427 | { | |
5ad0ea13 LOK |
428 | if (bSingleCommand) |
429 | cout << "autodetect "; | |
abbca718 LOK |
430 | cout << "FAILED" << endl; |
431 | UnloadLibCec(parser); | |
432 | return 1; | |
433 | } | |
434 | else | |
435 | { | |
5ad0ea13 LOK |
436 | if (!bSingleCommand) |
437 | { | |
438 | cout << endl << " path: " << devices[0].path << endl << | |
439 | " com port: " << devices[0].comm << endl << endl; | |
440 | } | |
3d0dca16 | 441 | g_strPort = devices[0].comm; |
abbca718 LOK |
442 | } |
443 | } | |
e6d2161b | 444 | |
3d0dca16 | 445 | if (!parser->Open(g_strPort.c_str())) |
abbca718 | 446 | { |
3d0dca16 | 447 | cout << "unable to open the device on port " << g_strPort << endl; |
d5f66c28 | 448 | FlushLog(parser); |
abbca718 LOK |
449 | UnloadLibCec(parser); |
450 | return 1; | |
451 | } | |
452 | ||
5ad0ea13 LOK |
453 | if (!bSingleCommand) |
454 | { | |
455 | cout << "cec device opened" << endl; | |
abbca718 | 456 | |
5ad0ea13 LOK |
457 | parser->PowerOnDevices(CECDEVICE_TV); |
458 | FlushLog(parser); | |
abbca718 | 459 | |
5ad0ea13 LOK |
460 | parser->SetActiveSource(); |
461 | FlushLog(parser); | |
462 | ||
463 | cout << "waiting for input" << endl; | |
464 | } | |
abbca718 LOK |
465 | |
466 | bool bContinue(true); | |
abbca718 LOK |
467 | while (bContinue) |
468 | { | |
5ad0ea13 LOK |
469 | if (bSingleCommand) |
470 | bContinue = false; | |
471 | ||
d5f66c28 | 472 | FlushLog(parser); |
abbca718 | 473 | |
b5b53c7d LOK |
474 | /* just ignore the command buffer and clear it */ |
475 | cec_command dummy; | |
476 | while (parser && parser->GetNextCommand(&dummy)) {} | |
477 | ||
abbca718 LOK |
478 | string input; |
479 | getline(cin, input); | |
480 | cin.clear(); | |
481 | ||
482 | if (!input.empty()) | |
483 | { | |
484 | string command; | |
485 | if (GetWord(input, command)) | |
486 | { | |
faa6a23b | 487 | if (command == "tx" || command == "txn") |
abbca718 LOK |
488 | { |
489 | string strvalue; | |
8bca69de | 490 | uint8_t ivalue; |
9dee1670 | 491 | cec_command bytes; |
ab1469a0 | 492 | bytes.Clear(); |
25701fa6 | 493 | |
abbca718 | 494 | while (GetWord(input, strvalue) && HexStrToInt(strvalue, ivalue)) |
ab1469a0 | 495 | bytes.PushBack(ivalue); |
abbca718 | 496 | |
8d84e2c0 | 497 | if (command == "txn") |
1f0e9e0f | 498 | bytes.transmit_timeout = 0; |
8d84e2c0 LOK |
499 | |
500 | parser->Transmit(bytes); | |
abbca718 | 501 | } |
88f45c9b LOK |
502 | else if (command == "on") |
503 | { | |
504 | string strValue; | |
505 | uint8_t iValue = 0; | |
506 | if (GetWord(input, strValue) && HexStrToInt(strValue, iValue) && iValue <= 0xF) | |
507 | { | |
508 | parser->PowerOnDevices((cec_logical_address) iValue); | |
509 | } | |
510 | else | |
511 | { | |
512 | cout << "invalid destination" << endl; | |
513 | } | |
514 | } | |
515 | else if (command == "standby") | |
516 | { | |
517 | string strValue; | |
518 | uint8_t iValue = 0; | |
519 | if (GetWord(input, strValue) && HexStrToInt(strValue, iValue) && iValue <= 0xF) | |
520 | { | |
521 | parser->StandbyDevices((cec_logical_address) iValue); | |
522 | } | |
523 | else | |
524 | { | |
525 | cout << "invalid destination" << endl; | |
526 | } | |
527 | } | |
57f45e6c LOK |
528 | else if (command == "poll") |
529 | { | |
530 | string strValue; | |
531 | uint8_t iValue = 0; | |
532 | if (GetWord(input, strValue) && HexStrToInt(strValue, iValue) && iValue <= 0xF) | |
533 | { | |
534 | if (parser->PollDevice((cec_logical_address) iValue)) | |
535 | cout << "POLL message sent" << endl; | |
536 | else | |
537 | cout << "POLL message not sent" << endl; | |
538 | } | |
539 | else | |
540 | { | |
541 | cout << "invalid destination" << endl; | |
542 | } | |
543 | } | |
6dfe9213 LOK |
544 | else if (command == "la") |
545 | { | |
546 | string strvalue; | |
6dfe9213 LOK |
547 | if (GetWord(input, strvalue)) |
548 | { | |
549 | parser->SetLogicalAddress((cec_logical_address) atoi(strvalue.c_str())); | |
abbca718 LOK |
550 | } |
551 | } | |
a424ebac LOK |
552 | else if (command == "pa") |
553 | { | |
554 | string strB1, strB2; | |
555 | uint8_t iB1, iB2; | |
556 | if (GetWord(input, strB1) && HexStrToInt(strB1, iB1) && | |
557 | GetWord(input, strB2) && HexStrToInt(strB2, iB2)) | |
558 | { | |
559 | uint16_t iPhysicalAddress = ((uint16_t)iB1 << 8) + iB2; | |
560 | parser->SetPhysicalAddress(iPhysicalAddress); | |
561 | } | |
562 | } | |
1969b140 LOK |
563 | else if (command == "osd") |
564 | { | |
565 | bool bFirstWord(false); | |
566 | string strAddr, strMessage, strWord; | |
567 | uint8_t iAddr; | |
568 | if (GetWord(input, strAddr) && HexStrToInt(strAddr, iAddr) && iAddr < 0xF) | |
569 | { | |
570 | while (GetWord(input, strWord)) | |
571 | { | |
572 | if (bFirstWord) | |
573 | { | |
574 | bFirstWord = false; | |
575 | strMessage.append(" "); | |
576 | } | |
577 | strMessage.append(strWord); | |
578 | } | |
579 | parser->SetOSDString((cec_logical_address) iAddr, CEC_DISPLAY_CONTROL_DISPLAY_FOR_DEFAULT_TIME, strMessage.c_str()); | |
580 | } | |
581 | } | |
abbca718 LOK |
582 | else if (command == "ping") |
583 | { | |
2abe74eb | 584 | parser->PingAdapter(); |
abbca718 | 585 | } |
8b7e5ff6 LOK |
586 | else if (command == "mon") |
587 | { | |
588 | CStdString strEnable; | |
589 | if (GetWord(input, strEnable) && (strEnable.Equals("0") || strEnable.Equals("1"))) | |
590 | { | |
591 | parser->SwitchMonitoring(strEnable.Equals("1")); | |
592 | } | |
593 | } | |
abbca718 LOK |
594 | else if (command == "bl") |
595 | { | |
596 | parser->StartBootloader(); | |
597 | } | |
a3269a0a LOK |
598 | else if (command == "lang") |
599 | { | |
600 | CStdString strDev; | |
601 | if (GetWord(input, strDev)) | |
602 | { | |
603 | int iDev = atoi(strDev); | |
604 | if (iDev >= 0 && iDev < 15) | |
605 | { | |
606 | CStdString strLog; | |
607 | cec_menu_language language; | |
608 | if (parser->GetDeviceMenuLanguage((cec_logical_address) iDev, &language)) | |
609 | strLog.Format("menu language '%s'", language.language); | |
610 | else | |
611 | strLog = "failed!"; | |
612 | cout << strLog.c_str() << endl; | |
613 | } | |
614 | } | |
615 | } | |
44c74256 LOK |
616 | else if (command == "ven") |
617 | { | |
618 | CStdString strDev; | |
619 | if (GetWord(input, strDev)) | |
620 | { | |
621 | int iDev = atoi(strDev); | |
622 | if (iDev >= 0 && iDev < 15) | |
623 | { | |
624 | uint64_t iVendor = parser->GetDeviceVendorId((cec_logical_address) iDev); | |
625 | CStdString strLog; | |
626 | strLog.Format("vendor id: %06x", iVendor); | |
627 | cout << strLog.c_str() << endl; | |
628 | } | |
629 | } | |
630 | } | |
6a1c0009 LOK |
631 | else if (command == "ver") |
632 | { | |
633 | CStdString strDev; | |
634 | if (GetWord(input, strDev)) | |
635 | { | |
636 | int iDev = atoi(strDev); | |
637 | if (iDev >= 0 && iDev < 15) | |
638 | { | |
639 | cec_version iVersion = parser->GetDeviceCecVersion((cec_logical_address) iDev); | |
640 | switch (iVersion) | |
641 | { | |
642 | case CEC_VERSION_1_2: | |
643 | cout << "CEC version 1.2" << endl; | |
644 | break; | |
645 | case CEC_VERSION_1_2A: | |
646 | cout << "CEC version 1.2a" << endl; | |
647 | break; | |
648 | case CEC_VERSION_1_3: | |
649 | cout << "CEC version 1.3" << endl; | |
650 | break; | |
651 | case CEC_VERSION_1_3A: | |
652 | cout << "CEC version 1.3a" << endl; | |
653 | break; | |
654 | default: | |
655 | cout << "unknown CEC version" << endl; | |
656 | break; | |
657 | } | |
658 | } | |
659 | } | |
660 | } | |
e55f3f70 LOK |
661 | else if (command == "pow") |
662 | { | |
663 | CStdString strDev; | |
664 | if (GetWord(input, strDev)) | |
665 | { | |
666 | int iDev = atoi(strDev); | |
667 | if (iDev >= 0 && iDev < 15) | |
668 | { | |
669 | cec_power_status iPower = parser->GetDevicePowerStatus((cec_logical_address) iDev); | |
670 | switch (iPower) | |
671 | { | |
672 | case CEC_POWER_STATUS_ON: | |
673 | cout << "powered on" << endl; | |
674 | break; | |
675 | case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY: | |
676 | cout << "on -> standby" << endl; | |
677 | break; | |
678 | case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON: | |
679 | cout << "standby -> on" << endl; | |
680 | break; | |
681 | case CEC_POWER_STATUS_STANDBY: | |
682 | cout << "standby" << endl; | |
683 | break; | |
684 | default: | |
685 | cout << "unknown power status" << endl; | |
686 | break; | |
687 | } | |
688 | } | |
689 | } | |
690 | } | |
12027dbe LOK |
691 | else if (command == "r") |
692 | { | |
25701fa6 | 693 | cout << "closing the connection" << endl; |
12027dbe | 694 | parser->Close(); |
d5f66c28 | 695 | FlushLog(parser); |
25701fa6 LOK |
696 | |
697 | cout << "opening a new connection" << endl; | |
3d0dca16 | 698 | parser->Open(g_strPort.c_str()); |
d5f66c28 | 699 | FlushLog(parser); |
25701fa6 | 700 | |
18203d17 LOK |
701 | cout << "setting active source" << endl; |
702 | parser->SetActiveSource(); | |
12027dbe | 703 | } |
825ddb96 LOK |
704 | else if (command == "h" || command == "help") |
705 | { | |
d5f66c28 | 706 | ShowHelpConsole(); |
825ddb96 | 707 | } |
abbca718 LOK |
708 | else if (command == "q" || command == "quit") |
709 | { | |
710 | bContinue = false; | |
711 | } | |
bdd433cb LOK |
712 | else if (command == "log") |
713 | { | |
714 | CStdString strLevel; | |
715 | if (GetWord(input, strLevel)) | |
716 | { | |
717 | int iNewLevel = atoi(strLevel); | |
718 | if (iNewLevel >= CEC_LOG_ERROR && iNewLevel <= CEC_LOG_ALL) | |
719 | { | |
720 | g_cecLogLevel = iNewLevel; | |
721 | cout << "log level changed to " << strLevel.c_str() << endl; | |
722 | } | |
723 | } | |
724 | } | |
abbca718 LOK |
725 | } |
726 | if (bContinue) | |
727 | cout << "waiting for input" << endl; | |
728 | } | |
5ad0ea13 LOK |
729 | |
730 | if (bContinue) | |
731 | CCondition::Sleep(50); | |
abbca718 LOK |
732 | } |
733 | ||
5ad0ea13 LOK |
734 | if (!bSingleCommand) |
735 | parser->StandbyDevices(CECDEVICE_BROADCAST); | |
736 | ||
5f39c4d8 | 737 | parser->Close(); |
d5f66c28 | 738 | FlushLog(parser); |
abbca718 | 739 | UnloadLibCec(parser); |
e6d2161b LOK |
740 | |
741 | if (g_logOutput.is_open()) | |
742 | g_logOutput.close(); | |
743 | ||
abbca718 LOK |
744 | return 0; |
745 | } |