886 lines
		
	
	
		
			31 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			886 lines
		
	
	
		
			31 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_BRM_COMMON_H
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_COMMON_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* os shim includes */
							 | 
						||
| 
								 | 
							
								#include "os_types_api.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "iot_config_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_utils_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_pkt_api.h"
							 | 
						||
| 
								 | 
							
								#include "proto_645.h"
							 | 
						||
| 
								 | 
							
								#include "iot_rtc_api.h"
							 | 
						||
| 
								 | 
							
								#include "iot_sg_ext_sta_api.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define iot_brm_printf iot_printf
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_MOVE_DEV_ENABLE                 0
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* enable and disable cache functions  */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_CACHE_ENABLE                    1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define the maximum number of nodes supported by branch management devices */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_SUPPORT_NODE_MAX                32
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define periodic timer interval, uint is 1ms */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PERIOND_TIMER_INTERVAL          1000
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define the maximum number of baud rates supported */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_SUPPORT_BAUD_MAX                5
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* brm module protocol type definition */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PROTO_TYPE_TRANSPARENT          0
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PROTO_TYPE_645_1997             1
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PROTO_TYPE_645_2007             2
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PROTO_TYPE_69845                3
							 | 
						||
| 
								 | 
							
								/* this is an abstract protocol type, which is used to forward 645-2007
							 | 
						||
| 
								 | 
							
								 * messages through 376.1.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PROTO_TYPE_645_2007_BY_3761     4
							 | 
						||
| 
								 | 
							
								/* this is an abstract protocol type, which is used to forward 645-2007
							 | 
						||
| 
								 | 
							
								 * messages through 698.45.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PROTO_TYPE_645_2007_BY_69845    5
							 | 
						||
| 
								 | 
							
								/* this is an abstract protocol type, which is used to forward 698.45
							 | 
						||
| 
								 | 
							
								 * messages through 698.45.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PROTO_TYPE_69845_BY_3761        6
							 | 
						||
| 
								 | 
							
								/* this is an abstract protocol type, which is used to forward 698.45
							 | 
						||
| 
								 | 
							
								 * messages through 376.1.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PROTO_TYPE_69845_BY_69845       7
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PROTO_TYPE_MAX \
							 | 
						||
| 
								 | 
							
								    (IOT_BRM_PROTO_TYPE_69845_BY_69845 + 1)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* this define is the receive message timeout time parameter for proxy transfer
							 | 
						||
| 
								 | 
							
								 * command request
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PROXY_TRANS_TIMEOUT             3
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define the port where the node is located */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PORT_RS485                      0
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PORT_PLC_WEAK                   1
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PORT_PLC                        2
							 | 
						||
| 
								 | 
							
								/* the module and BRM are in the same network, but the module is from other
							 | 
						||
| 
								 | 
							
								 * vendor, and cannot be collected by PLC.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PORT_PLC_WEAK_NOT_SAME_VENDOR   3
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PORT_MAX \
							 | 
						||
| 
								 | 
							
								    (IOT_BRM_PORT_PLC_WEAK_NOT_SAME_VENDOR + 1)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define operator */
							 | 
						||
| 
								 | 
							
								#define  IOT_BRM_OPERATOR_EXT                   0
							 | 
						||
| 
								 | 
							
								#define  IOT_BRM_OPERATOR_INTERNAL              1
							 | 
						||
| 
								 | 
							
								#define  IOT_BRM_OPERATOR_CCO                   2
							 | 
						||
| 
								 | 
							
								#define  IOT_BRM_OPERATOR_MAX                   (IOT_BRM_OPERATOR_CCO + 1)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* defined phase value for BRM */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PHASE_ALL                         0
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PHASE_A                           1
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PHASE_B                           2
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PHASE_C                           3
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PHASE_MAX                         (IOT_BRM_PHASE_C + 1)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* quadrant1:  active power is positive, reactive power is positive. */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_QUAD_1                      0
							 | 
						||
| 
								 | 
							
								/* quadrant2:  active power is negative, reactive power is positive. */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_QUAD_2                      1
							 | 
						||
| 
								 | 
							
								/* quadrant3:  active power is negative, reactive power is negative. */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_QUAD_3                      2
							 | 
						||
| 
								 | 
							
								/* quadrant3:  active power is positive, reactive power is negative. */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_QUAD_4                      3
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* read meter time state */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_READ_METER_TIME_STATE_INIT        0
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_READ_METER_TIME_STATE_DATA        1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define support rates */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_RATE_MAX                    4
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define minimum effective voltage, unit is 0.1V */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_VALID_VOLTAGE_MIN                 100
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define support max node info count */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_PROTO_GET_INFO_CNT                16
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* calibration idle status */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_ONESHOT_CALIBRATE_IDLE            (0)
							 | 
						||
| 
								 | 
							
								/* calibration doing status */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_ONESHOT_CALIBRATE_DOING           (1)
							 | 
						||
| 
								 | 
							
								/* calibration successful status */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_ONESHOT_CALIBRATE_SUCCESS         (2)
							 | 
						||
| 
								 | 
							
								/* calibration fail status */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_ONESHOT_CALIBRATE_FAIL            (3)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define current transformer ratio number */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_I_RATIO_DEFAULT             (0)
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_I_RATIO_4000                (1)
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_I_RATIO_8000                (2)
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_I_RATIO_10000               (3)
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_I_RATIO_12000               (4)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* snr calculation factor. this value defined the proportion
							 | 
						||
| 
								 | 
							
								 * of the snr of the new snr while calculate the final snr
							 | 
						||
| 
								 | 
							
								 * based on the snr history. set this value to x means the new
							 | 
						||
| 
								 | 
							
								 * snr only contribute to 1/x to the final snr.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_NW_SNR_FACTOR                     (8)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* give smallest number, which is -128 */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_INVALID_SNR                       (-128)
							 | 
						||
| 
								 | 
							
								/* give largest number, which is 127 */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_MAX_SNR                           (127)
							 | 
						||
| 
								 | 
							
								/* highest available snr */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_SNR_HIGHEST                       (90)
							 | 
						||
| 
								 | 
							
								/* lowest available snr */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_SNR_LOWEST                        (-10)
							 | 
						||
| 
								 | 
							
								/* update snr max threshold value */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_MAX_FD_SNR                        (35)
							 | 
						||
| 
								 | 
							
								/* update snr min threshold value */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_MIN_FD_SNR                        (-10)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* demand max slide interval, unit: 1 minute */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_DEMAND_SLIDE_INTERVAL_MAX   (5)
							 | 
						||
| 
								 | 
							
								/* demand default slide interval, unit: 1 minute */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_DEMAND_SLIDE_INTERVAL_DEF   (1)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* max demand period, unit: 1 minute */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_DEMAND_PERIOD_MAX           (60)
							 | 
						||
| 
								 | 
							
								/* default demand period, unit: 1 minute */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_METER_DEMAND_PERIOD_DEF           (15)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* how many settlement dates can be set each month */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_SUPPORT_MSD_NUM                   (3)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* come from of the data transfer road */
							 | 
						||
| 
								 | 
							
								typedef enum _iot_brm_data_owner {
							 | 
						||
| 
								 | 
							
								    /* data is come from sg app */
							 | 
						||
| 
								 | 
							
								    iot_brm_data_owner_sg_app = 0,
							 | 
						||
| 
								 | 
							
								    /* data is come from rs485 */
							 | 
						||
| 
								 | 
							
								    iot_brm_data_owner_rs485,
							 | 
						||
| 
								 | 
							
								    /* data is come from multifunction rs485 */
							 | 
						||
| 
								 | 
							
								    iot_brm_data_owner_mf_rs485,
							 | 
						||
| 
								 | 
							
								    /* owner limit */
							 | 
						||
| 
								 | 
							
								    iot_brm_data_owner_max,
							 | 
						||
| 
								 | 
							
								} iot_brm_data_owner_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* three-phase energy-type meter data structure */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_brm_meter_energy_triphase {
							 | 
						||
| 
								 | 
							
								    /* 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];
							 | 
						||
| 
								 | 
							
								} iot_brm_meter_energy_triphase_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _iot_brm_meter_max_demand {
							 | 
						||
| 
								 | 
							
								    /* max demand */
							 | 
						||
| 
								 | 
							
								    uint32_t max_demand;
							 | 
						||
| 
								 | 
							
								    /* max demand time */
							 | 
						||
| 
								 | 
							
								    uint32_t ts;
							 | 
						||
| 
								 | 
							
								} iot_brm_meter_max_demand_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* three-phase energy-type meter demand data structure */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_brm_meter_triphase_max_demand {
							 | 
						||
| 
								 | 
							
								    /* max positive active energy demand, total ~ rates 1-4, uint: kw */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t ept_pos[IOT_BRM_METER_RATE_MAX + 1];
							 | 
						||
| 
								 | 
							
								    /* max negative active energy demand, total ~ rates 1-4, uint: kw */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t ept_neg[IOT_BRM_METER_RATE_MAX + 1];
							 | 
						||
| 
								 | 
							
								    /* max positive reactive energy demand, total ~ rates 1-4, uint: kvar */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t eqt_pos[IOT_BRM_METER_RATE_MAX + 1];
							 | 
						||
| 
								 | 
							
								    /* max negative reactive energy demand, total ~ rates 1-4, uint: kvar */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t eqt_neg[IOT_BRM_METER_RATE_MAX + 1];
							 | 
						||
| 
								 | 
							
								    /* max positive apparent energy demand, total ~ rates 1-4, uint: kVA */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t est_pos[IOT_BRM_METER_RATE_MAX + 1];
							 | 
						||
| 
								 | 
							
								    /* max negative apparent energy demand, total ~ rates 1-4, uint: kVA */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t est_neg[IOT_BRM_METER_RATE_MAX + 1];
							 | 
						||
| 
								 | 
							
								    /* quad reactive energy demand, uint: kvar */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t
							 | 
						||
| 
								 | 
							
								        eqt_quad[IOT_BRM_METER_QUAD_4 + 1][IOT_BRM_METER_RATE_MAX + 1];
							 | 
						||
| 
								 | 
							
								} iot_brm_meter_triphase_max_demand_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* sig-phase energy-type meter data structure */
							 | 
						||
| 
								 | 
							
								typedef  struct  _iot_brm_meter_sigphase_max_demand {
							 | 
						||
| 
								 | 
							
								    /* positive active energy demand, uint: kW */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t ept_pos;
							 | 
						||
| 
								 | 
							
								    /* negative active energy demand, uint: kW */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t ept_neg;
							 | 
						||
| 
								 | 
							
								    /* positive reactive energy demand, uint: kvar */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t eqt_pos;
							 | 
						||
| 
								 | 
							
								    /* negative reactive energy demand, uint: kvar */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t eqt_neg;
							 | 
						||
| 
								 | 
							
								    /* positive apparent energy, uint: kVAh */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t est_pos;
							 | 
						||
| 
								 | 
							
								    /* negative apparent energy, uint: kVAh */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t est_neg;
							 | 
						||
| 
								 | 
							
								    /* quad reactive energy demand, uint: kvar */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_max_demand_t eqt_quad[IOT_BRM_METER_QUAD_4 + 1];
							 | 
						||
| 
								 | 
							
								} iot_brm_meter_sigphase_max_demand_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* sig-phase energy-type meter data structure */
							 | 
						||
| 
								 | 
							
								typedef  struct  _iot_brm_meter_energy_sigphase {
							 | 
						||
| 
								 | 
							
								    /* 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;
							 | 
						||
| 
								 | 
							
								    /* positive apparent energy, uint is 1/ec kVAh */
							 | 
						||
| 
								 | 
							
								    uint32_t est_pos;
							 | 
						||
| 
								 | 
							
								    /* negative apparent energy, uint is 1/ec kVAh */
							 | 
						||
| 
								 | 
							
								    uint32_t est_neg;
							 | 
						||
| 
								 | 
							
								    /* quad reactive energy, uint is  1/ec kvarh */
							 | 
						||
| 
								 | 
							
								    uint32_t eqt_quad[IOT_BRM_METER_QUAD_4 + 1];
							 | 
						||
| 
								 | 
							
								} iot_brm_meter_energy_sigphase_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* variable-type meter data structure */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_brm_meter_var {
							 | 
						||
| 
								 | 
							
								     /* EC constant */
							 | 
						||
| 
								 | 
							
								    uint16_t    ec;
							 | 
						||
| 
								 | 
							
								    /* power line frequency, uint is 0.01Hz */
							 | 
						||
| 
								 | 
							
								    uint16_t    freq;
							 | 
						||
| 
								 | 
							
								    /* temperature, uint is 0.1 centigrade */
							 | 
						||
| 
								 | 
							
								    int16_t     temperature;
							 | 
						||
| 
								 | 
							
								    /* humidity, unit is 0.1 %RH */
							 | 
						||
| 
								 | 
							
								    int16_t     humidity;
							 | 
						||
| 
								 | 
							
								    /* voltage angle between phaseA and phaseB. unit: 1degrees */
							 | 
						||
| 
								 | 
							
								    int16_t     angle_ua_ub;
							 | 
						||
| 
								 | 
							
								    /* voltage angle between phaseA and phaseC. unit: 1degrees */
							 | 
						||
| 
								 | 
							
								    int16_t     angle_ua_uc;
							 | 
						||
| 
								 | 
							
								    /* voltage angle between phaseB and phaseC. unit: 1degrees */
							 | 
						||
| 
								 | 
							
								    int16_t     angle_ub_uc;
							 | 
						||
| 
								 | 
							
								    /* voltage RMS, uint is 0.1V */
							 | 
						||
| 
								 | 
							
								    uint16_t    v[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								    /* phase current RMS, uint is 0.001A */
							 | 
						||
| 
								 | 
							
								    int32_t     i[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								    /* N line current RMS, uint is 0.001A */
							 | 
						||
| 
								 | 
							
								    int32_t     i_n;
							 | 
						||
| 
								 | 
							
								    /* high-precision phase current RMS, uint is 0.00001A */
							 | 
						||
| 
								 | 
							
								    int32_t     i_high[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								    /* active power, uint is 0.0001 KW */
							 | 
						||
| 
								 | 
							
								    int32_t     p[IOT_BRM_PHASE_MAX];
							 | 
						||
| 
								 | 
							
								    /* high-precision active power RMS, uint is 0.000001 KW */
							 | 
						||
| 
								 | 
							
								    int32_t     p_high[IOT_BRM_PHASE_MAX];
							 | 
						||
| 
								 | 
							
								    /* reactive power, uint is 0.0001 Kvar */
							 | 
						||
| 
								 | 
							
								    int32_t     q[IOT_BRM_PHASE_MAX];
							 | 
						||
| 
								 | 
							
								    /* high-precision reactive power RMS, uint is 0.000001 Kvar */
							 | 
						||
| 
								 | 
							
								    int32_t     q_high[IOT_BRM_PHASE_MAX];
							 | 
						||
| 
								 | 
							
								    /* apparent power, uint is 0.0001 KVA */
							 | 
						||
| 
								 | 
							
								    int32_t     s[IOT_BRM_PHASE_MAX];
							 | 
						||
| 
								 | 
							
								    /* high-precision apparent power RMS, uint is 0.000001 KVA */
							 | 
						||
| 
								 | 
							
								    int32_t     s_high[IOT_BRM_PHASE_MAX];
							 | 
						||
| 
								 | 
							
								    /* power factor, uint is 0.001 */
							 | 
						||
| 
								 | 
							
								    int16_t     pf[IOT_BRM_PHASE_MAX];
							 | 
						||
| 
								 | 
							
								    /* voltage and current phase angle, uint is 0.1 degrees*/
							 | 
						||
| 
								 | 
							
								    uint16_t    ui_anglep[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								    /* quadrant of current work */
							 | 
						||
| 
								 | 
							
								    uint8_t     quad[IOT_BRM_PHASE_MAX];
							 | 
						||
| 
								 | 
							
								} iot_brm_meter_var_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* node sampling data structure */
							 | 
						||
| 
								 | 
							
								typedef struct {
							 | 
						||
| 
								 | 
							
								    /* voltage, uint is 0.1V */
							 | 
						||
| 
								 | 
							
								    uint16_t    v[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								    /* current, uint is 0.001A */
							 | 
						||
| 
								 | 
							
								    int32_t     i[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								    /* active power, uint is 0.1W */
							 | 
						||
| 
								 | 
							
								    int32_t     p[IOT_BRM_PHASE_MAX];
							 | 
						||
| 
								 | 
							
								    /* N-line current, uint is 0.001A  */
							 | 
						||
| 
								 | 
							
								    int32_t     i_n;
							 | 
						||
| 
								 | 
							
								    /* meter time difference uint is 1s */
							 | 
						||
| 
								 | 
							
								    int32_t     tm_diff;
							 | 
						||
| 
								 | 
							
								    /* meter time */
							 | 
						||
| 
								 | 
							
								    iot_time_tm_t tm;
							 | 
						||
| 
								 | 
							
								    /* number of opening covers */
							 | 
						||
| 
								 | 
							
								    uint32_t    open_cover_n;
							 | 
						||
| 
								 | 
							
								    /* meter time difference is valid or not, 0 - invalid, 1 - valid */
							 | 
						||
| 
								 | 
							
								    uint8_t     tm_diff_valid      : 1,
							 | 
						||
| 
								 | 
							
								    /* meter time difference is state,  see IOT_BRM_READ_METER_XXX */
							 | 
						||
| 
								 | 
							
								                tm_state           : 2,
							 | 
						||
| 
								 | 
							
								    /* correct time is start,  see IOT_BRM_CORRECT_TIME_XXX */
							 | 
						||
| 
								 | 
							
								                correct_time_state : 2,
							 | 
						||
| 
								 | 
							
								    /* correct time retry number, only 698.45 meter valid */
							 | 
						||
| 
								 | 
							
								                retry_cnt          : 3;
							 | 
						||
| 
								 | 
							
								    /* status words */
							 | 
						||
| 
								 | 
							
								    uint16_t    words[PROTO_645_07_MAX_STATUS_WORDS_INDEX];
							 | 
						||
| 
								 | 
							
								    /* flag to mark if the power information is updated */
							 | 
						||
| 
								 | 
							
								    uint32_t    p_update           : 1,
							 | 
						||
| 
								 | 
							
								    /* reserved for further use */
							 | 
						||
| 
								 | 
							
								                rsvd               : 31;
							 | 
						||
| 
								 | 
							
								} iot_brm_node_samp_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_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_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* day statistical infomation recording formats */
							 | 
						||
| 
								 | 
							
								typedef struct {
							 | 
						||
| 
								 | 
							
								    /* The state of max voltage */
							 | 
						||
| 
								 | 
							
								    iot_brm_max_min_v_t max_v[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								    /* The state of min voltage */
							 | 
						||
| 
								 | 
							
								    iot_brm_max_min_v_t min_v[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								    /* The state of max current */
							 | 
						||
| 
								 | 
							
								    iot_brm_max_min_i_t max_i[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								    /* The state of min current */
							 | 
						||
| 
								 | 
							
								    iot_brm_max_min_i_t min_i[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								} iot_brm_meter_day_stat_info_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* meter info structure */
							 | 
						||
| 
								 | 
							
								typedef struct  _iot_brm_meter_info {
							 | 
						||
| 
								 | 
							
								    /* voltage ratio */
							 | 
						||
| 
								 | 
							
								    uint32_t  v_ratio;
							 | 
						||
| 
								 | 
							
								    /* current ratio */
							 | 
						||
| 
								 | 
							
								    uint32_t  i_ratio;
							 | 
						||
| 
								 | 
							
								    /* current coefficient unit: 0.0001 */
							 | 
						||
| 
								 | 
							
								    uint32_t i_ratio_coeff;
							 | 
						||
| 
								 | 
							
								    /* variable-type meter data */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_var_t var;
							 | 
						||
| 
								 | 
							
								    /* three-phase total energy data structure*/
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_energy_triphase_t e_t;
							 | 
						||
| 
								 | 
							
								    /* sig-phase energy metering data, A/B/C */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_energy_sigphase_t e_s[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								    /* meter day statistical infomation recording formats */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_day_stat_info_t day_stat;
							 | 
						||
| 
								 | 
							
								    /* total three-phase total energy max demand data structure*/
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_triphase_max_demand_t e_t_max_demand;
							 | 
						||
| 
								 | 
							
								    /* sig-phase energy metering max demand data, A/B/C */
							 | 
						||
| 
								 | 
							
								    iot_brm_meter_sigphase_max_demand_t e_s_max_demand[IOT_BRM_PHASE_C];
							 | 
						||
| 
								 | 
							
								} iot_brm_meter_info_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define curve config structure */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_brm_curve_cfg {
							 | 
						||
| 
								 | 
							
								    /* flag to mark if "rec_start" valid */
							 | 
						||
| 
								 | 
							
								    uint16_t rec_start_valid : 1,
							 | 
						||
| 
								 | 
							
								    /* flag to mark if "interval" valid */
							 | 
						||
| 
								 | 
							
								             interval_valid  : 1,
							 | 
						||
| 
								 | 
							
								    /* reserved for further use */
							 | 
						||
| 
								 | 
							
								             rsvd            : 14;
							 | 
						||
| 
								 | 
							
								    /* starting base time of curve record */
							 | 
						||
| 
								 | 
							
								    iot_time_tm_t rec_start;
							 | 
						||
| 
								 | 
							
								    /* interval of curve recording, uint is 1s */
							 | 
						||
| 
								 | 
							
								    uint16_t interval;
							 | 
						||
| 
								 | 
							
								} iot_brm_curve_cfg_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define terminal config structure */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_brm_terminal_cfg {
							 | 
						||
| 
								 | 
							
								    /* terminal communication port number, see PROTO_PORT_RS485_X. */
							 | 
						||
| 
								 | 
							
								    uint8_t  trans_port         :2,
							 | 
						||
| 
								 | 
							
								    /* terminal type, if 0: 3761 terminal, 1: 698 terminal. */
							 | 
						||
| 
								 | 
							
								             is_698             :1,
							 | 
						||
| 
								 | 
							
								    /* reserved for further use. */
							 | 
						||
| 
								 | 
							
								             rsvd               :5;
							 | 
						||
| 
								 | 
							
								    /* terminal address configuration. */
							 | 
						||
| 
								 | 
							
								    union {
							 | 
						||
| 
								 | 
							
								        /* terminal address 698, little-endian */
							 | 
						||
| 
								 | 
							
								        uint8_t trans_698_addr[IOT_MAC_ADDR_LEN];
							 | 
						||
| 
								 | 
							
								        struct{
							 | 
						||
| 
								 | 
							
								            /* administrative region code */
							 | 
						||
| 
								 | 
							
								            uint16_t area_code;
							 | 
						||
| 
								 | 
							
								            /* terminal address region */
							 | 
						||
| 
								 | 
							
								            uint16_t dev_addr;
							 | 
						||
| 
								 | 
							
								        } trans_3761;
							 | 
						||
| 
								 | 
							
								    } terminal_addr;
							 | 
						||
| 
								 | 
							
								} iot_brm_terminal_cfg_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#pragma pack(push)  /* save the pack status */
							 | 
						||
| 
								 | 
							
								#pragma pack(1)     /* 1 byte align */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* node info descriptor */
							 | 
						||
| 
								 | 
							
								typedef struct _iot_brm_node_info {
							 | 
						||
| 
								 | 
							
								    /* node addr */
							 | 
						||
| 
								 | 
							
								    uint8_t  addr[IOT_MAC_ADDR_LEN];
							 | 
						||
| 
								 | 
							
								    /* node porto type, see IOT_BRM_PROTO_TYPE_XXX */
							 | 
						||
| 
								 | 
							
								    uint8_t  proto_type : 3,
							 | 
						||
| 
								 | 
							
								    /* node port, see IOT_BRM_PORT_XXX */
							 | 
						||
| 
								 | 
							
								             port       : 3,
							 | 
						||
| 
								 | 
							
								    /* reserved for further use */
							 | 
						||
| 
								 | 
							
								             rsvd       : 2;
							 | 
						||
| 
								 | 
							
								    /* PT ratio, uint is x1 */
							 | 
						||
| 
								 | 
							
								    uint8_t  v_ratio;
							 | 
						||
| 
								 | 
							
								    /* CT ratio, uint is x1 */
							 | 
						||
| 
								 | 
							
								    uint16_t i_ratio;
							 | 
						||
| 
								 | 
							
								    /* assembly number */
							 | 
						||
| 
								 | 
							
								    uint8_t  ass_pos : 6,
							 | 
						||
| 
								 | 
							
								    /* reserved for further use */
							 | 
						||
| 
								 | 
							
								             rsvd2   : 2;
							 | 
						||
| 
								 | 
							
								    /* node baud */
							 | 
						||
| 
								 | 
							
								    uint32_t baud;
							 | 
						||
| 
								 | 
							
								    /* TODO: adding more information */
							 | 
						||
| 
								 | 
							
								} iot_brm_node_info_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _iot_brm_location_unit {
							 | 
						||
| 
								 | 
							
								    /* location unit seconds : BCD code */
							 | 
						||
| 
								 | 
							
								    uint16_t    sec_0 : 4,
							 | 
						||
| 
								 | 
							
								                sec_1 : 4,
							 | 
						||
| 
								 | 
							
								                sec_2 : 4,
							 | 
						||
| 
								 | 
							
								                sec_3 : 4;
							 | 
						||
| 
								 | 
							
								    /* location unit min : BCD code */
							 | 
						||
| 
								 | 
							
								    uint8_t     min_0 : 4,
							 | 
						||
| 
								 | 
							
								                min_1 : 4;
							 | 
						||
| 
								 | 
							
								    /* location unit degree : BCD code */
							 | 
						||
| 
								 | 
							
								    uint16_t    degree_0 : 4,
							 | 
						||
| 
								 | 
							
								                degree_1 : 4,
							 | 
						||
| 
								 | 
							
								                degree_2 : 4,
							 | 
						||
| 
								 | 
							
								                degree_4_rsvd : 4;
							 | 
						||
| 
								 | 
							
								} iot_brm_location_unit_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* node information entry descriptor */
							 | 
						||
| 
								 | 
							
								typedef struct iot_brm_pm_node_entry {
							 | 
						||
| 
								 | 
							
								    /* node address */
							 | 
						||
| 
								 | 
							
								    uint8_t   addr[IOT_MAC_ADDR_LEN];
							 | 
						||
| 
								 | 
							
								    /* protocol type, see IOT_BRM_PROTO_TYPE_XXX */
							 | 
						||
| 
								 | 
							
								    uint16_t  proto_type : 4,
							 | 
						||
| 
								 | 
							
								    /* port type. see IOT_BRM_PORT_XXX */
							 | 
						||
| 
								 | 
							
								              port       : 3,
							 | 
						||
| 
								 | 
							
								    /* baud rate id */
							 | 
						||
| 
								 | 
							
								              bid        : 4,
							 | 
						||
| 
								 | 
							
								    /* creator of node, see IOT_BRM_OPERATOR_XXX */
							 | 
						||
| 
								 | 
							
								              creator    : 2,
							 | 
						||
| 
								 | 
							
								    /* reserved for further use */
							 | 
						||
| 
								 | 
							
								              rsvd       : 3;
							 | 
						||
| 
								 | 
							
								    /* current transformer ratio of node, uint is x1 */
							 | 
						||
| 
								 | 
							
								    uint16_t  i_ratio;
							 | 
						||
| 
								 | 
							
								    /* voltage transformer ratio of node, uint is x1 */
							 | 
						||
| 
								 | 
							
								    uint8_t   v_ratio;
							 | 
						||
| 
								 | 
							
								    /* assembly number */
							 | 
						||
| 
								 | 
							
								    uint8_t  ass_pos : 6,
							 | 
						||
| 
								 | 
							
								    /* reserved for future */
							 | 
						||
| 
								 | 
							
								             rsvd1   : 2;
							 | 
						||
| 
								 | 
							
								    /* reserved for further use */
							 | 
						||
| 
								 | 
							
								    uint8_t   rsvd2[19];
							 | 
						||
| 
								 | 
							
								} iot_brm_nv_node_entry_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* convert ntb to ms. in HW, the ntb clock freq is 25 mhz. */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_NTB_TO_MS(ntb)             ((ntb) / (25 * 1000))
							 | 
						||
| 
								 | 
							
								/* convert ms to ntb. in HW, the ntb clock freq is 25 mhz. */
							 | 
						||
| 
								 | 
							
								#define IOT_BRM_MS_TO_NTB(ms)              ((ms) * (25 * 1000))
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#pragma pack(pop)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#if IOT_BRM_ENABLE
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_data_print() - print data, format is hex.
							 | 
						||
| 
								 | 
							
								 * @param str:    a short string to be printed before data
							 | 
						||
| 
								 | 
							
								 * @param buf:    buffer contain data to be printed
							 | 
						||
| 
								 | 
							
								 * @param len:    length of data in the buffer
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_data_print(const char* str, uint8_t* buf, uint32_t len);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_post_msg() - post messages to brm app queue
							 | 
						||
| 
								 | 
							
								 * @param msg_type: message type, see IOT_BRM_MSG_TYPE_XXXX.
							 | 
						||
| 
								 | 
							
								 * @param msg_id:   message id, see IOT_BRM_MSG_ID_XXXX.
							 | 
						||
| 
								 | 
							
								 * @param prio:     message prio, see IOT_BRM_MSG_QUEUE_XXXX.
							 | 
						||
| 
								 | 
							
								 * @param data:     data pointer carried by message
							 | 
						||
| 
								 | 
							
								 * @param data2:    integer data carried by messages
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_post_msg(uint16_t msg_type, uint16_t msg_id,
							 | 
						||
| 
								 | 
							
								    uint8_t prio, void *data, uint32_t data2);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_clean_msg() - clean messages in brm app queue.
							 | 
						||
| 
								 | 
							
								 * @param msg_type: message type, see IOT_BRM_MSG_TYPE_XXXX.
							 | 
						||
| 
								 | 
							
								 * @param msg_id:   message id, see IOT_BRM_MSG_ID_XXXX
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_clean_msg(uint16_t msg_type, uint16_t msg_id);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_calc_nw_snr() - calculate new snr
							 | 
						||
| 
								 | 
							
								 * @param orig_snr: orig snr
							 | 
						||
| 
								 | 
							
								 * @param new_snr:  new snr
							 | 
						||
| 
								 | 
							
								 * @retval current snr
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								int8_t iot_brm_calc_nw_snr(int8_t orig_snr, int8_t new_snr);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_send_mr_cmd() - send meter reading message to PLC.
							 | 
						||
| 
								 | 
							
								 * @param dest_addr:  destination address.
							 | 
						||
| 
								 | 
							
								 * @param sn:         seq number to be used by message.
							 | 
						||
| 
								 | 
							
								 * @param proto_type: proto type of messages, see IOT_BRM_PROTO_TYPE_XXXX
							 | 
						||
| 
								 | 
							
								 * @param data:       point to the content of meter reading message.
							 | 
						||
| 
								 | 
							
								 * @param len:        length of meter reading message.
							 | 
						||
| 
								 | 
							
								 * @param ppm_fix:    current transmission PPM fix value.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_send_mr_cmd(uint8_t *dest_addr, uint16_t sn,
							 | 
						||
| 
								 | 
							
								    uint8_t proto_type, uint8_t *data, uint16_t len, int8_t ppm_fix);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_send_mr_cmd() - load meter info data.
							 | 
						||
| 
								 | 
							
								 * @retval: pointer to meter info.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								iot_brm_meter_info_t *iot_brm_load_meter_info(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_data_handler() - handle data massage.
							 | 
						||
| 
								 | 
							
								 * @param pkt:       data packet.
							 | 
						||
| 
								 | 
							
								 * @param recv_from: where is the data from, see iot_brm_data_owner_t
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_data_handler(iot_pkt_t *pkt, iot_brm_data_owner_t recv_from);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_node_add() - adding nodes.
							 | 
						||
| 
								 | 
							
								 * @param addr: node address, little Endian.
							 | 
						||
| 
								 | 
							
								 * @param prot: prot type. see IOT_BRM_PORT_XXX
							 | 
						||
| 
								 | 
							
								 * @param proto_type: node protocol type, see IOT_BRM_PROTO_TYPE_645_XXX.
							 | 
						||
| 
								 | 
							
								 * @param baud: node baud rate.
							 | 
						||
| 
								 | 
							
								 * @param i_ratio: pointer to current ratio.
							 | 
						||
| 
								 | 
							
								 * @param v_ratio: pointer to voltage ratio.
							 | 
						||
| 
								 | 
							
								 * @param pos:     assembly number.
							 | 
						||
| 
								 | 
							
								 * @param operator: operator, see IOT_BRM_OPERATOR_XXX.
							 | 
						||
| 
								 | 
							
								 * @retval ERR_OK - for success case, othersie - error code.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_node_add(uint8_t *addr, uint8_t prot,
							 | 
						||
| 
								 | 
							
								    uint8_t proto_type, uint32_t baud, uint16_t *i_ratio, uint8_t *v_ratio,
							 | 
						||
| 
								 | 
							
								    uint8_t *pos, uint8_t operator);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_node_rm() - delete node.
							 | 
						||
| 
								 | 
							
								 * @param addr: the address of the node to be deleted, little Endian.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_node_rm(uint8_t *addr);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_node_rm_by_creator() - delete all nodes of the specified
							 | 
						||
| 
								 | 
							
								 *        creator.
							 | 
						||
| 
								 | 
							
								 * @param bm_creator: bitmap for creator of node,
							 | 
						||
| 
								 | 
							
								 *                    mean of bit see IOT_BRM_OPERATOR_XXX
							 | 
						||
| 
								 | 
							
								 * @retval: node cnt.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_node_rm_by_creator(uint8_t bm_creator);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_data_init() - initialize branch management app data.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_data_init(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_get_dev_addr() - get device address.
							 | 
						||
| 
								 | 
							
								 * @addr: return device address, little Endian.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_get_dev_addr(uint8_t *addr);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_set_dev_addr() - set device address.
							 | 
						||
| 
								 | 
							
								 * @addr: src device address, little Endian.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_set_dev_addr(uint8_t *addr);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_get_node_cnt() - get node cnt.
							 | 
						||
| 
								 | 
							
								 * @retval: node cnt.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_get_node_cnt();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_get_node_cnt_by_creator() - get node cnt of the specified
							 | 
						||
| 
								 | 
							
								 *        creator.
							 | 
						||
| 
								 | 
							
								 * @param bm_creator: bitmap for creator of node,
							 | 
						||
| 
								 | 
							
								 *                    mean of bit see IOT_BRM_OPERATOR_XXX
							 | 
						||
| 
								 | 
							
								 * @retval: node cnt.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_get_node_cnt_by_creator(uint8_t bm_creator);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_get_node_info() - iot_brm_get_node_info.
							 | 
						||
| 
								 | 
							
								 * @param start_seq:  node start seq number to be queried.
							 | 
						||
| 
								 | 
							
								 * @param cnt: number of nodes to be queried.
							 | 
						||
| 
								 | 
							
								 * @param info: buffer from node information.
							 | 
						||
| 
								 | 
							
								 * @param info_cnt: info buffer count.
							 | 
						||
| 
								 | 
							
								 * @param bm_creator: bitmap for creator of node,
							 | 
						||
| 
								 | 
							
								 *                    mean of bit see IOT_BRM_OPERATOR_XXX
							 | 
						||
| 
								 | 
							
								 * @retval: number of nodes actually queried.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_get_node_info(uint8_t start_seq, uint8_t cnt,
							 | 
						||
| 
								 | 
							
								    iot_brm_node_info_t *info, uint8_t info_cnt, uint8_t bm_creator);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_find_nv_node() - get node info from nv region.
							 | 
						||
| 
								 | 
							
								 * @param addr: node addr.
							 | 
						||
| 
								 | 
							
								 * @retval: pointer to nv node information.
							 | 
						||
| 
								 | 
							
								 * @retval: null faill.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								iot_brm_nv_node_entry_t *iot_brm_find_nv_node(uint8_t *addr);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_get_node_samp_info() - get samp info of nodes.
							 | 
						||
| 
								 | 
							
								 * @param idx:  node idx.
							 | 
						||
| 
								 | 
							
								 * @retval: return samp info of nodes.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								iot_brm_node_samp_t *iot_brm_get_node_samp_info(uint8_t idx);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_send_pkt_to_sg_app() - send pkt to sg app.
							 | 
						||
| 
								 | 
							
								 * @param pkt:  pointer to pkt to be sent.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_send_pkt_to_sg_app(iot_pkt_t *pkt);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_send_resp_pkt() - send response pkt.
							 | 
						||
| 
								 | 
							
								 * @param pkt    :  pointer to pkt to be sent.
							 | 
						||
| 
								 | 
							
								 * @param send_to:  send the pkt back, see iot_brm_data_owner_t.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_send_resp_pkt(iot_pkt_t *pkt, iot_brm_data_owner_t send_to);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_rs485_set_check_state() - set 485 bus to enter check state.
							 | 
						||
| 
								 | 
							
								 *        in this state, 485 will not forward SG app and internal meter reading
							 | 
						||
| 
								 | 
							
								 *        message, which is specially used for assembling check.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_rs485_set_check_state(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_rs485_send() - send data to 485 bus.
							 | 
						||
| 
								 | 
							
								 * @param pkt: iot_pkt to be send.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								 void iot_brm_rs485_send(iot_pkt_t *pkt);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_rs485_config_buad_internal() - configure RS485 baud rate and
							 | 
						||
| 
								 | 
							
								 *        protocol type.
							 | 
						||
| 
								 | 
							
								 * @param buad: baud value.
							 | 
						||
| 
								 | 
							
								 * @param proto_type: protocol type, see IOT_BRM_PROTO_TYPE_XXX.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_rs485_config_buad_internal(uint32_t buad,
							 | 
						||
| 
								 | 
							
								    uint8_t proto_type);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_get_addr_from_message() - get address from message
							 | 
						||
| 
								 | 
							
								 * @param data: message data.
							 | 
						||
| 
								 | 
							
								 * @param len: message data length.
							 | 
						||
| 
								 | 
							
								 * @param addr[out]: the address.
							 | 
						||
| 
								 | 
							
								 * @param proto_type[out]: protocol type, see IOT_BRM_PROTO_TYPE_XXX.
							 | 
						||
| 
								 | 
							
								 * @retuval: if success return ERR_OK, else return ERR_FAIL.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t iot_brm_get_addr_from_message(uint8_t *data,
							 | 
						||
| 
								 | 
							
								    uint16_t len, uint8_t *addr, uint8_t *proto_type);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_baud_to_bid() - convert baud rate to bid.
							 | 
						||
| 
								 | 
							
								 * @param baud: baud rate to be converted.
							 | 
						||
| 
								 | 
							
								 * @retuval: baud id.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_baud_to_bid(uint32_t baud);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_baud_to_bid() - convert baud id to baud.
							 | 
						||
| 
								 | 
							
								 * @param baud: baud id to be converted.
							 | 
						||
| 
								 | 
							
								 * @retuval: baud value.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t iot_brm_bid_to_baud(uint8_t bid);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_set_gps_info() - setting GPS information, longitude
							 | 
						||
| 
								 | 
							
								 *        and latitude.
							 | 
						||
| 
								 | 
							
								 * @param latitude:  pointer to latitude.
							 | 
						||
| 
								 | 
							
								 * @param longitude: pointer to longitude.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_set_gps_info(iot_brm_location_unit_t *latitude,
							 | 
						||
| 
								 | 
							
								    iot_brm_location_unit_t *longitude);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_get_gps_info() - get GPS information, longitude
							 | 
						||
| 
								 | 
							
								 *        and latitude.
							 | 
						||
| 
								 | 
							
								 * @param latitude:  return latitude.
							 | 
						||
| 
								 | 
							
								 * @param longitude: return longitude.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_get_gps_info(iot_brm_location_unit_t *latitude,
							 | 
						||
| 
								 | 
							
								    iot_brm_location_unit_t *longitude);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_set_meter_ratio() - set the meetr transformation ratio
							 | 
						||
| 
								 | 
							
								 * @param v_ratio: voltage ratio.
							 | 
						||
| 
								 | 
							
								 * @param i_ratio: current ratio.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_set_meter_ratio(uint32_t v_ratio, uint32_t i_ratio);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_send_config_cmd() - set the meter transformation ratio
							 | 
						||
| 
								 | 
							
								 * @param dest_addr: target address to be configuration.
							 | 
						||
| 
								 | 
							
								 * @param band: target band to be configuration.
							 | 
						||
| 
								 | 
							
								 * @param dur: duration for which the configuration takes effect, uint is 1s.
							 | 
						||
| 
								 | 
							
								 * @param is_sta: if set, the target address to be configured is sta
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_send_config_cmd(uint8_t *dest_addr, uint8_t band,
							 | 
						||
| 
								 | 
							
								    uint8_t dur, uint8_t is_sta);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_set_whitelist_enable() - enable whitelist
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_set_whitelist_enable();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_set_fb() - set working frequency band
							 | 
						||
| 
								 | 
							
								 * @param band_id: target band to be set, see PLC_LIB_FREQ_BAND_X.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_set_fb(uint8_t band_id);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_e_to_proto_645() - cal  energy data then transfer to 645 format
							 | 
						||
| 
								 | 
							
								 * @param e: energy
							 | 
						||
| 
								 | 
							
								 * @param ec:  EC constant.
							 | 
						||
| 
								 | 
							
								 * @param: pointer of target 645 format data
							 | 
						||
| 
								 | 
							
								 * @retuval: lenth of 645 format data
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_e_to_proto_645(uint32_t e, uint16_t ec, uint8_t * out_buf);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_get_plc_state() - get PLC status
							 | 
						||
| 
								 | 
							
								 * @retuval: 0--not joined, 1--joined
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_get_plc_state(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_get_cco_addr() - get PLC cco address
							 | 
						||
| 
								 | 
							
								 * @param addr[out]     cco address
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t *iot_brm_get_cco_addr(void);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_sync_node_list_to_sg_app() - synchronize rs485 node to sg app
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_sync_node_list_to_sg_app();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_send_resp_data() - brm send response data to recv from.
							 | 
						||
| 
								 | 
							
								 * @param data: response data ptr.
							 | 
						||
| 
								 | 
							
								 * @param len:  response data length.
							 | 
						||
| 
								 | 
							
								 * @param send_to: dealwith data recv from, see iot_brm_data_owner_t.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_send_resp_data(uint8_t *data, uint32_t len,
							 | 
						||
| 
								 | 
							
								    iot_brm_data_owner_t send_to);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_port_is_exist() - check whether the corresponding port exists
							 | 
						||
| 
								 | 
							
								 * @param port: port number, see IOT_BRM_PORT_XXX.
							 | 
						||
| 
								 | 
							
								 * @retuval: 1  -- exist, 0 -- not.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_port_is_exist(uint8_t port);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_node_is_exist() - check whether the corresponding node exist
							 | 
						||
| 
								 | 
							
								 * @param addr: node addr.
							 | 
						||
| 
								 | 
							
								 * @retuval: 1  -- exist, 0 -- not.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_node_is_exist(uint8_t *addr);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_485_mode_setting() - set 485 slave/master mode.
							 | 
						||
| 
								 | 
							
								 * @param slave_flag: 1 - set 485 slave mode, 0 - set 485 master mode.
							 | 
						||
| 
								 | 
							
								 * @param baudrate: 485 baudrate slave mode.
							 | 
						||
| 
								 | 
							
								 * @param hold_time: 485 slave mode hold time, unit - 1ms.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_485_mode_setting(uint8_t slave_flag, uint32_t baudrate,
							 | 
						||
| 
								 | 
							
								    uint32_t hold_time);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_set_curve_cfg() - curve recording configuration.
							 | 
						||
| 
								 | 
							
								 * @param cfg:  pointer to curve record configuration information.
							 | 
						||
| 
								 | 
							
								 * @retval ERR_OK - for success case, othersie - error code
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint32_t iot_brm_set_curve_cfg(iot_brm_curve_cfg_t *cfg);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_get_curve_cfg() - get curve recording configuration info.
							 | 
						||
| 
								 | 
							
								 * @param cfg: 1 - return curve recording configuration info.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								void iot_brm_get_curve_cfg(iot_brm_curve_cfg_t *cfg);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @brief iot_brm_get_terminal_cfg() - get terminal configuration info.
							 | 
						||
| 
								 | 
							
								 * @param cfg: return terminal configuration info.
							 | 
						||
| 
								 | 
							
								 * @retval ERR_OK - for success case, ERR_INVAL - no set case.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_get_terminal_cfg(iot_brm_terminal_cfg_t *cfg);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								* @brief iot_brm_set_terminal_cfg() - set terminal configuration info.
							 | 
						||
| 
								 | 
							
								* @param cfg: set terminal configuration info.
							 | 
						||
| 
								 | 
							
								* @retval ERR_OK - for success case, othersie - error code
							 | 
						||
| 
								 | 
							
								*/
							 | 
						||
| 
								 | 
							
								uint32_t iot_brm_set_terminal_cfg(iot_brm_terminal_cfg_t *cfg);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								* @brief iot_brm_is_brk() - device is breaker.
							 | 
						||
| 
								 | 
							
								* @retval 1 - is breaker, 0 - is not breaker.
							 | 
						||
| 
								 | 
							
								*/
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_is_brk();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								* @brief iot_brm_mr_698_get_apdu_sn() - get and update 698 proto seq number.
							 | 
						||
| 
								 | 
							
								* @retval: 698 proto seq number.
							 | 
						||
| 
								 | 
							
								*/
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_mr_698_get_apdu_sn();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								* @brief iot_brm_oneshot_calibration_req() - req oneshot calibration.
							 | 
						||
| 
								 | 
							
								* @param i: calibration current param unit - 0.01A.
							 | 
						||
| 
								 | 
							
								* @param u: calibration voltage param unit - 0.1V.
							 | 
						||
| 
								 | 
							
								* @param ec: EC constant.
							 | 
						||
| 
								 | 
							
								* @param i_rate: current channel transfer rate.
							 | 
						||
| 
								 | 
							
								* @param i_sample: current channel sample resistance value. unit: ohm.
							 | 
						||
| 
								 | 
							
								* @param u_rate: voltage channel transfer rate.
							 | 
						||
| 
								 | 
							
								* @param max_smpl: max sample times.
							 | 
						||
| 
								 | 
							
								* @retval: ERR_OK - success oneshot calibration, others - fail.
							 | 
						||
| 
								 | 
							
								*/
							 | 
						||
| 
								 | 
							
								uint32_t iot_brm_oneshot_calibration_req(uint16_t i, uint16_t u, uint32_t ec,
							 | 
						||
| 
								 | 
							
								    uint32_t i_rate, uint32_t i_sample, uint32_t u_rate, uint16_t max_smpl);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								* @brief iot_brm_oneshot_calibration_query() - query oneshot calibration status.
							 | 
						||
| 
								 | 
							
								* @param fail_code: calibration fail code when calibration fail.
							 | 
						||
| 
								 | 
							
								* @retval: calibration status, see  - IOT_BRM_ONESHOT_CALIBRATE_XXX.
							 | 
						||
| 
								 | 
							
								*/
							 | 
						||
| 
								 | 
							
								uint8_t iot_brm_get_oneshot_calibration_status(uint8_t *fail_code);
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif /* IOT_BRM_ENABLE */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif  /* IOT_BRM_COMMON_H */
							 |