#include "plc_task.h"

Plc_Task::Plc_Task(){
    m_task_type = Task_type::PLC_TASK;
    mb_result_set_flag = false;
}

Plc_Task::~Plc_Task(){

}

Error_manager Plc_Task::init(){
    m_measure_result.terminal_id = -1;
    m_measure_result.correctness = false;
    m_measure_result.x = 0;
    m_measure_result.y = 0;
    m_measure_result.angle = 0;
    m_measure_result.length = 0;
    m_measure_result.width = 0;
    m_measure_result.height = 0;
    m_measure_result.wheel_base = 0;
    m_task_statu = Task_statu::TASK_CREATED;
    return SUCCESS;
}

Error_manager Plc_Task::get_result(struct measure_result &result){
    if(mb_result_set_flag)
    {
        memcpy(&result, &m_measure_result, sizeof(m_measure_result));
        return Error_manager(Error_code::SUCCESS, Error_level::NORMAL, "成功获取测量结果");
    }
    else
    {
        return Error_manager(Error_code::PLC_EMPTY_TASK, Error_level::NEGLIGIBLE_ERROR, "未获得测量结果，或许是由于在set之前被调用");
    }
}

Error_manager Plc_Task::set_result(struct measure_result result){
    memcpy(&m_measure_result, &result, sizeof(result));
    mb_result_set_flag = true;
    return Error_manager(Error_code::SUCCESS, Error_level::NORMAL, "设置测量结果成功");
}

bool Plc_Task::get_result_set_flag(){
    return mb_result_set_flag;
}
