743 lines
		
	
	
		
			26 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			743 lines
		
	
	
		
			26 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
| /****************************************************************************
 | |
| 
 | |
| 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_BRM_REC_H
 | |
| #define IOT_BRM_REC_H
 | |
| 
 | |
| /* os shim includes */
 | |
| #include "os_types_api.h"
 | |
| #include "iot_brm_common.h"
 | |
| #include "iot_pkt_api.h"
 | |
| #include "iot_plc_hw_topo_api.h"
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| extern "C" {
 | |
| #endif
 | |
| 
 | |
| #if (IOT_BRM_ENABLE && PLC_SUPPORT_STA_ROLE)
 | |
| 
 | |
| #define QIEDIAN_RESERVE_BYTE                97
 | |
| #define DAY_STAT_RESERVE_BYTE               162
 | |
| 
 | |
| #define METER_CHANGE_MAX_NUMBER             16
 | |
| 
 | |
| /* definition whether enable record buffer */
 | |
| #define IOT_BRM_EN_REC_BUFFER_FROZEN_D      (1 >> 0)
 | |
| #define IOT_BRM_EN_REC_BUFFER_FROZEN_H      (1 >> 1)
 | |
| #define IOT_BRM_EN_REC_BUFFER_FROZEN_RT     (1 >> 2)
 | |
| #define IOT_BRM_EN_REC_BUFFER_CURVE         (1 >> 3)
 | |
| #define IOT_BRM_EN_REC_BUFFER_EVT_QD        (1 >> 4)
 | |
| #define IOT_BRM_EN_REC_BUFFER_EVT_METER_CHG (1 >> 5)
 | |
| 
 | |
| /* definition of freezing type */
 | |
| typedef enum {
 | |
|     iot_brm_frozen_type_h,
 | |
|     iot_brm_frozen_type_d,
 | |
|     iot_brm_frozen_type_rt,
 | |
|     iot_brm_frozen_type_msd,     /* monthly settlement date */
 | |
|     iot_brm_frozen_type_max,
 | |
| } iot_brm_frozen_type_t;
 | |
| 
 | |
| /* definition of evt records type */
 | |
| typedef enum {
 | |
|     /* qiedian event */
 | |
|     iot_brm_evt_type_qd,
 | |
|     /* meter change event */
 | |
|     iot_brm_evt_type_meter_chg,
 | |
|     /* power down event */
 | |
|     iot_brm_evt_type_pd,
 | |
|     /* A phase under voltage */
 | |
|     iot_brm_evt_type_uv_a,
 | |
|     /* B phase under voltage */
 | |
|     iot_brm_evt_type_uv_b,
 | |
|     /* C phase under voltage */
 | |
|     iot_brm_evt_type_uv_c,
 | |
|     /* A phase over voltage */
 | |
|     iot_brm_evt_type_ov_a,
 | |
|     /* B phase over voltage */
 | |
|     iot_brm_evt_type_ov_b,
 | |
|     /* C phase over voltage */
 | |
|     iot_brm_evt_type_ov_c,
 | |
|     /* A phase failure */
 | |
|     iot_brm_evt_type_pf_a,
 | |
|     /* B phase failure */
 | |
|     iot_brm_evt_type_pf_b,
 | |
|     /* C phase failure */
 | |
|     iot_brm_evt_type_pf_c,
 | |
|     /* A phase over current */
 | |
|     iot_brm_evt_type_oi_a,
 | |
|     /* B phase over current */
 | |
|     iot_brm_evt_type_oi_b,
 | |
|     /* C phase over current */
 | |
|     iot_brm_evt_type_oi_c,
 | |
|     /* voltage unbalance */
 | |
|     iot_brm_evt_type_unbal_v,
 | |
|     iot_brm_evt_type_max,
 | |
| } iot_brm_evt_type_t;
 | |
| 
 | |
| /* definition statistical records type */
 | |
| typedef enum {
 | |
|     /* day variable record */
 | |
|     iot_brm_stat_rec_type_d,
 | |
|     iot_brm_stat_rec_type_max,
 | |
| } iot_brm_stat_rec_type_t;
 | |
| 
 | |
| /* definition debug info record type */
 | |
| typedef enum {
 | |
|     /* tsfm debug info */
 | |
|     iot_brm_rec_dbg_type_tsfm,
 | |
|     iot_brm_rec_dbg_type_max,
 | |
| } iot_brm_rec_dbg_type_t;
 | |
| 
 | |
| /* definition of miscellaneous record type */
 | |
| typedef enum {
 | |
|     iot_brm_rec_misc_type_msd,
 | |
|     iot_brm_rec_misc_type_max,
 | |
| } iot_brm_rec_misc_type_t;
 | |
| 
 | |
| #pragma pack(push)  /* save the pack status */
 | |
| #pragma pack(1)     /* 1 byte align */
 | |
| 
 | |
| /* data to be saved when modifying settlement date */
 | |
| typedef struct {
 | |
|     /* operator code */
 | |
|     uint32_t op_code;
 | |
|     /* settlement date data */
 | |
|     proto_645_07_msd_frozen_time_t msd[IOT_BRM_SUPPORT_MSD_NUM];
 | |
| } iot_brm_msd_modify_record_t;
 | |
| 
 | |
| /* meter total active energy data structure */
 | |
| typedef struct {
 | |
|     /* total positive active energy, uint is 0.01kwh */
 | |
|     uint32_t ept_pos;
 | |
|     /* total negative active energy, uint is 0.01kwh */
 | |
|     uint32_t ept_neg;
 | |
| } iot_brm_meter_ept_frozen_t;
 | |
| 
 | |
| /* hour frozen record format */
 | |
| typedef struct {
 | |
|     /* tri-phase total active energy data */
 | |
|     iot_brm_meter_ept_frozen_t e_t;
 | |
|     /* sigle-phase total active energy data, A/B/C */
 | |
|     iot_brm_meter_ept_frozen_t e_s[IOT_BRM_PHASE_C];
 | |
| } iot_brm_frozen1_t;
 | |
| 
 | |
| /* daily, real-time frozen record format */
 | |
| typedef struct {
 | |
|     /* total positive active energy, total ~ rates 1-4, uint is 0.01kwh */
 | |
|     uint32_t ept_pos[IOT_BRM_METER_RATE_MAX + 1];
 | |
|     /* total negative active energy, total ~ rates 1-4, uint is 0.01kwh */
 | |
|     uint32_t ept_neg[IOT_BRM_METER_RATE_MAX + 1];
 | |
|     /* total positive reactive energy, total ~ rates 1-4,
 | |
|      * uint is 0.0001 Kvarh.
 | |
|      */
 | |
|     uint32_t eqt_pos[IOT_BRM_METER_RATE_MAX + 1];
 | |
|     /* total negative reactive energy, total ~ rates 1-4,
 | |
|      * uint is 0.0001 Kvarh.
 | |
|      */
 | |
|     uint32_t eqt_neg[IOT_BRM_METER_RATE_MAX + 1];
 | |
| } iot_brm_frozen2_t;
 | |
| 
 | |
| /* sig-phase energy-type meter data structure.
 | |
|  * this structure uses 132 bytes of storage space.
 | |
|  */
 | |
| typedef struct {
 | |
|     /* positive apparent energy, uint is  1/ec kVAh */
 | |
|     uint32_t est_pos;
 | |
|     /* negative apparent energy, uint is  1/ec kVAh */
 | |
|     uint32_t est_neg;
 | |
|     /* positive active energy, uint is  1/ec kwh */
 | |
|     uint32_t ept_pos;
 | |
|     /* negative active energy, uint is  1/ec kwh */
 | |
|     uint32_t ept_neg;
 | |
|     /* positive reactive energy, uint is  1/ec kvarh */
 | |
|     uint32_t eqt_pos;
 | |
|     /* negative reactive energy, uint is  1/ec kvarh*/
 | |
|     uint32_t eqt_neg;
 | |
|     /* quad reactive energy, uint is  1/ec kvarh */
 | |
|     uint32_t eqt_quad[IOT_BRM_METER_QUAD_4 + 1];
 | |
|     /* sig-phase energy-type meter data structure */
 | |
|     iot_brm_meter_sigphase_max_demand_t demand;
 | |
|     /* reserve for future */
 | |
|     uint8_t rsvd[28];
 | |
| } iot_brm_meter_energy_frozen_sigphase_t;
 | |
| 
 | |
| /* tri-phase energy-type meter data structure.
 | |
|  * this structure uses 648 bytes of storage space.
 | |
|  */
 | |
| typedef struct {
 | |
|     /* combined active energy, total ~ rates 1-4, uint is 1/ec kWh */
 | |
|     uint32_t ept_comp[IOT_BRM_METER_RATE_MAX + 1];
 | |
|     /* positive active energy, total ~ rates 1-4, uint is 1/ec kwh */
 | |
|     uint32_t ept_pos[IOT_BRM_METER_RATE_MAX + 1];
 | |
|     /* negative active energy, total ~ rates 1-4, uint is 1/ec kwh */
 | |
|     uint32_t ept_neg[IOT_BRM_METER_RATE_MAX + 1];
 | |
|     /* positive reactive energy, total ~ rates 1-4, uint is  1/ec kvarh */
 | |
|     uint32_t eqt_pos[IOT_BRM_METER_RATE_MAX + 1];
 | |
|     /* negative reactive energy, total ~ rates 1-4, uint is  1/ec kvarh */
 | |
|     uint32_t eqt_neg[IOT_BRM_METER_RATE_MAX + 1];
 | |
|     /* positive apparent energy, total ~ rates 1-4, uint is  1/ec kVAh */
 | |
|     uint32_t est_pos[IOT_BRM_METER_RATE_MAX + 1];
 | |
|     /* negative apparent energy, total ~ rates 1-4, uint is  1/ec kVAh */
 | |
|     uint32_t est_neg[IOT_BRM_METER_RATE_MAX + 1];
 | |
|     /* quad reactive energy, uint is  1/ec kvarh */
 | |
|     uint32_t eqt_quad[IOT_BRM_METER_QUAD_4 + 1][IOT_BRM_METER_RATE_MAX + 1];
 | |
|     /* three-phase energy-type meter demand data structure */
 | |
|     iot_brm_meter_triphase_max_demand_t demand;
 | |
|     /* reserve for future */
 | |
|     uint8_t rsvd[28];
 | |
| } iot_brm_meter_energy_frozen_triphase_t;
 | |
| 
 | |
| /* settlement date frozen record format.
 | |
|  * this structure uses 2048 bytes of storage space.
 | |
|  */
 | |
| typedef struct {
 | |
|     /* three-phase total energy data and demand structure*/
 | |
|     iot_brm_meter_energy_frozen_triphase_t e_t;
 | |
|     /* sig-phase energy metering data and demand, A/B/C */
 | |
|     iot_brm_meter_energy_frozen_sigphase_t e_s[IOT_BRM_PHASE_C];
 | |
|     /* reserve for future */
 | |
|     uint8_t rsvd[946];
 | |
| } iot_brm_frozen3_t;
 | |
| 
 | |
| /* day frozen record format */
 | |
| typedef struct {
 | |
|     /* three-phase total energy data structure */
 | |
|     iot_brm_frozen2_t e_t;
 | |
|     /* sigle-phase total active energy data, A/B/C */
 | |
|     iot_brm_meter_ept_frozen_t e_s[IOT_BRM_PHASE_C];
 | |
| } iot_brm_frozen4_t;
 | |
| 
 | |
| /* curve recording formats */
 | |
| typedef struct {
 | |
|     /* A/B/C phase voltage, uint is 0.1v */
 | |
|     uint16_t v[IOT_BRM_PHASE_C];
 | |
|     /* A/B/C phase current, uint is 0.001A */
 | |
|     int32_t  i[IOT_BRM_PHASE_C];
 | |
|     /* total/A/B/C active power, uint is 0.0001 KW */
 | |
|     int32_t p[IOT_BRM_PHASE_MAX];
 | |
|     /* total/A/B/C reactive power, uint is 0.0001 Kvar */
 | |
|     int32_t q[IOT_BRM_PHASE_MAX];
 | |
|     /* total/A/B/C power factor, uint is 0.001 */
 | |
|     int16_t pf[IOT_BRM_PHASE_MAX];
 | |
|     /* total/A/B/C forward active energy, uint is 0.01kWh */
 | |
|     uint32_t ept_pos[IOT_BRM_PHASE_MAX];
 | |
|     /* total/A/B/C reverse active energy, uint is 0.01kWh */
 | |
|     uint32_t ept_neg[IOT_BRM_PHASE_MAX];
 | |
|     /* temperature, uint is 0.1 centigrade */
 | |
|     int16_t  temperature;
 | |
|     /* humidity, unit is 0.1 %RH */
 | |
|     int16_t  humidity;
 | |
|     /* positive reactive total energy, uint is  1/ec kvarh */
 | |
|     uint32_t eqt_pos;
 | |
|     /* negative reactive total energy, uint is  1/ec kvarh */
 | |
|     uint32_t eqt_neg;
 | |
|     /* quad total reactive energy, uint is  1/ec kvarh */
 | |
|     uint32_t eqt_quad[IOT_BRM_METER_QUAD_4 + 1];
 | |
| } iot_brm_curve_entry_t;
 | |
| 
 | |
| /* curve recording formats */
 | |
| typedef struct {
 | |
|     /* content of curve recording */
 | |
|     iot_brm_curve_entry_t rec;
 | |
|      /* flag to mark if curve recording is valid */
 | |
|     uint8_t valid;
 | |
| } iot_brm_curve_desc_t;
 | |
| 
 | |
| /* qiedian event recording formats */
 | |
| typedef struct {
 | |
|     /* The state of qiedian */
 | |
|     uint8_t state;
 | |
|     /* time of occurrence qiedian */
 | |
|     uint32_t ts;
 | |
|     /* qiedian into the line current, uint is 0.001A */
 | |
|     int32_t  i_in;
 | |
|     /* qiedian out the Client current, uint is 0.001A */
 | |
|     int32_t  i_out;
 | |
|     /* total active power of incoming line, uint is 0.1W */
 | |
|     int32_t  power_in;
 | |
|     /* total active power of outgoing  line, uint is 0.1W */
 | |
|     int32_t  power_out;
 | |
|     /* reserved for further use */
 | |
|     uint8_t reserve[QIEDIAN_RESERVE_BYTE];
 | |
| } iot_brm_qiedian_rec_entry_t;
 | |
| 
 | |
| /* max min voltage recording formats */
 | |
| typedef struct {
 | |
|     /* voltage, uint is 0.1v */
 | |
|     uint16_t v;
 | |
|     /* time of occurrence mix or min */
 | |
|     uint32_t ts;
 | |
| } iot_brm_max_min_v_entry_t;
 | |
| 
 | |
| /* max min current recording formats */
 | |
| typedef struct {
 | |
|     /* current, uint is 0.001A */
 | |
|     int32_t i;
 | |
|     /* time of occurrence mix or min */
 | |
|     uint32_t ts;
 | |
| } iot_brm_max_min_i_entry_t;
 | |
| 
 | |
| /* state record recording formats */
 | |
| typedef struct {
 | |
|     /* The state of max voltage */
 | |
|     iot_brm_max_min_v_entry_t max_v[IOT_BRM_PHASE_C];
 | |
|     /* The state of min voltage */
 | |
|     iot_brm_max_min_v_entry_t min_v[IOT_BRM_PHASE_C];
 | |
|     /* The state of max current */
 | |
|     iot_brm_max_min_i_entry_t max_i[IOT_BRM_PHASE_C];
 | |
|     /* The state of min current */
 | |
|     iot_brm_max_min_i_entry_t min_i[IOT_BRM_PHASE_C];
 | |
|     /* reserve */
 | |
|     uint8_t reserve[DAY_STAT_RESERVE_BYTE];
 | |
| } iot_brm_rec_day_stat_entry_t;
 | |
| 
 | |
| /* record head */
 | |
| typedef struct iot_brm_rec_head {
 | |
|     /* record sequence n umber */
 | |
|     uint32_t rec_seq;
 | |
|     /* time stamp */
 | |
|     uint32_t ts;
 | |
|     /* check crc */
 | |
|     uint16_t crc;
 | |
|     /* payload label */
 | |
|     uint8_t  data[0];
 | |
| } iot_brm_rec_head_t;
 | |
| 
 | |
| /* add meter information */
 | |
| typedef struct _iot_brm_meter_rec_info{
 | |
|     uint8_t addr[IOT_MAC_ADDR_LEN];
 | |
|     /* proto type, see IOT_BRM_PROTO_TYPE_XXXX */
 | |
|     uint8_t proto_type : 3,
 | |
|     /* node port, see IOT_BRM_PORT_XXX */
 | |
|             port       : 2,
 | |
|     /* reserved for further use */
 | |
|             rsvd       : 3;
 | |
|     /* reserve */
 | |
|     uint8_t reserve[6];
 | |
| } iot_brm_meter_rec_info_t;
 | |
| 
 | |
| /* add meter event recording formats */
 | |
| typedef struct _iot_brm_meter_change_rec_entry{
 | |
|     /* add or delete meter event, 0: delete meter, 1: add or delete meter */
 | |
|     uint8_t flag;
 | |
|     /* time of occurrence event, uint is 1s */
 | |
|     uint32_t ts;
 | |
|     /* event add or detele meter number */
 | |
|     uint8_t  meter_cnt;
 | |
|     /* event add or detele meter addr */
 | |
|     iot_brm_meter_rec_info_t meter[METER_CHANGE_MAX_NUMBER];
 | |
| } iot_brm_meter_change_rec_entry_t;
 | |
| 
 | |
| /* power down event recording formats */
 | |
| typedef struct _iot_brm_pd_rec_entry {
 | |
|     /* start time of power down, uint is 1s */
 | |
|     uint32_t start_ts;
 | |
|     /* end time of power down, uint is 1s */
 | |
|     uint32_t end_ts;
 | |
|     /* reserved for further use */
 | |
|     uint8_t rsvd[14];
 | |
| } iot_brm_pd_rec_entry_t;
 | |
| 
 | |
| /* total/A/B/C energy (forward active, reverse active, combined reactive energy
 | |
|  * data 1 and combined reactive energy data 2) structure for record.
 | |
|  */
 | |
| typedef struct _iot_brm_rec_3p_energy {
 | |
|     /* total/A/B/C forward active energy, uint is 0.01kWh */
 | |
|     uint32_t ept_pos[IOT_BRM_PHASE_MAX];
 | |
|     /* total/A/B/C reverse active energy, uint is 0.01kWh */
 | |
|     uint32_t ept_neg[IOT_BRM_PHASE_MAX];
 | |
|     /* total/A/B/C combined reactive energy data 1, unit is 0.01kvarh */
 | |
|     uint32_t eqt_pos[IOT_BRM_PHASE_MAX];
 | |
|     /* total/A/B/C combined reactive energy data 2, unit is 0.01kvarh */
 | |
|     uint32_t eqt_neg[IOT_BRM_PHASE_MAX];
 | |
| } iot_brm_rec_3p_energy_t;
 | |
| 
 | |
| /* phase A/B/C variable (voltage, current, active power, reactive power and
 | |
|  * power factor) structure for record.
 | |
|  */
 | |
| typedef struct _iot_brm_rec_3p_var {
 | |
|     /* A/B/C phase voltage, uint is 0.1v */
 | |
|     uint16_t v[IOT_BRM_PHASE_C];
 | |
|     /* A/B/C phase current, uint is 0.001A */
 | |
|     int32_t i[IOT_BRM_PHASE_C];
 | |
|     /* total/A/B/C active power, uint is 0.0001 KW */
 | |
|     int32_t p[IOT_BRM_PHASE_MAX];
 | |
|     /* total/A/B/C reactive power, uint is 0.0001 Kvar */
 | |
|     int32_t q[IOT_BRM_PHASE_MAX];
 | |
|     /* total/A/B/C power factor, uint is 0.001 */
 | |
|     int16_t pf[IOT_BRM_PHASE_MAX];
 | |
| } iot_brm_rec_3p_var_t;
 | |
| 
 | |
| /* voltage abnormal event (loss of voltage, under voltage, over voltage,
 | |
|  * phase failure) recording formats.
 | |
|  */
 | |
| typedef struct _iot_brm_voltage_abnormal_rec_entry {
 | |
|     /* start time of voltage abnormal, uint is 1s */
 | |
|     uint32_t start_ts;
 | |
|     /* total/A/B/C energy (forward active, reverse active, combined reactive
 | |
|      * energy data 1 and combined reactive energy data 2) at start.
 | |
|      */
 | |
|     iot_brm_rec_3p_energy_t start_energy;
 | |
|     /* end time of voltage abnormal, uint is 1s */
 | |
|     uint32_t end_ts;
 | |
|     /* total/A/B/C energy (forward active, reverse active, combined reactive
 | |
|      * energy data 1 and combined reactive energy data 2) at end.
 | |
|      */
 | |
|     iot_brm_rec_3p_energy_t end_energy;
 | |
|     /* phase A/B/C meter variable (voltage, current, active power,
 | |
|      * reactive power and power factor) at start.
 | |
|      */
 | |
|     iot_brm_rec_3p_var_t start_var;
 | |
|     /* total/A/B/C ampere hour during the event active, uint is 0.01Ah */
 | |
|     uint32_t dur_ah[IOT_BRM_PHASE_MAX];
 | |
|     /* reserved for further use, and keep the size is 246 bytes */
 | |
|     uint8_t rsvd[36];
 | |
| } iot_brm_abn_v_rec_entry_t;
 | |
| 
 | |
| /* current abnormal event (loss of current, over current, current failure)
 | |
|  * recording formats.
 | |
|  */
 | |
| typedef struct _iot_brm_abnormal_current_rec_entry {
 | |
|     /* start time of current abnormal, uint is 1s */
 | |
|     uint32_t start_ts;
 | |
|     /* total/A/B/C energy (forward active, reverse active, combined reactive
 | |
|      * energy data 1 and combined reactive energy data 2) at start.
 | |
|      */
 | |
|     iot_brm_rec_3p_energy_t start_energy;
 | |
|     /* end time of current abnormal, uint is 1s */
 | |
|     uint32_t end_ts;
 | |
|     /* total/A/B/C energy (forward active, reverse active, combined reactive
 | |
|      * energy data 1 and combined reactive energy data 2) at start.
 | |
|      */
 | |
|     iot_brm_rec_3p_energy_t end_energy;
 | |
|     /* phase A/B/C meter variable (voltage, current, active power,
 | |
|      * reactive power and power factor) at start.
 | |
|      */
 | |
|     iot_brm_rec_3p_var_t start_var;
 | |
|     /* reserved for further use, and keep the size is 246 bytes */
 | |
|     uint8_t rsvd[52];
 | |
| } iot_brm_abn_i_rec_entry_t;
 | |
| 
 | |
| /* unbalance event (voltage unbalance, current unbalance) recording formats. */
 | |
| typedef struct _iot_brm_unbalance_rec_entry {
 | |
|     /* start time of current abnormal, uint is 1s */
 | |
|     uint32_t start_ts;
 | |
|     /* total/A/B/C energy (forward active, reverse active, combined reactive
 | |
|      * energy data 1 and combined reactive energy data 2) at start.
 | |
|      */
 | |
|     iot_brm_rec_3p_energy_t start_energy;
 | |
|     /* end time of current abnormal, uint is 1s */
 | |
|     uint32_t end_ts;
 | |
|     /* total/A/B/C energy (forward active, reverse active, combined reactive
 | |
|      * energy data 1 and combined reactive energy data 2) at start.
 | |
|      */
 | |
|     iot_brm_rec_3p_energy_t end_energy;
 | |
|     /* maximum unbalance rate */
 | |
|     uint32_t max_rate;
 | |
|     /* reserved for further use, and keep the size is 246 bytes */
 | |
|     uint8_t rsvd[106];
 | |
| } iot_brm_unbal_rec_entry_t;
 | |
| 
 | |
| /* debug tsfm info recording formats */
 | |
| typedef struct _iot_brm_rec_dbg_tsfm_entry {
 | |
|     /* time stamp */
 | |
|     uint32_t ts;
 | |
|     /* energy: average delta of zc, uint is 1us */
 | |
|     uint16_t energy;
 | |
|     /* the phase line where the tsfm info is received, see IOT_PLC_PHASE_XXX */
 | |
|     uint8_t  phase          : 2,
 | |
|     /* flag to mark if it is reverse zero crossing reception */
 | |
|              is_reverse_zc  : 1,
 | |
|     /* flag to mark if the received tsfm info is valid */
 | |
|              is_valid       : 1,
 | |
|     /* reserved for further use */
 | |
|              rsvd1          : 4;
 | |
|     /* received tsfm address */
 | |
|     uint8_t  tsfm_addr[IOT_MAC_ADDR_LEN];
 | |
|     /* reserved for further use */
 | |
|     uint8_t  rsvd2[9];
 | |
| } iot_brm_rec_dbg_tsfm_entry_t;
 | |
| 
 | |
| /* branch detect recording formats */
 | |
| typedef struct {
 | |
|     /* time stamp of received identification signal */
 | |
|     uint32_t ts;
 | |
|     /* signal intensity 1, unit: 1.0A */
 | |
|     float   signal1_rssi;
 | |
|     /* signal intensity 2, unit: 1.0A */
 | |
|     float   signal2_rssi;
 | |
|     /* base wave intensity */
 | |
|     float   base_rssi;
 | |
|     /* background noise, unit: 1.0A */
 | |
|     float   noise;
 | |
|     /* success flag */
 | |
|     uint8_t is_vaild  : 1,
 | |
|     /* phase see, IOT_PLC_PHASE_XXX */
 | |
|             phase     : 2,
 | |
|     /* reserved */
 | |
|             reserved1 : 5;
 | |
|     /* identification code len */
 | |
|     uint8_t id_code_len;
 | |
|     /* identification code */
 | |
|     uint8_t id_code[IOT_HW_TOPO_MAX_NUMBER_OF_CODES];
 | |
|     /* reserved */
 | |
|     uint8_t reserved2[16];
 | |
| } iot_brm_recv_rec_entry_t;
 | |
| 
 | |
| #pragma pack(pop)
 | |
| 
 | |
| typedef struct iot_brm_rec_buffer_desc {
 | |
|     /* record number in the buffer */
 | |
|     uint8_t cnt;
 | |
|     /* buffer recording depth */
 | |
|     uint8_t depth;
 | |
|     /* buffer data */
 | |
|     uint8_t  data_buf[0];
 | |
| } iot_brm_rec_buffer_desc_t;
 | |
| 
 | |
| /* record region descriptor */
 | |
| typedef struct iot_brm_rec_region_desc {
 | |
|     /* record entry size, contains record headers */
 | |
|     uint32_t entry_size;
 | |
|     /* region start position */
 | |
|     uint32_t start;
 | |
|     /* region size */
 | |
|     uint32_t size;
 | |
|     /* recording depth */
 | |
|     uint32_t rec_depth;
 | |
|     /* record serial number will assigned */
 | |
|     uint32_t seq;
 | |
|     /* recording depth */
 | |
|     uint32_t new_idx;
 | |
|     /* */
 | |
|     uint32_t oldest_idx;
 | |
|     /* timestamp of the latest record */
 | |
|     uint32_t last_rec_ts;
 | |
|     /* buffer record serial number */
 | |
|     iot_brm_rec_buffer_desc_t  *buffer;
 | |
| } iot_brm_rec_region_desc_t;
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_get_cur_reg() - get record region.
 | |
|  * @retval:          return record region.
 | |
|  */
 | |
| iot_brm_rec_region_desc_t *iot_brm_get_cur_reg(void);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_frozen_rec_read() - read frozen records.
 | |
|  * @param tp:        frozen type, see iot_brm_frozen_type_t.
 | |
|  * @param last_idx:  specifies that the last n frozen records will be read.
 | |
|  * @param ts:        return record timestamp.
 | |
|  * @param pkt:       if read successfully, return iot_pkt containing recorded
 | |
|  *                   data.
 | |
|  * @retval: ERR_OK - successfully, otherwise - error code
 | |
|  */
 | |
| uint8_t iot_brm_frozen_rec_read(iot_brm_frozen_type_t tp,
 | |
|     uint32_t last_idx, uint32_t *ts, iot_pkt_t **pkt);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_frozen_rec() - freezing data.
 | |
|  * @param tp:     frozen type, see iot_brm_frozen_type_t.
 | |
|  * @param ts:     freezing timestamp.
 | |
|  * @param frozen_data: if set NULL, frozen the current data, if fill hole,
 | |
|  *                     please fill need frozen data
 | |
|  */
 | |
| void iot_brm_frozen_rec(iot_brm_frozen_type_t tp, uint32_t ts,
 | |
|     void *frozen_data);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_curve_rec() - curve Recording.
 | |
|  * @param ts: timestamp.
 | |
|  */
 | |
| void iot_brm_curve_rec(uint32_t ts);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_curve_rec_read() - reading curve record.
 | |
|  * @param ts: specify the start time,  and return the time of the first point of
 | |
|  *            successful lookup
 | |
|  * @param inteval: time interval.
 | |
|  * @param n: specifies the number of points to be read, returns the number of
 | |
|  *           points actually read.
 | |
|  * @retval: ERR_OK - successfully, otherwise - error code
 | |
|  */
 | |
| uint8_t iot_brm_curve_rec_read(uint32_t *ts,
 | |
|     uint32_t inteval, uint8_t *n, iot_pkt_t **pkt);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_evt_rec_read() - read event records.
 | |
|  * @param tp:        event type, see iot_brm_evt_type_t.
 | |
|  * @param last_idx:  specifies that the last n event records will be read.
 | |
|  * @param ts:        return record timestamp.
 | |
|  * @param pkt:       if read successfully, return iot_pkt containing recorded
 | |
|  *                   data.
 | |
|  * @retval: ERR_OK - successfully, otherwise - error code
 | |
|  */
 | |
| uint8_t iot_brm_evt_rec_read(iot_brm_evt_type_t tp,
 | |
|     uint32_t last_idx, uint32_t *ts, iot_pkt_t **pkt);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_evt_rec() - eventing data.
 | |
|  * @param tp:     event type, see iot_brm_evt_type_t.
 | |
|  * @param ts:     eventing timestamp.
 | |
|  * @param p_arg:  eventing record data.
 | |
|  * @param is_overlast: do you want to override the last record, 1 - over,
 | |
|  *                     0 - not
 | |
|  */
 | |
| void iot_brm_evt_rec(iot_brm_evt_type_t tp, uint32_t ts, void *p_arg,
 | |
|     uint8_t is_overlast);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_rec_load() - load records region descriptor.
 | |
|  * @param rec_desc:     the record region descriptor.
 | |
|  * @param is_order:     Whether to sort the record data.
 | |
|  */
 | |
| void iot_brm_rec_load(iot_brm_rec_region_desc_t *rec_desc, uint8_t is_order);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_rec_misc_write() - misc data.
 | |
|  * @param tp:     misc type, see iot_brm_rec_misc_type_t.
 | |
|  * @param ts:     timestamp.
 | |
|  * @param p_arg:  record data.
 | |
|  * @param is_overlast: do you want to override the last record, 1 - over,
 | |
|  *                     0 - not
 | |
|  */
 | |
| void iot_brm_rec_misc_write(iot_brm_rec_misc_type_t tp, uint32_t ts,
 | |
|     void *p_arg, uint8_t is_overlast);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_rec_misc_read() - read misc records.
 | |
|  * @param tp:        misc type, see iot_brm_rec_misc_type_t.
 | |
|  * @param last_idx:  specifies that the last n event records will be read.
 | |
|  * @param ts:        return timestamp.
 | |
|  * @param pkt:       if read successfully, return iot_pkt containing recorded
 | |
|  *                   data.
 | |
|  * @retval: ERR_OK - successfully, otherwise - error code
 | |
|  */
 | |
| uint8_t iot_brm_rec_misc_read(iot_brm_rec_misc_type_t tp,
 | |
|     uint32_t last_idx, uint32_t *ts, iot_pkt_t **pkt);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_rec_get_misc_total_num() - Get the record serial number.
 | |
|  * @param tp:        misc type, see iot_brm_rec_misc_type_t.
 | |
|  * @retval:          serial number.
 | |
|  */
 | |
| uint32_t iot_brm_rec_get_misc_total_num(iot_brm_rec_misc_type_t tp);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_rec_write() - write records data.
 | |
|  * @param desc:         record region descriptor.
 | |
|  * @param ts:           the record data timestamp.
 | |
|  * @param rec_data:     the recorded data will be write.
 | |
|  * @param is_immediate: whether the recorded data need to immediate into flash.
 | |
|  * @param is_overlast:  do you want to override the last record, 1 - over,
 | |
|  *                      0 - not
 | |
| 
 | |
|  */
 | |
| void iot_brm_rec_write(iot_brm_rec_region_desc_t *desc, uint32_t ts,
 | |
|     uint8_t *rec_data, uint8_t is_immediate, uint8_t is_overlast);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_rec_read() - read records data.
 | |
|  * @param p_rec_desc:   record region descriptor.
 | |
|  * @param last_idx:     specifies that the last n event records will be read.
 | |
|  * @param ts:           return record timestamp.
 | |
|  * @param pkt:          if read successfully, return iot_pkt containing recorded
 | |
|  *                      data.
 | |
|  * @retval: ERR_OK - successfully, otherwise - error code
 | |
|  */
 | |
| uint8_t iot_brm_rec_read(iot_brm_rec_region_desc_t *p_rec_desc,
 | |
|     uint32_t last_idx, uint32_t *ts, iot_pkt_t **pkt);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_stat_rec() - write statistic record data.
 | |
|  * @param tp:     stat rec type, see iot_brm_stat_rec_type_t.
 | |
|  */
 | |
| void iot_brm_stat_rec(iot_brm_stat_rec_type_t tp);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_stat_rec_read() - read statistic record.
 | |
|  * @param tp:        stat rec type, see iot_brm_stat_rec_type_t.
 | |
|  * @param last_idx:  specifies that the last n max min records will be read.
 | |
|  * @param ts:        return record timestamp.
 | |
|  * @retval: recorded statistic data.
 | |
|  * @retval: NULL - read is fail.
 | |
|  *
 | |
|  */
 | |
| iot_pkt_t *iot_brm_stat_rec_read(iot_brm_stat_rec_type_t tp, uint32_t last_idx,
 | |
|     uint32_t *ts);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_rec_dbg_write() - write debug record data.
 | |
|  * @param tp: debug record type, see iot_brm_rec_dbg_type_t.
 | |
|  */
 | |
| void iot_brm_rec_dbg_write(iot_brm_rec_dbg_type_t tp, void *info);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_rec_dbg_read() - read debug record.
 | |
|  * @param tp:        debug record type, see iot_brm_rec_dbg_type_t.
 | |
|  * @param last_idx:  specify the latest nth record.
 | |
|  * @param ts:        return record timestamp.
 | |
|  * @retval: recorded data.
 | |
|  * @retval: NULL - read is fail.
 | |
|  */
 | |
| iot_pkt_t *iot_brm_rec_dbg_read(iot_brm_rec_dbg_type_t tp,
 | |
|     uint32_t last_idx, uint32_t *ts);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_rec_dbg_get_cnt() - get debug record counter.
 | |
|  * @param tp: debug record type, see iot_brm_rec_dbg_type_t.
 | |
|  * @retval: debug record counter.
 | |
|  */
 | |
| uint32_t iot_brm_rec_dbg_get_cnt(iot_brm_rec_dbg_type_t tp);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_br_recv_rec() - information data record.
 | |
|  * @param ts:          time stamp.
 | |
|  * @param len:         data len.
 | |
|  * @param data:        data pointer.
 | |
|  */
 | |
| void iot_brm_br_recv_rec(uint32_t ts, uint8_t len, uint8_t *data);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_br_rec_read() - reading information record.
 | |
|  * @param ts: specify the start time, and return the time of the first point of
 | |
|  *            successful lookup
 | |
|  * @param total_cnt: return The number of the latest records in the current ts.
 | |
|  * @param n: specifies the number of points to be read, returns the number of
 | |
|  *           points actually read.
 | |
|  * @param pkt: return reading information record pointer.
 | |
|  * @param start_index: the number after idx found according to ts.
 | |
|  * @retval: ERR_OK - successfully, otherwise - error code
 | |
|  */
 | |
| uint8_t iot_brm_br_rec_read(uint32_t *ts, uint16_t *total_cnt,
 | |
|     uint8_t *n, iot_pkt_t **pkt, uint16_t start_idx);
 | |
| 
 | |
| /**
 | |
|  * @brief iot_brm_rec_init() - initialization recording Module
 | |
|  * @param buf_config:   match enable buffer flag, bit 0, 1, 2, 3...,
 | |
|                         see IOT_BRM_EN_REC_BUFFER_XXX.
 | |
|  * @retval: ERR_OK - successfully, otherwise - error code
 | |
|  */
 | |
| uint32_t iot_brm_rec_init(uint32_t buf_config);
 | |
| 
 | |
| #endif /* IOT_BRM_ENABLE && PLC_SUPPORT_STA_ROLE */
 | |
| 
 | |
| #ifdef __cplusplus
 | |
| }
 | |
| #endif
 | |
| 
 | |
| #endif  /* IOT_BRM_REC_H */
 | |
| 
 |