7a60eb2c5a9e9673c899aad00816356459da482c
[deb_libcec.git] / src / testclient / main.cpp
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
33 #include <cec.h>
34
35 #include <cstdio>
36 #include <fcntl.h>
37 #include <iostream>
38 #include <fstream>
39 #include <string>
40 #include <sstream>
41 #include "../lib/platform/threads.h"
42 #include "../lib/util/StdString.h"
43
44 using namespace CEC;
45 using namespace std;
46
47 #define CEC_TEST_CLIENT_VERSION 1
48
49 #include <cecloader.h>
50
51 int g_cecLogLevel = CEC_LOG_ALL;
52 ofstream g_logOutput;
53 bool g_bShortLog = false;
54 CStdString g_strPort;
55
56 inline bool HexStrToInt(const std::string& data, uint8_t& value)
57 {
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;
67
68 return true;
69 }
70
71 return false;
72 }
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
108 void FlushLog(ICECAdapter *cecParser)
109 {
110 cec_log_message message;
111 while (cecParser && cecParser->GetNextLogMessage(&message))
112 {
113 if ((message.level & g_cecLogLevel) == message.level)
114 {
115 CStdString strLevel;
116 switch (message.level)
117 {
118 case CEC_LOG_ERROR:
119 strLevel = "ERROR: ";
120 break;
121 case CEC_LOG_WARNING:
122 strLevel = "WARNING: ";
123 break;
124 case CEC_LOG_NOTICE:
125 strLevel = "NOTICE: ";
126 break;
127 case CEC_LOG_TRAFFIC:
128 strLevel = "TRAFFIC: ";
129 break;
130 case CEC_LOG_DEBUG:
131 strLevel = "DEBUG: ";
132 break;
133 default:
134 break;
135 }
136
137 CStdString strFullLog;
138 strFullLog.Format("%s[%16lld]\t%s", strLevel.c_str(), message.time, message.message);
139 cout << strFullLog.c_str() << endl;
140
141 if (g_logOutput.is_open())
142 {
143 if (g_bShortLog)
144 g_logOutput << message.message << endl;
145 else
146 g_logOutput << strFullLog.c_str() << endl;
147 }
148 }
149 }
150 }
151
152 void ListDevices(ICECAdapter *parser)
153 {
154 cec_adapter *devices = new cec_adapter[10];
155 uint8_t iDevicesFound = parser->FindAdapters(devices, 10, NULL);
156 if (iDevicesFound <= 0)
157 {
158 cout << "Found devices: NONE" << endl;
159 }
160 else
161 {
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++)
166 {
167 CStdString strDevice;
168 strDevice.Format("device: %d\npath: %s\ncom port: %s", iDevicePtr + 1, devices[iDevicePtr].path, devices[iDevicePtr].comm);
169 cout << endl << strDevice.c_str() << endl;
170 }
171 }
172 }
173
174 void ShowHelpCommandLine(const char* strExec)
175 {
176 cout << endl <<
177 strExec << " {-h|--help|-l|--list-devices|[COM PORT]}" << endl <<
178 endl <<
179 "parameters:" << endl <<
180 " -h --help Shows this help text" << endl <<
181 " -l --list-devices List all devices on this system" << endl <<
182 " -t --type {p|r|t|a} The device type to use. More than one is possible." << endl <<
183 " -p --port {int} The HDMI port to use as active source." << endl <<
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 <<
187 " -d --log-level {level} Sets the log level. See cectypes.h for values." << endl <<
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 <<
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 <<
193 endl <<
194 "Type 'h' or 'help' and press enter after starting the client to display all " << endl <<
195 "available commands" << endl;
196 }
197
198 ICECAdapter *CreateParser(cec_device_type_list typeList)
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
218 void ShowHelpConsole(void)
219 {
220 cout << endl <<
221 "================================================================================" << endl <<
222 "Available commands:" << endl <<
223 endl <<
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 "[mon] {1|0} enable or disable CEC bus monitoring." << endl <<
241 "[log] {1 - 31} change the log level. see cectypes.h for values." << endl <<
242 "[ping] send a ping command to the CEC adapter." << endl <<
243 "[bl] to let the adapter enter the bootloader, to upgrade" << endl <<
244 " the flash rom." << endl <<
245 "[r] reconnect to the CEC adapter." << endl <<
246 "[h] or [help] show this help." << endl <<
247 "[q] or [quit] to quit the CEC test client and switch off all" << endl <<
248 " connected CEC devices." << endl <<
249 "================================================================================" << endl;
250 }
251
252 int main (int argc, char *argv[])
253 {
254 int8_t iHDMIPort(-1);
255 cec_device_type_list typeList;
256 typeList.clear();
257
258 int iArgPtr = 1;
259 bool bSingleCommand(false);
260 while (iArgPtr < argc)
261 {
262 if (argc >= iArgPtr + 1)
263 {
264 if (!strcmp(argv[iArgPtr], "-f") ||
265 !strcmp(argv[iArgPtr], "--log-file") ||
266 !strcmp(argv[iArgPtr], "-sf") ||
267 !strcmp(argv[iArgPtr], "--short-log-file"))
268 {
269 if (argc >= iArgPtr + 2)
270 {
271 g_logOutput.open(argv[iArgPtr + 1]);
272 g_bShortLog = (!strcmp(argv[iArgPtr], "-sf") || !strcmp(argv[iArgPtr], "--short-log-file"));
273 iArgPtr += 2;
274 }
275 else
276 {
277 cout << "== skipped log-file parameter: no file given ==" << endl;
278 ++iArgPtr;
279 }
280 }
281 else if (!strcmp(argv[iArgPtr], "-d") ||
282 !strcmp(argv[iArgPtr], "--log-level"))
283 {
284 if (argc >= iArgPtr + 2)
285 {
286 int iNewLevel = atoi(argv[iArgPtr + 1]);
287 if (iNewLevel >= CEC_LOG_ERROR && iNewLevel <= CEC_LOG_ALL)
288 {
289 g_cecLogLevel = iNewLevel;
290 if (!bSingleCommand)
291 cout << "log level set to " << argv[iArgPtr + 1] << endl;
292 }
293 else
294 {
295 cout << "== skipped log-level parameter: invalid level '" << argv[iArgPtr + 1] << "' ==" << endl;
296 }
297 iArgPtr += 2;
298 }
299 else
300 {
301 cout << "== skipped log-level parameter: no level given ==" << endl;
302 ++iArgPtr;
303 }
304 }
305 else if (!strcmp(argv[iArgPtr], "-t") ||
306 !strcmp(argv[iArgPtr], "--type"))
307 {
308 if (argc >= iArgPtr + 2)
309 {
310 if (!strcmp(argv[iArgPtr + 1], "p"))
311 {
312 if (!bSingleCommand)
313 cout << "== using device type 'playback device'" << endl;
314 typeList.add(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
315 }
316 else if (!strcmp(argv[iArgPtr + 1], "r"))
317 {
318 if (!bSingleCommand)
319 cout << "== using device type 'recording device'" << endl;
320 typeList.add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
321 }
322 else if (!strcmp(argv[iArgPtr + 1], "t"))
323 {
324 if (!bSingleCommand)
325 cout << "== using device type 'tuner'" << endl;
326 typeList.add(CEC_DEVICE_TYPE_TUNER);
327 }
328 else if (!strcmp(argv[iArgPtr + 1], "a"))
329 {
330 if (!bSingleCommand)
331 cout << "== using device type 'audio system'" << endl;
332 typeList.add(CEC_DEVICE_TYPE_AUDIO_SYSTEM);
333 }
334 else
335 {
336 cout << "== skipped invalid device type '" << argv[iArgPtr + 1] << "'" << endl;
337 }
338 ++iArgPtr;
339 }
340 ++iArgPtr;
341 }
342 else if (!strcmp(argv[iArgPtr], "--list-devices") ||
343 !strcmp(argv[iArgPtr], "-l"))
344 {
345 ICECAdapter *parser = CreateParser(typeList);
346 if (parser)
347 {
348 ListDevices(parser);
349 UnloadLibCec(parser);
350 }
351 return 0;
352 }
353 else if (!strcmp(argv[iArgPtr], "--single-command") ||
354 !strcmp(argv[iArgPtr], "-s"))
355 {
356 bSingleCommand = true;
357 ++iArgPtr;
358 }
359 else if (!strcmp(argv[iArgPtr], "--help") ||
360 !strcmp(argv[iArgPtr], "-h"))
361 {
362 ShowHelpCommandLine(argv[0]);
363 return 0;
364 }
365 else if (!strcmp(argv[iArgPtr], "-p") ||
366 !strcmp(argv[iArgPtr], "--port"))
367 {
368 if (argc >= iArgPtr + 2)
369 {
370 iHDMIPort= atoi(argv[iArgPtr + 1]);
371 cout << "using HDMI port '" << iHDMIPort << "'" << endl;
372 ++iArgPtr;
373 }
374 ++iArgPtr;
375 }
376 else
377 {
378 g_strPort = argv[iArgPtr++];
379 }
380 }
381 }
382
383 if (typeList.IsEmpty())
384 {
385 if (!bSingleCommand)
386 cout << "No device type given. Using 'recording device'" << endl;
387 typeList.add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
388 }
389
390 ICECAdapter *parser = LibCecInit("CECTester", typeList);
391 if (!parser || parser->GetMinLibVersion() > CEC_TEST_CLIENT_VERSION)
392 {
393 #ifdef __WINDOWS__
394 cout << "Cannot load libcec.dll" << endl;
395 #else
396 cout << "Cannot load libcec.so" << endl;
397 #endif
398 return 1;
399 }
400
401 if (!bSingleCommand)
402 {
403 CStdString strLog;
404 strLog.Format("CEC Parser created - libcec version %d.%d", parser->GetLibVersionMajor(), parser->GetLibVersionMinor());
405 cout << strLog.c_str() << endl;
406
407 //make stdin non-blocking
408 #ifndef __WINDOWS__
409 int flags = fcntl(0, F_GETFL, 0);
410 flags |= O_NONBLOCK;
411 fcntl(0, F_SETFL, flags);
412 #endif
413 }
414
415 if (g_strPort.IsEmpty())
416 {
417 if (!bSingleCommand)
418 cout << "no serial port given. trying autodetect: ";
419 cec_adapter devices[10];
420 uint8_t iDevicesFound = parser->FindAdapters(devices, 10, NULL);
421 if (iDevicesFound <= 0)
422 {
423 if (bSingleCommand)
424 cout << "autodetect ";
425 cout << "FAILED" << endl;
426 UnloadLibCec(parser);
427 return 1;
428 }
429 else
430 {
431 if (!bSingleCommand)
432 {
433 cout << endl << " path: " << devices[0].path << endl <<
434 " com port: " << devices[0].comm << endl << endl;
435 }
436 g_strPort = devices[0].comm;
437 }
438 }
439
440 if (iHDMIPort > 0)
441 {
442 parser->SetHDMIPort((uint8_t)iHDMIPort);
443 FlushLog(parser);
444 }
445
446 cout << "scanning the CEC bus..." << endl;
447
448 if (!parser->Open(g_strPort.c_str()))
449 {
450 cout << "unable to open the device on port " << g_strPort << endl;
451 FlushLog(parser);
452 UnloadLibCec(parser);
453 return 1;
454 }
455
456 if (!bSingleCommand)
457 {
458 cout << "cec device opened" << endl;
459
460 parser->PowerOnDevices(CECDEVICE_TV);
461 FlushLog(parser);
462
463 parser->SetActiveSource();
464 FlushLog(parser);
465
466 cout << "waiting for input" << endl;
467 }
468
469 bool bContinue(true);
470 while (bContinue)
471 {
472 if (bSingleCommand)
473 bContinue = false;
474
475 FlushLog(parser);
476
477 /* just ignore the command buffer and clear it */
478 cec_command dummy;
479 while (parser && parser->GetNextCommand(&dummy)) {}
480
481 string input;
482 getline(cin, input);
483 cin.clear();
484
485 if (!input.empty())
486 {
487 string command;
488 if (GetWord(input, command))
489 {
490 if (command == "tx" || command == "txn")
491 {
492 string strvalue;
493 uint8_t ivalue;
494 cec_command bytes;
495 bytes.Clear();
496
497 while (GetWord(input, strvalue) && HexStrToInt(strvalue, ivalue))
498 bytes.PushBack(ivalue);
499
500 if (command == "txn")
501 bytes.transmit_timeout = 0;
502
503 parser->Transmit(bytes);
504 }
505 else if (command == "on")
506 {
507 string strValue;
508 uint8_t iValue = 0;
509 if (GetWord(input, strValue) && HexStrToInt(strValue, iValue) && iValue <= 0xF)
510 {
511 parser->PowerOnDevices((cec_logical_address) iValue);
512 }
513 else
514 {
515 cout << "invalid destination" << endl;
516 }
517 }
518 else if (command == "standby")
519 {
520 string strValue;
521 uint8_t iValue = 0;
522 if (GetWord(input, strValue) && HexStrToInt(strValue, iValue) && iValue <= 0xF)
523 {
524 parser->StandbyDevices((cec_logical_address) iValue);
525 }
526 else
527 {
528 cout << "invalid destination" << endl;
529 }
530 }
531 else if (command == "poll")
532 {
533 string strValue;
534 uint8_t iValue = 0;
535 if (GetWord(input, strValue) && HexStrToInt(strValue, iValue) && iValue <= 0xF)
536 {
537 if (parser->PollDevice((cec_logical_address) iValue))
538 cout << "POLL message sent" << endl;
539 else
540 cout << "POLL message not sent" << endl;
541 }
542 else
543 {
544 cout << "invalid destination" << endl;
545 }
546 }
547 else if (command == "la")
548 {
549 string strvalue;
550 if (GetWord(input, strvalue))
551 {
552 parser->SetLogicalAddress((cec_logical_address) atoi(strvalue.c_str()));
553 }
554 }
555 else if (command == "p")
556 {
557 string strvalue;
558 if (GetWord(input, strvalue))
559 {
560 parser->SetHDMIPort(atoi(strvalue.c_str()));
561 }
562 }
563 else if (command == "pa")
564 {
565 string strB1, strB2;
566 uint8_t iB1, iB2;
567 if (GetWord(input, strB1) && HexStrToInt(strB1, iB1) &&
568 GetWord(input, strB2) && HexStrToInt(strB2, iB2))
569 {
570 uint16_t iPhysicalAddress = ((uint16_t)iB1 << 8) + iB2;
571 parser->SetPhysicalAddress(iPhysicalAddress);
572 }
573 }
574 else if (command == "osd")
575 {
576 bool bFirstWord(false);
577 string strAddr, strMessage, strWord;
578 uint8_t iAddr;
579 if (GetWord(input, strAddr) && HexStrToInt(strAddr, iAddr) && iAddr < 0xF)
580 {
581 while (GetWord(input, strWord))
582 {
583 if (bFirstWord)
584 {
585 bFirstWord = false;
586 strMessage.append(" ");
587 }
588 strMessage.append(strWord);
589 }
590 parser->SetOSDString((cec_logical_address) iAddr, CEC_DISPLAY_CONTROL_DISPLAY_FOR_DEFAULT_TIME, strMessage.c_str());
591 }
592 }
593 else if (command == "ping")
594 {
595 parser->PingAdapter();
596 }
597 else if (command == "mon")
598 {
599 CStdString strEnable;
600 if (GetWord(input, strEnable) && (strEnable.Equals("0") || strEnable.Equals("1")))
601 {
602 parser->SwitchMonitoring(strEnable.Equals("1"));
603 }
604 }
605 else if (command == "bl")
606 {
607 parser->StartBootloader();
608 }
609 else if (command == "lang")
610 {
611 CStdString strDev;
612 if (GetWord(input, strDev))
613 {
614 int iDev = atoi(strDev);
615 if (iDev >= 0 && iDev < 15)
616 {
617 CStdString strLog;
618 cec_menu_language language;
619 if (parser->GetDeviceMenuLanguage((cec_logical_address) iDev, &language))
620 strLog.Format("menu language '%s'", language.language);
621 else
622 strLog = "failed!";
623 cout << strLog.c_str() << endl;
624 }
625 }
626 }
627 else if (command == "ven")
628 {
629 CStdString strDev;
630 if (GetWord(input, strDev))
631 {
632 int iDev = atoi(strDev);
633 if (iDev >= 0 && iDev < 15)
634 {
635 uint64_t iVendor = parser->GetDeviceVendorId((cec_logical_address) iDev);
636 CStdString strLog;
637 strLog.Format("vendor id: %06x", iVendor);
638 cout << strLog.c_str() << endl;
639 }
640 }
641 }
642 else if (command == "ver")
643 {
644 CStdString strDev;
645 if (GetWord(input, strDev))
646 {
647 int iDev = atoi(strDev);
648 if (iDev >= 0 && iDev < 15)
649 {
650 cec_version iVersion = parser->GetDeviceCecVersion((cec_logical_address) iDev);
651 switch (iVersion)
652 {
653 case CEC_VERSION_1_2:
654 cout << "CEC version 1.2" << endl;
655 break;
656 case CEC_VERSION_1_2A:
657 cout << "CEC version 1.2a" << endl;
658 break;
659 case CEC_VERSION_1_3:
660 cout << "CEC version 1.3" << endl;
661 break;
662 case CEC_VERSION_1_3A:
663 cout << "CEC version 1.3a" << endl;
664 break;
665 default:
666 cout << "unknown CEC version" << endl;
667 break;
668 }
669 }
670 }
671 }
672 else if (command == "pow")
673 {
674 CStdString strDev;
675 if (GetWord(input, strDev))
676 {
677 int iDev = atoi(strDev);
678 if (iDev >= 0 && iDev < 15)
679 {
680 cec_power_status iPower = parser->GetDevicePowerStatus((cec_logical_address) iDev);
681 switch (iPower)
682 {
683 case CEC_POWER_STATUS_ON:
684 cout << "powered on" << endl;
685 break;
686 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
687 cout << "on -> standby" << endl;
688 break;
689 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
690 cout << "standby -> on" << endl;
691 break;
692 case CEC_POWER_STATUS_STANDBY:
693 cout << "standby" << endl;
694 break;
695 default:
696 cout << "unknown power status" << endl;
697 break;
698 }
699 }
700 }
701 }
702 else if (command == "lad")
703 {
704 cout << "listing active devices:" << endl;
705 cec_logical_addresses addresses = parser->GetActiveDevices();
706 for (unsigned iPtr = 0; iPtr < 16; iPtr++)
707 if (addresses[iPtr])
708 cout << "logical address " << iPtr << endl;
709 }
710 else if (command == "ad")
711 {
712 CStdString strDev;
713 if (GetWord(input, strDev))
714 {
715 int iDev = atoi(strDev);
716 if (iDev >= 0 && iDev < 15)
717 cout << "logical address " << iDev << " is " << (parser->IsActiveDevice((cec_logical_address)iDev) ? "active" : "not active") << endl;
718 }
719 }
720 else if (command == "at")
721 {
722 CStdString strType;
723 if (GetWord(input, strType))
724 {
725 cec_device_type type = CEC_DEVICE_TYPE_TV;
726 if (strType.Equals("a"))
727 type = CEC_DEVICE_TYPE_AUDIO_SYSTEM;
728 else if (strType.Equals("p"))
729 type = CEC_DEVICE_TYPE_PLAYBACK_DEVICE;
730 else if (strType.Equals("r"))
731 type = CEC_DEVICE_TYPE_RECORDING_DEVICE;
732 else if (strType.Equals("t"))
733 type = CEC_DEVICE_TYPE_TUNER;
734 cout << "device " << type << " is " << (parser->IsActiveDeviceType(type) ? "active" : "not active") << endl;
735 }
736 }
737 else if (command == "r")
738 {
739 cout << "closing the connection" << endl;
740 parser->Close();
741 FlushLog(parser);
742
743 cout << "opening a new connection" << endl;
744 parser->Open(g_strPort.c_str());
745 FlushLog(parser);
746
747 cout << "setting active source" << endl;
748 parser->SetActiveSource();
749 }
750 else if (command == "h" || command == "help")
751 {
752 ShowHelpConsole();
753 }
754 else if (command == "q" || command == "quit")
755 {
756 bContinue = false;
757 }
758 else if (command == "log")
759 {
760 CStdString strLevel;
761 if (GetWord(input, strLevel))
762 {
763 int iNewLevel = atoi(strLevel);
764 if (iNewLevel >= CEC_LOG_ERROR && iNewLevel <= CEC_LOG_ALL)
765 {
766 g_cecLogLevel = iNewLevel;
767 cout << "log level changed to " << strLevel.c_str() << endl;
768 }
769 }
770 }
771 }
772 if (bContinue)
773 cout << "waiting for input" << endl;
774 }
775
776 if (bContinue)
777 CCondition::Sleep(50);
778 }
779
780 if (!bSingleCommand)
781 parser->StandbyDevices(CECDEVICE_BROADCAST);
782
783 parser->Close();
784 FlushLog(parser);
785 UnloadLibCec(parser);
786
787 if (g_logOutput.is_open())
788 g_logOutput.close();
789
790 return 0;
791 }