X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Flib%2FAdapterCommunication.h;h=97cd18d2f3b1debbc01207509dbe4ac94e4103d5;hb=4fe8d858f161384e8f808751c47d0e7e541b3adb;hp=461ed586f887e427615feb5a2ccb30f95ab9cc93;hpb=82d1a9a150628b179d1ad501eb9a73feb3f6dd1d;p=deb_libcec.git diff --git a/src/lib/AdapterCommunication.h b/src/lib/AdapterCommunication.h index 461ed58..97cd18d 100644 --- a/src/lib/AdapterCommunication.h +++ b/src/lib/AdapterCommunication.h @@ -32,10 +32,12 @@ */ #include -#include "platform/threads.h" -#include "util/buffer.h" -#include "util/StdString.h" -#include +#include "platform/os.h" + +namespace PLATFORM +{ + class CSerialPort; +} namespace CEC { @@ -62,7 +64,7 @@ namespace CEC uint8_t operator[](uint8_t pos) const { return packet[pos]; } uint8_t at(uint8_t pos) const { return packet[pos]; } uint8_t size(void) const { return packet.size; } - void clear(void) { state = ADAPTER_MESSAGE_STATE_UNKNOWN; transmit_timeout = 0; packet.Clear(); maxTries = 5; tries = 0; reply = MSGCODE_NOTHING; } + void clear(void) { state = ADAPTER_MESSAGE_STATE_UNKNOWN; transmit_timeout = 0; packet.Clear(); maxTries = CEC_DEFAULT_TRANSMIT_RETRIES + 1; tries = 0; reply = MSGCODE_NOTHING; } void shift(uint8_t iShiftBy) { packet.Shift(iShiftBy); } void push_back(uint8_t add) { packet.PushBack(add); } cec_adapter_messagecode message(void) const { return packet.size >= 1 ? (cec_adapter_messagecode) (packet.At(0) & ~(MSGCODE_FRAME_EOM | MSGCODE_FRAME_ACK)) : MSGCODE_NOTHING; } @@ -75,7 +77,6 @@ namespace CEC bool needs_retry(void) const { return reply == MSGCODE_NOTHING || reply == MSGCODE_RECEIVE_FAILED || reply == MSGCODE_TIMEOUT_ERROR || - reply == MSGCODE_TRANSMIT_FAILED_ACK || reply == MSGCODE_TRANSMIT_FAILED_LINE || reply == MSGCODE_TRANSMIT_FAILED_TIMEOUT_DATA || reply == MSGCODE_TRANSMIT_FAILED_TIMEOUT_LINE || @@ -87,14 +88,13 @@ namespace CEC cec_datapacket packet; cec_adapter_message_state state; int32_t transmit_timeout; - CMutex mutex; - CCondition condition; + PLATFORM::CMutex mutex; + PLATFORM::CCondition condition; }; - class CSerialPort; class CCECProcessor; - class CAdapterCommunication : private CThread + class CAdapterCommunication : private PLATFORM::CThread { public: CAdapterCommunication(CCECProcessor *processor); @@ -105,11 +105,12 @@ namespace CEC bool Write(CCECAdapterMessage *data); bool PingAdapter(void); void Close(void); - bool IsOpen(void) const; + bool IsOpen(void); std::string GetError(void) const; void *Process(void); + bool SetLineTimeout(uint8_t iTimeout); bool StartBootloader(void); private: @@ -118,12 +119,13 @@ namespace CEC void AddData(uint8_t *data, uint8_t iLen); bool ReadFromDevice(uint32_t iTimeout); - CSerialPort * m_port; - CCECProcessor * m_processor; - CecBuffer m_inBuffer; - CecBuffer m_outBuffer; - CMutex m_mutex; - CCondition m_rcvCondition; - CCondition m_startCondition; + PLATFORM::CSerialPort * m_port; + CCECProcessor * m_processor; + PLATFORM::SyncedBuffer m_inBuffer; + PLATFORM::SyncedBuffer m_outBuffer; + PLATFORM::CMutex m_mutex; + PLATFORM::CCondition m_rcvCondition; + PLATFORM::CCondition m_startCondition; + uint8_t m_iLineTimeout; }; };