📄 dlservice.h
字号:
#ifndef _DLSERVICE_H#define _DLSERVICE_H#include "msystem.h"//#include "101frame.h"#include "cdtframe.h"#include "TAFrame.h"#include "simuframe.h"#include "isaframe.h"#include "modbusframe.h"#include "intbusframe.h"#include "gpsframe.h"#include "physerver.h"#include "ja05frame.h"/** *@author */class CSerialPortDef;class CDLService {protected: CDLService(CSerialPortDef* pChannel) : m_PhyService(pChannel) { m_nStatus = -1; }public: bool Reset() { return m_PhyService.Reset(); } //retval 0:No indications to Report; 1:valid data; -1:failure int IND(CFrameNode& FNRecv) { int nIndications = -1; if (m_PhyService.Status() == 0) { nIndications = 0; CDQue* pDQueRecv = m_PhyService.GetRecvQueue(); if (BufferToFrame(pDQueRecv)) { m_pFrame->FrameToBuf(FNRecv); nIndications = 1; } } return nIndications; } //retval 0:Successful no Reply; 1:Successful Reply; -1:Failure / Disconnect; //service 1:SEND-CONFIRM; 0:SEND-NOREPLY; 2:SEND-CONFIRM; 3:SEND-NOREPLY; 4:return Link Status, int REQ(BYTE byService,CFrameNode *pFNSend,CFrameNode& FNRecv,BYTE byPriority/*0:h;1:l*/,bool bRetry) { int nConfirm = -1; if (m_PhyService.Status() == 0) { SetupFrame(pFNSend); CDataNode dn; FrameToBuffer(dn); BYTE b; for (b=0;b<m_byMaxRepeatTimes;b++) { switch (byService) { case 0: //send-no-reply m_PhyService.Write(dn.m_pbyData,dn.m_wSize); nConfirm = 0; break; case 1: //send-confirm; Request-Respond { if (dn.m_wSize) m_PhyService.Write(dn.m_pbyData,dn.m_wSize); usleep(10000); CDQue* pDQueRecv = m_PhyService.GetRecvQueue(); if (BufferToFrame(pDQueRecv)) { m_pFrame->FrameToBuf(FNRecv); nConfirm = 1; } break; } case 2: //send-confirm ,cancel current secondary frames for half duplex break; case 3: //send-no-reply ,cancel current secondary frames for half duplex break; case 4: //return link status, return successful if the data link is not busy break; default: break; } if ((nConfirm >= 0) || (bRetry == false)) break; } } return nConfirm; } //retval 0:No indications to Report; -1:failure int RESP(CFrameNode *pFNSend) { int nConfirm = -1; if (m_PhyService.Status() == 0) { SetupFrame(pFNSend); CDataNode dn; FrameToBuffer(dn); m_PhyService.Write(dn.m_pbyData,dn.m_wSize);/* for (WORD bbb=0; bbb< dn.m_wSize; bbb++) { char c[16]; sprintf(c,"%02x ",dn.m_pbyData[bbb]); cout << c; if ((bbb+1)%64 == 0) cout << endl; } cout <<endl;*/ nConfirm = 0; } return nConfirm; } int Status() { if ((m_nStatus == -1) && (m_PhyService.Status() == 0)) //Idle { m_nStatus = 0; } return m_nStatus; } bool GetStreamNode(CDataNode*& pdnStream) { return m_PhyService.GetStreamNode(pdnStream); }protected: CPhyService m_PhyService; CFrame* m_pFrame; int m_nStatus; BYTE m_byMaxRepeatTimes; void SetupFrame(CFrameNode *pFNSend) { m_pFrame->SetupFrame(pFNSend); } bool BufferToFrame(CDQue* pPhyDQ) { return m_pFrame->BufferToFrame(pPhyDQ); } bool FrameToBuffer(CDataNode &dn) { return m_pFrame->FrameToBuffer(dn); }};class CCDTDLS : public CDLService{public: CCDTDLS(CSerialPortDef* pChannel) : CDLService(pChannel) { m_pFrame = new CCDTFrame; m_byMaxRepeatTimes = 1; } ~CCDTDLS() { if (m_pFrame) delete m_pFrame; }};class CTADLS : public CDLService{public: CTADLS(CSerialPortDef* pChannel) : CDLService(pChannel) { m_pFrame = new CTAFrame; m_byMaxRepeatTimes = 1; } ~CTADLS() { if (m_pFrame) delete m_pFrame; }};class CSimuDLS : public CDLService{public: CSimuDLS(CSerialPortDef* pChannel) : CDLService(pChannel) { m_pFrame = new CSimuFrame; m_byMaxRepeatTimes = 1; } ~CSimuDLS() { if (m_pFrame) delete m_pFrame; }};class CISADLS : public CDLService{public: CISADLS(CSerialPortDef* pChannel) : CDLService(pChannel) { m_pFrame = new CISAFrame; m_byMaxRepeatTimes = 1; } ~CISADLS() { if (m_pFrame) delete m_pFrame; }};class CModbusDLL : public CDLService{public: CModbusDLL(CSerialPortDef* pChannel,bool bIsSlave = false) : CDLService(pChannel) { m_pFrame = new CModbusFrame(bIsSlave); m_byMaxRepeatTimes = 1; } ~CModbusDLL() { if (m_pFrame) delete m_pFrame; } void SetEchoLen(WORD wEchoLen) { ((CModbusFrame *)m_pFrame)->SetEchoLen(wEchoLen); CDQue* pDQueRecv = m_PhyService.GetRecvQueue(); while (pDQueRecv->Size()) { CDataNode *pDN = NULL; if (pDQueRecv->Get(pDN)) delete pDN; } }};class CIntbusDLL : public CDLService{public: CIntbusDLL(CSerialPortDef* pChannel) : CDLService(pChannel) { m_pFrame = new CIntbusFrame; m_byMaxRepeatTimes = 1; } ~CIntbusDLL() { if (m_pFrame) delete m_pFrame; }};class CGpsDLL : public CDLService{public: CGpsDLL(CSerialPortDef* pChannel) : CDLService(pChannel) { m_pFrame = new CGpsFrame; m_byMaxRepeatTimes = 1; } ~CGpsDLL() { if (m_pFrame) delete m_pFrame; }};class CJA05DLL : public CDLService{public: CJA05DLL(CSerialPortDef* pChannel) : CDLService(pChannel) { m_pFrame = new CJA05Frame; m_byMaxRepeatTimes = 1; } ~CJA05DLL() { if (m_pFrame) delete m_pFrame; }};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -