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