#define CEC_DEFAULT_TRANSMIT_WAIT 2000
#define CEC_DEFAULT_TRANSMIT_RETRIES 1
#define CEC_PING_ADAPTER_TRIES 5
+#define CEC_FW_VERSION_TRIES 5
#define CEC_MIN_LIB_VERSION 1
#define CEC_LIB_VERSION_MAJOR 1
if (bPingOk)
{
- uint16_t iFirmwareVersion = m_communication->GetFirmwareVersion();
- if ((bReturn = (iFirmwareVersion != CEC_FW_VERSION_UNKNOWN)) == false)
- m_controller->AddLog(CEC_LOG_ERROR, "the adapter is running an unknown firmware version");
+ uint16_t iFirmwareVersion(CEC_FW_VERSION_UNKNOWN);
+ int iFwVersionTry(0);
+ bool bFwVersionOk(false);
+ while (!bFwVersionOk && iFwVersionTry++ < CEC_FW_VERSION_TRIES)
+ {
+ if ((iFirmwareVersion = m_communication->GetFirmwareVersion()) == CEC_FW_VERSION_UNKNOWN)
+ {
+ CLibCEC::AddLog(CEC_LOG_ERROR, "the adapter did not respond with a correct firmware version (try %d of %d)", iFwVersionTry, CEC_FW_VERSION_TRIES);
+ Sleep(500);
+ }
+ }
- CLibCEC::AddLog(CEC_LOG_NOTICE, "CEC Adapter firmware version: %d", iFirmwareVersion);
+ if (iFirmwareVersion == CEC_FW_VERSION_UNKNOWN)
+ {
+ bReturn = false;
+ }
+ else
+ {
+ bReturn = true;
+ CLibCEC::AddLog(CEC_LOG_NOTICE, "CEC Adapter firmware version: %d", iFirmwareVersion);
+ }
}
return bReturn;
return false;
}
- CLibCEC::AddLog(CEC_LOG_DEBUG, "connection opened");
+ 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[1];
- while (m_port->Read(buff, 1, 5) == 1) {}
+ 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())
{
CCECAdapterMessage input;
if (!Read(input, CEC_DEFAULT_TRANSMIT_WAIT) || input.Message() != MSGCODE_FIRMWARE_VERSION || input.Size() != 3)
- CLibCEC::AddLog(CEC_LOG_ERROR, "no or invalid firmware version");
+ CLibCEC::AddLog(CEC_LOG_ERROR, "no or invalid firmware version (size = %d, message = %d)", input.Size(), input.Message());
else
{
m_iFirmwareVersion = (input[1] << 8 | input[2]);