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