cec-client: fixed entering bootloader mode
[deb_libcec.git] / src / lib / CECProcessor.cpp
1 /*
2 * This file is part of the libCEC(R) library.
3 *
4 * libCEC(R) is Copyright (C) 2011-2012 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 "CECProcessor.h"
34
35 #include "adapter/USBCECAdapterCommunication.h"
36 #include "devices/CECBusDevice.h"
37 #include "devices/CECAudioSystem.h"
38 #include "devices/CECPlaybackDevice.h"
39 #include "devices/CECRecordingDevice.h"
40 #include "devices/CECTuner.h"
41 #include "devices/CECTV.h"
42 #include "implementations/CECCommandHandler.h"
43 #include "LibCEC.h"
44 #include "platform/util/timeutils.h"
45
46 using namespace CEC;
47 using namespace std;
48 using namespace PLATFORM;
49
50 #define CEC_PROCESSOR_SIGNAL_WAIT_TIME 1000
51
52 CCECProcessor::CCECProcessor(CLibCEC *controller, libcec_configuration *configuration) :
53 m_bConnectionOpened(false),
54 m_bInitialised(false),
55 m_communication(NULL),
56 m_controller(controller),
57 m_bMonitor(false),
58 m_iStandardLineTimeout(3),
59 m_iRetryLineTimeout(3),
60 m_iLastTransmission(0)
61 {
62 CreateBusDevices();
63 m_configuration.Clear();
64 m_configuration.serverVersion = LIBCEC_VERSION_CURRENT;
65 SetConfiguration(configuration);
66
67 if (m_configuration.tvVendor != CEC_VENDOR_UNKNOWN)
68 m_busDevices[CECDEVICE_TV]->ReplaceHandler(false);
69 }
70
71 CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types, uint16_t iPhysicalAddress) :
72 m_bConnectionOpened(false),
73 m_bInitialised(false),
74 m_communication(NULL),
75 m_controller(controller),
76 m_bMonitor(false),
77 m_iStandardLineTimeout(3),
78 m_iRetryLineTimeout(3),
79 m_iLastTransmission(0)
80 {
81 m_configuration.Clear();
82 m_configuration.serverVersion = LIBCEC_VERSION_CURRENT;
83
84 // client version < 1.5.0
85 m_configuration.clientVersion = (uint32_t)CEC_CLIENT_VERSION_PRE_1_5;
86 snprintf(m_configuration.strDeviceName, 13, "%s", strDeviceName);
87 m_configuration.deviceTypes = types;
88 m_configuration.iPhysicalAddress = iPhysicalAddress;
89 m_configuration.baseDevice = (cec_logical_address)CEC_DEFAULT_BASE_DEVICE;
90 m_configuration.iHDMIPort = CEC_DEFAULT_HDMI_PORT;
91
92 if (m_configuration.deviceTypes.IsEmpty())
93 m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
94 CreateBusDevices();
95 }
96
97 void CCECProcessor::CreateBusDevices(void)
98 {
99 for (int iPtr = 0; iPtr < 16; iPtr++)
100 {
101 switch(iPtr)
102 {
103 case CECDEVICE_AUDIOSYSTEM:
104 m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
105 break;
106 case CECDEVICE_PLAYBACKDEVICE1:
107 case CECDEVICE_PLAYBACKDEVICE2:
108 case CECDEVICE_PLAYBACKDEVICE3:
109 m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
110 break;
111 case CECDEVICE_RECORDINGDEVICE1:
112 case CECDEVICE_RECORDINGDEVICE2:
113 case CECDEVICE_RECORDINGDEVICE3:
114 m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
115 break;
116 case CECDEVICE_TUNER1:
117 case CECDEVICE_TUNER2:
118 case CECDEVICE_TUNER3:
119 case CECDEVICE_TUNER4:
120 m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
121 break;
122 case CECDEVICE_TV:
123 m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, CEC_PHYSICAL_ADDRESS_TV);
124 break;
125 default:
126 m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, CEC_INVALID_PHYSICAL_ADDRESS);
127 break;
128 }
129 }
130 }
131
132 CCECProcessor::~CCECProcessor(void)
133 {
134 Close();
135
136 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
137 {
138 delete m_busDevices[iPtr];
139 m_busDevices[iPtr] = NULL;
140 }
141 }
142
143 void CCECProcessor::Close(void)
144 {
145 StopThread(false);
146 SetInitialised(false);
147 StopThread();
148
149 bool bClose(false);
150 {
151 CLockObject lock(m_mutex);
152 bClose = m_bConnectionOpened;
153 m_bConnectionOpened = false;
154 }
155
156 if (bClose && m_communication)
157 {
158 delete m_communication;
159 m_communication = NULL;
160 }
161 }
162
163 bool CCECProcessor::OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening /* = true */)
164 {
165 bool bReturn(false);
166 Close();
167
168 {
169 CLockObject lock(m_mutex);
170 if (m_bConnectionOpened)
171 {
172 CLibCEC::AddLog(CEC_LOG_ERROR, "connection already opened");
173 return false;
174 }
175 m_communication = new CUSBCECAdapterCommunication(this, strPort, iBaudRate);
176 m_bConnectionOpened = (m_communication != NULL);
177 }
178
179 CTimeout timeout(iTimeoutMs > 0 ? iTimeoutMs : CEC_DEFAULT_TRANSMIT_WAIT);
180
181 /* open a new connection */
182 unsigned iConnectTry(0);
183 while (timeout.TimeLeft() > 0 && (bReturn = m_communication->Open((timeout.TimeLeft() / CEC_CONNECT_TRIES), false, bStartListening)) == false)
184 {
185 CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry);
186 m_communication->Close();
187 CEvent::Sleep(CEC_DEFAULT_CONNECT_RETRY_WAIT);
188 }
189
190 if (bReturn)
191 {
192 m_configuration.iFirmwareVersion = m_communication->GetFirmwareVersion();
193 m_configuration.iFirmwareBuildDate = m_communication->GetFirmwareBuildDate();
194 CStdString strLog;
195 strLog.Format("connected to the CEC adapter. libCEC version = %s, client version = %s, firmware version = %d", ToString((cec_server_version)m_configuration.serverVersion), ToString((cec_client_version)m_configuration.clientVersion), m_configuration.iFirmwareVersion);
196 if (m_configuration.iFirmwareBuildDate != CEC_DEFAULT_FIRMWARE_BUILD_DATE)
197 {
198 time_t buildTime = (time_t)m_configuration.iFirmwareBuildDate;
199 strLog.AppendFormat(", firmware build date: %s", asctime(gmtime(&buildTime)));
200 strLog = strLog.Left((int)strLog.length() - 1); // strip \n added by asctime
201 strLog.append(" +0000");
202 }
203 CLibCEC::AddLog(CEC_LOG_NOTICE, strLog);
204 }
205
206 if (m_configuration.bGetSettingsFromROM == 1)
207 {
208 libcec_configuration config;
209 config.Clear();
210 m_communication->GetConfiguration(&config);
211
212 CLockObject lock(m_mutex);
213 if (!config.deviceTypes.IsEmpty())
214 m_configuration.deviceTypes = config.deviceTypes;
215 if (config.iPhysicalAddress > 0)
216 m_configuration.iPhysicalAddress = config.iPhysicalAddress;
217 snprintf(m_configuration.strDeviceName, 13, "%s", config.strDeviceName);
218 }
219
220 return bReturn;
221 }
222
223 bool CCECProcessor::IsInitialised(void)
224 {
225 CLockObject lock(m_threadMutex);
226 return m_bInitialised;
227 }
228
229 void CCECProcessor::SetInitialised(bool bSetTo /* = true */)
230 {
231 CLockObject lock(m_mutex);
232 m_bInitialised = bSetTo;
233 }
234
235 bool CCECProcessor::Initialise(void)
236 {
237 bool bReturn(false);
238 {
239 CLockObject lock(m_mutex);
240 if (!m_configuration.logicalAddresses.IsEmpty())
241 m_configuration.logicalAddresses.Clear();
242
243 if (!FindLogicalAddresses())
244 {
245 CLibCEC::AddLog(CEC_LOG_ERROR, "could not detect our logical addresses");
246 return bReturn;
247 }
248
249 /* only set our OSD name for the primary device */
250 m_busDevices[m_configuration.logicalAddresses.primary]->m_strDeviceName = m_configuration.strDeviceName;
251
252 /* make the primary device the active source if the option is set */
253 if (m_configuration.bActivateSource == 1)
254 m_busDevices[m_configuration.logicalAddresses.primary]->m_bActiveSource = true;
255
256 /* set the default menu language for devices we control */
257 cec_menu_language language;
258 language.device = m_configuration.logicalAddresses.primary;
259 memcpy(language.language, m_configuration.strDeviceLanguage, 3);
260 language.language[3] = 0;
261
262 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
263 {
264 if (m_configuration.logicalAddresses[iPtr])
265 {
266 language.device = (cec_logical_address) iPtr;
267 m_busDevices[iPtr]->SetMenuLanguage(language);
268 }
269 }
270 }
271
272 /* get the vendor id from the TV, so we are using the correct handler */
273 m_busDevices[CECDEVICE_TV]->GetVendorId();
274
275 if (m_configuration.iPhysicalAddress != 0)
276 {
277 CLibCEC::AddLog(CEC_LOG_NOTICE, "setting the physical address to %4x", m_configuration.iPhysicalAddress);
278 m_busDevices[m_configuration.logicalAddresses.primary]->m_iPhysicalAddress = m_configuration.iPhysicalAddress;
279 if ((bReturn = m_busDevices[m_configuration.logicalAddresses.primary]->TransmitPhysicalAddress()) == false)
280 CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set the physical address to %4x", m_configuration.iPhysicalAddress);
281 }
282 else if (m_configuration.iPhysicalAddress == 0 && (bReturn = SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort, true)) == false)
283 CLibCEC::AddLog(CEC_LOG_ERROR, "unable to set HDMI port %d on %s (%x)", m_configuration.iHDMIPort, ToString(m_configuration.baseDevice), (uint8_t)m_configuration.baseDevice);
284
285 if (bReturn && m_configuration.bActivateSource == 1)
286 m_busDevices[m_configuration.logicalAddresses.primary]->ActivateSource();
287
288 SetInitialised(bReturn);
289 if (bReturn)
290 CLibCEC::ConfigurationChanged(m_configuration);
291
292 return bReturn;
293 }
294
295 bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = CEC_SERIAL_DEFAULT_BAUDRATE */, uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */)
296 {
297 bool bReturn(false);
298
299 {
300 CLockObject lock(m_mutex);
301 if (!OpenConnection(strPort, iBaudRate, iTimeoutMs))
302 return bReturn;
303
304 /* create the processor thread */
305 if (!CreateThread())
306 {
307 CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread");
308 return bReturn;
309 }
310 }
311
312 if ((bReturn = Initialise()) == false)
313 {
314 CLibCEC::AddLog(CEC_LOG_ERROR, "could not create a processor thread");
315 StopThread(true);
316 }
317 else
318 {
319 CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started");
320 }
321
322 return bReturn;
323 }
324
325 bool CCECProcessor::TryLogicalAddress(cec_logical_address address)
326 {
327 if (m_busDevices[address]->TryLogicalAddress())
328 {
329 m_configuration.logicalAddresses.Set(address);
330 return true;
331 }
332
333 return false;
334 }
335
336 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
337 {
338 CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'");
339 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1) ||
340 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2) ||
341 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3);
342 }
343
344 bool CCECProcessor::FindLogicalAddressTuner(void)
345 {
346 CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'");
347 return TryLogicalAddress(CECDEVICE_TUNER1) ||
348 TryLogicalAddress(CECDEVICE_TUNER2) ||
349 TryLogicalAddress(CECDEVICE_TUNER3) ||
350 TryLogicalAddress(CECDEVICE_TUNER4);
351 }
352
353 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
354 {
355 CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'");
356 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1) ||
357 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2) ||
358 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3);
359 }
360
361 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
362 {
363 CLibCEC::AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'");
364 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM);
365 }
366
367 bool CCECProcessor::ChangeDeviceType(cec_device_type from, cec_device_type to)
368 {
369 bool bChanged(false);
370
371 CLibCEC::AddLog(CEC_LOG_NOTICE, "changing device type '%s' into '%s'", ToString(from), ToString(to));
372
373 CLockObject lock(m_mutex);
374 CCECBusDevice *previousDevice = GetDeviceByType(from);
375 m_configuration.logicalAddresses.primary = CECDEVICE_UNKNOWN;
376
377 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
378 {
379 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
380 continue;
381
382 if (m_configuration.deviceTypes.types[iPtr] == from)
383 {
384 bChanged = true;
385 m_configuration.deviceTypes.types[iPtr] = to;
386 }
387 else if (m_configuration.deviceTypes.types[iPtr] == to && bChanged)
388 {
389 m_configuration.deviceTypes.types[iPtr] = CEC_DEVICE_TYPE_RESERVED;
390 }
391 }
392
393 if (bChanged)
394 {
395 FindLogicalAddresses();
396
397 CCECBusDevice *newDevice = GetDeviceByType(to);
398 if (previousDevice && newDevice)
399 {
400 newDevice->SetDeviceStatus(CEC_DEVICE_STATUS_HANDLED_BY_LIBCEC);
401 previousDevice->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT);
402
403 newDevice->SetCecVersion(previousDevice->GetCecVersion(false));
404 previousDevice->SetCecVersion(CEC_VERSION_UNKNOWN);
405
406 newDevice->SetMenuLanguage(previousDevice->GetMenuLanguage(false));
407
408 newDevice->SetMenuState(previousDevice->GetMenuState());
409 previousDevice->SetMenuState(CEC_MENU_STATE_DEACTIVATED);
410
411 newDevice->SetOSDName(previousDevice->GetOSDName(false));
412 previousDevice->SetOSDName(ToString(previousDevice->GetLogicalAddress()));
413
414 newDevice->SetPhysicalAddress(previousDevice->GetPhysicalAddress());
415 previousDevice->SetPhysicalAddress(CEC_INVALID_PHYSICAL_ADDRESS);
416
417 newDevice->SetPowerStatus(previousDevice->GetPowerStatus(false));
418 previousDevice->SetPowerStatus(CEC_POWER_STATUS_UNKNOWN);
419
420 newDevice->SetVendorId(previousDevice->GetVendorId(false));
421 previousDevice->SetVendorId(CEC_VENDOR_UNKNOWN);
422
423 if ((from == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || from == CEC_DEVICE_TYPE_RECORDING_DEVICE) &&
424 (to == CEC_DEVICE_TYPE_PLAYBACK_DEVICE || to == CEC_DEVICE_TYPE_RECORDING_DEVICE))
425 {
426 ((CCECPlaybackDevice *) newDevice)->SetDeckControlMode(((CCECPlaybackDevice *) previousDevice)->GetDeckControlMode());
427 ((CCECPlaybackDevice *) previousDevice)->SetDeckControlMode(CEC_DECK_CONTROL_MODE_STOP);
428
429 ((CCECPlaybackDevice *) newDevice)->SetDeckStatus(((CCECPlaybackDevice *) previousDevice)->GetDeckStatus());
430 ((CCECPlaybackDevice *) previousDevice)->SetDeckStatus(CEC_DECK_INFO_STOP);
431 }
432 }
433 }
434
435 return true;
436 }
437
438 bool CCECProcessor::FindLogicalAddresses(void)
439 {
440 bool bReturn(true);
441 m_configuration.logicalAddresses.Clear();
442
443 if (m_configuration.deviceTypes.IsEmpty())
444 {
445 CLibCEC::AddLog(CEC_LOG_ERROR, "no device types set");
446 return false;
447 }
448
449 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
450 {
451 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
452 continue;
453
454 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - device %d: type %d", __FUNCTION__, iPtr, m_configuration.deviceTypes.types[iPtr]);
455
456 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE)
457 bReturn &= FindLogicalAddressRecordingDevice();
458 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_TUNER)
459 bReturn &= FindLogicalAddressTuner();
460 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
461 bReturn &= FindLogicalAddressPlaybackDevice();
462 if (m_configuration.deviceTypes.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
463 bReturn &= FindLogicalAddressAudioSystem();
464 }
465
466 if (bReturn)
467 SetAckMask(m_configuration.logicalAddresses.AckMask());
468
469 return bReturn;
470 }
471
472 void CCECProcessor::ReplaceHandlers(void)
473 {
474 if (!IsInitialised())
475 return;
476 for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
477 m_busDevices[iPtr]->ReplaceHandler(m_bInitialised);
478 }
479
480 bool CCECProcessor::OnCommandReceived(const cec_command &command)
481 {
482 return m_inBuffer.Push(command);
483 }
484
485 void *CCECProcessor::Process(void)
486 {
487 CLibCEC::AddLog(CEC_LOG_DEBUG, "processor thread started");
488
489 cec_command command;
490 command.Clear();
491
492 while (!IsStopped() && m_communication->IsOpen())
493 {
494 if (m_inBuffer.Pop(command, CEC_PROCESSOR_SIGNAL_WAIT_TIME))
495 ParseCommand(command);
496
497 if (IsInitialised())
498 {
499 ReplaceHandlers();
500
501 m_controller->CheckKeypressTimeout();
502 }
503 }
504
505 return NULL;
506 }
507
508 bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
509 {
510 bool bReturn(false);
511
512 if (!IsRunning())
513 return bReturn;
514
515 cec_logical_address addr = m_configuration.logicalAddresses.primary;
516
517 if (type != CEC_DEVICE_TYPE_RESERVED)
518 {
519 for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
520 {
521 if (m_configuration.logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
522 {
523 addr = (cec_logical_address) iPtr;
524 break;
525 }
526 }
527 }
528
529 m_busDevices[addr]->SetActiveSource();
530 if (m_busDevices[addr]->GetPhysicalAddress() != CEC_INVALID_PHYSICAL_ADDRESS)
531 bReturn = m_busDevices[addr]->ActivateSource();
532
533 return bReturn;
534 }
535
536 bool CCECProcessor::SetActiveSource(uint16_t iStreamPath)
537 {
538 bool bReturn(false);
539
540 // suppress polls when searching for a device
541 CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
542 if (device)
543 {
544 device->SetActiveSource();
545 bReturn = true;
546 }
547 else
548 {
549 CLibCEC::AddLog(CEC_LOG_DEBUG, "device with PA '%04x' not found", iStreamPath);
550 }
551
552 return bReturn;
553 }
554
555 void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout)
556 {
557 CLockObject lock(m_mutex);
558 m_iStandardLineTimeout = iTimeout;
559 }
560
561 void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout)
562 {
563 CLockObject lock(m_mutex);
564 m_iRetryLineTimeout = iTimeout;
565 }
566
567 bool CCECProcessor::SetActiveView(void)
568 {
569 CLibCEC::AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__);
570 return SetActiveSource(m_configuration.deviceTypes.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_configuration.deviceTypes[0]);
571 }
572
573 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */)
574 {
575 bool bReturn(false);
576
577 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
578 if (device)
579 {
580 ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode);
581 if (bSendUpdate)
582 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
583 bReturn = true;
584 }
585
586 return bReturn;
587 }
588
589 bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */)
590 {
591 bool bReturn(false);
592
593 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
594 if (device)
595 {
596 ((CCECPlaybackDevice *) device)->SetDeckStatus(info);
597 if (bSendUpdate)
598 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
599 bReturn = true;
600 }
601
602 return bReturn;
603 }
604
605 bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce /* = false */)
606 {
607 bool bReturn(false);
608
609 // limit the HDMI port range to 1-15
610 if (iPort < CEC_MIN_HDMI_PORTNUMBER ||
611 iPort > CEC_MAX_HDMI_PORTNUMBER)
612 return bReturn;
613
614 {
615 CLockObject lock(m_mutex);
616 m_configuration.baseDevice = iBaseDevice;
617 m_configuration.iHDMIPort = iPort;
618 }
619
620 if (!IsRunning() && !bForce)
621 return true;
622
623 CLibCEC::AddLog(CEC_LOG_DEBUG, "setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice);
624
625 uint16_t iPhysicalAddress(0);
626 if (iBaseDevice > CECDEVICE_TV)
627 {
628 iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
629 }
630
631 if (iPhysicalAddress <= CEC_MAX_PHYSICAL_ADDRESS)
632 {
633 if (iPhysicalAddress == 0)
634 iPhysicalAddress += 0x1000 * iPort;
635 else if (iPhysicalAddress % 0x1000 == 0)
636 iPhysicalAddress += 0x100 * iPort;
637 else if (iPhysicalAddress % 0x100 == 0)
638 iPhysicalAddress += 0x10 * iPort;
639 else if (iPhysicalAddress % 0x10 == 0)
640 iPhysicalAddress += iPort;
641
642 bReturn = true;
643 }
644
645 if (!bReturn)
646 CLibCEC::AddLog(CEC_LOG_ERROR, "failed to set the physical address");
647 else
648 SetPhysicalAddress(iPhysicalAddress);
649
650 return bReturn;
651 }
652
653 bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress)
654 {
655 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
656 {
657 if (m_busDevices[iPtr]->GetPhysicalAddress() == iPhysicalAddress)
658 return true;
659 }
660 return false;
661 }
662
663 bool CCECProcessor::TransmitInactiveSource(void)
664 {
665 if (!IsRunning())
666 return false;
667
668 if (!m_configuration.logicalAddresses.IsEmpty() && m_busDevices[m_configuration.logicalAddresses.primary])
669 return m_busDevices[m_configuration.logicalAddresses.primary]->TransmitInactiveSource();
670 return false;
671 }
672
673 void CCECProcessor::LogOutput(const cec_command &data)
674 {
675 CStdString strTx;
676 strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination);
677 if (data.opcode_set)
678 strTx.AppendFormat(":%02x", (uint8_t)data.opcode);
679
680 for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++)
681 strTx.AppendFormat(":%02x", data.parameters[iPtr]);
682 CLibCEC::AddLog(CEC_LOG_TRAFFIC, strTx.c_str());
683 }
684
685 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
686 {
687 CLockObject lock(m_mutex);
688 if (m_configuration.logicalAddresses.primary != iLogicalAddress)
689 {
690 CLibCEC::AddLog(CEC_LOG_NOTICE, "<< setting primary logical address to %1x", iLogicalAddress);
691 m_configuration.logicalAddresses.primary = iLogicalAddress;
692 m_configuration.logicalAddresses.Set(iLogicalAddress);
693 return SetAckMask(m_configuration.logicalAddresses.AckMask());
694 }
695
696 return true;
697 }
698
699 bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
700 {
701 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
702 {
703 if (m_configuration.logicalAddresses[iPtr])
704 m_busDevices[iPtr]->SetMenuState(state);
705 }
706
707 if (bSendUpdate)
708 m_busDevices[m_configuration.logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV);
709
710 return true;
711 }
712
713 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress, bool bSendUpdate /* = true */)
714 {
715 bool bSendActiveView(false);
716 bool bReturn(false);
717 cec_logical_addresses sendUpdatesTo;
718 sendUpdatesTo.Clear();
719
720 {
721 CLockObject lock(m_mutex);
722 m_configuration.iPhysicalAddress = iPhysicalAddress;
723 CLibCEC::AddLog(CEC_LOG_DEBUG, "setting physical address to '%4x'", iPhysicalAddress);
724
725 if (!m_configuration.logicalAddresses.IsEmpty())
726 {
727 bool bWasActiveSource(false);
728 for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
729 if (m_configuration.logicalAddresses[iPtr])
730 {
731 bWasActiveSource |= m_busDevices[iPtr]->IsActiveSource();
732 m_busDevices[iPtr]->SetInactiveSource();
733 m_busDevices[iPtr]->SetPhysicalAddress(iPhysicalAddress);
734 if (bSendUpdate)
735 sendUpdatesTo.Set((cec_logical_address)iPtr);
736 }
737
738 bSendActiveView = bWasActiveSource && bSendUpdate;
739 bReturn = true;
740 }
741 }
742
743 for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
744 if (sendUpdatesTo[iPtr])
745 m_busDevices[iPtr]->TransmitPhysicalAddress();
746
747 if (bSendActiveView)
748 SetActiveView();
749
750 if (bReturn)
751 {
752 libcec_configuration config;
753 {
754 CLockObject lock(m_mutex);
755 config = m_configuration;
756 }
757
758 PersistConfiguration(&config);
759 CLibCEC::ConfigurationChanged(config);
760 }
761
762 return bReturn;
763 }
764
765 bool CCECProcessor::SwitchMonitoring(bool bEnable)
766 {
767 CLibCEC::AddLog(CEC_LOG_NOTICE, "== %s monitoring mode ==", bEnable ? "enabling" : "disabling");
768
769 {
770 CLockObject lock(m_mutex);
771 m_bMonitor = bEnable;
772 }
773
774 if (bEnable)
775 return SetAckMask(0);
776 else
777 return SetAckMask(m_configuration.logicalAddresses.AckMask());
778 }
779
780 bool CCECProcessor::PollDevice(cec_logical_address iAddress)
781 {
782 if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress])
783 {
784 return m_configuration.logicalAddresses.primary == CECDEVICE_UNKNOWN ?
785 m_busDevices[iAddress]->TransmitPoll(iAddress) :
786 m_busDevices[m_configuration.logicalAddresses.primary]->TransmitPoll(iAddress);
787 }
788 return false;
789 }
790
791 uint8_t CCECProcessor::VolumeUp(bool bSendRelease /* = true */)
792 {
793 uint8_t status = 0;
794 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
795 status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bSendRelease);
796
797 return status;
798 }
799
800 uint8_t CCECProcessor::VolumeDown(bool bSendRelease /* = true */)
801 {
802 uint8_t status = 0;
803 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
804 status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bSendRelease);
805
806 return status;
807 }
808
809 uint8_t CCECProcessor::MuteAudio(bool bSendRelease /* = true */)
810 {
811 uint8_t status = 0;
812 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
813 status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bSendRelease);
814
815 return status;
816 }
817
818 CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bSuppressUpdate /* = true */)
819 {
820 CCECBusDevice *device(NULL);
821
822 // invalid PA
823 if (iPhysicalAddress == CEC_INVALID_PHYSICAL_ADDRESS)
824 return device;
825
826 // check each device until we found a match
827 for (unsigned int iPtr = 0; !device && iPtr < 16; iPtr++)
828 {
829 if (m_busDevices[iPtr]->GetPhysicalAddress(bSuppressUpdate) == iPhysicalAddress)
830 device = m_busDevices[iPtr];
831 }
832
833 return device;
834 }
835
836 CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const
837 {
838 CCECBusDevice *device = NULL;
839
840 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
841 {
842 if (m_busDevices[iPtr]->m_type == type && m_configuration.logicalAddresses[iPtr])
843 {
844 device = m_busDevices[iPtr];
845 break;
846 }
847 }
848
849 return device;
850 }
851
852 CCECBusDevice *CCECProcessor::GetPrimaryDevice(void) const
853 {
854 CCECBusDevice *device(NULL);
855 cec_logical_address primary = m_configuration.logicalAddresses.primary;
856 if (primary != CECDEVICE_UNKNOWN)
857 device = m_busDevices[primary];
858 return device;
859 }
860
861 cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
862 {
863 return m_busDevices[iAddress]->GetCecVersion();
864 }
865
866 cec_osd_name CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress)
867 {
868 CStdString strOSDName = m_busDevices[iAddress]->GetOSDName();
869 cec_osd_name retVal;
870
871 snprintf(retVal.name, sizeof(retVal.name), "%s", strOSDName.c_str());
872 retVal.device = iAddress;
873
874 return retVal;
875 }
876
877 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
878 {
879 if (m_busDevices[iAddress])
880 {
881 *language = m_busDevices[iAddress]->GetMenuLanguage();
882 return (strcmp(language->language, "???") != 0);
883 }
884 return false;
885 }
886
887 CStdString CCECProcessor::GetDeviceName(void) const
888 {
889 CStdString strName;
890 strName = m_configuration.strDeviceName;
891 return strName;
892 }
893
894 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress)
895 {
896 if (m_busDevices[iAddress])
897 return m_busDevices[iAddress]->GetVendorId();
898 return false;
899 }
900
901 uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress)
902 {
903 if (m_busDevices[iAddress])
904 return m_busDevices[iAddress]->GetPhysicalAddress(false);
905 return false;
906 }
907
908 cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress)
909 {
910 if (m_busDevices[iAddress])
911 return m_busDevices[iAddress]->GetPowerStatus();
912 return CEC_POWER_STATUS_UNKNOWN;
913 }
914
915 cec_logical_address CCECProcessor::GetActiveSource(bool bRequestActiveSource /* = true */)
916 {
917 for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
918 {
919 if (m_busDevices[iPtr]->IsActiveSource())
920 return (cec_logical_address)iPtr;
921 }
922
923 if (bRequestActiveSource && m_configuration.logicalAddresses.primary != CECDEVICE_UNKNOWN)
924 {
925 CCECBusDevice *primary = m_busDevices[m_configuration.logicalAddresses.primary];
926 if (primary)
927 primary->RequestActiveSource();
928
929 return GetActiveSource(false);
930 }
931
932 return CECDEVICE_UNKNOWN;
933 }
934
935 bool CCECProcessor::IsActiveSource(cec_logical_address iAddress)
936 {
937 return iAddress >= CECDEVICE_TV && iAddress < CECDEVICE_BROADCAST ?
938 m_busDevices[iAddress]->IsActiveSource() :
939 false;
940 }
941
942 bool CCECProcessor::Transmit(const cec_command &data)
943 {
944 if (m_configuration.logicalAddresses[(uint8_t)data.destination])
945 {
946 CLibCEC::AddLog(CEC_LOG_WARNING, "not sending data to myself!");
947 return false;
948 }
949
950 uint8_t iMaxTries(0);
951 {
952 CLockObject lock(m_mutex);
953 if (IsStopped())
954 return false;
955 LogOutput(data);
956 m_iLastTransmission = GetTimeMs();
957 if (!m_communication || !m_communication->IsOpen())
958 {
959 CLibCEC::AddLog(CEC_LOG_ERROR, "cannot transmit command: connection closed");
960 return false;
961 }
962 iMaxTries = m_busDevices[data.initiator]->GetHandler()->GetTransmitRetries() + 1;
963 }
964
965 bool bRetry(true);
966 uint8_t iTries(0);
967 uint8_t iLineTimeout = m_iStandardLineTimeout;
968 cec_adapter_message_state adapterState = ADAPTER_MESSAGE_STATE_UNKNOWN;
969
970 while (bRetry && ++iTries < iMaxTries)
971 {
972 if (m_busDevices[data.initiator]->IsUnsupportedFeature(data.opcode))
973 return false;
974
975 adapterState = m_communication->Write(data, bRetry, iLineTimeout);
976 iLineTimeout = m_iRetryLineTimeout;
977 }
978
979 return adapterState == ADAPTER_MESSAGE_STATE_SENT_ACKED;
980 }
981
982 void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
983 {
984 CLibCEC::AddLog(CEC_LOG_DEBUG, "<< transmitting abort message");
985
986 cec_command command;
987 // TODO
988 cec_command::Format(command, m_configuration.logicalAddresses.primary, address, CEC_OPCODE_FEATURE_ABORT);
989 command.parameters.PushBack((uint8_t)opcode);
990 command.parameters.PushBack((uint8_t)reason);
991
992 Transmit(command);
993 }
994
995 void CCECProcessor::ParseCommand(const cec_command &command)
996 {
997 CStdString dataStr;
998 dataStr.Format(">> %1x%1x", command.initiator, command.destination);
999 if (command.opcode_set == 1)
1000 dataStr.AppendFormat(":%02x", command.opcode);
1001 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
1002 dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]);
1003 CLibCEC::AddLog(CEC_LOG_TRAFFIC, dataStr.c_str());
1004
1005 if (!m_bMonitor && command.initiator >= CECDEVICE_TV && command.initiator <= CECDEVICE_BROADCAST)
1006 m_busDevices[(uint8_t)command.initiator]->HandleCommand(command);
1007 }
1008
1009 cec_logical_addresses CCECProcessor::GetActiveDevices(void)
1010 {
1011 cec_logical_addresses addresses;
1012 addresses.Clear();
1013 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
1014 {
1015 if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
1016 addresses.Set((cec_logical_address) iPtr);
1017 }
1018 return addresses;
1019 }
1020
1021 bool CCECProcessor::IsPresentDevice(cec_logical_address address)
1022 {
1023 return m_busDevices[address]->GetStatus() == CEC_DEVICE_STATUS_PRESENT;
1024 }
1025
1026 bool CCECProcessor::IsPresentDeviceType(cec_device_type type)
1027 {
1028 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
1029 {
1030 if (m_busDevices[iPtr]->GetType() == type && m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
1031 return true;
1032 }
1033
1034 return false;
1035 }
1036
1037 uint16_t CCECProcessor::GetPhysicalAddress(void) const
1038 {
1039 if (!m_configuration.logicalAddresses.IsEmpty() && m_busDevices[m_configuration.logicalAddresses.primary])
1040 return m_busDevices[m_configuration.logicalAddresses.primary]->GetPhysicalAddress();
1041 return false;
1042 }
1043
1044 bool CCECProcessor::SetAckMask(uint16_t iMask)
1045 {
1046 return m_communication ? m_communication->SetAckMask(iMask) : false;
1047 }
1048
1049 bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */)
1050 {
1051 return m_busDevices[iDestination]->TransmitKeypress(key, bWait);
1052 }
1053
1054 bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination, bool bWait /* = true */)
1055 {
1056 return m_busDevices[iDestination]->TransmitKeyRelease(bWait);
1057 }
1058
1059 bool CCECProcessor::EnablePhysicalAddressDetection(void)
1060 {
1061 CLibCEC::AddLog(CEC_LOG_WARNING, "deprecated method %s called", __FUNCTION__);
1062 uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress();
1063 if (iPhysicalAddress != 0)
1064 {
1065 m_configuration.bAutodetectAddress = 1;
1066 m_configuration.iPhysicalAddress = iPhysicalAddress;
1067 m_configuration.baseDevice = CECDEVICE_UNKNOWN;
1068 m_configuration.iHDMIPort = 0;
1069 return SetPhysicalAddress(iPhysicalAddress);
1070 }
1071 return false;
1072 }
1073
1074 bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
1075 {
1076 if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
1077 {
1078 bool bReturn(true);
1079 for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++)
1080 {
1081 if (m_configuration.powerOffDevices[iPtr])
1082 {
1083 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - putting '%s' in standby mode", __FUNCTION__, ToString((cec_logical_address)iPtr));
1084 bReturn &= m_busDevices[iPtr]->Standby();
1085 }
1086 }
1087 return bReturn;
1088 }
1089
1090 return m_busDevices[address]->Standby();
1091 }
1092
1093 bool CCECProcessor::PowerOnDevices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
1094 {
1095 if (address == CECDEVICE_BROADCAST && m_configuration.clientVersion >= CEC_CLIENT_VERSION_1_5_0)
1096 {
1097 bool bReturn(true);
1098 for (uint8_t iPtr = 0; iPtr <= 0xF; iPtr++)
1099 {
1100 if (m_configuration.wakeDevices[iPtr])
1101 {
1102 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - powering on '%s'", __FUNCTION__, ToString((cec_logical_address)iPtr));
1103 bReturn &= m_busDevices[iPtr]->PowerOn();
1104 }
1105 }
1106 return bReturn;
1107 }
1108
1109 return m_busDevices[address]->PowerOn();
1110 }
1111
1112 const char *CCECProcessor::ToString(const cec_device_type type)
1113 {
1114 switch (type)
1115 {
1116 case CEC_DEVICE_TYPE_AUDIO_SYSTEM:
1117 return "audio system";
1118 case CEC_DEVICE_TYPE_PLAYBACK_DEVICE:
1119 return "playback device";
1120 case CEC_DEVICE_TYPE_RECORDING_DEVICE:
1121 return "recording device";
1122 case CEC_DEVICE_TYPE_RESERVED:
1123 return "reserved";
1124 case CEC_DEVICE_TYPE_TUNER:
1125 return "tuner";
1126 case CEC_DEVICE_TYPE_TV:
1127 return "TV";
1128 default:
1129 return "unknown";
1130 }
1131 }
1132
1133 const char *CCECProcessor::ToString(const cec_menu_state state)
1134 {
1135 switch (state)
1136 {
1137 case CEC_MENU_STATE_ACTIVATED:
1138 return "activated";
1139 case CEC_MENU_STATE_DEACTIVATED:
1140 return "deactivated";
1141 default:
1142 return "unknown";
1143 }
1144 }
1145
1146 const char *CCECProcessor::ToString(const cec_version version)
1147 {
1148 switch (version)
1149 {
1150 case CEC_VERSION_1_2:
1151 return "1.2";
1152 case CEC_VERSION_1_2A:
1153 return "1.2a";
1154 case CEC_VERSION_1_3:
1155 return "1.3";
1156 case CEC_VERSION_1_3A:
1157 return "1.3a";
1158 case CEC_VERSION_1_4:
1159 return "1.4";
1160 default:
1161 return "unknown";
1162 }
1163 }
1164
1165 const char *CCECProcessor::ToString(const cec_power_status status)
1166 {
1167 switch (status)
1168 {
1169 case CEC_POWER_STATUS_ON:
1170 return "on";
1171 case CEC_POWER_STATUS_STANDBY:
1172 return "standby";
1173 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
1174 return "in transition from on to standby";
1175 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
1176 return "in transition from standby to on";
1177 default:
1178 return "unknown";
1179 }
1180 }
1181
1182 const char *CCECProcessor::ToString(const cec_logical_address address)
1183 {
1184 switch(address)
1185 {
1186 case CECDEVICE_AUDIOSYSTEM:
1187 return "Audio";
1188 case CECDEVICE_BROADCAST:
1189 return "Broadcast";
1190 case CECDEVICE_FREEUSE:
1191 return "Free use";
1192 case CECDEVICE_PLAYBACKDEVICE1:
1193 return "Playback 1";
1194 case CECDEVICE_PLAYBACKDEVICE2:
1195 return "Playback 2";
1196 case CECDEVICE_PLAYBACKDEVICE3:
1197 return "Playback 3";
1198 case CECDEVICE_RECORDINGDEVICE1:
1199 return "Recorder 1";
1200 case CECDEVICE_RECORDINGDEVICE2:
1201 return "Recorder 2";
1202 case CECDEVICE_RECORDINGDEVICE3:
1203 return "Recorder 3";
1204 case CECDEVICE_RESERVED1:
1205 return "Reserved 1";
1206 case CECDEVICE_RESERVED2:
1207 return "Reserved 2";
1208 case CECDEVICE_TUNER1:
1209 return "Tuner 1";
1210 case CECDEVICE_TUNER2:
1211 return "Tuner 2";
1212 case CECDEVICE_TUNER3:
1213 return "Tuner 3";
1214 case CECDEVICE_TUNER4:
1215 return "Tuner 4";
1216 case CECDEVICE_TV:
1217 return "TV";
1218 default:
1219 return "unknown";
1220 }
1221 }
1222
1223 const char *CCECProcessor::ToString(const cec_deck_control_mode mode)
1224 {
1225 switch (mode)
1226 {
1227 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND:
1228 return "skip forward wind";
1229 case CEC_DECK_CONTROL_MODE_EJECT:
1230 return "eject";
1231 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND:
1232 return "reverse rewind";
1233 case CEC_DECK_CONTROL_MODE_STOP:
1234 return "stop";
1235 default:
1236 return "unknown";
1237 }
1238 }
1239
1240 const char *CCECProcessor::ToString(const cec_deck_info status)
1241 {
1242 switch (status)
1243 {
1244 case CEC_DECK_INFO_PLAY:
1245 return "play";
1246 case CEC_DECK_INFO_RECORD:
1247 return "record";
1248 case CEC_DECK_INFO_PLAY_REVERSE:
1249 return "play reverse";
1250 case CEC_DECK_INFO_STILL:
1251 return "still";
1252 case CEC_DECK_INFO_SLOW:
1253 return "slow";
1254 case CEC_DECK_INFO_SLOW_REVERSE:
1255 return "slow reverse";
1256 case CEC_DECK_INFO_FAST_FORWARD:
1257 return "fast forward";
1258 case CEC_DECK_INFO_FAST_REVERSE:
1259 return "fast reverse";
1260 case CEC_DECK_INFO_NO_MEDIA:
1261 return "no media";
1262 case CEC_DECK_INFO_STOP:
1263 return "stop";
1264 case CEC_DECK_INFO_SKIP_FORWARD_WIND:
1265 return "info skip forward wind";
1266 case CEC_DECK_INFO_SKIP_REVERSE_REWIND:
1267 return "info skip reverse rewind";
1268 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD:
1269 return "info index search forward";
1270 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE:
1271 return "info index search reverse";
1272 case CEC_DECK_INFO_OTHER_STATUS:
1273 return "other";
1274 default:
1275 return "unknown";
1276 }
1277 }
1278
1279 const char *CCECProcessor::ToString(const cec_opcode opcode)
1280 {
1281 switch (opcode)
1282 {
1283 case CEC_OPCODE_ACTIVE_SOURCE:
1284 return "active source";
1285 case CEC_OPCODE_IMAGE_VIEW_ON:
1286 return "image view on";
1287 case CEC_OPCODE_TEXT_VIEW_ON:
1288 return "text view on";
1289 case CEC_OPCODE_INACTIVE_SOURCE:
1290 return "inactive source";
1291 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
1292 return "request active source";
1293 case CEC_OPCODE_ROUTING_CHANGE:
1294 return "routing change";
1295 case CEC_OPCODE_ROUTING_INFORMATION:
1296 return "routing information";
1297 case CEC_OPCODE_SET_STREAM_PATH:
1298 return "set stream path";
1299 case CEC_OPCODE_STANDBY:
1300 return "standby";
1301 case CEC_OPCODE_RECORD_OFF:
1302 return "record off";
1303 case CEC_OPCODE_RECORD_ON:
1304 return "record on";
1305 case CEC_OPCODE_RECORD_STATUS:
1306 return "record status";
1307 case CEC_OPCODE_RECORD_TV_SCREEN:
1308 return "record tv screen";
1309 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER:
1310 return "clear analogue timer";
1311 case CEC_OPCODE_CLEAR_DIGITAL_TIMER:
1312 return "clear digital timer";
1313 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER:
1314 return "clear external timer";
1315 case CEC_OPCODE_SET_ANALOGUE_TIMER:
1316 return "set analogue timer";
1317 case CEC_OPCODE_SET_DIGITAL_TIMER:
1318 return "set digital timer";
1319 case CEC_OPCODE_SET_EXTERNAL_TIMER:
1320 return "set external timer";
1321 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE:
1322 return "set timer program title";
1323 case CEC_OPCODE_TIMER_CLEARED_STATUS:
1324 return "timer cleared status";
1325 case CEC_OPCODE_TIMER_STATUS:
1326 return "timer status";
1327 case CEC_OPCODE_CEC_VERSION:
1328 return "cec version";
1329 case CEC_OPCODE_GET_CEC_VERSION:
1330 return "get cec version";
1331 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
1332 return "give physical address";
1333 case CEC_OPCODE_GET_MENU_LANGUAGE:
1334 return "get menu language";
1335 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
1336 return "report physical address";
1337 case CEC_OPCODE_SET_MENU_LANGUAGE:
1338 return "set menu language";
1339 case CEC_OPCODE_DECK_CONTROL:
1340 return "deck control";
1341 case CEC_OPCODE_DECK_STATUS:
1342 return "deck status";
1343 case CEC_OPCODE_GIVE_DECK_STATUS:
1344 return "give deck status";
1345 case CEC_OPCODE_PLAY:
1346 return "play";
1347 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS:
1348 return "give tuner status";
1349 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE:
1350 return "select analogue service";
1351 case CEC_OPCODE_SELECT_DIGITAL_SERVICE:
1352 return "set digital service";
1353 case CEC_OPCODE_TUNER_DEVICE_STATUS:
1354 return "tuner device status";
1355 case CEC_OPCODE_TUNER_STEP_DECREMENT:
1356 return "tuner step decrement";
1357 case CEC_OPCODE_TUNER_STEP_INCREMENT:
1358 return "tuner step increment";
1359 case CEC_OPCODE_DEVICE_VENDOR_ID:
1360 return "device vendor id";
1361 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
1362 return "give device vendor id";
1363 case CEC_OPCODE_VENDOR_COMMAND:
1364 return "vendor command";
1365 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
1366 return "vendor command with id";
1367 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN:
1368 return "vendor remote button down";
1369 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP:
1370 return "vendor remote button up";
1371 case CEC_OPCODE_SET_OSD_STRING:
1372 return "set osd string";
1373 case CEC_OPCODE_GIVE_OSD_NAME:
1374 return "give osd name";
1375 case CEC_OPCODE_SET_OSD_NAME:
1376 return "set osd name";
1377 case CEC_OPCODE_MENU_REQUEST:
1378 return "menu request";
1379 case CEC_OPCODE_MENU_STATUS:
1380 return "menu status";
1381 case CEC_OPCODE_USER_CONTROL_PRESSED:
1382 return "user control pressed";
1383 case CEC_OPCODE_USER_CONTROL_RELEASE:
1384 return "user control release";
1385 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
1386 return "give device power status";
1387 case CEC_OPCODE_REPORT_POWER_STATUS:
1388 return "report power status";
1389 case CEC_OPCODE_FEATURE_ABORT:
1390 return "feature abort";
1391 case CEC_OPCODE_ABORT:
1392 return "abort";
1393 case CEC_OPCODE_GIVE_AUDIO_STATUS:
1394 return "give audio status";
1395 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
1396 return "give audio mode status";
1397 case CEC_OPCODE_REPORT_AUDIO_STATUS:
1398 return "report audio status";
1399 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE:
1400 return "set system audio mode";
1401 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
1402 return "system audio mode request";
1403 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS:
1404 return "system audio mode status";
1405 case CEC_OPCODE_SET_AUDIO_RATE:
1406 return "set audio rate";
1407 case CEC_OPCODE_NONE:
1408 return "poll";
1409 default:
1410 return "UNKNOWN";
1411 }
1412 }
1413
1414 const char *CCECProcessor::ToString(const cec_system_audio_status mode)
1415 {
1416 switch(mode)
1417 {
1418 case CEC_SYSTEM_AUDIO_STATUS_ON:
1419 return "on";
1420 case CEC_SYSTEM_AUDIO_STATUS_OFF:
1421 return "off";
1422 default:
1423 return "unknown";
1424 }
1425 }
1426
1427 const char *CCECProcessor::ToString(const cec_audio_status UNUSED(status))
1428 {
1429 // TODO this is a mask
1430 return "TODO";
1431 }
1432
1433 const char *CCECProcessor::ToString(const cec_vendor_id vendor)
1434 {
1435 switch (vendor)
1436 {
1437 case CEC_VENDOR_SAMSUNG:
1438 return "Samsung";
1439 case CEC_VENDOR_LG:
1440 return "LG";
1441 case CEC_VENDOR_PANASONIC:
1442 return "Panasonic";
1443 case CEC_VENDOR_PIONEER:
1444 return "Pioneer";
1445 case CEC_VENDOR_ONKYO:
1446 return "Onkyo";
1447 case CEC_VENDOR_YAMAHA:
1448 return "Yamaha";
1449 case CEC_VENDOR_PHILIPS:
1450 return "Philips";
1451 case CEC_VENDOR_SONY:
1452 return "Sony";
1453 case CEC_VENDOR_TOSHIBA:
1454 return "Toshiba";
1455 default:
1456 return "Unknown";
1457 }
1458 }
1459
1460 const char *CCECProcessor::ToString(const cec_client_version version)
1461 {
1462 switch (version)
1463 {
1464 case CEC_CLIENT_VERSION_PRE_1_5:
1465 return "pre-1.5";
1466 case CEC_CLIENT_VERSION_1_5_0:
1467 return "1.5.0";
1468 case CEC_CLIENT_VERSION_1_5_1:
1469 return "1.5.1";
1470 case CEC_CLIENT_VERSION_1_5_2:
1471 return "1.5.2";
1472 case CEC_CLIENT_VERSION_1_5_3:
1473 return "1.5.3";
1474 case CEC_CLIENT_VERSION_1_6_0:
1475 return "1.6.0";
1476 case CEC_CLIENT_VERSION_1_6_1:
1477 return "1.6.1";
1478 case CEC_CLIENT_VERSION_1_6_2:
1479 return "1.6.2";
1480 default:
1481 return "Unknown";
1482 }
1483 }
1484
1485 const char *CCECProcessor::ToString(const cec_server_version version)
1486 {
1487 switch (version)
1488 {
1489 case CEC_SERVER_VERSION_PRE_1_5:
1490 return "pre-1.5";
1491 case CEC_SERVER_VERSION_1_5_0:
1492 return "1.5.0";
1493 case CEC_SERVER_VERSION_1_5_1:
1494 return "1.5.1";
1495 case CEC_SERVER_VERSION_1_5_2:
1496 return "1.5.2";
1497 case CEC_SERVER_VERSION_1_5_3:
1498 return "1.5.3";
1499 case CEC_SERVER_VERSION_1_6_0:
1500 return "1.6.0";
1501 case CEC_SERVER_VERSION_1_6_1:
1502 return "1.6.1";
1503 case CEC_SERVER_VERSION_1_6_2:
1504 return "1.6.2";
1505 default:
1506 return "Unknown";
1507 }
1508 }
1509
1510 bool CCECProcessor::StartBootloader(const char *strPort /* = NULL */)
1511 {
1512 bool bReturn(false);
1513 if (!m_communication && strPort)
1514 {
1515 IAdapterCommunication *comm = new CUSBCECAdapterCommunication(this, strPort);
1516 CTimeout timeout(CEC_DEFAULT_CONNECT_TIMEOUT);
1517 int iConnectTry(0);
1518 while (timeout.TimeLeft() > 0 && (bReturn = comm->Open(timeout.TimeLeft() / CEC_CONNECT_TRIES, true)) == false)
1519 {
1520 CLibCEC::AddLog(CEC_LOG_ERROR, "could not open a connection (try %d)", ++iConnectTry);
1521 comm->Close();
1522 Sleep(CEC_DEFAULT_TRANSMIT_RETRY_WAIT);
1523 }
1524 if (comm->IsOpen())
1525 {
1526 bReturn = comm->StartBootloader();
1527 delete comm;
1528 }
1529 return bReturn;
1530 }
1531 else
1532 {
1533 m_communication->StartBootloader();
1534 Close();
1535 bReturn = true;
1536 }
1537
1538 return bReturn;
1539 }
1540
1541 bool CCECProcessor::PingAdapter(void)
1542 {
1543 return m_communication->PingAdapter();
1544 }
1545
1546 void CCECProcessor::HandlePoll(cec_logical_address initiator, cec_logical_address destination)
1547 {
1548 if (destination < CECDEVICE_BROADCAST)
1549 m_busDevices[destination]->HandlePollFrom(initiator);
1550 }
1551
1552 bool CCECProcessor::HandleReceiveFailed(cec_logical_address initiator)
1553 {
1554 return !m_busDevices[initiator]->HandleReceiveFailed();
1555 }
1556
1557 bool CCECProcessor::SetStreamPath(uint16_t iPhysicalAddress)
1558 {
1559 // stream path changes are sent by the TV
1560 return m_busDevices[CECDEVICE_TV]->GetHandler()->TransmitSetStreamPath(iPhysicalAddress);
1561 }
1562
1563 bool CCECProcessor::SetConfiguration(const libcec_configuration *configuration)
1564 {
1565 bool bReinit(false);
1566 CCECBusDevice *primary = IsRunning() ? GetPrimaryDevice() : NULL;
1567 cec_device_type oldPrimaryType = primary ? primary->GetType() : CEC_DEVICE_TYPE_RECORDING_DEVICE;
1568 m_configuration.clientVersion = configuration->clientVersion;
1569 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using client version '%s'", __FUNCTION__, ToString((cec_client_version)configuration->clientVersion));
1570
1571 // client version 1.5.0
1572
1573 // device types
1574 bool bDeviceTypeChanged = IsRunning () && m_configuration.deviceTypes != configuration->deviceTypes;
1575 m_configuration.deviceTypes = configuration->deviceTypes;
1576 if (bDeviceTypeChanged)
1577 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using primary device type '%s'", __FUNCTION__, ToString(configuration->deviceTypes[0]));
1578
1579 bool bPhysicalAddressChanged(false);
1580
1581 // autodetect address
1582 bool bPhysicalAutodetected(false);
1583 if (IsRunning() && configuration->bAutodetectAddress == 1)
1584 {
1585 uint16_t iPhysicalAddress = m_communication->GetPhysicalAddress();
1586 if (iPhysicalAddress != 0)
1587 {
1588 if (IsRunning())
1589 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - autodetected physical address '%4x'", __FUNCTION__, iPhysicalAddress);
1590 else
1591 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using physical address '%x'", __FUNCTION__, iPhysicalAddress);
1592 bPhysicalAddressChanged = (m_configuration.iPhysicalAddress != iPhysicalAddress);
1593 m_configuration.iPhysicalAddress = iPhysicalAddress;
1594 m_configuration.iHDMIPort = 0;
1595 m_configuration.baseDevice = CECDEVICE_UNKNOWN;
1596 bPhysicalAutodetected = true;
1597 }
1598 }
1599
1600 // physical address
1601 if (!bPhysicalAutodetected)
1602 {
1603 if (configuration->iPhysicalAddress != 0)
1604 bPhysicalAddressChanged = IsRunning() && m_configuration.iPhysicalAddress != configuration->iPhysicalAddress;
1605 if (bPhysicalAddressChanged)
1606 {
1607 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - physical address '%x'", __FUNCTION__, configuration->iPhysicalAddress);
1608 m_configuration.iPhysicalAddress = configuration->iPhysicalAddress;
1609 }
1610 }
1611
1612 bool bHdmiPortChanged(false);
1613 if (!bPhysicalAutodetected && !bPhysicalAddressChanged)
1614 {
1615 // base device
1616 bHdmiPortChanged = IsRunning() && m_configuration.baseDevice != configuration->baseDevice;
1617 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using base device '%x'", __FUNCTION__, (int)configuration->baseDevice);
1618 m_configuration.baseDevice = configuration->baseDevice;
1619
1620 // hdmi port
1621 bHdmiPortChanged |= IsRunning() && m_configuration.iHDMIPort != configuration->iHDMIPort;
1622 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using HDMI port '%d'", __FUNCTION__, configuration->iHDMIPort);
1623 m_configuration.iHDMIPort = configuration->iHDMIPort;
1624 }
1625 else
1626 {
1627 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - resetting HDMI port and base device to defaults", __FUNCTION__);
1628 m_configuration.baseDevice = CECDEVICE_UNKNOWN;
1629 m_configuration.iHDMIPort = 0;
1630 }
1631
1632 bReinit = bPhysicalAddressChanged || bHdmiPortChanged || bDeviceTypeChanged;
1633
1634 // device name
1635 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - using OSD name '%s'", __FUNCTION__, configuration->strDeviceName);
1636 snprintf(m_configuration.strDeviceName, 13, "%s", configuration->strDeviceName);
1637 if (primary && !primary->GetOSDName().Equals(m_configuration.strDeviceName))
1638 {
1639 primary->SetOSDName(m_configuration.strDeviceName);
1640 if (!bReinit && IsRunning())
1641 primary->TransmitOSDName(CECDEVICE_TV);
1642 }
1643
1644 // tv vendor id override
1645 CLibCEC::AddLog(CEC_LOG_DEBUG, "%s - vendor id '%s'", __FUNCTION__, ToString((cec_vendor_id)configuration->tvVendor));
1646 if (m_configuration.tvVendor != configuration->tvVendor)
1647 {
1648 m_configuration.tvVendor= configuration->tvVendor;
1649 m_busDevices[CECDEVICE_TV]->SetVendorId((uint64_t)m_configuration.tvVendor);
1650 }
1651
1652 // wake CEC devices
1653 if (m_configuration.wakeDevices != configuration->wakeDevices)
1654 {
1655 m_configuration.wakeDevices = configuration->wakeDevices;
1656 if (!bReinit && IsRunning())
1657 PowerOnDevices();
1658 }
1659
1660 // just copy these
1661 m_configuration.bUseTVMenuLanguage = configuration->bUseTVMenuLanguage;
1662 m_configuration.bActivateSource = configuration->bActivateSource;
1663 m_configuration.bGetSettingsFromROM = configuration->bGetSettingsFromROM;
1664 m_configuration.powerOffDevices = configuration->powerOffDevices;
1665 m_configuration.bPowerOffScreensaver = configuration->bPowerOffScreensaver;
1666 m_configuration.bPowerOffOnStandby = configuration->bPowerOffOnStandby;
1667
1668 // client version 1.5.1
1669 if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_1)
1670 m_configuration.bSendInactiveSource = configuration->bSendInactiveSource;
1671
1672 // client version 1.6.0
1673 if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_6_0)
1674 {
1675 m_configuration.bPowerOffDevicesOnStandby = configuration->bPowerOffDevicesOnStandby;
1676 m_configuration.bShutdownOnStandby = configuration->bShutdownOnStandby;
1677 }
1678
1679 // client version 1.6.2
1680 if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_6_2)
1681 {
1682 memcpy(m_configuration.strDeviceLanguage, configuration->strDeviceLanguage, 3);
1683 }
1684
1685 // ensure that there is at least 1 device type set
1686 if (m_configuration.deviceTypes.IsEmpty())
1687 m_configuration.deviceTypes.Add(CEC_DEVICE_TYPE_RECORDING_DEVICE);
1688
1689 // persist the configuration
1690 if (IsRunning())
1691 m_communication->PersistConfiguration(&m_configuration);
1692
1693 if (bReinit || m_configuration.logicalAddresses.IsEmpty())
1694 {
1695 if (bDeviceTypeChanged)
1696 return ChangeDeviceType(oldPrimaryType, m_configuration.deviceTypes[0]);
1697 else if (bPhysicalAddressChanged)
1698 return SetPhysicalAddress(m_configuration.iPhysicalAddress);
1699 else
1700 return SetHDMIPort(m_configuration.baseDevice, m_configuration.iHDMIPort);
1701 }
1702 else if (m_configuration.bActivateSource == 1 && IsRunning() && !IsActiveSource(m_configuration.logicalAddresses.primary))
1703 {
1704 // activate the source if we're not already the active source
1705 SetActiveSource(m_configuration.deviceTypes.types[0]);
1706 }
1707
1708 return true;
1709 }
1710
1711 bool CCECProcessor::GetCurrentConfiguration(libcec_configuration *configuration)
1712 {
1713 // client version 1.5.0
1714 snprintf(configuration->strDeviceName, 13, "%s", m_configuration.strDeviceName);
1715 configuration->deviceTypes = m_configuration.deviceTypes;
1716 configuration->bAutodetectAddress = m_configuration.bAutodetectAddress;
1717 configuration->iPhysicalAddress = m_configuration.iPhysicalAddress;
1718 configuration->baseDevice = m_configuration.baseDevice;
1719 configuration->iHDMIPort = m_configuration.iHDMIPort;
1720 configuration->clientVersion = m_configuration.clientVersion;
1721 configuration->serverVersion = m_configuration.serverVersion;
1722 configuration->tvVendor = m_configuration.tvVendor;
1723
1724 configuration->bGetSettingsFromROM = m_configuration.bGetSettingsFromROM;
1725 configuration->bUseTVMenuLanguage = m_configuration.bUseTVMenuLanguage;
1726 configuration->bActivateSource = m_configuration.bActivateSource;
1727 configuration->wakeDevices = m_configuration.wakeDevices;
1728 configuration->powerOffDevices = m_configuration.powerOffDevices;
1729 configuration->bPowerOffScreensaver = m_configuration.bPowerOffScreensaver;
1730 configuration->bPowerOffOnStandby = m_configuration.bPowerOffOnStandby;
1731
1732 // client version 1.5.1
1733 if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_1)
1734 configuration->bSendInactiveSource = m_configuration.bSendInactiveSource;
1735
1736 // client version 1.5.3
1737 if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_5_3)
1738 configuration->logicalAddresses = m_configuration.logicalAddresses;
1739
1740 // client version 1.6.0
1741 if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_6_0)
1742 {
1743 configuration->iFirmwareVersion = m_configuration.iFirmwareVersion;
1744 configuration->bPowerOffDevicesOnStandby = m_configuration.bPowerOffDevicesOnStandby;
1745 configuration->bShutdownOnStandby = m_configuration.bShutdownOnStandby;
1746 }
1747
1748 // client version 1.6.2
1749 if (configuration->clientVersion >= CEC_CLIENT_VERSION_1_6_2)
1750 {
1751 memcpy(configuration->strDeviceLanguage, m_configuration.strDeviceLanguage, 3);
1752 configuration->iFirmwareBuildDate = m_configuration.iFirmwareBuildDate;
1753 }
1754 return true;
1755 }
1756
1757 bool CCECProcessor::CanPersistConfiguration(void)
1758 {
1759 return m_communication ? m_communication->GetFirmwareVersion() >= 2 : false;
1760 }
1761
1762 bool CCECProcessor::PersistConfiguration(libcec_configuration *configuration)
1763 {
1764 return m_communication ? m_communication->PersistConfiguration(configuration) : false;
1765 }
1766
1767 void CCECProcessor::RescanActiveDevices(void)
1768 {
1769 for (unsigned int iPtr = 0; iPtr < CECDEVICE_BROADCAST; iPtr++)
1770 m_busDevices[iPtr]->GetStatus(true);
1771 }
1772
1773 bool CCECProcessor::GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs /* = CEC_DEFAULT_CONNECT_TIMEOUT */)
1774 {
1775 if (!OpenConnection(strPort, CEC_SERIAL_DEFAULT_BAUDRATE, iTimeoutMs, false))
1776 return false;
1777
1778 config->iFirmwareVersion = m_communication->GetFirmwareVersion();
1779 config->iPhysicalAddress = m_communication->GetPhysicalAddress();
1780 config->iFirmwareBuildDate = m_communication->GetFirmwareBuildDate();
1781
1782 return true;
1783 }
1784
1785 bool CCECProcessor::TransmitPendingActiveSourceCommands(void)
1786 {
1787 bool bReturn(true);
1788 for (unsigned int iPtr = 0; iPtr < CECDEVICE_BROADCAST; iPtr++)
1789 bReturn &= m_busDevices[iPtr]->TransmitPendingActiveSourceCommands();
1790 return bReturn;
1791 }