forked from ccsens_hardware/stc_ttss_weight
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
238 lines
4.6 KiB
238 lines
4.6 KiB
#ifndef APP_COMMON_H
|
|
#define APP_COMMON_H
|
|
|
|
#include "../clib/type.h"
|
|
|
|
#define APP_VERSION 0x10
|
|
#define P485_SLAVER_ID 0x01
|
|
|
|
#define D_MCU_BIGENDIAN 1
|
|
// #define D_MCU_LITTLEENDIAN 1
|
|
|
|
#define D_COUNT_WEIGHT(adc) ((S32)((1000.0 * G.p.weight_max * (adc)) / (2 * 0x7FFFFF / 1000 * D_ADS1213_GAIN_VAL * G.p.lmd)))
|
|
|
|
enum tp_handle
|
|
{
|
|
TP_HANDLED,
|
|
TP_UNHANDLE
|
|
};
|
|
|
|
/**
|
|
* EEPROM 存储结构
|
|
*/
|
|
#define EEPROM_PARAM_DATA_MAX 86
|
|
#define EEPROM_PARAM_FILTER 0xAA
|
|
|
|
typedef struct ts_eeprom_param
|
|
{
|
|
U8 filter;
|
|
U8 len;
|
|
U8 buf[EEPROM_PARAM_DATA_MAX];
|
|
U8 crc[2];
|
|
}EEPROM_PARAM;
|
|
|
|
#define MCU_ID_LEN 7
|
|
#define MCU_ID_KEY_LEN 4
|
|
#define EEPROM_ENC_DATA_MAX 64
|
|
#define EEPROM_ENC_FILTER 0xAA
|
|
typedef struct ts_eeprom_enc
|
|
{
|
|
U8 enc_key[MCU_ID_KEY_LEN];
|
|
U8 enc_val[MCU_ID_LEN];
|
|
U8 crc[2];
|
|
}EEPROM_ENC;
|
|
|
|
|
|
/**
|
|
* 用户协议
|
|
*/
|
|
enum PROTOCOL_OPER
|
|
{
|
|
OPER_RESERVED = 0x00,
|
|
OPER_READ = 0x01,
|
|
OPER_WRITE = 0x02,
|
|
OPER_ACK = 0x03,
|
|
OPER_REPORT = 0x04,
|
|
};
|
|
|
|
enum MODBUS_OPER
|
|
{
|
|
MODBUS_OPER_READ = 0x03,
|
|
MODBUS_OPER_WRITE = 0x06,
|
|
MODBUS_OPER_ERR = 0x8F,
|
|
};
|
|
|
|
enum MODBUS_ERR_CODE
|
|
{
|
|
MODBUS_ERR_LEN = 0x01,
|
|
MODBUS_ERR_CRC = 0x02,
|
|
MODBUS_ERR_OPCODE = 0x03,
|
|
};
|
|
|
|
//协议类型: MODBUS RTU模式
|
|
//#define D_s_PH4_modbus_max (16)
|
|
#define D_s_PH4_modbus_max (64)
|
|
|
|
typedef struct ts_ph4_modbus
|
|
{
|
|
U8 salver; //从机地址
|
|
U8 oper; //功能码
|
|
U8 buf[D_s_PH4_modbus_max];
|
|
U8 crc[2];
|
|
U8 num;
|
|
}TS_PH4_modbus;
|
|
|
|
typedef struct s_modbus_03
|
|
{
|
|
U16 reg;
|
|
U16 num;
|
|
}Modbus03;
|
|
|
|
typedef struct s_modbus_03_ack
|
|
{
|
|
U8 bytes;
|
|
U8 buf[D_s_PH4_modbus_max-1];
|
|
}Modbus03Ack;
|
|
|
|
typedef struct s_modbus_06
|
|
{
|
|
U16 reg;
|
|
U16 val;
|
|
}Modbus06;
|
|
|
|
typedef struct s_modbus_06_ack
|
|
{
|
|
U16 reg;
|
|
U16 val;
|
|
}Modbus06Ack;
|
|
|
|
typedef struct s_modbus_10
|
|
{
|
|
U16 reg;
|
|
U16 num;
|
|
U8 count;
|
|
}Modbus10;
|
|
|
|
typedef struct s_modbus_10_ack
|
|
{
|
|
U16 reg;
|
|
U16 num;
|
|
}Modbus10Ack;
|
|
|
|
|
|
typedef struct s_modbus_err_ack
|
|
{
|
|
U8 errcode;
|
|
}ModbusErrAck;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
* Register Map
|
|
*/
|
|
|
|
#define D_ch_max_num 4
|
|
#define D_weight_std_num 10
|
|
|
|
#if 0
|
|
序号 量程 系数
|
|
1 100kg 100%
|
|
2 200kg 100%
|
|
3 300kg 100%
|
|
4 400kg 100%
|
|
5 500kg 100%
|
|
6 600kg 100%
|
|
7 700kg 100%
|
|
8 800kg 100%
|
|
9 900kg 100%
|
|
10 1000kg 100%
|
|
#endif
|
|
typedef struct weight_stdization
|
|
{
|
|
S16 weight_range; //量程 x 100
|
|
S16 ratio; //重量计算系数,默认100,保留两位小数,相当于x1
|
|
}WeightStdization;
|
|
|
|
#define D_weight_show_limit_num 5
|
|
typedef struct weight_show_limit
|
|
{
|
|
S16 weight;
|
|
S16 times;
|
|
}WeightShowLimit;
|
|
|
|
//需要持久化的参数,不能超过72字节,否则会导致eeprom溢出
|
|
typedef struct global_param_changable
|
|
{
|
|
U16 reset; //reset标志,写入任何值,所有参数恢复初始值
|
|
U16 adc_ch_status;
|
|
S16 slaver_id;
|
|
S16 zero; //清0标志,写入任何值清0(去皮)
|
|
S16 weight_max; //量程
|
|
S16 lmd; //2mv/v
|
|
S16 cc_blur_ch_avg; //均值滤波点数
|
|
S16 cc_blur_ch_shift; //移位滤波点数
|
|
S16 cc_blur_all_shift0; //和值移位滤波点数1
|
|
S16 cc_blur_all_shift1; //和值移位滤波点数2
|
|
S16 cc_blur_all_out_d_threshold; //移位阈值1
|
|
S16 cc_blur_all_out_dd_threshold;//移位阈值2
|
|
WeightShowLimit weight_show_limit[D_weight_show_limit_num];
|
|
WeightStdization weight_std[D_weight_std_num];
|
|
}GlobalNeedPersistParam;
|
|
|
|
typedef struct mcu_encrypt_info
|
|
{
|
|
U8 enc_key[MCU_ID_KEY_LEN];
|
|
U8 mcu_id[MCU_ID_LEN];
|
|
U8 mcu_enc_id[MCU_ID_LEN];
|
|
}McuEncryptInfo;
|
|
|
|
typedef struct global_param
|
|
{
|
|
//RO Register
|
|
S16 reserved1;
|
|
S32 total_weight; //净重(显示重量)*100
|
|
S32 total_zweight; //皮重*100
|
|
|
|
//RW Register
|
|
S16 reserved2;
|
|
GlobalNeedPersistParam p;
|
|
S16 reserved3;
|
|
|
|
//EncryptInfo
|
|
McuEncryptInfo e;
|
|
|
|
//Global Variables
|
|
S32 weight[D_ch_max_num]; //4路重量
|
|
S32 _total_weight; //实际重量*1000
|
|
S32 _total_zweight; //实际皮重*1000
|
|
}GlobalParam;
|
|
|
|
#define ADC_status_chx_Ready_BASE 0x01
|
|
#define ADC_status_ch1_Ready 0x01
|
|
#define ADC_status_ch2_Ready 0x02
|
|
#define ADC_status_ch3_Ready 0x04
|
|
#define ADC_status_ch4_Ready 0x08
|
|
|
|
//寄存器内存基地址
|
|
#define REG_MEM_BASE ((U16*)(&G)) //寄存器基础地址(本文件外部不应该使用该宏定义)
|
|
//变量地址转寄存器
|
|
#define MEM_2_REG(mem) (((U16*)(mem) - REG_MEM_BASE) + 1)
|
|
//寄存器转变量地址
|
|
#define REG_2_MEM(reg) (REG_MEM_BASE + (U16)((reg) - 1))
|
|
|
|
|
|
extern struct global_param G;
|
|
extern struct ts_eeprom_param eep_param;
|
|
extern struct ts_eeprom_enc eep_enc;
|
|
|
|
extern void L3_reg_init(void);
|
|
extern int L3_ph4_common_handler(TS_PH4_modbus *pmodbus);
|
|
extern int L3_ph4_send_error_pkg(U8 errcode);
|
|
extern int L3_mcu_id_ok();
|
|
extern S32 L3_count_std_weight(S32 weight);
|
|
|
|
|
|
#endif
|
|
|
|
|