1
0
Selaa lähdekoodia

prepare to combine person and car

zhuyf 2 vuotta sitten
vanhempi
commit
35e0d7912e
5 muutettua tiedostoa jossa 107 lisäystä ja 20 poistoa
  1. 41 10
      card_base.cpp
  2. 1 0
      card_base.h
  3. 2 0
      card_car.cpp
  4. 59 3
      module_service/module_traffic_light_manager.h
  5. 4 7
      net-service.cpp

+ 41 - 10
card_base.cpp

@@ -50,7 +50,7 @@ card_location_base::card_location_base(const std::string&type,uint32_t id,uint16
 void card_location_base::do_status(int st)
 {
 	time_t now = time(0);
-	bool   help_flag = false;
+	//bool   help_flag = false;
 
 	log_info("[help-battery] card_id=%d, help_bit=%d, status=%d", m_id, m_help_bit, st);
 	// 呼救
@@ -74,7 +74,7 @@ void card_location_base::do_status(int st)
 		if((m_help_bit&0x3)==2)
 		{
 			//log_warn("[help-battery] handle_m_help, card_id=%d",m_id);
-			help_flag=true;
+			//help_flag=true;
 		}
 
 		m_help_last_time = now;
@@ -137,6 +137,22 @@ void card_location_base::make_his_location(uint64_t t,const point & pt,bool bclo
 //坐标点输入业务入口
 void card_location_base::on_location(const std::vector<point>&vp, const std::vector<loc_message> &lm, bool is_v_map)
 {
+	m_isVehicleMap = false;
+	if (is_vehicle())
+	{
+		if (!is_v_map)
+		{
+			return;
+		}
+	}
+	if (is_person())
+	{
+		if (is_v_map)
+		{
+			m_isVehicleMap = true;
+		}
+	}
+
     loc_point pt = m_sel_tool->select_solution(vp, lm);
     //pt.y = pt.y;
     
@@ -146,17 +162,32 @@ void card_location_base::on_location(const std::vector<point>&vp, const std::vec
         sid = site_ptr->m_id;
 	if(pt.m_useless)
 	{
-		if (!is_v_map)
+		if (is_person())
 		{
-			x = tool_other::round(pt.x, 3);
-			y = tool_other::round(pt.y, 3);
+			if (!is_v_map)
+			{
+				x = tool_other::round(pt.x, 3);
+				y = tool_other::round(pt.y, 3);
+			}
+			else
+			{
+				m_v_point.x = tool_other::round(pt.x, 3);
+				m_v_point.y = tool_other::round(pt.y, 3);
+				log_info("useful loc m_v_point: type=%d, card=%d, site=%d, ct=%d, timestamp=%llu, x=%f, y=%f, speed=%.2f, acc=%.2f", m_type, m_id, sid, m_ct, m_time, m_v_point.x, m_v_point.y, m_speed, lm[0].m_acc);
+				return;
+			}
 		}
-		else
+		else if (is_vehicle())
 		{
-			m_v_point.x = tool_other::round(pt.x, 3);
-			m_v_point.y = tool_other::round(pt.y, 3);
-			log_info("useful loc m_v_point: type=%d, card=%d, site=%d, ct=%d, timestamp=%llu, x=%f, y=%f, speed=%.2f, acc=%.2f", m_type, m_id, sid, m_ct, m_time, m_v_point.x, m_v_point.y, m_speed, lm[0].m_acc);
-			return;
+			if (is_v_map)
+			{
+				x = tool_other::round(pt.x, 3);
+				y = tool_other::round(pt.y, 3);
+			}
+			else
+			{
+				return;
+			}
 		}
 
 		double acc = lm[0].m_acc;

+ 1 - 0
card_base.h

@@ -71,6 +71,7 @@ struct card:point
     double   m_acc;
 	double   m_speed;			//速度
 	point	m_v_point;			//车辆定位系统的定位结果
+	bool m_isVehicleMap = false;
 };
 
 struct card_location_base:card,std::enable_shared_from_this<card_location_base>

+ 2 - 0
card_car.cpp

@@ -64,6 +64,8 @@ void car::handle_anti_coll(const point& pt, const int& sid)
     std::map<int, call_card> cards;
     auto tmp_cards = card_list::instance()->m_map; 
 
+	log_info("[anti_coll] card'size = %d", tmp_cards.size());
+
     double min_d = 9999999.9;
     double cur_v = 0.0;
     for(auto k : CYaSetting::m_sys_setting.mp_anti_collision){

+ 59 - 3
module_service/module_traffic_light_manager.h

@@ -187,14 +187,19 @@ struct traffic_light_manager{
         return it->second.size();
     }
 
-    bool send_light_data(const int& light_id, const int& type, const int& shape){
+    bool send_light_data(const int& light_id, const int& dev_type, const int& shape, const int cmd_type = 0){
         std::vector<char> msg;
 
         uint16_t cmd = THIRD_PARTY_CHAR_LIGHT_SETUP_STATE;
+		if(1 == cmd_type){
+			cmd = THIRD_PARTY_CHAR_LIGHT_REQ_STATE;
+		}
+
         tool_other::memcpy_int<uint16_t>(msg, cmd);
         tool_other::memcpy_int<uint32_t>(msg, light_id);
 
-        msg.push_back(0x05);
+		// 设备类型
+        msg.push_back(dev_type);
 
         msg.push_back(static_cast<char>(shape));
 
@@ -222,7 +227,58 @@ struct traffic_light_manager{
         return true;
     }
 
-    void output_message(std::vector<char>&& msg, int light_id)
+	/*
+	 * @brief 采集收到红绿灯心跳数据,将心跳数据发送给红绿灯设备
+	 *
+	 * @param
+	 *		const char* data		发送给红绿灯设备的心跳数据
+	 *		const int len			心跳数据长度
+	 *		const int light_id		红绿灯灯号
+	 *
+	 * @return
+	 *		false	发送失败
+	 *		true	发送成功
+	 * @note
+	 * @warning
+	 * @bug
+	 * */
+	bool send_heart_data(const char* data, const int len, const int light_id)
+	{
+		auto light_ptr = get(light_id);
+
+		if(light_ptr == nullptr){
+			log_error("[light_info] 未找到%d红绿灯", light_id);
+			return false;
+		}
+
+		std::vector<char> m;
+		for(int i = 0;i < len; i++){
+			m.push_back(data[i]);
+		}
+		//m.insert(m.begin(), std::begin(data), std::end(data));
+
+		if(light_ptr->m_clt){
+			std::vector<char> md = m;
+			output_message(std::move(md), light_id);
+			light_ptr->m_clt->send(std::move(m));
+		}
+
+		return true;
+	}
+
+    /*
+	 * @brief
+	 *		输出红绿灯的16进制数据
+	 * @param
+	 *		std::vector<char>&& msg		红绿灯数据
+	 *		int light_id				灯号
+	 * @return
+	 *		无
+	 * @note
+	 * @warning
+	 * @bug
+	 * */
+	void output_message(std::vector<char>&& msg, int light_id)
     {
         std::string s("红绿灯控制的数据帧,灯号=");
         s.append(std::to_string(light_id));

+ 4 - 7
net-service.cpp

@@ -354,9 +354,9 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
                     if(light_ptr)
                     {
                         //traffic_light_manager::instance()->send_light_ctrl(id, DT_LIGHT, light_ptr->m_state); 
-                        traffic_light_manager::instance()->send_light_data(id, DT_LIGHT, light_shape::green_all_on);
+                        traffic_light_manager::instance()->send_light_data(id, DT_LIGHT, light_shape::green_all_on, 1);
                     }else{
-                        traffic_light_manager::instance()->send_light_data(id, DT_LIGHT, light_shape::green_spark);
+                        traffic_light_manager::instance()->send_light_data(id, DT_LIGHT, light_shape::green_spark, 1);
                     }	
                 }
                 break;
@@ -385,12 +385,9 @@ void net_service::on_message(const std::shared_ptr<client> &clt,const char*data,
                     light_ptr->m_state = status;
                     light_ptr->m_rec_time = time(0);
 					
+					// 采集给红绿灯设备发送心跳指令
+					traffic_light_manager::instance()->send_heart_data(data, len, id);
 					module_device_net::instance()->do_business(clt->name(), light_ptr->m_light_id, light_ptr->m_device_type_id);
-
-                    /*if((stamp%10) == 0){
-                        int shape = (status == light_shape::red_spark)?light_shape::green_spark:light_shape::red_spark;
-                        traffic_light_manager::instance()->send_light_ctrl(id, 0x05, shape);
-                    }*/
                 }
                 break;
 			default: