LAPTOP-SNT8I5JK\Boounion
2025-09-19 81df82be1f5f401b80780f65e5811685d9a8e4c4
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#pragma once
#include <string>
#include <list>
#include "HsmsAction.h"
#include <functional>
#include <vector>
#include <map>
#include <set>
#include "CCollectionEvent.h"
#include "ProcessJob.h"
#include "CControlJob.h"
 
 
#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
#define ER_NO_EVENT                -4
#define ER_UNLINK_EVENT_REPORT    -5
#define ER_NO_PPID_LIST            -6
#define ER_NOT_SUPPORTED        -7
 
 
/* CAACK */
 
#define CAACK_0                    0        /* ok */
#define CAACK_1                    1        /* invalid command */
#define CAACK_2                    2        /* cannot perform now */
#define CAACK_3                    3        /* invalid data or argument */
#define CAACK_4                    4        /* initiated for asynchronous completion */
#define CAACK_5                    5        /* rejected - invalid state */
#define CAACK_6                    6        /* command performed with errors */
 
/*
 * ³£Á¿Êý¾Ý½á¹¹
 */
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 std::function<void(void* pFrom, SYSTEMTIME& time)> DATETIMESYNC;
typedef std::function<void(void* pFrom, bool bEnable, std::vector<unsigned int>& ids)> EDEVENTREPORT;
typedef std::function<void(void* pFrom, bool bEnable, unsigned int id)> EDALARMREPORT;
typedef std::function<std::vector<std::string> (void* pFrom)> QUERYPPIDLIST;
typedef std::function<unsigned int (void* pFrom,
    unsigned int DATAID,
    const char* pszCarrierAction,
    const char* pszCarrierId,
    unsigned char PTN, 
    std::string& strErrorTxt)> CARRIERACTION;
typedef std::function<int(void* pFrom, std::vector<SERVO::CProcessJob*>& pjs)> PRJOBMULTICREATE;
typedef std::function<int(void* pFrom, SERVO::CControlJob& controlJob)> CONTROLJOBCREATE;
typedef struct _SECSListener
{
    SECSEQOFFLINE                onEQOffLine;
    SECSEQOFFLINE                onEQOnLine;
    SECSEQCONSTANTREQUEST        onEQConstantRequest;
    SECSEQCONSTANTREQUEST        onEQConstantSend;
    SECSCommand                    onCommand;
    DATETIMESYNC                onDatetimeSync;
    EDEVENTREPORT                onEnableDisableEventReport;
    EDALARMREPORT                onEnableDisableAlarmReport;
    QUERYPPIDLIST                onQueryPPIDList;
    CARRIERACTION                onCarrierAction;
    PRJOBMULTICREATE            onPRJobMultiCreate;
    CONTROLJOBCREATE            onControlJobCreate;
} SECSListener;
 
 
class CModel;
class CHsmsPassive
{
public:
    CHsmsPassive();
    ~CHsmsPassive();
 
public:
    /* ÉèÖûúÆ÷ÐͺŠ×î´ó³¤¶È 20 bytes */
    void setEquipmentModelType(const char* pszMode);
 
    /* ÉèÖÃÈí¼þ°æ±¾ºÅ ×î´ó³¤¶È 20 bytes */
    void setSoftRev(const char* pszRev);
 
    /* Ìí¼Ó±äÁ¿Öµµ½ISECS2Item */
    void addVariableValueToItem(ISECS2Item* pParent, SERVO::CVariable* pVariable);
 
    // Á¬½ÓReport
    void linkEventReport(unsigned int CEID, unsigned int RPTID);
 
    // È¡ÏûÁ¬½Óreport
    void unlinkEventReport(unsigned int CEID);
 
    // define Report
    SERVO::CReport* defineReport(unsigned int RPTID, std::vector<unsigned int>& vids);
 
    // È¡Ïû define report
    bool removeReport(int rptid);
    void clearAllReport();
 
    // ´ÓÎļþÖмÓÔØCVariableÁбí
    int loadVarialbles(const char* pszFilepath);
 
    // È¡µÃCVariableÁбí
    std::vector<SERVO::CVariable*>& getVariables();
 
    // È¡µÃÖ¸¶¨Variable
    SERVO::CVariable* getVariable(int variableId);
    SERVO::CVariable* getVariable(const char* pszName);
 
    // ÉèÖñäÁ¿Öµ
    void setVariableValue(const char* pszName, __int64 value);
    void setVariableValue(const char* pszName, const char* value);
    void setVariableValue(const char* pszName, std::vector<SERVO::CVariable>& vars);
 
    // ´ÓÎļþÖмÓÔØCReportÁбí
    int loadReports(const char* pszFilepath);
 
    // È¡µÃReportÁбí
    std::vector<SERVO::CReport*>& getReports();
 
    // ´ÓÎļþÖмÓÔØCCollectionEventÁбí
    int loadCollectionEvents(const char* pszFilepath);
 
    // È¡µÃCCollectionEventÁбí
    std::vector<SERVO::CCollectionEvent*>& getCollectionEvents();
 
    // È¡Ïû/ɾ³ýËùÓÐCollectionEvent
    void clearAllCollectionEvent();
 
    // È¡µÃCCollectionEvent
    SERVO::CCollectionEvent* getEvent(unsigned short CEID);
 
    // È¡µÃReport
    SERVO::CReport* getReport(int rptid);
 
    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 loadCacheFromFile(const char* pszFilepath);
    int saveCache();
    int term();
    int serialize(char* pszBuffer, int nBufferSize);
    int unserialize(const char* pszBuffer, int nBufferSize);
 
public:
    /* request¿ªÍ·µÄº¯ÊýΪÖ÷¶¯·¢ËÍÊý¾ÝµÄº¯Êý */
    int requestAreYouThere();
    int requestAlarmReport(int ALCD, int ALID, const char* ALTX);
    int requestEventReportSend(unsigned int CEID);
    int requestEventReportSend(const char* pszEventName);
    int requestEventReportSend_CarrierID_Readed();
    int requestEventReportSend_Port_Unload_Ready();
    int requestEventReportSend_Port_Load_Ready();
    int requestEventReportSend_Port_Blocked();
    int requestEventReportSend_PJ_Queued();
    int requestEventReportSend_PJ_Start();
    int requestEventReportSend_PJ_End();
    int requestEventReportSend_CJ_Start();
    int requestEventReportSend_CJ_End();
    int requestEventReportSend_Panel_Start();
    int requestEventReportSend_Panel_End();
 
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 replySelectedEquipmentStatusData(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 replyConfigureSpooling(IMessage* pRecv);
    int replyCarrierAction(IMessage* pRecv);
    int replyEanbleDisableAlarmReport(IMessage* pRecv);
    int replyPurgeSpooledData(IMessage* pRecv);
    int replyQueryPPIDList(IMessage* pRecv);
    int replyTerminalDisplay(IMessage* pRecv);
    int replyCreateObj(IMessage* pRecv);
    int replyPRJobMultiCreate(IMessage* pRecv);
 
private:
    inline void Lock() { EnterCriticalSection(&m_criticalSection); }
    inline void Unlock() { LeaveCriticalSection(&m_criticalSection); }
    int onRecvMsg(IMessage* pMessage);
    void clearAllVariabel();
    std::vector<unsigned int> parseVidList(CString& strNums);
 
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;
    std::list<CHsmsAction*> m_listActionSpooling;
 
private:
    SECSListener m_listener;
    BOOL m_bCimWorking;
    HANDLE m_hCimWorkEvent;
    HANDLE m_hCimWorkThreadHandle;
    unsigned m_nCimWorkThrdaddr;
    std::string m_strCacheFilepath;
    CHsmsAction* m_pActiveAction;
 
private:
    // CVariable vector
    std::vector<SERVO::CVariable*> m_variabels;
 
    // CReport vector
    std::vector<SERVO::CReport*> m_reports;
 
    // CollectionEvent vector
    std::vector<SERVO::CCollectionEvent*> m_collectionEvents;
 
    // Spooling Config
    std::map<uint16_t, std::set<uint16_t>> m_spoolingConfig;
};