Commit | Line | Data |
---|---|---|
e9de9629 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
b492c10e | 4 | * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved. |
e9de9629 LOK |
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" |
004b8382 | 37 | #include "../CECClient.h" |
387b6f6f | 38 | #include "../CECProcessor.h" |
5477a250 | 39 | #include "../LibCEC.h" |
0d800fe5 | 40 | #include "../CECTypeUtils.h" |
c9d15485 | 41 | #include "../platform/util/util.h" |
e9de9629 LOK |
42 | |
43 | using namespace CEC; | |
8747dd4f | 44 | using namespace std; |
f00ff009 | 45 | using namespace PLATFORM; |
e9de9629 | 46 | |
004b8382 | 47 | #define LIB_CEC m_busDevice->GetProcessor()->GetLib() |
0d800fe5 | 48 | #define ToString(p) CCECTypeUtils::ToString(p) |
004b8382 | 49 | |
8fa35473 LOK |
50 | CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) : |
51 | m_busDevice(busDevice), | |
52 | m_processor(m_busDevice->GetProcessor()), | |
ae693aaa LOK |
53 | m_iTransmitTimeout(CEC_DEFAULT_TRANSMIT_TIMEOUT), |
54 | m_iTransmitWait(CEC_DEFAULT_TRANSMIT_WAIT), | |
89a726fa | 55 | m_iTransmitRetries(CEC_DEFAULT_TRANSMIT_RETRIES), |
b64db02e | 56 | m_bHandlerInited(false), |
d79b67d8 | 57 | m_bOPTSendDeckStatusUpdateOnActiveSource(false), |
960f33c6 | 58 | m_vendorId(CEC_VENDOR_UNKNOWN), |
24dd566c | 59 | m_waitForResponse(new CWaitForResponse) |
e9de9629 | 60 | { |
8fa35473 LOK |
61 | } |
62 | ||
63 | CCECCommandHandler::~CCECCommandHandler(void) | |
64 | { | |
c9d15485 | 65 | DELETE_AND_NULL(m_waitForResponse); |
e9de9629 LOK |
66 | } |
67 | ||
68 | bool CCECCommandHandler::HandleCommand(const cec_command &command) | |
69 | { | |
d297cbd4 LOK |
70 | if (command.opcode_set == 0) |
71 | return HandlePoll(command); | |
72 | ||
3e61b350 | 73 | bool bHandled(true); |
e9de9629 | 74 | |
004b8382 LOK |
75 | CCECClient *client = m_busDevice->GetClient(); |
76 | if (client) | |
77 | client->AddCommand(command); | |
855a3a98 | 78 | |
6b72afcd | 79 | switch(command.opcode) |
e9de9629 | 80 | { |
6b72afcd LOK |
81 | case CEC_OPCODE_REPORT_POWER_STATUS: |
82 | HandleReportPowerStatus(command); | |
83 | break; | |
84 | case CEC_OPCODE_CEC_VERSION: | |
85 | HandleDeviceCecVersion(command); | |
86 | break; | |
87 | case CEC_OPCODE_SET_MENU_LANGUAGE: | |
88 | HandleSetMenuLanguage(command); | |
89 | break; | |
90 | case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: | |
004b8382 | 91 | if (m_processor->CECInitialised()) |
3e61b350 | 92 | HandleGivePhysicalAddress(command); |
6b72afcd | 93 | break; |
fbdea54c | 94 | case CEC_OPCODE_GET_MENU_LANGUAGE: |
004b8382 | 95 | if (m_processor->CECInitialised()) |
fbdea54c MK |
96 | HandleGiveMenuLanguage(command); |
97 | break; | |
6b72afcd | 98 | case CEC_OPCODE_GIVE_OSD_NAME: |
004b8382 | 99 | if (m_processor->CECInitialised()) |
3e61b350 | 100 | HandleGiveOSDName(command); |
6b72afcd LOK |
101 | break; |
102 | case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: | |
004b8382 | 103 | if (m_processor->CECInitialised()) |
3e61b350 | 104 | HandleGiveDeviceVendorId(command); |
6b72afcd LOK |
105 | break; |
106 | case CEC_OPCODE_DEVICE_VENDOR_ID: | |
3e61b350 | 107 | HandleDeviceVendorId(command); |
6b72afcd LOK |
108 | break; |
109 | case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: | |
110 | HandleDeviceVendorCommandWithId(command); | |
111 | break; | |
112 | case CEC_OPCODE_GIVE_DECK_STATUS: | |
004b8382 | 113 | if (m_processor->CECInitialised()) |
3e61b350 | 114 | HandleGiveDeckStatus(command); |
6b72afcd LOK |
115 | break; |
116 | case CEC_OPCODE_DECK_CONTROL: | |
117 | HandleDeckControl(command); | |
118 | break; | |
119 | case CEC_OPCODE_MENU_REQUEST: | |
004b8382 | 120 | if (m_processor->CECInitialised()) |
3e61b350 | 121 | HandleMenuRequest(command); |
6b72afcd LOK |
122 | break; |
123 | case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: | |
004b8382 | 124 | if (m_processor->CECInitialised()) |
3e61b350 | 125 | HandleGiveDevicePowerStatus(command); |
6b72afcd LOK |
126 | break; |
127 | case CEC_OPCODE_GET_CEC_VERSION: | |
004b8382 | 128 | if (m_processor->CECInitialised()) |
3e61b350 | 129 | HandleGetCecVersion(command); |
6b72afcd LOK |
130 | break; |
131 | case CEC_OPCODE_USER_CONTROL_PRESSED: | |
004b8382 | 132 | if (m_processor->CECInitialised()) |
3e61b350 | 133 | HandleUserControlPressed(command); |
6b72afcd LOK |
134 | break; |
135 | case CEC_OPCODE_USER_CONTROL_RELEASE: | |
004b8382 | 136 | if (m_processor->CECInitialised()) |
3e61b350 | 137 | HandleUserControlRelease(command); |
6b72afcd LOK |
138 | break; |
139 | case CEC_OPCODE_GIVE_AUDIO_STATUS: | |
004b8382 | 140 | if (m_processor->CECInitialised()) |
3e61b350 | 141 | HandleGiveAudioStatus(command); |
6b72afcd LOK |
142 | break; |
143 | case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS: | |
004b8382 | 144 | if (m_processor->CECInitialised()) |
3e61b350 | 145 | HandleGiveSystemAudioModeStatus(command); |
6b72afcd LOK |
146 | break; |
147 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST: | |
004b8382 | 148 | if (m_processor->CECInitialised()) |
3e61b350 | 149 | HandleSystemAudioModeRequest(command); |
aa517a0d LOK |
150 | break; |
151 | case CEC_OPCODE_REPORT_AUDIO_STATUS: | |
855a3a98 | 152 | HandleReportAudioStatus(command); |
aa517a0d LOK |
153 | break; |
154 | case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS: | |
855a3a98 | 155 | HandleSystemAudioModeStatus(command); |
aa517a0d LOK |
156 | break; |
157 | case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE: | |
855a3a98 | 158 | HandleSetSystemAudioMode(command); |
6b72afcd LOK |
159 | break; |
160 | case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: | |
004b8382 | 161 | if (m_processor->CECInitialised()) |
3e61b350 | 162 | HandleRequestActiveSource(command); |
6b72afcd LOK |
163 | break; |
164 | case CEC_OPCODE_SET_STREAM_PATH: | |
165 | HandleSetStreamPath(command); | |
166 | break; | |
167 | case CEC_OPCODE_ROUTING_CHANGE: | |
168 | HandleRoutingChange(command); | |
169 | break; | |
907bd60f LOK |
170 | case CEC_OPCODE_ROUTING_INFORMATION: |
171 | HandleRoutingInformation(command); | |
172 | break; | |
6b72afcd | 173 | case CEC_OPCODE_STANDBY: |
004b8382 | 174 | if (m_processor->CECInitialised()) |
3e61b350 | 175 | HandleStandby(command); |
6b72afcd LOK |
176 | break; |
177 | case CEC_OPCODE_ACTIVE_SOURCE: | |
178 | HandleActiveSource(command); | |
179 | break; | |
907bd60f LOK |
180 | case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS: |
181 | HandleReportPhysicalAddress(command); | |
182 | break; | |
15d1a84c LOK |
183 | case CEC_OPCODE_SET_OSD_NAME: |
184 | HandleSetOSDName(command); | |
185 | break; | |
1a6669b8 LOK |
186 | case CEC_OPCODE_IMAGE_VIEW_ON: |
187 | HandleImageViewOn(command); | |
188 | break; | |
189 | case CEC_OPCODE_TEXT_VIEW_ON: | |
190 | HandleTextViewOn(command); | |
191 | break; | |
4d738fe3 LOK |
192 | case CEC_OPCODE_FEATURE_ABORT: |
193 | HandleFeatureAbort(command); | |
194 | break; | |
468a1414 LOK |
195 | case CEC_OPCODE_VENDOR_COMMAND: |
196 | HandleVendorCommand(command); | |
197 | break; | |
6b72afcd | 198 | default: |
e9de9629 | 199 | bHandled = false; |
6b72afcd | 200 | break; |
e9de9629 LOK |
201 | } |
202 | ||
3e61b350 | 203 | if (bHandled) |
24dd566c | 204 | m_waitForResponse->Received((command.opcode == CEC_OPCODE_FEATURE_ABORT && command.parameters.size > 0) ? (cec_opcode)command.parameters[0] : command.opcode); |
004b8382 LOK |
205 | else |
206 | UnhandledCommand(command); | |
8fa35473 | 207 | |
e9de9629 LOK |
208 | return bHandled; |
209 | } | |
210 | ||
be5b0e24 LOK |
211 | bool CCECCommandHandler::HandleActiveSource(const cec_command &command) |
212 | { | |
213 | if (command.parameters.size == 2) | |
214 | { | |
215 | uint16_t iAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
004b8382 LOK |
216 | CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iAddress); |
217 | if (device) | |
218 | device->MarkAsActiveSource(); | |
be5b0e24 LOK |
219 | } |
220 | ||
221 | return true; | |
222 | } | |
223 | ||
a9232a79 LOK |
224 | bool CCECCommandHandler::HandleDeckControl(const cec_command &command) |
225 | { | |
aa40e0e2 LOK |
226 | CCECPlaybackDevice *device = CCECBusDevice::AsPlaybackDevice(GetDevice(command.destination)); |
227 | if (device && command.parameters.size > 0) | |
a9232a79 | 228 | { |
aa40e0e2 | 229 | device->SetDeckControlMode((cec_deck_control_mode) command.parameters[0]); |
a9232a79 LOK |
230 | return true; |
231 | } | |
232 | ||
233 | return false; | |
234 | } | |
235 | ||
6a1c0009 LOK |
236 | bool CCECCommandHandler::HandleDeviceCecVersion(const cec_command &command) |
237 | { | |
238 | if (command.parameters.size == 1) | |
239 | { | |
240 | CCECBusDevice *device = GetDevice(command.initiator); | |
241 | if (device) | |
242 | device->SetCecVersion((cec_version) command.parameters[0]); | |
243 | } | |
244 | ||
245 | return true; | |
246 | } | |
247 | ||
e9de9629 LOK |
248 | bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) |
249 | { | |
0b8c7eab | 250 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
1d2cc194 | 251 | m_processor->TransmitAbort(command.destination, command.initiator, command.opcode, CEC_ABORT_REASON_REFUSED); |
6b72afcd | 252 | |
6a1c0009 | 253 | return true; |
e9de9629 LOK |
254 | } |
255 | ||
256 | bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command) | |
257 | { | |
8fa35473 | 258 | return SetVendorId(command); |
e9de9629 LOK |
259 | } |
260 | ||
4d738fe3 LOK |
261 | bool CCECCommandHandler::HandleFeatureAbort(const cec_command &command) |
262 | { | |
69a1a673 LOK |
263 | if (command.parameters.size == 2 && |
264 | (command.parameters[1] == CEC_ABORT_REASON_UNRECOGNIZED_OPCODE || | |
265 | command.parameters[1] == CEC_ABORT_REASON_REFUSED)) | |
004b8382 | 266 | m_processor->GetDevice(command.initiator)->SetUnsupportedFeature((cec_opcode)command.parameters[0]); |
7de6ad36 | 267 | return true; |
4d738fe3 LOK |
268 | } |
269 | ||
e9de9629 LOK |
270 | bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command) |
271 | { | |
0b8c7eab | 272 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd LOK |
273 | { |
274 | CCECBusDevice *device = GetDevice(command.destination); | |
275 | if (device) | |
276 | return device->TransmitCECVersion(command.initiator); | |
277 | } | |
0f23c85c LOK |
278 | |
279 | return false; | |
e9de9629 LOK |
280 | } |
281 | ||
a1f8fb1b LOK |
282 | bool CCECCommandHandler::HandleGiveAudioStatus(const cec_command &command) |
283 | { | |
0b8c7eab | 284 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd | 285 | { |
aa40e0e2 LOK |
286 | CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.destination)); |
287 | if (device) | |
288 | return device->TransmitAudioStatus(command.initiator); | |
6b72afcd | 289 | } |
a1f8fb1b LOK |
290 | |
291 | return false; | |
292 | } | |
293 | ||
e9de9629 LOK |
294 | bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command) |
295 | { | |
0b8c7eab | 296 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd | 297 | { |
aa40e0e2 LOK |
298 | CCECPlaybackDevice *device = CCECBusDevice::AsPlaybackDevice(GetDevice(command.destination)); |
299 | if (device) | |
300 | return device->TransmitDeckStatus(command.initiator); | |
6b72afcd | 301 | } |
0f23c85c LOK |
302 | |
303 | return false; | |
e9de9629 LOK |
304 | } |
305 | ||
306 | bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) | |
307 | { | |
0b8c7eab | 308 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd LOK |
309 | { |
310 | CCECBusDevice *device = GetDevice(command.destination); | |
311 | if (device) | |
312 | return device->TransmitPowerState(command.initiator); | |
313 | } | |
0f23c85c LOK |
314 | |
315 | return false; | |
e9de9629 LOK |
316 | } |
317 | ||
318 | bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command) | |
319 | { | |
0b8c7eab | 320 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd LOK |
321 | { |
322 | CCECBusDevice *device = GetDevice(command.destination); | |
323 | if (device) | |
324 | return device->TransmitVendorID(command.initiator); | |
325 | } | |
0f23c85c LOK |
326 | |
327 | return false; | |
e9de9629 LOK |
328 | } |
329 | ||
330 | bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command) | |
331 | { | |
0b8c7eab | 332 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd LOK |
333 | { |
334 | CCECBusDevice *device = GetDevice(command.destination); | |
335 | if (device) | |
336 | return device->TransmitOSDName(command.initiator); | |
337 | } | |
0f23c85c LOK |
338 | |
339 | return false; | |
e9de9629 LOK |
340 | } |
341 | ||
342 | bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command) | |
343 | { | |
0b8c7eab | 344 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
6b72afcd LOK |
345 | { |
346 | CCECBusDevice *device = GetDevice(command.destination); | |
347 | if (device) | |
7656096e | 348 | return device->TransmitPhysicalAddress(); |
6b72afcd | 349 | } |
09c10b66 LOK |
350 | |
351 | return false; | |
e9de9629 LOK |
352 | } |
353 | ||
fbdea54c MK |
354 | bool CCECCommandHandler::HandleGiveMenuLanguage(const cec_command &command) |
355 | { | |
0b8c7eab | 356 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
fbdea54c MK |
357 | { |
358 | CCECBusDevice *device = GetDevice(command.destination); | |
359 | if (device) | |
360 | return device->TransmitSetMenuLanguage(command.initiator); | |
361 | } | |
362 | ||
363 | return false; | |
364 | } | |
365 | ||
1a6669b8 LOK |
366 | bool CCECCommandHandler::HandleGiveSystemAudioModeStatus(const cec_command &command) |
367 | { | |
0b8c7eab | 368 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
1a6669b8 | 369 | { |
aa40e0e2 LOK |
370 | CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.destination)); |
371 | if (device) | |
372 | return device->TransmitSystemAudioModeStatus(command.initiator); | |
1a6669b8 LOK |
373 | } |
374 | ||
375 | return false; | |
376 | } | |
377 | ||
378 | bool CCECCommandHandler::HandleImageViewOn(const cec_command &command) | |
379 | { | |
004b8382 | 380 | m_processor->GetDevice(command.initiator)->MarkAsActiveSource(); |
1a6669b8 LOK |
381 | return true; |
382 | } | |
383 | ||
e9de9629 LOK |
384 | bool CCECCommandHandler::HandleMenuRequest(const cec_command &command) |
385 | { | |
0b8c7eab | 386 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
0f23c85c | 387 | { |
e1804a4e LOK |
388 | CCECBusDevice *device = GetDevice(command.destination); |
389 | if (device) | |
6b72afcd | 390 | { |
004b8382 LOK |
391 | CCECClient *client = device->GetClient(); |
392 | if (client) | |
e1804a4e | 393 | { |
004b8382 LOK |
394 | if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_ACTIVATE) |
395 | { | |
396 | if (client->MenuStateChanged(CEC_MENU_STATE_ACTIVATED) == 1) | |
397 | device->SetMenuState(CEC_MENU_STATE_ACTIVATED); | |
398 | } | |
399 | else if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_DEACTIVATE) | |
400 | { | |
401 | if (client->MenuStateChanged(CEC_MENU_STATE_DEACTIVATED) == 1) | |
402 | device->SetMenuState(CEC_MENU_STATE_DEACTIVATED); | |
403 | } | |
e1804a4e LOK |
404 | } |
405 | return device->TransmitMenuState(command.initiator); | |
6b72afcd | 406 | } |
15d1a84c LOK |
407 | } |
408 | ||
409 | return false; | |
410 | } | |
411 | ||
d297cbd4 LOK |
412 | bool CCECCommandHandler::HandlePoll(const cec_command &command) |
413 | { | |
a75e3a5a | 414 | m_busDevice->HandlePoll(command.destination); |
d297cbd4 LOK |
415 | return true; |
416 | } | |
417 | ||
15d1a84c LOK |
418 | bool CCECCommandHandler::HandleReportAudioStatus(const cec_command &command) |
419 | { | |
420 | if (command.parameters.size == 1) | |
421 | { | |
aa40e0e2 LOK |
422 | CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.initiator)); |
423 | if (device) | |
6b72afcd | 424 | { |
aa40e0e2 | 425 | device->SetAudioStatus(command.parameters[0]); |
15d1a84c | 426 | return true; |
6b72afcd | 427 | } |
0f23c85c LOK |
428 | } |
429 | return false; | |
e9de9629 LOK |
430 | } |
431 | ||
907bd60f LOK |
432 | bool CCECCommandHandler::HandleReportPhysicalAddress(const cec_command &command) |
433 | { | |
0bfce006 | 434 | if (command.parameters.size == 3) |
907bd60f LOK |
435 | { |
436 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
16b1e052 | 437 | SetPhysicalAddress(command.initiator, iNewAddress); |
907bd60f LOK |
438 | } |
439 | return true; | |
440 | } | |
441 | ||
e55f3f70 LOK |
442 | bool CCECCommandHandler::HandleReportPowerStatus(const cec_command &command) |
443 | { | |
444 | if (command.parameters.size == 1) | |
445 | { | |
446 | CCECBusDevice *device = GetDevice(command.initiator); | |
447 | if (device) | |
448 | device->SetPowerStatus((cec_power_status) command.parameters[0]); | |
449 | } | |
450 | return true; | |
451 | } | |
452 | ||
e9de9629 LOK |
453 | bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) |
454 | { | |
0b8c7eab | 455 | if (m_processor->CECInitialised()) |
5f316715 | 456 | { |
004b8382 LOK |
457 | LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %i requests active source", (uint8_t) command.initiator); |
458 | m_processor->GetDevice(command.initiator)->SetPowerStatus(CEC_POWER_STATUS_ON); | |
8747dd4f | 459 | |
5f316715 | 460 | vector<CCECBusDevice *> devices; |
f00ff009 | 461 | for (size_t iDevicePtr = 0; iDevicePtr < GetMyDevices(devices); iDevicePtr++) |
5f316715 | 462 | devices[iDevicePtr]->TransmitActiveSource(); |
c4098482 | 463 | |
5f316715 LOK |
464 | return true; |
465 | } | |
466 | return false; | |
e9de9629 LOK |
467 | } |
468 | ||
469 | bool CCECCommandHandler::HandleRoutingChange(const cec_command &command) | |
470 | { | |
471 | if (command.parameters.size == 4) | |
472 | { | |
473 | uint16_t iOldAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
474 | uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]); | |
e9de9629 | 475 | |
0f23c85c LOK |
476 | CCECBusDevice *device = GetDevice(command.initiator); |
477 | if (device) | |
9dc04b07 | 478 | device->SetStreamPath(iNewAddress, iOldAddress); |
e9de9629 LOK |
479 | } |
480 | return true; | |
481 | } | |
482 | ||
907bd60f LOK |
483 | bool CCECCommandHandler::HandleRoutingInformation(const cec_command &command) |
484 | { | |
485 | if (command.parameters.size == 2) | |
486 | { | |
487 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
004b8382 LOK |
488 | CCECBusDevice *device = m_processor->GetDeviceByPhysicalAddress(iNewAddress); |
489 | if (device) | |
490 | device->MarkAsActiveSource(); | |
907bd60f | 491 | } |
15d1a84c LOK |
492 | |
493 | return false; | |
907bd60f LOK |
494 | } |
495 | ||
a3269a0a LOK |
496 | bool CCECCommandHandler::HandleSetMenuLanguage(const cec_command &command) |
497 | { | |
498 | if (command.parameters.size == 3) | |
499 | { | |
500 | CCECBusDevice *device = GetDevice(command.initiator); | |
501 | if (device) | |
502 | { | |
503 | cec_menu_language language; | |
504 | language.device = command.initiator; | |
56701628 | 505 | for (uint8_t iPtr = 0; iPtr < 4; iPtr++) |
a3269a0a LOK |
506 | language.language[iPtr] = command.parameters[iPtr]; |
507 | language.language[3] = 0; | |
508 | device->SetMenuLanguage(language); | |
15d1a84c LOK |
509 | return true; |
510 | } | |
511 | } | |
512 | return false; | |
513 | } | |
514 | ||
515 | bool CCECCommandHandler::HandleSetOSDName(const cec_command &command) | |
516 | { | |
517 | if (command.parameters.size > 0) | |
518 | { | |
519 | CCECBusDevice *device = GetDevice(command.initiator); | |
520 | if (device) | |
521 | { | |
522 | char buf[1024]; | |
523 | for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++) | |
524 | buf[iPtr] = (char)command.parameters[iPtr]; | |
525 | buf[command.parameters.size] = 0; | |
526 | ||
527 | CStdString strName(buf); | |
528 | device->SetOSDName(strName); | |
6b72afcd | 529 | |
15d1a84c | 530 | return true; |
a3269a0a LOK |
531 | } |
532 | } | |
15d1a84c | 533 | return false; |
a3269a0a LOK |
534 | } |
535 | ||
e9de9629 LOK |
536 | bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) |
537 | { | |
0b8c7eab | 538 | if (m_processor->CECInitialised() && command.parameters.size >= 2) |
e9de9629 | 539 | { |
b6c7bc94 | 540 | uint16_t iStreamAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); |
004b8382 | 541 | LIB_CEC->AddLog(CEC_LOG_DEBUG, ">> %i sets stream path to physical address %04x", command.initiator, iStreamAddress); |
72689600 LOK |
542 | |
543 | /* one of the device handled by libCEC has been made active */ | |
544 | CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamAddress); | |
004b8382 LOK |
545 | if (device && device->IsHandledByLibCEC()) |
546 | device->ActivateSource(); | |
e9de9629 | 547 | } |
15d1a84c | 548 | return false; |
e9de9629 LOK |
549 | } |
550 | ||
aa517a0d | 551 | bool CCECCommandHandler::HandleSystemAudioModeRequest(const cec_command &command) |
e5e86c76 | 552 | { |
0b8c7eab | 553 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
e5e86c76 | 554 | { |
aa40e0e2 LOK |
555 | CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.destination)); |
556 | if (device) | |
aa517a0d LOK |
557 | { |
558 | if (command.parameters.size >= 2) | |
559 | { | |
560 | device->SetPowerStatus(CEC_POWER_STATUS_ON); | |
aa40e0e2 | 561 | device->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_ON); |
aa517a0d LOK |
562 | uint16_t iNewAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); |
563 | CCECBusDevice *newActiveDevice = GetDeviceByPhysicalAddress(iNewAddress); | |
564 | if (newActiveDevice) | |
004b8382 | 565 | newActiveDevice->MarkAsActiveSource(); |
aa40e0e2 | 566 | return device->TransmitSetSystemAudioMode(command.initiator); |
aa517a0d LOK |
567 | } |
568 | else | |
569 | { | |
aa40e0e2 LOK |
570 | device->SetSystemAudioModeStatus(CEC_SYSTEM_AUDIO_STATUS_OFF); |
571 | return device->TransmitSetSystemAudioMode(command.initiator); | |
aa517a0d LOK |
572 | } |
573 | } | |
e5e86c76 | 574 | } |
6b72afcd | 575 | return false; |
e5e86c76 LOK |
576 | } |
577 | ||
4d6b4433 LOK |
578 | bool CCECCommandHandler::HandleStandby(const cec_command &command) |
579 | { | |
580 | CCECBusDevice *device = GetDevice(command.initiator); | |
581 | if (device) | |
582 | device->SetPowerStatus(CEC_POWER_STATUS_STANDBY); | |
6b72afcd | 583 | |
4d6b4433 LOK |
584 | return true; |
585 | } | |
586 | ||
aa517a0d | 587 | bool CCECCommandHandler::HandleSystemAudioModeStatus(const cec_command &command) |
868dc71f | 588 | { |
aa517a0d | 589 | if (command.parameters.size == 1) |
868dc71f | 590 | { |
aa40e0e2 LOK |
591 | CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.initiator)); |
592 | if (device) | |
aa517a0d | 593 | { |
aa40e0e2 | 594 | device->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); |
aa517a0d LOK |
595 | return true; |
596 | } | |
597 | } | |
598 | ||
599 | return false; | |
600 | } | |
601 | ||
602 | bool CCECCommandHandler::HandleSetSystemAudioMode(const cec_command &command) | |
603 | { | |
604 | if (command.parameters.size == 1) | |
605 | { | |
aa40e0e2 LOK |
606 | CCECAudioSystem *device = CCECBusDevice::AsAudioSystem(GetDevice(command.initiator)); |
607 | if (device) | |
aa517a0d | 608 | { |
aa40e0e2 | 609 | device->SetSystemAudioModeStatus((cec_system_audio_status)command.parameters[0]); |
aa517a0d LOK |
610 | return true; |
611 | } | |
868dc71f LOK |
612 | } |
613 | ||
614 | return false; | |
615 | } | |
616 | ||
1a6669b8 | 617 | bool CCECCommandHandler::HandleTextViewOn(const cec_command &command) |
cf0ecd85 | 618 | { |
004b8382 | 619 | m_processor->GetDevice(command.initiator)->MarkAsActiveSource(); |
1a6669b8 | 620 | return true; |
cf0ecd85 LOK |
621 | } |
622 | ||
e9de9629 LOK |
623 | bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) |
624 | { | |
0b8c7eab | 625 | if (m_processor->CECInitialised() && |
004b8382 | 626 | m_processor->IsHandledByLibCEC(command.destination) && |
e33e0d75 | 627 | command.parameters.size > 0) |
e9de9629 | 628 | { |
004b8382 LOK |
629 | CCECBusDevice *device = GetDevice(command.destination); |
630 | if (!device) | |
631 | return true; | |
632 | ||
633 | CCECClient *client = device->GetClient(); | |
634 | if (client) | |
635 | client->AddKey(); | |
636 | ||
e9de9629 | 637 | if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX) |
004b8382 | 638 | client->SetCurrentButton((cec_user_control_code) command.parameters[0]); |
e33e0d75 MK |
639 | |
640 | if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER || | |
641 | command.parameters[0] == CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION) | |
e9de9629 | 642 | { |
e33e0d75 | 643 | bool bPowerOn(true); |
e33e0d75 MK |
644 | if (!device) |
645 | return true; | |
646 | ||
647 | // CEC_USER_CONTROL_CODE_POWER operates as a toggle | |
648 | // assume CEC_USER_CONTROL_CODE_POWER_ON_FUNCTION does not | |
649 | if (command.parameters[0] == CEC_USER_CONTROL_CODE_POWER) | |
68391d4f | 650 | { |
004b8382 | 651 | cec_power_status status = device->GetCurrentPowerStatus(); |
e33e0d75 MK |
652 | bPowerOn = !(status == CEC_POWER_STATUS_ON || status == CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON); |
653 | } | |
654 | ||
655 | if (bPowerOn) | |
656 | { | |
004b8382 | 657 | device->ActivateSource(); |
68391d4f | 658 | } |
d1ab114f LOK |
659 | else |
660 | { | |
004b8382 | 661 | device->MarkAsInactiveSource(); |
e33e0d75 MK |
662 | device->TransmitInactiveSource(); |
663 | device->SetMenuState(CEC_MENU_STATE_DEACTIVATED); | |
d1ab114f | 664 | } |
e9de9629 | 665 | } |
e33e0d75 MK |
666 | |
667 | return true; | |
e9de9629 | 668 | } |
15d1a84c | 669 | return false; |
e9de9629 LOK |
670 | } |
671 | ||
672 | bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command) | |
673 | { | |
004b8382 LOK |
674 | CCECClient *client = m_processor->GetClient(command.destination); |
675 | if (client) | |
676 | client->AddKey(); | |
e9de9629 LOK |
677 | return true; |
678 | } | |
679 | ||
1de6617c LOK |
680 | bool CCECCommandHandler::HandleVendorCommand(const cec_command & UNUSED(command)) |
681 | { | |
682 | return true; | |
683 | } | |
684 | ||
e9de9629 LOK |
685 | void CCECCommandHandler::UnhandledCommand(const cec_command &command) |
686 | { | |
004b8382 LOK |
687 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "unhandled command with opcode %02x from address %d", command.opcode, command.initiator); |
688 | ||
0b8c7eab | 689 | if (m_processor->CECInitialised() && m_processor->IsHandledByLibCEC(command.destination)) |
004b8382 | 690 | m_processor->TransmitAbort(m_busDevice->GetLogicalAddress(), command.initiator, command.opcode, CEC_ABORT_REASON_UNRECOGNIZED_OPCODE); |
0f23c85c LOK |
691 | } |
692 | ||
6f14b512 | 693 | size_t CCECCommandHandler::GetMyDevices(vector<CCECBusDevice *> &devices) const |
8747dd4f | 694 | { |
6f14b512 | 695 | size_t iReturn(0); |
8747dd4f | 696 | |
fcf10e27 | 697 | cec_logical_addresses addresses = m_processor->GetLogicalAddresses(); |
d2d1660c | 698 | for (uint8_t iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++) |
8747dd4f LOK |
699 | { |
700 | if (addresses[iPtr]) | |
701 | { | |
702 | devices.push_back(GetDevice((cec_logical_address) iPtr)); | |
703 | ++iReturn; | |
704 | } | |
705 | } | |
706 | ||
707 | return iReturn; | |
708 | } | |
709 | ||
0f23c85c LOK |
710 | CCECBusDevice *CCECCommandHandler::GetDevice(cec_logical_address iLogicalAddress) const |
711 | { | |
004b8382 | 712 | return m_processor->GetDevice(iLogicalAddress); |
e9de9629 | 713 | } |
6685ae07 LOK |
714 | |
715 | CCECBusDevice *CCECCommandHandler::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const | |
716 | { | |
fcf10e27 | 717 | return m_processor->GetDeviceByPhysicalAddress(iPhysicalAddress); |
6685ae07 | 718 | } |
181b3475 | 719 | |
8fa35473 | 720 | bool CCECCommandHandler::SetVendorId(const cec_command &command) |
181b3475 | 721 | { |
8fa35473 | 722 | bool bChanged(false); |
181b3475 LOK |
723 | if (command.parameters.size < 3) |
724 | { | |
004b8382 | 725 | LIB_CEC->AddLog(CEC_LOG_WARNING, "invalid vendor ID received"); |
8fa35473 | 726 | return bChanged; |
181b3475 LOK |
727 | } |
728 | ||
bae71306 LOK |
729 | uint64_t iVendorId = ((uint64_t)command.parameters[0] << 16) + |
730 | ((uint64_t)command.parameters[1] << 8) + | |
181b3475 LOK |
731 | (uint64_t)command.parameters[2]; |
732 | ||
733 | CCECBusDevice *device = GetDevice((cec_logical_address) command.initiator); | |
734 | if (device) | |
8fa35473 LOK |
735 | bChanged = device->SetVendorId(iVendorId); |
736 | return bChanged; | |
181b3475 | 737 | } |
5e822b09 | 738 | |
16b1e052 LOK |
739 | void CCECCommandHandler::SetPhysicalAddress(cec_logical_address iAddress, uint16_t iNewAddress) |
740 | { | |
004b8382 | 741 | if (!m_processor->IsHandledByLibCEC(iAddress)) |
16b1e052 | 742 | { |
c0152c09 LOK |
743 | CCECBusDevice *otherDevice = m_processor->GetDeviceByPhysicalAddress(iNewAddress); |
744 | CCECClient *client = otherDevice ? otherDevice->GetClient() : NULL; | |
004b8382 | 745 | |
c0152c09 LOK |
746 | CCECBusDevice *device = m_processor->GetDevice(iAddress); |
747 | if (device) | |
748 | device->SetPhysicalAddress(iNewAddress); | |
749 | else | |
16b1e052 | 750 | { |
c0152c09 | 751 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "device with logical address %X not found", iAddress); |
16b1e052 | 752 | } |
c0152c09 LOK |
753 | |
754 | /* another device reported the same physical address as ours */ | |
755 | if (client) | |
756 | client->ResetPhysicalAddress(); | |
757 | } | |
758 | else | |
759 | { | |
760 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "ignore physical address report for device %s (%X) because it's marked as handled by libCEC", ToString(iAddress), iAddress); | |
16b1e052 LOK |
761 | } |
762 | } | |
855a3a98 | 763 | |
f4698390 LOK |
764 | bool CCECCommandHandler::PowerOn(const cec_logical_address iInitiator, const cec_logical_address iDestination) |
765 | { | |
766 | if (iDestination == CECDEVICE_TV) | |
767 | return TransmitImageViewOn(iInitiator, iDestination); | |
768 | ||
769 | return TransmitKeypress(iInitiator, iDestination, CEC_USER_CONTROL_CODE_POWER) && | |
770 | TransmitKeyRelease(iInitiator, iDestination); | |
771 | } | |
772 | ||
b64db02e | 773 | bool CCECCommandHandler::TransmitImageViewOn(const cec_logical_address iInitiator, const cec_logical_address iDestination) |
8fa35473 LOK |
774 | { |
775 | cec_command command; | |
ae693aaa | 776 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_IMAGE_VIEW_ON); |
8fa35473 | 777 | |
4fde2fd0 | 778 | return Transmit(command); |
8fa35473 LOK |
779 | } |
780 | ||
781 | bool CCECCommandHandler::TransmitStandby(const cec_logical_address iInitiator, const cec_logical_address iDestination) | |
782 | { | |
783 | cec_command command; | |
ae693aaa | 784 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_STANDBY); |
8fa35473 | 785 | |
4fde2fd0 | 786 | return Transmit(command); |
8fa35473 LOK |
787 | } |
788 | ||
5734016c LOK |
789 | bool CCECCommandHandler::TransmitRequestActiveSource(const cec_logical_address iInitiator, bool bWaitForResponse /* = true */) |
790 | { | |
791 | cec_command command; | |
792 | cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_REQUEST_ACTIVE_SOURCE); | |
793 | ||
794 | return Transmit(command, !bWaitForResponse); | |
795 | } | |
796 | ||
a75e3a5a | 797 | bool CCECCommandHandler::TransmitRequestCecVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) |
8fa35473 LOK |
798 | { |
799 | cec_command command; | |
ae693aaa | 800 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_CEC_VERSION); |
8fa35473 | 801 | |
4fde2fd0 | 802 | return Transmit(command, !bWaitForResponse); |
8fa35473 LOK |
803 | } |
804 | ||
a75e3a5a | 805 | bool CCECCommandHandler::TransmitRequestMenuLanguage(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) |
8fa35473 LOK |
806 | { |
807 | cec_command command; | |
ae693aaa | 808 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GET_MENU_LANGUAGE); |
8fa35473 | 809 | |
4fde2fd0 | 810 | return Transmit(command, !bWaitForResponse); |
8fa35473 LOK |
811 | } |
812 | ||
a75e3a5a | 813 | bool CCECCommandHandler::TransmitRequestOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) |
8fa35473 LOK |
814 | { |
815 | cec_command command; | |
ae693aaa | 816 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_OSD_NAME); |
8fa35473 | 817 | |
4fde2fd0 | 818 | return Transmit(command, !bWaitForResponse); |
8fa35473 LOK |
819 | } |
820 | ||
a75e3a5a | 821 | bool CCECCommandHandler::TransmitRequestPhysicalAddress(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) |
8fa35473 LOK |
822 | { |
823 | cec_command command; | |
ae693aaa | 824 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_PHYSICAL_ADDRESS); |
8fa35473 | 825 | |
4fde2fd0 | 826 | return Transmit(command, !bWaitForResponse); |
8fa35473 LOK |
827 | } |
828 | ||
a75e3a5a | 829 | bool CCECCommandHandler::TransmitRequestPowerStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) |
8fa35473 LOK |
830 | { |
831 | cec_command command; | |
ae693aaa | 832 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_POWER_STATUS); |
8fa35473 | 833 | |
4fde2fd0 | 834 | return Transmit(command, !bWaitForResponse); |
8fa35473 LOK |
835 | } |
836 | ||
a75e3a5a | 837 | bool CCECCommandHandler::TransmitRequestVendorId(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWaitForResponse /* = true */) |
8fa35473 LOK |
838 | { |
839 | cec_command command; | |
ae693aaa | 840 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_GIVE_DEVICE_VENDOR_ID); |
8fa35473 | 841 | |
4fde2fd0 | 842 | return Transmit(command, !bWaitForResponse); |
8fa35473 LOK |
843 | } |
844 | ||
845 | bool CCECCommandHandler::TransmitActiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress) | |
846 | { | |
847 | cec_command command; | |
ae693aaa | 848 | cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_ACTIVE_SOURCE); |
8fa35473 LOK |
849 | command.parameters.PushBack((uint8_t) ((iPhysicalAddress >> 8) & 0xFF)); |
850 | command.parameters.PushBack((uint8_t) (iPhysicalAddress & 0xFF)); | |
851 | ||
4fde2fd0 | 852 | return Transmit(command); |
8fa35473 LOK |
853 | } |
854 | ||
855 | bool CCECCommandHandler::TransmitCECVersion(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_version cecVersion) | |
856 | { | |
857 | cec_command command; | |
ae693aaa | 858 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_CEC_VERSION); |
8fa35473 LOK |
859 | command.parameters.PushBack((uint8_t)cecVersion); |
860 | ||
4fde2fd0 | 861 | return Transmit(command); |
8fa35473 LOK |
862 | } |
863 | ||
864 | bool CCECCommandHandler::TransmitInactiveSource(const cec_logical_address iInitiator, uint16_t iPhysicalAddress) | |
865 | { | |
866 | cec_command command; | |
ae693aaa | 867 | cec_command::Format(command, iInitiator, CECDEVICE_TV, CEC_OPCODE_INACTIVE_SOURCE); |
8fa35473 LOK |
868 | command.parameters.PushBack((iPhysicalAddress >> 8) & 0xFF); |
869 | command.parameters.PushBack(iPhysicalAddress & 0xFF); | |
870 | ||
4fde2fd0 | 871 | return Transmit(command); |
8fa35473 LOK |
872 | } |
873 | ||
874 | bool CCECCommandHandler::TransmitMenuState(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_menu_state menuState) | |
875 | { | |
876 | cec_command command; | |
ae693aaa | 877 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_MENU_STATUS); |
8fa35473 LOK |
878 | command.parameters.PushBack((uint8_t)menuState); |
879 | ||
4fde2fd0 | 880 | return Transmit(command); |
8fa35473 LOK |
881 | } |
882 | ||
883 | bool CCECCommandHandler::TransmitOSDName(const cec_logical_address iInitiator, const cec_logical_address iDestination, CStdString strDeviceName) | |
884 | { | |
885 | cec_command command; | |
ae693aaa | 886 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_NAME); |
6f14b512 | 887 | for (size_t iPtr = 0; iPtr < strDeviceName.length(); iPtr++) |
8fa35473 LOK |
888 | command.parameters.PushBack(strDeviceName.at(iPtr)); |
889 | ||
4fde2fd0 | 890 | return Transmit(command); |
8fa35473 LOK |
891 | } |
892 | ||
893 | bool CCECCommandHandler::TransmitOSDString(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_display_control duration, const char *strMessage) | |
894 | { | |
895 | cec_command command; | |
ae693aaa | 896 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_OSD_STRING); |
8fa35473 LOK |
897 | command.parameters.PushBack((uint8_t)duration); |
898 | ||
6f14b512 | 899 | size_t iLen = strlen(strMessage); |
8fa35473 LOK |
900 | if (iLen > 13) iLen = 13; |
901 | ||
6f14b512 | 902 | for (size_t iPtr = 0; iPtr < iLen; iPtr++) |
8fa35473 LOK |
903 | command.parameters.PushBack(strMessage[iPtr]); |
904 | ||
4fde2fd0 | 905 | return Transmit(command); |
8fa35473 LOK |
906 | } |
907 | ||
908 | bool CCECCommandHandler::TransmitPhysicalAddress(const cec_logical_address iInitiator, uint16_t iPhysicalAddress, cec_device_type type) | |
909 | { | |
910 | cec_command command; | |
ae693aaa | 911 | cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_REPORT_PHYSICAL_ADDRESS); |
8fa35473 LOK |
912 | command.parameters.PushBack((uint8_t) ((iPhysicalAddress >> 8) & 0xFF)); |
913 | command.parameters.PushBack((uint8_t) (iPhysicalAddress & 0xFF)); | |
914 | command.parameters.PushBack((uint8_t) (type)); | |
915 | ||
4fde2fd0 | 916 | return Transmit(command); |
fbdea54c MK |
917 | } |
918 | ||
919 | bool CCECCommandHandler::TransmitSetMenuLanguage(const cec_logical_address iInitiator, const char lang[3]) | |
920 | { | |
921 | cec_command command; | |
922 | command.Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_SET_MENU_LANGUAGE); | |
923 | command.parameters.PushBack((uint8_t) lang[0]); | |
924 | command.parameters.PushBack((uint8_t) lang[1]); | |
925 | command.parameters.PushBack((uint8_t) lang[2]); | |
926 | ||
4fde2fd0 | 927 | return Transmit(command); |
8fa35473 LOK |
928 | } |
929 | ||
930 | bool CCECCommandHandler::TransmitPoll(const cec_logical_address iInitiator, const cec_logical_address iDestination) | |
931 | { | |
932 | cec_command command; | |
ae693aaa | 933 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_NONE); |
8fa35473 | 934 | |
4fde2fd0 | 935 | return Transmit(command); |
8fa35473 LOK |
936 | } |
937 | ||
938 | bool CCECCommandHandler::TransmitPowerState(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_power_status state) | |
939 | { | |
940 | cec_command command; | |
ae693aaa | 941 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_REPORT_POWER_STATUS); |
8fa35473 LOK |
942 | command.parameters.PushBack((uint8_t) state); |
943 | ||
4fde2fd0 | 944 | return Transmit(command); |
8fa35473 LOK |
945 | } |
946 | ||
947 | bool CCECCommandHandler::TransmitVendorID(const cec_logical_address iInitiator, uint64_t iVendorId) | |
948 | { | |
949 | cec_command command; | |
ae693aaa | 950 | cec_command::Format(command, iInitiator, CECDEVICE_BROADCAST, CEC_OPCODE_DEVICE_VENDOR_ID); |
8fa35473 LOK |
951 | |
952 | command.parameters.PushBack((uint8_t) (((uint64_t)iVendorId >> 16) & 0xFF)); | |
953 | command.parameters.PushBack((uint8_t) (((uint64_t)iVendorId >> 8) & 0xFF)); | |
954 | command.parameters.PushBack((uint8_t) ((uint64_t)iVendorId & 0xFF)); | |
955 | ||
4fde2fd0 | 956 | return Transmit(command); |
8fa35473 LOK |
957 | } |
958 | ||
959 | bool CCECCommandHandler::TransmitAudioStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, uint8_t state) | |
960 | { | |
961 | cec_command command; | |
ae693aaa | 962 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_REPORT_AUDIO_STATUS); |
8fa35473 LOK |
963 | command.parameters.PushBack(state); |
964 | ||
4fde2fd0 | 965 | return Transmit(command); |
8fa35473 LOK |
966 | } |
967 | ||
968 | bool CCECCommandHandler::TransmitSetSystemAudioMode(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state) | |
969 | { | |
970 | cec_command command; | |
ae693aaa | 971 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SET_SYSTEM_AUDIO_MODE); |
8fa35473 LOK |
972 | command.parameters.PushBack((uint8_t)state); |
973 | ||
4fde2fd0 | 974 | return Transmit(command); |
8fa35473 LOK |
975 | } |
976 | ||
f42d3e0f LOK |
977 | bool CCECCommandHandler::TransmitSetStreamPath(uint16_t iStreamPath) |
978 | { | |
979 | cec_command command; | |
980 | cec_command::Format(command, m_busDevice->GetLogicalAddress(), CECDEVICE_BROADCAST, CEC_OPCODE_SET_STREAM_PATH); | |
981 | command.parameters.PushBack((uint8_t) ((iStreamPath >> 8) & 0xFF)); | |
982 | command.parameters.PushBack((uint8_t) (iStreamPath & 0xFF)); | |
983 | ||
4fde2fd0 | 984 | return Transmit(command); |
f42d3e0f LOK |
985 | } |
986 | ||
8fa35473 LOK |
987 | bool CCECCommandHandler::TransmitSystemAudioModeStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_system_audio_status state) |
988 | { | |
989 | cec_command command; | |
ae693aaa | 990 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS); |
8fa35473 LOK |
991 | command.parameters.PushBack((uint8_t)state); |
992 | ||
4fde2fd0 | 993 | return Transmit(command); |
8fa35473 LOK |
994 | } |
995 | ||
996 | bool CCECCommandHandler::TransmitDeckStatus(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_deck_info state) | |
997 | { | |
998 | cec_command command; | |
ae693aaa | 999 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_DECK_STATUS); |
8fa35473 LOK |
1000 | command.PushBack((uint8_t)state); |
1001 | ||
4fde2fd0 | 1002 | return Transmit(command); |
8fa35473 LOK |
1003 | } |
1004 | ||
4bec9d79 | 1005 | bool CCECCommandHandler::TransmitKeypress(const cec_logical_address iInitiator, const cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */) |
8fa35473 LOK |
1006 | { |
1007 | cec_command command; | |
ae693aaa | 1008 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_PRESSED); |
8fa35473 LOK |
1009 | command.parameters.PushBack((uint8_t)key); |
1010 | ||
4fde2fd0 | 1011 | return Transmit(command, !bWait); |
8fa35473 LOK |
1012 | } |
1013 | ||
4bec9d79 | 1014 | bool CCECCommandHandler::TransmitKeyRelease(const cec_logical_address iInitiator, const cec_logical_address iDestination, bool bWait /* = true */) |
8fa35473 LOK |
1015 | { |
1016 | cec_command command; | |
ae693aaa | 1017 | cec_command::Format(command, iInitiator, iDestination, CEC_OPCODE_USER_CONTROL_RELEASE); |
8fa35473 | 1018 | |
4fde2fd0 | 1019 | return Transmit(command, !bWait); |
8fa35473 LOK |
1020 | } |
1021 | ||
4fde2fd0 | 1022 | bool CCECCommandHandler::Transmit(cec_command &command, bool bSuppressWait /* = false */) |
8fa35473 | 1023 | { |
b64db02e | 1024 | bool bReturn(false); |
4fde2fd0 LOK |
1025 | cec_opcode expectedResponse(cec_command::GetResponseOpcode(command.opcode)); |
1026 | bool bExpectResponse(expectedResponse != CEC_OPCODE_NONE && !bSuppressWait); | |
ae693aaa | 1027 | command.transmit_timeout = m_iTransmitTimeout; |
ae693aaa | 1028 | |
7e4558f1 LOK |
1029 | if (command.initiator == CECDEVICE_UNKNOWN) |
1030 | { | |
004b8382 | 1031 | LIB_CEC->AddLog(CEC_LOG_ERROR, "not transmitting a command without a valid initiator"); |
7e4558f1 LOK |
1032 | return bReturn; |
1033 | } | |
1034 | ||
ae693aaa | 1035 | { |
6c0ccaa5 | 1036 | uint8_t iTries(0), iMaxTries(!command.opcode_set ? 1 : m_iTransmitRetries + 1); |
ec15344c | 1037 | while (!bReturn && ++iTries <= iMaxTries && !m_busDevice->IsUnsupportedFeature(command.opcode)) |
b64db02e | 1038 | { |
99666519 | 1039 | if ((bReturn = m_processor->Transmit(command)) == true) |
19cbfa8f | 1040 | { |
004b8382 | 1041 | LIB_CEC->AddLog(CEC_LOG_DEBUG, "command transmitted"); |
4478bc79 | 1042 | if (bExpectResponse) |
24dd566c LOK |
1043 | { |
1044 | bReturn = m_waitForResponse->Wait(expectedResponse); | |
004b8382 | 1045 | LIB_CEC->AddLog(CEC_LOG_DEBUG, bReturn ? "expected response received (%X: %s)" : "expected response not received (%X: %s)", (int)expectedResponse, ToString(expectedResponse)); |
24dd566c | 1046 | } |
19cbfa8f | 1047 | } |
b64db02e | 1048 | } |
ae693aaa | 1049 | } |
8fa35473 | 1050 | |
b64db02e | 1051 | return bReturn; |
8fa35473 | 1052 | } |
83be0701 | 1053 | |
3e61b350 | 1054 | bool CCECCommandHandler::ActivateSource(void) |
83be0701 | 1055 | { |
c4287bcd | 1056 | if (m_busDevice->IsActiveSource() && |
004b8382 | 1057 | m_busDevice->IsHandledByLibCEC()) |
c4287bcd LOK |
1058 | { |
1059 | m_busDevice->SetPowerStatus(CEC_POWER_STATUS_ON); | |
1060 | m_busDevice->SetMenuState(CEC_MENU_STATE_ACTIVATED); | |
1061 | ||
1062 | m_busDevice->TransmitImageViewOn(); | |
1063 | m_busDevice->TransmitActiveSource(); | |
1064 | m_busDevice->TransmitMenuState(CECDEVICE_TV); | |
aa40e0e2 LOK |
1065 | |
1066 | CCECPlaybackDevice *playbackDevice = m_busDevice->AsPlaybackDevice(); | |
1067 | if (playbackDevice && SendDeckStatusUpdateOnActiveSource()) | |
1068 | playbackDevice->TransmitDeckStatus(CECDEVICE_TV); | |
c4287bcd | 1069 | m_bHandlerInited = true; |
83be0701 | 1070 | } |
7dc58c9f | 1071 | return true; |
83be0701 | 1072 | } |
b499cf16 LOK |
1073 | |
1074 | void CCECCommandHandler::SignalOpcode(cec_opcode opcode) | |
1075 | { | |
1076 | m_waitForResponse->Received(opcode); | |
1077 | } |