darker
2025-02-18 4289dfbba5033a08e9aea375f439e2ea7e0648da
Merge branch 'clh' into liuyang
已修改5个文件
52 ■■■■ 文件已修改
SourceCode/Bond/Servo/CEquipment.cpp 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CEquipment.h 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CMaster.cpp 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CMaster.h 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/Model.cpp 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SourceCode/Bond/Servo/CEquipment.cpp
@@ -7,8 +7,9 @@
    CEquipment::CEquipment() : m_nID(0), m_strName(""), m_strDescription(""), m_station(0, 255)
    {
        m_listener = { nullptr, nullptr };
        m_alive = {FALSE, 0, FALSE};
        m_listener.onAlive = {nullptr};
        m_bCimState = FALSE;
        InitializeCriticalSection(&m_criticalSection);
    }
@@ -20,6 +21,7 @@
    void CEquipment::setListener(EquipmentListener listener)
    {
        m_listener.onAlive = listener.onAlive;
        m_listener.onCimStateChanged = listener.onCimStateChanged;
    }
    void CEquipment::init()
@@ -131,7 +133,10 @@
        }
        // 解释数据
        // 以下解释和处理数据
        // alive
        /*
        BOOL bAliveFlag = isBitOn(pszData, size, 0x340);
        if (m_alive.flag != bAliveFlag) {
            m_alive.flag = bAliveFlag;
@@ -145,6 +150,15 @@
                }
            }
        }
        */
        // CIM State
        BOOL bCimState = isBitOn(pszData, size, 0x341);
        if ((bCimState && !m_bCimState) || (!bCimState && m_bCimState)) {
            m_bCimState = bCimState;
            if (m_listener.onCimStateChanged != nullptr) {
                m_listener.onCimStateChanged(this, m_bCimState);
            }
        }
    }
    BOOL CEquipment::isBitOn(const char* pszData, size_t size, int index)
SourceCode/Bond/Servo/CEquipment.h
@@ -10,6 +10,7 @@
    typedef struct _EquipmentListener
    {
        ONALIVE                onAlive;
        ONALIVE                onCimStateChanged;
    } EquipmentListener;
    // Memory Block 结构体定义
@@ -73,7 +74,10 @@
        StationIdentifier m_station;
        MemoryBlock m_blockReadBit;
        MemoryBlock m_blockWriteBit;
    private:
        ALIVE m_alive;
        BOOL m_bCimState;            // ON/OFF
    };
}
SourceCode/Bond/Servo/CMaster.cpp
@@ -12,7 +12,7 @@
    CMaster::CMaster()
    {
        m_listener = {nullptr};
        m_listener = {nullptr, nullptr};
    }
    CMaster::~CMaster()
@@ -26,6 +26,7 @@
    void CMaster::setListener(MasterListener listener)
    {
        m_listener.onEqAlive = listener.onEqAlive;
        m_listener.onEqCimStateChanged = listener.onEqCimStateChanged;
    }
    int CMaster::init()
@@ -106,12 +107,27 @@
                m_listener.onEqAlive(this, p, bAlive);
            }
        };
        listener.onCimStateChanged = [&](void* pEquipment, BOOL bOn) -> void {
            CEquipment* p = (CEquipment*)pEquipment;
            if (m_listener.onEqCimStateChanged != nullptr) {
                m_listener.onEqCimStateChanged(this, p, bOn);
            }
        };
        pEquipment->setListener(listener);
        m_listEquipment.push_back(pEquipment);
        return 0;
    }
    CEquipment* CMaster::getEquipment(int id)
    {
        for (auto item : m_listEquipment) {
            if (item->getID() == id) return item;
        }
        return nullptr;
    }
    void CMaster::onTimer(UINT nTimerid)
    {
        for (auto item : m_listEquipment) {
SourceCode/Bond/Servo/CMaster.h
@@ -11,6 +11,7 @@
    typedef struct _MasterListener
    {
        ONEQALIVE                onEqAlive;
        ONEQALIVE                onEqCimStateChanged;
    } MasterListener;
    class CMaster
@@ -25,11 +26,10 @@
        int init();
        int term();
        void onTimer(UINT nTimerid);
        CEquipment* getEquipment(int id);
    private:
        int addEquipment(CEquipment* pEquipment);
    private:
        MasterListener m_listener;
SourceCode/Bond/Servo/Model.cpp
@@ -91,9 +91,15 @@
    SERVO::MasterListener masterListener;
    masterListener.onEqAlive = [&](void* pMaster, SERVO::CEquipment* pEquipment, BOOL bAlive) -> void {
        LOGI("<CModel>Equipment onAlive:%d.\n", pEquipment->getName().c_str(),
        LOGI("<CModel>Equipment onAlive:%s(%s).\n", pEquipment->getName().c_str(),
            bAlive ? _T("ON") : _T("OFF"));
        notifyPtr(RX_CODE_EQ_ALIVE, pEquipment);
    };
    masterListener.onEqCimStateChanged = [&](void* pMaster, SERVO::CEquipment* pEquipment, BOOL bOn) -> void {
        LOGI("<CModel>Equipment Cim State:%s(%s).\n", pEquipment->getName().c_str(),
            bOn ? _T("ON") : _T("OFF"));
    };
    m_master.setListener(masterListener);