/*        

该任务用于接收来自各个不同的控制方式所期望的控制指令 将其集中统一化后分发给各个模块

*/			

#ifndef _CMD_H
#define _CMD_H
#include "struct_typedef.h"
#include "device.h"
#include "Action.h"

//遥控器状态
typedef enum{
	RC_DR16,
	RC_LD	,
	Control_loss
}rc_type_t;

/* 拨杆位置 */
typedef enum {
  CMD_SW_ERR = 0,
  CMD_SW_UP = 1,
  CMD_SW_MID = 3,
  CMD_SW_DOWN = 2,
} CMD_SwitchPos_t;

//遥控器数据
typedef struct {

  rc_type_t rc_type;

  struct {
  float ch_l_x; /* 遥控器左侧摇杆横轴值，上为正 */
  float ch_l_y; /* 遥控器左侧摇杆纵轴值，右为正 */
  float ch_r_x; /* 遥控器右侧摇杆横轴值，上为正 */
  float ch_r_y; /* 遥控器右侧摇杆纵轴值，右为正 */

  CMD_SwitchPos_t sw_r; /* 右侧拨杆位置 */
  CMD_SwitchPos_t sw_l; /* 左侧拨杆位置 */

	}__attribute__((packed))DJ;
	
	struct {
  float ch_l_x ;/* 遥控器左侧摇杆横轴值，上为正 */
  float ch_l_y ;/* 遥控器左侧摇杆纵轴值，右为正 */
  float ch_r_x ;/* 遥控器右侧摇杆横轴值，上为正 */
  float ch_r_y ;/* 遥控器右侧摇杆纵轴值，右为正 */
 
  CMD_SwitchPos_t key_A ;
	CMD_SwitchPos_t key_B ;	
  CMD_SwitchPos_t key_C ;
  CMD_SwitchPos_t key_D ;
	CMD_SwitchPos_t key_E ;
  CMD_SwitchPos_t key_F;
  CMD_SwitchPos_t key_G ;
  CMD_SwitchPos_t key_H ;
	
	int16_t knob_left;//左旋钮
	int16_t knob_right;//右旋钮	
	}__attribute__((packed))LD;

} __attribute__((packed))CMD_RC_t;

//码盘数据
typedef	struct
	{
		fp32 Vx;
		fp32 Vy;
		fp32 Vw;
	}OpsHopeVector_t;
	
typedef struct {
	
  OpsHopeVector_t out;
	
} CMD_ACTION_t;

//nuc数据
typedef struct {
   struct 
   {
   float flag;     //校准成功nuc反馈标志位
	 float angle;	   //偏差角度
	 float yaw;      //自身角度
	 float gyro_z; 	 //雷达陀螺仪数据
   }nuc;
 } CMD_NUC_t;

//导航数据
typedef enum{
	 POS_1,
   POS_2,
   POS_3,
   POS_4,
   POS_5,
   POS_6,
   POS_7,	
	 POS_8,
	 POS_9,
	 POS_10,
	 POS_11,
	 POS_12,
	 POS_13,
	 POS_14,
	 POS_15,	
 }CMD_Chassis_navi_pos;

typedef  enum{
  STOP,        //底盘锁死
	RC,          //遥控模式
  NAVI,        //导航模式
  }CMD_Chassis_mode;

typedef  enum{	
  WORLD,       //无头模式
  ANGLE,       //角度纠正
	RADAR_RESET, //雷达复位
  }CMD_Chassis_radar;

typedef  enum{	
  NO,          //锁框
	YES,         //锁车
  }CMD_Chassis_Communication;

typedef  enum{	
  RUNNING,        
	Pause,       
  }CMD_Chassis_Dribble;
	
typedef struct{
 CMD_Chassis_navi_pos pos;                //码盘点位

 CMD_Chassis_mode mode;                   //底盘模式

	
 CMD_Chassis_radar nuc_radar;             //导航模式

 CMD_Chassis_Communication	communicate;  //瞄准模式

 CMD_Chassis_Dribble dribble;             //运球锁死模式
	}CMD_Chassis_Ctrl_t;

typedef  struct {
  float vx;
  float vy;
  float wz;
}CMD_FOR_NAVI;

typedef struct {  
  int cmd_power_on_safe;  // 上电安全标志
 
  CMD_Chassis_Ctrl_t C_cmd; 

  //遥控器输出值
   fp32 Vx;
   fp32 Vy;
   fp32 Vw;
	 fp32 throttle; 
	
   CMD_FOR_NAVI C_navi;//导航输出值	  
	
	//nuc输出值
	struct {
	float angle;	
  float yaw;		
  }nuc;	
	
} CMD_t;


void CMD_Init(CMD_t *cmd);

void CMD_ParseRc(CMD_t *cmd,CMD_RC_t *rc);

int8_t CMD_CtrlSet(CMD_t *cmd,const CMD_RC_t *rc);

int8_t CMD_ParseAction(CMD_t *cmd,CMD_ACTION_t *act);

int8_t CMD_ParseNuc(CMD_t *cmd,CMD_NUC_t *n);

#endif 

