cec: fixed - report physical address sends 3 parameters, not 2. check whether the...
[deb_libcec.git] / src / lib / implementations / CECCommandHandler.cpp
CommitLineData
e9de9629
LOK
1/*
2 * This file is part of the libCEC(R) library.
3 *
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
6 *
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
8 *
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 *
23 *
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
26 *
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
31 */
32
33#include "CECCommandHandler.h"
eafa9d46 34#include "../devices/CECBusDevice.h"
a1f8fb1b 35#include "../devices/CECAudioSystem.h"
28089abc 36#include "../devices/CECPlaybackDevice.h"
387b6f6f 37#include "../CECProcessor.h"
e9de9629
LOK
38
39using namespace CEC;
8747dd4f 40using namespace std;
e9de9629
LOK
41
42CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice)
43{
44 m_busDevice = busDevice;
45}
46
47bool CCECCommandHandler::HandleCommand(const cec_command &command)
48{
49 bool bHandled(true);
50
5e822b09 51 CStdString strLog;
62f5527d 52 strLog.Format(">> %s (%X) -> %s (%X): %s (%2X)", ToString(command.initiator), command.initiator, ToString(command.destination), command.destination, ToString(command.opcode), command.opcode);
5e822b09
LOK
53 m_busDevice->AddLog(CEC_LOG_NOTICE, strLog);
54
6b72afcd 55 switch(command.opcode)
e9de9629 56 {
6b72afcd
LOK
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;
907bd60f
LOK
120 case CEC_OPCODE_ROUTING_INFORMATION:
121 HandleRoutingInformation(command);
122 break;
6b72afcd
LOK
123 case CEC_OPCODE_STANDBY:
124 HandleStandby(command);
125 break;
126 case CEC_OPCODE_ACTIVE_SOURCE:
127 HandleActiveSource(command);
128 break;
907bd60f
LOK
129 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
130 HandleReportPhysicalAddress(command);
131 break;
6b72afcd
LOK
132 default:
133 UnhandledCommand(command);
134 if (command.destination == CECDEVICE_BROADCAST || m_busDevice->MyLogicalAddressContains(command.destination))
be5b0e24 135 m_busDevice->GetProcessor()->AddCommand(command);
e9de9629 136 bHandled = false;
6b72afcd 137 break;
e9de9629
LOK
138 }
139
140 return bHandled;
141}
142
be5b0e24
LOK
143bool CCECCommandHandler::HandleActiveSource(const cec_command &command)
144{
145 if (command.parameters.size == 2)
146 {
6b72afcd
LOK
147 m_busDevice->GetProcessor()->AddCommand(command);
148
be5b0e24
LOK
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
a9232a79
LOK
156bool CCECCommandHandler::HandleDeckControl(const cec_command &command)
157{
158 CCECBusDevice *device = GetDevice(command.destination);
88e5de6f 159 if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) && command.parameters.size > 0)
a9232a79 160 {
6b72afcd
LOK
161 m_busDevice->GetProcessor()->AddCommand(command);
162
a9232a79
LOK
163 ((CCECPlaybackDevice *) device)->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]);
164 return true;
165 }
166
167 return false;
168}
169
6a1c0009
LOK
170bool 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
e9de9629
LOK
182bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command)
183{
6b72afcd
LOK
184 if (m_busDevice->MyLogicalAddressContains(command.destination))
185 m_busDevice->GetProcessor()->TransmitAbort(command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED);
186
6a1c0009 187 return true;
e9de9629
LOK
188}
189
190bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command)
191{
181b3475 192 SetVendorId(command);
6a1c0009 193 return true;
e9de9629
LOK
194}
195
196bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command)
197{
6b72afcd
LOK
198 if (m_busDevice->MyLogicalAddressContains(command.destination))
199 {
200 CCECBusDevice *device = GetDevice(command.destination);
201 if (device)
202 return device->TransmitCECVersion(command.initiator);
203 }
0f23c85c
LOK
204
205 return false;
e9de9629
LOK
206}
207
a1f8fb1b
LOK
208bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command)
209{
6b72afcd
LOK
210 if (m_busDevice->MyLogicalAddressContains(command.destination))
211 {
212 CCECBusDevice *device = GetDevice(command.destination);
213 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
214 return ((CCECAudioSystem *) device)->TransmitAudioStatus(command.initiator);
215 }
a1f8fb1b
LOK
216
217 return false;
218}
219
e9de9629
LOK
220bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command)
221{
6b72afcd
LOK
222 if (m_busDevice->MyLogicalAddressContains(command.destination))
223 {
224 CCECBusDevice *device = GetDevice(command.destination);
225 if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE))
226 return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator);
227 }
0f23c85c
LOK
228
229 return false;
e9de9629
LOK
230}
231
232bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command)
233{
6b72afcd
LOK
234 if (m_busDevice->MyLogicalAddressContains(command.destination))
235 {
236 CCECBusDevice *device = GetDevice(command.destination);
237 if (device)
238 return device->TransmitPowerState(command.initiator);
239 }
0f23c85c
LOK
240
241 return false;
e9de9629
LOK
242}
243
244bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command)
245{
6b72afcd
LOK
246 if (m_busDevice->MyLogicalAddressContains(command.destination))
247 {
248 CCECBusDevice *device = GetDevice(command.destination);
249 if (device)
250 return device->TransmitVendorID(command.initiator);
251 }
0f23c85c
LOK
252
253 return false;
e9de9629
LOK
254}
255
256bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command)
257{
6b72afcd
LOK
258 if (m_busDevice->MyLogicalAddressContains(command.destination))
259 {
260 CCECBusDevice *device = GetDevice(command.destination);
261 if (device)
262 return device->TransmitOSDName(command.initiator);
263 }
0f23c85c
LOK
264
265 return false;
e9de9629
LOK
266}
267
268bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command)
269{
6b72afcd
LOK
270 if (m_busDevice->MyLogicalAddressContains(command.destination))
271 {
272 CCECBusDevice *device = GetDevice(command.destination);
273 if (device)
274 return device->TransmitPhysicalAddress();
275 }
09c10b66
LOK
276
277 return false;
e9de9629
LOK
278}
279
280bool CCECCommandHandler::HandleMenuRequest(const cec_command &command)
281{
6b72afcd 282 if (m_busDevice->MyLogicalAddressContains(command.destination))
0f23c85c 283 {
6b72afcd
LOK
284 if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_QUERY)
285 {
286 CCECBusDevice *device = GetDevice(command.destination);
287 if (device)
288 return device->TransmitMenuState(command.initiator);
289 }
290 else
291 {
292 m_busDevice->GetProcessor()->AddCommand(command);
293 }
0f23c85c 294 }
6b72afcd 295
0f23c85c 296 return false;
e9de9629
LOK
297}
298
907bd60f
LOK
299bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command)
300{
0bfce006 301 if (command.parameters.size == 3)
907bd60f
LOK
302 {
303 uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
0bfce006 304 cec_device_type type = (cec_device_type)command.parameters[2];
907bd60f
LOK
305
306 CCECBusDevice *device = GetDevice(command.initiator);
0bfce006 307 if (device && device->GetType() == type)
907bd60f
LOK
308 device->SetPhysicalAddress(iNewAddress);
309 }
310 return true;
311}
312
e55f3f70
LOK
313bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command)
314{
315 if (command.parameters.size == 1)
316 {
317 CCECBusDevice *device = GetDevice(command.initiator);
318 if (device)
319 device->SetPowerStatus((cec_power_status) command.parameters[0]);
320 }
321 return true;
322}
323
e9de9629
LOK
324bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command)
325{
326 CStdString strLog;
327 strLog.Format(">> %i requests active source", (uint8_t) command.initiator);
328 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
8747dd4f
LOK
329
330 vector<CCECBusDevice *> devices;
331 for (int iDevicePtr = (int)GetMyDevices(devices)-1; iDevicePtr >=0; iDevicePtr--)
332 devices[iDevicePtr]->TransmitActiveSource();
c4098482 333
8747dd4f 334 return true;
e9de9629
LOK
335}
336
337bool CCECCommandHandler::HandleRoutingChange(const cec_command &command)
338{
339 if (command.parameters.size == 4)
340 {
341 uint16_t iOldAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
342 uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]);
e9de9629 343
0f23c85c
LOK
344 CCECBusDevice *device = GetDevice(command.initiator);
345 if (device)
9dc04b07 346 device->SetStreamPath(iNewAddress, iOldAddress);
e9de9629
LOK
347 }
348 return true;
349}
350
907bd60f
LOK
351bool CCECCommandHandler::HandleRoutingInformation(const cec_command &command)
352{
353 if (command.parameters.size == 2)
354 {
355 uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
356
357 CCECBusDevice *device = GetDevice(command.initiator);
358 if (device)
359 device->SetPhysicalAddress(iNewAddress);
360 }
361}
362
a3269a0a
LOK
363bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command)
364{
365 if (command.parameters.size == 3)
366 {
367 CCECBusDevice *device = GetDevice(command.initiator);
368 if (device)
369 {
370 cec_menu_language language;
371 language.device = command.initiator;
56701628 372 for (uint8_t iPtr = 0; iPtr < 4; iPtr++)
a3269a0a
LOK
373 language.language[iPtr] = command.parameters[iPtr];
374 language.language[3] = 0;
375 device->SetMenuLanguage(language);
6b72afcd
LOK
376
377 if (m_busDevice->MyLogicalAddressContains(command.destination))
378 m_busDevice->GetProcessor()->AddCommand(command);
a3269a0a
LOK
379 }
380 }
381 return true;
382}
383
e9de9629
LOK
384bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command)
385{
386 if (command.parameters.size >= 2)
387 {
b6c7bc94 388 uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]);
e9de9629 389 CStdString strLog;
b6c7bc94 390 strLog.Format(">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress);
e9de9629 391 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
04437dcf 392
b6c7bc94
LOK
393 if (m_busDevice->GetProcessor()->SetStreamPath(iStreamAddress))
394 {
395 CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress);
396 if (device)
397 {
398 return device->TransmitActiveSource() &&
399 device->TransmitMenuState(command.initiator);
400 }
401 }
402 return false;
e9de9629
LOK
403 }
404 return true;
405}
406
e5e86c76
LOK
407bool CCECCommandHandler::HandleSetSystemAudioModeRequest(const cec_command &command)
408{
6b72afcd 409 if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size >= 1)
e5e86c76
LOK
410 {
411 CCECBusDevice *device = GetDevice(command.destination);
412 if (device&& device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
413 return ((CCECAudioSystem *) device)->SetSystemAudioMode(command);
414 }
6b72afcd 415 return false;
e5e86c76
LOK
416}
417
4d6b4433
LOK
418bool CCECCommandHandler::HandleStandby(const cec_command &command)
419{
420 CCECBusDevice *device = GetDevice(command.initiator);
421 if (device)
422 device->SetPowerStatus(CEC_POWER_STATUS_STANDBY);
6b72afcd
LOK
423
424 m_busDevice->GetProcessor()->AddCommand(command);
425
4d6b4433
LOK
426 return true;
427}
428
cf0ecd85
LOK
429bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command)
430{
6b72afcd
LOK
431 if (m_busDevice->MyLogicalAddressContains(command.destination))
432 {
433 CCECBusDevice *device = GetDevice(command.destination);
434 if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
435 return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator);
436 }
cf0ecd85
LOK
437
438 return false;
439}
440
e9de9629
LOK
441bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command)
442{
6b72afcd 443 if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0)
e9de9629
LOK
444 {
445 m_busDevice->GetProcessor()->AddKey();
446
447 if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX)
448 {
449 CStdString strLog;
68391d4f 450 strLog.Format("key pressed: %x", command.parameters[0]);
e9de9629
LOK
451 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str());
452
68391d4f
LOK
453 if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER ||
454 command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION)
455 {
456 CCECBusDevice *device = GetDevice(command.destination);
457 if (device)
458 device->SetPowerStatus(CEC_POWER_STATUS_ON);
459 }
460
e9de9629
LOK
461 m_busDevice->GetProcessor()->SetCurrentButton((cec_user_control_code) command.parameters[0]);
462 }
463 }
464 return true;
465}
466
467bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command)
468{
6b72afcd
LOK
469 if (m_busDevice->MyLogicalAddressContains(command.destination))
470 m_busDevice->GetProcessor()->AddKey();
471
e9de9629
LOK
472 return true;
473}
474
475void CCECCommandHandler::UnhandledCommand(const cec_command &command)
476{
b5b53c7d
LOK
477 CStdString strLog;
478 strLog.Format("unhandled command with opcode %02x from address %d", command.opcode, command.initiator);
479 m_busDevice->AddLog(CEC_LOG_DEBUG, strLog);
0f23c85c
LOK
480}
481
8747dd4f
LOK
482unsigned int CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const
483{
484 unsigned int iReturn(0);
485
486 cec_logical_addresses addresses = m_busDevice->GetProcessor()->GetLogicalAddresses();
f2198ab5 487 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
8747dd4f
LOK
488 {
489 if (addresses[iPtr])
490 {
491 devices.push_back(GetDevice((cec_logical_address) iPtr));
492 ++iReturn;
493 }
494 }
495
496 return iReturn;
497}
498
0f23c85c
LOK
499CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress) const
500{
501 CCECBusDevice *device = NULL;
502
503 if (iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST)
504 device = m_busDevice->GetProcessor()->m_busDevices[iLogicalAddress];
505
506 return device;
e9de9629 507}
6685ae07
LOK
508
509CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
510{
8ac9c610 511 return m_busDevice->GetProcessor()->GetDeviceByPhysicalAddress(iPhysicalAddress);
6685ae07 512}
181b3475 513
c4098482
LOK
514CCECBusDevice *CCECCommandHandler::GetDeviceByType(cec_device_type type) const
515{
516 return m_busDevice->GetProcessor()->GetDeviceByType(type);
517}
518
181b3475
LOK
519void CCECCommandHandler::SetVendorId(const cec_command &command)
520{
521 if (command.parameters.size < 3)
522 {
523 m_busDevice->AddLog(CEC_LOG_WARNING, "invalid vendor ID received");
524 return;
525 }
526
bae71306
LOK
527 uint64_t iVendorId = ((uint64_t)command.parameters[0] << 16) +
528 ((uint64_t)command.parameters[1] << 8) +
181b3475
LOK
529 (uint64_t)command.parameters[2];
530
531 CCECBusDevice *device = GetDevice((cec_logical_address) command.initiator);
532 if (device)
c4098482 533 device->SetVendorId(iVendorId);
181b3475 534}
5e822b09 535
28fa6c97
LOK
536const char *CCECCommandHandler::ToString(const cec_menu_state state)
537{
538 switch (state)
539 {
540 case CEC_MENU_STATE_ACTIVATED:
541 return "activated";
542 case CEC_MENU_STATE_DEACTIVATED:
543 return "deactivated";
544 default:
545 return "unknown";
546 }
547}
548
c686413b
LOK
549const char *CCECCommandHandler::ToString(const cec_version version)
550{
551 switch (version)
552 {
553 case CEC_VERSION_1_2:
554 return "1.2";
555 case CEC_VERSION_1_2A:
556 return "1.2a";
557 case CEC_VERSION_1_3:
558 return "1.3";
559 case CEC_VERSION_1_3A:
560 return "1.3a";
c4098482
LOK
561 case CEC_VERSION_1_4:
562 return "1.4";
c686413b
LOK
563 default:
564 return "unknown";
565 }
566}
567
66c16b69
LOK
568const char *CCECCommandHandler::ToString(const cec_power_status status)
569{
570 switch (status)
571 {
572 case CEC_POWER_STATUS_ON:
573 return "on";
574 case CEC_POWER_STATUS_STANDBY:
575 return "standby";
576 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
577 return "in transition from on to standby";
578 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
579 return "in transition from standby to on";
580 default:
581 return "unknown";
582 }
583}
584
62f5527d
LOK
585const char *CCECCommandHandler::ToString(const cec_logical_address address)
586{
587 switch(address)
588 {
589 case CECDEVICE_AUDIOSYSTEM:
590 return "Audio";
591 case CECDEVICE_BROADCAST:
592 return "Broadcast";
593 case CECDEVICE_FREEUSE:
594 return "Free use";
595 case CECDEVICE_PLAYBACKDEVICE1:
596 return "Playback 1";
597 case CECDEVICE_PLAYBACKDEVICE2:
598 return "Playback 2";
599 case CECDEVICE_PLAYBACKDEVICE3:
600 return "Playback 3";
601 case CECDEVICE_RECORDINGDEVICE1:
602 return "Recorder 1";
603 case CECDEVICE_RECORDINGDEVICE2:
604 return "Recorder 2";
605 case CECDEVICE_RECORDINGDEVICE3:
606 return "Recorder 3";
607 case CECDEVICE_RESERVED1:
608 return "Reserved 1";
609 case CECDEVICE_RESERVED2:
610 return "Reserved 2";
611 case CECDEVICE_TUNER1:
612 return "Tuner 1";
613 case CECDEVICE_TUNER2:
614 return "Tuner 2";
615 case CECDEVICE_TUNER3:
616 return "Tuner 3";
617 case CECDEVICE_TUNER4:
618 return "Tuner 4";
619 case CECDEVICE_TV:
620 return "TV";
621 default:
622 return "unknown";
623 }
624}
625
a9232a79
LOK
626const char *CCECCommandHandler::ToString(const cec_deck_control_mode mode)
627{
628 switch (mode)
629 {
630 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND:
631 return "skip forward wind";
632 case CEC_DECK_CONTROL_MODE_EJECT:
633 return "eject";
634 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND:
635 return "reverse rewind";
636 case CEC_DECK_CONTROL_MODE_STOP:
637 return "stop";
638 default:
639 return "unknown";
640 }
641}
642
8ac9c610
LOK
643const char *CCECCommandHandler::ToString(const cec_deck_info status)
644{
645 switch (status)
646 {
647 case CEC_DECK_INFO_PLAY:
648 return "play";
649 case CEC_DECK_INFO_RECORD:
650 return "record";
651 case CEC_DECK_INFO_PLAY_REVERSE:
652 return "play reverse";
653 case CEC_DECK_INFO_STILL:
654 return "still";
655 case CEC_DECK_INFO_SLOW:
656 return "slow";
657 case CEC_DECK_INFO_SLOW_REVERSE:
658 return "slow reverse";
659 case CEC_DECK_INFO_FAST_FORWARD:
660 return "fast forward";
661 case CEC_DECK_INFO_FAST_REVERSE:
662 return "fast reverse";
663 case CEC_DECK_INFO_NO_MEDIA:
664 return "no media";
665 case CEC_DECK_INFO_STOP:
666 return "stop";
667 case CEC_DECK_INFO_SKIP_FORWARD_WIND:
668 return "info skip forward wind";
669 case CEC_DECK_INFO_SKIP_REVERSE_REWIND:
670 return "info skip reverse rewind";
671 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD:
672 return "info index search forward";
673 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE:
674 return "info index search reverse";
675 case CEC_DECK_INFO_OTHER_STATUS:
676 return "other";
677 default:
678 return "unknown";
679 }
680}
681
5e822b09
LOK
682const char *CCECCommandHandler::ToString(const cec_opcode opcode)
683{
684 switch (opcode)
685 {
686 case CEC_OPCODE_ACTIVE_SOURCE:
687 return "active source";
688 case CEC_OPCODE_IMAGE_VIEW_ON:
689 return "image view on";
690 case CEC_OPCODE_TEXT_VIEW_ON:
691 return "text view on";
692 case CEC_OPCODE_INACTIVE_SOURCE:
693 return "inactive source";
694 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
695 return "request active source";
696 case CEC_OPCODE_ROUTING_CHANGE:
697 return "routing change";
698 case CEC_OPCODE_ROUTING_INFORMATION:
699 return "routing information";
700 case CEC_OPCODE_SET_STREAM_PATH:
701 return "set stream path";
702 case CEC_OPCODE_STANDBY:
703 return "standby";
704 case CEC_OPCODE_RECORD_OFF:
705 return "record off";
706 case CEC_OPCODE_RECORD_ON:
707 return "record on";
708 case CEC_OPCODE_RECORD_STATUS:
709 return "record status";
710 case CEC_OPCODE_RECORD_TV_SCREEN:
711 return "record tv screen";
712 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER:
713 return "clear analogue timer";
714 case CEC_OPCODE_CLEAR_DIGITAL_TIMER:
715 return "clear digital timer";
716 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER:
717 return "clear external timer";
718 case CEC_OPCODE_SET_ANALOGUE_TIMER:
719 return "set analogue timer";
720 case CEC_OPCODE_SET_DIGITAL_TIMER:
721 return "set digital timer";
722 case CEC_OPCODE_SET_EXTERNAL_TIMER:
723 return "set external timer";
724 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE:
725 return "set timer program title";
726 case CEC_OPCODE_TIMER_CLEARED_STATUS:
727 return "timer cleared status";
728 case CEC_OPCODE_TIMER_STATUS:
729 return "timer status";
730 case CEC_OPCODE_CEC_VERSION:
731 return "cec version";
732 case CEC_OPCODE_GET_CEC_VERSION:
733 return "get cec version";
734 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
735 return "give physical address";
736 case CEC_OPCODE_GET_MENU_LANGUAGE:
737 return "get menu language";
738 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
739 return "report physical address";
740 case CEC_OPCODE_SET_MENU_LANGUAGE:
741 return "set menu language";
742 case CEC_OPCODE_DECK_CONTROL:
743 return "deck control";
744 case CEC_OPCODE_DECK_STATUS:
745 return "deck status";
746 case CEC_OPCODE_GIVE_DECK_STATUS:
747 return "give deck status";
748 case CEC_OPCODE_PLAY:
749 return "play";
750 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS:
751 return "give tuner status";
752 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE:
753 return "select analogue service";
754 case CEC_OPCODE_SELECT_DIGITAL_SERVICE:
755 return "set digital service";
756 case CEC_OPCODE_TUNER_DEVICE_STATUS:
757 return "tuner device status";
758 case CEC_OPCODE_TUNER_STEP_DECREMENT:
759 return "tuner step decrement";
760 case CEC_OPCODE_TUNER_STEP_INCREMENT:
761 return "tuner step increment";
762 case CEC_OPCODE_DEVICE_VENDOR_ID:
763 return "device vendor id";
764 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
765 return "give device vendor id";
766 case CEC_OPCODE_VENDOR_COMMAND:
767 return "vendor command";
768 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
769 return "vendor command with id";
770 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN:
771 return "vendor remote button down";
772 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP:
773 return "vendor remote button up";
774 case CEC_OPCODE_SET_OSD_STRING:
775 return "set osd string";
776 case CEC_OPCODE_GIVE_OSD_NAME:
777 return "give osd name";
778 case CEC_OPCODE_SET_OSD_NAME:
779 return "set osd name";
780 case CEC_OPCODE_MENU_REQUEST:
781 return "menu request";
782 case CEC_OPCODE_MENU_STATUS:
783 return "menu status";
784 case CEC_OPCODE_USER_CONTROL_PRESSED:
785 return "user control pressed";
786 case CEC_OPCODE_USER_CONTROL_RELEASE:
787 return "user control release";
788 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
789 return "give device power status";
790 case CEC_OPCODE_REPORT_POWER_STATUS:
791 return "report power status";
792 case CEC_OPCODE_FEATURE_ABORT:
793 return "feature abort";
794 case CEC_OPCODE_ABORT:
795 return "abort";
796 case CEC_OPCODE_GIVE_AUDIO_STATUS:
797 return "give audio status";
798 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
799 return "give audio mode status";
800 case CEC_OPCODE_REPORT_AUDIO_STATUS:
801 return "report audio status";
802 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE:
803 return "set system audio mode";
804 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
805 return "system audio mode request";
806 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS:
807 return "system audio mode status";
808 case CEC_OPCODE_SET_AUDIO_RATE:
809 return "set audio rate";
810 default:
811 return "UNKNOWN";
812 }
813}
c4098482
LOK
814
815const char *CCECCommandHandler::ToString(const cec_system_audio_status mode)
816{
817 switch(mode)
818 {
819 case CEC_SYSTEM_AUDIO_STATUS_ON:
820 return "on";
821 case CEC_SYSTEM_AUDIO_STATUS_OFF:
822 return "off";
823 default:
824 return "unknown";
825 }
826}
827
828const char *CCECCommandHandler::ToString(const cec_audio_status status)
829{
830 // TODO this is a mask
831 return "TODO";
832}
833
834const char *CCECCommandHandler::ToString(const cec_vendor_id vendor)
835{
836 switch (vendor)
837 {
838 case CEC_VENDOR_SAMSUNG:
839 return "Samsung";
840 case CEC_VENDOR_LG:
841 return "LG";
842 case CEC_VENDOR_PANASONIC:
843 return "Panasonic";
844 case CEC_VENDOR_PIONEER:
845 return "Pioneer";
cd02e9b2
LOK
846 case CEC_VENDOR_ONKYO:
847 return "Onkyo";
c4098482
LOK
848 default:
849 return "Unknown";
850 }
851}