#ifndef __PTZ_SELF_CHECK_H_
#define __PTZ_SELF_CHECK_H_

#include "ptz_struct.h"

///全范围自检开始
#define PTZ_HORI_SELF_CHECK_COMPLETE_STEP  0
///自检数据保存
#define PTZ_HORI_SELF_CHECK_DATA_SAVE      100
///简易自检开始
#define PTZ_HORI_SELF_CHECK_SIMPLIFY_STEP  150

///全范围自检开始
#define PTZ_VERT_SELF_CHECK_COMPLETE_STEP  0
///自检数据保存
#define PTZ_VERT_SELF_CHECK_DATA_SAVE      100
///简易自检开始
#define PTZ_VERT_SELF_CHECK_SIMPLIFY_STEP  150

///云台自检结束
#define PTZ_HORI_SELF_CHECK_END      255
#define PTZ_VERT_SELF_CHECK_END      255

#define SELF_CHECK_DATA_FLASH_ADD            0x00860000 //自检参数存储地址
#define SELF_CHECK_DATA_BACKUP_FLASH_ADD     0x00870000 //自检参数备份存储地址
#define SELF_CHECK_DATA_SAVE_FLASH_NUM       3 //自检参数保存次数
#define SELF_CHECK_DATA_READ_FLASH_NUM       3 //自检参数读取次数

#ifdef PTZ_LIGHT_GEAR_L6235D_AS5047D
    ///水平自检最大转速
    #define PTZ_HORI_SELF_CHECK_SPEED   1.8
    ///垂直自检最大转速
    #define PTZ_VERT_SELF_CHECK_SPEED   1.5
#endif

#ifdef PTZ_MEDIUM_WORM_L6235D_AS5047D
    ///水平自检最大转速
    #define PTZ_HORI_SELF_CHECK_SPEED   1.0
    ///垂直自检最大转速
    #define PTZ_VERT_SELF_CHECK_SPEED   0.5
#endif

#ifdef PTZ_HEAVY_WORM_L6235D_AS5047D
    ///水平自检最大转速
    #define PTZ_HORI_SELF_CHECK_SPEED   2.1//1.5//1.8//1.8
    ///垂直自检最大转速
    #define PTZ_VERT_SELF_CHECK_SPEED   0.3//0.25//0.3//0.4
#endif

#ifdef PTZ_SUPER_LIGHT_WORM_L6235D_AS5047D_12V
    ///水平自检最大转速
    #define PTZ_HORI_SELF_CHECK_SPEED   0.8
    ///垂直自检最大转速
    #define PTZ_VERT_SELF_CHECK_SPEED   0.8
#endif



#ifdef PTZ_SUPER_LIGHT_WORM_L6235D_AS5047D_24V
    ///水平自检最大转速
    #define PTZ_HORI_SELF_CHECK_SPEED   1.5
    ///垂直自检最大转速
    #define PTZ_VERT_SELF_CHECK_SPEED   1.5
#endif


//步进电机
#ifdef PTZ_SUPER_LIGHT_WORM_STEP_DRV8711_AS5047D_12V
    ///水平自检最大转速
    #define PTZ_HORI_SELF_CHECK_SPEED   1.5
    ///垂直自检最大转速
    #define PTZ_VERT_SELF_CHECK_SPEED   1.5
#endif

#ifdef PTZ_SUPER_LIGHT_WORM_STEP_DRV8711_AS5047D_24V
    ///水平自检最大转速
    #define PTZ_HORI_SELF_CHECK_SPEED   1.5
    ///垂直自检最大转速
    #define PTZ_VERT_SELF_CHECK_SPEED   1.5
#endif

#ifdef PTZ_SUPER_LIGHT_WORM_STEP_TMC2160_AS5047D_24V
    ///水平自检最大转速
    #define PTZ_HORI_SELF_CHECK_SPEED   1.5
    ///垂直自检最大转速
    #define PTZ_VERT_SELF_CHECK_SPEED   1.5
#endif

//中型步进电机
#ifdef PTZ_MEDIUM_WORM_STEP_TMC2160_AS5047D_24V
    ///水平自检最大转速
    #define PTZ_HORI_SELF_CHECK_SPEED   1.2
    ///垂直自检最大转速
    #define PTZ_VERT_SELF_CHECK_SPEED   0.8
#endif

///云台自检参数需要保存和读取的部分
typedef struct _PtzSelfCheckData_
{
  PtzAs5047D hori_as5047d;
  PtzAs5047D vert_as5047d;
  PtzAngleParameter hori_angleP;
  PtzAngleParameter vert_angleP;
  float hori_angle_error;//水平结构误差
  unsigned int crc;//效验码
}PtzSelfCheckData;


void init_self_check_module(void);
char ptz_self_check_data_save();
char ptz_self_check_data_read();
char ptz_self_check_data_erase();
unsigned int ptz_self_check_data_crc(PtzSelfCheckData data);

#endif