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