//
// Created by huli on 2021/9/25.
//

#ifndef NNXX_TESTS_DISPATCH_GROUND_LIDAR_H
#define NNXX_TESTS_DISPATCH_GROUND_LIDAR_H

#include "../error_code/error_code.h"
#include <glog/logging.h>
#include <thread>
#include <mutex>
#include "../tool/thread_condition.h"
#include "../tool/common_data.h"
#include "../tool/time_tool.h"
#include "../task/task_base.h"
//#include "../message/dispatch_message.pb.h"
//#include "../message/measure_message.pb.h"
#include "../message/message.pb.h"
#include "../dispatch/dispatch_communication.h"

//调度地面雷达
class Dispatch_ground_lidar
{
public:
	//调度plc状态
	enum Dispatch_ground_lidar_status
	{
		DISPATCH_GROUND_LIDAR_UNKNOW               	= 0,    //未知
		DISPATCH_GROUND_LIDAR_READY               	= 1,    //准备，待机


		DISPATCH_GROUND_LIDAR_FAULT					= 10,	//故障
		DISPATCH_GROUND_LIDAR_DISCONNECT			= 11, 	//断连

	};
public:
	Dispatch_ground_lidar();
	Dispatch_ground_lidar(const Dispatch_ground_lidar& other)= default;
	Dispatch_ground_lidar& operator =(const Dispatch_ground_lidar& other)= default;
	~Dispatch_ground_lidar();
public://API functions
	//调度地面雷达 初始化
	Error_manager dispatch_ground_lidar_init(int plc_id, int ground_lidar_id);
	//调度地面雷达 反初始化
	Error_manager dispatch_ground_lidar_uninit();
	//调度地面雷达 执行状态消息
//	Error_manager execute_for_ground_status_msg(message::Ground_status_msg &ground_status_msg);
	//调度地面雷达 执行状态消息
	Error_manager execute_for_ground_status_msg_new(measure_info &t_measure_info);
public://get or set member variable
	Dispatch_ground_lidar_status get_dispatch_ground_lidar_status();
protected://member functions
	//执行外界任务的执行函数
	void execute_thread_fun();

	//检查感测消息
	Error_manager check_measure_info(measure_info &t_measure_info);
protected://member variable
	std::atomic<Dispatch_ground_lidar_status>				m_dispatch_ground_lidar_status;//调度地面雷达的状态


	int 										m_plc_id;				//设备id, 索引, 就是楚天车库的单元号.
	int 										m_ground_lidar_id;		//地面雷达的id
	std::mutex									m_lock;	//锁

	//任务执行线程
	std::thread*        						mp_execute_thread;   			//执行的线程指针，内存由本类管理
	Thread_condition							m_execute_condition;			//执行的条件变量

	//数据缓存
//	message::Ground_status_msg 						m_ground_status_msg;				//旧版雷达数据
	measure_info									m_measure_info;						//新版雷达数据
	std::chrono::system_clock::time_point			m_ground_status_msg_updata_time;	//状态更新时间点
	std::atomic<bool>								m_ground_status_msg_updata_flag;
private:

};


#endif //NNXX_TESTS_DISPATCH_GROUND_LIDAR_H
