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