bool CCECProcessor::StartBootloader(const char *strPort /* = NULL */)
{
+ bool bReturn(false);
if (!m_communication && strPort)
{
- bool bReturn(false);
IAdapterCommunication *comm = new CUSBCECAdapterCommunication(this, strPort);
CTimeout timeout(CEC_DEFAULT_CONNECT_TIMEOUT);
int iConnectTry(0);
}
else
{
- return m_communication->StartBootloader();
+ m_communication->StartBootloader();
+ Close();
+ bReturn = true;
}
+
+ return bReturn;
}
bool CCECProcessor::PingAdapter(void)
while (!IsStopped())
{
/* wait for a new message */
- if (m_writeQueue.Pop(message, MESSAGE_QUEUE_SIGNAL_WAIT_TIME))
+ if (m_writeQueue.Pop(message, MESSAGE_QUEUE_SIGNAL_WAIT_TIME) && message)
{
/* write this message */
- m_com->WriteToDevice(message->m_message);
- if (message->m_message->state == ADAPTER_MESSAGE_STATE_ERROR)
+ {
+ CLockObject lock(m_mutex);
+ m_com->WriteToDevice(message->m_message);
+ }
+ if (message->m_message->state == ADAPTER_MESSAGE_STATE_ERROR ||
+ message->m_message->Message() == MSGCODE_START_BOOTLOADER)
{
message->Signal();
Clear();
m_com->SetLineTimeout(msg->lineTimeout);
}
- CCECAdapterMessageQueueEntry *entry(NULL);
+ CCECAdapterMessageQueueEntry *entry = new CCECAdapterMessageQueueEntry(msg);
uint64_t iEntryId(0);
/* add to the wait for ack queue */
if (msg->Message() != MSGCODE_START_BOOTLOADER)
{
CLockObject lock(m_mutex);
- entry = new CCECAdapterMessageQueueEntry(msg);
iEntryId = m_iNextMessage++;
m_messages.insert(make_pair(iEntryId, entry));
}
bReturn = false;
}
- CLockObject lock(m_mutex);
- m_messages.erase(iEntryId);
+ if (msg->Message() != MSGCODE_START_BOOTLOADER)
+ {
+ CLockObject lock(m_mutex);
+ m_messages.erase(iEntryId);
+ }
delete entry;
}