1643 lines
62 KiB
C
1643 lines
62 KiB
C
|
/****************************************************************************
|
||
|
|
||
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
||
|
|
||
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
||
|
be copied by any method or incorporated into another program without
|
||
|
the express written consent of Aerospace C.Power. This Information or any portion
|
||
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
||
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
||
|
liability for its use in any way and conveys no license or title under
|
||
|
any patent or copyright and makes no representation or warranty that this
|
||
|
Information is free from patent or copyright infringement.
|
||
|
|
||
|
****************************************************************************/
|
||
|
#ifndef IOT_SG_STA_FLASH_H
|
||
|
#define IOT_SG_STA_FLASH_H
|
||
|
|
||
|
#include "os_types_api.h"
|
||
|
#include "iot_utils_api.h"
|
||
|
#include "proto_645.h"
|
||
|
#include "proto_69845.h"
|
||
|
#include "iot_sg_fr.h"
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
extern "C" {
|
||
|
#endif
|
||
|
|
||
|
/* pack for the structures in the whole file */
|
||
|
#pragma pack(push) /* save the pack status */
|
||
|
#pragma pack(1) /* 1 byte align */
|
||
|
|
||
|
/* define number of meter day frozen */
|
||
|
#define IOT_SG_STA_METER_DF_CNT (7)
|
||
|
|
||
|
/* define number of meter impedance anomaly */
|
||
|
#define IOT_SG_STA_METER_IA_CNT (7)
|
||
|
|
||
|
|
||
|
/* define number of meter load curve data, for XIAN protocol */
|
||
|
#define IOT_SG_STA_METER_XIAN_LC_CNT_256B (576)
|
||
|
/* define number of meter load curve data in earse size 4K, XIAN protocol */
|
||
|
#define IOT_SG_STA_METER_XIAN_LC_CNT_4K (1440)
|
||
|
/* define number of meter load curve data, for GX protocol */
|
||
|
#define IOT_SG_STA_METER_GX_LC_CNT_256B (192)
|
||
|
/* define number of meter load curve data in earse size 4K, GX protocol */
|
||
|
#define IOT_SG_STA_METER_GX_LC_CNT_4K (288)
|
||
|
/* define number of meter load curve data, for NW protocol */
|
||
|
#define IOT_SG_STA_METER_NW_LC_CNT (192)
|
||
|
/* define number of meter line lose data, for AI management module */
|
||
|
#define IOT_SG_STA_METER_AI_LL_CNT (192)
|
||
|
/* define number of meter load curve data, for PW */
|
||
|
#define IOT_SG_STA_METER_PW_LC_CNT_256B (48)
|
||
|
/* define number of meter load curve data in earse size 4K, for PW */
|
||
|
#define IOT_SG_STA_METER_PW_LC_CNT_4K (288)
|
||
|
/* define number of meter clct data in earse size 4K, for GW */
|
||
|
#define IOT_SG_STA_METER_GW_CLCT_CNT_4K (50)
|
||
|
/* define number of meter clct data in earse size 256B, for GW */
|
||
|
#define IOT_SG_STA_METER_GW_CLCT_CNT_256B (53)
|
||
|
/* define number of meter edge computing, for NW custom */
|
||
|
#define IOT_SG_STA_METER_NW_EC_CNT (1)
|
||
|
|
||
|
/* define meter data type */
|
||
|
/* define meter day frozen data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_INVALID (0)
|
||
|
/* define meter day frozen data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_DF (1)
|
||
|
/* define meter hour frozen data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_HF (2)
|
||
|
/* define meter impedance anomaly data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_IA (3)
|
||
|
/* define meter gx load curve data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_GX_LC (4)
|
||
|
/* define meter xian load curve data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_XIAN_LC (5)
|
||
|
/* define meter GUANGDONG collection task data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_GUANGDONG_CT (6)
|
||
|
/* define meter GUANGZHOU state score data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_GUANGZHOU_SS (7)
|
||
|
/* define meter pw load curve data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_PW_LC (8)
|
||
|
/* define meter js sta mouth frozen data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_JS_MF (9)
|
||
|
/* define meter js sta day frozen data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_JS_DF (10)
|
||
|
/* define meter js sta 15min curve data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_JS_15MIN_CURVE (11)
|
||
|
/* define meter js sta minute curve data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_JS_1MIN_CURVE (12)
|
||
|
/* define meter fj freeze task data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_FJ_TASK (13)
|
||
|
/* define meter nw freeze task data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_NW_TASK (14)
|
||
|
/* define AI management module line lose type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_AI_LL (15)
|
||
|
/* define meter gw clct task data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_GW_TASK (16)
|
||
|
/* define health check task data type */
|
||
|
#define IOT_SG_STA_METER_DATA_TYPE_EC (17)
|
||
|
|
||
|
/* define meter collection task data identification count */
|
||
|
#define IOT_SG_STA_METER_CLCT_TASK_DI_CNT (4)
|
||
|
/* define meter collections task data identification count for gw */
|
||
|
#define IOT_SG_STA_METER_CLCT_TASK_DI_CNT_GW (20)
|
||
|
|
||
|
/* define max cnt of meter data in flash */
|
||
|
#define IOT_SG_STA_FLASH_METER_DATA_MAX_CNT (16)
|
||
|
|
||
|
/* defines the sg app sta flash storage meter cnt to FJ */
|
||
|
#define IOT_SG_STA_FLASH_SM_METER_CNT_FJ (1)
|
||
|
|
||
|
/* define max cnt of meter in flash */
|
||
|
#define IOT_SG_STA_FLASH_METER_MAX_CNT \
|
||
|
(IOT_SG_STA_FLASH_SM_METER_CNT_GUANGZHOU)
|
||
|
|
||
|
/* define meter energy data length */
|
||
|
#define IOT_SG_STA_METER_ENERGY_DATA_LEN (4)
|
||
|
|
||
|
/* define meter power data length */
|
||
|
#define IOT_SG_STA_METER_POWER_LEN (3)
|
||
|
|
||
|
/* define meter voltage data length */
|
||
|
#define IOT_SG_STA_METER_V_LEN (2)
|
||
|
|
||
|
/* define meter current data length */
|
||
|
#define IOT_SG_STA_METER_A_LEN (3)
|
||
|
|
||
|
/* define meter power data length */
|
||
|
#define IOT_SG_STA_METER_P_LEN (3)
|
||
|
|
||
|
/* define meter power factor data length */
|
||
|
#define IOT_SG_STA_METER_PF_LEN (2)
|
||
|
|
||
|
/* define data collection type */
|
||
|
#define IOT_SG_STA_METER_CLCT_TYPE_CURRENT (0)
|
||
|
#define IOT_SG_STA_METER_CLCT_TYPE_FREEZE_TIME (2)
|
||
|
#define IOT_SG_STA_METER_CLCT_TYPE_INTER_TIME (3)
|
||
|
/* define freeze task record uint max length for fujian protocol */
|
||
|
#define IOT_SG_STA_METER_FJ_TASK_RECORD_UINT_LEN (128)
|
||
|
/* define freeze task cfg info max length for fujian protocol */
|
||
|
#define IOT_SG_STA_METER_FJ_TASK_CFG_MAX_LEN (100)
|
||
|
|
||
|
/* define meter collection task desc max length */
|
||
|
#define IOT_SG_STA_METER_TASK_DESC_MAX_LEN (256)
|
||
|
|
||
|
/* define CRC value length in flash */
|
||
|
#define IOT_SG_STA_FLASH_CRC_LENGTH (1)
|
||
|
|
||
|
typedef struct _iot_sg_meter_unit_time {
|
||
|
/* data time stamp */
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
} iot_sg_meter_unit_time_t;
|
||
|
|
||
|
typedef struct _iot_sg_sta_drv_score_bit_map {
|
||
|
/* clock battery undervoltage */
|
||
|
uint16_t clock_battery : 1,
|
||
|
/* protocol version number invalid */
|
||
|
proto_ver : 1,
|
||
|
/* manufacturing date far away */
|
||
|
mfg_date : 1,
|
||
|
/* memory failure or damage */
|
||
|
memory : 1,
|
||
|
/* control loop error */
|
||
|
ctrl_loop : 1,
|
||
|
/* initialization error of internal card */
|
||
|
inter_card : 1,
|
||
|
/* internal program error */
|
||
|
inter_program : 1,
|
||
|
/* voltage fault */
|
||
|
v_fault : 1,
|
||
|
/* open covers time too long */
|
||
|
open_covers : 1,
|
||
|
/* program record time too long */
|
||
|
program : 1,
|
||
|
/* positive energy abnormal */
|
||
|
pos_energy : 1,
|
||
|
/* too frequent power down */
|
||
|
pd_record : 1,
|
||
|
/* reserved for future */
|
||
|
reserved : 4;
|
||
|
} iot_sg_sta_drv_score_bit_map_t;
|
||
|
|
||
|
/* meter state score data structure in flash */
|
||
|
typedef struct _iot_sg_sta_drv_meter_ss_data {
|
||
|
/* data time stamp */
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
/* state score */
|
||
|
uint8_t score;
|
||
|
/* voltage fault days */
|
||
|
uint16_t v_fault_days;
|
||
|
/* program enable days */
|
||
|
uint16_t program_en_days;
|
||
|
/* power down days */
|
||
|
uint16_t pd_days;
|
||
|
/* state score bit map */
|
||
|
iot_sg_sta_drv_score_bit_map_t bit_map;
|
||
|
/* CRC8 check code, check from data time stamp to bit_map */
|
||
|
uint8_t crc;
|
||
|
} iot_sg_sta_drv_meter_ss_data_t;
|
||
|
|
||
|
/* meter header structure in flash */
|
||
|
typedef struct _iot_sg_sta_drv_meter_hdr {
|
||
|
/* sn of meter */
|
||
|
uint32_t sn;
|
||
|
/* mac address of meter */
|
||
|
uint8_t mac[IOT_MAC_ADDR_LEN];
|
||
|
/* cnt of meter data */
|
||
|
uint8_t cnt;
|
||
|
/* length of all meter data */
|
||
|
uint32_t data_len;
|
||
|
/* CRC8 check code, check from mac to cnt */
|
||
|
uint8_t hdr_crc;
|
||
|
} iot_sg_sta_drv_meter_hdr_t;
|
||
|
|
||
|
/* meter data headr structure in flash */
|
||
|
typedef struct _iot_sg_sta_drv_meter_data_hdr {
|
||
|
/* type of meter data, see IOT_SG_STA_METER_DATA_TYPE_XX */
|
||
|
uint8_t data_type;
|
||
|
/* length of meter data, see IOT_SG_STA_METER_TYPE_XXX */
|
||
|
uint32_t data_len;
|
||
|
/* reserve for future */
|
||
|
uint16_t reserve;
|
||
|
/* CRC8 check code, check from data_type to crc */
|
||
|
uint8_t hdr_crc;
|
||
|
} iot_sg_sta_drv_meter_data_hdr_t;
|
||
|
|
||
|
/* meter data identification info structure in flash */
|
||
|
typedef struct _iot_sg_sta_drv_meter_di_info {
|
||
|
/* di */
|
||
|
uint32_t di;
|
||
|
/* 645 request control code */
|
||
|
uint8_t control;
|
||
|
/* data len */
|
||
|
uint8_t data_len;
|
||
|
} iot_sg_sta_drv_meter_di_info_t;
|
||
|
|
||
|
/* meter collection task info structure, for guangdong x4 protocol */
|
||
|
typedef struct _iot_sg_sta_drv_meter_x4_task_info {
|
||
|
/* cco address, big-endian */
|
||
|
uint8_t cco_addr[IOT_MAC_ADDR_LEN];
|
||
|
/* start time */
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
/* task id */
|
||
|
uint8_t id;
|
||
|
/* pm type, see IOT_SG_EXT_CLCT_TASK_PM_TYPE_XXX */
|
||
|
uint8_t pm_type : 3,
|
||
|
/* pm protocol type, see IOT_SG_EXT_CLCT_TASK_PROTO_TYPE_XXX */
|
||
|
proto_type : 5;
|
||
|
/* task timout time, uint is 1s */
|
||
|
uint16_t timeout;
|
||
|
/* collection base time */
|
||
|
uint16_t base_min : 6,
|
||
|
base_hour : 5,
|
||
|
base_day : 5;
|
||
|
/* collection period, see IOT_SG_EXT_CLCT_TASK_PERIOD_XXX */
|
||
|
uint8_t period : 5,
|
||
|
/* data identification count */
|
||
|
di_cnt : 3;
|
||
|
/* data identification info */
|
||
|
iot_sg_sta_drv_meter_di_info_t di_info[IOT_SG_STA_METER_CLCT_TASK_DI_CNT];
|
||
|
/* add collection task info crc */
|
||
|
uint16_t crc;
|
||
|
} iot_sg_sta_drv_meter_x4_task_info_t;
|
||
|
|
||
|
typedef struct _iot_sg_sta_drv_meter_gw_di_info {
|
||
|
/* data identification */
|
||
|
uint32_t di;
|
||
|
/* data item data unit length */
|
||
|
uint8_t data_len;
|
||
|
} iot_sg_sta_drv_meter_gw_di_info_t;
|
||
|
|
||
|
/* info for minute level data collection task in flash */
|
||
|
typedef struct _iot_sg_sta_drv_meter_gw_clct_task_info {
|
||
|
/* task id, range is 1 ~ 8, Otherwise, it is invalid. */
|
||
|
uint8_t id;
|
||
|
/* power meter phase type, see IOT_SG_STA_DEV_TYPE_XXX */
|
||
|
uint8_t pm_type;
|
||
|
/* power meter protocol type id, see IOT_SG_STA_DATA_TYPE_XXX */
|
||
|
uint8_t proto_type;
|
||
|
/* task clct period, unit is minute */
|
||
|
uint8_t period;
|
||
|
/* clct task data identification count, max to
|
||
|
* IOT_SG_STA_METER_CLCT_TASK_DI_CNT_GW
|
||
|
* However, the size of the entire structure cannot exceed
|
||
|
* IOT_SG_STA_METER_TASK_DESC_MAX_LEN
|
||
|
*/
|
||
|
uint8_t di_cnt;
|
||
|
/* task clct data identification info */
|
||
|
iot_sg_sta_drv_meter_gw_di_info_t
|
||
|
di_info[IOT_SG_STA_METER_CLCT_TASK_DI_CNT_GW];
|
||
|
} iot_sg_sta_drv_meter_gw_clct_task_info_t;
|
||
|
|
||
|
/* meter collection task unit data include
|
||
|
* iot_sg_sta_drv_meter_ct_unit_head_t and
|
||
|
* variable iot_sg_sta_drv_meter_ct_unit_data_t and
|
||
|
* iot_sg_sta_drv_meter_ct_unit_tail_t.
|
||
|
*/
|
||
|
|
||
|
/* meter collection task unit data head structure in flash */
|
||
|
typedef struct _iot_sg_sta_drv_meter_ct_unit_head {
|
||
|
/* data time stamp */
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
/* unit data */
|
||
|
uint8_t data[0];
|
||
|
} iot_sg_sta_drv_meter_ct_unit_head_t;
|
||
|
|
||
|
/* meter collection task unit data structure in flash */
|
||
|
typedef struct _iot_sg_sta_drv_meter_ct_unit_data {
|
||
|
/* 645 response control code */
|
||
|
uint8_t control;
|
||
|
/* 645 response cs */
|
||
|
uint8_t cs;
|
||
|
/* 645 response original data */
|
||
|
uint8_t data[0];
|
||
|
} iot_sg_sta_drv_meter_ct_unit_data_t;
|
||
|
|
||
|
/* meter collection task unit data tail structure in flash */
|
||
|
typedef struct _iot_sg_sta_drv_meter_ct_unit_tail {
|
||
|
/* CRC8 check code, check from unit data head to unit data */
|
||
|
uint8_t crc;
|
||
|
} iot_sg_sta_drv_meter_ct_unit_tail_t;
|
||
|
|
||
|
/* meter freeze collection task info structure for fujiang protocol */
|
||
|
typedef struct _iot_sg_sta_drv_meter_fj_task_info {
|
||
|
/* task id */
|
||
|
uint8_t id;
|
||
|
/* type of task, see PROTO_645_FJ_TASK_TYPE_XXX */
|
||
|
uint8_t type;
|
||
|
/* task cycle value */
|
||
|
uint16_t value : 11,
|
||
|
/* task cycle unit, see PROTO_645_FJ_TASK_CYCLE_UNIT_TYPE_XXX */
|
||
|
unit : 3,
|
||
|
/* reserved */
|
||
|
rsvd_1 : 2;
|
||
|
/* read delay, unit is 1s */
|
||
|
uint8_t delay;
|
||
|
/* data saving times */
|
||
|
uint16_t save_cnt;
|
||
|
/* receive response data total length */
|
||
|
uint8_t rec_total_len;
|
||
|
/* task priority, only for PROTO_645_FJ_TASK_TYPE_FREEZE.
|
||
|
* 0 mean low priority, 1 mean high priority
|
||
|
*/
|
||
|
uint8_t prio : 1,
|
||
|
/* task data storage mode.
|
||
|
* 0 means power down storage.
|
||
|
* 1 means power down not storage.
|
||
|
*/
|
||
|
storage_mode : 1,
|
||
|
/* reserved */
|
||
|
rsvd_2 : 1,
|
||
|
/* data report enable
|
||
|
* 0 mean data not report.
|
||
|
* 1 mean data report
|
||
|
*/
|
||
|
flag_rpt : 1,
|
||
|
/* reserved */
|
||
|
rsvd_3 : 4;
|
||
|
/* task exec times, 1~65535. 0xFFFF mean infinite loop. */
|
||
|
uint16_t exe_cnt;
|
||
|
/* length of task_info_desc */
|
||
|
uint8_t desc_len;
|
||
|
/* task info desc
|
||
|
* when type is PROTO_645_FJ_TASK_TYPE_FREEZE,
|
||
|
* see proto_645_fj_task_set_freeze_hdr_t.
|
||
|
* when type is PROTO_645_FJ_TASK_TYPE_INCON_RPT,
|
||
|
* see proto_645_fj_task_set_incon_rpt_hdr_t.
|
||
|
* when type is PROTO_645_FJ_TASK_TYPE_CROSS_RPT,
|
||
|
* see proto_645_fj_task_set_cross_rpt_t.
|
||
|
* when type is PROTO_645_FJ_TASK_TYPE_CHG_RPT,
|
||
|
* see proto_645_fj_task_set_change_rpt_hdr_t.
|
||
|
*/
|
||
|
uint8_t desc[IOT_SG_STA_METER_FJ_TASK_CFG_MAX_LEN];
|
||
|
} iot_sg_sta_drv_meter_fj_task_info_t;
|
||
|
|
||
|
/* meter collection task header structure in flash */
|
||
|
typedef struct _iot_sg_sta_drv_meter_ct_hdr {
|
||
|
/* task id */
|
||
|
uint8_t task_id;
|
||
|
/* collection task desc, see iot_sg_sta_drv_meter_fj_task_info_t or
|
||
|
* iot_sg_sta_drv_meter_x4_task_info_t
|
||
|
*/
|
||
|
uint8_t desc[IOT_SG_STA_METER_TASK_DESC_MAX_LEN];
|
||
|
/* collection task add sn */
|
||
|
uint16_t sn;
|
||
|
/* unit data structure len */
|
||
|
uint16_t unit_len;
|
||
|
/* unit data count */
|
||
|
uint16_t unit_cnt;
|
||
|
/* CRC8 check code, check from id to di_info */
|
||
|
uint8_t hdr_crc;
|
||
|
} iot_sg_sta_drv_meter_ct_hdr_t;
|
||
|
|
||
|
/* meter collection task unit time stamp with second structure */
|
||
|
typedef struct _iot_sg_meter_unit_time_with_sec {
|
||
|
/* data time stamp */
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
uint8_t second;
|
||
|
} iot_sg_meter_unit_time_with_sec_t;
|
||
|
|
||
|
/* meter collection task unit data structure in flash for fujian protocol */
|
||
|
typedef struct _iot_sg_sta_drv_meter_fj_task_unit {
|
||
|
/* unit time stamp */
|
||
|
iot_sg_meter_unit_time_with_sec_t uint_time;
|
||
|
/* save cnt */
|
||
|
uint16_t save_cnt;
|
||
|
/* storage times to task response */
|
||
|
uint16_t storage_times;
|
||
|
/* task report cnt within 24h */
|
||
|
uint8_t rpt_cnt;
|
||
|
/* total response data cnt in uint data */
|
||
|
uint8_t resp_data_cnt;
|
||
|
/* Number of executables remaining */
|
||
|
uint16_t exe_cnt_remain;
|
||
|
/* valid data length in uint data */
|
||
|
uint8_t valid_len;
|
||
|
/* unit data, see iot_sg_sta_drv_meter_fj_unit_data_t */
|
||
|
uint8_t uint_data[IOT_SG_STA_METER_FJ_TASK_RECORD_UINT_LEN];
|
||
|
} iot_sg_sta_drv_meter_fj_task_unit_t;
|
||
|
|
||
|
/* unit data structure in iot_sg_sta_drv_meter_fj_task_unit_t */
|
||
|
typedef struct _iot_sg_sta_drv_meter_fj_unit_data {
|
||
|
/* 645 response data len */
|
||
|
uint8_t len;
|
||
|
/* 645 response original data */
|
||
|
uint8_t data[0];
|
||
|
} iot_sg_sta_drv_meter_fj_unit_data_t;
|
||
|
|
||
|
/* meter one day frozen data structure in flash */
|
||
|
typedef struct _iot_sg_meter_one_df {
|
||
|
/* positive active energy data */
|
||
|
proto_645_07_energy_data_t positive;
|
||
|
/* negative active energy data */
|
||
|
proto_645_07_energy_data_t negative;
|
||
|
/* combined reactive energy data 1 */
|
||
|
proto_645_07_energy_data_t reactive1;
|
||
|
/* combined reactive energy data 2 */
|
||
|
proto_645_07_energy_data_t reactive2;
|
||
|
} iot_sg_meter_one_df_t;
|
||
|
|
||
|
/* meter seven day frozen data structure in flash */
|
||
|
typedef struct _iot_sg_sta_drv_meter_df {
|
||
|
/* last 1 day forzen data time */
|
||
|
proto_645_07_frozen_time_t last1_time;
|
||
|
/* last 7 day forzen data */
|
||
|
iot_sg_meter_one_df_t last[IOT_SG_STA_METER_DF_CNT];
|
||
|
} iot_sg_sta_drv_meter_df_t;
|
||
|
|
||
|
/* meter hour frozen benchmark data structure in flash */
|
||
|
typedef struct _iot_sg_sta_drv_meter_hf_mark {
|
||
|
/* hour forzen data time and flag of hour frozen data validity */
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
/* cnt of data using this benchmark data as a benchmark */
|
||
|
uint8_t cnt;
|
||
|
/* positive active energy data */
|
||
|
proto_645_07_hf_energy_t positive;
|
||
|
/* negative active energy data */
|
||
|
proto_645_07_hf_energy_t negative;
|
||
|
} iot_sg_sta_drv_meter_hf_mark_t;
|
||
|
|
||
|
/* meter hour frozen data structure in flash */
|
||
|
typedef struct _iot_sg_sta_drv_meter_hf {
|
||
|
/* time interval between the last and current freezing data */
|
||
|
uint8_t time_interval;
|
||
|
/* positive active energy interval between the last and current
|
||
|
* freezing data
|
||
|
*/
|
||
|
/* positive interval integer, max integer = 8191 */
|
||
|
uint16_t positive_interval_integer : 13,
|
||
|
/* positive interval decimal high 3 bit, max decimal = 99 */
|
||
|
positive_interval_decimal_h: 3;
|
||
|
/* negative active energy interval between the last and current
|
||
|
* freezing data
|
||
|
*/
|
||
|
/* negative interval integer, max integer = 8191 */
|
||
|
uint16_t negative_interval_integer : 13,
|
||
|
/* negative interval decimal high 3 bit, max decimal = 99 */
|
||
|
negative_interval_decimal_h: 3;
|
||
|
/* positive interval decimal low 4 bit */
|
||
|
uint8_t positive_interval_decimal_l: 4,
|
||
|
/* negative interval decimal low 4 bit */
|
||
|
negative_interval_decimal_l: 4;
|
||
|
} iot_sg_sta_drv_meter_hf_t;
|
||
|
|
||
|
/* meter impedance anomaly data structure in flash */
|
||
|
typedef struct _iot_sg_sta_drv_meter_ia {
|
||
|
/* last 7 impedance anomaly data */
|
||
|
proto_645_07_ia_t last[IOT_SG_STA_METER_IA_CNT];
|
||
|
} iot_sg_sta_drv_meter_ia_t;
|
||
|
|
||
|
/* data structure for data collection of
|
||
|
* load curve per unit time. for GX protocol.
|
||
|
*/
|
||
|
typedef struct _iot_sg_meter_gx_lc_uint_data {
|
||
|
/* data time stamp */
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
/* voltage in phase a */
|
||
|
uint8_t v[PROTO_645_V_LEN];
|
||
|
} iot_sg_meter_gx_lc_uint_data_t;
|
||
|
|
||
|
/* data structure for data collection of
|
||
|
* load curve per unit time. for xian protocol.
|
||
|
*/
|
||
|
typedef struct _iot_sg_meter_lc_uint_xian_data {
|
||
|
/* data time stamp */
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
/* voltage */
|
||
|
proto_645_v_t v;
|
||
|
/* current */
|
||
|
proto_645_07_a_t i;
|
||
|
/* neutral current. use 3 bytes of BCD code to represent */
|
||
|
uint8_t n[PROTO_645_07_A_LEN];
|
||
|
/* active power */
|
||
|
proto_645_07_p_t active_power;
|
||
|
/* reactive power */
|
||
|
proto_645_07_p_t reactive_power;
|
||
|
/* power factor */
|
||
|
proto_645_07_pf_t power_factor;
|
||
|
/* combined active power */
|
||
|
proto_645_07_energy_data_t ca_power;
|
||
|
/* forward direction active power */
|
||
|
proto_645_07_energy_data_t fda_power;
|
||
|
/* backward direction active power */
|
||
|
proto_645_07_energy_data_t bda_power;
|
||
|
/* combined total reactive power 1. use 3 bytes of BCD code to represent */
|
||
|
uint8_t cr_power1[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* combined total reactive power 2. use 3 bytes of BCD code to represent */
|
||
|
uint8_t cr_power2[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* 1st Phase Line total reactive power.
|
||
|
* use 3 bytes of BCD code to represent.
|
||
|
*/
|
||
|
uint8_t re_1st_power[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* 2st Phase Line total reactive power.
|
||
|
* use 3 bytes of BCD code to represent.
|
||
|
*/
|
||
|
uint8_t re_2nd_power[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* 3st Phase Line total reactive power.
|
||
|
* use 3 bytes of BCD code to represent.
|
||
|
*/
|
||
|
uint8_t re_3rd_power[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* 4st Phase Line total reactive power.
|
||
|
* use 3 bytes of BCD code to represent.
|
||
|
*/
|
||
|
uint8_t re_4th_power[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* active power demand */
|
||
|
uint8_t ap_demand[PROTO_645_07_P_LEN];
|
||
|
/* reactive power demand */
|
||
|
uint8_t rp_demand[PROTO_645_07_P_LEN];
|
||
|
/* current total pos-active power demand data with time */
|
||
|
uint8_t pos_ap_demand[PROTO_645_07_CURR_PD_LEN];
|
||
|
/* current total neg-active power demand data with time */
|
||
|
uint8_t neg_ap_demand[PROTO_645_07_CURR_PD_LEN];
|
||
|
/* positive active a phase energy */
|
||
|
uint8_t pos_a[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* positive active b phase energy */
|
||
|
uint8_t pos_b[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* positive active c phase energy */
|
||
|
uint8_t pos_c[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
} iot_sg_meter_lc_uint_xian_data_t;
|
||
|
|
||
|
/* data structure for data collection of
|
||
|
* load curve per unit time. for PW.
|
||
|
*/
|
||
|
typedef struct _iot_sg_meter_pw_lc_uint_data {
|
||
|
/* data time stamp */
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
/* voltage */
|
||
|
proto_645_v_t v;
|
||
|
/* current */
|
||
|
proto_645_07_a_t i;
|
||
|
/* active power */
|
||
|
proto_645_07_p_t active_power;
|
||
|
/* reactive power */
|
||
|
proto_645_07_p_t reactive_power;
|
||
|
/* power factor */
|
||
|
proto_645_07_pf_t power_factor;
|
||
|
/* forward active energy, uint is 0.01kWh */
|
||
|
uint8_t ept_pos[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* reverse active energy, uint is 0.00kWh */
|
||
|
uint8_t ept_neg[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
} iot_sg_meter_pw_lc_uint_data_t;
|
||
|
|
||
|
typedef struct _iot_sg_meter_energy_data {
|
||
|
/* use 4 bytes of BCD code to represent total energy value. for example,
|
||
|
* 123456.78KWh uses 4 bytes of BCD code to represent the following
|
||
|
* 0x12, 0x34, 0x56, 0x78.
|
||
|
*/
|
||
|
uint8_t total[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* use 4 bytes of BCD code to represent the rate 1 energy value.
|
||
|
* for example, 123456.78KWh uses 4 bytes of BCD code to
|
||
|
* represent the following 0x12, 0x34, 0x56, 0x78.
|
||
|
*/
|
||
|
uint8_t rate_1[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* use 4 bytes of BCD code to represent the rate 2 energy value.
|
||
|
* for example, 123456.78KWh uses 4 bytes of BCD code to
|
||
|
* represent the following 0x12, 0x34, 0x56, 0x78.
|
||
|
*/
|
||
|
uint8_t rate_2[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* use 4 bytes of BCD code to represent the rate 3 energy value.
|
||
|
* for example, s123456.78KWh uses 4 bytes of BCD code to
|
||
|
* represent the following 0x12, 0x34, 0x56, 0x78.
|
||
|
*/
|
||
|
uint8_t rate_3[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* use 4 bytes of BCD code to represent the rate 3 energy value.
|
||
|
* for example, s123456.78KWh uses 4 bytes of BCD code to
|
||
|
* represent the following 0x12, 0x34, 0x56, 0x78.
|
||
|
*/
|
||
|
uint8_t rate_4[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
} iot_sg_meter_energy_data_t;
|
||
|
|
||
|
/* meter frozen maximum demand and happen time data struct */
|
||
|
typedef struct _iot_sg_meter_max_demand_and_ht {
|
||
|
/* maximum demand */
|
||
|
uint8_t max_demand[IOT_SG_STA_METER_POWER_LEN];
|
||
|
/* happen time */
|
||
|
uint8_t minute;
|
||
|
uint8_t hour;
|
||
|
uint8_t day;
|
||
|
uint8_t month;
|
||
|
uint8_t year;
|
||
|
} iot_sg_meter_max_demand_and_ht_t;
|
||
|
|
||
|
/* meter running status word data struct */
|
||
|
typedef struct _iot_sg_meter_rs_word {
|
||
|
/* running status valid flag, 0 is valid 0xff is invalid */
|
||
|
uint8_t valid_flag;
|
||
|
/* the running status word 1 for the electricity meter */
|
||
|
proto_645_07_rs_word_1_t rs_word_1;
|
||
|
/* the running status word 2 for the electricity meter */
|
||
|
proto_645_07_rs_word_2_t rs_word_2;
|
||
|
/* the running status word 3 for the electricity meter */
|
||
|
proto_645_07_rs_word_3_t rs_word_3;
|
||
|
/* the running status word 4 for the electricity meter */
|
||
|
proto_645_07_rs_word_456_t rs_word_4;
|
||
|
/* the running status word 4 for the electricity meter */
|
||
|
proto_645_07_rs_word_456_t rs_word_5;
|
||
|
/* the running status word 4 for the electricity meter */
|
||
|
proto_645_07_rs_word_456_t rs_word_6;
|
||
|
/* the running status word 7 for the electricity meter */
|
||
|
proto_645_07_rs_word_7_t rs_word_7;
|
||
|
} iot_sg_meter_rs_word_t;
|
||
|
|
||
|
/* data structure for data collection of frozen data per unit time.
|
||
|
* for jiangsu protocol.
|
||
|
*/
|
||
|
typedef struct _iot_sg_meter_js_frozen_uint_data {
|
||
|
/* data time stamp */
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
/* forward active energy */
|
||
|
iot_sg_meter_energy_data_t ept_pos;
|
||
|
/* reverse active energy */
|
||
|
iot_sg_meter_energy_data_t ept_neg;
|
||
|
/* combined reactive energy data 1 */
|
||
|
iot_sg_meter_energy_data_t cre1;
|
||
|
/* combined reactive energy data 2 */
|
||
|
iot_sg_meter_energy_data_t cre2;
|
||
|
/* 1st quadrant reactive energy, uint is 0.01kWh */
|
||
|
iot_sg_meter_energy_data_t re_1st_power;
|
||
|
/* 2st quadrant reactive energy, uint is 0.01kWh */
|
||
|
iot_sg_meter_energy_data_t re_2nd_power;
|
||
|
/* 3st quadrant reactive energy, uint is 0.01kWh */
|
||
|
iot_sg_meter_energy_data_t re_3rd_power;
|
||
|
/* 4st quadrant reactive energy, uint is 0.01kWh */
|
||
|
iot_sg_meter_energy_data_t re_4th_power;
|
||
|
/* forward active maximum demand and happen time */
|
||
|
iot_sg_meter_max_demand_and_ht_t pos_act_dem_time;
|
||
|
/* reverse active maximum demand and happen time */
|
||
|
iot_sg_meter_max_demand_and_ht_t neg_atc_dem_time;
|
||
|
/* combined reactive1 maximum demand and happen time */
|
||
|
iot_sg_meter_max_demand_and_ht_t com_react1_dem_time;
|
||
|
/* combined reactive2 maximum demand and happen time */
|
||
|
iot_sg_meter_max_demand_and_ht_t com_reatc2_dem_time;
|
||
|
/* voltage */
|
||
|
proto_645_v_t v;
|
||
|
/* current */
|
||
|
proto_645_07_a_t i;
|
||
|
/* neutral current. use 3 bytes of BCD code to represent */
|
||
|
uint8_t n[PROTO_645_07_A_LEN];
|
||
|
/* active power */
|
||
|
proto_645_07_p_t active_power;
|
||
|
/* reactive power */
|
||
|
proto_645_07_p_t reactive_power;
|
||
|
/* power factor */
|
||
|
proto_645_07_pf_t power_factor;
|
||
|
/* running status word */
|
||
|
iot_sg_meter_rs_word_t rs_word;
|
||
|
} iot_sg_meter_js_frozen_uint_data_t;
|
||
|
|
||
|
/* meter voltage data struct */
|
||
|
typedef struct _iot_sg_meter_voltage {
|
||
|
/* A phase voltage.use 2 bytes of BCD code to represent the voltage.
|
||
|
* for example, 220.0V uses 2 bytes of BCD code to represent
|
||
|
* the following 0x22, 0x00.
|
||
|
*/
|
||
|
uint8_t a[IOT_SG_STA_METER_V_LEN];
|
||
|
/* B phase voltage.use 2 bytes of BCD code to represent the voltage.
|
||
|
* for example, 220.0V uses 2 bytes of BCD code to represent
|
||
|
* the following 0x22, 0x00.
|
||
|
*/
|
||
|
uint8_t b[IOT_SG_STA_METER_V_LEN];
|
||
|
/* C phase voltage.use 2 bytes of BCD code to represent the voltage.
|
||
|
* for example, 220.0V uses 2 bytes of BCD code to represent
|
||
|
* the following 0x22, 0x00.
|
||
|
*/
|
||
|
uint8_t c[IOT_SG_STA_METER_V_LEN];
|
||
|
} iot_sg_meter_voltage_t;
|
||
|
|
||
|
/* meter current data struct */
|
||
|
typedef struct _iot_sg_meter_current {
|
||
|
/* A phase current.use 3 bytes of BCD code to represent the current.
|
||
|
* for example, 123.456A uses 3 bytes of BCD code to represent
|
||
|
* the following 0x12, 0x34, 0x56.
|
||
|
*/
|
||
|
uint8_t a[IOT_SG_STA_METER_A_LEN];
|
||
|
/* B phase current.use 3 bytes of BCD code to represent the current.
|
||
|
* for example, 123.456A uses 3 bytes of BCD code to represent
|
||
|
* the following 0x12, 0x34, 0x56.
|
||
|
*/
|
||
|
uint8_t b[IOT_SG_STA_METER_A_LEN];
|
||
|
/* C phase current.use 3 bytes of BCD code to represent the current.
|
||
|
* for example, 123.456A uses 3 bytes of BCD code to represent
|
||
|
* the following 0x12, 0x34, 0x56.
|
||
|
*/
|
||
|
uint8_t c[IOT_SG_STA_METER_A_LEN];
|
||
|
} iot_sg_meter_current_t;
|
||
|
|
||
|
/* meter power factor data struct */
|
||
|
typedef struct _iot_sg_meter_power_factor {
|
||
|
/* total power factor.use 2 bytes of BCD code to represent the power
|
||
|
* factor. for example, 0.999 uses 2 bytes of BCD code to represent
|
||
|
* the following 0x09, 0x99.
|
||
|
*/
|
||
|
uint8_t total[IOT_SG_STA_METER_PF_LEN];
|
||
|
/* A phase power factor.use 2 bytes of BCD code to represent the power
|
||
|
* factor. for example, 0.999 uses 2 bytes of BCD code to represent
|
||
|
* the following 0x09, 0x99.
|
||
|
*/
|
||
|
uint8_t a[IOT_SG_STA_METER_PF_LEN];
|
||
|
/* B phase power factor.use 2 bytes of BCD code to represent the power
|
||
|
* factor. for example, 0.999 uses 2 bytes of BCD code to represent
|
||
|
* the following 0x09, 0x99.
|
||
|
*/
|
||
|
uint8_t b[IOT_SG_STA_METER_PF_LEN];
|
||
|
/* C phase power factor.use 2 bytes of BCD code to represent the power
|
||
|
* factor. for example, 0.999 uses 2 bytes of BCD code to represent
|
||
|
* the following 0x09, 0x99.
|
||
|
*/
|
||
|
uint8_t c[IOT_SG_STA_METER_PF_LEN];
|
||
|
} iot_sg_meter_power_factor_t;
|
||
|
|
||
|
/* meter current time */
|
||
|
typedef struct _iot_sg_meter_cur_time {
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
uint8_t second;
|
||
|
} iot_sg_meter_cur_time_t;
|
||
|
|
||
|
/* data structure for data collection
|
||
|
* 1 minute curve data per unit time. for jiangsu protocol.
|
||
|
* uint length is 152 byte. for jiangsu protocol.
|
||
|
*/
|
||
|
typedef struct _iot_sg_meter_js_min_curve_uint_data {
|
||
|
/* data time stamp */
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
/* voltage */
|
||
|
proto_645_v_t v;
|
||
|
/* current */
|
||
|
proto_645_07_a_t i;
|
||
|
/* neutral current. use 3 bytes of BCD code to represent */
|
||
|
uint8_t n[PROTO_645_07_A_LEN];
|
||
|
/* active power */
|
||
|
proto_645_07_p_t active_power;
|
||
|
/* reactive power */
|
||
|
proto_645_07_p_t reactive_power;
|
||
|
/* power factor */
|
||
|
proto_645_07_pf_t power_factor;
|
||
|
/* current meter time */
|
||
|
iot_sg_meter_cur_time_t time;
|
||
|
} iot_sg_meter_js_min_curve_uint_data_t;
|
||
|
|
||
|
/* data structure for data collection of frozen data per unit time.
|
||
|
* for jiangsu protocol. only for single-phase module
|
||
|
*/
|
||
|
typedef struct _iot_sg_meter_js_sig_frozen_uint_data {
|
||
|
/* data time stamp */
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
/* forward active energy */
|
||
|
uint8_t ept_pos[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* reverse active energy */
|
||
|
uint8_t ept_neg[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* combined reactive energy data 1 */
|
||
|
uint8_t cre1[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* combined reactive energy data 2 */
|
||
|
uint8_t cre2[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* voltage */
|
||
|
uint8_t v[PROTO_645_V_LEN];
|
||
|
/* current */
|
||
|
uint8_t i[PROTO_645_07_A_LEN];
|
||
|
/* neutral current. use 3 bytes of BCD code to represent */
|
||
|
uint8_t n[PROTO_645_07_A_LEN];
|
||
|
/* active power */
|
||
|
uint8_t active_power[PROTO_645_07_P_LEN];
|
||
|
/* reactive power */
|
||
|
uint8_t reactive_power[PROTO_645_07_P_LEN];
|
||
|
/* power factor */
|
||
|
uint8_t power_factor[PROTO_645_07_PF_LEN];
|
||
|
/* current meter time */
|
||
|
iot_sg_meter_cur_time_t time;
|
||
|
} iot_sg_meter_js_sig_frozen_uint_data_t;
|
||
|
|
||
|
/* meter current active and reactive power demand */
|
||
|
typedef struct _iot_sg_meter_cur_demand_all {
|
||
|
/* active power demand */
|
||
|
uint8_t ap_demand[PROTO_645_07_P_LEN];
|
||
|
/* reactive power demand */
|
||
|
uint8_t rp_demand[PROTO_645_07_P_LEN];
|
||
|
} iot_sg_meter_cur_demand_all_t;
|
||
|
|
||
|
/* meter total energy data block */
|
||
|
typedef struct _iot_sg_meter_total_energy_all {
|
||
|
/* forward active total energy */
|
||
|
uint8_t ept_pos_t[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* reverse active total energy */
|
||
|
uint8_t ept_neg_t[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* combined reactive total energy data 1 */
|
||
|
uint8_t cre1_t[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* combined reactive total energy data 2 */
|
||
|
uint8_t cre2_t[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
} iot_sg_meter_total_energy_all_t;
|
||
|
|
||
|
/* meter quadrant reactive total energy data block */
|
||
|
typedef struct _iot_sg_meter_qr_total_energy_all {
|
||
|
/* 1st quadrant reactive energy total, uint is 0.01kWh */
|
||
|
uint8_t re_1st_et[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* 2st quadrant reactive energy total, uint is 0.01kWh */
|
||
|
uint8_t re_2st_et[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* 3st quadrant reactive energy total, uint is 0.01kWh */
|
||
|
uint8_t re_3st_et[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
/* 4st quadrant reactive energy total, uint is 0.01kWh */
|
||
|
uint8_t re_4st_et[IOT_SG_STA_METER_ENERGY_DATA_LEN];
|
||
|
} iot_sg_meter_qr_total_energy_all_t;
|
||
|
|
||
|
/* data structure for data collection of
|
||
|
* load curve per unit time. for NW protocol.
|
||
|
*/
|
||
|
typedef struct _iot_sg_meter_lc_uint_nw_data {
|
||
|
/* data time stamp */
|
||
|
uint32_t year : 7,
|
||
|
month : 4,
|
||
|
day : 5,
|
||
|
hour : 5,
|
||
|
minute : 6,
|
||
|
reserve: 5;
|
||
|
/* voltage */
|
||
|
proto_645_v_t v;
|
||
|
/* current */
|
||
|
proto_645_07_a_t i;
|
||
|
/* neutral current. use 3 bytes of BCD code to represent */
|
||
|
uint8_t n[PROTO_645_07_A_LEN];
|
||
|
/* active power */
|
||
|
proto_645_07_p_t active_power;
|
||
|
/* reactive power */
|
||
|
proto_645_07_p_t reactive_power;
|
||
|
/* apparent power */
|
||
|
proto_645_07_p_t apparent_power;
|
||
|
/* power factor */
|
||
|
proto_645_07_pf_t power_factor;
|
||
|
/* phase angle */
|
||
|
proto_645_07_phase_angle_t phase_angle;
|
||
|
/* voltage waveform distortion */
|
||
|
proto_645_07_waveform_dis_t v_waveform_dis;
|
||
|
/* current waveform distortion */
|
||
|
proto_645_07_waveform_dis_t i_waveform_dis;
|
||
|
/* a phase voltage harmonic content */
|
||
|
proto_645_07_harmonic_cont_t a_v_hc;
|
||
|
/* b phase voltage harmonic content */
|
||
|
proto_645_07_harmonic_cont_t b_v_hc;
|
||
|
/* c phase voltage harmonic content */
|
||
|
proto_645_07_harmonic_cont_t c_v_hc;
|
||
|
/* a current voltage harmonic content */
|
||
|
proto_645_07_harmonic_cont_t a_i_hc;
|
||
|
/* b current voltage harmonic content */
|
||
|
proto_645_07_harmonic_cont_t b_i_hc;
|
||
|
/* c current voltage harmonic content */
|
||
|
proto_645_07_harmonic_cont_t c_i_hc;
|
||
|
/* frequency data */
|
||
|
proto_645_freq_t freq;
|
||
|
/* 1 min average power */
|
||
|
uint8_t average_p[PROTO_645_07_P_LEN];
|
||
|
/* current active and reactive power demand */
|
||
|
iot_sg_meter_cur_demand_all_t cur_demand;
|
||
|
/* apparent power demand */
|
||
|
uint8_t at_demand[PROTO_645_07_P_LEN];
|
||
|
/* temperature */
|
||
|
uint8_t temperature[PROTO_645_TEMPERATURE_LEN];
|
||
|
/* clock battery voltage */
|
||
|
uint8_t clock_battery_v[PROTO_645_V_LEN];
|
||
|
/* meter read battery voltage */
|
||
|
uint8_t mr_battery_v[PROTO_645_V_LEN];
|
||
|
/* interior battery work time */
|
||
|
uint8_t work_time[PROTO_645_INTER_BATTERY_TIME_LEN];
|
||
|
/* total energy data block */
|
||
|
iot_sg_meter_total_energy_all_t energy_t;
|
||
|
/* quadrant reactive total energy data block */
|
||
|
iot_sg_meter_qr_total_energy_all_t qr_energy_t;
|
||
|
/* crc8 from time stamp to reserve */
|
||
|
uint8_t crc;
|
||
|
} iot_sg_meter_lc_uint_nw_data_t;
|
||
|
|
||
|
/* meter load curve data structure in flash for NW protocol */
|
||
|
typedef struct _iot_sg_sta_drv_meter_nw_lc {
|
||
|
/* load curve data */
|
||
|
iot_sg_meter_lc_uint_nw_data_t lc_data[IOT_SG_STA_METER_NW_LC_CNT];
|
||
|
} iot_sg_sta_drv_meter_nw_lc_t;
|
||
|
|
||
|
typedef struct _iot_sg_meter_ai_ll_unit_data {
|
||
|
/* unit data time */
|
||
|
iot_sg_meter_unit_time_with_sec_t unit_tm;
|
||
|
/* start collection tm */
|
||
|
uint8_t start_sec : 7,
|
||
|
/* valid flag of data from v to re_4st_total */
|
||
|
flag_data : 1;
|
||
|
/* collect interval, unit is 1min */
|
||
|
uint8_t interval;
|
||
|
/* flag of collection data */
|
||
|
uint8_t flag_p : 1,
|
||
|
flag_i : 1,
|
||
|
flag_gi : 1,
|
||
|
flag_v : 1,
|
||
|
flag_pf : 1,
|
||
|
flag_pos : 1,
|
||
|
flag_neg : 1,
|
||
|
flag_qtr : 1;
|
||
|
/* start collection tm */
|
||
|
uint32_t start_year : 7,
|
||
|
start_month : 4,
|
||
|
start_day : 5,
|
||
|
start_hour : 5,
|
||
|
start_minute : 6,
|
||
|
cycle : 5;
|
||
|
/* delta between meter clock and AI module clock, unit is 1s */
|
||
|
uint32_t delta : 30,
|
||
|
/* flag with negative delta. 0 mean that delta is a positive number,
|
||
|
* 1 mean that delta is a negative number
|
||
|
*/
|
||
|
neg_delta : 1,
|
||
|
/* valid flag of delta. 0 mean that delta is invalid,
|
||
|
* 1 mean that delta is valid
|
||
|
*/
|
||
|
valid : 1;
|
||
|
/* voltage */
|
||
|
proto_645_v_t v;
|
||
|
/* current */
|
||
|
proto_645_07_a_t i;
|
||
|
/* GND current */
|
||
|
uint8_t gnd_a[PROTO_645_07_A_LEN];
|
||
|
/* active power */
|
||
|
proto_645_07_p_t ap;
|
||
|
/* power factor */
|
||
|
proto_645_07_pf_t pf;
|
||
|
/* positive active total energy */
|
||
|
uint8_t pos_total[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* positive active a phase energy */
|
||
|
uint8_t pos_a[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* positive active b phase energy */
|
||
|
uint8_t pos_b[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* positive active c phase energy */
|
||
|
uint8_t pos_c[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* negative active total energy */
|
||
|
uint8_t neg_total[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* negative active a phase energy */
|
||
|
uint8_t neg_a[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* negative active b phase energy */
|
||
|
uint8_t neg_b[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* negative active c phase energy */
|
||
|
uint8_t neg_c[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* reactive total energy in the first quadrant */
|
||
|
uint8_t re_1st_total[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* reactive total energy in the second quadrant */
|
||
|
uint8_t re_2st_total[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* reactive total energy in the third quadrant */
|
||
|
uint8_t re_3st_total[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
/* reactive total energy in the fourth quadrant */
|
||
|
uint8_t re_4st_total[PROTO_645_07_ENERGY_DATA_LEN];
|
||
|
} iot_sg_meter_ai_ll_unit_data_t;
|
||
|
|
||
|
#pragma pack(pop) /* restore the pack status */
|
||
|
|
||
|
/* sta flash storage mode data descriptor */
|
||
|
typedef struct _iot_sg_sta_flash_data_desc {
|
||
|
/* storage data type */
|
||
|
uint8_t type;
|
||
|
/* storage data type length */
|
||
|
uint32_t len;
|
||
|
} iot_sg_sta_flash_data_desc_t;
|
||
|
|
||
|
/* sta flash storage mode descriptor */
|
||
|
typedef struct _iot_sg_sta_flash_storage_mode {
|
||
|
/* cnt of storage meter */
|
||
|
uint8_t meter_cnt;
|
||
|
/* a meter storage space size */
|
||
|
uint32_t space_size;
|
||
|
/* cnt of storage data type */
|
||
|
uint8_t cnt;
|
||
|
/* storage data type description */
|
||
|
iot_sg_sta_flash_data_desc_t data[IOT_SG_STA_FLASH_METER_DATA_MAX_CNT];
|
||
|
} iot_sg_sta_flash_storage_mode_t;
|
||
|
|
||
|
/* meter collection task header info */
|
||
|
typedef struct _iot_sg_sta_drv_meter_ct_hdr_info {
|
||
|
/* flag of flash reset */
|
||
|
uint8_t flag_reset;
|
||
|
/* collection task id */
|
||
|
uint8_t task_id;
|
||
|
/* collection task add sn */
|
||
|
uint16_t sn;
|
||
|
/* unit data structure len */
|
||
|
uint16_t unit_len;
|
||
|
/* unit data count */
|
||
|
uint16_t unit_cnt;
|
||
|
} iot_sg_sta_drv_meter_ct_hdr_info_t;
|
||
|
|
||
|
/* meter data descriptor in flash */
|
||
|
typedef struct _iot_sg_sta_flash_meter_data_desc {
|
||
|
/* meter data offset in flash */
|
||
|
uint32_t offset;
|
||
|
/* meter data headr info */
|
||
|
iot_sg_sta_drv_meter_data_hdr_t data_hdr;
|
||
|
/* meter collection task header info */
|
||
|
iot_sg_sta_drv_meter_ct_hdr_info_t ct_info;
|
||
|
} iot_sg_sta_flash_meter_data_desc_t;
|
||
|
|
||
|
/* meter descriptor in flash */
|
||
|
typedef struct _iot_sg_sta_flash_meter_desc {
|
||
|
/* meter info offset in flash */
|
||
|
uint32_t offset;
|
||
|
/* meter headr info */
|
||
|
iot_sg_sta_drv_meter_hdr_t meter_hdr;
|
||
|
/* data cnt in data_list */
|
||
|
uint8_t data_cnt;
|
||
|
/* meter data list */
|
||
|
iot_sg_sta_flash_meter_data_desc_t *data_list;
|
||
|
} iot_sg_sta_flash_meter_desc_t;
|
||
|
|
||
|
/* sta flash info descriptor */
|
||
|
typedef struct _iot_sg_sta_flash_info_desc {
|
||
|
/* flag of flash enabled */
|
||
|
uint8_t flash_en;
|
||
|
/* erase mode, see IOT_SG_STA_FLASH_ERASE_MODE_EACH_xxx */
|
||
|
uint8_t erase_mode;
|
||
|
/* the total number of meters that can be stored */
|
||
|
uint8_t total_meter_cnt;
|
||
|
/* free meter cnt */
|
||
|
uint8_t free_meter_cnt;
|
||
|
/* flash data mode */
|
||
|
uint8_t mode;
|
||
|
/* pointer to buf used to cache CRC check data */
|
||
|
uint8_t *crc_buf;
|
||
|
/* pointer to buf used to cache meter_list data */
|
||
|
uint8_t *flash_desc_buf;
|
||
|
/* flash erase cell size */
|
||
|
uint16_t erase_unit_size;
|
||
|
/* flash storage mode */
|
||
|
iot_sg_sta_flash_storage_mode_t *flash_mode;
|
||
|
} iot_sg_sta_flash_info_t;
|
||
|
|
||
|
/* collection task id info */
|
||
|
typedef struct _iot_sg_sta_flash_clct_task_id {
|
||
|
/* task cnt */
|
||
|
uint8_t cnt;
|
||
|
/* task id */
|
||
|
uint8_t task_id[0];
|
||
|
} iot_sg_sta_flash_clct_task_id_t;
|
||
|
|
||
|
/*------------------------------------------------------------------
|
||
|
* collection task flash layout shows like below |
|
||
|
* ---- ------------------------------------------------------------
|
||
|
* /|\ | meter head | 16 bytes | |
|
||
|
* | |--------------------------------| | |
|
||
|
* r | meter data head | the first | 8 bytes | |
|
||
|
* e |-----------------| collection | | |
|
||
|
* a | task info head | task data | 48 bytes | |
|
||
|
* d |-----------------| of the meter | | |
|
||
|
* | data | | | |
|
||
|
* |--------------------------------| | the first |
|
||
|
* | the second collection task | | meter data |
|
||
|
* | data of the meter | | |
|
||
|
* |--------------------------------| | |
|
||
|
* | ........ | | |
|
||
|
* |--------------------------------| | |
|
||
|
* | the fifth collection task | | |
|
||
|
* | data of the meter | | |
|
||
|
* |----------------------------------------------------------|
|
||
|
* w | the second meter data, |
|
||
|
* r | the length is same as the first meter data |
|
||
|
* i |----------------------------------------------------------|
|
||
|
* t | . |
|
||
|
* e | . |
|
||
|
* | | . |
|
||
|
* | |----------------------------------------------------------|
|
||
|
* | | the N meter data, |
|
||
|
* \|/ | the length is same as the first meter data |
|
||
|
* ----- |----------------------------------------------------------|
|
||
|
* note : each meter data structure is the same.
|
||
|
*/
|
||
|
|
||
|
/*------------------------------------------------------------------
|
||
|
* collection task 4k alignment flash layout shows like below |
|
||
|
* ---- ------------------------------------------------------------
|
||
|
* /|\ | meter head | 4k bytes | |
|
||
|
* | |--------------------------------|----------| |
|
||
|
* r | meter data head | the first | | |
|
||
|
* e |-----------------| collection | 4k bytes | |
|
||
|
* a | task info head | task data | | |
|
||
|
* d |-----------------| of the meter |----------| |
|
||
|
* | data | | 4k * N | |
|
||
|
* |--------------------------------|----------| the first |
|
||
|
* | the second collection task | | meter data |
|
||
|
* | data of the meter | | |
|
||
|
* |--------------------------------| | |
|
||
|
* | ........ | | |
|
||
|
* |--------------------------------| | |
|
||
|
* | the fifth collection task | | |
|
||
|
* | data of the meter | | |
|
||
|
* |----------------------------------------------------------|
|
||
|
* w | the second meter data, |
|
||
|
* r | the length is same as the first meter data |
|
||
|
* i |----------------------------------------------------------|
|
||
|
* t | . |
|
||
|
* e | . |
|
||
|
* | | . |
|
||
|
* | |----------------------------------------------------------|
|
||
|
* | | the N meter data, |
|
||
|
* \|/ | the length is same as the first meter data |
|
||
|
* ----- |----------------------------------------------------------|
|
||
|
* note : each meter data structure is the same.
|
||
|
*/
|
||
|
|
||
|
/*------------------------------------------------------------------
|
||
|
* meter data flash layout shows like below
|
||
|
* ---- ------------------------------------------------------------
|
||
|
* /|\ | meter head | 16 bytes | |
|
||
|
* | |--------------------------------| | |
|
||
|
* r | meter data head |the first data| 8 bytes | |
|
||
|
* e |-----------------| | | |
|
||
|
* a | data | of the meter | | |
|
||
|
* d |--------------------------------| | the first |
|
||
|
* | the second data of the meter | | meter data |
|
||
|
* |--------------------------------| | |
|
||
|
* | ........ | | |
|
||
|
* |--------------------------------| | |
|
||
|
* | the N data of the meter | | |
|
||
|
* |--------------------------------| | |
|
||
|
* | reserve | | |
|
||
|
* |----------------------------------------------------------|
|
||
|
* w | the second meter data, |
|
||
|
* r | the length is same as the first meter data |
|
||
|
* i |----------------------------------------------------------|
|
||
|
* t | . |
|
||
|
* e | . |
|
||
|
* | | . |
|
||
|
* | |----------------------------------------------------------|
|
||
|
* | | the N meter data, |
|
||
|
* \|/ | the length is same as the first meter data |
|
||
|
* ----- |----------------------------------------------------------|
|
||
|
* note : each meter data structure is the same.
|
||
|
*/
|
||
|
|
||
|
/* define data length in flash */
|
||
|
/* define max cnt of meter hour frozen benchmark data */
|
||
|
#define IOT_SG_STA_METER_HF_MARK_MAX_CNT (20)
|
||
|
|
||
|
/* define max cnt of meter day frozen benchmark data. for jiangsu protocol */
|
||
|
#define IOT_SG_STA_METER_JS_DF_MARK_MAX_CNT (31)
|
||
|
|
||
|
/* define max cnt of meter month frozen benchmark data. for jiangsu protocol */
|
||
|
#define IOT_SG_STA_METER_JS_MF_MARK_MAX_CNT (12)
|
||
|
|
||
|
/* define max cnt of meter 15 minutecurve benchmark data. for jiangsu protocol */
|
||
|
#define IOT_SG_STA_METER_JS_15MIN_CURVE_MARK_MAX_CNT (480)
|
||
|
|
||
|
/* define max cnt of meter 1 minute curve benchmark data. for jiangsu protocol */
|
||
|
#define IOT_SG_STA_METER_JS_1MIN_CURVE_MARK_MAX_CNT (1440)
|
||
|
|
||
|
/* define max cnt of freeze task record data. for fujian protocol */
|
||
|
#define IOT_SG_STA_METER_FJ_FRZ_TASK_MARK_MAX_CNT (1600)
|
||
|
|
||
|
/* define max cnt of meter hour frozen data */
|
||
|
#define IOT_SG_STA_METER_HF_MAX_CNT (138)
|
||
|
|
||
|
/* meter collection task unit data total len */
|
||
|
#define IOT_SG_STA_CLCT_TASK_UNIT_DATA_TOTAL_LEN (1024 * 8)
|
||
|
|
||
|
/* define meter header length in flash */
|
||
|
#define IOT_SG_STA_METER_HEADER_LEN sizeof(iot_sg_sta_drv_meter_hdr_t)
|
||
|
|
||
|
/* meter data header length */
|
||
|
#define IOT_SG_STA_METER_DATA_HEADER_LEN sizeof(iot_sg_sta_drv_meter_data_hdr_t)
|
||
|
|
||
|
/* meter day frozen data max length */
|
||
|
#define IOT_SG_STA_METER_TYPE_DF_MAX_LEN \
|
||
|
(((sizeof(iot_sg_sta_drv_meter_df_t) >> 2) + 1) << 2)
|
||
|
|
||
|
/* meter impedance anomaly data max length */
|
||
|
#define IOT_SG_STA_METER_TYPE_IA_MAX_LEN \
|
||
|
(((sizeof(iot_sg_sta_drv_meter_ia_t) >> 2) + 1) << 2)
|
||
|
|
||
|
/* meter hour frozen data max length */
|
||
|
#define IOT_SG_STA_METER_TYPE_HF_MAX_LEN \
|
||
|
((((IOT_SG_STA_METER_HF_MARK_MAX_CNT * \
|
||
|
sizeof(iot_sg_sta_drv_meter_hf_mark_t) + \
|
||
|
IOT_SG_STA_METER_HF_MAX_CNT * sizeof(iot_sg_sta_drv_meter_hf_t)) \
|
||
|
>> 2) + 1) << 2)
|
||
|
|
||
|
/* meter load curve data max length for NW protocol */
|
||
|
#define IOT_SG_STA_METER_TYPE_NW_LC_MAX_LEN \
|
||
|
(((sizeof(iot_sg_sta_drv_meter_nw_lc_t) >> 2) + 1) << 2)
|
||
|
|
||
|
/* meter collection task max length for GUANGDONG protocol */
|
||
|
#define IOT_SG_STA_METER_TYPE_GUANGDONG_MAX_LEN \
|
||
|
((((IOT_SG_STA_CLCT_TASK_UNIT_DATA_TOTAL_LEN + \
|
||
|
sizeof(iot_sg_sta_drv_meter_ct_hdr_t)) >> 2) + 1) << 2)
|
||
|
|
||
|
/* meter state score data max length for GUANGZHOU protocol */
|
||
|
#define IOT_SG_STA_METER_TYPE_GUANGZHOU_MAX_LEN \
|
||
|
(((sizeof(iot_sg_sta_drv_meter_ss_data_t) >> 2) + 1) << 2)
|
||
|
|
||
|
/* meter state score data max length for NW edge computing */
|
||
|
#define IOT_SG_STA_METER_TYPE_EC_MAX_LEN \
|
||
|
(((sizeof(iot_sg_sta_drv_meter_ss_data_t) >> 2) + 1) << 2)
|
||
|
|
||
|
/* define start offset in flash */
|
||
|
#define IOT_SG_STA_METER_START_OFFSET (0)
|
||
|
|
||
|
/* define invalid offset in flash */
|
||
|
#define IOT_SG_STA_FLASH_INVALID_OFFSET (0xffffffff)
|
||
|
|
||
|
/* define CRC check type */
|
||
|
#define IOT_SG_STA_FLASH_CRC16 1
|
||
|
#define IOT_SG_STA_FLASH_CRC8 2
|
||
|
|
||
|
/**
|
||
|
* @brief: sta flash init function.
|
||
|
* @retval: ERR_OK -- initialization success
|
||
|
* @retval: otherwise -- other value for failed case, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_init();
|
||
|
|
||
|
/**
|
||
|
* @brief: sta flash deinit function.
|
||
|
*/
|
||
|
void iot_sg_sta_flash_deinit(void);
|
||
|
|
||
|
/**
|
||
|
* @brief: add meter info to flash.
|
||
|
* @param addr: address of meter, little endian.
|
||
|
* @retval: ERR_OK -- add meter info success
|
||
|
* @retval: otherwise -- other value for failed case, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_meter_add(uint8_t *addr);
|
||
|
|
||
|
/**
|
||
|
* @brief: delete meter info to flash.
|
||
|
* @param addr: address of meter, little endian.
|
||
|
* @retval: ERR_OK -- delete meter info success
|
||
|
* @retval: otherwise -- other value for failed case, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_meter_delete(uint8_t *addr);
|
||
|
|
||
|
/**
|
||
|
* @brief: get CRC of a segment of data in flash.
|
||
|
* @param offset: offset from IOT_SG_STA_METER_START_OFFSET.
|
||
|
* @param len: length of data.
|
||
|
* @param crc_type: type of crc, see IOT_SG_STA_FLASH_XXX.
|
||
|
* @retval: CRC.
|
||
|
*/
|
||
|
uint16_t iot_sg_sta_flash_get_crc(uint32_t offset, uint32_t len,
|
||
|
uint8_t crc_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: save collection data of per unit time.
|
||
|
* @param addr: address of meter, little endian.
|
||
|
* @param index: index in flash buffer.
|
||
|
* @param data: pointer to cache data.
|
||
|
* @param len: length of lc_data.
|
||
|
* @param data_type: data type, see IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @retval: ERR_OK, save success.
|
||
|
* @retval: otherwise, save fail, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_unit_data_save(uint8_t *addr,
|
||
|
uint16_t index, uint8_t *data, uint16_t len, uint8_t data_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: read collection data of per unit time.
|
||
|
* @param addr: address of meter, little endian.
|
||
|
* @param index: index in flash buffer.
|
||
|
* @param data: pointer to cache data.
|
||
|
* @param len: length of lc_data.
|
||
|
* @param data_type: data type, see IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @retval: ERR_OK, read success.
|
||
|
* @retval: otherwise, read fail, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_unit_data_read(uint8_t *addr,
|
||
|
uint16_t index, uint8_t *data, uint16_t len, uint8_t data_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: find the latest unit data.
|
||
|
* @param addr: address of meter, little endian.
|
||
|
* @param index_ptr: output found unit data index.
|
||
|
* @param: data: pointer to found unit data cache.
|
||
|
* @param: len: length of data.
|
||
|
* @param data_type: data type, see IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @retval: ERR_OK, save success.
|
||
|
* @retval: otherwise, save fail, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_unit_data_find_latest(uint8_t *addr,
|
||
|
uint16_t *index_ptr, uint8_t *data, uint16_t len, uint8_t data_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: find the nearest unit data by time.
|
||
|
* @param: addr: address of meter, little endian.
|
||
|
* @param: index_ptr: output found unit data index.
|
||
|
* @param: tm: time.
|
||
|
* @param: data: pointer to found unit data cache.
|
||
|
* @param: len: length of data.
|
||
|
* @param: data_type data type, see IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @param: flag_up: flag of up, 1 mean that the time must be
|
||
|
* greater than time of data found, 0 mean that the time must be
|
||
|
* less than time of data found .
|
||
|
* @retval: ERR_OK, find success.
|
||
|
* @retval: otherwise, find fail, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_unit_data_find_by_time(uint8_t *addr,
|
||
|
uint16_t *index_ptr, iot_time_tm_t *tm, uint8_t *data, uint16_t len,
|
||
|
uint8_t data_type, uint8_t flag_up);
|
||
|
|
||
|
/**
|
||
|
* @brief: find the nearest unit data by multiple time,
|
||
|
* the maximum see IOT_SG_STA_FLASH_UNIT_DATA_FIND_BY_TIME_MAX_CNT.
|
||
|
* @param: addr: address of meter, little endian.
|
||
|
* @param: index_ptr: output found unit data index array,
|
||
|
* if index is 0xffff data is invalid.
|
||
|
* @param: tm: time array.
|
||
|
* @param: tm_cnt: number of time
|
||
|
* @param: data_type data type, see IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @param: flag_up: flag of up, 1 mean that the time must be
|
||
|
* greater than time of data found, 0 mean that the time must be
|
||
|
* less than time of data found .
|
||
|
* @retval: ERR_OK, find success.
|
||
|
* @retval: otherwise, find fail, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_unit_data_find_by_multiple_time(uint8_t *addr,
|
||
|
uint16_t *index_ptr, iot_time_tm_t *tm, uint8_t tm_cnt, uint8_t data_type,
|
||
|
uint8_t *flag_up);
|
||
|
|
||
|
/**
|
||
|
* @brief: check the validity of uint data by time.
|
||
|
* @param: addr: address of meter, little endian.
|
||
|
* @param: index: initial index of unit data index check.
|
||
|
* @param: tm: time.
|
||
|
* @param: data_type data type, see IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @retval: cnt of invalid uint data cleared.
|
||
|
*/
|
||
|
uint16_t iot_sg_sta_flash_unit_data_check(uint8_t *addr, uint16_t index,
|
||
|
iot_time_tm_t *tm, uint8_t data_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: save collection task data of per unit time.
|
||
|
* @param addr: address of meter, little endian.
|
||
|
* @param index: index in flash buffer.
|
||
|
* @param data: pointer to cache data.
|
||
|
* @param len: length of ct_unit_data.
|
||
|
* @param task_id: collection task id.
|
||
|
* @retval: ERR_OK, save success.
|
||
|
* @retval: otherwise, save fail, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_ct_unit_data_save(uint8_t *addr,
|
||
|
uint16_t index, uint8_t *data, uint16_t len, uint8_t task_id);
|
||
|
|
||
|
/**
|
||
|
* @brief: read collection task data of per unit time.
|
||
|
* @param addr: address of meter, little endian.
|
||
|
* @param index: index in flash buffer.
|
||
|
* @param data: pointer to cache data.
|
||
|
* @param len: length of ct_unit_data.
|
||
|
* @param task_id: collection task id.
|
||
|
* @retval: ERR_OK, read success.
|
||
|
* @retval: otherwise, read fail, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_ct_unit_data_read(uint8_t *addr,
|
||
|
uint16_t index, uint8_t *data, uint16_t len, uint8_t task_id);
|
||
|
|
||
|
/**
|
||
|
* @brief: find the latest collection task unit data.
|
||
|
* @param addr: address of meter, little endian.
|
||
|
* @param index_ptr: output found unit data index.
|
||
|
* @param: data: pointer to found unit data cache.
|
||
|
* @param: len: length of data.
|
||
|
* @param task_id: collection task id.
|
||
|
* @param data_type: data_type, IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @retval: ERR_OK, save success.
|
||
|
* @retval: otherwise, save fail, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_ct_unit_data_find_latest(uint8_t *addr,
|
||
|
uint16_t *index_ptr, uint8_t *data, uint16_t len, uint8_t task_id,
|
||
|
uint8_t data_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: find the nearest collection task unit data by time.
|
||
|
* @param: addr: address of meter, little endian.
|
||
|
* @param: index_ptr: output found unit data index.
|
||
|
* @param: tm: time.
|
||
|
* @param: data: pointer to found unit data cache.
|
||
|
* @param: len: length of data.
|
||
|
* @param task_id: collection task id.
|
||
|
* @param: flag_up: flag of up, 1 mean that the time must be
|
||
|
* greater than time of data found, 0 mean that the time must be
|
||
|
* less than time of data found.
|
||
|
* @param data_type: data_type, IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @retval: ERR_OK, find success.
|
||
|
* @retval: otherwise, find fail, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_ct_unit_data_find_by_time(uint8_t *addr,
|
||
|
uint16_t *index_ptr, iot_time_tm_t *tm, uint8_t *data, uint16_t len,
|
||
|
uint8_t task_id, uint8_t flag_up, uint8_t data_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: check the validity of collection task uint data by time.
|
||
|
* @param: addr: address of meter, little endian.
|
||
|
* @param: index: initial index of unit data index check.
|
||
|
* @param: tm: time.
|
||
|
* @param data_type: data_type, IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @param: task_id: collection task id.
|
||
|
*/
|
||
|
void iot_sg_sta_flash_ct_unit_data_check(uint8_t *addr, uint16_t index,
|
||
|
iot_time_tm_t *tm, uint8_t task_id, uint8_t data_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: sta get collection task info.
|
||
|
* @param: addr: address of meter, little endian.
|
||
|
* @param: task_id: task id of get collection task.
|
||
|
* @param: task_ptr: pointer to collection task info cache.
|
||
|
* @param: len: task length.
|
||
|
* @param data_type: data_type, IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @retval: ERR_OK -- get task info success.
|
||
|
* @retval: otherwise -- other value for failed case, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_clct_task_info_get(uint8_t *addr, uint8_t task_id,
|
||
|
uint8_t *task_ptr, uint32_t len, uint8_t data_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: sta add collection task.
|
||
|
* @param: addr: address of meter, little endian.
|
||
|
* @param: task_ptr: pointer to collection task info.
|
||
|
* @param: len: task length.
|
||
|
* @param data_type: data_type, IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @retval: ERR_OK -- add success.
|
||
|
* @retval: otherwise -- other value for failed case, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_clct_task_add(uint8_t *addr,
|
||
|
uint8_t *task_ptr, uint32_t len, uint8_t data_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: sta delete collection task.
|
||
|
* @param: addr: address of meter, little endian.
|
||
|
* @param: task_id: task id.
|
||
|
* @param: flag_reset: flag of flash reset.
|
||
|
* @param data_type: data_type, IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @retval: ERR_OK -- delete success.
|
||
|
* @retval: otherwise -- other value for failed case, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_clct_task_del(uint8_t *addr, uint8_t task_id,
|
||
|
uint8_t flag_reset, uint8_t data_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: sta oldest collection task find.
|
||
|
* @param: addr: address of meter, little endian.
|
||
|
* @retval: task id.
|
||
|
*/
|
||
|
uint8_t iot_sg_sta_flash_clct_find_oldest_task(uint8_t *addr);
|
||
|
|
||
|
/**
|
||
|
* @brief: sta collection task update.
|
||
|
* @param: addr: address of meter, little endian.
|
||
|
* @param: task_ptr: pointer to collection task info.
|
||
|
* @param: len: task length.
|
||
|
* @param data_type: data_type, IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @retval: ERR_OK -- add success.
|
||
|
* @retval: otherwise -- other value for failed case, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_clct_task_info_update(uint8_t *addr,
|
||
|
uint8_t *task_ptr, uint32_t len, uint8_t data_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: sta get collection task data length.
|
||
|
* @param addr: the pointer to address of meter.
|
||
|
* @param task_id: id of collection task.
|
||
|
* @retval: length of task data.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_ct_unit_data_len_get(uint8_t *addr, uint8_t task_id);
|
||
|
|
||
|
/**
|
||
|
* @brief: sta get collection task data cnt.
|
||
|
* @param addr: the pointer to address of meter.
|
||
|
* @param task_id: id of collection task.
|
||
|
* @retval: task data cnt.
|
||
|
*/
|
||
|
uint16_t iot_sg_sta_flash_ct_unit_cnt_get(uint8_t *addr, uint8_t task_id);
|
||
|
|
||
|
/**
|
||
|
* @brief: sta get collection task id info.
|
||
|
* @param addr: address of meter, little endian.
|
||
|
* @retval: pkt -- the pkt buffer for collection task id info.
|
||
|
* @retval: NULL -- failed case.
|
||
|
*/
|
||
|
iot_pkt_t *iot_sg_sta_flash_clct_task_id_info_get(uint8_t *addr);
|
||
|
|
||
|
/**
|
||
|
* @brief: save state score data to flash.
|
||
|
* @param addr: address of meter, little endian.
|
||
|
* @param data: pointer to data cache.
|
||
|
* @param len: length of data.
|
||
|
* @param data_type: data type.
|
||
|
* @retval: ERR_OK -- save data success.
|
||
|
* @retval: otherwise -- other value for failed case, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_score_data_save(uint8_t *addr, uint8_t *data,
|
||
|
uint16_t len, uint8_t data_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: read state score data from flash.
|
||
|
* @param addr: address of meter, little endian.
|
||
|
* @param data: pointer to data cache.
|
||
|
* @param len: length of data.
|
||
|
* @param data_type: data type.
|
||
|
* @retval: ERR_OK -- read data success.
|
||
|
* @retval: otherwise -- other value for failed case, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_score_data_read(uint8_t *addr, uint8_t *data,
|
||
|
uint16_t len, uint8_t data_type);
|
||
|
|
||
|
/**
|
||
|
* @brief: check whether the flash mode is a single-phase module mode in JS.
|
||
|
* @retval: 1 -- the flash mode is a single-phase module mode in JS.
|
||
|
* @retval: 0 -- the flash mode isn't a single-phase module mode in JS.
|
||
|
*/
|
||
|
uint8_t iot_sg_sta_flash_mode_js_sig_check(void);
|
||
|
|
||
|
/**
|
||
|
* @brief: sta get flash unit data info.
|
||
|
* @param data_type: data type, see IOT_SG_STA_METER_DATA_TYPE_XXX.
|
||
|
* @param unit_len: pointer to unit length data.
|
||
|
* @param max_cnt: pointer to max count data.
|
||
|
* @retval: ERR_OK -- get data info success.
|
||
|
* @retval: otherwise -- other value for failed case, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_unit_get_data_info(uint8_t data_type,
|
||
|
uint16_t *unit_len, uint16_t *max_cnt);
|
||
|
|
||
|
/**
|
||
|
* @brief: save collection task data list.
|
||
|
* @param addr: address of meter, little endian.
|
||
|
* @param start_index: index in flash buffer.
|
||
|
* @param data: pointer to cache data.
|
||
|
* @param len: length of data.
|
||
|
* @param unit_len: data unit len.
|
||
|
* @param task_id: collection task id.
|
||
|
* @retval: ERR_OK, save success.
|
||
|
* @retval: otherwise, save fail, see ERR_XXX.
|
||
|
*/
|
||
|
uint32_t iot_sg_sta_flash_ct_unit_data_list_save(uint8_t *addr,
|
||
|
uint16_t start_index, uint8_t *data, uint16_t len, uint16_t unit_len,
|
||
|
uint8_t task_id);
|
||
|
|
||
|
#ifdef __cplusplus
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
#endif /* IOT_SG_STA_FLASH_H */
|