123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #include "wj_lidar_task.h"
- /**
- * 无参构造
- * */
- Wj_lidar_Task::Wj_lidar_Task()
- {
- m_task_type = Task_type::WJ_TASK;
- mb_result_flag = false;
- }
- /**
- * 析构
- * */
- Wj_lidar_Task::~Wj_lidar_Task()
- {
- }
- /**
- * 子类初始化函数
- * */
- Error_manager Wj_lidar_Task::init()
- {
- memset(&m_command, 0, sizeof(wj_command));
- m_wj_measure_result.terminal_id = -1;
- m_wj_measure_result.correctness = false;
- m_wj_measure_result.x = 0;
- m_wj_measure_result.y = 0;
- m_wj_measure_result.angle = 0;
- m_wj_measure_result.length = 0;
- m_wj_measure_result.width = 0;
- m_wj_measure_result.height = 0;
- m_wj_measure_result.wheel_base = 0;
- m_task_statu = Task_statu::TASK_CREATED;
- return SUCCESS;
- }
- /**
- * 获取命令
- * */
- Error_manager Wj_lidar_Task::get_command(wj_command &command)
- {
- // 检查参数合法性
- // 若终端编号小于零,或当前时间已经超时,则返回参数非法指令
- if (m_command.terminal_id < 0 ||
- std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - m_command.command_time).count() >= m_command.timeout_in_milliseconds)
- {
- return Error_manager(Error_code::WJ_LIDAR_TASK_INVALID_TASK);
- }else{
- m_mutex.lock();
- memcpy(&command, &m_command, sizeof(wj_command));
- m_mutex.unlock();
- return Error_manager(Error_code::SUCCESS);
- }
- }
- /**
- * 设置测量命令
- * */
- Error_manager Wj_lidar_Task::set_command(wj_command command)
- {
- // 检查参数合法性
- // 若终端编号小于零,或当前时间已经超时,则返回参数非法指令
- if (command.terminal_id < 0 ||
- std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - command.command_time).count() >= command.timeout_in_milliseconds)
- {
- return Error_manager(Error_code::WJ_LIDAR_TASK_INVALID_TASK);
- }else{
- m_mutex.lock();
- memcpy(&m_command, &command, sizeof(wj_command));
- m_mutex.unlock();
- return Error_manager(Error_code::SUCCESS);
- }
- }
- /**
- * 获取万集测量结果
- * 若结果未被更新则返回 WJ_LIDAR_TASK_RESULT_EMPTY
- * */
- Error_manager Wj_lidar_Task::get_result(wj_measure_result &result)
- {
- if (mb_result_flag)
- {
- m_mutex.lock();
- memcpy(&result, &m_wj_measure_result, sizeof(m_wj_measure_result));
- m_mutex.unlock();
- return Error_manager(Error_code::SUCCESS);
- }
- else
- {
- return Error_manager(Error_code::WJ_LIDAR_TASK_EMPTY_RESULT);
- }
- }
- /**
- * 设置万集测量结果
- * */
- Error_manager Wj_lidar_Task::set_result(wj_measure_result result)
- {
- m_mutex.lock();
- memcpy(&m_wj_measure_result, &result, sizeof(result));
- m_mutex.unlock();
- mb_result_flag = true;
- return Error_manager(Error_code::SUCCESS);
- }
- bool Wj_lidar_Task::get_result_flag()
- {
- return mb_result_flag;
- }
|