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.
 
 
 
 

160 lines
4.1 KiB

#ifndef APP_COMMON_H
#define APP_COMMON_H
#include "../clib/type.h"
#include "../clib/clib.h"
#include "../bsp/bsp_config.h"
#include "../tpc/ccmodbus.h"
#include "../tpc/modbus.h"
//#include "../asp/asp_oid.h"
#define SERVER_ID 0x01
#define APP_VERSION 0x10
#define SLAVER_TCP_SERVER_ID 0x14
#define APP_VERSION_HEX 0x11 //高4位主版本,低4位次版本
#define D_COUNT_WEIGHT(adc) (U32)((adc) / D_ADS1213_GAIN_VAL / R.p.lmd * R.p.weight_max * 1000 / (2 * 0x7FFFFF / 1000 ))
#define D_COUNT_ADC(wInG) (U32)((wInG) * D_ADS1213_GAIN_VAL * R.p.lmd * (2 * 0x7FFFFF / 1000) / R.p.weight_max / 1000)
//STEP 1 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Register CONFIG
//寄存器编号从1开始
//#define D_COUNT_WEIGHT(adc) (U32)(1000.0 * R.p.weight_max * (adc) / (2 * 0x7FFFFF / 1000 * D_ADS1213_GAIN_VAL * R.p.lmd))
//#define D_blur_threshold_2_1(threshold) (U32) ( 1.0 * threshold *(2 * 0x7FFFFF / 1000 * D_ADS1213_GAIN_VAL * R.p.lmd) / (1000.0 * R.p.weight_max ))
#define CCMD_SLAVER_INFO_MAX 2
typedef struct pen_point
{
U16 x_axis;//横坐标
U16 y_axis;//纵坐标
U32 time;//时间
U16 angle;//角度
}PenPoint;
typedef enum
{
POW_OFF = 0, //关机状态
POW_ON = 1, //开机状态
WIFI_CONFIG = 2, //WIFI配置连接中
WIFI_CONNECTED = 3, //WIFI连接成功
TCP_CONNECTED = 4, //TCP连接成
}APP_STATUS;
typedef struct global_register
{
//RO Register
U16 pen_sta;//点读笔状态
U16 pen_net_sta;//联网状态
U16 pen_ele_sta;//电池电量
U16 question_sta;//问题 0上题 1下题
U16 spee_order;//语音序号
U32 oid3_order;//序号通知(oid3普通码)
U16 null[25];
//U16 pack_order;//包序号
//U16 frame_order;//帧序号
//U16 pack_mask;//包标志
//Ts_OID_frame_xy_ points[POINT_LEN];
struct {
//oid type
U8 type;
//oid code
U8 dat;
}oid;
struct {
//oid type
U8 type;
//oid code
U8 dat;
}game;
APP_STATUS app_status;
}GlobalRegister;
extern GlobalRegister R;
//寄存器内存基地址
#define REG_MEM_BASE ((U16*)(&R)) //寄存器基础地址(本文件外部不应该使用该宏定义)
//变量地址转寄存器
#define MEM_2_REG(mem) (((U16*)(mem) - REG_MEM_BASE))
//寄存器转变量地址
#define REG_2_MEM(reg) (REG_MEM_BASE + (U16)((reg))) //寄存及从0地址开始
//STEP 1 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Register CONFIG End
//STEP 2 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Global Variables CONFIG
typedef struct global_param
{
//调试模式
U8 debug;
U8 reset;
//station模式状态
U8 st_status; //0:none 1:wifi_ok 2:tcp_connect_ok
//station模式sid
U8 st_sid[32];//必须是一个字符串 "ccsens\0"
//station模式pwd
U8 st_pwd[32];//必须是一个字符串 "ccsens123\0"
//ap模式状态
U8 ap_status; //0: none 1: ap_ok 2:tcp_server_ok
//ap模式sid
U8 ap_sid[32];
//ap模式pwd
U8 ap_pwd[32];
//w600联网模式
U16 w600_mode;
U16 status_eep_save;
U16 slaver_id;
vU32 modbusstmp;
U16 authed;
U16 flowStartVal;
U8 mcu_id[7];
U8 pen_up;
U8 pen_down;
U8 pen_hold;
U8 pen_end;
U8 pen_t;
U8 oid_p;
U8 oid_x;
U8 datapkg;
CCMD_SLAVER_INFO ccmd_slaver_info[CCMD_SLAVER_INFO_MAX];///16*3
}GlobalParam;
extern GlobalParam G;
//STEP 2 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Global Variables CONFIG End
#if 0
typedef struct
{
vU8 rIndex;//读标志
vU8 Index;//读标志
vU8 wIndex;//写标志
vU8 full;//缓冲区满标志位
vU8 null;//缓冲区空标志位
vU8 maxsize;//数组最大长度
vU8 readdr;//缓冲区读写结束新地址
vU8 relen;//从缓冲区头开始的新长度
//PenPoint buf[POINT_LEN+6];//8*48*2
}WR_Buf;
extern WR_Buf wr_buf;
#endif
extern void L3_param_init(void);
extern void L3_reg_2_iap(void);
extern void L3_iap_2_reg(void);
extern void L3_reg_reset(void);
extern void L3_reg_init(void);
//extern void Lc_buf_full(WR_Buf *p);
//extern U16 Lc_write_cyc_buf(PenPoint *wbuf ,WR_Buf *wp ,U16 wlen);
//extern U16 Lc_read_cyc_buf(PenPoint *rbuf ,WR_Buf *rp ,U16 rlen);
#endif