LAPTOP-SNT8I5JK\Boounion
2025-01-06 ff688ae6ea488901a79c017463832bd8b554b717
1.引入Hsms库,封装发送接收类,模拟测试Are you there;
已添加11个文件
已修改8个文件
753 ■■■■■ 文件已修改
SourceCode/Bond/HSMSSDK/Include/HSMSSDK.h 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/HSMSSDK/Include/IMessage.h 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/HSMSSDK/Include/IPassive.h 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/HSMSSDK/Include/ISECS2Item.h 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/HSMSSDK/使用说明.txt 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Common.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Context.cpp 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Context.h 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/HsmsAction.cpp 109 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/HsmsAction.h 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/HsmsPassive.cpp 293 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/HsmsPassive.h 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Model.cpp 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Model.h 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.cpp 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.rc 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.vcxproj 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Servo.vcxproj.filters 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/stdafx.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/HSMSSDK/Include/HSMSSDK.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,71 @@
#pragma once
#include <functional>
#include "IPassive.h"
#include "IMessage.h"
#ifdef _COMPILE_AS_LIB
#warning "compiling as lib!"
#else
#ifdef _DEBUG
#ifndef _WIN64
#pragma comment(lib, "../HSMSSDK/lib/Win32/Debug/HSMS.lib")
#else
#pragma comment(lib, "../HSMSSDK/lib/x64/Debug/HSMS.lib")
#endif
#else
#ifndef _WIN64
#pragma comment(lib, "../HSMSSDK/lib/Win32/Release/HSMS.lib")
#else
#pragma comment(lib, "../HSMSSDK/lib/x64/Release/HSMS.lib")
#endif
#endif
#endif // !BUILD_AS_LIB
///////////////////////////////////////////////////////////////////////////////////
//// Define C linkage if using a C++ compiler
///////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
    ///////////////////////////////////////////////////////////////////////////////////
    //// Determine callling convention baesd on compiler
    ///////////////////////////////////////////////////////////////////////////////////
#ifdef __BORLANDC__
#ifdef __WIN32__
#define EXPORTED __declspec(dllexport) __stdcall
#else
#define EXPORTED FAR PASCAL __export
#endif // WIN32
#else // __BORLANDC__
#ifdef WIN32
#define EXPORTED __declspec(dllexport)
#else
#define EXPORTED FAR PASCAL __export
#endif // WIN32
#endif //__BORLANDC__
    /////////////////////////////////////////////////////////////////////////////////////
    //// å¯¼å‡ºå‡½æ•°
    ////////////////////////////////////////////////////////////////////////////////////
    int                EXPORTED    HSMS_Initialize();
    int                EXPORTED    HSMS_Term();
    int                EXPORTED    HSMS_CreatePassive(OUT IPassive*& pPassive, const char* pName, const unsigned int nPort);
    int                EXPORTED    HSMS_DestroyPassive(IPassive* pPassive);
    int                EXPORTED    HSMS_Create1Message(OUT IMessage*& pMessage, unsigned short sessionId, BYTE stream, BYTE function, unsigned int nSystemBytes);
    int                EXPORTED    HSMS_Destroy1Message(IMessage* pMessage);
#ifdef __cplusplus
};
#endif //__cplusplus
SourceCode/Bond/HSMSSDK/Include/IMessage.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,32 @@
#pragma once
#include "ISECS2Item.h"
#define MSG_DATA            0
#define MSG_SELECT_REQ        1
#define MSG_SELECT_RSP        2
#define MSG_DESELECT_REQ    3
#define MSG_DESELECT_RSP    4
#define MSG_LINKTEST_REQ    5
#define MSG_LINKTEST_RSP    6
#define MSG_REJECT_REQ        7
#define MSG_SEPARATE_REQ    9
#define REPLY                0x80
typedef struct _HEADER
{
    unsigned short sessionId;
    BYTE stream;
    BYTE function;
    BYTE pType;
    BYTE sType;
    unsigned int systemBytes;
}HEADER;
class IMessage
{
public:
    virtual int getLength() = 0;
    virtual HEADER* getHeader() = 0;
    virtual ISECS2Item* getBody() = 0;
    virtual const char* toString() = 0;
};
SourceCode/Bond/HSMSSDK/Include/IPassive.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,40 @@
#pragma once
#include <functional>
#include "IMessage.h"
enum STATE
{
    NOT_CONNECTED = 0,
    NOT_SELECTED = 1,
    SELECTED = 2
};
typedef std::function<void(void* pFrom, STATE state)> ONSTATECHANGED;
typedef std::function<void(void* pFrom, const char* pszData, int size)> ONRECVRAWDATA;
typedef std::function<void(void* pFrom, IMessage* pMessage)> ONRECVDATAMSG;
typedef std::function<void(void* pFrom, IMessage* pMessage)> ONRECVSYSMSG;
typedef std::function<void(void* pFrom, int error)> ONDATAERROR;
typedef struct _PassiveListener
{
    ONSTATECHANGED        funStateChanged;
    ONRECVRAWDATA        funRecvRawData;
    ONRECVDATAMSG        funRecvDataMessage;
    ONRECVSYSMSG        funRecvSysMessage;
    ONDATAERROR            funError;
} PassiveListener;
class IPassive
{
public:
    virtual void setListener(PassiveListener listener) = 0;
    virtual void setTimeout3(int timeout) = 0;
    virtual void setTimeout5(int timeout) = 0;
    virtual void setTimeout6(int timeout) = 0;
    virtual void setTimeout7(int timeout) = 0;
    virtual void setTimeout8(int timeout) = 0;
    virtual int sendMessage(IMessage* pMessage) = 0;
    virtual STATE getState() = 0;
};
SourceCode/Bond/HSMSSDK/Include/ISECS2Item.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,35 @@
#pragma once
enum SITYPE
{
    L = 000,
    B = 010,
    Bool = 011,
    A = 020,
    J = 021,
    SLASH = 022,
    I8 = 030,
    I1 = 031,
    I2 = 032,
    I4 = 034,
    F8 = 040,
    F4 = 044,
    U8 = 050,
    U1 = 051,
    U2 = 052,
    U4 = 054
};
class ISECS2Item
{
public:
    virtual SITYPE getType() = 0;
    virtual const char* toString() = 0;
    virtual bool getString(char*& pszText) = 0;
    virtual int getSubItemSize() = 0;
    virtual ISECS2Item* getSubItem(int index) = 0;
    virtual bool getSubItemString(int index, char*& pszText) = 0;
    virtual void reset() = 0;
    virtual ISECS2Item* addItem(const char* pszText, const char* pszNote) = 0;
    virtual ISECS2Item* addItem() = 0;
};
SourceCode/Bond/HSMSSDK/ʹÓÃ˵Ã÷.txt
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,24 @@
使用说明:
1.在程序启动时初始化
HSMS_Initialize
2.创建服务端
IPassive* m_pPassive;
HSMS_CreatePassive(m_pPassive, "APP", 7000);
调用IPassive的setListener监听连接状态
3.构造消息和发送消息
IMessage* pMessage = NULL;
HSMS_Create1Message(pMessage, m_nSessionId, 1| REPLY, 1, getSystemByte());
    ISECS2Item* pItem = pMessage->getBody();
    pItem->addItem((LPTSTR)(LPCTSTR)m_strEquipmentModelType, "MDLN");
    pItem->addItem((LPTSTR)(LPCTSTR)m_strSoftRev, "SOFTREV");
m_pPassive->sendMessage(pMessage);
HSMS_Destroy1Message(pMessage);
4.程序结束时调用
HSMS_Term()
SourceCode/Bond/Servo/Common.h
@@ -4,6 +4,8 @@
/* Rx Code */
#define RX_CODE_TEST                    0
#define RX_CODE_LOG                        1000
#define RX_CODE_PASSIVE_STATUS_CHANGED    1001
#define RX_CODE_MES_MESSAGE                1002
/* Channel Name */
SourceCode/Bond/Servo/Context.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,12 @@
#include "stdafx.h"
#include "Context.h"
CContext::CContext()
{
}
CContext::~CContext()
{
}
SourceCode/Bond/Servo/Context.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,8 @@
#pragma once
class CContext
{
public:
    CContext();
    ~CContext();
};
SourceCode/Bond/Servo/HsmsAction.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,109 @@
#include "stdafx.h"
#include "HsmsAction.h"
CHsmsAction::CHsmsAction()
{
    m_nAction = ACTION_IDLE;
    m_bNeedWaitReply = FALSE;
    m_nTimeout = 45;
    m_nResponseTime = 0;
    m_pContext = NULL;
    m_hEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
}
CHsmsAction::CHsmsAction(int nAction, BOOL bNeedReply, unsigned int nTimeout)
{
    m_nAction = nAction;
    m_bNeedWaitReply = bNeedReply;
    m_nTimeout = nTimeout;
    m_nResponseTime = 0;
    m_pContext = NULL;
    m_hEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
}
CHsmsAction::~CHsmsAction()
{
    if (m_hEvent != NULL) {
        CloseHandle(m_hEvent);
        m_hEvent = NULL;
    }
    if (m_pSendMessage != NULL) {
        HSMS_Destroy1Message(m_pSendMessage);
        m_pSendMessage = NULL;
    }
}
void CHsmsAction::reset()
{
    m_nAction = ACTION_IDLE;
    m_bNeedWaitReply = FALSE;
    m_nTimeout = 45;
    m_nResponseTime = 0;
    ::ResetEvent(m_hEvent);
}
void CHsmsAction::resetResponseTime()
{
    m_nResponseTime = 0;
}
void CHsmsAction::setAction(int nAction, BOOL bNeedReply/* = TRUE*/, unsigned int nTimeout/* = 45*/)
{
    m_nAction = nAction;
    m_bNeedWaitReply = bNeedReply;
    m_nTimeout = nTimeout;
}
int CHsmsAction::getAction()
{
    return m_nAction;
}
void CHsmsAction::setContext(CContext* pContext)
{
    m_pContext = pContext;
}
CContext* CHsmsAction::getContext()
{
    return m_pContext;
}
void CHsmsAction::setSendMessage(IMessage* pMessage)
{
    m_pSendMessage = pMessage;
}
IMessage* CHsmsAction::getSendMessage()
{
    return m_pSendMessage;
}
unsigned int CHsmsAction::getTimeout()
{
    return m_nTimeout;
}
BOOL CHsmsAction::isNeedWaitReply()
{
    return m_bNeedWaitReply;
}
HANDLE CHsmsAction::getEvent()
{
    return m_hEvent;
}
int CHsmsAction::responseTimeIncrement()
{
    return InterlockedIncrement(&m_nResponseTime);
}
BOOL CHsmsAction::incrementAndCheckTimeout()
{
    unsigned int nResponseTime = InterlockedIncrement(&m_nResponseTime);
    return nResponseTime >= m_nTimeout;
}
SourceCode/Bond/Servo/HsmsAction.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,40 @@
#pragma once
#include "Context.h"
#define ACTION_IDLE                                0
#define ACTION_HELLO                            1        /* S1F1 */
class CHsmsAction
{
public:
    CHsmsAction();
    CHsmsAction(int nAction, BOOL bNeedReply, unsigned int nTimeout);
    ~CHsmsAction();
public:
    void reset();
    void resetResponseTime();
    void setAction(int nAction, BOOL bNeedReply = TRUE, unsigned int nTimeout = 45);
    int getAction();
    void setContext(CContext* pContext);
    CContext* getContext();
    void setSendMessage(IMessage* pMessage);
    IMessage* getSendMessage();
    unsigned int getTimeout();
    BOOL isNeedWaitReply();
    HANDLE getEvent();
    int responseTimeIncrement();
    BOOL incrementAndCheckTimeout();
private:
    int m_nAction;
    unsigned int m_nTimeout;                // è¶…æ—¶(秒)
    unsigned int m_nResponseTime;
    CContext* m_pContext;
    HANDLE m_hEvent;
    BOOL m_bNeedWaitReply;
    IMessage* m_pSendMessage;
};
SourceCode/Bond/Servo/HsmsPassive.cpp
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,293 @@
#include "stdafx.h"
#include "HsmsPassive.h"
#include "Log.h"
#include "Model.h"
#include "Common.h"
unsigned __stdcall CimWorkThreadFunction(LPVOID lpParam)
{
    CHsmsPassive* pPassive = (CHsmsPassive*)lpParam;
    return pPassive->OnCimWork();
}
CHsmsPassive* g_pPassive = NULL;
void CALLBACK HsmsPassiveTimerProc(HWND hWnd, UINT nMsg, UINT nTimerid, DWORD dwTime)
{
    if (g_pPassive != NULL) {
        g_pPassive->OnTimer(nTimerid);
    }
}
CHsmsPassive::CHsmsPassive()
{
    m_pPassive = nullptr;
    m_bAreYouThereRequest = FALSE;
    m_pModel = nullptr;
    m_nActionTimeout = 6;
    m_nSystemByte = 0;
    m_strSoftRev = _T("1.0.1");
    m_hCimWorkThreadHandle = NULL;
    m_nCimWorkThrdaddr = 0;
    m_bCimWorking = FALSE;
    m_hCimWorkEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
    InitializeCriticalSection(&m_criticalSection);
}
CHsmsPassive::~CHsmsPassive()
{
    Lock();
    for (auto item : m_listAction) {
        delete item;
    }
    m_listAction.clear();
    for (auto item : m_listActionSent) {
        delete item;
    }
    m_listActionSent.clear();
    Unlock();
    if (m_hCimWorkEvent != NULL) {
        CloseHandle(m_hCimWorkEvent);
        m_hCimWorkEvent = NULL;
    }
    DeleteCriticalSection(&m_criticalSection);
}
void CHsmsPassive::setActionTimeout(int nSecond)
{
    m_nActionTimeout = max(3, nSecond);
}
void CHsmsPassive::OnTimer(UINT nTimerid)
{
    // æ‰€æœ‰å·²å‘送的Action自加1
    Lock();
    for (auto iter = m_listActionSent.begin(); iter != m_listActionSent.end();) {
        if ((*iter)->incrementAndCheckTimeout()) {
            TRACE("CHsmsPassive::超时\n");
            delete (*iter);
            m_listActionSent.erase(iter++);
        }
        else {
            ++iter;
        }
    }
    Unlock();
}
int CHsmsPassive::onRecvMsg(IMessage* pMessage)
{
    Lock();
    CHsmsAction* pAction = nullptr;
    for (auto iter = m_listActionSent.begin(); iter != m_listActionSent.end(); iter++) {
        if ((*iter)->getSendMessage()->getHeader()->systemBytes == pMessage->getHeader()->systemBytes) {
            LOGI("CHsmsPassive::找到");
            pAction = (*iter);
            m_listActionSent.erase(iter);
            break;
        }
    }
    Unlock();
    if (pAction != nullptr) {
        LOGI("onRecvMsg::相应处理");
        delete pAction;
    }
    return 0;
}
int CHsmsPassive::init(CModel* pModel, const char* pszName, unsigned int port)
{
    m_pModel = pModel;
    HSMS_CreatePassive(m_pPassive, pszName, port);
    if (m_pPassive == NULL) {
        return -1;
    }
    auto onStatusChanged = [&](void* pFrom, STATE state) -> void {
        m_pModel->notifyInt(RX_CODE_PASSIVE_STATUS_CHANGED, (int)state);
        // è¿žä¸Šä¹‹åŽå‘S1F1,
        if (STATE::SELECTED == state) {
            m_bAreYouThereRequest = FALSE;
            if (!m_bAreYouThereRequest) {
                m_bAreYouThereRequest = TRUE;
                secsAreYouThereRequest();
            }
        }
    };
    auto onRecvSysMessage = [&](void* pFrom, IMessage* pMessage) -> void {
        LOGI("<HSMS>onRecvSysMessage:sessionId:%d, sType:%d systemBytes:%d",
            pMessage->getHeader()->sessionId, pMessage->getHeader()->sType, pMessage->getHeader()->systemBytes);
        onRecvMsg(pMessage);
        if (MSG_LINKTEST_REQ == pMessage->getHeader()->sType) {
            Sleep(10);
            if (!m_bAreYouThereRequest) {
                m_bAreYouThereRequest = TRUE;
                secsAreYouThereRequest();
            }
        }
    };
    auto onError = [&](void* pFrom, int error) -> void {
        LOGI("<HSMS>onError:%d", error);
        // secsIllegalData();
    };
    auto onRecvRawData = [&](void* pFrom, const char* pszData, int size) {
        LOGI("<HSMS>onRecvRawData:<0x%x, %d>", pszData, size);
    };
    auto onRecvDataMessage = [&](void* pFrom, IMessage* pMessage) -> void {
        HEADER* pHeader = pMessage->getHeader();
        int nStream = (pHeader->stream & 0x7F);
        LOGI("<HSMS>收到消息 S%dF%d", nStream, pHeader->function);
        if (nStream == 1 && pHeader->function == 1) {
            // S1F1
            secsAreYouThereReply(pHeader->sessionId, pHeader->systemBytes);
        }
    };
    PassiveListener listener;
    listener.funStateChanged = onStatusChanged;
    listener.funRecvRawData = onRecvRawData;
    listener.funRecvDataMessage = onRecvDataMessage;
    listener.funRecvSysMessage = onRecvSysMessage;
    listener.funError = onError;
    m_pPassive->setListener(listener);
    // å¯åŠ¨å·¥ä½œçº¿ç¨‹
    m_bCimWorking = TRUE;
    m_hCimWorkThreadHandle = (HANDLE)_beginthreadex(NULL, 0, ::CimWorkThreadFunction, this,
        0, &m_nCimWorkThrdaddr);
    g_pPassive = this;
    SetTimer(NULL, 1, 1000, (TIMERPROC)HsmsPassiveTimerProc);
    return 0;
}
int CHsmsPassive::term()
{
    // ç»“束线程
    m_bCimWorking = FALSE;
    SetEvent(m_hCimWorkEvent);
    if (m_hCimWorkThreadHandle != NULL) {
        WaitForSingleObject(m_hCimWorkThreadHandle, INFINITE);
        CloseHandle(m_hCimWorkThreadHandle);
        m_hCimWorkThreadHandle = NULL;
    }
    if (m_pPassive != NULL) {
        HSMS_DestroyPassive(m_pPassive);
        m_pPassive = NULL;
    }
    return 0;
}
unsigned CHsmsPassive::OnCimWork()
{
    while (m_bCimWorking) {
        // å¾…退出信号或时间到
        int nRet = WaitForSingleObject(m_hCimWorkEvent, INFINITE);
        ResetEvent(m_hCimWorkEvent);
        if (!m_bCimWorking) break;
        // å–出请求列表并进行处理
        std::list<CHsmsAction*> list;
        Lock();
        list.splice(list.end(), m_listAction);
        Unlock();
        while (!list.empty()) {
            Lock();
            CHsmsAction* pAction = list.front();
            Unlock();
            list.pop_front();
            TRACE("OnCimWork 004.\n");
            IMessage* pMessage = pAction->getSendMessage();
            ASSERT(pMessage);
            m_pPassive->sendMessage(pMessage);
            LOGI("<HSMS> [SEND] SysByte=%u sessionId:%d", pMessage->getHeader()->systemBytes, pMessage->getHeader()->sessionId);
            if (pAction->isNeedWaitReply()) {
                // å¦‚果需要等待回复
                int nRet = WaitForSingleObject(pAction->getEvent(), pAction->getTimeout() * 1000);
                if (nRet == WAIT_TIMEOUT) {
                    TRACE("Timeout...\n");
                    CContext* pContext = pAction->getContext();
                    if (pContext != NULL) {
                        //pContext->setRetCode(CRC_TIMEOUT);
                        //pContext->setRetMsg("超时");
                        //pContext->setEvent();
                    }
                }
                delete pAction;
                pAction = NULL;
                TRACE("delete m_pCurrentAction, next...\n");
            }
            else {
                Lock();
                m_listActionSent.push_back(pAction);
                Unlock();
            }
        }
        TRACE("OnCimWork \n");
    }
    // _endthreadex(0);
    TRACE("OnCimWork exit\n");
    return 0;
}
// S1F1
int CHsmsPassive::secsAreYouThereRequest()
{
    if (m_pPassive == NULL || STATE::SELECTED != m_pPassive->getState()) {
        return ER_NOTSELECT;
    }
    Lock();
    CHsmsAction* pAction = new CHsmsAction(ACTION_HELLO, FALSE, m_nActionTimeout);
    m_listAction.push_back(pAction);
    IMessage* pMessage = NULL;
    HSMS_Create1Message(pMessage, 0xffff, 1 | REPLY, 1, ++m_nSystemByte);
    ASSERT(pMessage);
    pAction->setSendMessage(pMessage);
    SetEvent(m_hCimWorkEvent);
    Unlock();
    return ER_NOERROR;
}
// S1F2
int CHsmsPassive::secsAreYouThereReply(unsigned int sessionId, unsigned int systemBytes)
{
    if (m_pPassive == NULL || STATE::SELECTED != m_pPassive->getState()) {
        return ER_NOTSELECT;
    }
    IMessage* pMessage = NULL;
    HSMS_Create1Message(pMessage, sessionId, 1, 2, systemBytes);
    ASSERT(pMessage);
    ISECS2Item* pItem = pMessage->getBody();
    pItem->addItem(m_strEquipmentModelType.c_str(), "MDLN");
    pItem->addItem(m_strSoftRev.c_str(), "SOFTREV");
    m_pPassive->sendMessage(pMessage);
    LOGI("<HSMS>[SECS Msg SEND]S1F2 (SysByte=%u)", pMessage->getHeader()->systemBytes);
    HSMS_Destroy1Message(pMessage);
    return 0;
}
SourceCode/Bond/Servo/HsmsPassive.h
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,51 @@
#pragma once
#include <string>
#include <list>
#include "HsmsAction.h"
#define ER_NOERROR            0
#define ER_NOTSELECT        -1
#define ER_BUSY                -2
class CModel;
class CHsmsPassive
{
public:
    CHsmsPassive();
    ~CHsmsPassive();
public:
    unsigned OnCimWork();
    void OnTimer(UINT nTimerid);
    void setActionTimeout(int nSecond);
    int init(CModel* pModel, const char* pszName, unsigned int port);
    int term();
    int secsAreYouThereRequest();
    int secsAreYouThereReply(unsigned int sessionId, unsigned int systemBytes);
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;
    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:
    BOOL m_bCimWorking;
    HANDLE m_hCimWorkEvent;
    HANDLE m_hCimWorkThreadHandle;
    unsigned m_nCimWorkThrdaddr;
};
SourceCode/Bond/Servo/Model.cpp
@@ -52,11 +52,15 @@
    });
    m_hsmsPassive.init(this, "APP", 7000);
    return 0;
}
int CModel::term()
{
    m_hsmsPassive.term();
    CLog::GetLog()->SetOnLogCallback(nullptr);
    return 0;
}
SourceCode/Bond/Servo/Model.h
@@ -1,5 +1,6 @@
#pragma once
#include "Configuration.h"
#include "HsmsPassive.h"
class CModel
{
@@ -29,6 +30,7 @@
public:
    CConfiguration m_configuration;
    CHsmsPassive m_hsmsPassive;
private:
    IObservable* m_pObservable;
SourceCode/Bond/Servo/Servo.cpp
@@ -88,8 +88,9 @@
    CServoGraph::RegisterWndClass();
    // åˆå§‹åŒ–BEQ库
    // åˆå§‹åŒ–Rx库
    RX_Init();
    HSMS_Initialize();
    CServoDlg dlg;
@@ -125,6 +126,7 @@
int CServoApp::ExitInstance()
{
    m_model.term();
    HSMS_Term();
    RX_Term();
    return CWinApp::ExitInstance();
SourceCode/Bond/Servo/Servo.rc
Binary files differ
SourceCode/Bond/Servo/Servo.vcxproj
@@ -193,6 +193,9 @@
    <ClInclude Include="BlButton.h" />
    <ClInclude Include="Common.h" />
    <ClInclude Include="Configuration.h" />
    <ClInclude Include="Context.h" />
    <ClInclude Include="HsmsAction.h" />
    <ClInclude Include="HsmsPassive.h" />
    <ClInclude Include="Log.h" />
    <ClInclude Include="LogDlg.h" />
    <ClInclude Include="LogEdit.h" />
@@ -207,6 +210,9 @@
  <ItemGroup>
    <ClCompile Include="BlButton.cpp" />
    <ClCompile Include="Configuration.cpp" />
    <ClCompile Include="Context.cpp" />
    <ClCompile Include="HsmsAction.cpp" />
    <ClCompile Include="HsmsPassive.cpp" />
    <ClCompile Include="Log.cpp" />
    <ClCompile Include="LogDlg.cpp" />
    <ClCompile Include="LogEdit.cpp" />
SourceCode/Bond/Servo/Servo.vcxproj.filters
@@ -57,6 +57,15 @@
    <ClInclude Include="Log.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="HsmsPassive.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="HsmsAction.h">
      <Filter>头文件</Filter>
    </ClInclude>
    <ClInclude Include="Context.h">
      <Filter>头文件</Filter>
    </ClInclude>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="Servo.cpp">
@@ -89,6 +98,15 @@
    <ClCompile Include="Log.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="HsmsPassive.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="HsmsAction.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
    <ClCompile Include="Context.cpp">
      <Filter>源文件</Filter>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="Servo.rc">
SourceCode/Bond/Servo/stdafx.h
@@ -36,7 +36,7 @@
#include "..\RxWindows1.0\include\RxWindowsLib.h"
#include "..\HSMSSDK\Include\HSMSSDK.h"