darker
2025-02-11 9b2d1e962bf802f75c44c1f5372fc4cf029e3f4e
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
#pragma once
#include <string>
#include <list>
#include "HsmsAction.h"
#include <functional>
#include <vector>
 
 
#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[256];
} EQConstant;
 
/*
 * Command Êý¾Ý½á¹¹
 */
typedef struct _CommandParameter
{
    char szName[256];
    char szValue[256];
} CommandParameter;
 
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);
 
    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);
 
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 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;
};