2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
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/
33 #include "CECProcessor.h"
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"
44 #include "util/StdString.h"
45 #include "platform/timeutils.h"
50 CCECProcessor::CCECProcessor(CLibCEC
*controller
, CAdapterCommunication
*serComm
, const char *strDeviceName
, cec_logical_address iLogicalAddress
/* = CECDEVICE_PLAYBACKDEVICE1 */, uint16_t iPhysicalAddress
/* = CEC_DEFAULT_PHYSICAL_ADDRESS*/) :
52 m_iHDMIPort(CEC_DEFAULT_HDMI_PORT
),
53 m_strDeviceName(strDeviceName
),
54 m_communication(serComm
),
55 m_controller(controller
),
59 m_logicalAddresses
.Clear();
60 m_logicalAddresses
.Set(iLogicalAddress
);
62 for (int iPtr
= 0; iPtr
<= 16; iPtr
++)
63 m_busDevices
[iPtr
] = new CCECBusDevice(this, (cec_logical_address
) iPtr
, iPtr
== iLogicalAddress
? iPhysicalAddress
: 0);
66 CCECProcessor::CCECProcessor(CLibCEC
*controller
, CAdapterCommunication
*serComm
, const char *strDeviceName
, const cec_device_type_list
&types
) :
68 m_iHDMIPort(CEC_DEFAULT_HDMI_PORT
),
69 m_strDeviceName(strDeviceName
),
71 m_communication(serComm
),
72 m_controller(controller
),
75 m_logicalAddresses
.Clear();
76 for (int iPtr
= 0; iPtr
< 16; iPtr
++)
80 case CECDEVICE_AUDIOSYSTEM
:
81 m_busDevices
[iPtr
] = new CCECAudioSystem(this, (cec_logical_address
) iPtr
, 0xFFFF);
83 case CECDEVICE_PLAYBACKDEVICE1
:
84 case CECDEVICE_PLAYBACKDEVICE2
:
85 case CECDEVICE_PLAYBACKDEVICE3
:
86 m_busDevices
[iPtr
] = new CCECPlaybackDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
88 case CECDEVICE_RECORDINGDEVICE1
:
89 case CECDEVICE_RECORDINGDEVICE2
:
90 case CECDEVICE_RECORDINGDEVICE3
:
91 m_busDevices
[iPtr
] = new CCECRecordingDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
93 case CECDEVICE_TUNER1
:
94 case CECDEVICE_TUNER2
:
95 case CECDEVICE_TUNER3
:
96 case CECDEVICE_TUNER4
:
97 m_busDevices
[iPtr
] = new CCECTuner(this, (cec_logical_address
) iPtr
, 0xFFFF);
100 m_busDevices
[iPtr
] = new CCECTV(this, (cec_logical_address
) iPtr
, 0);
103 m_busDevices
[iPtr
] = new CCECBusDevice(this, (cec_logical_address
) iPtr
, 0xFFFF);
109 CCECProcessor::~CCECProcessor(void)
113 m_busScan
->StopThread();
117 m_startCondition
.Broadcast();
120 m_communication
= NULL
;
122 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
123 delete m_busDevices
[iPtr
];
126 bool CCECProcessor::Start(void)
128 CLockObject
lock(&m_mutex
);
129 if (!m_communication
|| !m_communication
->IsOpen())
131 m_controller
->AddLog(CEC_LOG_ERROR
, "connection is closed");
137 if (!m_startCondition
.Wait(&m_mutex
) || !m_bStarted
)
139 m_controller
->AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
144 if (SetAckMask(m_logicalAddresses
.AckMask()) &&
145 SetHDMIPort(m_iHDMIPort
, true))
147 m_busScan
= new CCECBusScan(this);
148 m_busScan
->CreateThread(true);
153 m_controller
->AddLog(CEC_LOG_ERROR
, "could not create a processor thread");
158 bool CCECProcessor::TryLogicalAddress(cec_logical_address address
)
160 if (m_busDevices
[address
]->TryLogicalAddress())
162 /* only set our OSD name and active source for the primary device */
163 if (m_logicalAddresses
.IsEmpty())
165 m_busDevices
[address
]->m_strDeviceName
= m_strDeviceName
;
166 m_busDevices
[address
]->m_bActiveSource
= true;
168 m_logicalAddresses
.Set(address
);
175 bool CCECProcessor::FindLogicalAddressRecordingDevice(void)
177 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'recording device'");
178 return TryLogicalAddress(CECDEVICE_RECORDINGDEVICE1
) ||
179 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE2
) ||
180 TryLogicalAddress(CECDEVICE_RECORDINGDEVICE3
);
183 bool CCECProcessor::FindLogicalAddressTuner(void)
185 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'tuner'");
186 return TryLogicalAddress(CECDEVICE_TUNER1
) ||
187 TryLogicalAddress(CECDEVICE_TUNER2
) ||
188 TryLogicalAddress(CECDEVICE_TUNER3
) ||
189 TryLogicalAddress(CECDEVICE_TUNER4
);
192 bool CCECProcessor::FindLogicalAddressPlaybackDevice(void)
194 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'playback device'");
195 return TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE1
) ||
196 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE2
) ||
197 TryLogicalAddress(CECDEVICE_PLAYBACKDEVICE3
);
200 bool CCECProcessor::FindLogicalAddressAudioSystem(void)
202 AddLog(CEC_LOG_DEBUG
, "detecting logical address for type 'audio'");
203 return TryLogicalAddress(CECDEVICE_AUDIOSYSTEM
);
206 bool CCECProcessor::FindLogicalAddresses(void)
209 m_logicalAddresses
.Clear();
212 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
214 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_RESERVED
)
217 strLog
.Format("%s - device %d: type %d", __FUNCTION__
, iPtr
, m_types
.types
[iPtr
]);
218 AddLog(CEC_LOG_DEBUG
, strLog
);
220 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_RECORDING_DEVICE
)
221 bReturn
&= FindLogicalAddressRecordingDevice();
222 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_TUNER
)
223 bReturn
&= FindLogicalAddressTuner();
224 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_PLAYBACK_DEVICE
)
225 bReturn
&= FindLogicalAddressPlaybackDevice();
226 if (m_types
.types
[iPtr
] == CEC_DEVICE_TYPE_AUDIO_SYSTEM
)
227 bReturn
&= FindLogicalAddressAudioSystem();
233 void *CCECProcessor::Process(void)
235 bool bParseFrame(false);
237 CCECAdapterMessage msg
;
239 if (m_logicalAddresses
.IsEmpty() && !FindLogicalAddresses())
241 CLockObject
lock(&m_mutex
);
242 m_controller
->AddLog(CEC_LOG_ERROR
, "could not detect our logical addresses");
243 m_startCondition
.Signal();
248 CLockObject
lock(&m_mutex
);
250 m_controller
->AddLog(CEC_LOG_DEBUG
, "processor thread started");
251 m_startCondition
.Signal();
260 CLockObject
lock(&m_mutex
);
261 if (m_commandBuffer
.Pop(command
))
265 else if (m_communication
->IsOpen() && m_communication
->Read(msg
, 50))
267 m_controller
->AddLog(msg
.is_error() ? CEC_LOG_WARNING
: CEC_LOG_DEBUG
, msg
.ToString());
268 if ((bParseFrame
= (ParseMessage(msg
) && !IsStopped())) == true)
269 command
= m_currentframe
;
274 ParseCommand(command
);
279 m_controller
->CheckKeypressTimeout();
285 bool CCECProcessor::SetActiveSource(cec_device_type type
/* = CEC_DEVICE_TYPE_RESERVED */)
292 cec_logical_address addr
= m_logicalAddresses
.primary
;
294 if (type
!= CEC_DEVICE_TYPE_RESERVED
)
296 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
298 if (m_logicalAddresses
[iPtr
] && m_busDevices
[iPtr
]->m_type
== type
)
300 addr
= (cec_logical_address
) iPtr
;
306 return SetStreamPath(m_busDevices
[addr
]->GetPhysicalAddress(false)) &&
307 m_busDevices
[addr
]->TransmitActiveSource();
310 bool CCECProcessor::SetActiveSource(cec_logical_address iAddress
)
312 return SetStreamPath(m_busDevices
[iAddress
]->GetPhysicalAddress(false));
315 bool CCECProcessor::SetActiveView(void)
317 return SetActiveSource(m_types
.IsEmpty() ? CEC_DEVICE_TYPE_RESERVED
: m_types
[0]);
320 bool CCECProcessor::SetDeckControlMode(cec_deck_control_mode mode
, bool bSendUpdate
/* = true */)
324 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
327 ((CCECPlaybackDevice
*) device
)->SetDeckControlMode(mode
);
329 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
336 bool CCECProcessor::SetDeckInfo(cec_deck_info info
, bool bSendUpdate
/* = true */)
340 CCECBusDevice
*device
= GetDeviceByType(CEC_DEVICE_TYPE_PLAYBACK_DEVICE
);
343 ((CCECPlaybackDevice
*) device
)->SetDeckStatus(info
);
345 ((CCECPlaybackDevice
*) device
)->TransmitDeckStatus(CECDEVICE_TV
);
352 bool CCECProcessor::SetHDMIPort(uint8_t iPort
, bool bForce
/* = false */)
357 strLog
.Format("setting HDMI port to %d", iPort
);
358 AddLog(CEC_LOG_DEBUG
, strLog
);
361 if (!m_bStarted
&& !bForce
)
364 uint16_t iPhysicalAddress(0);
366 while(!bReturn
&& iPos
>= 0)
368 iPhysicalAddress
+= ((uint16_t)iPort
* (0x1 << iPos
*4));
369 strLog
.Format("checking physical address %4x", iPhysicalAddress
);
370 AddLog(CEC_LOG_DEBUG
, strLog
);
371 if (CheckPhysicalAddress(iPhysicalAddress
))
373 strLog
.Format("physical address %4x is in use", iPhysicalAddress
);
374 AddLog(CEC_LOG_DEBUG
, strLog
);
379 SetPhysicalAddress(iPhysicalAddress
);
387 bool CCECProcessor::CheckPhysicalAddress(uint16_t iPhysicalAddress
)
389 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
391 if (m_busDevices
[iPtr
]->GetPhysicalAddress(false) == iPhysicalAddress
)
397 bool CCECProcessor::SetStreamPath(uint16_t iStreamPath
)
401 CCECBusDevice
*device
= GetDeviceByPhysicalAddress(iStreamPath
);
404 device
->SetActiveDevice();
411 bool CCECProcessor::TransmitInactiveSource(void)
416 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
417 return m_busDevices
[m_logicalAddresses
.primary
]->TransmitInactiveSource();
421 void CCECProcessor::LogOutput(const cec_command
&data
)
424 strTx
.Format("<< %02x", ((uint8_t)data
.initiator
<< 4) + (uint8_t)data
.destination
);
426 strTx
.AppendFormat(":%02x", (uint8_t)data
.opcode
);
428 for (uint8_t iPtr
= 0; iPtr
< data
.parameters
.size
; iPtr
++)
429 strTx
.AppendFormat(":%02x", data
.parameters
[iPtr
]);
430 m_controller
->AddLog(CEC_LOG_TRAFFIC
, strTx
.c_str());
433 bool CCECProcessor::SetLogicalAddress(cec_logical_address iLogicalAddress
)
435 if (m_logicalAddresses
.primary
!= iLogicalAddress
)
438 strLog
.Format("<< setting primary logical address to %1x", iLogicalAddress
);
439 m_controller
->AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
440 m_logicalAddresses
.primary
= iLogicalAddress
;
441 m_logicalAddresses
.Set(iLogicalAddress
);
442 return SetAckMask(m_logicalAddresses
.AckMask());
448 bool CCECProcessor::SetMenuState(cec_menu_state state
, bool bSendUpdate
/* = true */)
450 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
452 if (m_logicalAddresses
[iPtr
])
453 m_busDevices
[iPtr
]->SetMenuState(state
);
457 m_busDevices
[m_logicalAddresses
.primary
]->TransmitMenuState(CECDEVICE_TV
);
462 bool CCECProcessor::SetPhysicalAddress(uint16_t iPhysicalAddress
)
464 if (!m_logicalAddresses
.IsEmpty())
466 for (uint8_t iPtr
= 0; iPtr
< 15; iPtr
++)
467 if (m_logicalAddresses
[iPtr
])
468 m_busDevices
[iPtr
]->SetPhysicalAddress(iPhysicalAddress
);
469 return SetActiveView();
474 bool CCECProcessor::SwitchMonitoring(bool bEnable
)
477 strLog
.Format("== %s monitoring mode ==", bEnable
? "enabling" : "disabling");
478 m_controller
->AddLog(CEC_LOG_NOTICE
, strLog
.c_str());
480 m_bMonitor
= bEnable
;
482 return SetAckMask(0);
484 return SetAckMask(m_logicalAddresses
.AckMask());
487 bool CCECProcessor::PollDevice(cec_logical_address iAddress
)
489 if (iAddress
!= CECDEVICE_UNKNOWN
&& m_busDevices
[iAddress
])
491 return m_logicalAddresses
.primary
== CECDEVICE_UNKNOWN
?
492 m_busDevices
[iAddress
]->TransmitPoll(iAddress
) :
493 m_busDevices
[m_logicalAddresses
.primary
]->TransmitPoll(iAddress
);
498 uint8_t CCECProcessor::VolumeUp(bool bWait
/* = true */)
501 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM
))
502 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeUp(bWait
);
507 uint8_t CCECProcessor::VolumeDown(bool bWait
/* = true */)
510 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM
))
511 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->VolumeDown(bWait
);
516 uint8_t CCECProcessor::MuteAudio(bool bWait
/* = true */)
519 if (IsActiveDevice(CECDEVICE_AUDIOSYSTEM
))
520 status
= ((CCECAudioSystem
*)m_busDevices
[CECDEVICE_AUDIOSYSTEM
])->MuteAudio(bWait
);
525 CCECBusDevice
*CCECProcessor::GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress
, bool bRefresh
/* = false */) const
527 if (m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false) == iPhysicalAddress
)
528 return m_busDevices
[m_logicalAddresses
.primary
];
530 CCECBusDevice
*device
= NULL
;
531 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
533 if (m_busDevices
[iPtr
]->GetPhysicalAddress(bRefresh
) == iPhysicalAddress
)
535 device
= m_busDevices
[iPtr
];
543 CCECBusDevice
*CCECProcessor::GetDeviceByType(cec_device_type type
) const
545 CCECBusDevice
*device
= NULL
;
547 for (unsigned int iPtr
= 0; iPtr
< 16; iPtr
++)
549 if (m_busDevices
[iPtr
]->m_type
== type
)
551 device
= m_busDevices
[iPtr
];
559 cec_version
CCECProcessor::GetDeviceCecVersion(cec_logical_address iAddress
)
561 return m_busDevices
[iAddress
]->GetCecVersion();
564 cec_osd_name
CCECProcessor::GetDeviceOSDName(cec_logical_address iAddress
)
566 CStdString strOSDName
= m_busDevices
[iAddress
]->GetOSDName();
569 snprintf(retVal
.name
, sizeof(retVal
.name
), "%s", strOSDName
.c_str());
570 retVal
.device
= iAddress
;
575 bool CCECProcessor::GetDeviceMenuLanguage(cec_logical_address iAddress
, cec_menu_language
*language
)
577 if (m_busDevices
[iAddress
])
579 *language
= m_busDevices
[iAddress
]->GetMenuLanguage();
580 return (strcmp(language
->language
, "???") != 0);
585 uint64_t CCECProcessor::GetDeviceVendorId(cec_logical_address iAddress
)
587 if (m_busDevices
[iAddress
])
588 return m_busDevices
[iAddress
]->GetVendorId();
592 cec_power_status
CCECProcessor::GetDevicePowerStatus(cec_logical_address iAddress
)
594 if (m_busDevices
[iAddress
])
595 return m_busDevices
[iAddress
]->GetPowerStatus();
596 return CEC_POWER_STATUS_UNKNOWN
;
599 bool CCECProcessor::Transmit(const cec_command
&data
)
604 CCECAdapterMessage
*output
= new CCECAdapterMessage(data
);
605 bReturn
= Transmit(output
);
611 bool CCECProcessor::Transmit(CCECAdapterMessage
*output
)
614 CLockObject
lock(&m_mutex
);
616 CLockObject
msgLock(&output
->mutex
);
617 if (!m_communication
|| !m_communication
->Write(output
))
621 output
->condition
.Wait(&output
->mutex
);
622 if (output
->state
!= ADAPTER_MESSAGE_STATE_SENT
)
624 m_controller
->AddLog(CEC_LOG_ERROR
, "command was not sent");
629 if (output
->transmit_timeout
> 0)
631 if ((bReturn
= WaitForTransmitSucceeded(output
->size(), output
->transmit_timeout
)) == false)
632 m_controller
->AddLog(CEC_LOG_DEBUG
, "did not receive ack");
641 void CCECProcessor::TransmitAbort(cec_logical_address address
, cec_opcode opcode
, cec_abort_reason reason
/* = CEC_ABORT_REASON_UNRECOGNIZED_OPCODE */)
643 m_controller
->AddLog(CEC_LOG_DEBUG
, "<< transmitting abort message");
647 cec_command::Format(command
, m_logicalAddresses
.primary
, address
, CEC_OPCODE_FEATURE_ABORT
);
648 command
.parameters
.PushBack((uint8_t)opcode
);
649 command
.parameters
.PushBack((uint8_t)reason
);
654 bool CCECProcessor::WaitForTransmitSucceeded(uint8_t iLength
, uint32_t iTimeout
/* = 1000 */)
657 bool bTransmitSucceeded(false);
658 uint8_t iPacketsLeft(iLength
/ 4);
660 int64_t iNow
= GetTimeMs();
661 int64_t iTargetTime
= iNow
+ (uint64_t) iTimeout
;
663 while (!bTransmitSucceeded
&& !bError
&& (iTimeout
== 0 || iNow
< iTargetTime
))
665 CCECAdapterMessage msg
;
667 if (!m_communication
->Read(msg
, iTimeout
> 0 ? (int32_t)(iTargetTime
- iNow
) : 1000))
673 if ((bError
= msg
.is_error()) == false)
675 m_controller
->AddLog(bError
? CEC_LOG_WARNING
: CEC_LOG_DEBUG
, msg
.ToString());
677 switch(msg
.message())
679 case MSGCODE_COMMAND_ACCEPTED
:
680 if (iPacketsLeft
> 0)
683 case MSGCODE_TRANSMIT_SUCCEEDED
:
684 bTransmitSucceeded
= (iPacketsLeft
== 0);
685 bError
= !bTransmitSucceeded
;
688 if (ParseMessage(msg
))
689 m_commandBuffer
.Push(m_currentframe
);
696 return bTransmitSucceeded
&& !bError
;
699 bool CCECProcessor::ParseMessage(const CCECAdapterMessage
&msg
)
706 switch(msg
.message())
708 case MSGCODE_FRAME_START
:
710 m_currentframe
.Clear();
713 m_currentframe
.initiator
= msg
.initiator();
714 m_currentframe
.destination
= msg
.destination();
715 m_currentframe
.ack
= msg
.ack();
716 m_currentframe
.eom
= msg
.eom();
720 case MSGCODE_FRAME_DATA
:
724 m_currentframe
.PushBack(msg
[1]);
725 m_currentframe
.eom
= msg
.eom();
737 void CCECProcessor::ParseCommand(cec_command
&command
)
740 dataStr
.Format(">> %1x%1x:%02x", command
.initiator
, command
.destination
, command
.opcode
);
741 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
742 dataStr
.AppendFormat(":%02x", (unsigned int)command
.parameters
[iPtr
]);
743 m_controller
->AddLog(CEC_LOG_TRAFFIC
, dataStr
.c_str());
745 if (!m_bMonitor
&& command
.initiator
>= CECDEVICE_TV
&& command
.initiator
<= CECDEVICE_BROADCAST
)
746 m_busDevices
[(uint8_t)command
.initiator
]->HandleCommand(command
);
749 cec_logical_addresses
CCECProcessor::GetActiveDevices(void)
751 cec_logical_addresses addresses
;
753 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
755 if (m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
756 addresses
.Set((cec_logical_address
) iPtr
);
761 bool CCECProcessor::IsActiveDevice(cec_logical_address address
)
763 return m_busDevices
[address
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
;
766 bool CCECProcessor::IsActiveDeviceType(cec_device_type type
)
768 for (unsigned int iPtr
= 0; iPtr
< 15; iPtr
++)
770 if (m_busDevices
[iPtr
]->GetType() == type
&& m_busDevices
[iPtr
]->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
777 uint16_t CCECProcessor::GetPhysicalAddress(void) const
779 if (!m_logicalAddresses
.IsEmpty() && m_busDevices
[m_logicalAddresses
.primary
])
780 return m_busDevices
[m_logicalAddresses
.primary
]->GetPhysicalAddress(false);
784 void CCECProcessor::SetCurrentButton(cec_user_control_code iButtonCode
)
786 m_controller
->SetCurrentButton(iButtonCode
);
789 void CCECProcessor::AddCommand(const cec_command
&command
)
791 m_controller
->AddCommand(command
);
794 void CCECProcessor::AddKey(cec_keypress
&key
)
796 m_controller
->AddKey(key
);
799 void CCECProcessor::AddKey(void)
801 m_controller
->AddKey();
804 void CCECProcessor::AddLog(cec_log_level level
, const CStdString
&strMessage
)
806 m_controller
->AddLog(level
, strMessage
);
809 bool CCECProcessor::SetAckMask(uint16_t iMask
)
813 strLog
.Format("setting ackmask to %2x", iMask
);
814 m_controller
->AddLog(CEC_LOG_DEBUG
, strLog
.c_str());
816 CCECAdapterMessage
*output
= new CCECAdapterMessage
;
818 output
->push_back(MSGSTART
);
819 output
->push_escaped(MSGCODE_SET_ACK_MASK
);
820 output
->push_escaped(iMask
>> 8);
821 output
->push_escaped((uint8_t)iMask
);
822 output
->push_back(MSGEND
);
824 if ((bReturn
= Transmit(output
)) == false)
825 m_controller
->AddLog(CEC_LOG_ERROR
, "could not set the ackmask");
832 bool CCECProcessor::SendKeypress(cec_logical_address iDestination
, cec_user_control_code key
, bool bWait
/* = false */)
834 return m_busDevices
[iDestination
]->SendKeypress(key
, bWait
);
837 bool CCECProcessor::SendKeyRelease(cec_logical_address iDestination
, bool bWait
/* = false */)
839 return m_busDevices
[iDestination
]->SendKeyRelease(bWait
);
842 void *CCECBusScan::Process(void)
844 CCECBusDevice
*device(NULL
);
847 for (unsigned int iPtr
= 0; iPtr
< 15 && !IsStopped(); iPtr
++)
849 device
= m_processor
->m_busDevices
[iPtr
];
850 if (device
&& device
->GetStatus() == CEC_DEVICE_STATUS_PRESENT
)
853 device
->GetPhysicalAddress(false);
857 device
->GetCecVersion();
861 device
->GetVendorId();