cec: added some more audio related opcode handling. added TransmitVendorId(), but...
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.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 "CECCommandHandler.h"
34 #include "../devices/CECBusDevice.h"
35 #include "../devices/CECAudioSystem.h"
36 #include "../devices/CECPlaybackDevice.h"
37 #include "../CECProcessor.h"
38
39 using namespace CEC;
40 using namespace std;
41
42 CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice)
43 {
44 m_busDevice = busDevice;
45 }
46
47 bool CCECCommandHandler::HandleCommand(const cec_command &command)
48 {
49 bool bHandled(true);
50
51 CStdString strLog;
52 strLog.Format(">> %s (%X) -> %s (%X): %s (%2X)", ToString(command.initiator), command.initiator, ToString(command.destination), command.destination, ToString(command.opcode), command.opcode);
53 m_busDevice->AddLog(CEC_LOG_NOTICE, strLog);
54
55 if (m_busDevice->MyLogicalAddressContains(command.destination))
56 {
57 switch(command.opcode)
58 {
59 case CEC_OPCODE_REPORT_POWER_STATUS:
60 HandleReportPowerStatus(command);
61 break;
62 case CEC_OPCODE_CEC_VERSION:
63 HandleDeviceCecVersion(command);
64 break;
65 case CEC_OPCODE_SET_MENU_LANGUAGE:
66 HandleSetMenuLanguage(command);
67 /* pass to listeners */
68 m_busDevice->GetProcessor()->AddCommand(command);
69 break;
70 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
71 HandleGivePhysicalAddress(command);
72 break;
73 case CEC_OPCODE_GIVE_OSD_NAME:
74 HandleGiveOSDName(command);
75 break;
76 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
77 HandleGiveDeviceVendorId(command);
78 break;
79 case CEC_OPCODE_DEVICE_VENDOR_ID:
80 HandleDeviceVendorId(command);
81 break;
82 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
83 HandleDeviceVendorCommandWithId(command);
84 break;
85 case CEC_OPCODE_GIVE_DECK_STATUS:
86 HandleGiveDeckStatus(command);
87 break;
88 case CEC_OPCODE_DECK_CONTROL:
89 HandleDeckControl(command);
90 break;
91 case CEC_OPCODE_MENU_REQUEST:
92 HandleMenuRequest(command);
93 break;
94 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
95 HandleGiveDevicePowerStatus(command);
96 break;
97 case CEC_OPCODE_GET_CEC_VERSION:
98 HandleGetCecVersion(command);
99 break;
100 case CEC_OPCODE_USER_CONTROL_PRESSED:
101 HandleUserControlPressed(command);
102 break;
103 case CEC_OPCODE_USER_CONTROL_RELEASE:
104 HandleUserControlRelease(command);
105 break;
106 case CEC_OPCODE_GIVE_AUDIO_STATUS:
107 HandleGiveAudioStatus(command);
108 break;
109 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
110 HandleGiveSystemAudioModeStatus(command);
111 break;
112 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
113 HandleSetSystemAudioModeRequest(command);
114 break;
115 default:
116 UnhandledCommand(command);
117 /* pass to listeners */
118 m_busDevice->GetProcessor()->AddCommand(command);
119 bHandled = false;
120 break;
121 }
122 }
123 else if (command.destination == CECDEVICE_BROADCAST)
124 {
125 CStdString strLog;
126 switch (command.opcode)
127 {
128 case CEC_OPCODE_SET_MENU_LANGUAGE:
129 HandleSetMenuLanguage(command);
130 /* pass to listeners */
131 m_busDevice->GetProcessor()->AddCommand(command);
132 break;
133 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
134 HandleRequestActiveSource(command);
135 break;
136 case CEC_OPCODE_SET_STREAM_PATH:
137 HandleSetStreamPath(command);
138 break;
139 case CEC_OPCODE_ROUTING_CHANGE:
140 HandleRoutingChange(command);
141 break;
142 case CEC_OPCODE_DEVICE_VENDOR_ID:
143 HandleDeviceVendorId(command);
144 break;
145 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
146 HandleDeviceVendorCommandWithId(command);
147 break;
148 case CEC_OPCODE_STANDBY:
149 HandleStandby(command);
150 /* pass to listeners */
151 m_busDevice->GetProcessor()->AddCommand(command);
152 break;
153 case CEC_OPCODE_ACTIVE_SOURCE:
154 HandleActiveSource(command);
155 /* pass to listeners */
156 m_busDevice->GetProcessor()->AddCommand(command);
157 break;
158 default:
159 UnhandledCommand(command);
160 /* pass to listeners */
161 m_busDevice->GetProcessor()->AddCommand(command);
162 bHandled = false;
163 break;
164 }
165 }
166 else
167 {
168 CStdString strLog;
169 strLog.Format("ignoring frame: we're not at destination %x", command.destination);
170 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
171 bHandled = false;
172 }
173
174 return bHandled;
175 }
176
177 bool CCECCommandHandler::HandleActiveSource(const cec_command &command)
178 {
179 if (command.parameters.size == 2)
180 {
181 uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
182 return m_busDevice->GetProcessor()->SetStreamPath(iAddress);
183 }
184
185 return true;
186 }
187
188 bool CCECCommandHandler::HandleDeckControl(const cec_command &command)
189 {
190 CCECBusDevice *device = GetDevice(command.destination);
191 if (device && device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE && command.parameters.size > 0)
192 {
193 ((CCECPlaybackDevice *) device)->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]);
194 return true;
195 }
196
197 return false;
198 }
199
200 bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command)
201 {
202 if (command.parameters.size == 1)
203 {
204 CCECBusDevice *device = GetDevice(command.initiator);
205 if (device)
206 device->SetCecVersion((cec_version) command.parameters[0]);
207 }
208
209 return true;
210 }
211
212 bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
213 {
214 SetVendorId(command);
215 m_busDevice->GetProcessor()->TransmitAbort(command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED);
216 return true;
217 }
218
219 bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command)
220 {
221 SetVendorId(command);
222 return true;
223 }
224
225 bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command)
226 {
227 CCECBusDevice *device = GetDevice(command.destination);
228 if (device)
229 return device->TransmitCECVersion(command.initiator);
230
231 return false;
232 }
233
234 bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command)
235 {
236 CCECBusDevice *device = GetDevice(command.destination);
237 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
238 return ((CCECAudioSystem *) device)->TransmitAudioStatus(command.initiator);
239
240 return false;
241 }
242
243 bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command)
244 {
245 CCECBusDevice *device = GetDevice(command.destination);
246 if (device && device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
247 return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator);
248
249 return false;
250 }
251
252 bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command)
253 {
254 CCECBusDevice *device = GetDevice(command.destination);
255 if (device)
256 return device->TransmitPowerState(command.initiator);
257
258 return false;
259 }
260
261 bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command)
262 {
263 CCECBusDevice *device = GetDevice(command.destination);
264 if (device)
265 return device->TransmitVendorID(command.initiator);
266
267 return false;
268 }
269
270 bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command)
271 {
272 CCECBusDevice *device = GetDevice(command.destination);
273 if (device)
274 return device->TransmitOSDName(command.initiator);
275
276 return false;
277 }
278
279 bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
280 {
281 CCECBusDevice *device = GetDevice(command.destination);
282 if (device)
283 return device->TransmitPhysicalAddress();
284
285 return false;
286 }
287
288 bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
289 {
290 if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_QUERY)
291 {
292 CCECBusDevice *device = GetDevice(command.destination);
293 if (device)
294 return device->TransmitMenuState(command.initiator);
295 }
296 return false;
297 }
298
299 bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command)
300 {
301 if (command.parameters.size == 1)
302 {
303 CCECBusDevice *device = GetDevice(command.initiator);
304 if (device)
305 device->SetPowerStatus((cec_power_status) command.parameters[0]);
306 }
307 return true;
308 }
309
310 bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command)
311 {
312 CStdString strLog;
313 strLog.Format(">> %i requests active source", (uint8_t) command.initiator);
314 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
315
316 vector<CCECBusDevice *> devices;
317 for (int iDevicePtr = (int)GetMyDevices(devices)-1; iDevicePtr >=0; iDevicePtr--)
318 devices[iDevicePtr]->TransmitActiveSource();
319
320 return true;
321 }
322
323 bool CCECCommandHandler::HandleRoutingChange(const cec_command &command)
324 {
325 if (command.parameters.size == 4)
326 {
327 uint16_t iOldAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
328 uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]);
329
330 CCECBusDevice *device = GetDevice(command.initiator);
331 if (device)
332 device->SetStreamPath(iNewAddress, iOldAddress);
333 }
334 return true;
335 }
336
337 bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command)
338 {
339 if (command.parameters.size == 3)
340 {
341 CCECBusDevice *device = GetDevice(command.initiator);
342 if (device)
343 {
344 cec_menu_language language;
345 language.device = command.initiator;
346 for (uint8_t iPtr = 0; iPtr < 4; iPtr++)
347 language.language[iPtr] = command.parameters[iPtr];
348 language.language[3] = 0;
349 device->SetMenuLanguage(language);
350 }
351 }
352 return true;
353 }
354
355 bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
356 {
357 if (command.parameters.size >= 2)
358 {
359 uint16_t streamaddr = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
360 CStdString strLog;
361 strLog.Format(">> %i sets stream path to physical address %04x", command.initiator, streamaddr);
362 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
363
364 return m_busDevice->GetProcessor()->SetStreamPath(streamaddr);
365 }
366 return true;
367 }
368
369 bool CCECCommandHandler::HandleSetSystemAudioModeRequest(const cec_command &command)
370 {
371 if (command.parameters.size >= 1)
372 {
373 CCECBusDevice *device = GetDevice(command.destination);
374 if (device&& device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
375 return ((CCECAudioSystem *) device)->SetSystemAudioMode(command);
376 }
377 return true;
378 }
379
380 bool CCECCommandHandler::HandleStandby(const cec_command &command)
381 {
382 CCECBusDevice *device = GetDevice(command.initiator);
383 if (device)
384 device->SetPowerStatus(CEC_POWER_STATUS_STANDBY);
385 return true;
386 }
387
388 bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command)
389 {
390 CCECBusDevice *device = GetDevice(command.destination);
391 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
392 return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator);
393
394 return false;
395 }
396
397 bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
398 {
399 if (command.parameters.size > 0)
400 {
401 m_busDevice->GetProcessor()->AddKey();
402
403 if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX)
404 {
405 CStdString strLog;
406 strLog.Format("key pressed: %x", command.parameters[0]);
407 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
408
409 if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER ||
410 command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION)
411 {
412 CCECBusDevice *device = GetDevice(command.destination);
413 if (device)
414 device->SetPowerStatus(CEC_POWER_STATUS_ON);
415 }
416
417 m_busDevice->GetProcessor()->SetCurrentButton((cec_user_control_code) command.parameters[0]);
418 }
419 }
420 return true;
421 }
422
423 bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command)
424 {
425 m_busDevice->GetProcessor()->AddKey();
426 return true;
427 }
428
429 void CCECCommandHandler::UnhandledCommand(const cec_command &command)
430 {
431 CStdString strLog;
432 strLog.Format("unhandled command with opcode %02x from address %d", command.opcode, command.initiator);
433 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog);
434 }
435
436 unsigned int CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
437 {
438 unsigned int iReturn(0);
439
440 cec_logical_addresses addresses = m_busDevice->GetProcessor()->GetLogicalAddresses();
441 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
442 {
443 if (addresses[iPtr])
444 {
445 devices.push_back(GetDevice((cec_logical_address) iPtr));
446 ++iReturn;
447 }
448 }
449
450 return iReturn;
451 }
452
453 CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress) const
454 {
455 CCECBusDevice *device = NULL;
456
457 if (iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST)
458 device = m_busDevice->GetProcessor()->m_busDevices[iLogicalAddress];
459
460 return device;
461 }
462
463 CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
464 {
465 return m_busDevice->GetProcessor()->GetDeviceByPhysicalAddress(iPhysicalAddress);
466 }
467
468 CCECBusDevice *CCECCommandHandler::GetDeviceByType(cec_device_type type) const
469 {
470 return m_busDevice->GetProcessor()->GetDeviceByType(type);
471 }
472
473 void CCECCommandHandler::SetVendorId(const cec_command &command)
474 {
475 if (command.parameters.size < 3)
476 {
477 m_busDevice->AddLog(CEC_LOG_WARNING, "invalid vendor ID received");
478 return;
479 }
480
481 uint64_t iVendorId = ((uint64_t)command.parameters[0] << 16) +
482 ((uint64_t)command.parameters[1] << 8) +
483 (uint64_t)command.parameters[2];
484
485 CCECBusDevice *device = GetDevice((cec_logical_address) command.initiator);
486 if (device)
487 device->SetVendorId(iVendorId);
488 }
489
490 const char *CCECCommandHandler::ToString(const cec_version version)
491 {
492 switch (version)
493 {
494 case CEC_VERSION_1_2:
495 return "1.2";
496 case CEC_VERSION_1_2A:
497 return "1.2a";
498 case CEC_VERSION_1_3:
499 return "1.3";
500 case CEC_VERSION_1_3A:
501 return "1.3a";
502 case CEC_VERSION_1_4:
503 return "1.4";
504 default:
505 return "unknown";
506 }
507 }
508
509 const char *CCECCommandHandler::ToString(const cec_power_status status)
510 {
511 switch (status)
512 {
513 case CEC_POWER_STATUS_ON:
514 return "on";
515 case CEC_POWER_STATUS_STANDBY:
516 return "standby";
517 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
518 return "in transition from on to standby";
519 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
520 return "in transition from standby to on";
521 default:
522 return "unknown";
523 }
524 }
525
526 const char *CCECCommandHandler::ToString(const cec_logical_address address)
527 {
528 switch(address)
529 {
530 case CECDEVICE_AUDIOSYSTEM:
531 return "Audio";
532 case CECDEVICE_BROADCAST:
533 return "Broadcast";
534 case CECDEVICE_FREEUSE:
535 return "Free use";
536 case CECDEVICE_PLAYBACKDEVICE1:
537 return "Playback 1";
538 case CECDEVICE_PLAYBACKDEVICE2:
539 return "Playback 2";
540 case CECDEVICE_PLAYBACKDEVICE3:
541 return "Playback 3";
542 case CECDEVICE_RECORDINGDEVICE1:
543 return "Recorder 1";
544 case CECDEVICE_RECORDINGDEVICE2:
545 return "Recorder 2";
546 case CECDEVICE_RECORDINGDEVICE3:
547 return "Recorder 3";
548 case CECDEVICE_RESERVED1:
549 return "Reserved 1";
550 case CECDEVICE_RESERVED2:
551 return "Reserved 2";
552 case CECDEVICE_TUNER1:
553 return "Tuner 1";
554 case CECDEVICE_TUNER2:
555 return "Tuner 2";
556 case CECDEVICE_TUNER3:
557 return "Tuner 3";
558 case CECDEVICE_TUNER4:
559 return "Tuner 4";
560 case CECDEVICE_TV:
561 return "TV";
562 default:
563 return "unknown";
564 }
565 }
566
567 const char *CCECCommandHandler::ToString(const cec_deck_control_mode mode)
568 {
569 switch (mode)
570 {
571 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND:
572 return "skip forward wind";
573 case CEC_DECK_CONTROL_MODE_EJECT:
574 return "eject";
575 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND:
576 return "reverse rewind";
577 case CEC_DECK_CONTROL_MODE_STOP:
578 return "stop";
579 default:
580 return "unknown";
581 }
582 }
583
584 const char *CCECCommandHandler::ToString(const cec_deck_info status)
585 {
586 switch (status)
587 {
588 case CEC_DECK_INFO_PLAY:
589 return "play";
590 case CEC_DECK_INFO_RECORD:
591 return "record";
592 case CEC_DECK_INFO_PLAY_REVERSE:
593 return "play reverse";
594 case CEC_DECK_INFO_STILL:
595 return "still";
596 case CEC_DECK_INFO_SLOW:
597 return "slow";
598 case CEC_DECK_INFO_SLOW_REVERSE:
599 return "slow reverse";
600 case CEC_DECK_INFO_FAST_FORWARD:
601 return "fast forward";
602 case CEC_DECK_INFO_FAST_REVERSE:
603 return "fast reverse";
604 case CEC_DECK_INFO_NO_MEDIA:
605 return "no media";
606 case CEC_DECK_INFO_STOP:
607 return "stop";
608 case CEC_DECK_INFO_SKIP_FORWARD_WIND:
609 return "info skip forward wind";
610 case CEC_DECK_INFO_SKIP_REVERSE_REWIND:
611 return "info skip reverse rewind";
612 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD:
613 return "info index search forward";
614 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE:
615 return "info index search reverse";
616 case CEC_DECK_INFO_OTHER_STATUS:
617 return "other";
618 default:
619 return "unknown";
620 }
621 }
622
623 const char *CCECCommandHandler::ToString(const cec_opcode opcode)
624 {
625 switch (opcode)
626 {
627 case CEC_OPCODE_ACTIVE_SOURCE:
628 return "active source";
629 case CEC_OPCODE_IMAGE_VIEW_ON:
630 return "image view on";
631 case CEC_OPCODE_TEXT_VIEW_ON:
632 return "text view on";
633 case CEC_OPCODE_INACTIVE_SOURCE:
634 return "inactive source";
635 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
636 return "request active source";
637 case CEC_OPCODE_ROUTING_CHANGE:
638 return "routing change";
639 case CEC_OPCODE_ROUTING_INFORMATION:
640 return "routing information";
641 case CEC_OPCODE_SET_STREAM_PATH:
642 return "set stream path";
643 case CEC_OPCODE_STANDBY:
644 return "standby";
645 case CEC_OPCODE_RECORD_OFF:
646 return "record off";
647 case CEC_OPCODE_RECORD_ON:
648 return "record on";
649 case CEC_OPCODE_RECORD_STATUS:
650 return "record status";
651 case CEC_OPCODE_RECORD_TV_SCREEN:
652 return "record tv screen";
653 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER:
654 return "clear analogue timer";
655 case CEC_OPCODE_CLEAR_DIGITAL_TIMER:
656 return "clear digital timer";
657 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER:
658 return "clear external timer";
659 case CEC_OPCODE_SET_ANALOGUE_TIMER:
660 return "set analogue timer";
661 case CEC_OPCODE_SET_DIGITAL_TIMER:
662 return "set digital timer";
663 case CEC_OPCODE_SET_EXTERNAL_TIMER:
664 return "set external timer";
665 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE:
666 return "set timer program title";
667 case CEC_OPCODE_TIMER_CLEARED_STATUS:
668 return "timer cleared status";
669 case CEC_OPCODE_TIMER_STATUS:
670 return "timer status";
671 case CEC_OPCODE_CEC_VERSION:
672 return "cec version";
673 case CEC_OPCODE_GET_CEC_VERSION:
674 return "get cec version";
675 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
676 return "give physical address";
677 case CEC_OPCODE_GET_MENU_LANGUAGE:
678 return "get menu language";
679 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
680 return "report physical address";
681 case CEC_OPCODE_SET_MENU_LANGUAGE:
682 return "set menu language";
683 case CEC_OPCODE_DECK_CONTROL:
684 return "deck control";
685 case CEC_OPCODE_DECK_STATUS:
686 return "deck status";
687 case CEC_OPCODE_GIVE_DECK_STATUS:
688 return "give deck status";
689 case CEC_OPCODE_PLAY:
690 return "play";
691 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS:
692 return "give tuner status";
693 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE:
694 return "select analogue service";
695 case CEC_OPCODE_SELECT_DIGITAL_SERVICE:
696 return "set digital service";
697 case CEC_OPCODE_TUNER_DEVICE_STATUS:
698 return "tuner device status";
699 case CEC_OPCODE_TUNER_STEP_DECREMENT:
700 return "tuner step decrement";
701 case CEC_OPCODE_TUNER_STEP_INCREMENT:
702 return "tuner step increment";
703 case CEC_OPCODE_DEVICE_VENDOR_ID:
704 return "device vendor id";
705 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
706 return "give device vendor id";
707 case CEC_OPCODE_VENDOR_COMMAND:
708 return "vendor command";
709 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
710 return "vendor command with id";
711 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN:
712 return "vendor remote button down";
713 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP:
714 return "vendor remote button up";
715 case CEC_OPCODE_SET_OSD_STRING:
716 return "set osd string";
717 case CEC_OPCODE_GIVE_OSD_NAME:
718 return "give osd name";
719 case CEC_OPCODE_SET_OSD_NAME:
720 return "set osd name";
721 case CEC_OPCODE_MENU_REQUEST:
722 return "menu request";
723 case CEC_OPCODE_MENU_STATUS:
724 return "menu status";
725 case CEC_OPCODE_USER_CONTROL_PRESSED:
726 return "user control pressed";
727 case CEC_OPCODE_USER_CONTROL_RELEASE:
728 return "user control release";
729 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
730 return "give device power status";
731 case CEC_OPCODE_REPORT_POWER_STATUS:
732 return "report power status";
733 case CEC_OPCODE_FEATURE_ABORT:
734 return "feature abort";
735 case CEC_OPCODE_ABORT:
736 return "abort";
737 case CEC_OPCODE_GIVE_AUDIO_STATUS:
738 return "give audio status";
739 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
740 return "give audio mode status";
741 case CEC_OPCODE_REPORT_AUDIO_STATUS:
742 return "report audio status";
743 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE:
744 return "set system audio mode";
745 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
746 return "system audio mode request";
747 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS:
748 return "system audio mode status";
749 case CEC_OPCODE_SET_AUDIO_RATE:
750 return "set audio rate";
751 default:
752 return "UNKNOWN";
753 }
754 }
755
756 const char *CCECCommandHandler::ToString(const cec_system_audio_status mode)
757 {
758 switch(mode)
759 {
760 case CEC_SYSTEM_AUDIO_STATUS_ON:
761 return "on";
762 case CEC_SYSTEM_AUDIO_STATUS_OFF:
763 return "off";
764 default:
765 return "unknown";
766 }
767 }
768
769 const char *CCECCommandHandler::ToString(const cec_audio_status status)
770 {
771 // TODO this is a mask
772 return "TODO";
773 }
774
775 const char *CCECCommandHandler::ToString(const cec_vendor_id vendor)
776 {
777 switch (vendor)
778 {
779 case CEC_VENDOR_SAMSUNG:
780 return "Samsung";
781 case CEC_VENDOR_LG:
782 return "LG";
783 case CEC_VENDOR_PANASONIC:
784 return "Panasonic";
785 case CEC_VENDOR_PIONEER:
786 return "Pioneer";
787 default:
788 return "Unknown";
789 }
790 }