📄 commserial.h
字号:
#ifndef _cculib_h_
#define _cculib_h_
#include <assert.h>
#include <errno.h>
//#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <termios.h>
//#include <netinet/in.h>
//#include <netinet/tcp.h>
//#include <sys/socket.h>
//#include <sys/shm.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "global.h"
//////////////////////////////////////////////////////////////////////////
#ifndef bool
#define bool unsigned char
#endif
#ifndef uint
#define uint unsigned int
#endif
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#define Pt printf
#define Err( fmt, para... ) fprintf( stderr, fmt, ##para )
//////////////////////////////////////////////////////////////////////////
/*
* channel type
*/
// #define CHANTYPE_UNKNOWN -1 /* unknown type */
// #define CHANTYPE_SERIAL 1 /* serial */
// #define CHANTYPE_422 2
// #define CHANTYPE_485 3
// #define CHANTYPE_UDP 4 /* udp */
// #define CHANTYPE_TCPCLIENT 5 /* tcp client */
// #define CHANTYPE_TCPSERVER 6 /* tcp server */
/*
* receive callback function
*/
typedef void(*RCVCALLBACK)(void*, BYTE*, int);
/*
* serial port
*/
typedef struct _SERIALPORT
{
int com;
char scom[128];
int baudrate;
int databits;
int stopbits;
int parity;
} SERIALPORT, *PSERIALPORT;
typedef struct
{
bool isOpen;
int fd;
pthread_t tid;
uint rcvTick;
RCVCALLBACK fnOnReceive;
void* userData;
/* to add */
/* synchronize rcvTick */
} SERIALPORTINFO;
/*
* ethernet port
*/
// typedef struct _ETHERPORT
// {
// char ip[16];
// int port;
//
// } ETHERPORT, *PETHERPORT;
/*
* device status
*/
#define DEVCSTAT_UNINITED 0 /* uninitialized */
#define DEVCSTAT_OFFLINE 1 /* offline */
#define DEVCSTAT_ONLINE 2 /* online */
/*
* system time
*/
typedef struct _SYSTEMTIME
{
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
#define MAKEWORD(a, b) ((WORD)(((BYTE)(a)) | ((WORD)((BYTE)(b))) << 8))
#define MAKELONG(a, b) ((LONG)(((WORD)(a)) | ((DWORD)((WORD)(b))) << 16))
#define LOWORD(l) ((WORD)(l))
#define HIWORD(l) ((WORD)(((DWORD)(l) >> 16) & 0xFFFF))
#define LOBYTE(w) ((BYTE)(w))
#define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
#define min(x, y) (x <= y ? x : y)
#define max(x, y) (x >= y ? x : y)
#define big_quotient(x, y) ((x % y == 0) ? (x / y) : ((x / y) + 1))
#define TRACE printf
#define ASSERT assert
#define _ffl_ printf("file=%s function=%s, line=%d\n", __FILE__, __FUNCTION__, __LINE__)
#define RTNERR(errcode) return (errcode)
#define Sleep(t) usleep(t*1000)
/******************************************************************************/
/* CSerialPort */
#define RS232 1
#define RS485 3
#define RS422 2
// class CSerialPort
// {
// public:
// CSerialPort();
// public:
// virtual ~CSerialPort();
// public:
// BOOL IsOpen();
// int Open(SERIALPORT* sp, RCVCALLBACK fnOnReceive, void* userData,int mode);
// void Close();
// int Send(BYTE* buf, int len);
// void SetRcvTicker(UINT tick);
// UINT GetRcvTicker();
// protected:
// HANDLE m_hPort;
// };
BOOL IsOpen();
int Open(SERIALPORT* sp, RCVCALLBACK fnOnReceive, void* userData,int mode);
void SerialPortClose();
int Send(BYTE* buf, int len);
void SetRcvTicker(UINT tick);
UINT GetRcvTicker();
/******************************************************************************/
int ParseSerialCommParaStr(char* para, SERIALPORT* port);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -