Project

General

Profile

Feature #794 » mBim4.h

lq Du, 09/09/2020 12:26 PM

 
1
#ifndef	__MBIM_H
2
#define	__MBIM_H
3

    
4
#include "daq/daq_protocol.h"
5
#include "daq/daq_raw.h"
6

    
7
#include "utility/CommonDef.h"
8

    
9
#ifdef NET_BYTEORDER
10
#define BITORDER 1
11
#endif
12

    
13

    
14

    
15
////////////////////////////////////////////////////
16
// position based on 0
17
inline bool GetValueFrom32bit(const uint32 dwSrc, const uint32 pos)
18
{
19
    uint32 opr = dwSrc ;
20
    if (0x00000001 == ((opr>>pos) & 0x00000001))
21
        return true;
22
    else
23
        return false;
24
}
25
inline void SetValueTo32bit(uint32 *dwSrc, const uint32 pos, const bool value)
26
{
27
    uint32 tmpV = *dwSrc ;
28
    if (value) {
29
        tmpV = ((uint32)0x1<<pos) | tmpV ;
30
    }
31
    else {
32
        tmpV = ~(((uint32)0x1)<<pos) & tmpV ;
33
    }
34
    *dwSrc = tmpV ;
35
}
36

    
37

    
38
////////////////////////////////////////////////////
39
#define RxDataLen       17
40
#define	TxDataMaxLen	(DEF_DCV_MAX_TANSSRC)//1042//WYF 20190526
41

    
42
#define FixSysID_Req    15  //0x0F
43
#define FixSysID_Ans    255 //0xFF
44
#define ReqTypeID_DI    1   //DI
45
#define ReqTypeID_AI    3   //AI
46

    
47
#define MaxObjPerFrame_DIAI     512 // һ֡???ܰ???????Ϣ???????
48
#define DINumberPerBlock        16  // 1??DI??Ϣ???????DI????
49

    
50

    
51
////////////////////////////////////////////////////
52
typedef struct _BimRTUConfig {
53
    uint32  rtuNo;
54
    
55
    uint32  totalYX;        // DI??????
56
    uint32  totalYxBlock;   // ??RTU??????DI??Ϣ?? -- ÿ????Ϣ??16λ??ÿ֡???512????Ϣ?? (??Ϣ??Ķ?????Э???޹أ?Ϊ?????RTUת??????)
57
    uint32  totalYC;        // AI??????
58
    uint32  totalYcFrame;   // ??RTU??????AI֡???? -- ÿ֡???512??AI??
59
}BimRTUConfig, *LPBimRTUConfig;
60
typedef struct _BimIniConfig {
61
    uint32          totalRtus;
62
    uint32          portNo;
63
    
64
    LPBimRTUConfig     rtuConfArray;
65
}BimIniConfig, *LPBimIniConfig;
66

    
67
typedef struct _databuf
68
{
69
    uint8 * headP;
70
    uint8 * trailP;
71
    uint8   databuf[TxDataMaxLen];
72
} DATABUF;
73

    
74
#define DataHeadLen     9
75
typedef struct
76
{
77
    uint8   HeadLo; // 0xEB
78
    uint8   HeadHi; // 0x90
79
    uint8   SysID;  // system ID, fixed
80
    uint8   PacketNoLo; // package number of frame, circle-self, 0~0xFFFF
81
    uint8   PacketNoHi;
82
    uint8   LenLo;  // calculate from Multi-Flag to the last data byte
83
    uint8   LenHi;
84
    uint8   MultiFlag;  // 0-end, 1-Subsequent Package
85
    uint8   MsgID;  // 1-DI, 3-AI
86
} DATA_HEAD;  //???ݵ?Ԫ??ʾ??
87

    
88

    
89
////////////////////////////////////////////////////
90
class CMBim : public CProtocol
91
{
92
public:
93
    CMBim();
94
    ~CMBim();
95

    
96
    virtual sint32 TxProc();	// һ?½ӿ?
97
    virtual sint32 RxProc();
98
    virtual sint32 GetZfFlag( )
99
    {
100
        return 1;
101
    };
102
    virtual void Init( S_PROTOCOLCFG * pcfg );
103

    
104
private:
105
//     sint32 GetNowSecond();
106

    
107
    void initStation();
108
    void appToLink();
109
    
110
    void readIni();
111

    
112
    void setFlagToDI(uint8 *buf, sint32 buflen);
113
    void setFlagToAI(uint8 *buf, sint32 buflen);
114

    
115
    sint32 procSendDI();
116
    sint32 procSendAI();
117

    
118
private:
119
    BimIniConfig    m_iniConfig;    // parameter from INI file
120

    
121
    DATABUF     m_sendData;
122

    
123
    BYTE    m_flagSendType;     // bit0: DI, bit1: AI
124
    uint16  m_nSendFrameNo; // index base 0, frame number for each type of send
125
    uint16  m_nSendSeqNo;   // 0 ~ 0xFFFF, circle-self, frame number
126

    
127
#ifdef OS_WIN
128
    Logger  *m_logger;
129
    DWORD   m_SendData_TimeBegin;
130
    DWORD   m_SendTypeData_TimeBegin;
131
#endif
132
};
133

    
134
#endif
135

    
136

    
(3-3/4)