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