1 Star 1 Fork 2

今夜无眠/GNSS_Viewer_V2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Serial.h 3.46 KB
一键复制 编辑 原始数据 按行查看 历史
Alex Lin 提交于 2018-07-18 16:21 . 2.0.326
#pragma once
// Serial.h
#define ASCII_CR 0x0D
#define ASCII_LF 0x0A
#define BINARY_HD1 0xA0
#define BINARY_HD2 0xA1
#define READ_ERROR ((DWORD)(-1))
#define ReadOK(len) ((len==READ_ERROR) ?0 :len)
//enum MessageType {
// MtUnknown = 0,
// StqBinary,
// NmeaMessage,
// RtcmMessage,
//};
class CSerial
{
public:
CSerial();
~CSerial();
//static int BaudrateTable[];
//static const int BaudrateTableSize;
enum { InQueueSize = 1024 * 128 };
enum { OutQueueSize = 1024 * 8 };
enum { MaxQueueLoop = 10 };
enum { IoPendingTimeOut = 2000 };
//Getter and Setter
bool IsOpened() { return m_isOpened; }
int GetComPort() { return m_comPort; }
int GetBaudRate() { return m_baudRate; }
HANDLE GetHandle() { return m_comDeviceHandle; };
void SetSentUnit(DWORD s) { m_sendUnit = s; };
void SetLogStatus(DWORD s) { m_logStatus = s; };
//Flow control
bool Open(int port = 2, int baudIndex = 5);
#if(SPECIAL_BAUD_RATE)
bool OpenByBaudrate(LPCSTR comPort, int baudrate = 172800);
#else
bool OpenByBaudrate(LPCSTR comPort, int baudrate = 115200);
#endif
void Close();
void CancelTransmission() { m_cancelTransmission = true; }
void ResetTransmission() { m_cancelTransmission = false; }
bool GetCancelTransmission() { return m_cancelTransmission; }
bool* GetCancelTransmissionPtr() { return &m_cancelTransmission; }
bool ResetPort(int baudIndex);
void ClearQueue();
//Read or write data
// Read data until buffer full, or com port is empty.
// If once is false, it'll check com port empty again after read data.
DWORD ReadData(void* buffer, DWORD bufferSize, bool once = false);
DWORD GetString(void* buffer, DWORD bufferSize, DWORD timeOut);
BOOL GetOneChar(U08 *c, DWORD* dwBytesDoRead, DWORD timeout);
DWORD GetBinary(void* buffer, DWORD bufferSize, DWORD timeout = 2000);
//DWORD GetParsingData(void* buffer, DWORD bufferSize, DWORD timeout = 2000);
//MessageType GetParsingData(void *buffer, DWORD bufferSize, DWORD* totalSize, DWORD timeout = 2000);
#if CUSTOMER_ZENLANE_160808
DWORD GetZenlaneMessage(void* buffer, DWORD bufferSize, DWORD timeout = 2000);
#endif
DWORD GetZenlaneResponse1(void* buffer, DWORD bufferSize, DWORD timeout = 2000);
DWORD GetBinaryAck(void* buffer, DWORD bufferSize, DWORD timeout = 2000);
DWORD GetBinaryBlock(void* buffer, DWORD bufferSize, DWORD blockSize);
DWORD GetBinaryBlockInSize(void* buffer, DWORD bufferSize, DWORD blockSize);
DWORD SendData(const void* buffer, DWORD bufferSize, bool blockTransfer = false, int delayDuration = 0);
//DWORD GetBinaryBlockInTime(void* buffer, DWORD bufferSize, DWORD timeout);
static inline void AddDebugString(const char* dbg);
static void SaveDebugString(bool backup = false);
static void SetDebugModeOn(bool on = true) { debugModeOn = on; };
static void SetDebugName(LPCSTR name) { debugName = name; };
static DWORD readCount;
DWORD errorCode;
protected:
static const int debugSize = 4 * 1024 * 1024;
static char debugBuffer[debugSize];
static char *debugPtr;
static bool debugModeOn;
static CString debugWorking;
static CString debugName;
static bool m_cancelTransmission;
HANDLE m_comDeviceHandle;
int m_comPort;
int m_baudRate;
bool m_isOpened;
OVERLAPPED m_OverlappedRead;
OVERLAPPED m_OverlappedWrite;
DWORD m_sendUnit;
DWORD m_logStatus;
int ComInitial();
int WaitingDataIn();
bool WriteCommBytes(char* buffer, int bufferSize);
bool ResetPortNoDelay(int baud);
public:
static DWORD GetComBinaryAck(HANDLE com, void *buffer, DWORD bufferSize, DWORD timeout);
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/null_130_5865/GNSS_Viewer_V2.git
[email protected]:null_130_5865/GNSS_Viewer_V2.git
null_130_5865
GNSS_Viewer_V2
GNSS_Viewer_V2
master

搜索帮助