#pragma once

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ----------------------------------------------------------------- */
#include <cmsis_os2.h>
#include <stdbool.h>

#include "bsp\can.h"
#include "device\device.h"

/* Exported constants ------------------------------------------------------- */

#define CAN_TX_SICK_BUF_SIZE (8)
#define CAN_RX_SICK_BUF_SIZE (8)

#define CAN_TX_BUF_SIZE_MAX  (8)
#define CAN_RX_BUF_SIZE_MAX  (8)
/* Exported macro ----------------------------------------------------------- */
/* Exported types ----------------------------------------------------------- */


typedef enum {
    CAN_SICK1_ID = 0x000,
    CAN_SICK2_ID = 0x001,
    CAN_SICK3_ID = 0x002,
    CAN_SICK4_ID = 0x003,
} CAN_Sick_ID_t;

// /* sick反馈信息 */
typedef struct {
  uint16_t distance;
  uint16_t save0;
  uint16_t save1;
  uint16_t save2;
} CAN_Sick_Feedback_t;

typedef struct {
  uint16_t sick[4];
} CAN_Sick_Output_t;

typedef struct {
  CAN_Sick_Feedback_t as_array[4];
  CAN_Sick_Output_t named;
} CAN_Sick_t;

typedef struct {
    BSP_CAN_t sick;
    BSP_CAN_t c_board;
} CAN_Params_t;

typedef struct {
    uint32_t recive_flag;
    CAN_Sick_t sick;
    const CAN_Params_t *param;
    struct {
      uint32_t sick;
    } mailbox;
    osMessageQueueId_t msgq_raw;
  } CAN_t;

typedef struct {
    CAN_RxHeaderTypeDef rx_header;
    uint8_t rx_data[CAN_RX_BUF_SIZE_MAX];
  } CAN_RawRx_t;
  
  typedef struct {
    CAN_TxHeaderTypeDef tx_header;
    uint8_t tx_data[CAN_TX_BUF_SIZE_MAX];
  } CAN_RawTx_t;

// /* Exported functions prototypes -------------------------------------------- */
int8_t CAN_Init(CAN_t *can, const CAN_Params_t *param);


#ifdef __cplusplus
}
#endif
