b94d85b393
1、新增了加速度,减速度,运行速度读配置档位 2、优化了串口通讯,待继续调试 3、测试用例,新增了 DCCScanStart() 和 DCCScanStop()的调试
127 lines
2.6 KiB
C++
127 lines
2.6 KiB
C++
#ifndef CMMIO_BASE_H
|
|
#define CMMIO_BASE_H
|
|
|
|
#include <WinBase.h>
|
|
#include <WinDef.h>
|
|
|
|
|
|
#define MAX_OUTPUT_BUFFER_SIZE 2048
|
|
#define MAX_RECIEVE_BUFFER_SIZE 30000
|
|
|
|
// TCP, serial style routines
|
|
struct SerialList
|
|
{
|
|
struct SerialList* Next;
|
|
DWORD Bytes;
|
|
int Item;
|
|
char* Buffer;
|
|
};
|
|
|
|
class CMMIO
|
|
{
|
|
private:
|
|
// For now we are not using the transmit list
|
|
// struct SerialList *m_TXHead;
|
|
char m_terminator;
|
|
BOOL m_usesTerminator;
|
|
char m_InputBuffer[MAX_RECIEVE_BUFFER_SIZE];
|
|
int CurrentPointer;
|
|
char m_sLastMessage[MAX_RECIEVE_BUFFER_SIZE];
|
|
|
|
struct SerialList* m_RXHead;
|
|
struct SerialList* m_RXTail;
|
|
char* m_RXTempPtr;
|
|
CString m_LastError;
|
|
BOOL m_hasError;
|
|
|
|
protected:
|
|
CString m_lastErrMsg;
|
|
int m_iNbMsgWaiting;
|
|
BOOL m_UseBuffferedSend;
|
|
CRITICAL_SECTION m_QueueLock; //ÁÙ½çÇø
|
|
CRITICAL_SECTION m_ReadLock;
|
|
CRITICAL_SECTION m_WriteLock;
|
|
|
|
struct SerialList* m_SXHead;
|
|
struct SerialList* m_SXTail;
|
|
char* m_SXTempPtr;
|
|
|
|
protected:
|
|
virtual void Init();
|
|
int AddReceived(const char* Buffer, DWORD Bytes); // [7/30/2004]
|
|
void Error(CString sErr)
|
|
{
|
|
TRACE(sErr);
|
|
m_LastError = sErr;
|
|
m_hasError = TRUE;
|
|
}
|
|
|
|
virtual DWORD Close();
|
|
|
|
public:
|
|
CMMIO()
|
|
{
|
|
InitializeCriticalSection(&m_QueueLock);
|
|
// Sean Flynn mutex needs to be initialized prior to attempting to lock otherwise it will core
|
|
InitializeCriticalSection(&m_ReadLock); // initializing here will ensure the mutex is always initialized
|
|
InitializeCriticalSection(&m_WriteLock);
|
|
Init();
|
|
};
|
|
|
|
virtual ~CMMIO()
|
|
{
|
|
DeleteCriticalSection(&m_QueueLock); // Clean up the mutexes resources when the destructor is called.
|
|
DeleteCriticalSection(&m_ReadLock);
|
|
DeleteCriticalSection(&m_WriteLock);
|
|
};
|
|
|
|
virtual DWORD Open()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
BOOL getError(CString& sErr)
|
|
{
|
|
BOOL hasError = m_hasError;
|
|
if (m_hasError)
|
|
{
|
|
sErr = m_LastError;
|
|
m_hasError = FALSE;
|
|
}
|
|
return (hasError);
|
|
}
|
|
|
|
virtual int GetNextReceived(char* inputBuf = nullptr);
|
|
|
|
virtual int HasNextReceived(void)
|
|
{
|
|
return (m_RXHead ? m_RXHead->Bytes : FALSE);
|
|
}
|
|
|
|
virtual void SetTerminateChar(char ch)
|
|
{
|
|
m_terminator = ch;
|
|
m_usesTerminator = TRUE;
|
|
}
|
|
|
|
virtual void LineReceive(char* s, int nbCharAvail, BOOL ignoreDelimiter = FALSE);
|
|
|
|
virtual CString GetLastErrStr()
|
|
{
|
|
return m_lastErrMsg;
|
|
}
|
|
|
|
using p_fstr = void(*)(CString);
|
|
void SetCallback(p_fstr);
|
|
|
|
virtual DWORD Send(LPCSTR buffer, int l, BOOL needsResponse = FALSE) = 0; // [8/11/2004]
|
|
virtual DWORD Send(CString buffer, BOOL needsResponse = FALSE); // [8/11/2004]
|
|
|
|
virtual bool IsValid() = 0; // pure virtual function
|
|
protected:
|
|
p_fstr m_pReceiveNotify;
|
|
};
|
|
|
|
|
|
#endif // CMMIO_BASE_H
|