From: Lars Op den Kamp Date: Tue, 4 Oct 2011 21:19:09 +0000 (+0200) Subject: cec: fixed int parameter sizes and some signed/unsigned warnings. will need to be... X-Git-Tag: upstream/2.2.0~1^2~290 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8bca69de10349c3cfb7ea3ba4ab5f7ebbb34a740;p=deb_libcec.git cec: fixed int parameter sizes and some signed/unsigned warnings. will need to be synced with linux --- diff --git a/include/CECExportsC.h b/include/CECExportsC.h index 61cabd2..b96beba 100644 --- a/include/CECExportsC.h +++ b/include/CECExportsC.h @@ -46,9 +46,9 @@ extern "C" { * @return True when initialised, false otherwise. */ #ifdef __cplusplus -extern DECLSPEC bool cec_init(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); +extern DECLSPEC bool cec_init(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); #else -extern DECLSPEC bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); +extern DECLSPEC bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); #endif /*! @@ -62,7 +62,7 @@ extern DECLSPEC void cec_destroy(void); * @param iTimeout Connection timeout in ms. * @return True when connected, false otherwise. */ -extern DECLSPEC bool cec_open(const char *strPort, int iTimeout); +extern DECLSPEC bool cec_open(const char *strPort, uint64_t iTimeout); /*! * @brief Close the connection to the CEC adapter. diff --git a/include/CECExportsCpp.h b/include/CECExportsCpp.h index f052592..f0a0ac9 100644 --- a/include/CECExportsCpp.h +++ b/include/CECExportsCpp.h @@ -41,7 +41,7 @@ namespace CEC /*! * @see cec_open */ - virtual bool Open(const char *strPort, int iTimeoutMs = 10000) = 0; + virtual bool Open(const char *strPort, uint64_t iTimeoutMs = 10000) = 0; /*! * @see cec_close @@ -122,7 +122,7 @@ namespace CEC }; }; -extern DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); +extern DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); #if !defined(DLL_EXPORT) #if defined(_WIN32) || defined(_WIN64) @@ -135,7 +135,7 @@ static int g_iLibCECInstanceCount = 0; /*! * @see cec_init */ -inline CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS) +inline CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_address iLogicalAddress = CEC::CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS) { typedef void* (__cdecl*_CreateLibCec)(const char *, uint8_t, uint8_t); _CreateLibCec CreateLibCec; @@ -149,7 +149,7 @@ inline CEC::ICECAdapter *LoadLibCec(const char *strName, CEC::cec_logical_addres CreateLibCec = (_CreateLibCec) (GetProcAddress(g_libCEC, "CECCreate")); if (!CreateLibCec) return NULL; - return static_cast< CEC::ICECAdapter* > (CreateLibCec(strName, iLogicalAddress, iPhysicalAddress)); + return static_cast< CEC::ICECAdapter* > (CreateLibCec(strName, (uint8_t) iLogicalAddress, iPhysicalAddress)); } /*! diff --git a/src/lib/AdapterCommunication.cpp b/src/lib/AdapterCommunication.cpp index d56ee16..4b0bcdd 100644 --- a/src/lib/AdapterCommunication.cpp +++ b/src/lib/AdapterCommunication.cpp @@ -58,7 +58,7 @@ CAdapterCommunication::~CAdapterCommunication(void) m_port = NULL; } -bool CAdapterCommunication::Open(const char *strPort, int iBaudRate /* = 38400 */, int iTimeoutMs /* = 10000 */) +bool CAdapterCommunication::Open(const char *strPort, uint16_t iBaudRate /* = 38400 */, uint64_t iTimeoutMs /* = 10000 */) { CLockObject lock(&m_commMutex); if (m_bStarted) @@ -121,16 +121,16 @@ void *CAdapterCommunication::Process(void) return NULL; } -bool CAdapterCommunication::ReadFromDevice(int iTimeout) +bool CAdapterCommunication::ReadFromDevice(uint64_t iTimeout) { uint8_t buff[1024]; CLockObject lock(&m_commMutex); if (!m_port) return false; - int iBytesRead = m_port->Read(buff, sizeof(buff), iTimeout); + int32_t iBytesRead = m_port->Read(buff, sizeof(buff), iTimeout); lock.Leave(); - if (iBytesRead < 0) + if (iBytesRead < 0 || iBytesRead > 256) { CStdString strError; strError.Format("error reading from serial port: %s", m_port->GetError().c_str()); @@ -138,12 +138,12 @@ bool CAdapterCommunication::ReadFromDevice(int iTimeout) return false; } else if (iBytesRead > 0) - AddData(buff, iBytesRead); + AddData(buff, (uint8_t) iBytesRead); return true; } -void CAdapterCommunication::AddData(uint8_t *data, int iLen) +void CAdapterCommunication::AddData(uint8_t *data, uint8_t iLen) { CLockObject lock(&m_bufferMutex); if (iLen + m_iInbufUsed > m_iInbufSize) @@ -162,7 +162,7 @@ bool CAdapterCommunication::Write(const cec_frame &data) { CLockObject lock(&m_commMutex); - if (m_port->Write(data) != data.size()) + if (m_port->Write(data) != (int) data.size()) { CStdString strError; strError.Format("error writing to serial port: %s", m_port->GetError().c_str()); @@ -177,7 +177,7 @@ bool CAdapterCommunication::Write(const cec_frame &data) return true; } -bool CAdapterCommunication::Read(cec_frame &msg, int iTimeout) +bool CAdapterCommunication::Read(cec_frame &msg, uint64_t iTimeout) { CLockObject lock(&m_bufferMutex); diff --git a/src/lib/AdapterCommunication.h b/src/lib/AdapterCommunication.h index 4266017..c95f729 100644 --- a/src/lib/AdapterCommunication.h +++ b/src/lib/AdapterCommunication.h @@ -45,8 +45,8 @@ namespace CEC CAdapterCommunication(CLibCEC *controller); virtual ~CAdapterCommunication(); - bool Open(const char *strPort, int iBaudRate = 38400, int iTimeoutMs = 10000); - bool Read(cec_frame &msg, int iTimeout = 1000); + bool Open(const char *strPort, uint16_t iBaudRate = 38400, uint64_t iTimeoutMs = 10000); + bool Read(cec_frame &msg, uint64_t iTimeout = 1000); bool Write(const cec_frame &frame); bool PingAdapter(void); void Close(void); @@ -59,8 +59,8 @@ namespace CEC bool SetAckMask(uint16_t iMask); static void PushEscaped(cec_frame &vec, uint8_t byte); private: - void AddData(uint8_t *data, int iLen); - bool ReadFromDevice(int iTimeout); + void AddData(uint8_t *data, uint8_t iLen); + bool ReadFromDevice(uint64_t iTimeout); CSerialPort * m_port; CLibCEC * m_controller; diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 4a276ee..258e164 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -112,7 +112,7 @@ bool CCECProcessor::PowerOnDevices(cec_logical_address address /* = CECDEVICE_TV m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str()); cec_frame frame; frame.push_back(GetSourceDestination(address)); - frame.push_back(CEC_OPCODE_TEXT_VIEW_ON); + frame.push_back((uint8_t) CEC_OPCODE_TEXT_VIEW_ON); return Transmit(frame); } @@ -126,7 +126,7 @@ bool CCECProcessor::StandbyDevices(cec_logical_address address /* = CECDEVICE_BR m_controller->AddLog(CEC_LOG_DEBUG, strLog.c_str()); cec_frame frame; frame.push_back(GetSourceDestination(address)); - frame.push_back(CEC_OPCODE_STANDBY); + frame.push_back((uint8_t) CEC_OPCODE_STANDBY); return Transmit(frame); } @@ -138,7 +138,7 @@ bool CCECProcessor::SetActiveView(void) m_controller->AddLog(CEC_LOG_DEBUG, "setting active view"); cec_frame frame; frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST)); - frame.push_back(CEC_OPCODE_ACTIVE_SOURCE); + frame.push_back((uint8_t) CEC_OPCODE_ACTIVE_SOURCE); frame.push_back((m_physicaladdress >> 8) & 0xFF); frame.push_back(m_physicaladdress & 0xFF); return Transmit(frame); @@ -152,7 +152,7 @@ bool CCECProcessor::SetInactiveView(void) m_controller->AddLog(CEC_LOG_DEBUG, "setting inactive view"); cec_frame frame; frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST)); - frame.push_back(CEC_OPCODE_INACTIVE_SOURCE); + frame.push_back((uint8_t) CEC_OPCODE_INACTIVE_SOURCE); frame.push_back((m_physicaladdress >> 8) & 0xFF); frame.push_back(m_physicaladdress & 0xFF); return Transmit(frame); @@ -232,9 +232,9 @@ void CCECProcessor::TransmitAbort(cec_logical_address address, cec_opcode opcode m_controller->AddLog(CEC_LOG_DEBUG, "transmitting abort message"); cec_frame frame; frame.push_back(GetSourceDestination(address)); - frame.push_back(CEC_OPCODE_FEATURE_ABORT); - frame.push_back(opcode); - frame.push_back(reason); + frame.push_back((uint8_t) CEC_OPCODE_FEATURE_ABORT); + frame.push_back((uint8_t) opcode); + frame.push_back((uint8_t) reason); Transmit(frame); } @@ -243,7 +243,7 @@ void CCECProcessor::ReportCECVersion(cec_logical_address address /* = CECDEVICE_ cec_frame frame; m_controller->AddLog(CEC_LOG_NOTICE, "reporting CEC version as 1.3a"); frame.push_back(GetSourceDestination(address)); - frame.push_back(CEC_OPCODE_CEC_VERSION); + frame.push_back((uint8_t) CEC_OPCODE_CEC_VERSION); frame.push_back(CEC_VERSION_1_3A); Transmit(frame); } @@ -257,8 +257,8 @@ void CCECProcessor::ReportPowerState(cec_logical_address address /*= CECDEVICE_T m_controller->AddLog(CEC_LOG_NOTICE, "reporting \"Off\" power status"); frame.push_back(GetSourceDestination(address)); - frame.push_back(CEC_OPCODE_REPORT_POWER_STATUS); - frame.push_back(bOn ? CEC_POWER_STATUS_ON : CEC_POWER_STATUS_STANDBY); + frame.push_back((uint8_t) CEC_OPCODE_REPORT_POWER_STATUS); + frame.push_back(bOn ? (uint8_t) CEC_POWER_STATUS_ON : (uint8_t) CEC_POWER_STATUS_STANDBY); Transmit(frame); } @@ -271,8 +271,8 @@ void CCECProcessor::ReportMenuState(cec_logical_address address /* = CECDEVICE_T m_controller->AddLog(CEC_LOG_NOTICE, "reporting menu state as inactive"); frame.push_back(GetSourceDestination(address)); - frame.push_back(CEC_OPCODE_MENU_STATUS); - frame.push_back(bActive ? CEC_MENU_STATE_ACTIVATED : CEC_MENU_STATE_DEACTIVATED); + frame.push_back((uint8_t) CEC_OPCODE_MENU_STATUS); + frame.push_back(bActive ? (uint8_t) CEC_MENU_STATE_ACTIVATED : (uint8_t) CEC_MENU_STATE_DEACTIVATED); Transmit(frame); } @@ -290,7 +290,7 @@ void CCECProcessor::ReportOSDName(cec_logical_address address /* = CECDEVICE_TV strLog.Format("reporting OSD name as %s", osdname); m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); frame.push_back(GetSourceDestination(address)); - frame.push_back(CEC_OPCODE_SET_OSD_NAME); + frame.push_back((uint8_t) CEC_OPCODE_SET_OSD_NAME); for (unsigned int i = 0; i < strlen(osdname); i++) frame.push_back(osdname[i]); @@ -305,7 +305,7 @@ void CCECProcessor::ReportPhysicalAddress(void) strLog.Format("reporting physical address as %04x", m_physicaladdress); m_controller->AddLog(CEC_LOG_NOTICE, strLog.c_str()); frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST)); - frame.push_back(CEC_OPCODE_REPORT_PHYSICAL_ADDRESS); + frame.push_back((uint8_t) CEC_OPCODE_REPORT_PHYSICAL_ADDRESS); frame.push_back((m_physicaladdress >> 8) & 0xFF); frame.push_back(m_physicaladdress & 0xFF); frame.push_back(CEC_DEVICE_TYPE_PLAYBACK_DEVICE); @@ -317,7 +317,7 @@ void CCECProcessor::BroadcastActiveSource(void) cec_frame frame; m_controller->AddLog(CEC_LOG_NOTICE, "broadcasting active source"); frame.push_back(GetSourceDestination(CECDEVICE_BROADCAST)); - frame.push_back(CEC_OPCODE_ACTIVE_SOURCE); + frame.push_back((uint8_t) CEC_OPCODE_ACTIVE_SOURCE); frame.push_back((m_physicaladdress >> 8) & 0xFF); frame.push_back(m_physicaladdress & 0xFF); Transmit(frame); diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 87759c1..3437e45 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -41,7 +41,7 @@ using namespace std; using namespace CEC; -CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) : +CLibCEC::CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint8_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) : m_iCurrentButton(CEC_USER_CONTROL_CODE_UNKNOWN), m_buttontime(0) { @@ -58,7 +58,7 @@ CLibCEC::~CLibCEC(void) m_comm = NULL; } -bool CLibCEC::Open(const char *strPort, int iTimeoutMs /* = 10000 */) +bool CLibCEC::Open(const char *strPort, uint64_t iTimeoutMs /* = 10000 */) { if (!m_comm) return false; @@ -233,7 +233,7 @@ void CLibCEC::SetCurrentButton(cec_user_control_code iButtonCode) m_buttontime = GetTimeMs(); } -DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /*= CEC::CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) +DECLSPEC void * CECCreate(const char *strDeviceName, CEC::cec_logical_address iLogicalAddress /*= CEC::CECDEVICE_PLAYBACKDEVICE1 */, uint8_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) { return static_cast< void* > (new CLibCEC(strDeviceName, iLogicalAddress, iPhysicalAddress)); } diff --git a/src/lib/LibCEC.h b/src/lib/LibCEC.h index b863cb4..cb9eb8c 100644 --- a/src/lib/LibCEC.h +++ b/src/lib/LibCEC.h @@ -47,10 +47,10 @@ namespace CEC * ICECAdapter implementation */ //@{ - CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, int iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); + CLibCEC(const char *strDeviceName, cec_logical_address iLogicalAddress = CECDEVICE_PLAYBACKDEVICE1, uint8_t iPhysicalAddress = CEC_DEFAULT_PHYSICAL_ADDRESS); virtual ~CLibCEC(void); - virtual bool Open(const char *strPort, int iTimeout = 10000); + virtual bool Open(const char *strPort, uint64_t iTimeout = 10000); virtual void Close(void); virtual int FindAdapters(std::vector &deviceList, const char *strDevicePath = NULL); virtual bool PingAdapter(void); diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index 7f2475b..60ada61 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -41,7 +41,7 @@ using namespace std; //@{ ICECAdapter *cec_parser; -bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, int iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) +bool cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */, uint8_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */) { cec_parser = (ICECAdapter *) CECCreate(strDeviceName, iLogicalAddress, iPhysicalAddress); return (cec_parser != NULL); @@ -54,7 +54,7 @@ void cec_destroy(void) cec_parser = NULL; } -bool cec_open(const char *strPort, int iTimeout) +bool cec_open(const char *strPort, uint64_t iTimeout) { if (cec_parser) return cec_parser->Open(strPort, iTimeout); diff --git a/src/lib/platform/baudrate.h b/src/lib/platform/baudrate.h index 53f04ac..759b1f1 100644 --- a/src/lib/platform/baudrate.h +++ b/src/lib/platform/baudrate.h @@ -21,14 +21,18 @@ //every baudrate I could find is in here in an #ifdef block //so it should compile on everything +#include "os-dependent.h" + +#ifndef __WINDOWS__ #include +#endif namespace CEC { static struct sbaudrate { - int rate; - int symbol; + int32_t rate; + int32_t symbol; } baudrates[] = { @@ -182,11 +186,11 @@ namespace CEC { -1, -1} }; - static int IntToBaudrate(int baudrate) + static int32_t IntToBaudrate(uint32_t baudrate) { for (unsigned int i = 0; i < sizeof(baudrates) / sizeof(CEC::sbaudrate) - 1; i++) { - if (baudrates[i].rate == baudrate) + if (baudrates[i].rate == (int32_t) baudrate) return baudrates[i].symbol; } diff --git a/src/lib/platform/serialport.h b/src/lib/platform/serialport.h index 2cdc108..ea6cdea 100644 --- a/src/lib/platform/serialport.h +++ b/src/lib/platform/serialport.h @@ -19,7 +19,6 @@ */ #include "os-dependent.h" -#include "baudrate.h" #include #include #include @@ -43,22 +42,22 @@ namespace CEC CSerialPort(); virtual ~CSerialPort(); - bool Open(std::string name, int baudrate, int databits = 8, int stopbits = 1, int parity = PAR_NONE); + bool Open(std::string name, uint32_t baudrate, uint8_t databits = 8, uint8_t stopbits = 1, uint8_t parity = PAR_NONE); bool IsOpen(); void Close(); - int Write(std::vector data) + int32_t Write(std::vector data) { - return Write(&data[0], data.size()); + return Write(&data[0], (uint32_t) data.size()); } - int Write(uint8_t* data, int len); - int Read(uint8_t* data, int len, int iTimeoutMs = -1); + int32_t Write(uint8_t* data, uint32_t len); + int32_t Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs = 0); std::string GetError() { return m_error; } std::string GetName() { return m_name; } private: - bool SetBaudRate(int baudrate); + bool SetBaudRate(uint32_t baudrate); std::string m_error; std::string m_name; @@ -69,10 +68,10 @@ namespace CEC HANDLE m_handle; bool m_bIsOpen; - int m_iBaudrate; - int m_iDatabits; - int m_iStopbits; - int m_iParity; + uint32_t m_iBaudrate; + uint8_t m_iDatabits; + uint8_t m_iStopbits; + uint8_t m_iParity; int64_t m_iTimeout; CecBuffer m_buffer; HANDLE m_ovHandle; diff --git a/src/lib/platform/windows/serialport.cpp b/src/lib/platform/windows/serialport.cpp index bfdc8d5..ce299cf 100644 --- a/src/lib/platform/windows/serialport.cpp +++ b/src/lib/platform/windows/serialport.cpp @@ -63,8 +63,9 @@ CSerialPort::~CSerialPort(void) Close(); } -bool CSerialPort::Open(string name, int baudrate, int databits, int stopbits, int parity) +bool CSerialPort::Open(string name, uint32_t baudrate, uint8_t databits, uint8_t stopbits, uint8_t parity) { + CLockObject lock(&m_mutex); m_handle = CreateFile(name.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (m_handle == INVALID_HANDLE_VALUE) { @@ -157,6 +158,7 @@ bool CSerialPort::SetTimeouts(bool bBlocking) void CSerialPort::Close(void) { + CLockObject lock(&m_mutex); if (m_bIsOpen) { CloseHandle(m_handle); @@ -164,8 +166,9 @@ void CSerialPort::Close(void) } } -int CSerialPort::Write(uint8_t* data, int len) +int32_t CSerialPort::Write(uint8_t* data, uint32_t len) { + CLockObject lock(&m_mutex); DWORD iBytesWritten = 0; if (!m_bIsOpen) return -1; @@ -177,31 +180,41 @@ int CSerialPort::Write(uint8_t* data, int len) return -1; } - return (int) iBytesWritten; + return iBytesWritten; } -int CSerialPort::Read(uint8_t* data, int len, int iTimeoutMs /* = -1 */) +int32_t CSerialPort::Read(uint8_t* data, uint32_t len, uint64_t iTimeoutMs /* = 0 */) { + CLockObject lock(&m_mutex); + int32_t iReturn(-1); DWORD iBytesRead = 0; if (m_handle == 0) { m_error = "Error while reading from COM port: invalid handle"; - return -1; + return iReturn; } if(!ReadFile(m_handle, data, len, &iBytesRead, NULL) != 0) { m_error = "unable to read from device"; FormatWindowsError(GetLastError(), m_error); - iBytesRead = -1; + iReturn = -1; + } + else + { + iReturn = (int32_t) iBytesRead; } - return (int) iBytesRead; + return iReturn; } -bool CSerialPort::SetBaudRate(int baudrate) +bool CSerialPort::SetBaudRate(uint32_t baudrate) { - m_iBaudrate = baudrate; + int32_t rate = IntToBaudrate(baudrate); + if (rate < 0) + m_iBaudrate = baudrate > 0 ? baudrate : 0; + else + m_iBaudrate = rate; DCB dcb; memset(&dcb,0,sizeof(dcb)); @@ -240,7 +253,8 @@ bool CSerialPort::SetBaudRate(int baudrate) return true; } -bool CSerialPort::IsOpen() const +bool CSerialPort::IsOpen() { + CLockObject lock(&m_mutex); return m_bIsOpen; } diff --git a/src/lib/util/buffer.h b/src/lib/util/buffer.h index f284131..d49de62 100644 --- a/src/lib/util/buffer.h +++ b/src/lib/util/buffer.h @@ -40,7 +40,7 @@ namespace CEC struct CecBuffer { public: - CecBuffer(int iMaxSize = 100) + CecBuffer(unsigned int iMaxSize = 100) { m_maxSize = iMaxSize; } @@ -72,7 +72,7 @@ namespace CEC } private: - int m_maxSize; + unsigned int m_maxSize; std::queue<_BType> m_buffer; CMutex m_mutex; }; diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index f2f2bf3..983ba13 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -45,11 +45,23 @@ using namespace std; #define CEC_TEST_CLIENT_VERSION 3 -inline bool HexStrToInt(const std::string& data, int& value) +inline bool HexStrToInt(const std::string& data, uint8_t& value) { - return sscanf(data.c_str(), "%x", &value) == 1; -} + int iTmp(0); + if (sscanf(data.c_str(), "%x", &iTmp) == 1) + { + if (iTmp > 256) + value = 255; + else if (iTmp < 0) + value = 0; + else + value = (uint8_t) iTmp; + return true; + } + + return false; +} //get the first word (separated by whitespace) from string data and place that in word //then remove that word from string data @@ -254,7 +266,7 @@ int main (int argc, char *argv[]) if (command == "tx") { string strvalue; - int ivalue; + uint8_t ivalue; vector bytes; while (GetWord(input, strvalue) && HexStrToInt(strvalue, ivalue)) bytes.push_back(ivalue);