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