Machine Interface Utility:VER1.0
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
#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 16000
|
||||
|
||||
// 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=NULL);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
typedef void(*p_fstr)(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
|
||||
Reference in New Issue
Block a user