#ifndef __BASIC_TNSPORT_HEADERS__ #define __BASIC_TNSPORT_HEADERS__ #include "basicLogCollection.h" #include "basicMutex.h" #include #include #include #ifdef DEBUG // #ifndef DUBUG_COMMUNICATION // #define DUBUG_COMMUNICATION // #endif #endif #define SERIAL_PING_PONG #ifdef SERIAL_PING_PONG class protocolParser; #endif #ifndef MAXIMAL_SERIAL_IO_BUFFER_LENGTH #define MAXIMAL_SERIAL_IO_BUFFER_LENGTH 102400 #endif typedef struct S_SIO_TZ { bool wReplay; bool finished; bool success; int inp_size; int out_size; #ifdef SERIAL_PING_PONG protocolParser * boundParser; #endif uint8_t out_buffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH]; uint8_t inp_buffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH]; } SIO_TZ; typedef std::queue Q_SIO_TZ; class protocolParser; typedef std::vector parseQueue; class basicTransport { private: basicLogCollection * m_pLog; protected: parseQueue m_vParsers; basicMutex m_mQueueProtectorMutex; basicMutex m_mBufferProtectorMutex; CONNECTION_STATUS m_eConnectionStatus; volatile uint32_t m_nConnectEpoch; // +1 on every change to CS_CONNECTED (a reconnect) public: basicTransport(); ~basicTransport(); #ifdef SERIAL_PING_PONG virtual bool sendData(unsigned char * Data, int DataSize, protocolParser *src = NULL ) #else virtual bool sendData(unsigned char * Data, int DataSize ) #endif { if ( !Data ) return false; if ( !DataSize ) return false; return true; } virtual bool reconnect(void) { return false; } // The device is reached over a network (e.g. an Ethernet to serial gateway on the Internet): // replies take longer than on a local serial line virtual bool isNetworkLink(void) { return false; } bool addRecipient(protocolParser * ProtoParser); bool removeRecipient(protocolParser * ProtoParser); bool getStatus(void) { return m_eConnectionStatus == CS_CONNECTED; } void setConnectionStatus(CONNECTION_STATUS ES); // Changes on every (re)connect: a user bound to this transport sees a reconnect it did not notice // as a short CS_DISCONNECTED (a device behind it may have lost its state meanwhile) uint32_t getConnectEpoch(void) { return m_nConnectEpoch; } CONNECTION_STATUS getConnectionStatus(void); virtual int getRawHandle(void) { return -1; } }; #endif