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.
131 lines
4.0 KiB
131 lines
4.0 KiB
#ifndef __DFSL_HARDWARE_SERIAL_PROVIDER_HEADER__
|
|
#define __DFSL_HARDWARE_SERIAL_PROVIDER_HEADER__
|
|
|
|
#include "hardwareResource.h"
|
|
#include "../components/base/basicTransport.h"
|
|
|
|
//#define HALF_DUPLEX
|
|
|
|
//#define FIO_SELECT_MODE
|
|
|
|
#ifndef HALF_DUPLEX
|
|
#include "../components/base/basicDualThread.h"
|
|
#else
|
|
#include "../components/base/basicThread.h"
|
|
#endif
|
|
|
|
#include <stdio.h> // standard input / output functions
|
|
#include <stdlib.h>
|
|
#include <string.h> // string function definitions
|
|
#include <fcntl.h> // File control definitions
|
|
#include <errno.h> // Error number definitions
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/select.h>
|
|
#include <unistd.h>
|
|
|
|
#ifdef __linux__
|
|
#include <unistd.h> // UNIX standard function definitions
|
|
#include <termios.h> // POSIX terminal control 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
|
|
|
|
|
|
#ifndef MAXIMAL_SOCKET_PACKET_LENGTH
|
|
#define MAXIMAL_SOCKET_PACKET_LENGTH 102400
|
|
#endif
|
|
|
|
#ifndef MAXIMAL_SERIAL_PACKET_LENGTH
|
|
#define MAXIMAL_SERIAL_PACKET_LENGTH MAXIMAL_SOCKET_PACKET_LENGTH
|
|
#endif
|
|
|
|
#include <queue>
|
|
|
|
typedef struct S_SIO_TZ{
|
|
uint32_t id;
|
|
bool wReplay;
|
|
bool finished;
|
|
bool success;
|
|
int inp_size;
|
|
int out_size;
|
|
uint8_t out_buffer[MAXIMAL_SOCKET_PACKET_LENGTH];
|
|
uint8_t inp_buffer[MAXIMAL_SOCKET_PACKET_LENGTH];
|
|
}SIO_TZ;
|
|
|
|
typedef std::queue<SIO_TZ*> Q_SIO_TZ;
|
|
|
|
#ifndef HALF_DUPLEX
|
|
class hardwareResourceSerialProvider: public hardwareResource, public basicTransport, public basicDualThread {
|
|
#else
|
|
class hardwareResourceSerialProvider: public hardwareResource, public basicTransport, public basicThread {
|
|
#endif
|
|
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
|
|
|
|
#ifndef HALF_DUPLEX
|
|
U8 m_pInputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH];//100KB
|
|
U8 m_pOutputBuffer[MAXIMAL_SOCKET_PACKET_LENGTH];
|
|
int m_nInputBufferSize;
|
|
int m_nOutputBufferSize;
|
|
|
|
virtual void m_fThreadAProc(void);
|
|
virtual void m_fThreadBProc(void);
|
|
#else
|
|
virtual void m_fThreadProc(void);
|
|
Q_SIO_TZ m_qIO;
|
|
//Q_SIO_TZ m_qREADY;
|
|
#endif
|
|
public:
|
|
explicit hardwareResourceSerialProvider( uint32_t dbID );
|
|
virtual ~hardwareResourceSerialProvider();
|
|
virtual bool create( void );
|
|
virtual bool validate( void );
|
|
virtual bool sendData( uint8_t *Data, int DataSize );
|
|
virtual bool reconnect( void );
|
|
};
|
|
|
|
#endif
|
|
|