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; | |
fcf10e27 | 45 | m_processor = m_busDevice->GetProcessor(); |
e9de9629 LOK |
46 | } |
47 | ||
48 | bool CCECCommandHandler::HandleCommand(const cec_command &command) | |
49 | { | |
50 | bool bHandled(true); | |
51 | ||
5e822b09 | 52 | CStdString strLog; |
fcf10e27 | 53 | strLog.Format(">> %s (%X) -> %s (%X): %s (%2X)", m_processor->ToString(command.initiator), command.initiator, m_processor->ToString(command.destination), command.destination, m_processor->ToString(command.opcode), command.opcode); |
5e822b09 LOK |
54 | m_busDevice->AddLog(CEC_LOG_NOTICE, strLog); |
55 | ||
855a3a98 LOK |
56 | m_processor->AddCommand(command); |
57 | ||
6b72afcd | 58 | switch(command.opcode) |
e9de9629 | 59 | { |
6b72afcd LOK |
60 | case CEC_OPCODE_REPORT_POWER_STATUS: |
61 | HandleReportPowerStatus(command); | |
62 | break; | |
63 | case CEC_OPCODE_CEC_VERSION: | |
64 | HandleDeviceCecVersion(command); | |
65 | break; | |
66 | case CEC_OPCODE_SET_MENU_LANGUAGE: | |
67 | HandleSetMenuLanguage(command); | |
68 | break; | |
69 | case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: | |
70 | HandleGivePhysicalAddress(command); | |
71 | break; | |
72 | case CEC_OPCODE_GIVE_OSD_NAME: | |
73 | HandleGiveOSDName(command); | |
74 | break; | |
75 | case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: | |
76 | HandleGiveDeviceVendorId(command); | |
77 | break; | |
78 | case CEC_OPCODE_DEVICE_VENDOR_ID: | |
79 | HandleDeviceVendorId(command); | |
80 | break; | |
81 | case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: | |
82 | HandleDeviceVendorCommandWithId(command); | |
83 | break; | |
84 | case CEC_OPCODE_GIVE_DECK_STATUS: | |
85 | HandleGiveDeckStatus(command); | |
86 | break; | |
87 | case CEC_OPCODE_DECK_CONTROL: | |
88 | HandleDeckControl(command); | |
89 | break; | |
90 | case CEC_OPCODE_MENU_REQUEST: | |
91 | HandleMenuRequest(command); | |
92 | break; | |
93 | case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: | |
94 | HandleGiveDevicePowerStatus(command); | |
95 | break; | |
96 | case CEC_OPCODE_GET_CEC_VERSION: | |
97 | HandleGetCecVersion(command); | |
98 | break; | |
99 | case CEC_OPCODE_USER_CONTROL_PRESSED: | |
100 | HandleUserControlPressed(command); | |
101 | break; | |
102 | case CEC_OPCODE_USER_CONTROL_RELEASE: | |
103 | HandleUserControlRelease(command); | |
104 | break; | |
105 | case CEC_OPCODE_GIVE_AUDIO_STATUS: | |
106 | HandleGiveAudioStatus(command); | |
107 | break; | |
108 | case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: | |
109 | HandleGiveSystemAudioModeStatus(command); | |
110 | break; | |
111 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: | |
aa517a0d LOK |
112 | HandleSystemAudioModeRequest(command); |
113 | break; | |
114 | case CEC_OPCODE_REPORT_AUDIO_STATUS: | |
855a3a98 | 115 | HandleReportAudioStatus(command); |
aa517a0d LOK |
116 | break; |
117 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: | |
855a3a98 | 118 | HandleSystemAudioModeStatus(command); |
aa517a0d LOK |
119 | break; |
120 | case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: | |
855a3a98 | 121 | HandleSetSystemAudioMode(command); |
6b72afcd LOK |
122 | break; |
123 | case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: | |
124 | HandleRequestActiveSource(command); | |
125 | break; | |
126 | case CEC_OPCODE_SET_STREAM_PATH: | |
127 | HandleSetStreamPath(command); | |
128 | break; | |
129 | case CEC_OPCODE_ROUTING_CHANGE: | |
130 | HandleRoutingChange(command); | |
131 | break; | |
907bd60f LOK |
132 | case CEC_OPCODE_ROUTING_INFORMATION: |
133 | HandleRoutingInformation(command); | |
134 | break; | |
6b72afcd LOK |
135 | case CEC_OPCODE_STANDBY: |
136 | HandleStandby(command); | |
137 | break; | |
138 | case CEC_OPCODE_ACTIVE_SOURCE: | |
139 | HandleActiveSource(command); | |
140 | break; | |
907bd60f LOK |
141 | case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: |
142 | HandleReportPhysicalAddress(command); | |
143 | break; | |
15d1a84c LOK |
144 | case CEC_OPCODE_SET_OSD_NAME: |
145 | HandleSetOSDName(command); | |
146 | break; | |
1a6669b8 LOK |
147 | case CEC_OPCODE_IMAGE_VIEW_ON: |
148 | HandleImageViewOn(command); | |
149 | break; | |
150 | case CEC_OPCODE_TEXT_VIEW_ON: | |
151 | HandleTextViewOn(command); | |
152 | break; | |
6b72afcd LOK |
153 | default: |
154 | UnhandledCommand(command); | |
e9de9629 | 155 | bHandled = false; |
6b72afcd | 156 | break; |
e9de9629 LOK |
157 | } |
158 | ||
159 | return bHandled; | |
160 | } | |
161 | ||
be5b0e24 LOK |
162 | bool CCECCommandHandler::HandleActiveSource(const cec_command &command) |
163 | { | |
164 | if (command.parameters.size == 2) | |
165 | { | |
166 | uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
fcf10e27 | 167 | return m_processor->SetStreamPath(iAddress); |
be5b0e24 LOK |
168 | } |
169 | ||
170 | return true; | |
171 | } | |
172 | ||
a9232a79 LOK |
173 | bool CCECCommandHandler::HandleDeckControl(const cec_command &command) |
174 | { | |
175 | CCECBusDevice *device = GetDevice(command.destination); | |
88e5de6f | 176 | if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) && command.parameters.size > 0) |
a9232a79 LOK |
177 | { |
178 | ((CCECPlaybackDevice *) device)->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]); | |
179 | return true; | |
180 | } | |
181 | ||
182 | return false; | |
183 | } | |
184 | ||
6a1c0009 LOK |
185 | bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command) |
186 | { | |
187 | if (command.parameters.size == 1) | |
188 | { | |
189 | CCECBusDevice *device = GetDevice(command.initiator); | |
190 | if (device) | |
191 | device->SetCecVersion((cec_version) command.parameters[0]); | |
192 | } | |
193 | ||
194 | return true; | |
195 | } | |
196 | ||
e9de9629 LOK |
197 | bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) |
198 | { | |
6b72afcd | 199 | if (m_busDevice->MyLogicalAddressContains(command.destination)) |
fcf10e27 | 200 | m_processor->TransmitAbort(command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED); |
6b72afcd | 201 | |
6a1c0009 | 202 | return true; |
e9de9629 LOK |
203 | } |
204 | ||
205 | bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command) | |
206 | { | |
181b3475 | 207 | SetVendorId(command); |
6a1c0009 | 208 | return true; |
e9de9629 LOK |
209 | } |
210 | ||
211 | bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command) | |
212 | { | |
6b72afcd LOK |
213 | if (m_busDevice->MyLogicalAddressContains(command.destination)) |
214 | { | |
215 | CCECBusDevice *device = GetDevice(command.destination); | |
216 | if (device) | |
217 | return device->TransmitCECVersion(command.initiator); | |
218 | } | |
0f23c85c LOK |
219 | |
220 | return false; | |
e9de9629 LOK |
221 | } |
222 | ||
a1f8fb1b LOK |
223 | bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command) |
224 | { | |
6b72afcd LOK |
225 | if (m_busDevice->MyLogicalAddressContains(command.destination)) |
226 | { | |
227 | CCECBusDevice *device = GetDevice(command.destination); | |
228 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
229 | return ((CCECAudioSystem *) device)->TransmitAudioStatus(command.initiator); | |
230 | } | |
a1f8fb1b LOK |
231 | |
232 | return false; | |
233 | } | |
234 | ||
e9de9629 LOK |
235 | bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command) |
236 | { | |
6b72afcd LOK |
237 | if (m_busDevice->MyLogicalAddressContains(command.destination)) |
238 | { | |
239 | CCECBusDevice *device = GetDevice(command.destination); | |
240 | if (device && (device->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || device->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE)) | |
241 | return ((CCECPlaybackDevice *) device)->TransmitDeckStatus(command.initiator); | |
242 | } | |
0f23c85c LOK |
243 | |
244 | return false; | |
e9de9629 LOK |
245 | } |
246 | ||
247 | bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) | |
248 | { | |
6b72afcd LOK |
249 | if (m_busDevice->MyLogicalAddressContains(command.destination)) |
250 | { | |
251 | CCECBusDevice *device = GetDevice(command.destination); | |
252 | if (device) | |
253 | return device->TransmitPowerState(command.initiator); | |
254 | } | |
0f23c85c LOK |
255 | |
256 | return false; | |
e9de9629 LOK |
257 | } |
258 | ||
259 | bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command) | |
260 | { | |
6b72afcd LOK |
261 | if (m_busDevice->MyLogicalAddressContains(command.destination)) |
262 | { | |
263 | CCECBusDevice *device = GetDevice(command.destination); | |
264 | if (device) | |
265 | return device->TransmitVendorID(command.initiator); | |
266 | } | |
0f23c85c LOK |
267 | |
268 | return false; | |
e9de9629 LOK |
269 | } |
270 | ||
271 | bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command) | |
272 | { | |
6b72afcd LOK |
273 | if (m_busDevice->MyLogicalAddressContains(command.destination)) |
274 | { | |
275 | CCECBusDevice *device = GetDevice(command.destination); | |
276 | if (device) | |
277 | return device->TransmitOSDName(command.initiator); | |
278 | } | |
0f23c85c LOK |
279 | |
280 | return false; | |
e9de9629 LOK |
281 | } |
282 | ||
283 | bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command) | |
284 | { | |
6b72afcd LOK |
285 | if (m_busDevice->MyLogicalAddressContains(command.destination)) |
286 | { | |
287 | CCECBusDevice *device = GetDevice(command.destination); | |
288 | if (device) | |
289 | return device->TransmitPhysicalAddress(); | |
290 | } | |
09c10b66 LOK |
291 | |
292 | return false; | |
e9de9629 LOK |
293 | } |
294 | ||
1a6669b8 LOK |
295 | bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command) |
296 | { | |
297 | if (m_busDevice->MyLogicalAddressContains(command.destination)) | |
298 | { | |
299 | CCECBusDevice *device = GetDevice(command.destination); | |
300 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
301 | return ((CCECAudioSystem *) device)->TransmitSystemAudioModeStatus(command.initiator); | |
302 | } | |
303 | ||
304 | return false; | |
305 | } | |
306 | ||
307 | bool CCECCommandHandler::HandleImageViewOn(const cec_command &command) | |
308 | { | |
fcf10e27 | 309 | m_processor->SetActiveSource(command.initiator); |
1a6669b8 LOK |
310 | return true; |
311 | } | |
312 | ||
e9de9629 LOK |
313 | bool CCECCommandHandler::HandleMenuRequest(const cec_command &command) |
314 | { | |
6b72afcd | 315 | if (m_busDevice->MyLogicalAddressContains(command.destination)) |
0f23c85c | 316 | { |
6b72afcd LOK |
317 | if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_QUERY) |
318 | { | |
319 | CCECBusDevice *device = GetDevice(command.destination); | |
320 | if (device) | |
321 | return device->TransmitMenuState(command.initiator); | |
322 | } | |
15d1a84c LOK |
323 | } |
324 | ||
325 | return false; | |
326 | } | |
327 | ||
328 | bool CCECCommandHandler::HandleReportAudioStatus(const cec_command &command) | |
329 | { | |
330 | if (command.parameters.size == 1) | |
331 | { | |
332 | CCECBusDevice *device = GetDevice(command.initiator); | |
333 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
6b72afcd | 334 | { |
15d1a84c LOK |
335 | ((CCECAudioSystem *)device)->SetAudioStatus(command.parameters[0]); |
336 | return true; | |
6b72afcd | 337 | } |
0f23c85c LOK |
338 | } |
339 | return false; | |
e9de9629 LOK |
340 | } |
341 | ||
907bd60f LOK |
342 | bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command) |
343 | { | |
0bfce006 | 344 | if (command.parameters.size == 3) |
907bd60f LOK |
345 | { |
346 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
16b1e052 | 347 | SetPhysicalAddress(command.initiator, iNewAddress); |
907bd60f LOK |
348 | } |
349 | return true; | |
350 | } | |
351 | ||
e55f3f70 LOK |
352 | bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command) |
353 | { | |
354 | if (command.parameters.size == 1) | |
355 | { | |
356 | CCECBusDevice *device = GetDevice(command.initiator); | |
357 | if (device) | |
358 | device->SetPowerStatus((cec_power_status) command.parameters[0]); | |
359 | } | |
360 | return true; | |
361 | } | |
362 | ||
e9de9629 LOK |
363 | bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) |
364 | { | |
365 | CStdString strLog; | |
366 | strLog.Format(">> %i requests active source", (uint8_t) command.initiator); | |
367 | m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); | |
8747dd4f LOK |
368 | |
369 | vector<CCECBusDevice *> devices; | |
370 | for (int iDevicePtr = (int)GetMyDevices(devices)-1; iDevicePtr >=0; iDevicePtr--) | |
371 | devices[iDevicePtr]->TransmitActiveSource(); | |
c4098482 | 372 | |
8747dd4f | 373 | return true; |
e9de9629 LOK |
374 | } |
375 | ||
376 | bool CCECCommandHandler::HandleRoutingChange(const cec_command &command) | |
377 | { | |
378 | if (command.parameters.size == 4) | |
379 | { | |
380 | uint16_t iOldAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
381 | uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]); | |
e9de9629 | 382 | |
0f23c85c LOK |
383 | CCECBusDevice *device = GetDevice(command.initiator); |
384 | if (device) | |
9dc04b07 | 385 | device->SetStreamPath(iNewAddress, iOldAddress); |
e9de9629 LOK |
386 | } |
387 | return true; | |
388 | } | |
389 | ||
907bd60f LOK |
390 | bool CCECCommandHandler::HandleRoutingInformation(const cec_command &command) |
391 | { | |
392 | if (command.parameters.size == 2) | |
393 | { | |
394 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
fcf10e27 | 395 | m_processor->SetStreamPath(iNewAddress); |
907bd60f | 396 | } |
15d1a84c LOK |
397 | |
398 | return false; | |
907bd60f LOK |
399 | } |
400 | ||
a3269a0a LOK |
401 | bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command) |
402 | { | |
403 | if (command.parameters.size == 3) | |
404 | { | |
405 | CCECBusDevice *device = GetDevice(command.initiator); | |
406 | if (device) | |
407 | { | |
408 | cec_menu_language language; | |
409 | language.device = command.initiator; | |
56701628 | 410 | for (uint8_t iPtr = 0; iPtr < 4; iPtr++) |
a3269a0a LOK |
411 | language.language[iPtr] = command.parameters[iPtr]; |
412 | language.language[3] = 0; | |
413 | device->SetMenuLanguage(language); | |
15d1a84c LOK |
414 | return true; |
415 | } | |
416 | } | |
417 | return false; | |
418 | } | |
419 | ||
420 | bool CCECCommandHandler::HandleSetOSDName(const cec_command &command) | |
421 | { | |
422 | if (command.parameters.size > 0) | |
423 | { | |
424 | CCECBusDevice *device = GetDevice(command.initiator); | |
425 | if (device) | |
426 | { | |
427 | char buf[1024]; | |
428 | for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) | |
429 | buf[iPtr] = (char)command.parameters[iPtr]; | |
430 | buf[command.parameters.size] = 0; | |
431 | ||
432 | CStdString strName(buf); | |
433 | device->SetOSDName(strName); | |
6b72afcd | 434 | |
15d1a84c | 435 | return true; |
a3269a0a LOK |
436 | } |
437 | } | |
15d1a84c | 438 | return false; |
a3269a0a LOK |
439 | } |
440 | ||
e9de9629 LOK |
441 | bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) |
442 | { | |
443 | if (command.parameters.size >= 2) | |
444 | { | |
b6c7bc94 | 445 | uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); |
e9de9629 | 446 | CStdString strLog; |
b6c7bc94 | 447 | strLog.Format(">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress); |
e9de9629 | 448 | m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); |
04437dcf | 449 | |
fcf10e27 | 450 | if (m_processor->SetStreamPath(iStreamAddress)) |
b6c7bc94 LOK |
451 | { |
452 | CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress); | |
453 | if (device) | |
454 | { | |
455 | return device->TransmitActiveSource() && | |
456 | device->TransmitMenuState(command.initiator); | |
457 | } | |
458 | } | |
e9de9629 | 459 | } |
15d1a84c | 460 | return false; |
e9de9629 LOK |
461 | } |
462 | ||
aa517a0d | 463 | bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command) |
e5e86c76 | 464 | { |
aa517a0d | 465 | if (m_busDevice->MyLogicalAddressContains(command.destination)) |
e5e86c76 LOK |
466 | { |
467 | CCECBusDevice *device = GetDevice(command.destination); | |
aa517a0d LOK |
468 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) |
469 | { | |
470 | if (command.parameters.size >= 2) | |
471 | { | |
472 | device->SetPowerStatus(CEC_POWER_STATUS_ON); | |
473 | ((CCECAudioSystem *) device)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_ON); | |
474 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
475 | CCECBusDevice *newActiveDevice = GetDeviceByPhysicalAddress(iNewAddress); | |
476 | if (newActiveDevice) | |
fcf10e27 | 477 | m_processor->SetActiveSource(newActiveDevice->GetLogicalAddress()); |
aa517a0d LOK |
478 | return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator); |
479 | } | |
480 | else | |
481 | { | |
482 | ((CCECAudioSystem *) device)->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_OFF); | |
483 | return ((CCECAudioSystem *) device)->TransmitSetSystemAudioMode(command.initiator); | |
484 | } | |
485 | } | |
e5e86c76 | 486 | } |
6b72afcd | 487 | return false; |
e5e86c76 LOK |
488 | } |
489 | ||
4d6b4433 LOK |
490 | bool CCECCommandHandler::HandleStandby(const cec_command &command) |
491 | { | |
492 | CCECBusDevice *device = GetDevice(command.initiator); | |
493 | if (device) | |
494 | device->SetPowerStatus(CEC_POWER_STATUS_STANDBY); | |
6b72afcd | 495 | |
4d6b4433 LOK |
496 | return true; |
497 | } | |
498 | ||
aa517a0d | 499 | bool CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command &command) |
868dc71f | 500 | { |
aa517a0d | 501 | if (command.parameters.size == 1) |
868dc71f | 502 | { |
aa517a0d LOK |
503 | CCECBusDevice *device = GetDevice(command.initiator); |
504 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
505 | { | |
506 | ((CCECAudioSystem *)device)->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); | |
507 | return true; | |
508 | } | |
509 | } | |
510 | ||
511 | return false; | |
512 | } | |
513 | ||
514 | bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command &command) | |
515 | { | |
516 | if (command.parameters.size == 1) | |
517 | { | |
518 | CCECBusDevice *device = GetDevice(command.initiator); | |
519 | if (device && device->GetType() == CEC_DEVICE_TYPE_AUDIO_SYSTEM) | |
520 | { | |
521 | ((CCECAudioSystem *)device)->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); | |
522 | return true; | |
523 | } | |
868dc71f LOK |
524 | } |
525 | ||
526 | return false; | |
527 | } | |
528 | ||
1a6669b8 | 529 | bool CCECCommandHandler::HandleTextViewOn(const cec_command &command) |
cf0ecd85 | 530 | { |
fcf10e27 | 531 | m_processor->SetActiveSource(command.initiator); |
1a6669b8 | 532 | return true; |
cf0ecd85 LOK |
533 | } |
534 | ||
e9de9629 LOK |
535 | bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) |
536 | { | |
6b72afcd | 537 | if (m_busDevice->MyLogicalAddressContains(command.destination) && command.parameters.size > 0) |
e9de9629 | 538 | { |
fcf10e27 | 539 | m_processor->AddKey(); |
e9de9629 LOK |
540 | |
541 | if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX) | |
542 | { | |
543 | CStdString strLog; | |
68391d4f | 544 | strLog.Format("key pressed: %x", command.parameters[0]); |
e9de9629 LOK |
545 | m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); |
546 | ||
68391d4f LOK |
547 | if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER || |
548 | command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION) | |
549 | { | |
550 | CCECBusDevice *device = GetDevice(command.destination); | |
551 | if (device) | |
552 | device->SetPowerStatus(CEC_POWER_STATUS_ON); | |
553 | } | |
554 | ||
fcf10e27 | 555 | m_processor->SetCurrentButton((cec_user_control_code) command.parameters[0]); |
15d1a84c | 556 | return true; |
e9de9629 LOK |
557 | } |
558 | } | |
15d1a84c | 559 | return false; |
e9de9629 LOK |
560 | } |
561 | ||
562 | bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command) | |
563 | { | |
6b72afcd | 564 | if (m_busDevice->MyLogicalAddressContains(command.destination)) |
fcf10e27 | 565 | m_processor->AddKey(); |
6b72afcd | 566 | |
e9de9629 LOK |
567 | return true; |
568 | } | |
569 | ||
570 | void CCECCommandHandler::UnhandledCommand(const cec_command &command) | |
571 | { | |
b5b53c7d LOK |
572 | CStdString strLog; |
573 | strLog.Format("unhandled command with opcode %02x from address %d", command.opcode, command.initiator); | |
574 | m_busDevice->AddLog(CEC_LOG_DEBUG, strLog); | |
0f23c85c LOK |
575 | } |
576 | ||
8747dd4f LOK |
577 | unsigned int CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const |
578 | { | |
579 | unsigned int iReturn(0); | |
580 | ||
fcf10e27 | 581 | cec_logical_addresses addresses = m_processor->GetLogicalAddresses(); |
f2198ab5 | 582 | for (uint8_t iPtr = 0; iPtr < 16; iPtr++) |
8747dd4f LOK |
583 | { |
584 | if (addresses[iPtr]) | |
585 | { | |
586 | devices.push_back(GetDevice((cec_logical_address) iPtr)); | |
587 | ++iReturn; | |
588 | } | |
589 | } | |
590 | ||
591 | return iReturn; | |
592 | } | |
593 | ||
0f23c85c LOK |
594 | CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress) const |
595 | { | |
596 | CCECBusDevice *device = NULL; | |
597 | ||
598 | if (iLogicalAddress >= CECDEVICE_TV && iLogicalAddress <= CECDEVICE_BROADCAST) | |
fcf10e27 | 599 | device = m_processor->m_busDevices[iLogicalAddress]; |
0f23c85c LOK |
600 | |
601 | return device; | |
e9de9629 | 602 | } |
6685ae07 LOK |
603 | |
604 | CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const | |
605 | { | |
fcf10e27 | 606 | return m_processor->GetDeviceByPhysicalAddress(iPhysicalAddress); |
6685ae07 | 607 | } |
181b3475 | 608 | |
c4098482 LOK |
609 | CCECBusDevice *CCECCommandHandler::GetDeviceByType(cec_device_type type) const |
610 | { | |
fcf10e27 | 611 | return m_processor->GetDeviceByType(type); |
c4098482 LOK |
612 | } |
613 | ||
181b3475 LOK |
614 | void CCECCommandHandler::SetVendorId(const cec_command &command) |
615 | { | |
616 | if (command.parameters.size < 3) | |
617 | { | |
618 | m_busDevice->AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); | |
619 | return; | |
620 | } | |
621 | ||
bae71306 LOK |
622 | uint64_t iVendorId = ((uint64_t)command.parameters[0] << 16) + |
623 | ((uint64_t)command.parameters[1] << 8) + | |
181b3475 LOK |
624 | (uint64_t)command.parameters[2]; |
625 | ||
626 | CCECBusDevice *device = GetDevice((cec_logical_address) command.initiator); | |
627 | if (device) | |
c4098482 | 628 | device->SetVendorId(iVendorId); |
181b3475 | 629 | } |
5e822b09 | 630 | |
16b1e052 LOK |
631 | void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress, uint16_t iNewAddress) |
632 | { | |
633 | if (!m_busDevice->MyLogicalAddressContains(iAddress)) | |
634 | { | |
fcf10e27 | 635 | bool bOurAddress(m_processor->GetPhysicalAddress() == iNewAddress); |
16b1e052 LOK |
636 | GetDevice(iAddress)->SetPhysicalAddress(iNewAddress); |
637 | if (bOurAddress) | |
638 | { | |
639 | /* another device reported the same physical address as ours | |
640 | * since we don't have physical address detection yet, we'll just use the | |
641 | * given address, increased by 0x100 for now */ | |
fcf10e27 | 642 | m_processor->SetPhysicalAddress(iNewAddress + 0x100); |
16b1e052 LOK |
643 | } |
644 | } | |
645 | } | |
855a3a98 LOK |
646 | |
647 | void CCECCommandHandler::HandlePoll(const cec_logical_address iInitiator, const cec_logical_address iDestination) | |
648 | { | |
649 | CStdString strLog; | |
650 | strLog.Format("<< POLL: %s (%x) -> %s (%x)", m_processor->ToString(iInitiator), iInitiator, m_processor->ToString(iDestination), iDestination); | |
651 | m_processor->AddLog(CEC_LOG_DEBUG, strLog); | |
652 | } | |
653 | ||
654 | bool CCECCommandHandler::HandleReceiveFailed(void) | |
655 | { | |
656 | /* default = error */ | |
657 | return true; | |
658 | } |