#ifndef _USER_SERVER_H__
#define _USER_SERVER_H__

#include <stdint.h>
#include <stdbool.h>
#include "define.h"
#include "user_can.h"

#ifdef __cplusplus
extern "C" {
#endif

#define USER_SERVER_INTERVAL						            10

#define LOCK_COUNT												          5

#define S_INS_WR_BYTE											          0x2F        //写操作发送命令字1个字节
#define S_INS_WR_WORD											          0x2B        //写操作发送命令字2个字节
#define S_INS_WR_DWORD											        0x23        //写操作发送命令字4个字节
#define R_INS_WR_SUCC                               0x60        //写操作成功接收命令字
#define R_INS_WR_FAIL                               0x80        //写操作失败接收命令字

#define S_INS_RD                                    0x40        //读操作发送命令字
#define R_INS_RD_BYTE											          0x4F        //读操作接收命令字1个字节
#define R_INS_RD_WORD											          0x4B        //读操作接收命令字2个字节
#define R_INS_RD_DWORD											        0x43        //读操作接收命令字4个字节
#define R_INS_RD_FAIL                               0x80        //读错误接收命令字

#define DEV_TYPE											              0x0001

#define REG_DEV_TYPE_IDX									          0x6000
#define REG_DEV_TYPE_SUBIDX                         0x00

#define REG_VERSION_IDX									            0x6003
#define REG_VERSION_SUBIDX                          0x00

#define REG_LOCK_STAT_IDX									          0x6010
#define REG_LOCK_STAT_SUBIDX                        0x00

#define REG_ELECT_STAT_IDX									        0x6011
#define REG_ELECT_STAT_SUBIDX                       0x00

#define REG_LOCK_ID_IDX							            	  0x6020
#define REG_LOCK_01_ID_SUBIDX                       0x00
#define REG_LOCK_02_ID_SUBIDX                       0x01
#define REG_LOCK_03_ID_SUBIDX                       0x02
#define REG_LOCK_04_ID_SUBIDX                       0x03
#define REG_LOCK_05_ID_SUBIDX                       0x04

typedef struct{
	uint8_t lock_stat;
  uint16_t elect_act;
	uint16_t elect_stat;
	uint8_t lock_id[LOCK_COUNT][4];
}__attribute__((packed))lock_data_s;

typedef struct{
  uint8_t ins;
  uint16_t idx;
  uint8_t subidx;
  uint8_t data[4];
}__attribute__((packed))can_open_data_s;

typedef enum
{
    SERVER_QUEUE_TIME   = 0,
    SERVER_QUEUE_CAN    = 1,
    SERVER_BLE_RST		  = 2,
}USER_SERVER_QUEUE_TYPE;

void vUser_server_init(void);
void vUser_server_task_start(void);
lock_data_s *vUser_server_get_lock_data(void);

extern tmosTaskID user_server_task_id;

#ifdef __cplusplus
}
#endif

#endif // ACTION_MOTOR_H__

/** @} */
