6 Commits 14216e7d46 ... 4bd71aeeea

Author SHA1 Message Date
  zengminguo 4bd71aeeea Merge branch 'xcjk' of zengminguo/server-l-zmg into xcjk 2 years ago
  zengminguo b9e17ed17f 支持最后下井时间记录 2 years ago
  zengminguo 4dd04206c2 Merge branch 'xcjk' of zengminguo/server-l-zmg into xcjk 2 years ago
  zengminguo 8f475eb8e0 超速告警中添加格子号和速度 2 years ago
  zengminguo 7f90025b37 Merge branch 'xcjk' of zengminguo/server-l-zmg into xcjk 2 years ago
  zengminguo fe23085953 采集支持超速阈值实时更新 2 years ago
12 changed files with 73 additions and 11 deletions
  1. 1 0
      .gitignore
  2. 17 3
      card_base.cpp
  3. 3 0
      card_base.h
  4. 9 5
      card_car.cpp
  5. 8 3
      event.cpp
  6. 4 0
      event.h
  7. 16 0
      his_location.cpp
  8. 1 0
      his_location.h
  9. 6 0
      module_service/module_web.cpp
  10. 1 0
      module_service/module_web.h
  11. 5 0
      websocket/jsonBuilder.cpp
  12. 2 0
      websocket/ws_common.h

+ 1 - 0
.gitignore

@@ -40,3 +40,4 @@ three_rates_module
 
 
 
+/3xls

+ 17 - 3
card_base.cpp

@@ -150,6 +150,11 @@ void card_location_base::make_his_location_cell_reader(uint64_t t, const loc_poi
 	m_his_location_card->insert_cell_reader(pt, t);
 }
 
+void card_location_base::make_his_vehicle_worktime(uint64_t t, uint32_t card_id)
+{
+	m_his_location_card->insert_vehicle_worktime(card_id, t);
+}
+
 float get_pdoa(const double poa[], const double& offset)
 {
 	if (poa == nullptr) {
@@ -505,9 +510,6 @@ void card_location_base::on_location(const std::vector<point>&vp, const std::vec
 			
 			pt.m_speed_change_rate = speed_diff;
 
-			
-
-			
 			log_info("[pdoa] card_location_base::on_location ,obj_id=%d, time=%s, reader_id=%d, ct=%d, poa1=%.4f, poa2=%.4f, poa3=%.4f, pdoa=%.4f, pdoa_offset=%.4f, speed=%f, avg_speed=%f, begin_pt.x=%f, begin_pt.y=%f, gesture=%d, dist_original=%f, dist=%f, angle=%f, acc=%.2f, rav=%d, cell_index=%d, cell_x=%f, cell_y=%f, site_cell_index=%d, cell_count=%d, moving_direct=%s, speed_diff=%f",
 				pt.m_cid,
 				tool_time::to_str_ex(lm[0].m_time_tmp).c_str(),
@@ -539,6 +541,7 @@ void card_location_base::on_location(const std::vector<point>&vp, const std::vec
 			m_speed = pt.m_speed;
 			m_stat = pt.m_stat;
 			m_cell_index_last = cell_index_current;
+			m_cell_index = cell_index_current;
 			m_avg_speed_last = speed_avg;
 			m_direction_last = pt.m_direction;
 			m_time_tmp_last = lm[0].m_time_tmp;
@@ -548,6 +551,16 @@ void card_location_base::on_location(const std::vector<point>&vp, const std::vec
 			//make_his_location_simplify(time(0) * 1000, pt);
 			make_his_location_cell_card(pt.m_time_tmp, pt);
 			make_his_location_cell_reader(pt.m_time_tmp, pt);
+			if (cell_index_current <= 30 && pt.m_direction == "-"&&m_rejudge_well_entry == true)
+			{
+				make_his_vehicle_worktime(pt.m_time_tmp, pt.m_cid);
+				m_rejudge_well_entry = false;
+			}
+			//已经入井了,可以重新记录入井时间
+			else if(cell_index_current > 30)
+			{
+				m_rejudge_well_entry = true;
+			}
 		}
 
 		//pt.m_speed *= 20;
@@ -765,6 +778,7 @@ void  card_location_base::clear()
     m_buff_size = 0;
     m_last_recv_time = 0;
     m_last_point = point(0,0);
+	m_cell_index = 0;
     m_last_site_id = 0;
     m_last_site_dir = -1;
     m_last_ct = 0;

+ 3 - 0
card_base.h

@@ -79,6 +79,7 @@ struct card:point
 	double	m_avg_speed_for_count = 0.0;
 	int			m_speed_count = 0;//累积速度数,最大10000
 	std::string	m_direction_last = "+";
+	bool	m_rejudge_well_entry = true; //重新判断入井
 	uint64_t m_time_tmp_last = 0;
 	int		 m_statusBeforeTurning = 0;
 	int		 m_biz_stat;
@@ -144,6 +145,7 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
     boost::circular_buffer<float> m_cb_tof;     // the list of tof that is pdoa history value
     boost::circular_buffer<point> m_cb_point;
     point m_last_point;
+	int m_cell_index;
 	int m_cur_site_counts = 0;				// 当前基站缓存数据总数
 	std::vector<float> m_vtp_dist;			// 相同分站存储距离数据
 	bool m_over_site = false;				// 过分站状态
@@ -181,6 +183,7 @@ struct card_location_base:card,std::enable_shared_from_this<card_location_base>
 	void make_his_location_simplify(uint64_t t, const loc_point & pt); //插入定位历史记录到数据库zengmg
 	void make_his_location_cell_card(uint64_t t, const loc_point & pt);
 	void make_his_location_cell_reader(uint64_t t, const loc_point & pt);
+	void make_his_vehicle_worktime(uint64_t t, uint32_t card_id);
 	void on_message(zloop<task*>* loop, message_locinfo&loc, bool is_history);
     void on_message(zloop<task*>* loop, message_tdoa_locinfo& loc, bool is_history);
     void on_message(zloop<task*>* loop, message_pdoa_locinfo& loc, bool is_history);

+ 9 - 5
card_car.cpp

@@ -94,22 +94,25 @@ void car::handle_over_speed()
 
 	bool status = true;
 	for(size_t i = 0;i < m_speeds.size();i++){
-		if(m_speed < 35){
+		if(m_speed < CYaSetting::m_sys_setting.over_speed){
 			status = false;
 		}
 	}
 
+	log_info("CYaSetting::m_sys_setting.over_speed=%.2f.", CYaSetting::m_sys_setting.over_speed);
+
 	uint64_t id = m_type;
 	id = ((id<<32) | m_id);
 	if(status){
 		// 产生告警
 		log_info("[v_over_speed] %d begin warning...", m_id);
-		event_tool::instance()->handle_event(OT_CARD, ET_CARD_OVER_SPEED, id, 0, 0, status);
+		//event_tool::instance()->handle_event(OT_CARD, ET_CARD_OVER_SPEED, id, 0, 0, status);
+		event_tool::instance()->handle_event(OT_CARD, ET_CARD_OVER_SPEED, id, m_cell_index, m_speed, status);
 	}
 
 	status = true;
 	for(size_t i = 20;i < m_speeds.size();i++){
-		if(m_speed>35){
+		if (m_speed > CYaSetting::m_sys_setting.over_speed) {
 			status = false;
 		}
 	}
@@ -182,7 +185,7 @@ void car::handle_anti_coll(const point& pt, const int& sid, int cell_index)
 			//float dist = pt.dist(c.second->m_v_point);
 			float dist = fabs(cell_index - c.second->m_v_cell_index);
 			// zmg
-			if (true)
+			if (false)
 			{
 				if (m_cid == 82)
 				{
@@ -340,7 +343,7 @@ void car::on_timer()
 	   }
    }
    //zmg
-   if (true)
+   if (false)
    {
 	   if (m_cid == 82)
 	   {
@@ -400,6 +403,7 @@ void car::make_package()
     
     cp.down_time = m_last_point.x;
     cp.z         = m_last_point.y;
+	cp.cell_index = m_cell_index;
 	
     upt_card_pos(cp, pt);
 

+ 8 - 3
event.cpp

@@ -87,6 +87,7 @@ event_tool * event_tool::instance()
  * */
 void event_tool::make_event_object()
 {
+	log_info("handle_alarm_event:make_event_object");
     m_map[OT_MORE_CARD] = std::make_shared<mine_event>();
     m_map[OT_AREA] = std::make_shared<area_event>();
     m_map[OT_DEVICE_READER] = std::make_shared<device_reader_event>();
@@ -180,7 +181,6 @@ void Event::handle_alarm_event(EVENT_TYPE et, uint64_t id, double limit_value, d
             ev_ptr=event_ptr;
         }
     }
-    
 	if(ev_ptr)
     {
         //event_list::save_event(ev_ptr);
@@ -190,6 +190,11 @@ void Event::handle_alarm_event(EVENT_TYPE et, uint64_t id, double limit_value, d
 			event_list::save_event_v(ev_ptr);
 		}else if(ev_ptr->m_ev_type == 8 || ev_ptr->m_ev_type == 21 || ev_ptr->m_ev_type == 41){
 			// 红绿灯失联、人车防碰撞、超速告警这三类保存到his_event_data_v表中
+			if (ev_ptr->m_ev_type == 21)
+			{
+				ev_ptr->m_cell_index = limit_value;
+				ev_ptr->m_speed = cur_value;
+			}
 			event_list::save_event_v(ev_ptr);
 		}else{
 			//其他的人员相关报警保存到his_event_data表中
@@ -355,8 +360,8 @@ void event_list::save_event_v(const std::shared_ptr<ya_event> &ev_ptr)
     std::string _time = tool_time::to_str_ex(ev_ptr->m_cur_time);
 	switch(ev_ptr->m_status){
 		case 0:
-			sprintf(sql, "INSERT IGNORE INTO his_event_data_v(id, event_type_id, obj_id, x, y ,start_time) VALUES(%ld, %d, '%s', %.2f, %.2f, '%s');",
-					ev_ptr->m_ev_id, ev_ptr->m_ev_type, ev_ptr->m_obj_id.c_str(), ev_ptr->x, ev_ptr->y, _time.c_str());
+			sprintf(sql, "INSERT IGNORE INTO his_event_data_v(id, event_type_id, obj_id, x, y ,start_time, speed, cell_index) VALUES(%ld, %d, '%s', %.2f, %.2f, '%s', %.2f, %d);",
+					ev_ptr->m_ev_id, ev_ptr->m_ev_type, ev_ptr->m_obj_id.c_str(), ev_ptr->x, ev_ptr->y, _time.c_str(), ev_ptr->m_speed, ev_ptr->m_cell_index);
 			break;
 		case 100:
 			sprintf(sql, "update his_event_data_v set end_time='%s' where id=%ld;", _time.c_str(), ev_ptr->m_ev_id);

+ 4 - 0
event.h

@@ -74,6 +74,10 @@ public:
     double m_cur_value;
     ///描述
     std::string m_desc;
+	//超速告警所在格子
+	int m_cell_index;
+	//超速告警的实际速度
+	double m_speed;
 
     //是否已经发送 ture bu发送, false推送. 推送完置为true
     bool m_is_sent;

+ 16 - 0
his_location.cpp

@@ -379,6 +379,22 @@ void location_card::insert_cell_reader(const loc_point &pt, uint64_t timestamp)
 	sDBConnPool.PushAsync(sql);
 }
 
+void location_card::insert_vehicle_worktime(uint32_t card_id, uint64_t timestamp)
+{
+	//按新表插入
+	char sql[1024] = { 0 };
+
+	std::string time = tool_time::to_str_ex(timestamp).c_str();
+
+	snprintf(sql, 1024, "replace into his_vehicle_worktime (card_id, work_Time) values(%d, '%s'); ",
+		card_id,
+		time.c_str());
+
+	log_info("[sql] %s", sql);
+
+	sDBConnPool.PushAsync(sql);
+}
+
 void location_card::update(const point &p,uint64_t timestamp,int flag/*=0*/,int dflag/*=0*/)
 {
     //std::string tabName=getTabName();

+ 1 - 0
his_location.h

@@ -63,6 +63,7 @@ struct location_card
 	void insert_simplify(const loc_point &pt, uint64_t timestamp);
 	void insert_cell_card(const loc_point &pt, uint64_t timestamp);
 	void insert_cell_reader(const loc_point &pt, uint64_t timestamp);
+	void insert_vehicle_worktime(uint32_t card_id, uint64_t timestamp);
 	void insert(uint64_t timestamp, const point & p, int32_t areaid, int32_t mapid, int32_t siteid, double scale);
 
 	void update(const point &p,uint64_t timestamp,int flag=0,int dflag=0);

+ 6 - 0
module_service/module_web.cpp

@@ -9,6 +9,8 @@
 #include "module_traffic_light_manager.h"
 #include "websocket/wsTimerThread.h"
 #include "load_raw.h"
+#include "sys_setting.h"
+#include <thread>
 
 static std::string s_file_path;
 // 只支持记录导入,不补报警等信息。
@@ -80,6 +82,10 @@ void module_web::accept( int ID, std::string const& name,
 			pthread_t  tid;
 			pthread_create(&tid, NULL, callback, NULL);    //callback 是一个回调函数
 		}
+		else if (JSON_KEY_NAME_SETTING == cmd) {
+			std::this_thread::sleep_for(std::chrono::milliseconds(300));
+			CYaSetting::Init_sys_setting();
+		}
 		else
 		{
 			sio::message::ptr data_value;

+ 1 - 0
module_service/module_web.h

@@ -50,6 +50,7 @@ public:
         MsgFuncList.insert( std::make_pair( JSON_CMD_REQ_ALL_PERSON_ON_CAR,&module_web::accept)); // 接收web端请求的在车上的人卡信息
         MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_LIGHTS_CTRL_REQUEST, &module_web::accept));  // 红绿灯控制指令
 		MsgFuncList.insert(std::make_pair(JSON_CMD_VALUE_LOAD_HISTORY_REQUEST, &module_web::accept));  // 导入历史文件指令
+		MsgFuncList.insert(std::make_pair(JSON_KEY_NAME_SETTING, &module_web::accept));  // 导入历史文件指令
     }
 
     /// web前端有用户登录时,反馈给web所有信息

+ 5 - 0
websocket/jsonBuilder.cpp

@@ -191,6 +191,11 @@ namespace sys
 		
 		DetailItem = Array_1;
 		Array.PushBack(DetailItem, Allocator );
+
+		//19 cell index
+		tmp_object.SetInt(CardPos.cell_index);
+		Array.PushBack(tmp_object, Allocator);
+
 		DetailItem = Array;
 		return true;
 	}

+ 2 - 0
websocket/ws_common.h

@@ -70,6 +70,7 @@ namespace sys
         double x;               //x坐标
         double y;               //y坐标
         double z;               //z坐标
+		int cell_index;
         double down_time;       //入井时间戳
         double enter_area_time; //进入区域时间戳
         double rec_time;        //最后接收时间戳
@@ -89,6 +90,7 @@ namespace sys
             x               = 0;
             y               = 0;
             z               = 0;
+			cell_index = 0;
             down_time       = 0;
             enter_area_time = 0;
             rec_time        = 0;