Kaynağa Gözat

20230113, huli

huli 2 yıl önce
ebeveyn
işleme
2e523b0cd3

+ 54 - 0
plc调度节点/dispatch/dispatch_command.cpp

@@ -416,6 +416,60 @@ Error_manager Dispatch_command::check_park_is_start(int import_id)
 	return Error_code::SUCCESS;
 }
 
+//获取指定入口的 存车流程的 唯一码,
+Error_manager Dispatch_command::get_primary_key_for_store(int import_id, std::string & primary_key )
+{
+	std::unique_lock<std::mutex> t_lock(m_lock);
+	//检查指令队列, 查询指定单元的取车完成状态指令的 出口id是否存在
+	char check_export_id_sql[1024];
+	memset(check_export_id_sql, 0, 1024);
+	sprintf(check_export_id_sql,"select * from command_queue where type = 1 and import_id = %d and (statu=0 or statu =1)",import_id);
+	boost::shared_ptr<sql::ResultSet>  tp_result = nullptr;
+	Error_manager t_error = Database_controller::get_instance_pointer()->sql_query(check_export_id_sql, tp_result);
+
+	if(t_error == Error_code::SUCCESS)
+	{
+		if (tp_result == nullptr)
+		{
+			return DB_RESULT_SET_EMPTY;
+		}
+
+		//如果存在, 就报错,   不存在就是空闲,返回成功
+		if ( tp_result->next() )
+		{
+			char buf[1024];
+			memset(buf, 0, 1024);
+			try
+			{
+				//解析数据
+				primary_key = tp_result->getString("primary_key");
+			}
+			catch (sql::SQLException &e)
+			{
+				/* Use what() (derived from std::runtime_error) to fetch the error message */
+				sprintf(buf, "# ERR: %s\n (MySQL error code: %d, SQLState: %s", e.what(), e.getErrorCode(), e.getSQLState().c_str());
+				return Error_manager(DB_RESULT_SET_PARSE_ERROR, NEGLIGIBLE_ERROR, buf);
+			}
+			catch (std::runtime_error &e)
+			{
+				sprintf(buf, "# ERR: %s\n ERR: runtime_error in  %s ", e.what(), __FILE__);
+				return Error_manager(DB_RESULT_SET_PARSE_ERROR, NEGLIGIBLE_ERROR, buf);
+			}
+			return Error_code::SUCCESS;
+		}
+		else
+		{
+			return Error_manager(Error_code::DB_QUERY_OUTLET_OCCUPY, Error_level::MINOR_ERROR,
+								 " check_export_id_is_ready fun error, 数据库 查询出口被占用 ");
+		}
+	}
+	else
+	{
+		return t_error;
+	}
+	return Error_code::SUCCESS;
+}
+
 //删除 指令队列, 根据出口编号
 Error_manager Dispatch_command::delete_command_queue_for_export_id(int export_id)
 {

+ 2 - 0
plc调度节点/dispatch/dispatch_command.h

@@ -100,6 +100,8 @@ public://API functions
 	Error_manager check_pickup_is_finish(int export_id);
 	//检查入口存车是否开始, 指定的入口有存车开始指令就返回成功, 否则报错.
 	Error_manager check_park_is_start(int import_id);
+	//获取指定入口的 存车流程的 唯一码,
+	Error_manager get_primary_key_for_store(int import_id, std::string & primary_key );
 
 	//删除 指令队列, 根据出口编号
 	Error_manager delete_command_queue_for_export_id(int export_id);

+ 2 - 0
plc调度节点/dispatch/dispatch_communication.cpp

@@ -287,6 +287,8 @@ Error_manager Dispatch_communication::communication_init(int plc_id)
 	t_index += sizeof(unsigned char)*1;
 	t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_data_validity", typeid(unsigned char).name(), t_index,sizeof(unsigned char), 1 });
 	t_index += sizeof(unsigned char)*1;
+	t_variable_information_vector.push_back(Snap7_buf::Variable_information{"m_response_data_validity", typeid(int).name(), t_index,sizeof(int), 1 });
+	t_index += sizeof(int)*1;
 
 
 

+ 3 - 1
plc调度节点/dispatch/dispatch_communication.h

@@ -482,13 +482,15 @@ public:
 		float					m_response_uniformed_car_y = 0;					//转角复位后,车辆中心点y
 		unsigned char			m_response_locate_correct = 0;				//数据是否有效, 0=无效, 1=有效
 
-		unsigned char			m_response_ground_status = 0;				//数据是否有效, 0=无效, 1=有效
+		unsigned char			m_response_ground_status = 0;				////0  ok 1,nothing 2,noise  3,border
 		unsigned char			m_reserved46_47[2] = {0};							//预留
 
 		unsigned char			m_response_heartbeat = 0;							//心跳位, 0-255循环
 		unsigned char			m_response_communication_mode = 0;					//通信模式	0 = 未知, 1=自动循环模式,2=手动刷新模式
 		unsigned char			m_response_refresh_command = 0;						//刷新指令 0-255任意数字,与上一次不同即可
 		unsigned char			m_response_data_validity = 0;						//数据有效性, 0 = 未知, 1 = 有效, 2 = 无效
+
+		int 					m_response_border_status = 0;						//超界状态描述, 按位运算
 	};
 
 	//plc给地面雷达

+ 27 - 8
plc调度节点/dispatch/dispatch_ground_lidar.cpp

@@ -64,7 +64,6 @@ Error_manager Dispatch_ground_lidar::dispatch_ground_lidar_uninit()
 //	return Error_code::SUCCESS;
 //}
 
-
 //调度地面雷达 执行状态消息
 Error_manager Dispatch_ground_lidar::execute_for_ground_status_msg_new(measure_info &t_measure_info)
 {
@@ -72,25 +71,25 @@ Error_manager Dispatch_ground_lidar::execute_for_ground_status_msg_new(measure_i
 	m_measure_info = t_measure_info;
 	m_ground_status_msg_updata_time = std::chrono::system_clock::now();
 	m_ground_status_msg_updata_flag = true;
+
 	//胡力 新增 接受雷达雷达 通信周期 超过1秒就打印
 	int time_key = 10+m_ground_lidar_id;
 	Time_tool::get_instance_references().time_end(time_key);
 	if ( Time_tool::get_instance_references().timetool_map.find(time_key)!=Time_tool::get_instance_references().timetool_map.end() )
 	{
-		if ( Time_tool::get_instance_references().timetool_map[time_key].t_time_difference >= std::chrono::milliseconds(1000) )
-		{
+	    if ( Time_tool::get_instance_references().timetool_map[time_key].t_time_difference >= std::chrono::milliseconds(1000) )
+	    {
 			Time_tool::get_instance_references().cout_time_millisecond(time_key);
-            double dieoutTime=(double)Time_tool::get_instance_references().timetool_map[time_key].t_time_difference.count()/1000000;
-//            std::cout << "计时器:"<<key<<" 计时的时间为:" <<dieoutTime<<" 毫秒" << std::endl;
-            LOG(INFO) << "计时器:"<<time_key<<" 计时的时间为:" <<dieoutTime<<" 毫秒" << " --- " << this;
-		}
+			double dieoutTime=(double)Time_tool::get_instance_references().timetool_map[time_key].t_time_difference.count()/1000000;
+			LOG(INFO) << "计时器:"<<time_key<<" 计时的时间为:" <<dieoutTime<<" 毫秒" << " --- " << this;
+	    }
 	}
 	Time_tool::get_instance_references().time_start(time_key);
 	//胡力 新增 接受雷达雷达 通信周期 超过1秒就打印
+
 	return Error_code::SUCCESS;
 }
 
-
 Dispatch_ground_lidar::Dispatch_ground_lidar_status Dispatch_ground_lidar::get_dispatch_ground_lidar_status()
 {
 	return m_dispatch_ground_lidar_status;
@@ -122,6 +121,9 @@ void Dispatch_ground_lidar::execute_thread_fun()
 				std::unique_lock<std::mutex> t_lock(Dispatch_communication::get_instance_references().m_data_lock);
 				std::unique_lock<std::mutex> t_lock2(m_lock);
 
+				check_measure_info(m_measure_info);
+
+
 				//将nnxx的protobuf 转化为 snap7的DB块,  把店面雷达数据转发给plc
 //				int t_inlet_id = m_ground_status_msg.mutable_id_struct()->terminal_id() % 2;
 				int t_inlet_id = m_ground_lidar_id;
@@ -166,6 +168,7 @@ void Dispatch_ground_lidar::execute_thread_fun()
 
 						p_response_data->m_response_locate_correct = 1;	//locate_correct  0=无效, 1=有效,
 						p_response_data->m_response_ground_status = m_measure_info.ground_status();	//0  ok 1,nothing 2,noise  3,border
+						p_response_data->m_response_border_status = m_measure_info.border_statu();	//超界状态描述, 按位运算
 
 					}
 					else
@@ -184,6 +187,8 @@ void Dispatch_ground_lidar::execute_thread_fun()
 
                         p_response_data->m_response_locate_correct = 0;
 						p_response_data->m_response_ground_status = m_measure_info.ground_status();	//0  ok 1,nothing 2,noise  3,border
+						p_response_data->m_response_border_status = m_measure_info.border_statu();	//超界状态描述, 按位运算
+
 					}
 
 //                    LOG(WARNING) << "------------------------------------------------------------ "<<std::endl;
@@ -237,6 +242,8 @@ void Dispatch_ground_lidar::execute_thread_fun()
 
                         p_response_data->m_response_locate_correct = 1;	//locate_correct  0=无效, 1=有效,
 						p_response_data->m_response_ground_status = m_measure_info.ground_status();	//0  ok 1,nothing 2,noise  3,border
+						p_response_data->m_response_border_status = m_measure_info.border_statu();	//超界状态描述, 按位运算
+
 					}
                     else
                     {
@@ -254,6 +261,8 @@ void Dispatch_ground_lidar::execute_thread_fun()
 
                         p_response_data->m_response_locate_correct = 0;
 						p_response_data->m_response_ground_status = m_measure_info.ground_status();	//0  ok 1,nothing 2,noise  3,border
+						p_response_data->m_response_border_status = m_measure_info.border_statu();	//超界状态描述, 按位运算
+
 					}
 				}
 
@@ -278,7 +287,17 @@ void Dispatch_ground_lidar::execute_thread_fun()
 	}
 }
 
+//检查感测消息
+Error_manager Dispatch_ground_lidar::check_measure_info(measure_info &t_measure_info)
+{
+	if ( t_measure_info.theta() > 10 ||
+	t_measure_info.theta() < -10)
+	{
+	    LOG(INFO) << " 地面雷达数据异常, t_measure_info =  " << t_measure_info.DebugString().c_str()  << " --- " ;
+	}
 
+	return Error_code::SUCCESS;
+}
 
 
 

+ 64 - 32
plc调度节点/dispatch/dispatch_singlechip.cpp

@@ -43,6 +43,8 @@ Error_manager Dispatch_singlechip::dispatch_singlechip_init(int plc_id, int sing
 
 	m_dispatch_singlechip_status = DISPATCH_SINGLECHIP_READY;
 
+	m_close_outsidedoor_flag = false;
+
 	return Error_code::SUCCESS;
 }
 //调度单片机 反初始化
@@ -260,52 +262,82 @@ void Dispatch_singlechip::execute_thread_fun()
 }
 
 //入口外门控制函数
-void Dispatch_singlechip::inlet_outsidedoor_control()
+Error_manager Dispatch_singlechip::inlet_outsidedoor_control()
 {
 //	return;
+	Error_manager t_error;
+
 	if ( m_dispatch_singlechip_status == DISPATCH_SINGLECHIP_READY )
 	{
 		int t_terminal_id = m_plc_id*2 + m_singlechip_id;
 		int t_singlechip_index = (m_singlechip_direction-1)*2 + m_singlechip_id;
 
-//		int t_outsidedoor_control = Dispatch_communication::get_instance_references().m_singlechip_request_from_plc_to_manager[t_singlechip_index].m_request_outsidedoor_control;
-
-//		std::cout << " huli test :::: " << " +++++++++++++++++++++++++++++++++ = " << 1 << std::endl;
-//		std::cout << " huli test :::: " << " get_inside_existence_flag() = " << get_inside_existence_flag() << std::endl;
-//		std::cout << " huli test :::: " << " t_outsidedoor_control = " << t_outsidedoor_control << std::endl;
-//		std::cout << " huli test :::: " << " hhhhhhhh = " << Dispatch_communication::get_instance_references().m_singlechip_request_from_plc_to_manager[t_singlechip_index].m_request_heartbeat << std::endl;
-
-		//检查出口取车是否完成, 出口有取车完成指令就返回成功, 否则报错.
-		if ( Dispatch_manager::get_instance_references().m_dispatch_command.check_park_is_start(t_terminal_id+1) == Error_code::SUCCESS )
-		{
+		std::string t_primary_key_now = "";
+		t_error = Dispatch_manager::get_instance_references().m_dispatch_command.get_primary_key_for_store(t_terminal_id+1, t_primary_key_now);
+			if ( t_error != Error_code::SUCCESS )
+			{
+				return t_error;
+			}
+			else if(t_primary_key_now != "")
+			{
+				int t_plc_outsidedoor_control = Dispatch_communication::get_instance_references().m_singlechip_request_from_plc_to_manager[t_singlechip_index].m_request_outsidedoor_control;
 
-			int t_outsidedoor_control = Dispatch_communication::get_instance_references().m_singlechip_request_from_plc_to_manager[t_singlechip_index].m_request_outsidedoor_control;
-//
-//			std::cout << " huli test :::: " << " +++++++++++++++++++++++++++++++++ = " << 1 << std::endl;
-//			std::cout << " huli test :::: " << " get_inside_existence_flag() = " << get_inside_existence_flag() << std::endl;
-//			std::cout << " huli test :::: " << " t_outsidedoor_control = " << t_outsidedoor_control << std::endl;
+				if ( ( t_primary_key_now != m_primary_key_last && get_inside_existence_flag() == 1)
+				 || t_plc_outsidedoor_control == 0  )
+			    {
+					m_close_outsidedoor_flag = true;
+					m_primary_key_last = t_primary_key_now;
+			    }
 
-			//检测入口是否有车, //有车就开门, 检查门的状态, 并发送关门指令
-			if ( get_inside_existence_flag() == 1 || t_outsidedoor_control == 0  )
+			    if ( m_close_outsidedoor_flag == true )
+			    {
+					//有车就开门, 检查门的状态, 并发送关门指令
+					if ( get_outside_door_status() == message::Outside_door_status::OUTSIDE_DOOR_STATUS_OPEN ||
+						 get_outside_door_status() == message::Outside_door_status::OUTSIDE_DOOR_STATUS_RUN )
+					{
+
+						//发送关门指令
+						close_outside_door();
+					}
+					else if (get_outside_door_status() == message::Outside_door_status::OUTSIDE_DOOR_STATUS_CLOSE)
+					{
+						m_close_outsidedoor_flag = false;
+					}
+			    }
+			}
+			else
 			{
-				//有车就开门, 检查门的状态, 并发送关门指令
-				if ( get_outside_door_status() == message::Outside_door_status::OUTSIDE_DOOR_STATUS_OPEN ||
-					 get_outside_door_status() == message::Outside_door_status::OUTSIDE_DOOR_STATUS_RUN )
-				{
 
-					//发送关门指令
-					close_outside_door();
-				}
-				//else 等待汽车离开
+				return Error_code::SUCCESS; ;
 			}
-			//else  什么也不做
-		}
-		//else 什么也不做
+
+
+//		//检查出口取车是否完成, 出口有取车完成指令就返回成功, 否则报错.
+//		if ( Dispatch_manager::get_instance_references().m_dispatch_command.check_park_is_start(t_terminal_id+1) == Error_code::SUCCESS )
+//		{
+//			int t_outsidedoor_control = Dispatch_communication::get_instance_references().m_singlechip_request_from_plc_to_manager[t_singlechip_index].m_request_outsidedoor_control;
+//
+//			//检测入口是否有车, //有车就开门, 检查门的状态, 并发送关门指令
+//			if ( get_inside_existence_flag() == 1 || t_outsidedoor_control == 0  )
+//			{
+//				//有车就开门, 检查门的状态, 并发送关门指令
+//				if ( get_outside_door_status() == message::Outside_door_status::OUTSIDE_DOOR_STATUS_OPEN ||
+//					 get_outside_door_status() == message::Outside_door_status::OUTSIDE_DOOR_STATUS_RUN )
+//				{
+//
+//					//发送关门指令
+//					close_outside_door();
+//				}
+//				//else 等待汽车离开
+//			}
+//			//else  什么也不做
+//		}
+//		//else 什么也不做
 	}
-	return;
+	return Error_code::SUCCESS;
 }
 //出口外门控制函数
-void Dispatch_singlechip::outlet_outsidedoor_control()
+Error_manager Dispatch_singlechip::outlet_outsidedoor_control()
 {
 //	return;
 	if ( m_dispatch_singlechip_status == DISPATCH_SINGLECHIP_READY )
@@ -336,7 +368,7 @@ void Dispatch_singlechip::outlet_outsidedoor_control()
 	    }
 	    //else 什么也不做
 	}
-	return;
+	return Error_code::SUCCESS;;
 }
 
 //发送开门指令

+ 4 - 2
plc调度节点/dispatch/dispatch_singlechip.h

@@ -76,9 +76,9 @@ protected://member functions
 	//任务执行线程, 负责门控和数据库操作
 	void execute_thread_fun();
 	//入口外门控制函数
-	void inlet_outsidedoor_control();
+	Error_manager inlet_outsidedoor_control();
 	//出口外门控制函数
-	void outlet_outsidedoor_control();
+	Error_manager outlet_outsidedoor_control();
 
 	//发送开门指令
 	Error_manager open_outside_door();
@@ -115,6 +115,8 @@ protected://member variable
 	std::chrono::system_clock::time_point			m_singlechip_data_msg_updata_time;	//状态更新时间点
 	std::atomic<bool>								m_singlechip_data_msg_updata_flag;
 
+	std::string										m_primary_key_last;//入口存车流程的唯一码
+	bool 											m_close_outsidedoor_flag;//入口外门关闭标志位
 
 private: