m_bMonitor(false),
m_busScan(NULL),
m_iStandardLineTimeout(3),
- m_iRetryLineTimeout(3)
+ m_iRetryLineTimeout(3),
+ m_iLastTransmission(0)
{
m_communication = new CAdapterCommunication(this);
m_logicalAddresses.Clear();
m_controller(controller),
m_bMonitor(false),
m_iStandardLineTimeout(3),
- m_iRetryLineTimeout(3)
+ m_iRetryLineTimeout(3),
+ m_iLastTransmission(0)
{
m_communication = new CAdapterCommunication(this);
m_logicalAddresses.Clear();
CCECProcessor::~CCECProcessor(void)
{
+ m_bStarted = false;
+ StopThread(false);
+
if (m_busScan)
{
m_busScan->StopThread();
if (type != CEC_DEVICE_TYPE_RESERVED)
{
- for (uint8_t iPtr = 0; iPtr < 16; iPtr++)
+ for (uint8_t iPtr = 0; iPtr <= 11; iPtr++)
{
if (m_logicalAddresses[iPtr] && m_busDevices[iPtr]->m_type == type)
{
CCECAdapterMessage *output = new CCECAdapterMessage(data);
bReturn = Transmit(output);
- delete output;
+ /* set to "not present" on failed ack */
+ if (output->is_error() && output->reply == MSGCODE_TRANSMIT_FAILED_ACK &&
+ output->destination() != CECDEVICE_BROADCAST)
+ m_busDevices[output->destination()]->SetDeviceStatus(CEC_DEVICE_STATUS_NOT_PRESENT);
+
+ delete output;
return bReturn;
}
bool bReturn(false);
CLockObject lock(&m_mutex);
{
+ m_iLastTransmission = GetTimeMs();
m_communication->SetLineTimeout(m_iStandardLineTimeout);
output->tries = 1;
m_currentframe.ack = msg.ack();
m_currentframe.eom = msg.eom();
}
- if (m_currentframe.ack == true)
+ if (m_currentframe.ack == 0x1)
{
m_lastInitiator = m_currentframe.initiator;
m_busDevices[m_lastInitiator]->GetHandler()->HandlePoll(m_currentframe.initiator, m_currentframe.destination);
void *CCECBusScan::Process(void)
{
CCECBusDevice *device(NULL);
- int iCount(50);
+
while (!IsStopped())
{
- if (iCount == 0)
+ for (unsigned int iPtr = 0; iPtr <= 11 && !IsStopped(); iPtr++)
{
- for (unsigned int iPtr = 0; iPtr <= 11 && !IsStopped(); iPtr++)
+ device = m_processor->m_busDevices[iPtr];
+ WaitUntilIdle();
+ if (device && device->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT)
{
- device = m_processor->m_busDevices[iPtr];
- if (device && device->GetStatus(true) == CEC_DEVICE_STATUS_PRESENT)
- {
- if (!IsStopped())
- {
- device->GetVendorId();
- Sleep(5);
- }
- if (!IsStopped())
- {
- device->GetPowerStatus(true);
- Sleep(5);
- }
- }
+ WaitUntilIdle();
+ if (!IsStopped())
+ device->GetVendorId();
+
+ WaitUntilIdle();
+ if (!IsStopped())
+ device->GetPowerStatus(true);
}
}
-
- if (++iCount > 60)
- iCount = 0;
- Sleep(1000);
}
+
return NULL;
}
+void CCECBusScan::WaitUntilIdle(void)
+{
+ if (IsStopped())
+ return;
+
+ int64_t iWaitTime = 3000 - (GetTimeMs() - m_processor->GetLastTransmission());
+ while (iWaitTime > 0)
+ {
+ Sleep(iWaitTime);
+ iWaitTime = 3000 - (GetTimeMs() - m_processor->GetLastTransmission());
+ }
+}
+
bool CCECProcessor::StartBootloader(void)
{
return m_communication->StartBootloader();