#pragma once #include #include #include #include #include class CDevice; enum class DAOCHA_POSITION { MP_UNKNOWN = 0, MP_FIX, MP_INVERT, MP_QUARTO, }; struct ST_MOMP_INFO { uint8_t check = 0xaa; uint8_t binstall_1 = 0; uint8_t binstall_2 = 0; uint8_t binstall_3 = 0; string name1; string name1utf; string name2; string name2utf; string name3; string name3utf; string out_name; string in_name; string imei; uint8_t idx = -1; CDevice *pDeivce = nullptr; uint32_t zzjno = 0; string mo; string mp; string name; //名称 int detectToday0 = 3000;//当定位保持力参考值 time_t detectTodayTime0 = 0; int detectToday1 = 3000;//当反位保持力参考值 time_t detectTodayTime1 = 0; public: //临时状态 bool bFirstOnline = true; public: //牵引点中间内存缓存数据 //定位常态保持力值 int fix_const_retension_force = INT_MIN; //反位常态保持力值 int invert_const_retension_force = INT_MIN; //道岔位置 //DAOCHA_POSITION epos = DAOCHA_POSITION::MP_UNKNOWN; std::map mapPos; int m_nPowerZeroOffset = 0; //阻力零值补偿 ~ST_MOMP_INFO(){ check = 0x00; } }; class CMonitorObject { public: CMonitorObject(); virtual ~CMonitorObject(); public: std::string id; std::string name; std::string type; std::string up; std::list m_lstMo; //type = mo.mp 时 生效 设备(转辙机编号) uint16_t eqpno = 0; //牵引点以上节点没有no。牵引点有自身no, 牵引点再往下一层为采集类型码AcqTypeCode CMonitorObject* parent = nullptr; uint8_t check = 0xaa; }; class CMonitorObjectMng { CMonitorObjectMng(); virtual ~CMonitorObjectMng(); public: static CMonitorObjectMng* Instance() { return &obj; }; friend class CResistAlarmMng; BOOL LoadMonitorTree(); BOOL LoadHistoryData(); //转换IMEI和idx 转换成 mo mp bool IMEI2MOMP(const std::string imei, const int idx, std::string& mo, std::string& mp); bool IMEI2MOMP(const std::string& imei_idx, std::string& mo_mp); bool MOMP2IMEI(const std::string& mo, const std::string& mp, std::string& imei, int& idx); bool MOMP2IMEI(const std::string& momp, std::string& imeiidx); bool MOMP2IMEI(const std::string& momp, std::string& imei, int& idx); //获取战场站点名 bool GetStationNameByMomP(const std::string& momp, std::string& station, std::string& momp_name); bool GetStationNameByMomP(const std::string& mo, const std::string& mp, std::string& station, std::string& momp_name); //获取测力曲线名称 bool GetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3); bool GetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3, std::string& out_name, std::string& in_name); //设置测力曲线名称 void SetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3); //获取转换阻力方向名称 bool GetDirectByMoMp(const std::string& momp, std::string& out_name, std::string& in_name); //设置转换阻力方向名称 void SetDirectByMoMp(const std::string& momp, std::string& out_name, std::string& in_name); static bool spiltByPoint(const std::string&src, std::string& dst1, std::string& dst2); std::string concatStringByPoint(const std::string& src1, const std::string& src2); //通过ID来获取树节点 CMonitorObject* GetTreeByID(const string& id); CMonitorObject* GetTreeByEpqID(uint16_t id); //根据momp来获取道岔对象 //获取所有Type对象 bool GetAllObjByType(std::vector& vctObj, const string& type); //序列化 uint32_t GeneralMoPack(uint8_t** pack, int* len); void GeneralMoPack(CMonitorObject* pObject, yyjson_mut_doc* doc, yyjson_mut_val* val); uint32_t GeneralMpPack(uint8_t** pack, int* len); //const std::map>* GetMoMpName()const { return &m_mapMoMpName; } const std::map* GetImeiIdxMoMp()const { return &m_mapImeiIdxMoMp; } inline auto GetZZJNO(const string& momp) { return m_mapMoMpInfo[momp]->zzjno; } inline auto GetZZJEPOS(const string& momp) { auto& epos = m_mapMoMpInfo[momp]; if (epos->mapPos.empty()) { return DAOCHA_POSITION::MP_UNKNOWN; } return epos->mapPos.rbegin()->second; } //删除ZZJ历史记录,保留最新的一个 void ClearZZJHistroyEPOS(time_t t); //判断ZZJ状态是否发生变化 bool IsZZJEPOSChanged(const string& momp, DAOCHA_POSITION ePos, time_t t) const { auto epos = m_mapMoMpInfo.find(momp); if (epos == m_mapMoMpInfo.end() || epos->second->mapPos.empty()) { return false; } if (epos->second->mapPos.size() == 1) { return epos->second->mapPos.begin()->second != ePos; } for (auto it = epos->second->mapPos.begin(); it != epos->second->mapPos.end(); it++) { if (it->first <= t) continue; if (it->second != ePos) { return true; } } return false; } void UpdateZZJEPOS(const string& momp, DAOCHA_POSITION epos); inline auto GetMoMpInfo(const string& momp) { return m_mapMoMpInfo[momp]; } inline ST_MOMP_INFO* GetMoMpInfoByZZJno(const int zzjno) { for (auto& it : m_mapMoMpInfo) { if (it.second->zzjno == zzjno) return it.second; } return nullptr; } private: static CMonitorObject* GetTreeByID(CMonitorObject* p, const string& id); static CMonitorObject* GetTreeByEpqID(CMonitorObject* p, uint16_t id); static void GetAllObjByType(CMonitorObject* p, std::vector& vctObj, const string& type); BOOL LoadMoMap(); void GetChild(std::list& lst, CMonitorObject* parent); bool GetStationNameByMomP(CMonitorObject* pInfo, const std::string& momp, std::string& station, std::string& momp_name); void Clear(); CMonitorObject* m_treeroot = nullptr;//整棵树 std::map m_mapImeiIdxMoMp;//设备号对应momp std::map m_mapMoMpImeiIdx; std::map m_mapMoMpInfo;//mo, mp 对应信息 private: static CMonitorObjectMng obj; };