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