m_lastInitiator(CECDEVICE_UNKNOWN),
m_bNextIsEscaped(false),
m_bGotStart(false),
- m_messageProcessor(NULL)
+ m_messageProcessor(NULL),
+ m_bInitialised(false)
{
m_port = new PLATFORM::CSerialPort(strPort, iBaudRate);
}
else
bReturn = true;
+ {
+ CLockObject lock(m_mutex);
+ m_bInitialised = bReturn;
+ }
+
return bReturn;
}
-bool CUSBCECAdapterCommunication::Open(IAdapterCommunicationCallback *cb, uint32_t iTimeoutMs /* = 10000 */)
+bool CUSBCECAdapterCommunication::Open(IAdapterCommunicationCallback *cb, uint32_t iTimeoutMs /* = 10000 */, bool bSkipChecks /* = false */)
{
uint64_t iNow = GetTimeMs();
uint64_t iTimeout = iNow + iTimeoutMs;
CLibCEC::AddLog(CEC_LOG_DEBUG, "connection opened, clearing any previous input and waiting for active transmissions to end before starting");
- //clear any input bytes
- uint8_t buff[1024];
- while (m_port->Read(buff, 1024, 100) > 0)
+ if (!bSkipChecks)
{
- CLibCEC::AddLog(CEC_LOG_DEBUG, "data received, clearing it");
- Sleep(250);
+ //clear any input bytes
+ uint8_t buff[1024];
+ while (m_port->Read(buff, 1024, 100) > 0)
+ {
+ CLibCEC::AddLog(CEC_LOG_DEBUG, "data received, clearing it");
+ Sleep(250);
+ }
}
}
if (CreateThread())
{
- if (!CheckAdapter())
+ if (!bSkipChecks && !CheckAdapter())
{
StopThread();
CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter failed to pass basic checks");
+ return false;
}
else
{
{
CLockObject lock(m_mutex);
ReadFromDevice(50);
- bCommandReceived = m_callback && Read(command, 0);
+ bCommandReceived = m_callback && Read(command, 0) && m_bInitialised;
}
/* push the next command to the callback method if there is one */
if (iTimeout == 0 || !m_rcvCondition.Wait(m_mutex, m_bHasData, iTimeout))
return false;
m_inBuffer.Pop(buf);
- m_bHasData = m_inBuffer.Size() > 0;
+ m_bHasData = !m_inBuffer.IsEmpty();
}
if (buf)
m_currentframe.PushBack(msg[1]);
m_currentframe.eom = msg.IsEOM();
}
- bEom = msg.IsEOM();
}
break;
default:
}
CLibCEC::AddLog(bIsError ? CEC_LOG_WARNING : CEC_LOG_DEBUG, msg.ToString());
- return bEom;
+ return msg.IsEOM();
}
uint16_t CUSBCECAdapterCommunication::GetFirmwareVersion(void)