You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
2.9 KiB
114 lines
2.9 KiB
#ifndef __DFSL_HARDWARE_SERIAL_PROVIDER_HEADER__
|
|
#define __DFSL_HARDWARE_SERIAL_PROVIDER_HEADER__
|
|
|
|
#include "../components/base/basicTransport.h"
|
|
#include "hardwareResource.h"
|
|
|
|
#define HALF_DUPLEX
|
|
|
|
// #define FIO_SELECT_MODE
|
|
|
|
#ifndef HALF_DUPLEX
|
|
#include "../components/base/basicDualThread.h"
|
|
#else
|
|
#include "../components/base/basicThread.h"
|
|
#endif
|
|
|
|
#include <errno.h> // Error number definitions
|
|
#include <fcntl.h> // File control definitions
|
|
#include <stdio.h> // standard input / output functions
|
|
#include <stdlib.h>
|
|
#include <string.h> // string function definitions
|
|
#include <sys/select.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
|
|
#ifdef __linux__
|
|
#include <termios.h> // POSIX terminal control definitions
|
|
#include <unistd.h> // UNIX standard function definitions
|
|
#if defined(__arm__) || defined(__aarch64__) || defined(RASPI_HARDWARE)
|
|
#define USE_WIRINGX
|
|
#include <wiringx.h>
|
|
#ifdef __aarch64__
|
|
#define WIRINGX_PLATFORM "rock4"
|
|
#define RTS_PIN_NUMBER 0
|
|
#else
|
|
#define WIRINGX_PLATFORM "raspberrypi4"
|
|
#define RTS_PIN_NUMBER 0
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
#ifdef DEBUG_EXTRA
|
|
// #define DEBUG_SERIAL_COMMUNICATION
|
|
#endif
|
|
|
|
#if defined( HALF_DUPLEX ) || defined( SERIAL_PING_PONG )
|
|
class hardwareResourceSerialProvider : public hardwareResource, public basicTransport, public basicThread
|
|
|
|
{
|
|
#else // ! HALF_DUPLEX SERIAL_PING_PONG
|
|
class hardwareResourceSerialProvider : public hardwareResource, public basicTransport, public basicDualThread
|
|
{
|
|
#endif // ! HALF_DUPLEX SERIAL_PING_PONG
|
|
private:
|
|
|
|
DBC_UART_DATA m_sUartData;
|
|
|
|
int m_iDeviceFD;
|
|
int m_iMasterFD;
|
|
#ifdef __linux__
|
|
struct termios m_sTTY;
|
|
int m_iInFID;
|
|
int m_iOutFID;
|
|
bool m_bManualRTS;
|
|
void setRTS(uint8_t Val);
|
|
#else
|
|
DCB PortDCB;
|
|
HANDLE m_ioFID;
|
|
#endif
|
|
bool pingDevice();
|
|
bool create_SOL();
|
|
bool create_HW();
|
|
bool closePort();
|
|
int sendBlock(unsigned char * Data, int DataSize);
|
|
int recptBlock(unsigned char * Buffer, int * BufferLength);
|
|
|
|
protected:
|
|
|
|
#ifdef FIO_SELECT_MODE
|
|
int m_nSenderSetMax;
|
|
int m_nReaderSetMax;
|
|
fd_set m_sSenderSet;
|
|
fd_set m_sReaderSet;
|
|
int m_iControlPipeFD[2];
|
|
#endif
|
|
|
|
#if defined( HALF_DUPLEX ) || defined( SERIAL_PING_PONG )
|
|
virtual void m_fThreadProc(void);
|
|
Q_SIO_TZ m_qIO;
|
|
// Q_SIO_TZ m_qREADY;
|
|
#else
|
|
U8 m_pInputBuffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH]; // 100KB
|
|
U8 m_pOutputBuffer[MAXIMAL_SERIAL_IO_BUFFER_LENGTH];
|
|
int m_nInputBufferSize;
|
|
int m_nOutputBufferSize;
|
|
virtual void m_fThreadAProc(void);
|
|
virtual void m_fThreadBProc(void);
|
|
#endif
|
|
public:
|
|
|
|
explicit hardwareResourceSerialProvider(uint32_t dbID);
|
|
virtual ~hardwareResourceSerialProvider();
|
|
virtual bool create(void);
|
|
virtual bool validate(void);
|
|
#ifdef SERIAL_PING_PONG
|
|
virtual bool sendData(uint8_t * Data, int DataSize, protocolParser *src = NULL );
|
|
#else
|
|
virtual bool sendData(uint8_t * Data, int DataSize );
|
|
#endif
|
|
virtual bool reconnect(void);
|
|
virtual bool activate( void );
|
|
};
|
|
|
|
#endif
|