1
|
#ifndef __MODBUS_EX_LINE_SVR_H
|
2
|
#define __MODBUS_EX_LINE_SVR_H
|
3
|
|
4
|
#include "daq/daq_protocol.h"
|
5
|
|
6
|
#include "utility/CommonDef_v2.h"
|
7
|
|
8
|
#ifdef NET_BYTEORDER
|
9
|
#define BITORDER 1
|
10
|
#endif
|
11
|
|
12
|
|
13
|
|
14
|
////////////////////////////////////////////////////
|
15
|
// #define RxDataLen 17
|
16
|
// #define TxDataMaxLen 1042
|
17
|
#define DataMaxLen 65554 // 64 * 1024 + ֡ͷ + ????ͷ + У???? + 1(??֤??ż??)
|
18
|
#define DINumberPerBlock 16 // 1??DI??Ϣ???????DI????
|
19
|
// #define MaxObjPerFrame_DI 512 // һ֡???ܰ?????DI?????Ϣ?? - ÿ16???????һ????Ϣ?飬ռ2???ֽں?2????ַ
|
20
|
// #define MaxObjPerFrame_AI 512 // һ֡???ܰ?????AI?????Ϣ?? - 1???????һ????Ϣ?飬ռ2???ֽں?1????ַ
|
21
|
|
22
|
#define FixSysID_Req 15 //0x0F
|
23
|
#define FixSysID_Ans 255 //0xFF
|
24
|
#define ReqTypeID_DI 1 //DI
|
25
|
#define ReqTypeID_AI 3 //AI
|
26
|
|
27
|
|
28
|
|
29
|
|
30
|
#define DataHeadLen 8
|
31
|
typedef struct
|
32
|
{
|
33
|
uint8 HeadLo; // 0xEB
|
34
|
uint8 HeadHi; // 0x90
|
35
|
uint8 SysID; // system ID, fixed
|
36
|
uint8 PacketNoLo; // package number of frame, circle-self, 0~0xFFFF
|
37
|
uint8 PacketNoHi;
|
38
|
uint8 LenLo; // calculate from Multi-Flag to the last data byte
|
39
|
uint8 LenHi;
|
40
|
uint8 FollowupFlag; // 0-end, 1-Subsequent Package
|
41
|
} DATA_HEAD; //???ݵ?Ԫ??ʾ??
|
42
|
|
43
|
#define DataBodyHeadLen 7
|
44
|
typedef struct
|
45
|
{
|
46
|
uint8 DataType; // 1-DI, 3-AI
|
47
|
uint8 DataCountLB; // Data count
|
48
|
uint8 DataCountMB;
|
49
|
uint8 DataCountHB;
|
50
|
uint8 DataStAddrLB; // Data start address
|
51
|
uint8 DataStAddrMB;
|
52
|
uint8 DataStAddrHB;
|
53
|
uint8 reserved1;
|
54
|
} DATA_BODY_HEAD; //???ݵ?Ԫ??ʾ??
|
55
|
|
56
|
|
57
|
|
58
|
////////////////////////////////////////////////////
|
59
|
typedef struct _IniRtuParam {
|
60
|
uint32 rtuNo;
|
61
|
|
62
|
uint32 totalYX; // DI??????
|
63
|
uint32 totalYxBlock; // ??RTU??????DI??Ϣ?? -- ÿ????Ϣ??16λ??ÿ֡???512????Ϣ?? (??Ϣ??Ķ?????Э???أ?Ϊ?????RTUת??????)
|
64
|
uint32 totalYC; // AI??????
|
65
|
// uint32 totalYcFrame; // ??RTU??????AI֡???? -- ÿ֡???512??AI??
|
66
|
}IniRtuParam, *LPIniRtuParam;
|
67
|
typedef struct _IniConfig {
|
68
|
uint32 totalRtus;
|
69
|
|
70
|
uint32 totalBytesYx;
|
71
|
uint32 totalBytesYc;
|
72
|
|
73
|
uint32 totalFramesYx;
|
74
|
uint32 totalFramesYc;
|
75
|
|
76
|
uint8 bufType; // =0: 1K bytes, =1: 2K bytes, =2: 4K bytes, =3: 8K bytes, =4: 16K bytes, =5: 32K bytes, =6: 64K bytes
|
77
|
uint8 reserved1;
|
78
|
|
79
|
LPIniRtuParam rtuConfArray;
|
80
|
}IniConfig, *LPIniConfig;
|
81
|
|
82
|
|
83
|
typedef struct _databuf
|
84
|
{
|
85
|
uint8 * headP;
|
86
|
uint8 * trailP;
|
87
|
uint8 databuf[DataMaxLen];
|
88
|
} DATABUF;
|
89
|
|
90
|
////////////////////////////////////////////////////
|
91
|
class CModbusExLnS : public CProtocol
|
92
|
{
|
93
|
public:
|
94
|
CModbusExLnS();
|
95
|
~CModbusExLnS();
|
96
|
virtual sint32 MsgProc(sint32 msg);
|
97
|
virtual sint32 TxProc(); // һ?½ӿ?
|
98
|
virtual sint32 RxProc();
|
99
|
virtual sint32 GetZfFlag( )
|
100
|
{
|
101
|
return 1;
|
102
|
};
|
103
|
virtual void Init( S_PROTOCOLCFG * pcfg );
|
104
|
|
105
|
static void GetData(void *);
|
106
|
|
107
|
sint32 procWriteBuffer_DI();
|
108
|
sint32 procWriteBuffer_AI();
|
109
|
|
110
|
private:
|
111
|
void initStation();
|
112
|
void appToLink(uint8 nDataType);
|
113
|
|
114
|
void resetIniParam(LPIniConfig pParam);
|
115
|
void readIni();
|
116
|
void initBuffer();
|
117
|
void setFrameProperty(uint8 bufType);
|
118
|
|
119
|
sint32 procSendDI();
|
120
|
sint32 procSendAI();
|
121
|
|
122
|
public:
|
123
|
uint32 m_TxDataMaxLen;
|
124
|
uint32 m_FrameObjNum_Max;
|
125
|
uint32 m_FrameDINum_Max;
|
126
|
|
127
|
sint32 m_hThreadGetData;
|
128
|
bool m_bExitMe;
|
129
|
uint8 m_b_InitBuff;
|
130
|
uint8 m_bufValueHasReady; // =0, no value; =1, has data
|
131
|
|
132
|
private:
|
133
|
IniConfig m_iniConfig; // parameter from INI file
|
134
|
|
135
|
DATABUF m_sendData;
|
136
|
|
137
|
BYTE m_flagSendType; // bit0: DI, bit1: AI
|
138
|
uint16 m_nSendFrameNo; // index base 0, frame number for each type of send
|
139
|
uint16 m_nSendSeqNo; // 0 ~ 0xFFFF, circle-self, frame number
|
140
|
|
141
|
uint8 * m_bufYX;
|
142
|
uint8 * m_bufYC;
|
143
|
sint32 GetNowSecond(unsigned short *mmt);
|
144
|
sint32 m_LastSendTime;
|
145
|
ushort mm_LastSendTime;
|
146
|
sint32 m_State;
|
147
|
public:
|
148
|
/*#ifdef LOG_WIN
|
149
|
Logger *m_logger;
|
150
|
#endif*/
|
151
|
DWORD m_timeBeginYX;
|
152
|
DWORD m_timeBeginYC;
|
153
|
uint16 m_nYXFrameCount;
|
154
|
uint16 m_nYCFrameCount;
|
155
|
int m_AIfactor;
|
156
|
};
|
157
|
|
158
|
#endif//__MODBUS_EX_LINE_SVR_H
|
159
|
|
160
|
|