Sfoglia il codice sorgente

20211125, outlet singlechip communicaton

huli 3 anni fa
parent
commit
ad9a0c5d11

+ 52 - 8
dispatch/dispatch_plc.cpp

@@ -4,6 +4,7 @@
 
 #include "dispatch_plc.h"
 #include "../system/system_communication.h"
+#include "dispatch_manager.h"
 
 Dispatch_plc::Dispatch_plc()
 {
@@ -149,20 +150,60 @@ void Dispatch_plc::execute_thread_fun()
 					if ( std::chrono::system_clock::now() - m_start_time > std::chrono::milliseconds(m_timeout_ms) )
 					{
 						//超时直接报错
-						m_result =  Error_manager(Error_code::DISPATCH_PLC_TIME_OUT, Error_level::MINOR_ERROR,
-												  " DISPATCH_PLC_TIME_OUT fun error ");
+						m_result = Error_manager(Error_code::DISPATCH_PLC_TIME_OUT, Error_level::MINOR_ERROR,
+												 " DISPATCH_PLC_TIME_OUT fun error ");
 						m_dispatch_plc_status = DISPATCH_PLC_RESPONSE;
 					}
 					else
 					{
-						//封装 给plc的调度请求
-						m_result = encapsulate_dispatch_request_to_plc();
-						if ( m_result == Error_code::SUCCESS )
+						if ( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_STORE_CAR )
 						{
-							m_dispatch_plc_status = DISPATCH_PLC_WORKING;
+							//封装 给plc的调度请求
+							m_result = encapsulate_dispatch_request_to_plc();
+							if ( m_result == Error_code::SUCCESS )
+							{
+								m_dispatch_plc_status = DISPATCH_PLC_WORKING;
+							}
+							else
+							{
+								m_dispatch_plc_status = DISPATCH_PLC_RESPONSE;
+							}
+						}
+						else if( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_PICKUP_CAR )
+						{
+							//判断2个出口是否空闲
+							if ( Dispatch_manager::get_instance_references().m_dispatch_singlechip[2].is_outlet_ready() )
+							{
+								//封装 给plc的调度请求
+								m_result = encapsulate_dispatch_request_to_plc(0);
+								if ( m_result == Error_code::SUCCESS )
+								{
+									m_dispatch_plc_status = DISPATCH_PLC_WORKING;
+								}
+								else
+								{
+									m_dispatch_plc_status = DISPATCH_PLC_RESPONSE;
+								}
+							}
+							else if ( Dispatch_manager::get_instance_references().m_dispatch_singlechip[3].is_outlet_ready() )
+							{
+								//封装 给plc的调度请求
+								m_result = encapsulate_dispatch_request_to_plc(1);
+								if ( m_result == Error_code::SUCCESS )
+								{
+									m_dispatch_plc_status = DISPATCH_PLC_WORKING;
+								}
+								else
+								{
+									m_dispatch_plc_status = DISPATCH_PLC_RESPONSE;
+								}
+							}
+							//else无限等待
 						}
 						else
 						{
+							m_result =  Error_manager(Error_code::DISPATCH_PLC_DIRECTION_ERROR, Error_level::MINOR_ERROR,
+													  " DISPATCH_PLC_DIRECTION_ERROR fun error ");
 							m_dispatch_plc_status = DISPATCH_PLC_RESPONSE;
 						}
 					}
@@ -228,7 +269,7 @@ void Dispatch_plc::execute_thread_fun()
 
 
 //封装 给plc的调度请求
-Error_manager Dispatch_plc::encapsulate_dispatch_request_to_plc()
+Error_manager Dispatch_plc::encapsulate_dispatch_request_to_plc(int outlet_id)
 {
 	//把m_dispatch_request_msg的信息传给本地的数据缓存.
 	std::unique_lock<std::mutex> t_lock(m_lock);
@@ -237,18 +278,21 @@ Error_manager Dispatch_plc::encapsulate_dispatch_request_to_plc()
 	{
 		m_request_dispatch_motion_direction = Common_data::Dispatch_motion_direction::DISPATCH_MOTION_DIRECTION_STORE;
 		m_request_passageway_direction = Common_data::Passageway_direction::PASSAGEWAY_DIRECTION_INLET;
+		m_request_passageway_id = m_dispatch_request_msg.terminal_id()+1;//0~5入口终端号改为1~6
 	}
 	else if( m_dispatch_request_msg.dispatch_motion_direction() == message::Dispatch_motion_direction::E_PICKUP_CAR )
 	{
 		m_request_dispatch_motion_direction = Common_data::Dispatch_motion_direction::DISPATCH_MOTION_DIRECTION_PICKUP;
 		m_request_passageway_direction = Common_data::Passageway_direction::PASSAGEWAY_DIRECTION_OUTLET;
+		m_request_passageway_id = m_dispatch_request_msg.terminal_id()*2+outlet_id+1;//0~2出口单元号改为1~6
+
 	}
 	else
 	{
 		m_request_dispatch_motion_direction = Common_data::Dispatch_motion_direction::DISPATCH_MOTION_DIRECTION_UNKNOWN;
 		m_request_passageway_direction = Common_data::Passageway_direction::PASSAGEWAY_DIRECTION_UNKNOWN;
+		m_request_passageway_id = -1;
 	}
-	m_request_passageway_id = m_dispatch_request_msg.terminal_id()+1;//0~5改为1~6
 
 	if ( m_dispatch_request_msg.locate_information().locate_correct() )
 	{

+ 1 - 1
dispatch/dispatch_plc.h

@@ -76,7 +76,7 @@ protected://member functions
 	void execute_thread_fun();
 
 	//封装 给plc的调度请求
-	Error_manager encapsulate_dispatch_request_to_plc();
+	Error_manager encapsulate_dispatch_request_to_plc(int outlet_id = 0);
 	//更新plc通信
 	Error_manager update_dispatch_plc_communication();
 	//检查plc答复反馈

+ 13 - 1
dispatch/dispatch_singlechip.cpp

@@ -76,7 +76,19 @@ Dispatch_singlechip::Dispatch_singlechip_status Dispatch_singlechip::get_dispatc
 }
 
 
-
+//判断出口是否空闲
+bool Dispatch_singlechip::is_outlet_ready()
+{
+	if ( m_dispatch_singlechip_status == DISPATCH_SINGLECHIP_READY &&
+	m_singlechip_data_msg.insideexistenceflag() == 1)
+	{
+	    return true;
+	}
+	else
+	{
+	    return false;
+	}
+}
 
 
 //执行外界任务的执行函数

+ 4 - 0
dispatch/dispatch_singlechip.h

@@ -43,6 +43,10 @@ public://API functions
 	Error_manager dispatch_singlechip_uninit();
 	//调度单片机 执行状态消息
 	Error_manager execute_for_singlechip_data_msg(message::Singlechip_data &singlechip_data_msg, bool validity);
+
+	//判断出口是否空闲
+	bool is_outlet_ready();
+
 public://get or set member variable
 	Dispatch_singlechip_status get_dispatch_singlechip_status();
 protected://member functions

+ 2 - 0
error_code/error_code.h

@@ -490,6 +490,8 @@ enum Error_code
 	DISPATCH_PLC_RESPONS_ERROR,								//调度plc模块,指令的执行失败
 	DISPATCH_PLC_STATUS_ERROR,								//调度plc模块,状态错误
 	DISPATCH_PLC_TIME_OUT,									//调度plc模块,超时
+	DISPATCH_PLC_DIRECTION_ERROR,							//调度plc模块,方向错误
+
 
 
 	//snap7 通信模块 错误码

+ 2 - 2
setting/communication.prototxt

@@ -42,8 +42,8 @@ communication_parameters
     connect_string_vector:"tcp://192.168.1.184:30009"
     connect_string_vector:"tcp://192.168.1.185:30009"
 
-    connect_string_vector:"tcp://192.168.1.186:30007"
-    connect_string_vector:"tcp://192.168.1.187:30007"
+    connect_string_vector:"tcp://192.168.1.186:30009"
+    connect_string_vector:"tcp://192.168.1.187:30009"
 
     connect_string_vector:"tcp://192.168.1.245:30009"