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 | ||
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 |
143 | bool 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 |
156 | bool 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 |
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 | ||
e9de9629 LOK |
182 | bool 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 | ||
190 | bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command) | |
191 | { | |
181b3475 | 192 | SetVendorId(command); |
6a1c0009 | 193 | return true; |
e9de9629 LOK |
194 | } |
195 | ||
196 | bool 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 |
208 | bool 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 |
220 | bool 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 | ||
232 | bool 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 | ||
244 | bool 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 | ||
256 | bool 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 | ||
268 | bool 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 | ||
280 | bool 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 |
299 | bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command) |
300 | { | |
301 | if (command.parameters.size == 2) | |
302 | { | |
303 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
304 | ||
305 | CCECBusDevice *device = GetDevice(command.initiator); | |
306 | if (device) | |
307 | device->SetPhysicalAddress(iNewAddress); | |
308 | } | |
309 | return true; | |
310 | } | |
311 | ||
e55f3f70 LOK |
312 | bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command) |
313 | { | |
314 | if (command.parameters.size == 1) | |
315 | { | |
316 | CCECBusDevice *device = GetDevice(command.initiator); | |
317 | if (device) | |
318 | device->SetPowerStatus((cec_power_status) command.parameters[0]); | |
319 | } | |
320 | return true; | |
321 | } | |
322 | ||
e9de9629 LOK |
323 | bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) |
324 | { | |
325 | CStdString strLog; | |
326 | strLog.Format(">> %i requests active source", (uint8_t) command.initiator); | |
327 | m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); | |
8747dd4f LOK |
328 | |
329 | vector<CCECBusDevice *> devices; | |
330 | for (int iDevicePtr = (int)GetMyDevices(devices)-1; iDevicePtr >=0; iDevicePtr--) | |
331 | devices[iDevicePtr]->TransmitActiveSource(); | |
c4098482 | 332 | |
8747dd4f | 333 | return true; |
e9de9629 LOK |
334 | } |
335 | ||
336 | bool CCECCommandHandler::HandleRoutingChange(const cec_command &command) | |
337 | { | |
338 | if (command.parameters.size == 4) | |
339 | { | |
340 | uint16_t iOldAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
341 | uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]); | |
e9de9629 | 342 | |
0f23c85c LOK |
343 | CCECBusDevice *device = GetDevice(command.initiator); |
344 | if (device) | |
9dc04b07 | 345 | device->SetStreamPath(iNewAddress, iOldAddress); |
e9de9629 LOK |
346 | } |
347 | return true; | |
348 | } | |
349 | ||
907bd60f LOK |
350 | bool CCECCommandHandler::HandleRoutingInformation(const cec_command &command) |
351 | { | |
352 | if (command.parameters.size == 2) | |
353 | { | |
354 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
355 | ||
356 | CCECBusDevice *device = GetDevice(command.initiator); | |
357 | if (device) | |
358 | device->SetPhysicalAddress(iNewAddress); | |
359 | } | |
360 | } | |
361 | ||
a3269a0a LOK |
362 | bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command) |
363 | { | |
364 | if (command.parameters.size == 3) | |
365 | { | |
366 | CCECBusDevice *device = GetDevice(command.initiator); | |
367 | if (device) | |
368 | { | |
369 | cec_menu_language language; | |
370 | language.device = command.initiator; | |
56701628 | 371 | for (uint8_t iPtr = 0; iPtr < 4; iPtr++) |
a3269a0a LOK |
372 | language.language[iPtr] = command.parameters[iPtr]; |
373 | language.language[3] = 0; | |
374 | device->SetMenuLanguage(language); | |
6b72afcd LOK |
375 | |
376 | if (m_busDevice->MyLogicalAddressContains(command.destination)) | |
377 | m_busDevice->GetProcessor()->AddCommand(command); | |
a3269a0a LOK |
378 | } |
379 | } | |
380 | return true; | |
381 | } | |
382 | ||
e9de9629 LOK |
383 | bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) |
384 | { | |
385 | if (command.parameters.size >= 2) | |
386 | { | |
b6c7bc94 | 387 | uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); |
e9de9629 | 388 | CStdString strLog; |
b6c7bc94 | 389 | strLog.Format(">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress); |
e9de9629 | 390 | m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); |
04437dcf | 391 | |
b6c7bc94 LOK |
392 | if (m_busDevice->GetProcessor()->SetStreamPath(iStreamAddress)) |
393 | { | |
394 | CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress); | |
395 | if (device) | |
396 | { | |
397 | return device->TransmitActiveSource() && | |
398 | device->TransmitMenuState(command.initiator); | |
399 | } | |
400 | } | |
401 | return false; | |
e9de9629 LOK |
402 | } |
403 | return true; | |
404 | } | |
405 | ||
e5e86c76 LOK |
406 | bool CCECCommandHandler::HandleSetSystemAudioModeRequest(const cec_command &command) |
407 | { | |
6b72afcd | 408 | if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size >= 1) |
e5e86c76 LOK |
409 | { |
410 | CCECBusDevice *device = GetDevice(command.destination); | |
411 | if (device&& device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
412 | return ((CCECAudioSystem *) device)->SetSystemAudioMode(command); | |
413 | } | |
6b72afcd | 414 | return false; |
e5e86c76 LOK |
415 | } |
416 | ||
4d6b4433 LOK |
417 | bool CCECCommandHandler::HandleStandby(const cec_command &command) |
418 | { | |
419 | CCECBusDevice *device = GetDevice(command.initiator); | |
420 | if (device) | |
421 | device->SetPowerStatus(CEC_POWER_STATUS_STANDBY); | |
6b72afcd LOK |
422 | |
423 | m_busDevice->GetProcessor()->AddCommand(command); | |
424 | ||
4d6b4433 LOK |
425 | return true; |
426 | } | |
427 | ||
cf0ecd85 LOK |
428 | bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command) |
429 | { | |
6b72afcd LOK |
430 | if (m_busDevice->MyLogicalAddressContains(command.destination)) |
431 | { | |
432 | CCECBusDevice *device = GetDevice(command.destination); | |
433 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
434 | return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator); | |
435 | } | |
cf0ecd85 LOK |
436 | |
437 | return false; | |
438 | } | |
439 | ||
e9de9629 LOK |
440 | bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) |
441 | { | |
6b72afcd | 442 | if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0) |
e9de9629 LOK |
443 | { |
444 | m_busDevice->GetProcessor()->AddKey(); | |
445 | ||
446 | if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX) | |
447 | { | |
448 | CStdString strLog; | |
68391d4f | 449 | strLog.Format("key pressed: %x", command.parameters[0]); |
e9de9629 LOK |
450 | m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); |
451 | ||
68391d4f LOK |
452 | if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER || |
453 | command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION) | |
454 | { | |
455 | CCECBusDevice *device = GetDevice(command.destination); | |
456 | if (device) | |
457 | device->SetPowerStatus(CEC_POWER_STATUS_ON); | |
458 | } | |
459 | ||
e9de9629 LOK |
460 | m_busDevice->GetProcessor()->SetCurrentButton((cec_user_control_code) command.parameters[0]); |
461 | } | |
462 | } | |
463 | return true; | |
464 | } | |
465 | ||
466 | bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command) | |
467 | { | |
6b72afcd LOK |
468 | if (m_busDevice->MyLogicalAddressContains(command.destination)) |
469 | m_busDevice->GetProcessor()->AddKey(); | |
470 | ||
e9de9629 LOK |
471 | return true; |
472 | } | |
473 | ||
474 | void CCECCommandHandler::UnhandledCommand(const cec_command &command) | |
475 | { | |
b5b53c7d LOK |
476 | CStdString strLog; |
477 | strLog.Format("unhandled command with opcode %02x from address %d", command.opcode, command.initiator); | |
478 | m_busDevice->AddLog(CEC_LOG_DEBUG, strLog); | |
0f23c85c LOK |
479 | } |
480 | ||
8747dd4f LOK |
481 | unsigned int CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const |
482 | { | |
483 | unsigned int iReturn(0); | |
484 | ||
485 | cec_logical_addresses addresses = m_busDevice->GetProcessor()->GetLogicalAddresses(); | |
f2198ab5 | 486 | for (uint8_t iPtr = 0; iPtr < 16; iPtr++) |
8747dd4f LOK |
487 | { |
488 | if (addresses[iPtr]) | |
489 | { | |
490 | devices.push_back(GetDevice((cec_logical_address) iPtr)); | |
491 | ++iReturn; | |
492 | } | |
493 | } | |
494 | ||
495 | return iReturn; | |
496 | } | |
497 | ||
0f23c85c LOK |
498 | CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress) const |
499 | { | |
500 | CCECBusDevice *device = NULL; | |
501 | ||
502 | if (iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST) | |
503 | device = m_busDevice->GetProcessor()->m_busDevices[iLogicalAddress]; | |
504 | ||
505 | return device; | |
e9de9629 | 506 | } |
6685ae07 LOK |
507 | |
508 | CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const | |
509 | { | |
8ac9c610 | 510 | return m_busDevice->GetProcessor()->GetDeviceByPhysicalAddress(iPhysicalAddress); |
6685ae07 | 511 | } |
181b3475 | 512 | |
c4098482 LOK |
513 | CCECBusDevice *CCECCommandHandler::GetDeviceByType(cec_device_type type) const |
514 | { | |
515 | return m_busDevice->GetProcessor()->GetDeviceByType(type); | |
516 | } | |
517 | ||
181b3475 LOK |
518 | void CCECCommandHandler::SetVendorId(const cec_command &command) |
519 | { | |
520 | if (command.parameters.size < 3) | |
521 | { | |
522 | m_busDevice->AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); | |
523 | return; | |
524 | } | |
525 | ||
bae71306 LOK |
526 | uint64_t iVendorId = ((uint64_t)command.parameters[0] << 16) + |
527 | ((uint64_t)command.parameters[1] << 8) + | |
181b3475 LOK |
528 | (uint64_t)command.parameters[2]; |
529 | ||
530 | CCECBusDevice *device = GetDevice((cec_logical_address) command.initiator); | |
531 | if (device) | |
c4098482 | 532 | device->SetVendorId(iVendorId); |
181b3475 | 533 | } |
5e822b09 | 534 | |
28fa6c97 LOK |
535 | const char *CCECCommandHandler::ToString(const cec_menu_state state) |
536 | { | |
537 | switch (state) | |
538 | { | |
539 | case CEC_MENU_STATE_ACTIVATED: | |
540 | return "activated"; | |
541 | case CEC_MENU_STATE_DEACTIVATED: | |
542 | return "deactivated"; | |
543 | default: | |
544 | return "unknown"; | |
545 | } | |
546 | } | |
547 | ||
c686413b LOK |
548 | const char *CCECCommandHandler::ToString(const cec_version version) |
549 | { | |
550 | switch (version) | |
551 | { | |
552 | case CEC_VERSION_1_2: | |
553 | return "1.2"; | |
554 | case CEC_VERSION_1_2A: | |
555 | return "1.2a"; | |
556 | case CEC_VERSION_1_3: | |
557 | return "1.3"; | |
558 | case CEC_VERSION_1_3A: | |
559 | return "1.3a"; | |
c4098482 LOK |
560 | case CEC_VERSION_1_4: |
561 | return "1.4"; | |
c686413b LOK |
562 | default: |
563 | return "unknown"; | |
564 | } | |
565 | } | |
566 | ||
66c16b69 LOK |
567 | const char *CCECCommandHandler::ToString(const cec_power_status status) |
568 | { | |
569 | switch (status) | |
570 | { | |
571 | case CEC_POWER_STATUS_ON: | |
572 | return "on"; | |
573 | case CEC_POWER_STATUS_STANDBY: | |
574 | return "standby"; | |
575 | case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY: | |
576 | return "in transition from on to standby"; | |
577 | case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON: | |
578 | return "in transition from standby to on"; | |
579 | default: | |
580 | return "unknown"; | |
581 | } | |
582 | } | |
583 | ||
62f5527d LOK |
584 | const char *CCECCommandHandler::ToString(const cec_logical_address address) |
585 | { | |
586 | switch(address) | |
587 | { | |
588 | case CECDEVICE_AUDIOSYSTEM: | |
589 | return "Audio"; | |
590 | case CECDEVICE_BROADCAST: | |
591 | return "Broadcast"; | |
592 | case CECDEVICE_FREEUSE: | |
593 | return "Free use"; | |
594 | case CECDEVICE_PLAYBACKDEVICE1: | |
595 | return "Playback 1"; | |
596 | case CECDEVICE_PLAYBACKDEVICE2: | |
597 | return "Playback 2"; | |
598 | case CECDEVICE_PLAYBACKDEVICE3: | |
599 | return "Playback 3"; | |
600 | case CECDEVICE_RECORDINGDEVICE1: | |
601 | return "Recorder 1"; | |
602 | case CECDEVICE_RECORDINGDEVICE2: | |
603 | return "Recorder 2"; | |
604 | case CECDEVICE_RECORDINGDEVICE3: | |
605 | return "Recorder 3"; | |
606 | case CECDEVICE_RESERVED1: | |
607 | return "Reserved 1"; | |
608 | case CECDEVICE_RESERVED2: | |
609 | return "Reserved 2"; | |
610 | case CECDEVICE_TUNER1: | |
611 | return "Tuner 1"; | |
612 | case CECDEVICE_TUNER2: | |
613 | return "Tuner 2"; | |
614 | case CECDEVICE_TUNER3: | |
615 | return "Tuner 3"; | |
616 | case CECDEVICE_TUNER4: | |
617 | return "Tuner 4"; | |
618 | case CECDEVICE_TV: | |
619 | return "TV"; | |
620 | default: | |
621 | return "unknown"; | |
622 | } | |
623 | } | |
624 | ||
a9232a79 LOK |
625 | const char *CCECCommandHandler::ToString(const cec_deck_control_mode mode) |
626 | { | |
627 | switch (mode) | |
628 | { | |
629 | case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND: | |
630 | return "skip forward wind"; | |
631 | case CEC_DECK_CONTROL_MODE_EJECT: | |
632 | return "eject"; | |
633 | case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND: | |
634 | return "reverse rewind"; | |
635 | case CEC_DECK_CONTROL_MODE_STOP: | |
636 | return "stop"; | |
637 | default: | |
638 | return "unknown"; | |
639 | } | |
640 | } | |
641 | ||
8ac9c610 LOK |
642 | const char *CCECCommandHandler::ToString(const cec_deck_info status) |
643 | { | |
644 | switch (status) | |
645 | { | |
646 | case CEC_DECK_INFO_PLAY: | |
647 | return "play"; | |
648 | case CEC_DECK_INFO_RECORD: | |
649 | return "record"; | |
650 | case CEC_DECK_INFO_PLAY_REVERSE: | |
651 | return "play reverse"; | |
652 | case CEC_DECK_INFO_STILL: | |
653 | return "still"; | |
654 | case CEC_DECK_INFO_SLOW: | |
655 | return "slow"; | |
656 | case CEC_DECK_INFO_SLOW_REVERSE: | |
657 | return "slow reverse"; | |
658 | case CEC_DECK_INFO_FAST_FORWARD: | |
659 | return "fast forward"; | |
660 | case CEC_DECK_INFO_FAST_REVERSE: | |
661 | return "fast reverse"; | |
662 | case CEC_DECK_INFO_NO_MEDIA: | |
663 | return "no media"; | |
664 | case CEC_DECK_INFO_STOP: | |
665 | return "stop"; | |
666 | case CEC_DECK_INFO_SKIP_FORWARD_WIND: | |
667 | return "info skip forward wind"; | |
668 | case CEC_DECK_INFO_SKIP_REVERSE_REWIND: | |
669 | return "info skip reverse rewind"; | |
670 | case CEC_DECK_INFO_INDEX_SEARCH_FORWARD: | |
671 | return "info index search forward"; | |
672 | case CEC_DECK_INFO_INDEX_SEARCH_REVERSE: | |
673 | return "info index search reverse"; | |
674 | case CEC_DECK_INFO_OTHER_STATUS: | |
675 | return "other"; | |
676 | default: | |
677 | return "unknown"; | |
678 | } | |
679 | } | |
680 | ||
5e822b09 LOK |
681 | const char *CCECCommandHandler::ToString(const cec_opcode opcode) |
682 | { | |
683 | switch (opcode) | |
684 | { | |
685 | case CEC_OPCODE_ACTIVE_SOURCE: | |
686 | return "active source"; | |
687 | case CEC_OPCODE_IMAGE_VIEW_ON: | |
688 | return "image view on"; | |
689 | case CEC_OPCODE_TEXT_VIEW_ON: | |
690 | return "text view on"; | |
691 | case CEC_OPCODE_INACTIVE_SOURCE: | |
692 | return "inactive source"; | |
693 | case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: | |
694 | return "request active source"; | |
695 | case CEC_OPCODE_ROUTING_CHANGE: | |
696 | return "routing change"; | |
697 | case CEC_OPCODE_ROUTING_INFORMATION: | |
698 | return "routing information"; | |
699 | case CEC_OPCODE_SET_STREAM_PATH: | |
700 | return "set stream path"; | |
701 | case CEC_OPCODE_STANDBY: | |
702 | return "standby"; | |
703 | case CEC_OPCODE_RECORD_OFF: | |
704 | return "record off"; | |
705 | case CEC_OPCODE_RECORD_ON: | |
706 | return "record on"; | |
707 | case CEC_OPCODE_RECORD_STATUS: | |
708 | return "record status"; | |
709 | case CEC_OPCODE_RECORD_TV_SCREEN: | |
710 | return "record tv screen"; | |
711 | case CEC_OPCODE_CLEAR_ANALOGUE_TIMER: | |
712 | return "clear analogue timer"; | |
713 | case CEC_OPCODE_CLEAR_DIGITAL_TIMER: | |
714 | return "clear digital timer"; | |
715 | case CEC_OPCODE_CLEAR_EXTERNAL_TIMER: | |
716 | return "clear external timer"; | |
717 | case CEC_OPCODE_SET_ANALOGUE_TIMER: | |
718 | return "set analogue timer"; | |
719 | case CEC_OPCODE_SET_DIGITAL_TIMER: | |
720 | return "set digital timer"; | |
721 | case CEC_OPCODE_SET_EXTERNAL_TIMER: | |
722 | return "set external timer"; | |
723 | case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE: | |
724 | return "set timer program title"; | |
725 | case CEC_OPCODE_TIMER_CLEARED_STATUS: | |
726 | return "timer cleared status"; | |
727 | case CEC_OPCODE_TIMER_STATUS: | |
728 | return "timer status"; | |
729 | case CEC_OPCODE_CEC_VERSION: | |
730 | return "cec version"; | |
731 | case CEC_OPCODE_GET_CEC_VERSION: | |
732 | return "get cec version"; | |
733 | case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: | |
734 | return "give physical address"; | |
735 | case CEC_OPCODE_GET_MENU_LANGUAGE: | |
736 | return "get menu language"; | |
737 | case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: | |
738 | return "report physical address"; | |
739 | case CEC_OPCODE_SET_MENU_LANGUAGE: | |
740 | return "set menu language"; | |
741 | case CEC_OPCODE_DECK_CONTROL: | |
742 | return "deck control"; | |
743 | case CEC_OPCODE_DECK_STATUS: | |
744 | return "deck status"; | |
745 | case CEC_OPCODE_GIVE_DECK_STATUS: | |
746 | return "give deck status"; | |
747 | case CEC_OPCODE_PLAY: | |
748 | return "play"; | |
749 | case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS: | |
750 | return "give tuner status"; | |
751 | case CEC_OPCODE_SELECT_ANALOGUE_SERVICE: | |
752 | return "select analogue service"; | |
753 | case CEC_OPCODE_SELECT_DIGITAL_SERVICE: | |
754 | return "set digital service"; | |
755 | case CEC_OPCODE_TUNER_DEVICE_STATUS: | |
756 | return "tuner device status"; | |
757 | case CEC_OPCODE_TUNER_STEP_DECREMENT: | |
758 | return "tuner step decrement"; | |
759 | case CEC_OPCODE_TUNER_STEP_INCREMENT: | |
760 | return "tuner step increment"; | |
761 | case CEC_OPCODE_DEVICE_VENDOR_ID: | |
762 | return "device vendor id"; | |
763 | case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: | |
764 | return "give device vendor id"; | |
765 | case CEC_OPCODE_VENDOR_COMMAND: | |
766 | return "vendor command"; | |
767 | case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: | |
768 | return "vendor command with id"; | |
769 | case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN: | |
770 | return "vendor remote button down"; | |
771 | case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP: | |
772 | return "vendor remote button up"; | |
773 | case CEC_OPCODE_SET_OSD_STRING: | |
774 | return "set osd string"; | |
775 | case CEC_OPCODE_GIVE_OSD_NAME: | |
776 | return "give osd name"; | |
777 | case CEC_OPCODE_SET_OSD_NAME: | |
778 | return "set osd name"; | |
779 | case CEC_OPCODE_MENU_REQUEST: | |
780 | return "menu request"; | |
781 | case CEC_OPCODE_MENU_STATUS: | |
782 | return "menu status"; | |
783 | case CEC_OPCODE_USER_CONTROL_PRESSED: | |
784 | return "user control pressed"; | |
785 | case CEC_OPCODE_USER_CONTROL_RELEASE: | |
786 | return "user control release"; | |
787 | case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: | |
788 | return "give device power status"; | |
789 | case CEC_OPCODE_REPORT_POWER_STATUS: | |
790 | return "report power status"; | |
791 | case CEC_OPCODE_FEATURE_ABORT: | |
792 | return "feature abort"; | |
793 | case CEC_OPCODE_ABORT: | |
794 | return "abort"; | |
795 | case CEC_OPCODE_GIVE_AUDIO_STATUS: | |
796 | return "give audio status"; | |
797 | case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: | |
798 | return "give audio mode status"; | |
799 | case CEC_OPCODE_REPORT_AUDIO_STATUS: | |
800 | return "report audio status"; | |
801 | case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: | |
802 | return "set system audio mode"; | |
803 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: | |
804 | return "system audio mode request"; | |
805 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: | |
806 | return "system audio mode status"; | |
807 | case CEC_OPCODE_SET_AUDIO_RATE: | |
808 | return "set audio rate"; | |
809 | default: | |
810 | return "UNKNOWN"; | |
811 | } | |
812 | } | |
c4098482 LOK |
813 | |
814 | const char *CCECCommandHandler::ToString(const cec_system_audio_status mode) | |
815 | { | |
816 | switch(mode) | |
817 | { | |
818 | case CEC_SYSTEM_AUDIO_STATUS_ON: | |
819 | return "on"; | |
820 | case CEC_SYSTEM_AUDIO_STATUS_OFF: | |
821 | return "off"; | |
822 | default: | |
823 | return "unknown"; | |
824 | } | |
825 | } | |
826 | ||
827 | const char *CCECCommandHandler::ToString(const cec_audio_status status) | |
828 | { | |
829 | // TODO this is a mask | |
830 | return "TODO"; | |
831 | } | |
832 | ||
833 | const char *CCECCommandHandler::ToString(const cec_vendor_id vendor) | |
834 | { | |
835 | switch (vendor) | |
836 | { | |
837 | case CEC_VENDOR_SAMSUNG: | |
838 | return "Samsung"; | |
839 | case CEC_VENDOR_LG: | |
840 | return "LG"; | |
841 | case CEC_VENDOR_PANASONIC: | |
842 | return "Panasonic"; | |
843 | case CEC_VENDOR_PIONEER: | |
844 | return "Pioneer"; | |
cd02e9b2 LOK |
845 | case CEC_VENDOR_ONKYO: |
846 | return "Onkyo"; | |
c4098482 LOK |
847 | default: |
848 | return "Unknown"; | |
849 | } | |
850 | } |