Browse Source

使用mompinfo。

git-svn-id: https://202.107.226.68:8443/svn/Services/ResistanceMonitor@5 a05970a1-87b9-9d4f-9ee5-fa77e2ec115b
shenchunzhong 1 year ago
parent
commit
f61c022dbe
2 changed files with 166 additions and 94 deletions
  1. 120 75
      4.Data/MonitorObject.cpp
  2. 46 19
      4.Data/MonitorObject.h

+ 120 - 75
4.Data/MonitorObject.cpp

@@ -106,8 +106,8 @@ BOOL CMonitorObjectMng::LoadMoMap()
 		if (imei[0x00] != 0x00) simei << imei << '.' << idx;
 
 		string momp = smomp.str();
-		m_mapMoMpZZJNO[momp] = zzj_no;
-		m_mapMoMpZZJEPOS[momp] = (DAOCHA_POSITION)epos;
+		//m_mapMoMpZZJNO[momp] = zzj_no;
+		//m_mapMoMpZZJEPOS[momp][0] = (DAOCHA_POSITION)epos;
 		m_mapMoMpImeiIdx[momp] = simei.str();
 		if (imei[0x00] != 0x00)	m_mapImeiIdxMoMp[simei.str()] = smomp.str();
 
@@ -130,9 +130,11 @@ BOOL CMonitorObjectMng::LoadMoMap()
 			it->zzjno = zzj_no;
 			it->mo = mo;
 			it->mp = mp;
+			it->mapPos[time(0)] = (DAOCHA_POSITION)epos;;
 			if (!it->imei.empty())
 				it->pDeivce = CDeviceMng::Instance()->Insert(imei);
 		}
+		/*
 		{
 			auto& it = m_mapMoMpName[momp];
 			if (it.size() == 0)
@@ -188,9 +190,10 @@ BOOL CMonitorObjectMng::LoadMoMap()
 				it.push_back(direct2);
 			}
 		}
+		*/
 	}
 	
-	return m_mapMoMpImeiIdx.size() + 1;
+	return m_mapMoMpInfo.size() + 1;
 }
 
 void CMonitorObjectMng::GetChild(std::list<CMonitorObject*>& lst, CMonitorObject* parent)
@@ -219,7 +222,7 @@ void CMonitorObjectMng::GetChild(std::list<CMonitorObject*>& lst, CMonitorObject
 						pObject->type = "mo.mp";
 						pObject->up = parent->id;
 						pObject->parent = parent;
-						pObject->eqpno = m_mapMoMpZZJNO[pObject->id];
+						pObject->eqpno = m_mapMoMpInfo[pObject->id]->zzjno;
 						parent->m_lstMo.push_back(pObject);
 					}
 				}
@@ -420,45 +423,66 @@ bool CMonitorObjectMng::GetStationNameByMomP(const std::string& mo, const std::s
 
 bool CMonitorObjectMng::GetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3)
 {
-	auto& it = m_mapMoMpName.find(momp);
-	if (it == m_mapMoMpName.end()) return false;
-	if (it->second.size() < 3) return false;
-	name1 = it->second[0];
-	name2 = it->second[1];
-	name3 = it->second[2];
-	return true;
+	//auto& it = m_mapMoMpName.find(momp);
+	//if (it == m_mapMoMpName.end()) return false;
+	//if (it->second.size() < 3) return false;
+	//name1 = it->second[0];
+	//name2 = it->second[1];
+	//name3 = it->second[2];
+	//return true;
+
+	auto it = GetMoMpInfo(momp);
+	if (it)
+	{
+		name1 = it->name1;
+		name2 = it->name2;
+		name3 = it->name3;
+		return true;
+	}
+	return false;
 }
 
 bool CMonitorObjectMng::GetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3, std::string& out_name, std::string& in_name)
 {
-	auto& it = m_mapMoMpName.find(momp);
-	if (it == m_mapMoMpName.end()) return false;
-	if (it->second.size() < 5) return false;
-	name1 = it->second[0];
-	name2 = it->second[1];
-	name3 = it->second[2];
-	out_name = it->second[3];
-	in_name = it->second[4];
-	return true;
+	//auto& it = m_mapMoMpName.find(momp);
+	//if (it == m_mapMoMpName.end()) return false;
+	//if (it->second.size() < 5) return false;
+	//name1 = it->second[0];
+	//name2 = it->second[1];
+	//name3 = it->second[2];
+	//out_name = it->second[3];
+	//in_name = it->second[4];
+
+	auto it = GetMoMpInfo(momp);
+	if (it)
+	{
+		name1 = it->name1;
+		name2 = it->name2;
+		name3 = it->name3;
+		out_name = it->out_name;
+		in_name = it->in_name;
+		return true;
+	}
+	return false;
 }
 
 void CMonitorObjectMng::SetNameByMoMp(const std::string& momp, std::string& name1, std::string& name2, std::string& name3)
 {
-	auto& it = m_mapMoMpName.find(momp);
-	if (it == m_mapMoMpName.end())
-	{
-		std::vector<string> vct;
-		vct.push_back(name1);
-		vct.push_back(name2);
-		vct.push_back(name3);
-		m_mapMoMpName[momp] = vct;
-	}
-	else
-	{
-		it->second[0] = name1;
-		it->second[1] = name2;
-		it->second[2] = name3;
-	}
+	//auto& it = m_mapMoMpName.find(momp);
+	//if (it == m_mapMoMpName.end())
+	//{
+	//	std::vector<string> vct;
+	//	vct.push_back(name1);
+	//	vct.push_back(name2);
+	//	vct.push_back(name3);
+	//	m_mapMoMpName[momp] = vct;
+	//}
+	//else
+	//{
+	//	it->second[0] = name1;
+	//	it->second[1] = name2;
+	//	it->second[2] = name3;
+	//}
 
 	{
 		auto it = GetMoMpInfo(momp);
@@ -469,7 +493,7 @@ void CMonitorObjectMng::SetNameByMoMp(const std::string& momp, std::string& name
 			it->name3 = name3;
 			it->name1utf = ANSItoUTF8(name1);
 			it->name2utf = ANSItoUTF8(name2);
-			it->name3 = ANSItoUTF8(name3);
+			it->name3utf = ANSItoUTF8(name3);
 		}
 	}
 }
@@ -485,19 +509,19 @@ bool CMonitorObjectMng::GetDirectByMoMp(const std::string& momp, std::string& ou
 
 void CMonitorObjectMng::SetDirectByMoMp(const std::string& momp, std::string& direct1, std::string& direct2)
 {
-	auto& it = m_mapMoMpDirect.find(momp);
-	if (it == m_mapMoMpDirect.end())
-	{
-		std::vector<string> vct;
-		vct.push_back(direct1);
-		vct.push_back(direct2);
-		m_mapMoMpDirect[momp] = vct;
-	}
-	else
-	{
-		it->second[0] = direct1;
-		it->second[1] = direct2;
-	}
+	//auto& it = m_mapMoMpDirect.find(momp);
+	//if (it == m_mapMoMpDirect.end())
+	//{
+	//	std::vector<string> vct;
+	//	vct.push_back(direct1);
+	//	vct.push_back(direct2);
+	//	m_mapMoMpDirect[momp] = vct;
+	//}
+	//else
+	//{
+	//	it->second[0] = direct1;
+	//	it->second[1] = direct2;
+	//}
 
 	{
 		auto it = GetMoMpInfo(momp);
@@ -653,38 +677,36 @@ void CMonitorObjectMng::GeneralMoPack(CMonitorObject* pObject, yyjson_mut_doc* d
 
 uint32_t CMonitorObjectMng::GeneralMpPack(uint8_t** pack, int* len)
 {
-	if (m_mapMoMpName.size() == 0) return 0;
+	if (m_mapMoMpInfo.size() == 0) return 0;
 
 	auto doc = yyjson_mut_doc_new(nullptr);
 	auto root = yyjson_mut_arr(doc);
 	yyjson_mut_doc_set_root(doc, root);
 
-	for (const auto& it : m_mapMoMpName)
+	for (const auto& it : m_mapMoMpInfo)
 	{
 		auto ss = it.second;
-		if (ss.size() == 5)
-		{
-			auto obj = yyjson_mut_obj(doc);
-			yyjson_mut_arr_add_val(root, obj);
-
-			string mo, mp, momp = it.first;
-			spiltByPoint(momp, mo, mp);
-			string station, mompname;
-			CMonitorObjectMng::Instance()->GetStationNameByMomP(momp, station, mompname);
-			string mo_name, mp_name;
-			spiltByPoint(mompname, mo_name, mp_name);
-
-			yyjson_mut_obj_add_strcpy(doc, obj, "station", station.c_str());
-			yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", mo_name.c_str());
-			yyjson_mut_obj_add_strcpy(doc, obj, "mp_name", mp_name.c_str());
-			yyjson_mut_obj_add_strcpy(doc, obj, "mo", mo.c_str());
-			yyjson_mut_obj_add_strcpy(doc, obj, "mp", mp.c_str());
-			yyjson_mut_obj_add_strcpy(doc, obj, "name1", ss[0].c_str());
-			yyjson_mut_obj_add_strcpy(doc, obj, "name2", ss[1].c_str());
-			yyjson_mut_obj_add_strcpy(doc, obj, "name3", ss[2].c_str());
-			yyjson_mut_obj_add_strcpy(doc, obj, "direct1", ss[3].c_str());
-			yyjson_mut_obj_add_strcpy(doc, obj, "direct2", ss[4].c_str());
-		}
+
+		auto obj = yyjson_mut_obj(doc);
+		yyjson_mut_arr_add_val(root, obj);
+
+		string mo, mp, momp = it.first;
+		spiltByPoint(momp, mo, mp);
+		string station, mompname;
+		CMonitorObjectMng::Instance()->GetStationNameByMomP(momp, station, mompname);
+		string mo_name, mp_name;
+		spiltByPoint(mompname, mo_name, mp_name);
+
+		yyjson_mut_obj_add_strcpy(doc, obj, "station", station.c_str());
+		yyjson_mut_obj_add_strcpy(doc, obj, "mo_name", mo_name.c_str());
+		yyjson_mut_obj_add_strcpy(doc, obj, "mp_name", mp_name.c_str());
+		yyjson_mut_obj_add_strcpy(doc, obj, "mo", mo.c_str());
+		yyjson_mut_obj_add_strcpy(doc, obj, "mp", mp.c_str());
+		yyjson_mut_obj_add_strcpy(doc, obj, "name1", ss->name1.c_str());
+		yyjson_mut_obj_add_strcpy(doc, obj, "name2", ss->name2.c_str());
+		yyjson_mut_obj_add_strcpy(doc, obj, "name3", ss->name3.c_str());
+		yyjson_mut_obj_add_strcpy(doc, obj, "direct1", ss->out_name.c_str());
+		yyjson_mut_obj_add_strcpy(doc, obj, "direct2", ss->in_name.c_str());
 	}
 
 	size_t json_len;
@@ -708,7 +730,12 @@ void CMonitorObjectMng::UpdateZZJEPOS(const string& momp, DAOCHA_POSITION epos)
 	auto ret = CDBConnectPool::Instance()->DBExecuteSQL(sql);
 	if (ret)
 	{
-		m_mapMoMpZZJEPOS[momp] = epos;
+		auto lstEPOS = m_mapMoMpInfo[momp];
+		lstEPOS->mapPos[time(0)] = (DAOCHA_POSITION)epos;
+		if (lstEPOS->mapPos.size() > 10)
+		{
+			lstEPOS->mapPos.erase(lstEPOS->mapPos.begin());
+		}
 	}
 	else
 	{
@@ -716,4 +743,22 @@ void CMonitorObjectMng::UpdateZZJEPOS(const string& momp, DAOCHA_POSITION epos)
 	}
 }
 
+//删除ZZJ历史记录,保留最新的一个
+void CMonitorObjectMng::ClearZZJHistroyEPOS(time_t t)
+{
+	for (auto& item : m_mapMoMpInfo)
+	{
+		//auto& epos = m_mapMoMpZZJEPOS[momp];
+		auto& epos = item.second->mapPos;
+	
+		for (auto it = epos.begin(); it != (--epos.end());)
+		{
+			if (it->first <= t)
+				it = epos.erase(it);
+			else
+				it++;
+		}
+	}
+}
+
 CMonitorObjectMng CMonitorObjectMng::obj;

+ 46 - 19
4.Data/MonitorObject.h

@@ -7,6 +7,12 @@
 
 class CDevice;
 
+enum class DAOCHA_POSITION {
+	MP_UNKNOWN = 0,
+	MP_FIX,
+	MP_INVERT,
+};
+
 struct ST_MOMP_INFO
 {
 	uint8_t check = 0xaa;
@@ -32,9 +38,12 @@ struct ST_MOMP_INFO
 public:
 	//牵引点中间内存缓存数据
 	//定位常态保持力值
-	// int  fix_const_retension_force = INT_MIN;
+	int  fix_const_retension_force = INT_MIN;
 	//反位常态保持力值
-	//int  int  invert_const_retension_force = INT_MIN;
+	int  invert_const_retension_force = INT_MIN;
+	//道岔位置
+	//DAOCHA_POSITION epos = DAOCHA_POSITION::MP_UNKNOWN;
+	std::map<time_t, DAOCHA_POSITION> mapPos;
 
 	
 	~ST_MOMP_INFO(){
@@ -42,11 +51,6 @@ public:
 	}
 };
 
-enum class DAOCHA_POSITION {
-	MP_UNKNOWN = 0,
-	MP_FIX,
-	MP_INVERT,
-};
 
 class CMonitorObject
 {
@@ -126,14 +130,45 @@ public:
 	void GeneralMoPack(CMonitorObject* pObject, yyjson_mut_doc* doc, yyjson_mut_val* val);
 	uint32_t  GeneralMpPack(uint8_t** pack, int* len);
 
-	const std::map<std::string, std::vector<string>>* GetMoMpName()const { return &m_mapMoMpName; }
+	//const std::map<std::string, std::vector<string>>* GetMoMpName()const { return &m_mapMoMpName; }
 	const std::map<std::string, std::string>* GetImeiIdxMoMp()const { return &m_mapImeiIdxMoMp; }
 
 	inline auto GetZZJNO(const string& momp) {
-		return m_mapMoMpZZJNO[momp];
+		return m_mapMoMpInfo[momp]->zzjno;
 	}
-	inline auto GetZZJEPOS(const string& momp){
-		return m_mapMoMpZZJEPOS[momp];
+	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);
 
@@ -159,17 +194,9 @@ private:
 	CMonitorObject*	m_treeroot = nullptr;//整棵树
 
 	std::map<std::string, std::string> m_mapImeiIdxMoMp;//设备号对应momp
-
 	std::map<std::string, std::string> m_mapMoMpImeiIdx;
 
-	std::map<std::string, std::vector<string>> m_mapMoMpName;  //mo, mp 对应三个测力曲线的名称
 	std::map<std::string, ST_MOMP_INFO*> m_mapMoMpInfo;//mo, mp 对应信息
-	std::map<std::string, std::vector<string>> m_mapMoMpDirect;	//mo, mp 对应的两个阻力转换方向名称
-
-
-	std::map<std::string, int> m_mapMoMpZZJNO;  //mo, mp 对应的转辙机编号
-	std::map<std::string, DAOCHA_POSITION> m_mapMoMpZZJEPOS;  //mo, mp 对应的转辙机位置
-
 private:
 	static CMonitorObjectMng obj;