mrDarker
2025-06-26 adf46e4da2f53d171cc5a0e95340d751ebacf763
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#pragma once
#include <string>
#include <list>
#include "HsmsAction.h"
#include <functional>
#include <vector>
#include <map>
 
 
#define EQCONSTANT_VALUE_MAX    64
#define COMMAND_NAME_MAX        64
#define COMMAND_VALUE_MAX        64
#define REPORT_NAME_MAX            64
#define VALUE_NAME_MAX            64
 
 
#define ER_NOERROR            0
#define ER_NOTSELECT        -1
#define ER_BUSY                -2
#define ER_PARAM_ERROR        -3
 
 
/*
 * ³£Á¿Êý¾Ý½á¹¹
 */
typedef struct _EQConstant
{
    unsigned int id;
    char szValue[EQCONSTANT_VALUE_MAX];
} EQConstant;
 
/*
 * Command Êý¾Ý½á¹¹
 */
typedef struct _CommandParameter
{
    char szName[COMMAND_NAME_MAX];
    char szValue[COMMAND_VALUE_MAX];
} CommandParameter;
 
/*
 * Report Êý¾Ý½á¹¹
 */
typedef struct _REPORT
{
    char szName[REPORT_NAME_MAX];
    unsigned int id;
} REPORT;
 
/*
 * Value Êý¾Ý½á¹¹
 */
typedef struct _VALUE
{
    char szName[VALUE_NAME_MAX];
    unsigned int id;
} VALUE;
 
 
typedef std::function<void(void* pFrom)> SECSEQOFFLINE;
typedef std::function<void(void* pFrom, std::vector<EQConstant>&)> SECSEQCONSTANTREQUEST;
typedef std::function<void(void* pFrom, const char*, std::vector<CommandParameter>&)> SECSCommand;
typedef struct _SECSListener
{
    SECSEQOFFLINE                onEQOffLine;
    SECSEQOFFLINE                onEQOnLine;
    SECSEQCONSTANTREQUEST        onEQConstantRequest;
    SECSEQCONSTANTREQUEST        onEQConstantSend;
    SECSCommand                    onCommand;
} SECSListener;
 
 
class CModel;
class CHsmsPassive
{
public:
    CHsmsPassive();
    ~CHsmsPassive();
 
public:
    /* ÉèÖûúÆ÷ÐͺŠ×î´ó³¤¶È 20 bytes */
    void setEquipmentModelType(const char* pszMode);
 
    /* ÉèÖÃÈí¼þ°æ±¾ºÅ ×î´ó³¤¶È 20 bytes */
    void setSoftRev(const char* pszRev);
 
    /* Ìí¼ÓReport */
    void addReport(unsigned int id, const char* pszName);
 
    // Á¬½ÓReport
    void linkEventReport(unsigned int RPTID, unsigned int CEID);
 
    // È¡ÏûÁ¬½Óreport
    void unlinkEventReport(unsigned int CEID);
 
    unsigned int getCEID(int RPTID);
 
    // define Report
    void defineReport(unsigned int VID, unsigned int RPTID);
 
    // È¡Ïû define report
    void deleteReport(unsigned int RPTID);
 
    // È¡Ïû/ɾ³ýËùÓРdefine report
    void deleteAllReport();
 
    void setListener(SECSListener listener);
    unsigned OnCimWork();
    void OnTimer(UINT nTimerid);
    void setActionTimeout(int nSecond);
    int init(CModel* pModel, const char* pszName, unsigned int port);
    int term();
 
public:
    /* request¿ªÍ·µÄº¯ÊýΪÖ÷¶¯·¢ËÍÊý¾ÝµÄº¯Êý */
    int requestAreYouThere();
    int requestAlarmReport(int ALCD, int ALID, const char* ALTX);
    int requestEventReportSend(unsigned int DATAID, unsigned int RPTID, const std::vector<std::string>& values);
 
private:
    void replyAck(int s, int f, unsigned int systemBytes, BYTE ack, const char* pszAckName);
 
    /* reply¿ªÍ·µÄº¯ÊýΪ»Ø¸´º¯Êý */
    int replyAreYouThere(IMessage* pRecv);
    int replyEstablishCommunications(IMessage* pRecv);
    int replyOnLine(IMessage* pRecv);
    int replyOffLine(IMessage* pRecv);
    int replyEquipmentConstantRequest(IMessage* pRecv);
    int replyEquipmentConstantSend(IMessage* pRecv);
    int replyDatetime(IMessage* pRecv);
    int replyDefineReport(IMessage* pRecv);
    int replyLinkEventReport(IMessage* pRecv);
    int replyEanbleDisableEventReport(IMessage* pRecv);
    int replyCommand(IMessage* pRecv);
    int replyEanbleDisableAlarmReport(IMessage* pRecv);
    int replyQueryPPIDList(IMessage* pRecv);
    int replyTerminalDisplay(IMessage* pRecv);
 
private:
    inline void Lock() { EnterCriticalSection(&m_criticalSection); }
    inline void Unlock() { LeaveCriticalSection(&m_criticalSection); }
    int onRecvMsg(IMessage* pMessage);
 
private:
    CModel* m_pModel;
    IPassive* m_pPassive;
    int m_nActionTimeout;
    unsigned int m_nSystemByte;
    unsigned short m_nSessionId;
    BOOL m_bAreYouThereRequest;
    std::string m_strEquipmentModelType;
    std::string m_strSoftRev;
    CRITICAL_SECTION m_criticalSection;
    std::list<CHsmsAction*> m_listAction;
    std::list<CHsmsAction*> m_listActionSent;
 
private:
    SECSListener m_listener;
    BOOL m_bCimWorking;
    HANDLE m_hCimWorkEvent;
    HANDLE m_hCimWorkThreadHandle;
    unsigned m_nCimWorkThrdaddr;
 
private:
    // RPTID to CEID
    std::map<unsigned int, unsigned int> m_mapReportIdToCEID;
    
    // RPTID to Report
    std::map<unsigned int, REPORT> m_mapReport;
 
    // VID to RPTID
    std::map<unsigned int, unsigned int> m_mapValueIdToPRTID;
 
    // VID to Report
    std::map<unsigned int, VALUE> m_mapValue;
};