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