e43d298fba3ddfac53c5639580d04be61af34daa
[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 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
47 using namespace CEC;
48 using namespace std;
49
50 CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
51 m_bStarted(false),
52 m_strDeviceName(strDeviceName),
53 m_communication(serComm),
54 m_controller(controller),
55 m_bMonitor(false)
56 {
57 m_logicalAddresses.Clear();
58 m_logicalAddresses.Set(iLogicalAddress);
59 m_types.clear();
60 for (int iPtr = 0; iPtr <= 16; iPtr++)
61 m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, iPtr == iLogicalAddress ? iPhysicalAddress : 0);
62 }
63
64 CCECProcessor::CCECProcessor(CLibCEC *controller, CAdapterCommunication *serComm, const char *strDeviceName, const cec_device_type_list &types) :
65 m_bStarted(false),
66 m_strDeviceName(strDeviceName),
67 m_types(types),
68 m_communication(serComm),
69 m_controller(controller),
70 m_bMonitor(false)
71 {
72 m_logicalAddresses.Clear();
73 for (int iPtr = 0; iPtr < 16; iPtr++)
74 {
75 switch(iPtr)
76 {
77 case CECDEVICE_AUDIOSYSTEM:
78 m_busDevices[iPtr] = new CCECAudioSystem(this, (cec_logical_address) iPtr, 0xFFFF);
79 break;
80 case CECDEVICE_PLAYBACKDEVICE1:
81 case CECDEVICE_PLAYBACKDEVICE2:
82 case CECDEVICE_PLAYBACKDEVICE3:
83 m_busDevices[iPtr] = new CCECPlaybackDevice(this, (cec_logical_address) iPtr, 0xFFFF);
84 break;
85 case CECDEVICE_RECORDINGDEVICE1:
86 case CECDEVICE_RECORDINGDEVICE2:
87 case CECDEVICE_RECORDINGDEVICE3:
88 m_busDevices[iPtr] = new CCECRecordingDevice(this, (cec_logical_address) iPtr, 0xFFFF);
89 break;
90 case CECDEVICE_TUNER1:
91 case CECDEVICE_TUNER2:
92 case CECDEVICE_TUNER3:
93 case CECDEVICE_TUNER4:
94 m_busDevices[iPtr] = new CCECTuner(this, (cec_logical_address) iPtr, 0xFFFF);
95 break;
96 case CECDEVICE_TV:
97 m_busDevices[iPtr] = new CCECTV(this, (cec_logical_address) iPtr, 0);
98 break;
99 default:
100 m_busDevices[iPtr] = new CCECBusDevice(this, (cec_logical_address) iPtr, 0xFFFF);
101 break;
102 }
103 }
104 }
105
106 CCECProcessor::~CCECProcessor(void)
107 {
108 m_startCondition.Broadcast();
109 StopThread();
110 m_communication = NULL;
111 m_controller = NULL;
112 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
113 delete m_busDevices[iPtr];
114 }
115
116 bool CCECProcessor::Start(void)
117 {
118 CLockObject lock(&m_mutex);
119 if (!m_communication || !m_communication->IsOpen())
120 {
121 m_controller->AddLog(CEC_LOG_ERROR, "connection is closed");
122 return false;
123 }
124
125 if (CreateThread())
126 {
127 if (!m_startCondition.Wait(&m_mutex) || !m_bStarted)
128 {
129 m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
130 return false;
131 }
132 return true;
133 }
134 else
135 m_controller->AddLog(CEC_LOG_ERROR, "could not create a processor thread");
136
137 return false;
138 }
139
140 bool CCECProcessor::TryLogicalAddress(cec_logical_address address)
141 {
142 if (m_busDevices[address]->TryLogicalAddress())
143 {
144 /* only set our OSD name and active source for the primary device */
145 if (m_logicalAddresses.IsEmpty())
146 {
147 m_busDevices[address]->m_strDeviceName = m_strDeviceName;
148 m_busDevices[address]->m_bActiveSource = true;
149 }
150 m_logicalAddresses.Set(address);
151
152 // TODO
153 m_busDevices[address]->SetPhysicalAddress((uint16_t)CEC_DEFAULT_PHYSICAL_ADDRESS);
154
155 return true;
156 }
157
158 return false;
159 }
160
161 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
162 {
163 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'recording device'");
164 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1) ||
165 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2) ||
166 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3);
167 }
168
169 bool CCECProcessor::FindLogicalAddressTuner(void)
170 {
171 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'tuner'");
172 return TryLogicalAddress(CECDEVICE_TUNER1) ||
173 TryLogicalAddress(CECDEVICE_TUNER2) ||
174 TryLogicalAddress(CECDEVICE_TUNER3) ||
175 TryLogicalAddress(CECDEVICE_TUNER4);
176 }
177
178 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
179 {
180 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'playback device'");
181 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1) ||
182 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2) ||
183 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3);
184 }
185
186 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
187 {
188 AddLog(CEC_LOG_DEBUG, "detecting logical address for type 'audio'");
189 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM);
190 }
191
192 bool CCECProcessor::FindLogicalAddresses(void)
193 {
194 bool bReturn(true);
195 m_logicalAddresses.Clear();
196 CStdString strLog;
197
198 for (unsigned int iPtr = 0; iPtr < 5; iPtr++)
199 {
200 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RESERVED)
201 continue;
202
203 strLog.Format("%s - device %d: type %d", __FUNCTION__, iPtr, m_types.types[iPtr]);
204 AddLog(CEC_LOG_DEBUG, strLog);
205
206 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_RECORDING_DEVICE)
207 bReturn &= FindLogicalAddressRecordingDevice();
208 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_TUNER)
209 bReturn &= FindLogicalAddressTuner();
210 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE)
211 bReturn &= FindLogicalAddressPlaybackDevice();
212 if (m_types.types[iPtr] == CEC_DEVICE_TYPE_AUDIO_SYSTEM)
213 bReturn &= FindLogicalAddressAudioSystem();
214 }
215
216 return bReturn;
217 }
218
219 void *CCECProcessor::Process(void)
220 {
221 bool bParseFrame(false);
222 cec_command command;
223 CCECAdapterMessage msg;
224
225 {
226 if (m_logicalAddresses.IsEmpty() && !FindLogicalAddresses())
227 {
228 CLockObject lock(&m_mutex);
229 m_controller->AddLog(CEC_LOG_ERROR, "could not detect our logical addressed");
230 m_startCondition.Signal();
231 return NULL;
232 }
233
234 SetAckMask(m_logicalAddresses.AckMask());
235
236 {
237 CLockObject lock(&m_mutex);
238 m_controller->AddLog(CEC_LOG_DEBUG, "processor thread started");
239 m_bStarted = true;
240 m_startCondition.Signal();
241 }
242 }
243
244 while (!IsStopped())
245 {
246 command.Clear();
247 msg.clear();
248
249 {
250 CLockObject lock(&m_mutex);
251 if (m_commandBuffer.Pop(command))
252 {
253 bParseFrame = true;
254 }
255 else if (m_communication->IsOpen() && m_communication->Read(msg, 50))
256 {
257 m_controller->AddLog(msg.is_error() ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
258 if ((bParseFrame = (ParseMessage(msg) && !IsStopped())) == true)
259 command = m_currentframe;
260 }
261 }
262
263 if (bParseFrame)
264 ParseCommand(command);
265 bParseFrame = false;
266
267 Sleep(5);
268
269 m_controller->CheckKeypressTimeout();
270
271 for (unsigned int iDevicePtr = 0; iDevicePtr < 16; iDevicePtr++)
272 {
273 if (!m_logicalAddresses[iDevicePtr])
274 m_busDevices[iDevicePtr]->PollVendorId();
275 }
276
277 Sleep(5);
278 }
279
280 return NULL;
281 }
282
283 bool CCECProcessor::SetActiveSource(cec_device_type type /* = CEC_DEVICE_TYPE_RESERVED */)
284 {
285 bool bReturn(false);
286
287 if (!IsRunning())
288 return bReturn;
289
290 cec_logical_address addr = m_logicalAddresses.primary;
291
292 if (type != CEC_DEVICE_TYPE_RESERVED)
293 {
294 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
295 {
296 if (m_logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
297 {
298 addr = (cec_logical_address) iPtr;
299 break;
300 }
301 }
302 }
303
304 return SetStreamPath(m_busDevices[addr]->GetPhysicalAddress()) &&
305 m_busDevices[addr]->TransmitActiveSource();
306 }
307
308 bool CCECProcessor::SetActiveView(void)
309 {
310 return SetActiveSource(m_types.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED : m_types[0]);
311 }
312
313 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode, bool bSendUpdate /* = true */)
314 {
315 bool bReturn(false);
316
317 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
318 if (device)
319 {
320 ((CCECPlaybackDevice *) device)->SetDeckControlMode(mode);
321 if (bSendUpdate)
322 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
323 bReturn = true;
324 }
325
326 return bReturn;
327 }
328
329 bool CCECProcessor::SetDeckInfo(cec_deck_info info, bool bSendUpdate /* = true */)
330 {
331 bool bReturn(false);
332
333 CCECBusDevice *device = GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE);
334 if (device)
335 {
336 ((CCECPlaybackDevice *) device)->SetDeckStatus(info);
337 if (bSendUpdate)
338 ((CCECPlaybackDevice *) device)->TransmitDeckStatus(CECDEVICE_TV);
339 bReturn = true;
340 }
341
342 return bReturn;
343 }
344
345 bool CCECProcessor::SetStreamPath(uint16_t iStreamPath)
346 {
347 bool bReturn(false);
348
349 CCECBusDevice *device = GetDeviceByPhysicalAddress(iStreamPath);
350 if (device)
351 {
352 device->SetActiveDevice();
353 bReturn = true;
354 }
355
356 return bReturn;
357 }
358
359 bool CCECProcessor::SetInactiveView(void)
360 {
361 if (!IsRunning())
362 return false;
363
364 if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
365 return m_busDevices[m_logicalAddresses.primary]->TransmitInactiveView();
366 return false;
367 }
368
369 void CCECProcessor::LogOutput(const cec_command &data)
370 {
371 CStdString strTx;
372 strTx.Format("<< %02x", ((uint8_t)data.initiator << 4) + (uint8_t)data.destination);
373 if (data.opcode_set)
374 strTx.AppendFormat(":%02x", (uint8_t)data.opcode);
375
376 for (uint8_t iPtr = 0; iPtr < data.parameters.size; iPtr++)
377 strTx.AppendFormat(":%02x", data.parameters[iPtr]);
378 m_controller->AddLog(CEC_LOG_TRAFFIC, strTx.c_str());
379 }
380
381 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress)
382 {
383 if (m_logicalAddresses.primary != iLogicalAddress)
384 {
385 CStdString strLog;
386 strLog.Format("<< setting primary logical address to %1x", iLogicalAddress);
387 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
388 m_logicalAddresses.primary = iLogicalAddress;
389 m_logicalAddresses.Set(iLogicalAddress);
390 return SetAckMask(m_logicalAddresses.AckMask());
391 }
392
393 return true;
394 }
395
396 bool CCECProcessor::SetMenuState(cec_menu_state state, bool bSendUpdate /* = true */)
397 {
398 for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
399 {
400 if (m_logicalAddresses[iPtr])
401 m_busDevices[iPtr]->SetMenuState(state);
402 }
403
404 if (bSendUpdate)
405 m_busDevices[m_logicalAddresses.primary]->TransmitMenuState(CECDEVICE_TV);
406
407 return true;
408 }
409
410 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress)
411 {
412 if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
413 {
414 m_busDevices[m_logicalAddresses.primary]->SetPhysicalAddress(iPhysicalAddress);
415 return SetActiveView();
416 }
417 return false;
418 }
419
420 bool CCECProcessor::SwitchMonitoring(bool bEnable)
421 {
422 CStdString strLog;
423 strLog.Format("== %s monitoring mode ==", bEnable ? "enabling" : "disabling");
424 m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str());
425
426 m_bMonitor = bEnable;
427 if (bEnable)
428 return SetAckMask(0);
429 else
430 return SetAckMask(m_logicalAddresses.AckMask());
431 }
432
433 bool CCECProcessor::PollDevice(cec_logical_address iAddress)
434 {
435 if (iAddress != CECDEVICE_UNKNOWN && m_busDevices[iAddress])
436 return m_busDevices[m_logicalAddresses.primary]->TransmitPoll(iAddress);
437 return false;
438 }
439
440 CCECBusDevice *CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const
441 {
442 if (m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress() == iPhysicalAddress)
443 return m_busDevices[m_logicalAddresses.primary];
444
445 CCECBusDevice *device = NULL;
446 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
447 {
448 if (m_busDevices[iPtr]->GetPhysicalAddress() == iPhysicalAddress)
449 {
450 device = m_busDevices[iPtr];
451 break;
452 }
453 }
454
455 return device;
456 }
457
458 CCECBusDevice *CCECProcessor::GetDeviceByType(cec_device_type type) const
459 {
460 CCECBusDevice *device = NULL;
461
462 for (unsigned int iPtr = 0; iPtr < 16; iPtr++)
463 {
464 if (m_busDevices[iPtr]->m_type == type)
465 {
466 device = m_busDevices[iPtr];
467 break;
468 }
469 }
470
471 return device;
472 }
473
474 cec_version CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress)
475 {
476 return m_busDevices[iAddress]->GetCecVersion();
477 }
478
479 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress, cec_menu_language *language)
480 {
481 if (m_busDevices[iAddress])
482 {
483 *language = m_busDevices[iAddress]->GetMenuLanguage();
484 return (strcmp(language->language, "???") != 0);
485 }
486 return false;
487 }
488
489 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress)
490 {
491 if (m_busDevices[iAddress])
492 return m_busDevices[iAddress]->GetVendorId();
493 return false;
494 }
495
496 cec_power_status CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress)
497 {
498 if (m_busDevices[iAddress])
499 return m_busDevices[iAddress]->GetPowerStatus();
500 return CEC_POWER_STATUS_UNKNOWN;
501 }
502
503 bool CCECProcessor::Transmit(const cec_command &data)
504 {
505 bool bReturn(false);
506 LogOutput(data);
507
508 CCECAdapterMessage *output = new CCECAdapterMessage(data);
509 bReturn = Transmit(output);
510 delete output;
511
512 return bReturn;
513 }
514
515 bool CCECProcessor::Transmit(CCECAdapterMessage *output)
516 {
517 bool bReturn(false);
518 CLockObject lock(&m_mutex);
519 {
520 CLockObject msgLock(&output->mutex);
521 if (!m_communication || !m_communication->Write(output))
522 return bReturn;
523 else
524 {
525 output->condition.Wait(&output->mutex);
526 if (output->state != ADAPTER_MESSAGE_STATE_SENT)
527 {
528 m_controller->AddLog(CEC_LOG_ERROR, "command was not sent");
529 return bReturn;
530 }
531 }
532
533 if (output->transmit_timeout > 0)
534 {
535 if ((bReturn = WaitForTransmitSucceeded(output->size(), output->transmit_timeout)) == false)
536 m_controller->AddLog(CEC_LOG_DEBUG, "did not receive ack");
537 }
538 else
539 bReturn = true;
540 }
541
542 return bReturn;
543 }
544
545 void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode, cec_abort_reason reason /* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
546 {
547 m_controller->AddLog(CEC_LOG_DEBUG, "<< transmitting abort message");
548
549 cec_command command;
550 // TODO
551 cec_command::Format(command, m_logicalAddresses.primary, address, CEC_OPCODE_FEATURE_ABORT);
552 command.parameters.PushBack((uint8_t)opcode);
553 command.parameters.PushBack((uint8_t)reason);
554
555 Transmit(command);
556 }
557
558 bool CCECProcessor::WaitForTransmitSucceeded(uint8_t iLength, uint32_t iTimeout /* = 1000 */)
559 {
560 bool bError(false);
561 bool bTransmitSucceeded(false);
562 uint8_t iPacketsLeft(iLength / 4);
563
564 int64_t iNow = GetTimeMs();
565 int64_t iTargetTime = iNow + (uint64_t) iTimeout;
566
567 while (!bTransmitSucceeded && !bError && (iTimeout == 0 || iNow < iTargetTime))
568 {
569 CCECAdapterMessage msg;
570
571 if (!m_communication->Read(msg, iTimeout > 0 ? (int32_t)(iTargetTime - iNow) : 1000))
572 {
573 iNow = GetTimeMs();
574 continue;
575 }
576
577 if ((bError = msg.is_error()) == false)
578 {
579 m_controller->AddLog(bError ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
580
581 switch(msg.message())
582 {
583 case MSGCODE_COMMAND_ACCEPTED:
584 if (iPacketsLeft > 0)
585 iPacketsLeft--;
586 break;
587 case MSGCODE_TRANSMIT_SUCCEEDED:
588 bTransmitSucceeded = (iPacketsLeft == 0);
589 bError = !bTransmitSucceeded;
590 break;
591 default:
592 if (ParseMessage(msg))
593 m_commandBuffer.Push(m_currentframe);
594 }
595
596 iNow = GetTimeMs();
597 }
598 }
599
600 return bTransmitSucceeded && !bError;
601 }
602
603 bool CCECProcessor::ParseMessage(const CCECAdapterMessage &msg)
604 {
605 bool bEom = false;
606
607 if (msg.empty())
608 return bEom;
609
610 switch(msg.message())
611 {
612 case MSGCODE_FRAME_START:
613 {
614 m_currentframe.Clear();
615 if (msg.size() >= 2)
616 {
617 m_currentframe.initiator = msg.initiator();
618 m_currentframe.destination = msg.destination();
619 m_currentframe.ack = msg.ack();
620 m_currentframe.eom = msg.eom();
621 }
622 }
623 break;
624 case MSGCODE_FRAME_DATA:
625 {
626 if (msg.size() >= 2)
627 {
628 m_currentframe.PushBack(msg[1]);
629 m_currentframe.eom = msg.eom();
630 }
631 bEom = msg.eom();
632 }
633 break;
634 default:
635 break;
636 }
637
638 return bEom;
639 }
640
641 void CCECProcessor::ParseCommand(cec_command &command)
642 {
643 CStdString dataStr;
644 dataStr.Format(">> %1x%1x:%02x", command.initiator, command.destination, command.opcode);
645 for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
646 dataStr.AppendFormat(":%02x", (unsigned int)command.parameters[iPtr]);
647 m_controller->AddLog(CEC_LOG_TRAFFIC, dataStr.c_str());
648
649 if (!m_bMonitor && command.initiator >= CECDEVICE_TV && command.initiator <= CECDEVICE_BROADCAST)
650 m_busDevices[(uint8_t)command.initiator]->HandleCommand(command);
651 }
652
653 cec_logical_addresses CCECProcessor::GetActiveDevices(void)
654 {
655 cec_logical_addresses addresses;
656 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
657 {
658 if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
659 addresses.Set((cec_logical_address) iPtr);
660 }
661 return addresses;
662 }
663
664 bool CCECProcessor::IsActiveDevice(cec_logical_address address)
665 {
666 return m_busDevices[address]->GetStatus() == CEC_DEVICE_STATUS_PRESENT;
667 }
668
669 bool CCECProcessor::IsActiveDeviceType(cec_device_type type)
670 {
671 for (unsigned int iPtr = 0; iPtr < 15; iPtr++)
672 {
673 if (m_busDevices[iPtr]->GetType() == type && m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT)
674 return true;
675 }
676
677 return false;
678 }
679
680 uint16_t CCECProcessor::GetPhysicalAddress(void) const
681 {
682 if (!m_logicalAddresses.IsEmpty() && m_busDevices[m_logicalAddresses.primary])
683 return m_busDevices[m_logicalAddresses.primary]->GetPhysicalAddress();
684 return false;
685 }
686
687 void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode)
688 {
689 m_controller->SetCurrentButton(iButtonCode);
690 }
691
692 void CCECProcessor::AddCommand(const cec_command &command)
693 {
694 m_controller->AddCommand(command);
695 }
696
697 void CCECProcessor::AddKey(cec_keypress &key)
698 {
699 m_controller->AddKey(key);
700 }
701
702 void CCECProcessor::AddKey(void)
703 {
704 m_controller->AddKey();
705 }
706
707 void CCECProcessor::AddLog(cec_log_level level, const CStdString &strMessage)
708 {
709 m_controller->AddLog(level, strMessage);
710 }
711
712 bool CCECProcessor::SetAckMask(uint16_t iMask)
713 {
714 bool bReturn(false);
715 CStdString strLog;
716 strLog.Format("setting ackmask to %2x", iMask);
717 m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str());
718
719 CCECAdapterMessage *output = new CCECAdapterMessage;
720
721 output->push_back(MSGSTART);
722 output->push_escaped(MSGCODE_SET_ACK_MASK);
723 output->push_escaped(iMask >> 8);
724 output->push_escaped((uint8_t)iMask);
725 output->push_back(MSGEND);
726
727 if ((bReturn = Transmit(output)) == false)
728 m_controller->AddLog(CEC_LOG_ERROR, "could not set the ackmask");
729
730 delete output;
731
732 return bReturn;
733 }