cec: let CCECProcessor replace the command handlers
[deb_libcec.git] / src / lib / CECProcessor.cpp
... / ...
CommitLineData
1/*
2 * This file is part of the libCEC(R) library.
3 *
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
6 *
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
8 *
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 *
23 *
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
26 *
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
31 */
32
33#include "CECProcessor.h"
34
35#include "AdapterCommunication.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 "util/StdString.h"
45#include "platform/timeutils.h"
46
47using namespace CEC;
48using namespace std;
49
50CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
51 m_bStarted(false),
52 m_bInitialised(false),
53 m_iHDMIPort(CEC_DEFAULT_HDMI_PORT),
54 m_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE),
55 m_lastInitiator(CECDEVICE_UNKNOWN),
56 m_strDeviceName(strDeviceName),
57 m_controller(controller),
58 m_bMonitor(false),
59 m_iStandardLineTimeout(3),
60 m_iRetryLineTimeout(3),
61 m_iLastTransmission(0)
62{
63 m_communication = new CAdapterCommunication(this);
64 m_logicalAddresses.Clear();
65 m_logicalAddresses.Set(iLogicalAddress);
66 m_types.clear();
67 for (int iPtr = 0; iPtr <= 16; iPtr++)
68 m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, iPtr == iLogicalAddress ? iPhysicalAddress : 0);
69}
70
71CCECProcessor::CCECProcessor(CLibCEC *controller, const char *strDeviceName, const cec_device_type_list &types) :
72 m_bStarted(false),
73 m_bInitialised(false),
74 m_iHDMIPort(CEC_DEFAULT_HDMI_PORT),
75 m_iBaseDevice((cec_logical_address)CEC_DEFAULT_BASE_DEVICE),
76 m_strDeviceName(strDeviceName),
77 m_types(types),
78 m_controller(controller),
79 m_bMonitor(false),
80 m_iStandardLineTimeout(3),
81 m_iRetryLineTimeout(3),
82 m_iLastTransmission(0)
83{
84 m_communication = new CAdapterCommunication(this);
85 m_logicalAddresses.Clear();
86 for (int iPtr = 0; iPtr < 16; iPtr++)
87 {
88 switch(iPtr)
89 {
90 case CECDEVICE_AUDIOSYSTEM:
91 m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, 0xFFFF);
92 break;
93 case CECDEVICE_PLAYBACKDEVICE1:
94 case CECDEVICE_PLAYBACKDEVICE2:
95 case CECDEVICE_PLAYBACKDEVICE3:
96 m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, 0xFFFF);
97 break;
98 case CECDEVICE_RECORDINGDEVICE1:
99 case CECDEVICE_RECORDINGDEVICE2:
100 case CECDEVICE_RECORDINGDEVICE3:
101 m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, 0xFFFF);
102 break;
103 case CECDEVICE_TUNER1:
104 case CECDEVICE_TUNER2:
105 case CECDEVICE_TUNER3:
106 case CECDEVICE_TUNER4:
107 m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, 0xFFFF);
108 break;
109 case CECDEVICE_TV:
110 m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, 0);
111 break;
112 default:
113 m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0xFFFF);
114 break;
115 }
116 }
117}
118
119CCECProcessor::~CCECProcessor(void)
120{
121 m_bStarted = false;
122 m_startCondition.Broadcast();
123 StopThread();
124
125 delete m_communication;
126 m_communication = NULL;
127 m_controller = NULL;
128 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
129 delete m_busDevices[iPtr];
130}
131
132bool CCECProcessor::Start(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint32_t iTimeoutMs /* = 10000 */)
133{
134 bool bReturn(false);
135
136 {
137 CLockObject lock(&m_mutex);
138
139 /* check for an already opened connection */
140 if (!m_communication || m_communication->IsOpen())
141 {
142 m_controller->AddLog(CEC_LOG_ERROR, "connection already opened");
143 return bReturn;
144 }
145
146 /* open a new connection */
147 if (!m_communication->Open(strPort, iBaudRate, iTimeoutMs))
148 {
149 m_controller->AddLog(CEC_LOG_ERROR, "could not open a connection");
150 return bReturn;
151 }
152
153 /* create the processor thread */
154 if (!CreateThread() || !m_startCondition.Wait(&m_mutex) || !m_bStarted)
155 {
156 m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
157 return bReturn;
158 }
159 }
160
161 /* find the logical address for the adapter */
162 bReturn = m_logicalAddresses.IsEmpty() ? FindLogicalAddresses() : true;
163 if (!bReturn)
164 m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addresses");
165
166 /* set the physical address for the adapter */
167 if (bReturn)
168 {
169 /* only set our OSD name for the primary device */
170 m_busDevices[m_logicalAddresses.primary]->m_strDeviceName = m_strDeviceName;
171
172 /* get the vendor id from the TV, so we are using the correct handler */
173 m_busDevices[CECDEVICE_TV]->GetVendorId();
174
175 bReturn = SetHDMIPort(m_iBaseDevice, m_iHDMIPort, true);
176 }
177
178 /* make the primary device the active source */
179 if (bReturn)
180 {
181 m_bInitialised = true;
182 m_busDevices[m_logicalAddresses.primary]->m_bActiveSource = true;
183 bReturn = m_busDevices[CECDEVICE_TV]->InitHandler();
184 }
185
186 if (bReturn)
187 {
188 m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
189 }
190 else
191 {
192 m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
193 StopThread(true);
194 }
195
196 return bReturn;
197}
198
199bool CCECProcessor::TryLogicalAddress(cec_logical_address address)
200{
201 if (m_busDevices[address]->TryLogicalAddress())
202 {
203 m_logicalAddresses.Set(address);
204 return true;
205 }
206
207 return false;
208}
209
210bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
211{
212 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'");
213 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1) ||
214 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2) ||
215 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3);
216}
217
218bool CCECProcessor::FindLogicalAddressTuner(void)
219{
220 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'");
221 return TryLogicalAddress(CECDEVICE_TUNER1) ||
222 TryLogicalAddress(CECDEVICE_TUNER2) ||
223 TryLogicalAddress(CECDEVICE_TUNER3) ||
224 TryLogicalAddress(CECDEVICE_TUNER4);
225}
226
227bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
228{
229 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'");
230 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1) ||
231 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2) ||
232 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3);
233}
234
235bool CCECProcessor::FindLogicalAddressAudioSystem(void)
236{
237 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'");
238 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM);
239}
240
241bool CCECProcessor::FindLogicalAddresses(void)
242{
243 bool bReturn(true);
244 m_logicalAddresses.Clear();
245 CStdString strLog;
246
247 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
248 {
249 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
250 continue;
251
252 strLog.Format("%s - device %d: type %d", __FUNCTION__, iPtr, m_types.types[iPtr]);
253 AddLog(CEC_LOG_DEBUG, strLog);
254
255 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE)
256 bReturn &= FindLogicalAddressRecordingDevice();
257 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_TUNER)
258 bReturn &= FindLogicalAddressTuner();
259 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
260 bReturn &= FindLogicalAddressPlaybackDevice();
261 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
262 bReturn &= FindLogicalAddressAudioSystem();
263 }
264
265 if (bReturn)
266 SetAckMask(m_logicalAddresses.AckMask());
267
268 return bReturn;
269}
270
271void CCECProcessor::ReplaceHandlers(void)
272{
273 for (uint8_t iPtr = 0; iPtr <= CECDEVICE_PLAYBACKDEVICE3; iPtr++)
274 m_busDevices[iPtr]->ReplaceHandler(true);
275}
276
277void *CCECProcessor::Process(void)
278{
279 bool bParseFrame(false);
280 cec_command command;
281 CCECAdapterMessage msg;
282
283 {
284 CLockObject lock(&m_mutex);
285 m_bStarted = true;
286 m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
287 m_startCondition.Signal();
288 }
289
290 while (!IsStopped())
291 {
292 ReplaceHandlers();
293
294 command.Clear();
295 msg.clear();
296
297 {
298 CLockObject lock(&m_mutex);
299 if (m_commandBuffer.Pop(command))
300 {
301 bParseFrame = true;
302 }
303 else if (m_communication->IsOpen() && m_communication->Read(msg, 50))
304 {
305 if ((bParseFrame = (ParseMessage(msg) && !IsStopped())) == true)
306 command = m_currentframe;
307 }
308 }
309
310 if (bParseFrame)
311 ParseCommand(command);
312 bParseFrame = false;
313
314 Sleep(5);
315
316 m_controller->CheckKeypressTimeout();
317 }
318
319 if (m_communication)
320 m_communication->Close();
321
322 return NULL;
323}
324
325bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
326{
327 bool bReturn(false);
328
329 if (!IsRunning())
330 return bReturn;
331
332 cec_logical_address addr = m_logicalAddresses.primary;
333
334 if (type != CEC_DEVICE_TYPE_RESERVED)
335 {
336 for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
337 {
338 if (m_logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
339 {
340 addr = (cec_logical_address) iPtr;
341 break;
342 }
343 }
344 }
345
346 m_busDevices[addr]->SetActiveSource();
347 if (m_busDevices[addr]->GetPhysicalAddress(false) != 0xFFFF)
348 {
349 bReturn = m_busDevices[addr]->TransmitActiveSource();
350
351 if (bReturn && (m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_PLAYBACK_DEVICE ||
352 m_busDevices[addr]->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE))
353 {
354 bReturn = ((CCECPlaybackDevice *)m_busDevices[addr])->TransmitDeckStatus(CECDEVICE_TV);
355 }
356 }
357
358 return bReturn;
359}
360
361bool CCECProcessor::SetActiveSource(uint16_t iStreamPath)
362{
363 bool bReturn(false);
364
365 CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
366 if (device)
367 {
368 device->SetActiveSource();
369 bReturn = true;
370 }
371
372 return bReturn;
373}
374
375void CCECProcessor::SetStandardLineTimeout(uint8_t iTimeout)
376{
377 CLockObject lock(&m_mutex);
378 m_iStandardLineTimeout = iTimeout;
379}
380
381void CCECProcessor::SetRetryLineTimeout(uint8_t iTimeout)
382{
383 CLockObject lock(&m_mutex);
384 m_iRetryLineTimeout = iTimeout;
385}
386
387bool CCECProcessor::SetActiveView(void)
388{
389 return SetActiveSource(m_types.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_types[0]);
390}
391
392bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */)
393{
394 bool bReturn(false);
395
396 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
397 if (device)
398 {
399 ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode);
400 if (bSendUpdate)
401 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
402 bReturn = true;
403 }
404
405 return bReturn;
406}
407
408bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */)
409{
410 bool bReturn(false);
411
412 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
413 if (device)
414 {
415 ((CCECPlaybackDevice *) device)->SetDeckStatus(info);
416 if (bSendUpdate)
417 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
418 bReturn = true;
419 }
420
421 return bReturn;
422}
423
424bool CCECProcessor::SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort, bool bForce /* = false */)
425{
426 bool bReturn(false);
427 CLockObject lock(&m_mutex);
428
429 m_iBaseDevice = iBaseDevice;
430 m_iHDMIPort = iPort;
431 if (!m_bStarted && !bForce)
432 return true;
433
434 CStdString strLog;
435 strLog.Format("setting HDMI port to %d on device %s (%d)", iPort, ToString(iBaseDevice), (int)iBaseDevice);
436 AddLog(CEC_LOG_DEBUG, strLog);
437
438 uint16_t iPhysicalAddress(0);
439 if (iBaseDevice > CECDEVICE_TV)
440 iPhysicalAddress = m_busDevices[iBaseDevice]->GetPhysicalAddress();
441
442 if (iPhysicalAddress < 0xffff)
443 {
444 if (iPhysicalAddress == 0)
445 iPhysicalAddress += 0x1000 * iPort;
446 else if (iPhysicalAddress % 0x1000 == 0)
447 iPhysicalAddress += 0x100 * iPort;
448 else if (iPhysicalAddress % 0x100 == 0)
449 iPhysicalAddress += 0x10 * iPort;
450 else if (iPhysicalAddress % 0x10 == 0)
451 iPhysicalAddress += iPort;
452
453 SetPhysicalAddress(iPhysicalAddress);
454 bReturn = true;
455 }
456
457 if (!bReturn)
458 m_controller->AddLog(CEC_LOG_ERROR, "failed to set the physical address");
459
460 return bReturn;
461}
462
463bool CCECProcessor::PhysicalAddressInUse(uint16_t iPhysicalAddress)
464{
465 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
466 {
467 if (m_busDevices[iPtr]->GetPhysicalAddress(false) == iPhysicalAddress)
468 return true;
469 }
470 return false;
471}
472
473bool CCECProcessor::TransmitInactiveSource(void)
474{
475 if (!IsRunning())
476 return false;
477
478 if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
479 return m_busDevices[m_logicalAddresses.primary]->TransmitInactiveSource();
480 return false;
481}
482
483void CCECProcessor::LogOutput(const cec_command &data)
484{
485 CStdString strTx;
486 strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination);
487 if (data.opcode_set)
488 strTx.AppendFormat(":%02x", (uint8_t)data.opcode);
489
490 for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++)
491 strTx.AppendFormat(":%02x", data.parameters[iPtr]);
492 m_controller->AddLog(CEC_LOG_TRAFFIC, strTx.c_str());
493}
494
495bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
496{
497 CLockObject lock(&m_mutex);
498 if (m_logicalAddresses.primary != iLogicalAddress)
499 {
500 CStdString strLog;
501 strLog.Format("<< setting primary logical address to %1x", iLogicalAddress);
502 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
503 m_logicalAddresses.primary = iLogicalAddress;
504 m_logicalAddresses.Set(iLogicalAddress);
505 return SetAckMask(m_logicalAddresses.AckMask());
506 }
507
508 return true;
509}
510
511bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
512{
513 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
514 {
515 if (m_logicalAddresses[iPtr])
516 m_busDevices[iPtr]->SetMenuState(state);
517 }
518
519 if (bSendUpdate)
520 m_busDevices[m_logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV);
521
522 return true;
523}
524
525bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
526{
527 CLockObject lock(&m_mutex);
528 if (!m_logicalAddresses.IsEmpty())
529 {
530 for (uint8_t iPtr = 0; iPtr < 15; iPtr++)
531 if (m_logicalAddresses[iPtr])
532 {
533 m_busDevices[iPtr]->SetInactiveSource();
534 m_busDevices[iPtr]->SetPhysicalAddress(iPhysicalAddress);
535 m_busDevices[iPtr]->TransmitPhysicalAddress();
536 }
537 return SetActiveView();
538 }
539 return false;
540}
541
542bool CCECProcessor::SwitchMonitoring(bool bEnable)
543{
544 CStdString strLog;
545 strLog.Format("== %s monitoring mode ==", bEnable ? "enabling" : "disabling");
546 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
547
548 {
549 CLockObject lock(&m_mutex);
550 m_bMonitor = bEnable;
551 }
552
553 if (bEnable)
554 return SetAckMask(0);
555 else
556 return SetAckMask(m_logicalAddresses.AckMask());
557}
558
559bool CCECProcessor::PollDevice(cec_logical_address iAddress)
560{
561 if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress])
562 {
563 return m_logicalAddresses.primary == CECDEVICE_UNKNOWN ?
564 m_busDevices[iAddress]->TransmitPoll(iAddress) :
565 m_busDevices[m_logicalAddresses.primary]->TransmitPoll(iAddress);
566 }
567 return false;
568}
569
570uint8_t CCECProcessor::VolumeUp(bool bSendRelease /* = true */)
571{
572 uint8_t status = 0;
573 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
574 status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeUp(bSendRelease);
575
576 return status;
577}
578
579uint8_t CCECProcessor::VolumeDown(bool bSendRelease /* = true */)
580{
581 uint8_t status = 0;
582 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
583 status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->VolumeDown(bSendRelease);
584
585 return status;
586}
587
588uint8_t CCECProcessor::MuteAudio(bool bSendRelease /* = true */)
589{
590 uint8_t status = 0;
591 if (IsPresentDevice(CECDEVICE_AUDIOSYSTEM))
592 status = ((CCECAudioSystem *)m_busDevices[CECDEVICE_AUDIOSYSTEM])->MuteAudio(bSendRelease);
593
594 return status;
595}
596
597CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress, bool bRefresh /* = false */) const
598{
599 if (m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress(false) == iPhysicalAddress)
600 return m_busDevices[m_logicalAddresses.primary];
601
602 CCECBusDevice *device = NULL;
603 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
604 {
605 if (m_busDevices[iPtr]->GetPhysicalAddress(bRefresh) == iPhysicalAddress)
606 {
607 device = m_busDevices[iPtr];
608 break;
609 }
610 }
611
612 return device;
613}
614
615CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const
616{
617 CCECBusDevice *device = NULL;
618
619 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
620 {
621 if (m_busDevices[iPtr]->m_type == type && m_logicalAddresses[iPtr])
622 {
623 device = m_busDevices[iPtr];
624 break;
625 }
626 }
627
628 return device;
629}
630
631CCECBusDevice *CCECProcessor::GetPrimaryDevice(void) const
632{
633 CCECBusDevice *device(NULL);
634 cec_logical_address primary = m_logicalAddresses.primary;
635 if (primary != CECDEVICE_UNKNOWN)
636 device = m_busDevices[primary];
637 return device;
638}
639
640cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
641{
642 return m_busDevices[iAddress]->GetCecVersion();
643}
644
645cec_osd_name CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress)
646{
647 CStdString strOSDName = m_busDevices[iAddress]->GetOSDName();
648 cec_osd_name retVal;
649
650 snprintf(retVal.name, sizeof(retVal.name), "%s", strOSDName.c_str());
651 retVal.device = iAddress;
652
653 return retVal;
654}
655
656bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
657{
658 if (m_busDevices[iAddress])
659 {
660 *language = m_busDevices[iAddress]->GetMenuLanguage();
661 return (strcmp(language->language, "???") != 0);
662 }
663 return false;
664}
665
666uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress)
667{
668 if (m_busDevices[iAddress])
669 return m_busDevices[iAddress]->GetVendorId();
670 return false;
671}
672
673uint16_t CCECProcessor::GetDevicePhysicalAddress(cec_logical_address iAddress)
674{
675 if (m_busDevices[iAddress])
676 return m_busDevices[iAddress]->GetPhysicalAddress(false);
677 return false;
678}
679
680cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress)
681{
682 if (m_busDevices[iAddress])
683 return m_busDevices[iAddress]->GetPowerStatus();
684 return CEC_POWER_STATUS_UNKNOWN;
685}
686
687cec_logical_address CCECProcessor::GetActiveSource(void)
688{
689 for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
690 {
691 if (m_busDevices[iPtr]->IsActiveSource())
692 return (cec_logical_address)iPtr;
693 }
694
695 return CECDEVICE_UNKNOWN;
696}
697
698bool CCECProcessor::IsActiveSource(cec_logical_address iAddress)
699{
700 return m_busDevices[iAddress]->IsActiveSource();
701}
702
703bool CCECProcessor::Transmit(const cec_command &data)
704{
705 bool bReturn(false);
706 LogOutput(data);
707
708 CCECAdapterMessage *output = new CCECAdapterMessage(data);
709
710 /* set the number of retries */
711 if (data.opcode == CEC_OPCODE_NONE)
712 output->maxTries = 1;
713 else if (data.initiator != CECDEVICE_BROADCAST)
714 output->maxTries = m_busDevices[data.initiator]->GetHandler()->GetTransmitRetries() + 1;
715
716 bReturn = Transmit(output);
717
718 /* set to "not present" on failed ack */
719 if (output->is_error() && output->reply == MSGCODE_TRANSMIT_FAILED_ACK &&
720 output->destination() != CECDEVICE_BROADCAST)
721 m_busDevices[output->destination()]->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT);
722
723 delete output;
724 return bReturn;
725}
726
727bool CCECProcessor::Transmit(CCECAdapterMessage *output)
728{
729 bool bReturn(false);
730 CLockObject lock(&m_mutex);
731 {
732 m_iLastTransmission = GetTimeMs();
733 m_communication->SetLineTimeout(m_iStandardLineTimeout);
734 output->tries = 1;
735
736 do
737 {
738 if (output->tries > 0)
739 m_communication->SetLineTimeout(m_iRetryLineTimeout);
740
741 CLockObject msgLock(&output->mutex);
742 if (!m_communication || !m_communication->Write(output))
743 return bReturn;
744 else
745 {
746 output->condition.Wait(&output->mutex);
747 if (output->state != ADAPTER_MESSAGE_STATE_SENT)
748 {
749 m_controller->AddLog(CEC_LOG_ERROR, "command was not sent");
750 return bReturn;
751 }
752 }
753
754 if (output->transmit_timeout > 0)
755 {
756 if ((bReturn = WaitForTransmitSucceeded(output)) == false)
757 m_controller->AddLog(CEC_LOG_DEBUG, "did not receive ack");
758 }
759 else
760 bReturn = true;
761 }while (output->transmit_timeout > 0 && output->needs_retry() && ++output->tries < output->maxTries);
762 }
763
764 m_communication->SetLineTimeout(m_iStandardLineTimeout);
765
766 return bReturn;
767}
768
769void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
770{
771 m_controller->AddLog(CEC_LOG_DEBUG, "<< transmitting abort message");
772
773 cec_command command;
774 // TODO
775 cec_command::Format(command, m_logicalAddresses.primary, address, CEC_OPCODE_FEATURE_ABORT);
776 command.parameters.PushBack((uint8_t)opcode);
777 command.parameters.PushBack((uint8_t)reason);
778
779 Transmit(command);
780}
781
782bool CCECProcessor::WaitForTransmitSucceeded(CCECAdapterMessage *message)
783{
784 bool bError(false);
785 bool bTransmitSucceeded(false);
786 uint8_t iPacketsLeft(message->size() / 4);
787
788 int64_t iNow = GetTimeMs();
789 int64_t iTargetTime = iNow + message->transmit_timeout;
790
791 while (!bTransmitSucceeded && !bError && (message->transmit_timeout == 0 || iNow < iTargetTime))
792 {
793 CCECAdapterMessage msg;
794
795 if (!m_communication->Read(msg, message->transmit_timeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000))
796 {
797 iNow = GetTimeMs();
798 continue;
799 }
800
801 if (msg.message() == MSGCODE_FRAME_START && msg.ack())
802 {
803 m_busDevices[msg.initiator()]->GetHandler()->HandlePoll(msg.initiator(), msg.destination());
804 m_lastInitiator = msg.initiator();
805 iNow = GetTimeMs();
806 continue;
807 }
808
809 bError = msg.is_error();
810 if (msg.message() == MSGCODE_RECEIVE_FAILED &&
811 m_lastInitiator != CECDEVICE_UNKNOWN &&
812 !m_busDevices[m_lastInitiator]->GetHandler()->HandleReceiveFailed())
813 {
814 iNow = GetTimeMs();
815 continue;
816 }
817
818 if (bError)
819 {
820 message->reply = msg.message();
821 m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
822 }
823 else
824 {
825 switch(msg.message())
826 {
827 case MSGCODE_COMMAND_ACCEPTED:
828 m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
829 if (iPacketsLeft > 0)
830 iPacketsLeft--;
831 break;
832 case MSGCODE_TRANSMIT_SUCCEEDED:
833 m_controller->AddLog(CEC_LOG_DEBUG, msg.ToString());
834 bTransmitSucceeded = (iPacketsLeft == 0);
835 bError = !bTransmitSucceeded;
836 message->reply = MSGCODE_TRANSMIT_SUCCEEDED;
837 break;
838 default:
839 // ignore other data while waiting
840 break;
841 }
842
843 iNow = GetTimeMs();
844 }
845 }
846
847 return bTransmitSucceeded && !bError;
848}
849
850bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg)
851{
852 bool bEom(false);
853 bool bIsError(msg.is_error());
854
855 if (msg.empty())
856 return bEom;
857
858 switch(msg.message())
859 {
860 case MSGCODE_FRAME_START:
861 {
862 m_currentframe.Clear();
863 if (msg.size() >= 2)
864 {
865 m_currentframe.initiator = msg.initiator();
866 m_currentframe.destination = msg.destination();
867 m_currentframe.ack = msg.ack();
868 m_currentframe.eom = msg.eom();
869 }
870 if (m_currentframe.ack == 0x1)
871 {
872 m_lastInitiator = m_currentframe.initiator;
873 m_busDevices[m_lastInitiator]->GetHandler()->HandlePoll(m_currentframe.initiator, m_currentframe.destination);
874 }
875 }
876 break;
877 case MSGCODE_RECEIVE_FAILED:
878 {
879 if (m_lastInitiator != CECDEVICE_UNKNOWN)
880 bIsError = m_busDevices[m_lastInitiator]->GetHandler()->HandleReceiveFailed();
881 }
882 break;
883 case MSGCODE_FRAME_DATA:
884 {
885 if (msg.size() >= 2)
886 {
887 m_currentframe.PushBack(msg[1]);
888 m_currentframe.eom = msg.eom();
889 }
890 bEom = msg.eom();
891 }
892 break;
893 default:
894 break;
895 }
896
897 m_controller->AddLog(bIsError ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
898 return bEom;
899}
900
901void CCECProcessor::ParseCommand(cec_command &command)
902{
903 CStdString dataStr;
904 dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode);
905 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
906 dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]);
907 m_controller->AddLog(CEC_LOG_TRAFFIC, dataStr.c_str());
908
909 if (!m_bMonitor && command.initiator >= CECDEVICE_TV && command.initiator <= CECDEVICE_BROADCAST)
910 m_busDevices[(uint8_t)command.initiator]->HandleCommand(command);
911}
912
913cec_logical_addresses CCECProcessor::GetActiveDevices(void)
914{
915 cec_logical_addresses addresses;
916 addresses.Clear();
917 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
918 {
919 if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
920 addresses.Set((cec_logical_address) iPtr);
921 }
922 return addresses;
923}
924
925bool CCECProcessor::IsPresentDevice(cec_logical_address address)
926{
927 return m_busDevices[address]->GetStatus() == CEC_DEVICE_STATUS_PRESENT;
928}
929
930bool CCECProcessor::IsPresentDeviceType(cec_device_type type)
931{
932 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
933 {
934 if (m_busDevices[iPtr]->GetType() == type && m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
935 return true;
936 }
937
938 return false;
939}
940
941uint16_t CCECProcessor::GetPhysicalAddress(void) const
942{
943 if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
944 return m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress(false);
945 return false;
946}
947
948void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode)
949{
950 m_controller->SetCurrentButton(iButtonCode);
951}
952
953void CCECProcessor::AddCommand(const cec_command &command)
954{
955 m_controller->AddCommand(command);
956}
957
958void CCECProcessor::AddKey(cec_keypress &key)
959{
960 m_controller->AddKey(key);
961}
962
963void CCECProcessor::AddKey(void)
964{
965 m_controller->AddKey();
966}
967
968void CCECProcessor::AddLog(cec_log_level level, const CStdString &strMessage)
969{
970 m_controller->AddLog(level, strMessage);
971}
972
973bool CCECProcessor::SetAckMask(uint16_t iMask)
974{
975 bool bReturn(false);
976 CStdString strLog;
977 strLog.Format("setting ackmask to %2x", iMask);
978 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
979
980 CCECAdapterMessage *output = new CCECAdapterMessage;
981
982 output->push_back(MSGSTART);
983 output->push_escaped(MSGCODE_SET_ACK_MASK);
984 output->push_escaped(iMask >> 8);
985 output->push_escaped((uint8_t)iMask);
986 output->push_back(MSGEND);
987
988 if ((bReturn = Transmit(output)) == false)
989 m_controller->AddLog(CEC_LOG_ERROR, "could not set the ackmask");
990
991 delete output;
992
993 return bReturn;
994}
995
996bool CCECProcessor::TransmitKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */)
997{
998 return m_busDevices[iDestination]->TransmitKeypress(key, bWait);
999}
1000
1001bool CCECProcessor::TransmitKeyRelease(cec_logical_address iDestination, bool bWait /* = true */)
1002{
1003 return m_busDevices[iDestination]->TransmitKeyRelease(bWait);
1004}
1005
1006const char *CCECProcessor::ToString(const cec_menu_state state)
1007{
1008 switch (state)
1009 {
1010 case CEC_MENU_STATE_ACTIVATED:
1011 return "activated";
1012 case CEC_MENU_STATE_DEACTIVATED:
1013 return "deactivated";
1014 default:
1015 return "unknown";
1016 }
1017}
1018
1019const char *CCECProcessor::ToString(const cec_version version)
1020{
1021 switch (version)
1022 {
1023 case CEC_VERSION_1_2:
1024 return "1.2";
1025 case CEC_VERSION_1_2A:
1026 return "1.2a";
1027 case CEC_VERSION_1_3:
1028 return "1.3";
1029 case CEC_VERSION_1_3A:
1030 return "1.3a";
1031 case CEC_VERSION_1_4:
1032 return "1.4";
1033 default:
1034 return "unknown";
1035 }
1036}
1037
1038const char *CCECProcessor::ToString(const cec_power_status status)
1039{
1040 switch (status)
1041 {
1042 case CEC_POWER_STATUS_ON:
1043 return "on";
1044 case CEC_POWER_STATUS_STANDBY:
1045 return "standby";
1046 case CEC_POWER_STATUS_IN_TRANSITION_ON_TO_STANDBY:
1047 return "in transition from on to standby";
1048 case CEC_POWER_STATUS_IN_TRANSITION_STANDBY_TO_ON:
1049 return "in transition from standby to on";
1050 default:
1051 return "unknown";
1052 }
1053}
1054
1055const char *CCECProcessor::ToString(const cec_logical_address address)
1056{
1057 switch(address)
1058 {
1059 case CECDEVICE_AUDIOSYSTEM:
1060 return "Audio";
1061 case CECDEVICE_BROADCAST:
1062 return "Broadcast";
1063 case CECDEVICE_FREEUSE:
1064 return "Free use";
1065 case CECDEVICE_PLAYBACKDEVICE1:
1066 return "Playback 1";
1067 case CECDEVICE_PLAYBACKDEVICE2:
1068 return "Playback 2";
1069 case CECDEVICE_PLAYBACKDEVICE3:
1070 return "Playback 3";
1071 case CECDEVICE_RECORDINGDEVICE1:
1072 return "Recorder 1";
1073 case CECDEVICE_RECORDINGDEVICE2:
1074 return "Recorder 2";
1075 case CECDEVICE_RECORDINGDEVICE3:
1076 return "Recorder 3";
1077 case CECDEVICE_RESERVED1:
1078 return "Reserved 1";
1079 case CECDEVICE_RESERVED2:
1080 return "Reserved 2";
1081 case CECDEVICE_TUNER1:
1082 return "Tuner 1";
1083 case CECDEVICE_TUNER2:
1084 return "Tuner 2";
1085 case CECDEVICE_TUNER3:
1086 return "Tuner 3";
1087 case CECDEVICE_TUNER4:
1088 return "Tuner 4";
1089 case CECDEVICE_TV:
1090 return "TV";
1091 default:
1092 return "unknown";
1093 }
1094}
1095
1096const char *CCECProcessor::ToString(const cec_deck_control_mode mode)
1097{
1098 switch (mode)
1099 {
1100 case CEC_DECK_CONTROL_MODE_SKIP_FORWARD_WIND:
1101 return "skip forward wind";
1102 case CEC_DECK_CONTROL_MODE_EJECT:
1103 return "eject";
1104 case CEC_DECK_CONTROL_MODE_SKIP_REVERSE_REWIND:
1105 return "reverse rewind";
1106 case CEC_DECK_CONTROL_MODE_STOP:
1107 return "stop";
1108 default:
1109 return "unknown";
1110 }
1111}
1112
1113const char *CCECProcessor::ToString(const cec_deck_info status)
1114{
1115 switch (status)
1116 {
1117 case CEC_DECK_INFO_PLAY:
1118 return "play";
1119 case CEC_DECK_INFO_RECORD:
1120 return "record";
1121 case CEC_DECK_INFO_PLAY_REVERSE:
1122 return "play reverse";
1123 case CEC_DECK_INFO_STILL:
1124 return "still";
1125 case CEC_DECK_INFO_SLOW:
1126 return "slow";
1127 case CEC_DECK_INFO_SLOW_REVERSE:
1128 return "slow reverse";
1129 case CEC_DECK_INFO_FAST_FORWARD:
1130 return "fast forward";
1131 case CEC_DECK_INFO_FAST_REVERSE:
1132 return "fast reverse";
1133 case CEC_DECK_INFO_NO_MEDIA:
1134 return "no media";
1135 case CEC_DECK_INFO_STOP:
1136 return "stop";
1137 case CEC_DECK_INFO_SKIP_FORWARD_WIND:
1138 return "info skip forward wind";
1139 case CEC_DECK_INFO_SKIP_REVERSE_REWIND:
1140 return "info skip reverse rewind";
1141 case CEC_DECK_INFO_INDEX_SEARCH_FORWARD:
1142 return "info index search forward";
1143 case CEC_DECK_INFO_INDEX_SEARCH_REVERSE:
1144 return "info index search reverse";
1145 case CEC_DECK_INFO_OTHER_STATUS:
1146 return "other";
1147 default:
1148 return "unknown";
1149 }
1150}
1151
1152const char *CCECProcessor::ToString(const cec_opcode opcode)
1153{
1154 switch (opcode)
1155 {
1156 case CEC_OPCODE_ACTIVE_SOURCE:
1157 return "active source";
1158 case CEC_OPCODE_IMAGE_VIEW_ON:
1159 return "image view on";
1160 case CEC_OPCODE_TEXT_VIEW_ON:
1161 return "text view on";
1162 case CEC_OPCODE_INACTIVE_SOURCE:
1163 return "inactive source";
1164 case CEC_OPCODE_REQUEST_ACTIVE_SOURCE:
1165 return "request active source";
1166 case CEC_OPCODE_ROUTING_CHANGE:
1167 return "routing change";
1168 case CEC_OPCODE_ROUTING_INFORMATION:
1169 return "routing information";
1170 case CEC_OPCODE_SET_STREAM_PATH:
1171 return "set stream path";
1172 case CEC_OPCODE_STANDBY:
1173 return "standby";
1174 case CEC_OPCODE_RECORD_OFF:
1175 return "record off";
1176 case CEC_OPCODE_RECORD_ON:
1177 return "record on";
1178 case CEC_OPCODE_RECORD_STATUS:
1179 return "record status";
1180 case CEC_OPCODE_RECORD_TV_SCREEN:
1181 return "record tv screen";
1182 case CEC_OPCODE_CLEAR_ANALOGUE_TIMER:
1183 return "clear analogue timer";
1184 case CEC_OPCODE_CLEAR_DIGITAL_TIMER:
1185 return "clear digital timer";
1186 case CEC_OPCODE_CLEAR_EXTERNAL_TIMER:
1187 return "clear external timer";
1188 case CEC_OPCODE_SET_ANALOGUE_TIMER:
1189 return "set analogue timer";
1190 case CEC_OPCODE_SET_DIGITAL_TIMER:
1191 return "set digital timer";
1192 case CEC_OPCODE_SET_EXTERNAL_TIMER:
1193 return "set external timer";
1194 case CEC_OPCODE_SET_TIMER_PROGRAM_TITLE:
1195 return "set timer program title";
1196 case CEC_OPCODE_TIMER_CLEARED_STATUS:
1197 return "timer cleared status";
1198 case CEC_OPCODE_TIMER_STATUS:
1199 return "timer status";
1200 case CEC_OPCODE_CEC_VERSION:
1201 return "cec version";
1202 case CEC_OPCODE_GET_CEC_VERSION:
1203 return "get cec version";
1204 case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS:
1205 return "give physical address";
1206 case CEC_OPCODE_GET_MENU_LANGUAGE:
1207 return "get menu language";
1208 case CEC_OPCODE_REPORT_PHYSICAL_ADDRESS:
1209 return "report physical address";
1210 case CEC_OPCODE_SET_MENU_LANGUAGE:
1211 return "set menu language";
1212 case CEC_OPCODE_DECK_CONTROL:
1213 return "deck control";
1214 case CEC_OPCODE_DECK_STATUS:
1215 return "deck status";
1216 case CEC_OPCODE_GIVE_DECK_STATUS:
1217 return "give deck status";
1218 case CEC_OPCODE_PLAY:
1219 return "play";
1220 case CEC_OPCODE_GIVE_TUNER_DEVICE_STATUS:
1221 return "give tuner status";
1222 case CEC_OPCODE_SELECT_ANALOGUE_SERVICE:
1223 return "select analogue service";
1224 case CEC_OPCODE_SELECT_DIGITAL_SERVICE:
1225 return "set digital service";
1226 case CEC_OPCODE_TUNER_DEVICE_STATUS:
1227 return "tuner device status";
1228 case CEC_OPCODE_TUNER_STEP_DECREMENT:
1229 return "tuner step decrement";
1230 case CEC_OPCODE_TUNER_STEP_INCREMENT:
1231 return "tuner step increment";
1232 case CEC_OPCODE_DEVICE_VENDOR_ID:
1233 return "device vendor id";
1234 case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID:
1235 return "give device vendor id";
1236 case CEC_OPCODE_VENDOR_COMMAND:
1237 return "vendor command";
1238 case CEC_OPCODE_VENDOR_COMMAND_WITH_ID:
1239 return "vendor command with id";
1240 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_DOWN:
1241 return "vendor remote button down";
1242 case CEC_OPCODE_VENDOR_REMOTE_BUTTON_UP:
1243 return "vendor remote button up";
1244 case CEC_OPCODE_SET_OSD_STRING:
1245 return "set osd string";
1246 case CEC_OPCODE_GIVE_OSD_NAME:
1247 return "give osd name";
1248 case CEC_OPCODE_SET_OSD_NAME:
1249 return "set osd name";
1250 case CEC_OPCODE_MENU_REQUEST:
1251 return "menu request";
1252 case CEC_OPCODE_MENU_STATUS:
1253 return "menu status";
1254 case CEC_OPCODE_USER_CONTROL_PRESSED:
1255 return "user control pressed";
1256 case CEC_OPCODE_USER_CONTROL_RELEASE:
1257 return "user control release";
1258 case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS:
1259 return "give device power status";
1260 case CEC_OPCODE_REPORT_POWER_STATUS:
1261 return "report power status";
1262 case CEC_OPCODE_FEATURE_ABORT:
1263 return "feature abort";
1264 case CEC_OPCODE_ABORT:
1265 return "abort";
1266 case CEC_OPCODE_GIVE_AUDIO_STATUS:
1267 return "give audio status";
1268 case CEC_OPCODE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
1269 return "give audio mode status";
1270 case CEC_OPCODE_REPORT_AUDIO_STATUS:
1271 return "report audio status";
1272 case CEC_OPCODE_SET_SYSTEM_AUDIO_MODE:
1273 return "set system audio mode";
1274 case CEC_OPCODE_SYSTEM_AUDIO_MODE_REQUEST:
1275 return "system audio mode request";
1276 case CEC_OPCODE_SYSTEM_AUDIO_MODE_STATUS:
1277 return "system audio mode status";
1278 case CEC_OPCODE_SET_AUDIO_RATE:
1279 return "set audio rate";
1280 default:
1281 return "UNKNOWN";
1282 }
1283}
1284
1285const char *CCECProcessor::ToString(const cec_system_audio_status mode)
1286{
1287 switch(mode)
1288 {
1289 case CEC_SYSTEM_AUDIO_STATUS_ON:
1290 return "on";
1291 case CEC_SYSTEM_AUDIO_STATUS_OFF:
1292 return "off";
1293 default:
1294 return "unknown";
1295 }
1296}
1297
1298const char *CCECProcessor::ToString(const cec_audio_status status)
1299{
1300 // TODO this is a mask
1301 return "TODO";
1302}
1303
1304const char *CCECProcessor::ToString(const cec_vendor_id vendor)
1305{
1306 switch (vendor)
1307 {
1308 case CEC_VENDOR_SAMSUNG:
1309 return "Samsung";
1310 case CEC_VENDOR_LG:
1311 return "LG";
1312 case CEC_VENDOR_PANASONIC:
1313 return "Panasonic";
1314 case CEC_VENDOR_PIONEER:
1315 return "Pioneer";
1316 case CEC_VENDOR_ONKYO:
1317 return "Onkyo";
1318 case CEC_VENDOR_YAMAHA:
1319 return "Yamaha";
1320 case CEC_VENDOR_PHILIPS:
1321 return "Philips";
1322 default:
1323 return "Unknown";
1324 }
1325}
1326
1327void *CCECBusScan::Process(void)
1328{
1329 CCECBusDevice *device(NULL);
1330 uint8_t iCounter(0);
1331
1332 while (!IsStopped())
1333 {
1334 if (++iCounter < 10)
1335 {
1336 Sleep(1000);
1337 continue;
1338 }
1339 for (unsigned int iPtr = 0; iPtr <= 11 && !IsStopped(); iPtr++)
1340 {
1341 device = m_processor->m_busDevices[iPtr];
1342 WaitUntilIdle();
1343 if (device && device->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT)
1344 {
1345 WaitUntilIdle();
1346 if (!IsStopped())
1347 device->GetVendorId();
1348
1349 WaitUntilIdle();
1350 if (!IsStopped())
1351 device->GetPowerStatus(true);
1352 }
1353 }
1354 }
1355
1356 return NULL;
1357}
1358
1359void CCECBusScan::WaitUntilIdle(void)
1360{
1361 if (IsStopped())
1362 return;
1363
1364 int32_t iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission());
1365 while (iWaitTime > 0)
1366 {
1367 Sleep(iWaitTime);
1368 iWaitTime = 3000 - (int32_t)(GetTimeMs() - m_processor->GetLastTransmission());
1369 }
1370}
1371
1372bool CCECProcessor::StartBootloader(void)
1373{
1374 return m_communication->StartBootloader();
1375}
1376
1377bool CCECProcessor::PingAdapter(void)
1378{
1379 return m_communication->PingAdapter();
1380}