#ifndef __BILL_H__ #define __BILL_H__ #include "stdint.h" #ifdef __cplusplus extern "C" { #endif #define MONTH_BILL_NUM (48) #define DAY_BILL_NUM (368) #define HOUR_BILL_NUM (32) #define FIVE_MIN_BILL_NUM (16) // 2026-4-2 修改为保存16天数据 #define CUM_FLOW_START_ADDR (0x17c00u) // 循环存储最新流量记录的eeprom地址 #define MAX_CUM_FLOW_NUM 256 // 循环存储数量 #define CUM_FLOW_SIZE 32 // 每个记录占用的空间大小 #define MONTH_BILL_START_ADDR (0x0800u) #define DAY_BILL_START_ADDR (MONTH_BILL_START_ADDR + (sizeof(bill_t) * MONTH_BILL_NUM)) #define HOUR_BILL_START_ADDR (DAY_BILL_START_ADDR + (sizeof(bill_t) * DAY_BILL_NUM)) #define FIVE_MIN_BILL_START_ADDR (HOUR_BILL_START_ADDR + (sizeof(hour_bill_t) * HOUR_BILL_NUM * 24)) #define MONTH_BILL_INDEX(year, month) ((year & 0x03) * 12 + (month - 1)) #define HOUR_BILL_INDEX(day, hour) ((day - 1) * 24 + hour) #define FIVE_MIN_BILL_INDEX(day, hour, minute) ((((day - 1) % FIVE_MIN_BILL_NUM) * 24 + hour) * 12 + minute / 5) #define END_RECORD_ADDR 0x17200 #define PRE_MONTH_COW_BAK_ADDR 0x1ac00 #define PRE_DAY_COW_BAK_ADDR 0x1ac20 #define PRE_HOUR_COW_BAK_ADDR 0x1ac40 #define PRE_5MIN_COW_BAK_ADDR 0x1ac60 #define COW_BAK_DATA_SIZE 32 #define BAK_5MIN_NUM 16 #define BAK_5MIN_SIZE 32 //////兼容以前的函数名/////////////// #define SetBillCumFlow set_cur_flow_bill #define SetBillVol set_flow_rate_bill #define read_day_bill get_day_used_bill #define read_month_bill get_month_used_bill #define read_hour_bill get_hour_used_bill #define read_five_min_bill get_5min_used_bill ///////////////////////////////////////////// typedef struct { uint8_t flag; uint8_t date[3]; uint32_t fw_used; uint32_t bw_used; uint8_t reserved[3]; uint8_t check; } bill_t; typedef struct { uint8_t flag; uint8_t date[4]; uint8_t fw_used[3]; uint8_t bw_used[3]; uint8_t pressure; uint8_t flow_rate[3]; uint8_t check; } hour_bill_t; /* typedef struct { uint8_t flag; double cum_flow; double fw_cum_flow; double bw_cum_flow; uint8_t date_time[7]; uint8_t check; }bill_cum_flow_t;*/ // typedef struct{ // uint32_t fw_cum_flow; // uint32_t bw_cum_flow; // }bak_bill_t; typedef struct { double fw_cum_flow; double bw_cum_flow; uint8_t date[6]; // 年月日时分秒 uint8_t flag; // 1有效 uint8_t check; } res_bill_t; typedef struct { double fw_cum_flow; double bw_cum_flow; int32_t global_cnt; uint8_t flag; // uint8_t date[6]; uint8_t check; } bak_5min_bill_t; typedef struct { double fw_cum_flow; double bw_cum_flow; int32_t global_cnt; uint8_t date[6]; uint8_t add_cnt; } bill_5min_ctrl_def; //////////当前流量数据结构体wxl2026-3-2////////// typedef struct { // 40byte uint8_t flag; uint8_t date_time[7]; // double cum_flow; double fw_cum_flow; double bw_cum_flow; int32_t gcnt; uint8_t check; // uint8_t reserv[3]; } bill_cum_flow_tx; ////////////wxl2026-3-2//////////////////// typedef struct { int32_t cur_gcnt; int16_t npos; double fw; double bw; } CUR_FLOW_INDEX_DEF; /////////////////////////////////////////// typedef struct { double fw_use_hour; double fw_use_day; double fw_use_month; double fw_use_five_min; double fw_cum_flow; double bw_cum_flow; double cum_flow; double bw_use_hour; double bw_use_day; double bw_use_month; double bw_use_five_min; double flow_rate; } bill_run_t; #define BIT0 1 #define BIT1 2 #define BIT2 4 #define BIT3 8 #define BIT4 0x10 #define BIT5 0x20 #define BIT6 0x40 #define BIT7 0x80 /////////////////////在初始化中调用////////////////////// extern void bill_init(void); extern void app_bill_run(void); ////////////////这两个子函数在计量中调用,向bill模块写入累计流量和瞬时流量///////////////////// extern void set_cur_flow_bill(double cum, double fw_cum, double bw_cum); extern void set_flow_rate_bill(double fw_vol, double bw_vol); ///////////////////////////////////////////////////////////////////// extern void set_month_used_bill(uint8_t year, uint8_t month, uint8_t day); extern void set_day_used_bill(uint8_t year, uint8_t month, uint8_t day); extern void set_hour_used_bill(uint8_t year, uint8_t month, uint8_t day, uint8_t hour); extern void set_5min_used_bill(uint8_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute); extern void set_cur_flow_bill(double cum, double fw_cum, double bw_cum); extern uint8_t get_hour_used_bill(uint8_t day, uint8_t hour, hour_bill_t *bill); extern uint8_t get_day_used_bill(uint8_t month, uint8_t day, bill_t *bill); extern uint8_t get_month_used_bill(uint8_t year, uint8_t month, bill_t *bill); extern uint8_t get_5min_used_bill(uint8_t day, uint8_t hour, uint8_t minute, hour_bill_t *bill); extern uint8_t CheckTime(uint8_t *); extern uint8_t Sum8(uint8_t *, uint16_t); extern bill_run_t BillRun; extern void init_month_cur_flow_bill(void); extern void init_day_cur_flow_bill(void); extern void init_hour_cur_flow_bill(void); extern void init_5min_cur_flow_bill(void); extern void init_cur_flow_bill(void); extern void save_cur_flow_bill(void); extern double CumFlow; extern double FwCumFlow; extern double BwCumFlow; extern double FlowVol; extern void Debug_bill(void); // extern uint8_t init_month_cum_flow(void); extern void clr_bill_struct_data(void); extern const uint8_t monthday[12]; extern int8_t SetRtcTime(tm_t *); extern unsigned char save_cur_flow_flag; // 置1触发保存当前累计量 extern int32_t get_hours_between_now(uint8_t year, uint8_t month, uint8_t day, uint8_t hour); extern int32_t get_days_between_now(uint8_t byear, uint8_t bmonth, uint8_t bday); extern void clear_all_record(void); // 清除所有记录 extern void clear_log(void); // 清除log extern void clear_bottom_data(void); extern void get_cur_flow_data(void); extern uint8_t StartUp; #ifdef DEBUG_BILL extern void verify_clear_operations(void); #endif #ifdef __cplusplus } #endif #endif