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