/******************************************************************************
 * Copyright 2020 The siasun Transport Authors. All Rights Reserved.
 * Author: limengqi
 * Licensed under the Apache License, Version 1.0 (the "License");
 *****************************************************************************/
#ifndef MESSAGECODER_H
#define MESSAGECODER_H

#include"candatatype.h"
#include "canbus.h"

namespace robot {
namespace canbusSpace {

class MessageCoder
{
private:
    //字符串反转
    static void CharReverse(unsigned char *s, int n);

    //执行机构使能请求--数据解析
    static void CanMsgAnalyseID_7F5(unsigned char * ucData, T_ACTUATOR_ENABLE_REQUEST *tActEnableReq);

    //转向执行机构控制命令--数据解析
    static void CanMsgAnalyseID_5F4(unsigned char *ucData, T_STR_ACT_CTR_REQ *tStrActCtrReq);

    //车辆状态1--数据解析
    static void CanMsgAnalyseID_6F1(unsigned char *ucData, T_VEHICLE_STATUS_1 *tVehicleStat1);

    //车辆状态2--数据解析
    static void CanMsgAnalyseID_6F2(unsigned char *ucData, T_VEHICLE_STATUS_2 *tVehicleStat2);

    //车辆状态3--数据解析
    static void CanMsgAnalyseID_6F3(unsigned char *ucData, T_VEHICLE_STATUS_3 *tVehicleStat3);

    //工控机状态--数据解析
    static void CanMsgAnalyseID_6F4(unsigned char *ucData, T_COMPUTER_STATUS *tComputerStat);

    //档位 Z 轴状态反馈--数据解析
    static void CanMsgAnalyseID_6F5(unsigned char *ucData, T_ZSFT_STATUS *tZSftStat);

    //机器人执行机构实际位置--数据解析
    static void CanMsgAnalyseID_6E0(unsigned char *ucData, T_RBT_ACT_PSNG *tRbtActPsng);

    //踏板学习位置反馈--数据解析
    static void CanMsgAnalyseID_6E1(unsigned char *ucData, T_ACC_BRK_PSNG *tAccBrkPsng);

    //转向学习位置反馈--数据解析
    static void CanMsgAnalyseID_6E2(unsigned char *ucData, T_STR_LRN_PSNG *tStrLrnPsng);

    //档位学习位置反馈1--数据解析
    static void CanMsgAnalyseID_6E3(unsigned char *ucData, T_SFT_LRN_PST_1 *tSftLrnPst1);

    //控制器上电状态--数据解析
    static void CanMsgAnalyseID_6E4(unsigned char *ucData, T_CTR_POW_STATUS *tCtrPowStatus);

    //执行机构使能状态--数据解析
    static void CanMsgAnalyseID_6E5(unsigned char *ucData, T_ACT_ENABLE_STATUS *tActEnableStatus);

    //油门控制状态反馈--数据解析
    static void CanMsgAnalyseID_6E6(unsigned char *ucData, T_ACC_CTR_STATUS *tAccCtrStatus);

    //制动踏板控制状态反馈--数据解析
    static void CanMsgAnalyseID_6E7(unsigned char *ucData, T_BRK_CTR_STATUS *tBrkCtrStatus);

    //离合踏板控制状态反馈--数据解析
    static void CanMsgAnalyseID_6E8(unsigned char *ucData, T_CLCH_CTR_STATUS *tClchCtrStatus);

    //转向控制状态反馈--数据解析
    static void CanMsgAnalyseID_6E9(unsigned char *ucData, T_STR_STATUS *tStrStatus);

    //档位控制状态反馈--数据解析
    static void CanMsgAnalyseID_6EA(unsigned char *ucData, T_SFT_STATUS *tSftStatus);

    //系统运行状态参数反馈1--数据解析
    static void CanMsgAnalyseID_6EB(unsigned char *ucData, T_SYS_INFO_1 *tSysInfo1);

    //系统运行状态参数反馈2--数据解析
    static void CanMsgAnalyseID_6ED(unsigned char *ucData, T_SYS_INFO_2 *tSysInfo2);

    //系统学习状态反馈--数据解析
    static void CanMsgAnalyseID_6EE(unsigned char *ucData, T_SYS_LRN *tSysLrn);

    //档位学习位置反馈2--数据解析
    static void CanMsgAnalyseID_6EF(unsigned char *ucData, T_SFT_LRN_PST_2 *tSFtLrnPst2);

    //系统监控状态反馈--数据解析
    static void CanMsgAnalyseID_6D0(unsigned char *ucData, T_SYS_MONITOR *tSysMonitor);

    //系统报警--数据解析
    static void CanMsgAnalyseID_6D1(unsigned char *ucData, T_SYS_ERR *tSysErr);

    //方向盘位置时间控制请求--数据解析
    static void CanMsgAnalyseID_6D7(unsigned char *ucData, T_STR_PST_TIME_REQ *tSteerPstTimeReq);

    //Estop系统信息--数据解析
    static void CanMsgAnalyseID_2E0(unsigned char *ucData, T_ESTOP_INFO *tEstopInfo);

    //Estop故障码--数据解析
    static void CanMsgAnalyseID_2E1(unsigned char *ucData, T_ESTOP_ERR *tEstopErr);

    //油门(acc)、制动(brk)、挡位(sft)X、挡位(sft)Y、转向(str)电机报警--数据解析
    static void CanMsgAnalyseErr(unsigned char *ucData, T_MOT_CTR_ERR *tMotCtrErr);

    //OBD实际油门踏板行程--数据解析
    static void OBDAnalyseID_070(unsigned char *ucData, T_OBD_ACC_PSNG *tOBDAccPsng);

    //控制器上电命令--数据组包
    static void CanMsgPackageID_7F2(T_POWER_ON_REQUEST *tPowOnReq, TPCANMsg *tCanMsg);

    //执行机构使能请求--数据组包
    static void CanMsgPackageID_7F5(T_ACTUATOR_ENABLE_REQUEST *tActEnableReq, TPCANMsg *tCanMsg);

    //学习模式请求确认--数据组包
    static void CanMsgPackageID_7F7(T_LEARN_MODE_REQUEST *tLearnMdReq, TPCANMsg *tCanMsg);

    //油门踏板执行机构控制命令--数据组包
    static void CanMsgPackageID_5F2(T_ACC_PEDAL_ACT_CTR_REQ *tAccPedalActCtrReq,TPCANMsg *tCanMsg);

    //制动踏板执行机构控制命令--数据组包
    static void CanMsgPackageID_5F0(T_BRK_PEDAL_ACT_CTR_REQ *tBrkPedalActCtrReq,TPCANMsg *tCanMsg);

    //转向执行机构控制命令--数据组包
    static void CanMsgPackageID_5F4(T_STR_ACT_CTR_REQ *tStrActCtrReq, TPCANMsg *tCanMsg);

    //档位执行机构控制命令--数据组包
    static void CanMsgPackageID_5FA(T_SFT_ACT_CTR_REQ *tSftActCtrReq,TPCANMsg *tCanMsg);

    //机器人自检控制命令--数据组包
    static void CanMsgPackageID_5FC(T_RBT_SLF_CHK_CTR_REQ *tRbtSlfChkCtrRq,TPCANMsg *tCanMsg);

    //机器人手动控制命令--数据组包
    static void CanMsgPackageID_5FD(T_RBT_DRIVER_CTR *tRbtDriverCtr, TPCANMsg *tCanMsg);

    //设备管理--数据组包
    static void CanMsgPackageID_7F6(T_RBT_MANAGER *tRbtManager, TPCANMsg *tCanMsg);

    //上位机监控--数据组包
    static void CanMsgPackageID_7F8(T_ICU_MONITOR *tIcuMonitor, TPCANMsg *tCanMsg);

    //执行机构加速度控制请求--数据组包
    static void CanMsgPackageID_5F5(T_STR_ACC_CTR_REQ *tActAccCtrReq, TPCANMsg *tCanMsg);

    //执行机构限值设置--数据组包
    static void CanMsgPackageID_7F3(T_ACT_CTR_LIMT *tActCtrLimt, TPCANMsg *tCanMsg);

    //力矩保护设置--数据组包
    static void CanMsgPackageID_7F4(T_TORQUE_PROTECT_SETUP *tTrqPrtctSetp, TPCANMsg *tCanMsg);

    //制动机构时间控制设置--数据组包
    static void CanMsgPackageID_5F1(T_BRK_FORCE_CTR_SETUP *tBrkFrcCtrStp, TPCANMsg *tCanMsg);

    //转向三角波/线性控制--数据组包
    static void CanMsgPackageID_5F6(T_STR_TRIANGLE_LINE_CTR *tStrTrnglLnCtr, TPCANMsg *tCanMsg);

    //转向正弦控制--数据组包
    static void CanMsgPackageID_5F7(T_STR_SIN_CTR *tStrSinCtr, TPCANMsg *tCanMsg);

    //油门机构位置时间控制--数据组包
    static void CanMsgPackageID_5F3(T_ACC_POSITION_CTR_SETUP *tAccPstnCtrStp, TPCANMsg *tCanMsg);

    //方向盘位置时间序列控制--数据组包
    static void CanMsgPackageID_5F8(T_STR_POSITION_TIME_CTR *tStrPstnTmCtr, TPCANMsg *tCanMsg);

    //车辆一键启动--数据组包
    static void CanMsgPackageID_5FB(T_VEHICLE_START *tVehicleStart,TPCANMsg *tCanMsg);

    //坡度模块--数据组包
    static void CanMsgPackageID_5FE(T_SLOPE_MODE *tSlopeMODE,TPCANMsg *tCanMsg);

    //车辆状态1--数据组包
    static void CanMsgPackageID_6F1(T_VEHICLE_STATUS_1 *tVehicleStatus1, TPCANMsg *tCanMsg);

    //车辆状态2--数据组包
    static void CanMsgPackageID_6F2(T_VEHICLE_STATUS_2 *tVehicleStatus2, TPCANMsg *tCanMsg);

    //车辆状态3--数据组包
    static void CanMsgPackageID_6F3(T_VEHICLE_STATUS_3 *tVehicleStatus3, TPCANMsg *tCanMsg);

    //急停控制--数据组包
    static void CanMsgPackageID_201(T_ESTP_CTRL *tEstpCtrl,TPCANMsg *tCanMsg);

    //机器人工作模式配置--数据组包
    static void CanMsgPackageID_7F0(T_WORKING_MODE_CONFING *tWorkingModeConfing,TPCANMsg *tCanMsg);

    //系统控制模式--数据组包
    static void  CanMsgPackageID_7F1(T_CONTROL_MODE *tControlMode,TPCANMsg *tCanMsg);

    //IO控制模块--数据组包
    static void  CanMsgPackageID_5FF(T_IO_REQ *tIOReq,TPCANMsg *tCanMsg);

    static void CanMsgPackageID_6E2 (T_STR_LRN_PSNG *tStrLrnPsng,TPCANMsg *tCanMsg);
public:
    //数据解析
    static void * CanMsgAnalyse(int id, unsigned char * ucData);
    //数据组包
    static void CanMsgPackage(void *p,int id, TPCANMsg *tCanMsg);

    static void ConvertUnCharToStr(char *str,unsigned char *UnChar,int ucLen);

};
}// namespace canbus
}// namespace robot

#endif // MESSAGECODER_H
