From: Lars Op den Kamp Date: Mon, 6 Aug 2012 10:34:38 +0000 (+0200) Subject: Merge branch 'development' X-Git-Tag: upstream/2.2.0~1^2~19^2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a8c39f8cb07622051f5091468efbcd980c833cff;hp=f8edb2973d37f3ebfd08291f28be5435d0cf8f64;p=deb_libcec.git Merge branch 'development' --- diff --git a/ChangeLog b/ChangeLog index 12e2792..5c43fc2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,29 @@ +libcec (1.8.2-1) unstable; urgency=low + + * changed/added: + * p8: match to the response provided by the firmware when checking + responses (added in firmware v2 rev6) + + * fixed: + * windows: update the error message when an error occurs while writing to + the serial port + * delayed source switch time was reset, resulting in an attempt every + second until it succeeded + * ensure that the vendor commands are always sent for panasonic, and that + the deck status for lg isn't reset. fixes some buttons not working after + a second or delayed source switch + * added guard so ReplaceHandler() doesn't accidently try to replace a + handler for the broadcast address + * wait until the commandhandler is replaced before registering a client, + so we don't register a client and replace it directly afterwards if the + tv doesn't support the device type + * ensure that the command handler of the tv is replaced before registering + a client, or it might result in a double eeprom write attempt + * p8: don't disable controlled mode when switching to monitoring mode + * p8: do delayed eeprom writes async or it'll block processing other input + + -- Pulse-Eight Packaging Tue, 3 Aug 2012 02:35:00 +0100 + libcec (1.8.1-1) unstable; urgency=low * changed/added: diff --git a/debian/changelog b/debian/changelog index 12e2792..5c43fc2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,29 @@ +libcec (1.8.2-1) unstable; urgency=low + + * changed/added: + * p8: match to the response provided by the firmware when checking + responses (added in firmware v2 rev6) + + * fixed: + * windows: update the error message when an error occurs while writing to + the serial port + * delayed source switch time was reset, resulting in an attempt every + second until it succeeded + * ensure that the vendor commands are always sent for panasonic, and that + the deck status for lg isn't reset. fixes some buttons not working after + a second or delayed source switch + * added guard so ReplaceHandler() doesn't accidently try to replace a + handler for the broadcast address + * wait until the commandhandler is replaced before registering a client, + so we don't register a client and replace it directly afterwards if the + tv doesn't support the device type + * ensure that the command handler of the tv is replaced before registering + a client, or it might result in a double eeprom write attempt + * p8: don't disable controlled mode when switching to monitoring mode + * p8: do delayed eeprom writes async or it'll block processing other input + + -- Pulse-Eight Packaging Tue, 3 Aug 2012 02:35:00 +0100 + libcec (1.8.1-1) unstable; urgency=low * changed/added: diff --git a/include/cec.h b/include/cec.h index 807bcd9..bd56fff 100644 --- a/include/cec.h +++ b/include/cec.h @@ -36,7 +36,7 @@ #include "cectypes.h" -#define LIBCEC_VERSION_CURRENT CEC_SERVER_VERSION_1_8_0 +#define LIBCEC_VERSION_CURRENT CEC_SERVER_VERSION_1_8_1 namespace CEC { diff --git a/include/cectypes.h b/include/cectypes.h index 794e124..4656141 100644 --- a/include/cectypes.h +++ b/include/cectypes.h @@ -1230,7 +1230,8 @@ typedef enum cec_client_version CEC_CLIENT_VERSION_1_7_0 = 0x1700, CEC_CLIENT_VERSION_1_7_1 = 0x1701, CEC_CLIENT_VERSION_1_7_2 = 0x1702, - CEC_CLIENT_VERSION_1_8_0 = 0x1800 + CEC_CLIENT_VERSION_1_8_0 = 0x1800, + CEC_CLIENT_VERSION_1_8_1 = 0x1801 } cec_client_version; typedef enum cec_server_version @@ -1247,7 +1248,8 @@ typedef enum cec_server_version CEC_SERVER_VERSION_1_7_0 = 0x1700, CEC_SERVER_VERSION_1_7_1 = 0x1701, CEC_SERVER_VERSION_1_7_2 = 0x1702, - CEC_SERVER_VERSION_1_8_0 = 0x1800 + CEC_SERVER_VERSION_1_8_0 = 0x1800, + CEC_SERVER_VERSION_1_8_1 = 0x1801 } cec_server_version; typedef struct libcec_configuration diff --git a/project/cec-config.rc b/project/cec-config.rc index be84610..9355214 100644 Binary files a/project/cec-config.rc and b/project/cec-config.rc differ diff --git a/project/libcec.rc b/project/libcec.rc index a73c7fd..05e40fe 100644 Binary files a/project/libcec.rc and b/project/libcec.rc differ diff --git a/project/testclient.rc b/project/testclient.rc index 0ee2868..8d5a34b 100644 Binary files a/project/testclient.rc and b/project/testclient.rc differ diff --git a/src/CecSharpTester/CecSharpClient.cs b/src/CecSharpTester/CecSharpClient.cs index 843823c..0d58134 100644 --- a/src/CecSharpTester/CecSharpClient.cs +++ b/src/CecSharpTester/CecSharpClient.cs @@ -43,7 +43,7 @@ namespace CecSharpClient Config = new LibCECConfiguration(); Config.DeviceTypes.Types[0] = CecDeviceType.RecordingDevice; Config.DeviceName = "CEC Tester"; - Config.ClientVersion = CecClientVersion.Version1_8_0; + Config.ClientVersion = CecClientVersion.Version1_8_1; Config.SetCallbacks(this); LogLevel = (int)CecLogLevel.All; diff --git a/src/CecSharpTester/Properties/AssemblyInfo.cs b/src/CecSharpTester/Properties/AssemblyInfo.cs index d941918..7161761 100644 --- a/src/CecSharpTester/Properties/AssemblyInfo.cs +++ b/src/CecSharpTester/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.8.0.0")] -[assembly: AssemblyFileVersion("1.8.0.0")] +[assembly: AssemblyVersion("1.8.1.0")] +[assembly: AssemblyFileVersion("1.8.1.0")] diff --git a/src/LibCecSharp/AssemblyInfo.cpp b/src/LibCecSharp/AssemblyInfo.cpp index 1640d3c..8cfa0ad 100644 --- a/src/LibCecSharp/AssemblyInfo.cpp +++ b/src/LibCecSharp/AssemblyInfo.cpp @@ -13,7 +13,7 @@ using namespace System::Security::Permissions; [assembly:AssemblyTrademarkAttribute("")]; [assembly:AssemblyCultureAttribute("")]; -[assembly:AssemblyVersionAttribute("1.8.0.0")]; +[assembly:AssemblyVersionAttribute("1.8.1.0")]; [assembly:ComVisible(false)]; [assembly:CLSCompliantAttribute(true)]; diff --git a/src/LibCecSharp/CecSharpTypes.h b/src/LibCecSharp/CecSharpTypes.h index 0ba3c04..7b02c0d 100644 --- a/src/LibCecSharp/CecSharpTypes.h +++ b/src/LibCecSharp/CecSharpTypes.h @@ -370,7 +370,8 @@ namespace CecSharp Version1_7_0 = 0x1700, Version1_7_1 = 0x1701, Version1_7_2 = 0x1702, - Version1_8_0 = 0x1800 + Version1_8_0 = 0x1800, + Version1_8_1 = 0x1801 }; public enum class CecServerVersion @@ -387,7 +388,8 @@ namespace CecSharp Version1_7_0 = 0x1700, Version1_7_1 = 0x1701, Version1_7_2 = 0x1702, - Version1_8_0 = 0x1800 + Version1_8_0 = 0x1800, + Version1_8_1 = 0x1801 }; public ref class CecAdapter diff --git a/src/cec-config-gui/CecConfigGUI.cs b/src/cec-config-gui/CecConfigGUI.cs index a57ac35..7521b09 100644 --- a/src/cec-config-gui/CecConfigGUI.cs +++ b/src/cec-config-gui/CecConfigGUI.cs @@ -28,7 +28,7 @@ namespace CecConfigGui Config.DeviceTypes.Types[0] = CecDeviceType.RecordingDevice; Config.DeviceName = "CEC Config"; Config.GetSettingsFromROM = true; - Config.ClientVersion = CecClientVersion.Version1_8_0; + Config.ClientVersion = CecClientVersion.Version1_8_1; Callbacks = new CecCallbackWrapper(this); Config.SetCallbacks(Callbacks); LoadXMLConfiguration(ref Config); diff --git a/src/cec-config-gui/Properties/AssemblyInfo.cs b/src/cec-config-gui/Properties/AssemblyInfo.cs index d47600b..91c1763 100644 --- a/src/cec-config-gui/Properties/AssemblyInfo.cs +++ b/src/cec-config-gui/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.8.0.0")] -[assembly: AssemblyFileVersion("1.8.0.0")] +[assembly: AssemblyVersion("1.8.1.0")] +[assembly: AssemblyFileVersion("1.8.1.0")] diff --git a/src/cec-config/cec-config.cpp b/src/cec-config/cec-config.cpp index fbfdd36..d7775e9 100644 --- a/src/cec-config/cec-config.cpp +++ b/src/cec-config/cec-config.cpp @@ -159,7 +159,7 @@ bool OpenConnection(cec_device_type type = CEC_DEVICE_TYPE_RECORDING_DEVICE) g_config.Clear(); snprintf(g_config.strDeviceName, 13, "CEC-config"); g_config.callbackParam = NULL; - g_config.clientVersion = (uint32_t)CEC_CLIENT_VERSION_1_6_2; + g_config.clientVersion = (uint32_t)CEC_CLIENT_VERSION_1_8_1; g_callbacks.CBCecLogMessage = &CecLogMessage; g_callbacks.CBCecKeyPress = &CecKeyPress; g_callbacks.CBCecCommand = &CecCommand; diff --git a/src/lib/CECClient.cpp b/src/lib/CECClient.cpp index b6c0812..e7ac955 100644 --- a/src/lib/CECClient.cpp +++ b/src/lib/CECClient.cpp @@ -1249,13 +1249,9 @@ bool CCECClient::SwitchMonitoring(bool bEnable) if (m_processor) { - if (bEnable) - return m_processor->UnregisterClient(this); - else - { - m_configuration.bMonitorOnly = false; - return m_processor->RegisterClient(this); - } + m_processor->SwitchMonitoring(bEnable); + m_configuration.bMonitorOnly = bEnable; + return bEnable ? true: m_processor->RegisterClient(this); } return false; diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 76c2465..88795e9 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -62,7 +62,8 @@ CCECProcessor::CCECProcessor(CLibCEC *libcec) : m_libcec(libcec), m_iStandardLineTimeout(3), m_iRetryLineTimeout(3), - m_iLastTransmission(0) + m_iLastTransmission(0), + m_bMonitor(true) { m_busDevices = new CCECDeviceMap(this); } @@ -665,10 +666,19 @@ bool CCECProcessor::RegisterClient(CCECClient *client) // ensure that we know the vendor id of the TV CCECBusDevice *tv = GetTV(); + cec_vendor_id tvVendor = CEC_VENDOR_UNKNOWN; if (m_communication->SupportsSourceLogicalAddress(CECDEVICE_UNREGISTERED)) - tv->GetVendorId(CECDEVICE_UNREGISTERED); + tvVendor = tv->GetVendorId(CECDEVICE_UNREGISTERED); else if (m_communication->SupportsSourceLogicalAddress(CECDEVICE_FREEUSE)) - tv->GetVendorId(CECDEVICE_FREEUSE); + tvVendor = tv->GetVendorId(CECDEVICE_FREEUSE); + + // wait until the handler is replaced, to avoid double registrations + if (tvVendor != CEC_VENDOR_UNKNOWN && + CCECCommandHandler::HasSpecificHandler(tvVendor)) + { + while (!tv->ReplaceHandler(false)) + CEvent::Sleep(5); + } // get the configuration from the client m_libcec->AddLog(CEC_LOG_NOTICE, "registering new CEC client - v%s", ToString((cec_client_version)configuration.clientVersion)); @@ -791,7 +801,7 @@ bool CCECProcessor::UnregisterClient(CCECClient *client) if (SetLogicalAddresses(addresses)) { // no more clients left, disable controlled mode - if (addresses.IsEmpty()) + if (addresses.IsEmpty() && !m_bMonitor) m_communication->SetControlledMode(false); return true; @@ -864,3 +874,13 @@ bool CCECProcessor::IsRunningLatestFirmware(void) m_communication->IsRunningLatestFirmware() : true; } + +void CCECProcessor::SwitchMonitoring(bool bSwitchTo) +{ + { + CLockObject lock(m_mutex); + m_bMonitor = bSwitchTo; + } + if (bSwitchTo) + UnregisterClients(); +} diff --git a/src/lib/CECProcessor.h b/src/lib/CECProcessor.h index 5aa532b..dc8e9f5 100644 --- a/src/lib/CECProcessor.h +++ b/src/lib/CECProcessor.h @@ -127,7 +127,9 @@ namespace CEC bool TryLogicalAddress(cec_logical_address address, cec_version libCECSpecVersion = CEC_VERSION_1_4); bool IsRunningLatestFirmware(void); - private: + void SwitchMonitoring(bool bSwitchTo); + + private: bool OpenConnection(const char *strPort, uint16_t iBaudRate, uint32_t iTimeoutMs, bool bStartListening = true); void SetCECInitialised(bool bSetTo = true); @@ -152,5 +154,6 @@ namespace CEC CCECInputBuffer m_inBuffer; CCECDeviceMap * m_busDevices; std::map m_clients; + bool m_bMonitor; }; }; diff --git a/src/lib/CECTypeUtils.h b/src/lib/CECTypeUtils.h index f088796..7a50d9e 100644 --- a/src/lib/CECTypeUtils.h +++ b/src/lib/CECTypeUtils.h @@ -545,6 +545,8 @@ namespace CEC return "1.7.2"; case CEC_CLIENT_VERSION_1_8_0: return "1.8.0"; + case CEC_CLIENT_VERSION_1_8_1: + return "1.8.1"; default: return "Unknown"; } @@ -580,6 +582,8 @@ namespace CEC return "1.7.2"; case CEC_SERVER_VERSION_1_8_0: return "1.8.0"; + case CEC_SERVER_VERSION_1_8_1: + return "1.8.1"; default: return "Unknown"; } diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp index 053860e..70e45ac 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.cpp @@ -55,8 +55,10 @@ using namespace PLATFORM; // firmware version 2 #define CEC_LATEST_ADAPTER_FW_VERSION 2 -// firmware date Thu Apr 26 20:14:49 2012 +0000 -#define CEC_LATEST_ADAPTER_FW_DATE 0x5009F0A3 +// firmware date Thu Aug 2 08:31:24 UTC 2012 +#define CEC_LATEST_ADAPTER_FW_DATE 0x501a4b0c + +#define CEC_FW_DATE_EXTENDED_RESPONSE 0x501a4b0c #define LIB_CEC m_callback->GetLib() @@ -67,10 +69,9 @@ CUSBCECAdapterCommunication::CUSBCECAdapterCommunication(IAdapterCommunicationCa m_lastPollDestination(CECDEVICE_UNKNOWN), m_bInitialised(false), m_pingThread(NULL), + m_eepromWriteThread(NULL), m_commands(NULL), - m_adapterMessageQueue(NULL), - m_iLastEepromWrite(0), - m_iScheduleEepromWrite(0) + m_adapterMessageQueue(NULL) { m_logicalAddresses.Clear(); for (unsigned int iPtr = CECDEVICE_TV; iPtr < CECDEVICE_BROADCAST; iPtr++) @@ -171,17 +172,27 @@ bool CUSBCECAdapterCommunication::Open(uint32_t iTimeoutMs /* = CEC_DEFAULT_CONN } else if (bStartListening) { - /* start a ping thread, that will ping the adapter every 15 seconds - if it doesn't receive any ping for 30 seconds, it'll switch to auto mode */ - m_pingThread = new CAdapterPingThread(this, CEC_ADAPTER_PING_TIMEOUT); - if (m_pingThread->CreateThread()) + /* start the eeprom write thread, that handles all eeprom writes async */ + m_eepromWriteThread = new CAdapterEepromWriteThread(this); + if (!m_eepromWriteThread->CreateThread()) { - bConnectionOpened = true; + bConnectionOpened = false; + LIB_CEC->AddLog(CEC_LOG_ERROR, "could not create the eeprom write thread"); } else { - bConnectionOpened = false; - LIB_CEC->AddLog(CEC_LOG_ERROR, "could not create a ping thread"); + /* start a ping thread, that will ping the adapter every 15 seconds + if it doesn't receive any ping for 30 seconds, it'll switch to auto mode */ + m_pingThread = new CAdapterPingThread(this, CEC_ADAPTER_PING_TIMEOUT); + if (m_pingThread->CreateThread()) + { + bConnectionOpened = true; + } + else + { + bConnectionOpened = false; + LIB_CEC->AddLog(CEC_LOG_ERROR, "could not create a ping thread"); + } } } @@ -210,6 +221,11 @@ void CUSBCECAdapterCommunication::Close(void) m_adapterMessageQueue->Clear(); + /* stop and delete the write thread */ + if (m_eepromWriteThread) + m_eepromWriteThread->Stop(); + DELETE_AND_NULL(m_eepromWriteThread); + /* stop and delete the ping thread */ DELETE_AND_NULL(m_pingThread); @@ -244,7 +260,6 @@ void *CUSBCECAdapterCommunication::Process(void) CCECAdapterMessage msg; LIB_CEC->AddLog(CEC_LOG_DEBUG, "communication thread started"); - bool bWriteEeprom(false); while (!IsStopped()) { /* read from the serial port */ @@ -257,31 +272,6 @@ void *CUSBCECAdapterCommunication::Process(void) break; } - // check if we need to do another eeprom write - { - CLockObject lock(m_mutex); - int64_t iNow = GetTimeMs(); - if (m_iScheduleEepromWrite > 0 && - m_iScheduleEepromWrite >= iNow) - { - m_iScheduleEepromWrite = 0; - m_iLastEepromWrite = iNow; - bWriteEeprom = true; - } - } - - if (bWriteEeprom) - { - LIB_CEC->AddLog(CEC_LOG_DEBUG, "updating the eeprom (scheduled)"); - bWriteEeprom = false; - if (!m_commands->WriteEEPROM()) - { - // failed, retry later - CLockObject lock(m_mutex); - m_iScheduleEepromWrite = GetTimeMs() + CEC_ADAPTER_EEPROM_WRITE_RETRY; - } - } - /* TODO sleep 5 ms so other threads can get a lock */ Sleep(5); } @@ -571,47 +561,35 @@ uint16_t CUSBCECAdapterCommunication::GetFirmwareVersion(void) uint32_t CUSBCECAdapterCommunication::GetFirmwareBuildDate(void) { - return IsOpen() ? m_commands->RequestBuildDate() : m_commands ? m_commands->GetPersistedBuildDate() : 0; + uint32_t iBuildDate(0); + if (m_commands) + iBuildDate = m_commands->GetPersistedBuildDate(); + if (iBuildDate == 0 && IsOpen()) + iBuildDate = m_commands->RequestBuildDate(); + + return iBuildDate; +} + +bool CUSBCECAdapterCommunication::ProvidesExtendedResponse(void) +{ + uint32_t iBuildDate(0); + if (m_commands) + iBuildDate = m_commands->GetPersistedBuildDate(); + + return iBuildDate >= CEC_FW_DATE_EXTENDED_RESPONSE; } bool CUSBCECAdapterCommunication::IsRunningLatestFirmware(void) { - return GetFirmwareVersion() >= CEC_LATEST_ADAPTER_FW_VERSION && - GetFirmwareBuildDate() >= CEC_LATEST_ADAPTER_FW_DATE; + return GetFirmwareBuildDate() >= CEC_LATEST_ADAPTER_FW_DATE && + GetFirmwareVersion() >= CEC_LATEST_ADAPTER_FW_VERSION; } bool CUSBCECAdapterCommunication::PersistConfiguration(const libcec_configuration &configuration) { - if (IsOpen()) - { - // returns true when something changed - if (m_commands->PersistConfiguration(configuration)) - { - { - CLockObject lock(m_mutex); - uint64_t iNow = GetTimeMs(); - if (iNow - m_iLastEepromWrite < CEC_ADAPTER_EEPROM_WRITE_INTERVAL) - { - // if there was more than 1 write within the last 30 seconds, schedule another one - if (m_iScheduleEepromWrite == 0) - m_iScheduleEepromWrite = m_iLastEepromWrite + CEC_ADAPTER_EEPROM_WRITE_INTERVAL; - return true; - } - else - { - m_iLastEepromWrite = iNow; - } - } - - if (!m_commands->WriteEEPROM()) - { - // write failed, retry later - CLockObject lock(m_mutex); - m_iScheduleEepromWrite = GetTimeMs() + CEC_ADAPTER_EEPROM_WRITE_RETRY; - } - } - } - return IsOpen() ? m_commands->PersistConfiguration(configuration) : false; + return IsOpen() ? + m_commands->PersistConfiguration(configuration) && m_eepromWriteThread->Write() : + false; } bool CUSBCECAdapterCommunication::GetConfiguration(libcec_configuration &configuration) @@ -700,7 +678,62 @@ void *CAdapterPingThread::Process(void) } } - Sleep(500); + Sleep(5); + } + return NULL; +} + +void CAdapterEepromWriteThread::Stop(void) +{ + StopThread(-1); + { + CLockObject lock(m_mutex); + if (m_iScheduleEepromWrite > 0) + m_com->LIB_CEC->AddLog(CEC_LOG_WARNING, "write thread stopped while a write was queued"); + m_condition.Signal(); + } + StopThread(); +} + +void *CAdapterEepromWriteThread::Process(void) +{ + while (!IsStopped()) + { + CLockObject lock(m_mutex); + if ((m_iScheduleEepromWrite > 0 && m_iScheduleEepromWrite < GetTimeMs()) || + m_condition.Wait(m_mutex, m_bWrite, 100)) + { + m_bWrite = false; + if (m_com->m_commands->WriteEEPROM()) + { + m_iLastEepromWrite = GetTimeMs(); + m_iScheduleEepromWrite = 0; + } + else + { + m_iScheduleEepromWrite = GetTimeMs() + CEC_ADAPTER_EEPROM_WRITE_RETRY; + } + } } return NULL; } + +bool CAdapterEepromWriteThread::Write(void) +{ + CLockObject lock(m_mutex); + if (m_iScheduleEepromWrite == 0) + { + int64_t iNow = GetTimeMs(); + if (m_iLastEepromWrite + CEC_ADAPTER_EEPROM_WRITE_INTERVAL > iNow) + { + m_com->LIB_CEC->AddLog(CEC_LOG_DEBUG, "delaying eeprom write by %ld ms", m_iLastEepromWrite + CEC_ADAPTER_EEPROM_WRITE_INTERVAL - iNow); + m_iScheduleEepromWrite = m_iLastEepromWrite + CEC_ADAPTER_EEPROM_WRITE_INTERVAL; + } + else + { + m_bWrite = true; + m_condition.Signal(); + } + } + return true; +} diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h index 5b065f3..1144d0e 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterCommunication.h @@ -43,6 +43,7 @@ namespace CEC { class CCECProcessor; class CAdapterPingThread; + class CAdapterEepromWriteThread; class CUSBCECAdapterCommands; class CCECAdapterMessageQueue; class CCECAdapterMessage; @@ -51,6 +52,7 @@ namespace CEC { friend class CUSBCECAdapterCommands; friend class CCECAdapterMessageQueue; + friend class CAdapterEepromWriteThread; public: /*! @@ -86,6 +88,8 @@ namespace CEC bool SupportsSourceLogicalAddress(const cec_logical_address UNUSED(address)) { return true; } ///} + bool ProvidesExtendedResponse(void); + void *Process(void); private: @@ -169,11 +173,32 @@ namespace CEC bool m_bInitialised; /**< true when the connection is initialised, false otherwise */ bool m_bWaitingForAck[15]; /**< array in which we store from which devices we're expecting acks */ CAdapterPingThread * m_pingThread; /**< ping thread, that pings the adapter every 15 seconds */ + CAdapterEepromWriteThread * m_eepromWriteThread; /**< eeprom writes are done async */ CUSBCECAdapterCommands * m_commands; /**< commands that can be sent to the adapter */ CCECAdapterMessageQueue * m_adapterMessageQueue; /**< the incoming and outgoing message queue */ cec_logical_addresses m_logicalAddresses; /**< the logical address list that this instance is using */ - int64_t m_iLastEepromWrite; /**< last time that this instance did an eeprom write */ - int64_t m_iScheduleEepromWrite; /**< in case there were more than 2 changes within 30 seconds, do another write at this time */ + }; + + class CAdapterEepromWriteThread : public PLATFORM::CThread + { + public: + CAdapterEepromWriteThread(CUSBCECAdapterCommunication *com) : + m_com(com), + m_bWrite(false), + m_iLastEepromWrite(0), + m_iScheduleEepromWrite(0) {} + virtual ~CAdapterEepromWriteThread(void) {} + + bool Write(void); + void* Process(void); + void Stop(void); + private: + CUSBCECAdapterCommunication *m_com; + bool m_bWrite; + PLATFORM::CCondition m_condition; + PLATFORM::CMutex m_mutex; + int64_t m_iLastEepromWrite; /**< last time that this instance did an eeprom write */ + int64_t m_iScheduleEepromWrite; /**< in case there were more than 2 changes within 30 seconds, do another write at this time */ }; class CAdapterPingThread : public PLATFORM::CThread @@ -184,7 +209,7 @@ namespace CEC m_timeout(iTimeout){} virtual ~CAdapterPingThread(void) {} - virtual void* Process(void); + void* Process(void); private: CUSBCECAdapterCommunication *m_com; PLATFORM::CTimeout m_timeout; diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.cpp b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.cpp index f213c1d..08e6c35 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.cpp +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.cpp @@ -126,9 +126,14 @@ std::string CCECAdapterMessage::ToString(void) const strMsg.AppendFormat(" %02x %s", At(2), IsEOM() ? "eom" : ""); break; default: - for (uint8_t iPtr = 2; iPtr < Size(); iPtr++) - if (At(iPtr) != MSGEND) - strMsg.AppendFormat(" %02x", At(iPtr)); + if (Size() >= 2 && (Message() == MSGCODE_COMMAND_ACCEPTED || Message() == MSGCODE_COMMAND_REJECTED)) + strMsg.AppendFormat(": %s", ToString((cec_adapter_messagecode)At(2))); + else + { + for (uint8_t iPtr = 2; iPtr < Size(); iPtr++) + if (At(iPtr) != MSGEND) + strMsg.AppendFormat(" %02x", At(iPtr)); + } break; } } @@ -329,6 +334,13 @@ cec_adapter_messagecode CCECAdapterMessage::Message(void) const MSGCODE_NOTHING; } +cec_adapter_messagecode CCECAdapterMessage::ResponseTo(void) const +{ + return packet.size >= 3 ? + (cec_adapter_messagecode) (packet.At(2) & ~(MSGCODE_FRAME_EOM | MSGCODE_FRAME_ACK)) : + MSGCODE_NOTHING; +} + bool CCECAdapterMessage::IsTranmission(void) const { cec_adapter_messagecode msgCode = Message(); diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.h b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.h index e4fedce..40ee1a4 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.h +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessage.h @@ -127,6 +127,11 @@ namespace CEC */ cec_adapter_messagecode Message(void) const; + /*! + * @return The messagecode (if provided) that this message is responding to + */ + cec_adapter_messagecode ResponseTo(void) const; + /*! * @return True when this message is a transmission, false otherwise. */ diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.cpp b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.cpp index c713eea..b05a20e 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.cpp +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.cpp @@ -113,21 +113,76 @@ cec_adapter_messagecode CCECAdapterMessageQueueEntry::MessageCode(void) return m_message->Message(); } -bool CCECAdapterMessageQueueEntry::IsResponse(const CCECAdapterMessage &msg) +bool CCECAdapterMessageQueueEntry::IsResponseOld(const CCECAdapterMessage &msg) { cec_adapter_messagecode msgCode = msg.Message(); + return msgCode == MessageCode() || - (m_message->IsTranmission() && msgCode == MSGCODE_TIMEOUT_ERROR) || msgCode == MSGCODE_COMMAND_ACCEPTED || msgCode == MSGCODE_COMMAND_REJECTED || - (m_message->IsTranmission() && msgCode == MSGCODE_HIGH_ERROR) || - (m_message->IsTranmission() && msgCode == MSGCODE_LOW_ERROR) || - (m_message->IsTranmission() && msgCode == MSGCODE_RECEIVE_FAILED) || - (m_message->IsTranmission() && msgCode == MSGCODE_TRANSMIT_FAILED_LINE) || - (m_message->IsTranmission() && msgCode == MSGCODE_TRANSMIT_FAILED_ACK) || - (m_message->IsTranmission() && msgCode == MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA) || - (m_message->IsTranmission() && msgCode == MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE) || - (m_message->IsTranmission() && msgCode == MSGCODE_TRANSMIT_SUCCEEDED); + (m_message->IsTranmission() && (msgCode == MSGCODE_TIMEOUT_ERROR || + msgCode == MSGCODE_HIGH_ERROR || + msgCode == MSGCODE_LOW_ERROR || + msgCode == MSGCODE_RECEIVE_FAILED || + msgCode == MSGCODE_TRANSMIT_FAILED_LINE || + msgCode == MSGCODE_TRANSMIT_FAILED_ACK || + msgCode == MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA || + msgCode == MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE || + msgCode == MSGCODE_TRANSMIT_SUCCEEDED)); +} + +bool CCECAdapterMessageQueueEntry::IsResponse(const CCECAdapterMessage &msg) +{ + cec_adapter_messagecode thisMsgCode = m_message->Message(); + cec_adapter_messagecode msgCode = msg.Message(); + cec_adapter_messagecode msgResponse = msg.ResponseTo(); + + // msgcode matches, always a response + if (msgCode == MessageCode()) + return true; + + if (!ProvidesExtendedResponse()) + return IsResponseOld(msg); + + // response without a msgcode + if (msgResponse == MSGCODE_NOTHING) + { + m_queue->m_com->m_callback->GetLib()->AddLog(CEC_LOG_WARNING, "no response code received"); + return true; + } + + // commands that only repond with accepted/rejected + if (thisMsgCode == MSGCODE_PING || + thisMsgCode == MSGCODE_SET_ACK_MASK || + thisMsgCode == MSGCODE_SET_CONTROLLED || + thisMsgCode == MSGCODE_SET_AUTO_ENABLED || + thisMsgCode == MSGCODE_SET_DEFAULT_LOGICAL_ADDRESS || + thisMsgCode == MSGCODE_SET_LOGICAL_ADDRESS_MASK || + thisMsgCode == MSGCODE_SET_PHYSICAL_ADDRESS || + thisMsgCode == MSGCODE_SET_DEVICE_TYPE || + thisMsgCode == MSGCODE_SET_HDMI_VERSION || + thisMsgCode == MSGCODE_SET_OSD_NAME || + thisMsgCode == MSGCODE_WRITE_EEPROM || + thisMsgCode == MSGCODE_TRANSMIT_IDLETIME) + return thisMsgCode == msgResponse; + + if (!m_message->IsTranmission()) + { + m_queue->m_com->m_callback->GetLib()->AddLog(CEC_LOG_WARNING, "FIXME! not a transmission"); + return false; + } + + return ((msgCode == MSGCODE_COMMAND_ACCEPTED || msgCode == MSGCODE_COMMAND_REJECTED) && + (msgResponse == MSGCODE_TRANSMIT_ACK_POLARITY || msgResponse == MSGCODE_TRANSMIT || msgResponse == MSGCODE_TRANSMIT_EOM)) || + msgCode == MSGCODE_TIMEOUT_ERROR || + msgCode == MSGCODE_HIGH_ERROR || + msgCode == MSGCODE_LOW_ERROR || + msgCode == MSGCODE_RECEIVE_FAILED || + msgCode == MSGCODE_TRANSMIT_FAILED_LINE || + msgCode == MSGCODE_TRANSMIT_FAILED_ACK || + msgCode == MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA || + msgCode == MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE || + msgCode == MSGCODE_TRANSMIT_SUCCEEDED; } const char *CCECAdapterMessageQueueEntry::ToString(void) const @@ -216,6 +271,11 @@ bool CCECAdapterMessageQueueEntry::MessageReceivedResponse(const CCECAdapterMess return true; } +bool CCECAdapterMessageQueueEntry::ProvidesExtendedResponse(void) +{ + return m_queue && m_queue->ProvidesExtendedResponse(); +} + CCECAdapterMessageQueue::CCECAdapterMessageQueue(CUSBCECAdapterCommunication *com) : PLATFORM::CThread(), m_com(com), @@ -359,3 +419,8 @@ bool CCECAdapterMessageQueue::Write(CCECAdapterMessage *msg) return bReturn; } + +bool CCECAdapterMessageQueue::ProvidesExtendedResponse(void) +{ + return m_com && m_com->ProvidesExtendedResponse(); +} diff --git a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.h b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.h index 6e325a7..edd34be 100644 --- a/src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.h +++ b/src/lib/adapter/Pulse-Eight/USBCECAdapterMessageQueue.h @@ -82,6 +82,7 @@ namespace CEC * @return True when it's a response, false otherwise. */ bool IsResponse(const CCECAdapterMessage &msg); + bool IsResponseOld(const CCECAdapterMessage &msg); /*! * @return The command that was sent in human readable form. @@ -114,6 +115,8 @@ namespace CEC */ void Signal(void); + bool ProvidesExtendedResponse(void); + CCECAdapterMessageQueue * m_queue; CCECAdapterMessage * m_message; /**< the message that was sent */ uint8_t m_iPacketsLeft; /**< the amount of acks that we're waiting on */ @@ -162,6 +165,8 @@ namespace CEC */ bool Write(CCECAdapterMessage *msg); + bool ProvidesExtendedResponse(void); + virtual void *Process(void); private: diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 5b3e2cb..466e977 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -95,6 +95,9 @@ CCECBusDevice::~CCECBusDevice(void) bool CCECBusDevice::ReplaceHandler(bool bActivateSource /* = true */) { + if (m_iLogicalAddress == CECDEVICE_BROADCAST) + return false; + bool bInitHandler(false); { CLockObject lock(m_mutex); diff --git a/src/lib/devices/CECBusDevice.h b/src/lib/devices/CECBusDevice.h index 4e21553..d208fd9 100644 --- a/src/lib/devices/CECBusDevice.h +++ b/src/lib/devices/CECBusDevice.h @@ -266,8 +266,8 @@ namespace CEC bool m_bReplaceHandler; cec_menu_state m_menuState; bool m_bActiveSource; - uint64_t m_iLastActive; - uint64_t m_iLastPowerStateUpdate; + int64_t m_iLastActive; + int64_t m_iLastPowerStateUpdate; cec_version m_cecVersion; cec_bus_device_status m_deviceStatus; std::set m_unsupportedFeatures; diff --git a/src/lib/implementations/CECCommandHandler.cpp b/src/lib/implementations/CECCommandHandler.cpp index 46edf98..f20f6af 100644 --- a/src/lib/implementations/CECCommandHandler.cpp +++ b/src/lib/implementations/CECCommandHandler.cpp @@ -1114,17 +1114,19 @@ bool CCECCommandHandler::ActivateSource(bool bTransmitDelayedCommandsOnly /* = f LIB_CEC->AddLog(CEC_LOG_DEBUG, "transmitting delayed activate source command"); } - - // clear previous pending active source command - m_iActiveSourcePending = 0; } // update the power state and menu state m_busDevice->SetPowerStatus(CEC_POWER_STATUS_ON); - m_busDevice->SetMenuState(CEC_MENU_STATE_ACTIVATED); // TODO: LG + m_busDevice->SetMenuState(CEC_MENU_STATE_ACTIVATED); + + // vendor specific hook + VendorPreActivateSourceHook(); // power on the TV - bool bActiveSourceFailed = !m_busDevice->TransmitImageViewOn(); + bool bActiveSourceFailed(false); + if (m_processor->GetDevice(CECDEVICE_TV)->GetPowerStatus(m_busDevice->GetLogicalAddress()) != CEC_POWER_STATUS_ON) + bActiveSourceFailed = !m_busDevice->TransmitImageViewOn(); // check if we're allowed to switch sources bool bSourceSwitchAllowed = SourceSwitchAllowed(); @@ -1151,9 +1153,16 @@ bool CCECCommandHandler::ActivateSource(bool bTransmitDelayedCommandsOnly /* = f { LIB_CEC->AddLog(CEC_LOG_DEBUG, "failed to make '%s' the active source. will retry later", m_busDevice->GetLogicalAddressName()); CLockObject lock(m_mutex); - m_iActiveSourcePending = GetTimeMs() + (int64_t)CEC_ACTIVE_SOURCE_SWITCH_RETRY_TIME_MS; + if (m_iActiveSourcePending == 0) + m_iActiveSourcePending = GetTimeMs() + (int64_t)CEC_ACTIVE_SOURCE_SWITCH_RETRY_TIME_MS; return false; } + else + { + CLockObject lock(m_mutex); + // clear previous pending active source command + m_iActiveSourcePending = 0; + } // mark the handler as initialised CLockObject lock(m_mutex); diff --git a/src/lib/implementations/CECCommandHandler.h b/src/lib/implementations/CECCommandHandler.h index 45e3522..61f9f47 100644 --- a/src/lib/implementations/CECCommandHandler.h +++ b/src/lib/implementations/CECCommandHandler.h @@ -138,6 +138,8 @@ namespace CEC virtual int HandleVendorRemoteButtonUp(const cec_command & UNUSED(command)) { return CEC_ABORT_REASON_REFUSED; } virtual void UnhandledCommand(const cec_command &command, const cec_abort_reason reason); + virtual void VendorPreActivateSourceHook(void) {}; + virtual size_t GetMyDevices(std::vector &devices) const; virtual CCECBusDevice *GetDevice(cec_logical_address iLogicalAddress) const; virtual CCECBusDevice *GetDeviceByPhysicalAddress(uint16_t iPhysicalAddress) const; diff --git a/src/lib/implementations/SLCommandHandler.cpp b/src/lib/implementations/SLCommandHandler.cpp index 32902c2..f495b8b 100644 --- a/src/lib/implementations/SLCommandHandler.cpp +++ b/src/lib/implementations/SLCommandHandler.cpp @@ -416,3 +416,10 @@ bool CSLCommandHandler::PowerOn(const cec_logical_address iInitiator, const cec_ return CCECCommandHandler::PowerOn(iInitiator, iDestination); } + +void CSLCommandHandler::VendorPreActivateSourceHook(void) +{ + CCECPlaybackDevice *device = m_busDevice->AsPlaybackDevice(); + if (device) + device->SetDeckStatus(!device->IsActiveSource() ? CEC_DECK_INFO_OTHER_STATUS : CEC_DECK_INFO_OTHER_STATUS_LG); +} diff --git a/src/lib/implementations/SLCommandHandler.h b/src/lib/implementations/SLCommandHandler.h index 8cc64f1..2cbef7b 100644 --- a/src/lib/implementations/SLCommandHandler.h +++ b/src/lib/implementations/SLCommandHandler.h @@ -74,6 +74,8 @@ namespace CEC void SetSLInitialised(void); bool ActiveSourceSent(void); + void VendorPreActivateSourceHook(void); + bool m_bSLEnabled; bool m_bActiveSourceSent; PLATFORM::CTimeout m_resetPowerState; diff --git a/src/lib/implementations/VLCommandHandler.cpp b/src/lib/implementations/VLCommandHandler.cpp index e78f942..e74daac 100644 --- a/src/lib/implementations/VLCommandHandler.cpp +++ b/src/lib/implementations/VLCommandHandler.cpp @@ -52,7 +52,7 @@ using namespace PLATFORM; #define ToString(p) LIB_CEC->ToString(p) // wait this amount of ms before trying to switch sources after receiving the message from the TV that it's powered on -#define SOURCE_SWITCH_DELAY_MS 1000 +#define SOURCE_SWITCH_DELAY_MS 3000 CVLCommandHandler::CVLCommandHandler(CCECBusDevice *busDevice, int32_t iTransmitTimeout /* = CEC_DEFAULT_TRANSMIT_TIMEOUT */, @@ -60,7 +60,8 @@ CVLCommandHandler::CVLCommandHandler(CCECBusDevice *busDevice, int8_t iTransmitRetries /* = CEC_DEFAULT_TRANSMIT_RETRIES */, int64_t iActiveSourcePending /* = 0 */) : CCECCommandHandler(busDevice, iTransmitTimeout, iTransmitWait, iTransmitRetries, iActiveSourcePending), - m_iPowerUpEventReceived(0) + m_iPowerUpEventReceived(0), + m_bCapabilitiesSent(false) { m_vendorId = CEC_VENDOR_PANASONIC; } @@ -82,8 +83,6 @@ bool CVLCommandHandler::InitHandler(void) if (primary->GetType() == CEC_DEVICE_TYPE_RECORDING_DEVICE) return m_processor->GetPrimaryClient()->ChangeDeviceType(CEC_DEVICE_TYPE_RECORDING_DEVICE, CEC_DEVICE_TYPE_PLAYBACK_DEVICE); - - m_processor->GetTV()->RequestPowerStatus(primary->GetLogicalAddress(), false); } return CCECCommandHandler::InitHandler(); @@ -96,6 +95,8 @@ int CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &comman command.parameters[2] != 0x45) return CEC_ABORT_REASON_INVALID_OPERAND; + // XXX this is also sent when the TV is powered off +#if 0 if (command.initiator == CECDEVICE_TV && command.parameters.At(3) == VL_UNKNOWN1) { @@ -108,7 +109,9 @@ int CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &comman // mark the TV as powered on m_processor->GetTV()->SetPowerStatus(CEC_POWER_STATUS_ON); } - else if (command.initiator == CECDEVICE_TV && + else +#endif + if (command.initiator == CECDEVICE_TV && command.destination == CECDEVICE_BROADCAST && command.parameters.At(3) == VL_POWER_CHANGE) { @@ -122,6 +125,9 @@ int CVLCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &comman } // mark the TV as powered on m_processor->GetTV()->SetPowerStatus(CEC_POWER_STATUS_ON); + + // send capabilties + SendVendorCommandCapabilities(m_processor->GetLogicalAddress(), command.initiator); } else if (command.parameters.At(4) == VL_POWERED_DOWN) { @@ -189,6 +195,34 @@ int CVLCommandHandler::HandleStandby(const cec_command &command) return CCECCommandHandler::HandleStandby(command); } +void CVLCommandHandler::VendorPreActivateSourceHook(void) +{ + bool bTransmit(false); + { + CLockObject lock(m_mutex); + bTransmit = m_bCapabilitiesSent; + } + if (bTransmit) + SendVendorCommandCapabilities(m_processor->GetLogicalAddress(), CECDEVICE_TV); +} + +void CVLCommandHandler::SendVendorCommandCapabilities(const cec_logical_address initiator, const cec_logical_address destination) +{ + cec_command response; + cec_command::Format(response, initiator, destination, CEC_OPCODE_VENDOR_COMMAND); + uint8_t iResponseData[] = {0x10, 0x02, 0xFF, 0xFF, 0x00, 0x05, 0x05, 0x45, 0x55, 0x5c, 0x58, 0x32}; + response.PushArray(12, iResponseData); + + if (Transmit(response, false, true)) + { + if (PowerUpEventReceived()) + { + CLockObject lock(m_mutex); + m_bCapabilitiesSent = true; + } + } +} + int CVLCommandHandler::HandleVendorCommand(const cec_command &command) { // some vendor command voodoo that will enable more buttons on the remote @@ -197,13 +231,7 @@ int CVLCommandHandler::HandleVendorCommand(const cec_command &command) command.parameters[1] == 0x01 && command.parameters[2] == 0x05) { - cec_command response; - cec_command::Format(response, command.destination, command.initiator, CEC_OPCODE_VENDOR_COMMAND); - uint8_t iResponseData[] = {0x10, 0x02, 0xFF, 0xFF, 0x00, 0x05, 0x05, 0x45, 0x55, 0x5c, 0x58, 0x32}; - response.PushArray(12, iResponseData); - - Transmit(response, false, true); - + SendVendorCommandCapabilities(m_processor->GetLogicalAddress(), command.initiator); return COMMAND_HANDLED; } @@ -231,3 +259,17 @@ int CVLCommandHandler::HandleSystemAudioModeRequest(const cec_command &command) return CCECCommandHandler::HandleSystemAudioModeRequest(command); } + +int CVLCommandHandler::HandleReportPowerStatus(const cec_command &command) +{ + if (command.initiator == m_busDevice->GetLogicalAddress() && + command.parameters.size == 1 && + (cec_power_status)command.parameters[0] == CEC_POWER_STATUS_ON) + { + CLockObject lock(m_mutex); + if (m_iPowerUpEventReceived == 0) + m_iPowerUpEventReceived = GetTimeMs(); + } + + return CCECCommandHandler::HandleReportPowerStatus(command); +} diff --git a/src/lib/implementations/VLCommandHandler.h b/src/lib/implementations/VLCommandHandler.h index d1b25d2..3ad80b4 100644 --- a/src/lib/implementations/VLCommandHandler.h +++ b/src/lib/implementations/VLCommandHandler.h @@ -58,8 +58,13 @@ namespace CEC bool SourceSwitchAllowed(void); - private: + protected: + void VendorPreActivateSourceHook(void); + void SendVendorCommandCapabilities(const cec_logical_address initiator, const cec_logical_address destination); + int HandleReportPowerStatus(const cec_command &command); + PLATFORM::CMutex m_mutex; uint64_t m_iPowerUpEventReceived; + bool m_bCapabilitiesSent; }; }; diff --git a/src/lib/platform/windows/serialport.cpp b/src/lib/platform/windows/serialport.cpp index ad7f871..c595468 100644 --- a/src/lib/platform/windows/serialport.cpp +++ b/src/lib/platform/windows/serialport.cpp @@ -100,7 +100,17 @@ void CSerialSocket::Shutdown(void) ssize_t CSerialSocket::Write(void* data, size_t len) { - return IsOpen() ? SerialSocketWrite(m_socket, &m_iError, data, len) : -1; + if (IsOpen()) + { + ssize_t iReturn = SerialSocketWrite(m_socket, &m_iError, data, len); + if (iReturn != len) + { + m_strError = "unable to write to the serial port"; + FormatWindowsError(GetLastError(), m_strError); + } + return iReturn; + } + return -1; } ssize_t CSerialSocket::Read(void* data, size_t len, uint64_t iTimeoutMs /* = 0 */) @@ -169,6 +179,7 @@ bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */) return false; } + m_strError.clear(); m_bIsOpen = true; return m_bIsOpen; } diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index 97bdcc6..e594eaf 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -47,7 +47,7 @@ using namespace CEC; using namespace std; using namespace PLATFORM; -#define CEC_CONFIG_VERSION CEC_CLIENT_VERSION_1_8_0; +#define CEC_CONFIG_VERSION CEC_CLIENT_VERSION_1_8_1; #include