#pragma once #include #include #include "HsmsAction.h" #include #include #include #include #include "CCollectionEvent.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 SECSEQOFFLINE; typedef std::function&)> SECSEQCONSTANTREQUEST; typedef std::function&)> SECSCommand; typedef std::function DATETIMESYNC; typedef std::function& ids)> EDEVENTREPORT; typedef std::function EDALARMREPORT; typedef std::function (void* pFrom)> QUERYPPIDLIST; typedef std::function CARRIERACTION; typedef struct _SECSListener { SECSEQOFFLINE onEQOffLine; SECSEQOFFLINE onEQOnLine; SECSEQCONSTANTREQUEST onEQConstantRequest; SECSEQCONSTANTREQUEST onEQConstantSend; SECSCommand onCommand; DATETIMESYNC onDatetimeSync; EDEVENTREPORT onEnableDisableEventReport; EDALARMREPORT onEnableDisableAlarmReport; QUERYPPIDLIST onQueryPPIDList; CARRIERACTION onCarrierAction; } 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& vids); // È¡Ïû define report bool removeReport(int rptid); void clearAllReport(); // ´ÓÎļþÖмÓÔØCVariableÁбí int loadVarialbles(const char* pszFilepath); // È¡µÃCVariableÁбí std::vector& 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); // ´ÓÎļþÖмÓÔØCReportÁбí int loadReports(const char* pszFilepath); // È¡µÃReportÁбí std::vector& getReports(); // ´ÓÎļþÖмÓÔØCCollectionEventÁбí int loadCollectionEvents(const char* pszFilepath); // È¡µÃCCollectionEventÁбí std::vector& 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(); 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); private: inline void Lock() { EnterCriticalSection(&m_criticalSection); } inline void Unlock() { LeaveCriticalSection(&m_criticalSection); } int onRecvMsg(IMessage* pMessage); void clearAllVariabel(); std::vector 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 m_listAction; std::list m_listActionSent; std::list 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 m_variabels; // CReport vector std::vector m_reports; // CollectionEvent vector std::vector m_collectionEvents; // Spooling Config std::map> m_spoolingConfig; };