#pragma once

#ifdef __cplusplus
extern "C" {
#endif
/* Includes ----------------------------------------------------------------- */
#include <cmsis_os2.h>
#include "FreeRTOS.h"
#include "task.h"

/* USER INCLUDE BEGIN */

/* USER INCLUDE END */
/* Exported constants ------------------------------------------------------- */
/* 任务运行频率 */
#define AI_FREQ (500.0)
#define GIMBAL_CTRL_FREQ (500.0)
#define CHASSIS_CTRL_FREQ (500.0)
#define SHOOT_CTRL_FREQ (500.0)
#define ATTI_ESTI_FREQ (500.0)
#define DR16_FREQ (500.0)
#define CMD_FREQ (500.0)
#define STEP_MOTOR_FREQ (500.0)
#define ET16S_FREQ (500.0)

/* 任务初始化延时ms */
#define TASK_INIT_DELAY (100u)
#define AI_INIT_DELAY (0)
#define GIMBAL_CTRL_INIT_DELAY (0)
#define CHASSIS_CTRL_INIT_DELAY (0)
#define SHOOT_CTRL_INIT_DELAY (0)
#define ATTI_ESTI_INIT_DELAY (0)
#define DR16_INIT_DELAY (0)
#define CMD_INIT_DELAY (0)
#define STEP_MOTOR_INIT_DELAY (0)
#define ET16S_INIT_DELAY (0)

/* Exported defines --------------------------------------------------------- */
/* Exported macro ----------------------------------------------------------- */
/* Exported types ----------------------------------------------------------- */

/* 任务运行时结构体 */
typedef struct {
    /* 各任务，也可以叫做线程 */
    struct {
        osThreadId_t ai;
        osThreadId_t gimbal_ctrl;
        osThreadId_t chassis_ctrl;
        osThreadId_t shoot_ctrl;
        osThreadId_t atti_esti;
        osThreadId_t dr16;
        osThreadId_t cmd;
        osThreadId_t step_motor;
        osThreadId_t ET16s;
    } thread;

    /* USER MESSAGE BEGIN */
    struct {
        osMessageQueueId_t user_msg; /* 用户自定义任务消息队列 */
			
				struct {
            osMessageQueueId_t cmd; /* 发射命令队列 */
						osMessageQueueId_t remote;
        }shoot;
        struct {
            osMessageQueueId_t imu;
            osMessageQueueId_t cmd;
						osMessageQueueId_t remote;
        }gimbal;
        struct {
            osMessageQueueId_t state;
            osMessageQueueId_t cmd;
						osMessageQueueId_t remote;
					
        }chassis;
        struct {
            osMessageQueueId_t state;
            osMessageQueueId_t cmd;
						osMessageQueueId_t remote;
					
        }telescoping;
        struct {
            osMessageQueueId_t state;
            osMessageQueueId_t dr16;
            osMessageQueueId_t et16s;					
        }rc;			
    } msgq;
    /* USER MESSAGE END */

    /* 机器人状态 */
    struct {
        float battery; /* 电池电量百分比 */
        float vbat; /* 电池电压 */
        float cpu_temp; /* CPU温度 */
    } status;

    /* USER CONFIG BEGIN */

    /* USER CONFIG END */

    /* 各任务的stack使用 */
    struct {
        UBaseType_t ai;
        UBaseType_t gimbal_ctrl;
        UBaseType_t chassis_ctrl;
        UBaseType_t shoot_ctrl;
        UBaseType_t atti_esti;
        UBaseType_t dr16;
        UBaseType_t cmd;
        UBaseType_t step_motor;
        UBaseType_t ET16s;
    } stack_water_mark;

    /* 各任务运行频率 */
    struct {
        float ai;
        float gimbal_ctrl;
        float chassis_ctrl;
        float shoot_ctrl;
        float atti_esti;
        float dr16;
        float cmd;
        float step_motor;
        float ET16s;
    } freq;

    /* 任务最近运行时间 */
    struct {
        float ai;
        float gimbal_ctrl;
        float chassis_ctrl;
        float shoot_ctrl;
        float atti_esti;
        float dr16;
        float cmd;
        float step_motor;
        float ET16s;
    } last_up_time;

} Task_Runtime_t;

/* 任务运行时结构体 */
extern Task_Runtime_t task_runtime;

/* 初始化任务句柄 */
extern const osThreadAttr_t attr_init;
extern const osThreadAttr_t attr_ai;
extern const osThreadAttr_t attr_gimbal_ctrl;
extern const osThreadAttr_t attr_chassis_ctrl;
extern const osThreadAttr_t attr_shoot_ctrl;
extern const osThreadAttr_t attr_atti_esti;
extern const osThreadAttr_t attr_dr16;
extern const osThreadAttr_t attr_cmd;
extern const osThreadAttr_t attr_step_motor;
extern const osThreadAttr_t attr_ET16s;

/* 任务函数声明 */
void Task_Init(void *argument);
void Task_ai(void *argument);
void Task_gimbal_ctrl(void *argument);
void Task_chassis_ctrl(void *argument);
void Task_shoot_ctrl(void *argument);
void Task_atti_esti(void *argument);
void Task_dr16(void *argument);
void Task_cmd(void *argument);
void Task_step_motor(void *argument);
void Task_ET16s(void *argument);

#ifdef __cplusplus
}
#endif