//
// Created by huli on 2020/6/29.
//

#ifndef NNXX_TESTS_COMMUNICATION_MESSAGE_H
#define NNXX_TESTS_COMMUNICATION_MESSAGE_H

#include "../error_code/error_code.h"

#include <time.h>
#include <sys/time.h>
#include <chrono>
//#include <iosfwd>

#include <string>
#include "../message/message_base.pb.h"


class Communication_message
{
public:
	//消息类型定义,每个在网络上传输的消息必须含有这个属性
	enum Message_type
	{
		eBase_msg=0x00,
		eCommand_msg=0x01,                      //指令消息


		eLocate_status_msg=0x11,                //定位模块状态消息
		eLocate_request_msg=0x12,               //定位请求消息
		eLocate_response_msg=0x13,              //定位反馈消息

		eLocate_sift_request_msg = 0x14,            //预测算法请求消息
		eLocate_sift_response_msg = 0x15,           //预测算法反馈消息

		eDispatch_status_msg=0x21,                	//调度模块硬件状态消息
		eDispatch_request_msg=0x22,              	//请求调度消息
		eDispatch_response_msg=0x23,             	//调度结果反馈消息

		eParkspace_allocation_status_msg=0x31,  		//车位分配模块状态消息，包括车位信息
		eParkspace_allocation_request_msg=0x32, 		//请求分配车位消息
		eParkspace_allocation_response_msg=0x33,		//分配车位结果反馈消息
		eParkspace_search_request_msg = 0x34,			//查询车位请求消息
		eParkspace_search_response_msg = 0x35,			//查询车位反馈消息
		eParkspace_release_request_msg = 0x36,			//释放车位请求消息
		eParkspace_release_response_msg = 0x37,			//释放车位反馈消息
		eParkspace_force_update_request_msg = 0x38,		//手动修改车位消息
		eParkspace_force_update_response_msg = 0x39,	//手动修改车位反馈消息
		eParkspace_confirm_alloc_request_msg = 0x3A,	//确认分配车位请求消息
		eParkspace_confirm_alloc_response_msg = 0x3B,	//确认分配车位反馈消息
        eParkspace_refresh_request_msg=0x3C,        	//请求更新车位数据
        eParkspace_allocation_data_response_msg=0x3D,	//车位数据反馈消息
		eParkspace_manual_search_request_msg = 0x3E,	//手动查询车位请求消息
		eParkspace_manual_search_response_msg = 0x3F,	//手动查询车位反馈消息

		eStore_command_request_msg=0x41,        	//终端停车请求消息
		eStore_command_response_msg=0x42,       	//停车请求反馈消息
		ePickup_command_request_msg=0x43,       	//取车请求消息
		ePickup_command_response_msg=0x44,       	//取车请求反馈消息
		eTerminal_status_msg = 0x50,	 			//终端状态消息


		eStoring_process_statu_msg=0x90,        //停车指令进度条消息
		ePicking_process_statu_msg=0x91,        //取车指令进度消息


		eCentral_controller_statu_msg=0xa0,     //中控系统状态消息

		eEntrance_manual_operation_msg=0xb0,            //针对出入口状态操作的手动消息
		eProcess_manual_operation_msg=0xb1,             //针对流程的手动消息

		eNotify_request_msg=0xc0,               //取车等候区通知请求
		eNotify_response_msg=0xc1,              //等候区反馈
		eNotify_status_msg=0xc2,                //等候区通知节点状态
		eUnNormalized_module_statu_msg = 0xd0, //非标节点状态

		eDispatch_plan_request_msg          = 0xe0,     //调度总规划的请求(用于启动整个调度算法)(调度管理->调度算法)
		eDispatch_plan_response_msg         = 0xe1,     //调度总规划的答复(调度算法->调度管理)
		eDispatch_control_request_msg       = 0xe2,     //调度控制的任务请求(调度算法->调度管理)
		eDispatch_control_response_msg      = 0xe3,     //调度控制的任务答复(调度管理->调度算法)
		eDispatch_manager_status_msg        = 0xea,     //调度管理的设备状态消息(调度底下所有硬件设备状态的汇总)
		eDispatch_manager_data_msg          = 0xeb,     //调度管理的设备详细的数据信息
		
		
		eGround_detect_request_msg=0xf0,        //地面雷达测量请求消息
    	eGround_detect_response_msg=0xf1,       //地面雷达测量反馈消息
		eGround_status_msg=0xf2,                //地面雷达状态消息


	};

//通讯单元
	enum Communicator
	{
		eEmpty=0x0000,
		eMain=0x0001,    //主流程

		eTerminor=0x0100,
		//车位表
		eParkspace=0x0200,
		//测量单元
		eMeasurer=0x0300,
		//测量单元
		eMeasurer_sift_server=0x0301,

		//调度机构
		eDispatch_mamager=0x0400,
		//调度机构
		eDispatch_control=0x0401,
		//取车等候区通知节点
		eNotify=0x0501,

		//地面测量单元
		eGround_measurer=0x0f00,
	};
public:
	Communication_message();
	Communication_message(std::string message_buf);
	Communication_message(char* p_buf, int size);
	Communication_message(const Communication_message& other)= default;
	Communication_message& operator =(const Communication_message& other)= default;
	~Communication_message();
public://API functions
	bool is_over_time();
public://get or set member variable
	void reset(const message::Base_info& base_info, std::string receive_string);

	Message_type get_message_type();
	Communicator get_sender();
	Communicator get_receiver();
	std::string& get_message_buf();
	std::chrono::system_clock::time_point get_receive_time();

protected://member variable
	Message_type								m_message_type;				//消息类型
	std::chrono::system_clock::time_point		m_receive_time;				//接收消息的时间点
	std::chrono::milliseconds					m_timeout_ms;				//超时时间, 整个软件都统一为毫秒
	Communicator								m_sender;					//发送者
	Communicator								m_receiver;					//接受者

	std::string									m_message_buf;				//消息数据

private:

};


#endif //NNXX_TESTS_COMMUNICATION_MESSAGE_H
