cec: added bWait parameter to volume change methods.
[deb_libcec.git] / src / testclient / main.cpp
CommitLineData
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
44using namespace CEC;
45using namespace std;
46
d75be19b 47#define CEC_TEST_CLIENT_VERSION 1
abbca718 48
761dcc45 49#include <cecloader.h>
8bc45476 50
3d0dca16
LOK
51int g_cecLogLevel = CEC_LOG_ALL;
52ofstream g_logOutput;
53bool g_bShortLog = false;
54CStdString g_strPort;
b9187cc6 55
8bca69de 56inline 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
76bool 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 108void 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 152void 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 174void 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 <<
16b1e052 183 " -p --port {int} The HDMI port to use as active source." << endl <<
8bc45476
LOK
184 " -f --log-file {file} Writes all libCEC log message to a file" << endl <<
185 " -sf --short-log-file {file} Writes all libCEC log message without timestamps" << endl <<
186 " and log levels to a file." << endl <<
606034b6 187 " -d --log-level {level} Sets the log level. See cectypes.h for values." << endl <<
5ad0ea13
LOK
188 " -s --single-command Execute a single command and exit. Does not power" << endl <<
189 " on devices on startup and power them off on exit." << endl <<
8bc45476
LOK
190 " [COM PORT] The com port to connect to. If no COM" << endl <<
191 " port is given, the client tries to connect to the" << endl <<
192 " first device that is detected." << endl <<
825ddb96 193 endl <<
8bc45476
LOK
194 "Type 'h' or 'help' and press enter after starting the client to display all " << endl <<
195 "available commands" << endl;
825ddb96
LOK
196}
197
d5f66c28 198ICECAdapter *CreateParser(cec_device_type_list typeList)
f8513317
LOK
199{
200 ICECAdapter *parser = LibCecInit("CECTester", typeList);
201 if (!parser || parser->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION)
202 {
203 #ifdef __WINDOWS__
204 cout << "Cannot load libcec.dll" << endl;
205 #else
206 cout << "Cannot load libcec.so" << endl;
207 #endif
208 return NULL;
209 }
210
211 CStdString strLog;
212 strLog.Format("CEC Parser created - libcec version %d.%d", parser->GetLibVersionMajor(), parser->GetLibVersionMinor());
213 cout << strLog.c_str() << endl;
214
215 return parser;
216}
217
d5f66c28 218void ShowHelpConsole(void)
825ddb96
LOK
219{
220 cout << endl <<
221 "================================================================================" << endl <<
222 "Available commands:" << endl <<
223 endl <<
7e793bdd
LOK
224 "[tx] {bytes} transfer bytes over the CEC line." << endl <<
225 "[txn] {bytes} transfer bytes but don't wait for transmission ACK." << endl <<
226 "[on] {address} power on the device with the given logical address." << endl <<
227 "[standby] {address} put the device with the given address in standby mode." << endl <<
228 "[la] {logical address} change the logical address of the CEC adapter." << endl <<
229 "[p] {port number} change the HDMI port number of the CEC adapter." << endl <<
230 "[pa] {physical address} change the physical address of the CEC adapter." << endl <<
231 "[osd] {addr} {string} set OSD message on the specified device." << endl <<
232 "[ver] {addr} get the CEC version of the specified device." << endl <<
233 "[ven] {addr} get the vendor ID of the specified device." << endl <<
234 "[lang] {addr} get the menu language of the specified device." << endl <<
235 "[pow] {addr} get the power status of the specified device." << endl <<
236 "[poll] {addr} poll the specified device." << endl <<
237 "[lad] lists active devices on the bus" << endl <<
238 "[ad] {addr} checks whether the specified device is active." << endl <<
239 "[at] {type} checks whether the specified device type is active." << endl <<
240 "[volup] send a volume up command to the amp if present" << endl <<
241 "[voldown] send a volume down command to the amp if present" << endl <<
242 "[mute] send a mute/unmute command to the amp if present" << endl <<
8b7e5ff6 243 "[mon] {1|0} enable or disable CEC bus monitoring." << endl <<
bdd433cb 244 "[log] {1 - 31} change the log level. see cectypes.h for values." << endl <<
825ddb96 245 "[ping] send a ping command to the CEC adapter." << endl <<
88f45c9b
LOK
246 "[bl] to let the adapter enter the bootloader, to upgrade" << endl <<
247 " the flash rom." << endl <<
248 "[r] reconnect to the CEC adapter." << endl <<
825ddb96 249 "[h] or [help] show this help." << endl <<
88f45c9b
LOK
250 "[q] or [quit] to quit the CEC test client and switch off all" << endl <<
251 " connected CEC devices." << endl <<
825ddb96 252 "================================================================================" << endl;
abbca718
LOK
253}
254
255int main (int argc, char *argv[])
256{
16b1e052 257 int8_t iHDMIPort(-1);
f8513317 258 cec_device_type_list typeList;
20b8870a 259 typeList.clear();
abbca718 260
3d0dca16 261 int iArgPtr = 1;
5ad0ea13 262 bool bSingleCommand(false);
3d0dca16 263 while (iArgPtr < argc)
e6d2161b 264 {
3d0dca16 265 if (argc >= iArgPtr + 1)
e6d2161b 266 {
3d0dca16
LOK
267 if (!strcmp(argv[iArgPtr], "-f") ||
268 !strcmp(argv[iArgPtr], "--log-file") ||
269 !strcmp(argv[iArgPtr], "-sf") ||
270 !strcmp(argv[iArgPtr], "--short-log-file"))
271 {
272 if (argc >= iArgPtr + 2)
273 {
274 g_logOutput.open(argv[iArgPtr + 1]);
275 g_bShortLog = (!strcmp(argv[iArgPtr], "-sf") || !strcmp(argv[iArgPtr], "--short-log-file"));
276 iArgPtr += 2;
277 }
278 else
279 {
606034b6
LOK
280 cout << "== skipped log-file parameter: no file given ==" << endl;
281 ++iArgPtr;
282 }
283 }
284 else if (!strcmp(argv[iArgPtr], "-d") ||
285 !strcmp(argv[iArgPtr], "--log-level"))
286 {
287 if (argc >= iArgPtr + 2)
288 {
289 int iNewLevel = atoi(argv[iArgPtr + 1]);
290 if (iNewLevel >= CEC_LOG_ERROR && iNewLevel <= CEC_LOG_ALL)
291 {
292 g_cecLogLevel = iNewLevel;
5ad0ea13
LOK
293 if (!bSingleCommand)
294 cout << "log level set to " << argv[iArgPtr + 1] << endl;
606034b6
LOK
295 }
296 else
297 {
298 cout << "== skipped log-level parameter: invalid level '" << argv[iArgPtr + 1] << "' ==" << endl;
299 }
300 iArgPtr += 2;
301 }
302 else
303 {
304 cout << "== skipped log-level parameter: no level given ==" << endl;
3d0dca16
LOK
305 ++iArgPtr;
306 }
307 }
f8513317
LOK
308 else if (!strcmp(argv[iArgPtr], "-t") ||
309 !strcmp(argv[iArgPtr], "--type"))
d6cc5f60
LOK
310 {
311 if (argc >= iArgPtr + 2)
312 {
f8513317
LOK
313 if (!strcmp(argv[iArgPtr + 1], "p"))
314 {
5ad0ea13
LOK
315 if (!bSingleCommand)
316 cout << "== using device type 'playback device'" << endl;
20b8870a 317 typeList.add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
f8513317
LOK
318 }
319 else if (!strcmp(argv[iArgPtr + 1], "r"))
d6cc5f60 320 {
5ad0ea13
LOK
321 if (!bSingleCommand)
322 cout << "== using device type 'recording device'" << endl;
20b8870a 323 typeList.add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
f8513317
LOK
324 }
325 else if (!strcmp(argv[iArgPtr + 1], "t"))
326 {
5ad0ea13
LOK
327 if (!bSingleCommand)
328 cout << "== using device type 'tuner'" << endl;
20b8870a 329 typeList.add(CEC_DEVICE_TYPE_TUNER);
f8513317
LOK
330 }
331 else if (!strcmp(argv[iArgPtr + 1], "a"))
332 {
5ad0ea13
LOK
333 if (!bSingleCommand)
334 cout << "== using device type 'audio system'" << endl;
20b8870a 335 typeList.add(CEC_DEVICE_TYPE_AUDIO_SYSTEM);
d6cc5f60
LOK
336 }
337 else
338 {
f8513317 339 cout << "== skipped invalid device type '" << argv[iArgPtr + 1] << "'" << endl;
d6cc5f60 340 }
d6cc5f60
LOK
341 ++iArgPtr;
342 }
f8513317 343 ++iArgPtr;
d6cc5f60 344 }
3d0dca16
LOK
345 else if (!strcmp(argv[iArgPtr], "--list-devices") ||
346 !strcmp(argv[iArgPtr], "-l"))
347 {
d5f66c28 348 ICECAdapter *parser = CreateParser(typeList);
f8513317
LOK
349 if (parser)
350 {
d5f66c28 351 ListDevices(parser);
f8513317
LOK
352 UnloadLibCec(parser);
353 }
3d0dca16
LOK
354 return 0;
355 }
5ad0ea13
LOK
356 else if (!strcmp(argv[iArgPtr], "--single-command") ||
357 !strcmp(argv[iArgPtr], "-s"))
358 {
359 bSingleCommand = true;
360 ++iArgPtr;
361 }
3d0dca16
LOK
362 else if (!strcmp(argv[iArgPtr], "--help") ||
363 !strcmp(argv[iArgPtr], "-h"))
364 {
d5f66c28 365 ShowHelpCommandLine(argv[0]);
3d0dca16
LOK
366 return 0;
367 }
45de9d9f 368 else if (!strcmp(argv[iArgPtr], "-p") ||
16b1e052 369 !strcmp(argv[iArgPtr], "--port"))
45de9d9f
LOK
370 {
371 if (argc >= iArgPtr + 2)
372 {
16b1e052
LOK
373 iHDMIPort= atoi(argv[iArgPtr + 1]);
374 cout << "using HDMI port '" << iHDMIPort << "'" << endl;
45de9d9f
LOK
375 ++iArgPtr;
376 }
377 ++iArgPtr;
378 }
3d0dca16
LOK
379 else
380 {
381 g_strPort = argv[iArgPtr++];
382 }
e6d2161b
LOK
383 }
384 }
385
ab1469a0 386 if (typeList.IsEmpty())
f8513317 387 {
5ad0ea13 388 if (!bSingleCommand)
88e5de6f
LOK
389 cout << "No device type given. Using 'recording device'" << endl;
390 typeList.add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
f8513317
LOK
391 }
392
393 ICECAdapter *parser = LibCecInit("CECTester", typeList);
394 if (!parser || parser->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION)
395 {
396#ifdef __WINDOWS__
397 cout << "Cannot load libcec.dll" << endl;
398#else
399 cout << "Cannot load libcec.so" << endl;
400#endif
401 return 1;
402 }
f8513317 403
5ad0ea13
LOK
404 if (!bSingleCommand)
405 {
406 CStdString strLog;
407 strLog.Format("CEC Parser created - libcec version %d.%d", parser->GetLibVersionMajor(), parser->GetLibVersionMinor());
408 cout << strLog.c_str() << endl;
409
410 //make stdin non-blocking
411 #ifndef __WINDOWS__
412 int flags = fcntl(0, F_GETFL, 0);
413 flags |= O_NONBLOCK;
414 fcntl(0, F_SETFL, flags);
415 #endif
416 }
f8513317 417
3d0dca16 418 if (g_strPort.IsEmpty())
abbca718 419 {
5ad0ea13
LOK
420 if (!bSingleCommand)
421 cout << "no serial port given. trying autodetect: ";
25701fa6
LOK
422 cec_adapter devices[10];
423 uint8_t iDevicesFound = parser->FindAdapters(devices, 10, NULL);
abbca718
LOK
424 if (iDevicesFound <= 0)
425 {
5ad0ea13
LOK
426 if (bSingleCommand)
427 cout << "autodetect ";
abbca718
LOK
428 cout << "FAILED" << endl;
429 UnloadLibCec(parser);
430 return 1;
431 }
432 else
433 {
5ad0ea13
LOK
434 if (!bSingleCommand)
435 {
436 cout << endl << " path: " << devices[0].path << endl <<
437 " com port: " << devices[0].comm << endl << endl;
438 }
3d0dca16 439 g_strPort = devices[0].comm;
abbca718
LOK
440 }
441 }
e6d2161b 442
16b1e052
LOK
443 if (iHDMIPort > 0)
444 {
445 parser->SetHDMIPort((uint8_t)iHDMIPort);
446 FlushLog(parser);
447 }
448
449 cout << "scanning the CEC bus..." << endl;
450
3d0dca16 451 if (!parser->Open(g_strPort.c_str()))
abbca718 452 {
3d0dca16 453 cout << "unable to open the device on port " << g_strPort << endl;
d5f66c28 454 FlushLog(parser);
abbca718
LOK
455 UnloadLibCec(parser);
456 return 1;
457 }
458
5ad0ea13
LOK
459 if (!bSingleCommand)
460 {
461 cout << "cec device opened" << endl;
abbca718 462
5ad0ea13
LOK
463 parser->PowerOnDevices(CECDEVICE_TV);
464 FlushLog(parser);
abbca718 465
5ad0ea13
LOK
466 parser->SetActiveSource();
467 FlushLog(parser);
468
469 cout << "waiting for input" << endl;
470 }
abbca718
LOK
471
472 bool bContinue(true);
abbca718
LOK
473 while (bContinue)
474 {
5ad0ea13
LOK
475 if (bSingleCommand)
476 bContinue = false;
477
d5f66c28 478 FlushLog(parser);
abbca718 479
b5b53c7d
LOK
480 /* just ignore the command buffer and clear it */
481 cec_command dummy;
482 while (parser && parser->GetNextCommand(&dummy)) {}
483
abbca718
LOK
484 string input;
485 getline(cin, input);
486 cin.clear();
487
488 if (!input.empty())
489 {
490 string command;
491 if (GetWord(input, command))
492 {
faa6a23b 493 if (command == "tx" || command == "txn")
abbca718
LOK
494 {
495 string strvalue;
8bca69de 496 uint8_t ivalue;
9dee1670 497 cec_command bytes;
ab1469a0 498 bytes.Clear();
25701fa6 499
abbca718 500 while (GetWord(input, strvalue) && HexStrToInt(strvalue, ivalue))
ab1469a0 501 bytes.PushBack(ivalue);
abbca718 502
8d84e2c0 503 if (command == "txn")
1f0e9e0f 504 bytes.transmit_timeout = 0;
8d84e2c0
LOK
505
506 parser->Transmit(bytes);
abbca718 507 }
88f45c9b
LOK
508 else if (command == "on")
509 {
510 string strValue;
511 uint8_t iValue = 0;
512 if (GetWord(input, strValue) && HexStrToInt(strValue, iValue) && iValue <= 0xF)
513 {
514 parser->PowerOnDevices((cec_logical_address) iValue);
515 }
516 else
517 {
518 cout << "invalid destination" << endl;
519 }
520 }
521 else if (command == "standby")
522 {
523 string strValue;
524 uint8_t iValue = 0;
525 if (GetWord(input, strValue) && HexStrToInt(strValue, iValue) && iValue <= 0xF)
526 {
527 parser->StandbyDevices((cec_logical_address) iValue);
528 }
529 else
530 {
531 cout << "invalid destination" << endl;
532 }
533 }
57f45e6c
LOK
534 else if (command == "poll")
535 {
536 string strValue;
537 uint8_t iValue = 0;
538 if (GetWord(input, strValue) && HexStrToInt(strValue, iValue) && iValue <= 0xF)
539 {
540 if (parser->PollDevice((cec_logical_address) iValue))
541 cout << "POLL message sent" << endl;
542 else
543 cout << "POLL message not sent" << endl;
544 }
545 else
546 {
547 cout << "invalid destination" << endl;
548 }
549 }
6dfe9213
LOK
550 else if (command == "la")
551 {
552 string strvalue;
6dfe9213
LOK
553 if (GetWord(input, strvalue))
554 {
555 parser->SetLogicalAddress((cec_logical_address) atoi(strvalue.c_str()));
abbca718
LOK
556 }
557 }
16b1e052
LOK
558 else if (command == "p")
559 {
560 string strvalue;
561 if (GetWord(input, strvalue))
562 {
563 parser->SetHDMIPort(atoi(strvalue.c_str()));
564 }
565 }
a424ebac
LOK
566 else if (command == "pa")
567 {
568 string strB1, strB2;
569 uint8_t iB1, iB2;
570 if (GetWord(input, strB1) && HexStrToInt(strB1, iB1) &&
571 GetWord(input, strB2) && HexStrToInt(strB2, iB2))
572 {
573 uint16_t iPhysicalAddress = ((uint16_t)iB1 << 8) + iB2;
574 parser->SetPhysicalAddress(iPhysicalAddress);
575 }
576 }
1969b140
LOK
577 else if (command == "osd")
578 {
579 bool bFirstWord(false);
580 string strAddr, strMessage, strWord;
581 uint8_t iAddr;
582 if (GetWord(input, strAddr) && HexStrToInt(strAddr, iAddr) && iAddr < 0xF)
583 {
584 while (GetWord(input, strWord))
585 {
586 if (bFirstWord)
587 {
588 bFirstWord = false;
589 strMessage.append(" ");
590 }
591 strMessage.append(strWord);
592 }
593 parser->SetOSDString((cec_logical_address) iAddr, CEC_DISPLAY_CONTROL_DISPLAY_FOR_DEFAULT_TIME, strMessage.c_str());
594 }
595 }
abbca718
LOK
596 else if (command == "ping")
597 {
2abe74eb 598 parser->PingAdapter();
abbca718 599 }
04e637f9
LOK
600 else if (command == "volup")
601 {
9f332fe2
LOK
602 CStdString strLog;
603 strLog.Format("volume up: %2X", parser->VolumeUp());
604 cout << strLog.c_str() << endl;
04e637f9
LOK
605 }
606 else if (command == "voldown")
607 {
9f332fe2
LOK
608 CStdString strLog;
609 strLog.Format("volume up: %2X", parser->VolumeDown());
610 cout << strLog.c_str() << endl;
04e637f9
LOK
611 }
612 else if (command == "mute")
613 {
9f332fe2
LOK
614 CStdString strLog;
615 strLog.Format("mute: %2X", parser->MuteAudio());
616 cout << strLog.c_str() << endl;
04e637f9 617 }
8b7e5ff6
LOK
618 else if (command == "mon")
619 {
620 CStdString strEnable;
621 if (GetWord(input, strEnable) && (strEnable.Equals("0") || strEnable.Equals("1")))
622 {
623 parser->SwitchMonitoring(strEnable.Equals("1"));
624 }
625 }
abbca718
LOK
626 else if (command == "bl")
627 {
628 parser->StartBootloader();
629 }
a3269a0a
LOK
630 else if (command == "lang")
631 {
632 CStdString strDev;
633 if (GetWord(input, strDev))
634 {
635 int iDev = atoi(strDev);
636 if (iDev >= 0 && iDev < 15)
637 {
638 CStdString strLog;
639 cec_menu_language language;
640 if (parser->GetDeviceMenuLanguage((cec_logical_address) iDev, &language))
641 strLog.Format("menu language '%s'", language.language);
642 else
643 strLog = "failed!";
644 cout << strLog.c_str() << endl;
645 }
646 }
647 }
44c74256
LOK
648 else if (command == "ven")
649 {
650 CStdString strDev;
651 if (GetWord(input, strDev))
652 {
653 int iDev = atoi(strDev);
654 if (iDev >= 0 && iDev < 15)
655 {
656 uint64_t iVendor = parser->GetDeviceVendorId((cec_logical_address) iDev);
657 CStdString strLog;
658 strLog.Format("vendor id: %06x", iVendor);
659 cout << strLog.c_str() << endl;
660 }
661 }
662 }
6a1c0009
LOK
663 else if (command == "ver")
664 {
665 CStdString strDev;
666 if (GetWord(input, strDev))
667 {
668 int iDev = atoi(strDev);
669 if (iDev >= 0 && iDev < 15)
670 {
671 cec_version iVersion = parser->GetDeviceCecVersion((cec_logical_address) iDev);
672 switch (iVersion)
673 {
674 case CEC_VERSION_1_2:
675 cout << "CEC version 1.2" << endl;
676 break;
677 case CEC_VERSION_1_2A:
678 cout << "CEC version 1.2a" << endl;
679 break;
680 case CEC_VERSION_1_3:
681 cout << "CEC version 1.3" << endl;
682 break;
683 case CEC_VERSION_1_3A:
684 cout << "CEC version 1.3a" << endl;
685 break;
686 default:
687 cout << "unknown CEC version" << endl;
688 break;
689 }
690 }
691 }
692 }
e55f3f70
LOK
693 else if (command == "pow")
694 {
695 CStdString strDev;
696 if (GetWord(input, strDev))
697 {
698 int iDev = atoi(strDev);
699 if (iDev >= 0 && iDev < 15)
700 {
701 cec_power_status iPower = parser->GetDevicePowerStatus((cec_logical_address) iDev);
702 switch (iPower)
703 {
704 case CEC_POWER_STATUS_ON:
705 cout << "powered on" << endl;
706 break;
707 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
708 cout << "on -> standby" << endl;
709 break;
710 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
711 cout << "standby -> on" << endl;
712 break;
713 case CEC_POWER_STATUS_STANDBY:
714 cout << "standby" << endl;
715 break;
716 default:
717 cout << "unknown power status" << endl;
718 break;
719 }
720 }
721 }
722 }
6d858ba4
LOK
723 else if (command == "lad")
724 {
725 cout << "listing active devices:" << endl;
726 cec_logical_addresses addresses = parser->GetActiveDevices();
727 for (unsigned iPtr = 0; iPtr < 16; iPtr++)
728 if (addresses[iPtr])
729 cout << "logical address " << iPtr << endl;
730 }
731 else if (command == "ad")
732 {
733 CStdString strDev;
734 if (GetWord(input, strDev))
735 {
736 int iDev = atoi(strDev);
737 if (iDev >= 0 && iDev < 15)
738 cout << "logical address " << iDev << " is " << (parser->IsActiveDevice((cec_logical_address)iDev) ? "active" : "not active") << endl;
739 }
740 }
741 else if (command == "at")
742 {
743 CStdString strType;
744 if (GetWord(input, strType))
745 {
746 cec_device_type type = CEC_DEVICE_TYPE_TV;
747 if (strType.Equals("a"))
748 type = CEC_DEVICE_TYPE_AUDIO_SYSTEM;
749 else if (strType.Equals("p"))
750 type = CEC_DEVICE_TYPE_PLAYBACK_DEVICE;
751 else if (strType.Equals("r"))
752 type = CEC_DEVICE_TYPE_RECORDING_DEVICE;
753 else if (strType.Equals("t"))
754 type = CEC_DEVICE_TYPE_TUNER;
755 cout << "device " << type << " is " << (parser->IsActiveDeviceType(type) ? "active" : "not active") << endl;
756 }
757 }
12027dbe
LOK
758 else if (command == "r")
759 {
25701fa6 760 cout << "closing the connection" << endl;
12027dbe 761 parser->Close();
d5f66c28 762 FlushLog(parser);
25701fa6
LOK
763
764 cout << "opening a new connection" << endl;
3d0dca16 765 parser->Open(g_strPort.c_str());
d5f66c28 766 FlushLog(parser);
25701fa6 767
18203d17
LOK
768 cout << "setting active source" << endl;
769 parser->SetActiveSource();
12027dbe 770 }
825ddb96
LOK
771 else if (command == "h" || command == "help")
772 {
d5f66c28 773 ShowHelpConsole();
825ddb96 774 }
abbca718
LOK
775 else if (command == "q" || command == "quit")
776 {
777 bContinue = false;
778 }
bdd433cb
LOK
779 else if (command == "log")
780 {
781 CStdString strLevel;
782 if (GetWord(input, strLevel))
783 {
784 int iNewLevel = atoi(strLevel);
785 if (iNewLevel >= CEC_LOG_ERROR && iNewLevel <= CEC_LOG_ALL)
786 {
787 g_cecLogLevel = iNewLevel;
788 cout << "log level changed to " << strLevel.c_str() << endl;
789 }
790 }
791 }
abbca718
LOK
792 }
793 if (bContinue)
794 cout << "waiting for input" << endl;
795 }
5ad0ea13
LOK
796
797 if (bContinue)
798 CCondition::Sleep(50);
abbca718
LOK
799 }
800
5ad0ea13
LOK
801 if (!bSingleCommand)
802 parser->StandbyDevices(CECDEVICE_BROADCAST);
803
5f39c4d8 804 parser->Close();
d5f66c28 805 FlushLog(parser);
abbca718 806 UnloadLibCec(parser);
e6d2161b
LOK
807
808 if (g_logOutput.is_open())
809 g_logOutput.close();
810
abbca718
LOK
811 return 0;
812}