/**************************************************************************** Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED. This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT be copied by any method or incorporated into another program without the express written consent of Aerospace C.Power. This Information or any portion thereof remains the property of Aerospace C.Power. The Information contained herein is believed to be accurate and Aerospace C.Power assumes no responsibility or liability for its use in any way and conveys no license or title under any patent or copyright and makes no representation or warranty that this Information is free from patent or copyright infringement. ****************************************************************************/ #ifndef IOT_SG_STA_H #define IOT_SG_STA_H /* os shim includes */ #include "os_types_api.h" #include "os_timer_api.h" /* common includes */ #include "iot_addr_hash_table_api.h" #include "iot_plc_msg_sta_api.h" #include "iot_rtc_api.h" /* smart grid internal includes */ #include "iot_sg_msg.h" #include "proto_gw_app.h" #include "proto_645.h" #include "proto_645_fj.h" #include "iot_sg_cfg.h" #include "iot_sg_sta_drv_api.h" #include "iot_sg_flash.h" #include "iot_sg_sta_cfg_flash.h" #include "iot_sg_sta_flash.h" #include "iot_sg_upgrade.h" #include "iot_sg_sta_tsfm.h" #include "iot_sg_sta_topo.h" #include "iot_sg_ext_sta_api.h" #include "iot_sg_sta_ext_mf.h" #ifdef __cplusplus extern "C" { #endif /* define max secondary node supported */ #define IOT_SG_STA_SEC_NODE_MAX 32 /* define secondary node hash table size */ #define IOT_SG_STA_SEC_NODE_HASH_TABLE_SIZE 4 /* define max black listed secondary node supported */ #define IOT_SG_STA_SEC_NODE_BL_MAX 100 /* define black listed secondary node hash table size */ #define IOT_SG_STA_SEC_NODE_BL_HASH_TABLE_SIZE 4 /* define size of the invalid mac address list */ #define IOT_SG_STA_INVALID_ADDR_LIST_SIZE 16 /* define invalid mac address listed valid mac duration. unit is 1s */ #define IOT_SG_STA_VALID_ADDR_DUR (30 * 60) /* define invalid mac address listed invalid mac duration. unit is 1s */ #define IOT_SG_STA_INVALID_ADDR_DUR (8 * 60) /* define the min interval with the last node register result. unit is 1min */ #define IOT_SG_STA_LAST_NODE_REG_RESULT_INTERVAL (30) /* define max request queue size. */ #define IOT_SG_STA_REQ_QUEUE_SIZE 16 /* dfining the priority of the request queue */ #define IOT_SG_STA_REQ_QUEUE_HP 0 #define IOT_SG_STA_REQ_QUEUE_MP 1 #define IOT_SG_STA_REQ_QUEUE_LP 2 /* define max 645 frames per concurrent meter read request from cco */ #define IOT_SG_STA_MAX_FRAME_PER_READ GW_APP_CON_MR_MAX_MSG_CNT /* defines the max message length of a non-645 message in a concurrent * meter read. */ #define IOT_SG_STA_MAX_MR_MSG_LEN GW_APP_CON_MR_MAX_MSG_LEN /* define max response buffer size */ #define IOT_SG_STA_RESPONSE_MAX_SIZE IOT_SG_STA_MAX_MR_MSG_LEN /* define max last response buffer size */ #define IOT_SG_STA_LAST_RESPONSE_MAX_SIZE 1000 /* in the status, sta isn't power off */ #define IOT_SG_STA_POWEROFF_IDLE (0) /* in the status, sta isn't power off and receive power off event * messages published by neighbor nodes. */ #define IOT_SG_STA_POWEROFF_COLLECT (1) /* in the status, sta is power off, start report power off event */ #define IOT_SG_STA_POWEROFF_REPORT (2) /* define effective duration of power down for fujian, uint is 1s */ #define IOT_SG_STA_FJ_PD_EVT_VALID_TIME_MIN (1) #define IOT_SG_STA_FJ_PD_EVT_VALID_TIME_MAX (15) #define IOT_SG_STA_FJ_PD_EVT_VALID_TIME_DFT (5) /* defines error code of meter reading */ /* meter reading issuing fail -- no memory */ #define IOT_SG_STA_MR_ERR_ISSUE_NMEM (0) /* initial allocation of memory failure in concurrent meter reading. */ #define IOT_SG_STA_MR_ERR_CON_NMEM_1 (1) /* memory expansion failure of concurrent meter reading. */ #define IOT_SG_STA_MR_ERR_CON_NMEM_2 (2) /* meter reading response message size exceeds maximum limit in concurrent * meter reading. */ #define IOT_SG_STA_MR_ERR_CON_NMEM_3 (3) /* concurrent meter reading timeout */ #define IOT_SG_STA_MR_ERR_CON_TO (4) /* concurrent reading received NACK response */ #define IOT_SG_STA_MR_ERR_CON_NACK (5) /* non concurrent meter reading timeout */ #define IOT_SG_STA_MR_ERR_NON_CON_TO (6) /* concurrent meter reading loss data items */ #define IOT_SG_STA_MR_ERR_CON_LOST_ITEM (7) /* meter reading issuing fail -- drive busy */ #define IOT_SG_STA_MR_ERR_DRV_BUSY (8) #define IOT_SG_STA_MR_ERR_MAX (IOT_SG_STA_MR_ERR_DRV_BUSY) /* define the number of pm checked */ #define IOT_SG_STA_PD_CHECK_PM_NUM (6) /* define the number of buffer used to collect addr version power down info */ #define IOT_SG_STA_PD_ADDRS_BUF_CNT 8 /* define the size of buffer used to collect addr version power down info */ #define IOT_SG_STA_PD_ADDRS_BUF_SIZE (450) /* define type of low layer link type, PLC */ #define IOT_SG_LINK_TYPE_PLC 0 /* define type of low layer link type, SWC */ #define IOT_SG_LINK_TYPE_SWC 1 /* define type of low layer link type, PLC connectionless */ #define IOT_SG_LINK_TYPE_PLC_CONN_LESS 2 /* define type of low layer link type, PLC CTRL */ #define IOT_SG_LINK_TYPE_PLC_CTRL 3 /* define type of low layer link type, APP */ #define IOT_SG_LINK_TYPE_APP 4 /* define type of low layer link type, BRM */ #define IOT_SG_LINK_TYPE_PLC_BRM 5 /* define type of low layer link type, CUS */ #define IOT_SG_LINK_TYPE_CUS 6 /* the lifetime of the last meter reading result of the cache. uint is 1ms */ #define IOT_SG_STA_LAST_MR_CACHE_LIFE (180 * 1000) /* define maximum retry count of non concurrent meter reading. * when the cert test behavior is detected, the retry function will be disabled. */ #define IOT_SG_STA_RETRY_CNT_NON_CON_MR 1 /* if the station with collector type, first n times reading were * unsuccessful, terminate the concurrent reading as the target power * meter may not be connected with local device. */ #define IOT_SG_STA_KILL_CON_READ_N_FOR_CT 2 /* define default meter read timeout. uint is 1ms */ #define IOT_SG_STA_MR_TIMEOUT (1600) /* define start secondary node register reason */ #define IOT_SG_STA_NODE_REG_REASON_START (0) #define IOT_SG_STA_NODE_REG_REASON_QUERY (1) #define IOT_SG_STA_NODE_REG_REASON_DRV (2) /* define sta meter reading req source id, max id is 7 */ #define IOT_SG_STA_MR_SRC_ID_COLLECT_FEATURE (0) #define IOT_SG_STA_MR_SRC_ID_EXT_READ (1) #define IOT_SG_STA_MR_SRC_ID_EXT_CLCT_TASK (2) #define IOT_SG_STA_MR_SRC_ID_SCORE (3) #define IOT_SG_STA_MR_SRC_ID_DATA_CLCT (4) #define IOT_SG_STA_MR_SRC_ID_DATA_FREEZE (5) #define IOT_SG_STA_MR_SRC_ID_NW_LC (6) #define IOT_SG_STA_MR_SRC_ID_NLI_DETECT (7) /* define sta meter reading req ext source id, id is 8 - 15 */ #define IOT_SG_STA_MR_SRC_ID_EXT_AI_TOPO (8) #define IOT_SG_STA_MR_SRC_ID_EXT_AI_LL (9) #define IOT_SG_STA_MR_SRC_ID_EXT_GW_CLCT (10) #define IOT_SG_STA_MR_SRC_ID_EXT_EC (11) #define IOT_SG_STA_MR_SRC_ID_EXT_UPGRADE (12) /* define sta joining nid list max number */ #define IOT_SG_STA_JOINING_NID_LIST_MAX_NUM (5) /* define invalid mac address report count for switch address */ #define IOT_SG_STA_INVALID_MAC_RPT_CNT (2) /* define sta load curve data id max cnt */ #define IOT_SG_STA_EXT_LR_DI_CNT_MAX 22 /* define the max value of xi'an time delta, uint is 1s */ #define IOT_SG_STA_TM_DELTA_MAX_XIAN (24 * 60 * 60) /* define the max value of hebei time delta, uint is 1s */ #define IOT_SG_STA_TM_DELTA_MAX_HEBEI (24 * 60 * 60) /* define the max value of guangdong time delta, uint is 1s */ #define IOT_SG_STA_TM_DELTA_MAX_GUANGDONG (10 * 60) /* define max cnt of correct time in 12 hours */ #define IOT_SG_STA_CORRECT_TIME_CNT_MAX (2) /* define the max time delta value between cctt and sta in collect task, * uint is 1s */ #define IOT_SG_STA_TM_DELTA_MAX_CLCT_TASK (5 * 60) /* define network lock time, 0 means no lock. uint is 1min */ #define IOT_SG_STA_NW_NOR_LOCK_TIME (360) /* define lock time of abnormal leave network, 0 means no lock. * uint is 1min */ #define IOT_SG_STA_NW_ABN_LOCK_TIME (15) /* define tei map length */ #define IOT_SG_STA_MAP_BYTE_LEN ((PLC_NETWORK_SCALE / 8) + 1) /* define max cnt of support collection di in collection task */ #define IOT_SG_EXT_CLCT_TASK_DI_CNT_MAX 4 /* define max cnt of support task in meter */ #define IOT_SG_EXT_CLCT_TASK_CNT_MAX 5 /* define report event type */ #define IOT_SG_STA_RPT_METER_NORMAL_EVT 0 #define IOT_SG_STA_RPT_MODULE_PHASE_EVT 1 #define IOT_SG_STA_RPT_MODULE_SCORE_EVT 2 #define IOT_SG_STA_RPT_MODULE_CLOCK_EVT 3 #define IOT_SG_STA_RPT_MODULE_SEQ_EVT 4 #define IOT_SG_STA_RPT_MODULE_NLI_EVT 5 #define IOT_SG_STA_RPT_MODULE_EC_EVT 6 /* define event report mode for fujian */ #define IOT_SG_STA_FJ_EVT_RPT_MODE_GW 0 #define IOT_SG_STA_FJ_EVT_RPT_MODE_EXT 1 /* define event report type for fujian */ /* just report when event occur */ #define IOT_SG_STA_FJ_EVT_RPT_TYPE_OCCUR 0 /* report when event occur and recover */ #define IOT_SG_STA_FJ_EVT_RPT_TYPE_BOTH 1 /* define uart state */ #define IOT_SG_STA_UART_STATE_NORMAL 0 #define IOT_SG_STA_UART_STATE_ONCE_ABNORMAL 1 #define IOT_SG_STA_UART_STATE_ABNORMAL 2 /* define query neighbor node infomation request from plc */ #define IOT_SG_STA_QUERY_NEIG_NODE_FROM_PLC (1) /* define query neighbor node infomation request from STA */ #define IOT_SG_STA_QUERY_NEIG_NODE_FROM_STA (2) /* define collect data report state, only for jangsu */ #define IOT_SG_STA_COLL_DATA_RPT_STATE_IDLE 0 #define IOT_SG_STA_COLL_DATA_RPT_STATE_MF 1 #define IOT_SG_STA_COLL_DATA_RPT_STATE_DF 2 #define IOT_SG_STA_COLL_DATA_RPT_STATE_15MIN 3 #define IOT_SG_STA_COLL_DATA_RPT_STATE_1MIN 4 #define IOT_SG_STA_COLL_DATA_RPT_STATE_END 5 /* define collection data report meter info max count */ #define IOT_SG_STA_CLCT_METER_INFO_MAX_CNT 12 /* define collection data last rpt info type */ #define IOT_SG_STA_CLCT_LAST_RPT_INVALID 0 #define IOT_SG_STA_CLCT_LAST_RPT_SIG_METER 1 #define IOT_SG_STA_CLCT_LAST_RPT_MULT_METER 2 /* define search meter event report state */ #define IOT_SG_STA_SM_EVT_REPORT_IDLE 0 #define IOT_SG_STA_SM_EVT_REPORTING 1 #define IOT_SG_STA_SM_EVT_REPORT_DONE 2 /* define correct time message type */ #define IOT_SG_STA_CORR_TYPE_UNKNOWN 0 #define IOT_SG_STA_CORR_TYPE_645 1 #define IOT_SG_STA_CORR_TYPE_698 2 /* convert ntb to ms. in HW, the ntb clock freq is 25 mhz. */ #define IOT_SG_STA_NTB_TO_MS(ntb) ((ntb) / (25 * 1000)) /* convert ms to ntb. in HW, the ntb clock freq is 25 mhz. */ #define IOT_SG_STA_MS_TO_NTB(ms) ((ms) * (25 * 1000)) /* define freeze task cfg info max lengtht */ #define IOT_SG_STA_EXT_FJ_FREEZE_TASK_CFG_MAX_LEN 100 /* define freeze task max cnt */ #define IOT_SG_STA_EXT_FJ_FREEZE_TASK_MAX_CNT 16 /* define freeze task data max lengtht */ #define IOT_SG_STA_EXT_FJ_FREEZE_TASK_DATA_MAX_LEN 128 /* define meter read operation done source. */ #define IOT_SG_STA_MR_DONE_BY_DRIVE (0) #define IOT_SG_STA_MR_DONE_BY_FRAMEWORK (1) /* define type of meter read. */ #define IOT_SG_STA_MR_TYPE_DEF (0) #define IOT_SG_STA_MR_TYPE_CONCENTRATOR (1) #define IOT_SG_STA_MR_TYPE_ROUTE (2) #define IOT_SG_STA_MR_TYPE_CONCENTRATOR_P (3) #define IOT_SG_STA_MR_TYPE_HISTORY (4) #if IOT_FOREIGN_QSXJ_PM_ENABLE /* define black list max count */ #define IOT_SG_STA_BLACK_LIST_MAX_CNT (16) #else /* define black list max count */ #define IOT_SG_STA_BLACK_LIST_MAX_CNT (1) #endif /* define ai module topo data cache max count */ #define IOT_SG_STA_EXT_AI_TOPO_DATA_MAX (71) /* define ai module topo data di max count */ #define IOT_SG_STA_EXT_AI_TOPO_DI_MAX (3) /* define ai module line lose data di max count */ #define IOT_SG_STA_EXT_AI_LL_DI_MAX (17) /* define gw v2.8 data collection task max cnt */ #define IOT_SG_STA_EXT_GW_V28_CLCT_TASK_MAX_CNT (8) /* define gw v2.8 data collection report cache pkt count */ #define IOT_SG_STA_EXT_GW_V28_CACHE_PKT_CNT (4) /* define gw v2.8 data collection report unit count */ #define IOT_SG_STA_EXT_GW_V28_RPT_UNIT_CNT (12) /* check sta vendor id is ZH */ #define IOT_SG_STA_VENDOR_ID_IS_ZH(vendor_id) (vendor_id == 0x5753 || \ vendor_id == 0x5357 || vendor_id == 0x5754) /* pack for the structures in the whole file */ #pragma pack(push) /* save the pack status */ #pragma pack(1) /* 1 byte align */ /* phase sequence report cache info */ typedef struct _iot_sg_phase_seq_status_cache_info { /* event type, see GW_APP_EVENT_TYPE_XXX */ uint8_t evt_type; /* three phase meter addr */ uint8_t pm_addr[IOT_MAC_ADDR_LEN]; /* phase_sequence_status, see GW_APP_PHASE_SEQUENCE_STAUS_XXX */ uint8_t phase_seq_status; } iot_sg_phase_seq_status_cache_info_t; /* local power down pm info structure, same as gw_app_power_evt_pm_info_t */ typedef struct _iot_sg_sta_pd_addrs_info { /* power meter mac address */ uint8_t mac[IOT_MAC_ADDR_LEN]; /* 0 - power off, 1- power on */ uint8_t power_state; } iot_sg_sta_pd_addrs_info_t; #pragma pack(pop) /* restore the pack status */ /* collection data report cache structure */ typedef struct _iot_sg_sta_ext_clct_rpt_desc { /* meter address */ uint8_t addr[IOT_MAC_ADDR_LEN]; /* flag of three phase */ uint8_t flag_3p; /* data type, see IOT_SG_STA_METER_DATA_TYPE_JS_XXX */ uint8_t data_type; /* start index */ uint16_t start_index; /* end index */ uint16_t end_index; /* rpt cnt */ uint16_t cnt; /* oad bit map */ uint32_t oad_map; } iot_sg_sta_ext_clct_rpt_desc_t; /* collection data report meter info */ typedef struct _iot_sg_sta_ext_clct_meter_info { /* rpt cnt */ uint16_t cnt; /* meter address */ uint8_t addr[IOT_MAC_ADDR_LEN]; /* start index */ uint16_t start_index; /* end index */ uint16_t end_index; } iot_sg_sta_ext_clct_meter_info_t; /* collection data multi meter report cache structure */ typedef struct _iot_sg_sta_ext_clct_multi_rpt_desc { /* flag of three phase */ uint8_t flag_3p; /* data type, see IOT_SG_STA_METER_DATA_TYPE_JS_XXX */ uint8_t data_type; /* meter info count */ uint8_t meter_info_cnt; /* meter info */ iot_sg_sta_ext_clct_meter_info_t meter_info[IOT_SG_STA_CLCT_METER_INFO_MAX_CNT]; /* oad bit map */ uint32_t oad_map; } iot_sg_sta_ext_clct_multi_rpt_desc_t; /* smart grid sta role persistant storage structure */ typedef struct _iot_sg_sta_ps { /* driver id. read only. See IOT_SG_STA_DRV_ID_XXX */ uint16_t drv_id; } iot_sg_sta_ps_t; /* sta device states */ typedef enum { iot_sg_sta_state_invalid = 0, iot_sg_sta_state_init, iot_sg_sta_state_starting, iot_sg_sta_state_started, /* always keep this as the last state */ iot_sg_sta_state_max, } iot_sg_sta_state_t; /* state machine callback */ typedef iot_sg_sta_state_t (*iot_sg_sta_sm_func_t)(iot_sg_msg_t *msg); /* sta role state machine */ typedef struct _iot_sg_sta_sm { /* previous state */ iot_sg_sta_state_t prev_state; /* current state */ iot_sg_sta_state_t cur_state; /* function pointer of each state */ iot_sg_sta_sm_func_t func[iot_sg_sta_state_max]; } iot_sg_sta_sm_t; typedef struct _iot_sg_sta_mr_stats { /* sta received valid concurrent meter reading pkt cnt */ uint32_t rec_valid_con_mr_cnt; /* sta response concurrent meter reading pkt cnt */ uint32_t con_mr_sus_cnt; /* sta received valid router meter reading pkt cnt */ uint32_t rec_valid_rt_mr_cnt; /* sta response router meter reading pkt cnt */ uint32_t rt_mr_sus_cnt; /* sta received valid cctt meter reading pkt cnt */ uint32_t rec_valid_cctt_mr_cnt; /* sta response cctt meter reading pkt cnt */ uint32_t cctt_mr_sus_cnt; /* black listed meter read request */ uint32_t mr_bl_cnt; /* cached meter read request hit count */ uint32_t mr_cache_cnt; /* sta received correct time pkt cnt */ uint32_t rec_correct_cnt; /* sta drv send correct time cnt */ uint32_t drv_send_correct_cnt; /* count of time the STA joined network */ uint16_t join_cnt; /* count of time the STA left network */ uint16_t leave_cnt; /* meter reading error counters */ uint8_t mr_err_cnts[IOT_SG_STA_MR_ERR_MAX + 1]; } iot_sg_sta_mr_stats_t; /* request */ typedef struct _iot_sg_sta_req { /* pointer to iot packet of the request */ iot_pkt_t *pkt; /* pointer to massage header */ uint8_t *hdr; /* power meter addr, it has not yet been used */ uint8_t pm_addr[IOT_MAC_ADDR_LEN]; /* type of lower layer link, see IOT_SG_LINK_TYPE_XXX */ uint8_t link_type : 6, /* flag to mark the request is connectionless forwarding msg */ is_conn_fwd : 1, /* flag to mark the request is correct time msg */ is_corr_time : 1; } iot_sg_sta_req_t; /* reqeust */ typedef struct _iot_sg_sta_req_entry { /* link of req queue */ iot_list_head_t link; /* request info */ iot_sg_sta_req_t req; } iot_sg_sta_req_entry_t; /* reqeust queue */ typedef struct _iot_sg_sta_req_queue { /* head of req queue */ iot_list_head_t head[IOT_SG_STA_REQ_QUEUE_LP + 1]; /* momery pool of req queue */ iot_mem_pool_t *q_pool; /* handle cnt of req queue */ uint8_t cnt[IOT_SG_STA_REQ_QUEUE_LP + 1]; } iot_sg_sta_req_queue_t; /* sta extended load curve info */ typedef struct _iot_sg_sta_node_lr_info { /* next read time */ iot_time_tm_t tm; /* flag to mark if multi di is detect done */ uint8_t multi_di_detect_done : 1, /* flag to mark if multi di is supported, 0 is not supported */ multi_di_supported : 1, /* reserved for future */ reserved : 6; } iot_sg_sta_node_lr_info_t; /* sta extended collection task info */ typedef struct _iot_sg_sta_node_clct_task_info { /* next collect time */ uint16_t tm_year; uint8_t tm_mon; uint8_t tm_mday; uint8_t tm_hour; uint8_t tm_min; /* task id */ uint8_t id; /* flag of done */ uint8_t flag_done; } iot_sg_sta_node_clct_task_info_t; /* sta extended data collection task info for jiangsu proto protocol */ typedef struct _iot_sg_sta_node_data_clct_info { /* day freeze next read time */ iot_time_tm_t df_tm; /* month freeze next read time */ iot_time_tm_t mf_tm; /* 1 minute curve next read time */ iot_time_tm_t cur_1m_tm; /* 15 minute curve next read time */ iot_time_tm_t cur_15m_tm; /* time of last collection success */ iot_time_tm_t last_clct_tm; /* collection failure times */ uint8_t clct_fail_times; /* collection task success bitmap, see IOT_SG_STA_METER_JS_CFG_XXX */ uint16_t task_suc_bm; /* latest rpt index of monthly frozen data in flash */ uint16_t mf_rpt_index; /* monthly frozen data cnt */ uint16_t mf_cnt; /* latest rpt index of day frozen data in flash */ uint16_t df_rpt_index; /* day frozen data cnt */ uint16_t df_cnt; /* latest rpt index of 15min frozen data in flash */ uint16_t min15_rpt_index; /* 15min frozen data cnt */ uint16_t min15_cnt; /* latest rpt index of 1min frozen data in flash */ uint16_t min1_rpt_index; /* 1min frozen data in flash */ uint16_t min1_cnt; } iot_sg_sta_node_data_clct_info_t; /* sta extended collection task info */ typedef struct _iot_sg_sta_node_clct_info { /* node task info */ iot_sg_sta_node_clct_task_info_t task_info[IOT_SG_EXT_CLCT_TASK_CNT_MAX]; } iot_sg_sta_node_clct_info_t; /* sta extended data freeze info fujian protocol */ typedef struct _iot_sg_sta_node_freeze_info { /* task execution time */ iot_time_tm_t task_tm[IOT_SG_STA_EXT_FJ_FREEZE_TASK_MAX_CNT]; } iot_sg_sta_node_freeze_info_t; /* sta extended gw data collection task info */ typedef struct _iot_sg_sta_node_gw_clct_info { /* task execution time */ iot_time_tm_t task_tm[IOT_SG_STA_EXT_GW_V28_CLCT_TASK_MAX_CNT]; } iot_sg_sta_node_gw_clct_info_t; typedef struct _iot_sg_sta_node_edge_computing_info { /* count of continuous overvoltage events */ uint8_t overvoltage_cnt; /* count of continuous undervoltage events */ uint8_t undervoltage_cnt; /* maximum overvoltage value per phase */ uint16_t max_va; uint16_t max_vb; uint16_t max_vc; /* minimum undervoltage value per phase */ uint16_t min_va; uint16_t min_vb; uint16_t min_vc; /* flag meter overvoltage event need upload */ uint8_t overvoltage : 1, /* flag meter undervoltage event need upload */ undervoltage: 1, /* flag meter health event need upload */ health : 1, /* reserve */ rsvd : 5; } iot_sg_sta_node_ec_info_t; /* secondary node descriptor */ typedef struct _iot_sg_sta_node_desc { /* hash table entry */ iot_addr_hash_entry_t entry; /* data type being used by the node. See IOT_SG_STA_DATA_TYPE_XXX */ uint8_t data_type :3, /* flag to mark if node is double protocol */ double_proto :1, /* flag of neutralwire and livewire abnormal function enable */ nli_en :1, /* flag of gw data collection enable */ gw_clclt_en :1, /* flag to mark if meter support edge computing function */ ec_en :1, /* flag to mark if the node is in neighbor state */ is_neighbor :1; /* module type of the node. IOT_SG_STA_DEV_TYPE_XXX */ uint8_t module_type :2, /* flag to mark if the node is Q/GDW 354-2009 meter */ is_09_rule :1, /* flag to mark if the meter is three phase meter */ is_three_phase :1, /* phase of the device, bit0-2 means phaseA/B/C, set "1" to * indicate which phase the device belongs to. */ phase :3, /* flag to mark if voltage reverse phase sequence */ v_rps :1; /* flag to mark if physical phase identification done */ uint8_t phase_ident :1, /* flag to mark if the node is obsolete. when the flag is set, the node * can't be queried */ obsolete :1, /* flag of load curve collection enable */ lr_en :1, /* sm event report state, see IOT_SG_STA_SM_EVT_REPORT_XXX */ sm_rpt_state :2, /* flag of data freeze function enable for FUJIAN proto */ data_freeze_en :1, /* flag of load cure function enable for NW proto */ nw_lc_en :1, /* flag of is neutralwire and livewire abnormal exec * neutralwire and livewire current detected. */ nli_detected :1; /* flag to mark if the meter support load record */ uint8_t supp_lr :1, /* flag to mark if the meter support collection task */ clct_task_en :1, /* flag of state score enable */ ss_en :1, /* flag of data collection enable */ data_clct_en :1, /* suspected status of the meter, 1 - power off, 0 - power on */ sus_pof :1, /* flag to mark if node time abnormal */ time_abnormal :1, /* flag to mark if need to collect last day frozen data after power on */ clct_last_df :1, /* flag to mark if if abnormal load record reading is detected */ lr_rec_abnormal :1; union { /* sta extended load curve info */ iot_sg_sta_node_lr_info_t lr_info; /* sta extended collect task info */ iot_sg_sta_node_clct_info_t clct_info; /* sta extended data collection info for jiangsu proto protocol */ iot_sg_sta_node_data_clct_info_t data_clct_info; /* sta extended data freeze info fujian protocol */ iot_sg_sta_node_freeze_info_t freeze_info; /* sta extended data collection info for gw proto protocol */ iot_sg_sta_node_gw_clct_info_t gw_node_clct_info; } ext; #if IOT_SMART_GRID_EDGE_COMPUTING_ENABLE union { iot_sg_sta_node_ec_info_t ec_info; } ext_1; #endif } iot_sg_sta_node_desc_t; /* black listed secondary node descriptor */ typedef struct _iot_sg_sta_node_bl_desc { /* hash table entry */ iot_addr_hash_entry_t entry; /* time stamp to remove the node from black list, unit is 1s */ uint32_t rm_ts; } iot_sg_sta_node_bl_desc_t; /* sta joining nid info */ typedef struct _iot_sg_sta_joining_nid_info { /* network id */ uint32_t nid :24, /* sta joining count */ join_cnt :8; } iot_sg_sta_joining_nid_info_t; /* invalid mac address descriptor */ typedef struct _iot_sg_sta_invalid_addr_entry { /* mac address */ uint8_t addr[IOT_MAC_ADDR_LEN]; /* flag of invalid mac address */ uint8_t invalid_mac; /* sta joining nid info count */ uint8_t nid_cnt; /* sta joining nid info */ iot_sg_sta_joining_nid_info_t nid_list[IOT_SG_STA_JOINING_NID_LIST_MAX_NUM]; /* time stamp to remove the node from invalid mac list, unit is 1s */ uint32_t rm_ts; } iot_sg_sta_invalid_addr_entry_t; /* power off event bitmap */ typedef struct _iot_sg_sta_power_off_bm { /* flag of updated */ uint8_t updated; /* bitmap of node that's power off */ uint8_t map[IOT_SG_STA_MAP_BYTE_LEN]; } iot_sg_sta_power_off_bm_t; /* buffer of power down information of addr version */ typedef struct _iot_sg_sta_pd_addrs_buf { /* the iot_pkt for caching power down info */ iot_pkt_t *pkt; /* rpt seq */ uint16_t seq; /* the number of valid meter info contained in iot_pkt */ uint8_t pm_cnt; /* flag to mark if power down info is updated */ uint8_t updated; } iot_sg_sta_pd_addrs_buf_t; /* power off event addrmap check ctrl descriptor */ typedef struct _iot_sg_sta_pd_addrs_ctrl { /* cnt of node checked*/ uint8_t check_cnt; /* index of node checked in node list */ uint8_t check_index; /* check cnt */ uint8_t check_pm_cnt : 4, /* check max cnt */ check_pm_cnt_max: 4; /* flag mark to if report started */ uint8_t started; /* local power down check results */ iot_sg_sta_pd_addrs_info_t local[IOT_SG_STA_SEC_NODE_MAX]; /* address version power down info buffer */ iot_sg_sta_pd_addrs_buf_t addrs_buf[IOT_SG_STA_PD_ADDRS_BUF_CNT]; } iot_sg_sta_pd_addrs_ctrl_t; /* power off event bitmap descriptor */ typedef struct _iot_sg_sta_pd_bitmap_desc { /* the tei of the fisrt power off node in bitmap */ uint16_t first_tei; /* the tei of the last power off node in bitmap */ uint16_t last_tei; /* length of bitmap, uint is 1 byte */ uint16_t length; } iot_sg_sta_pd_bitmap_desc_t; /* power on event addrmap descriptor */ typedef struct _iot_sg_sta_power_on_addrmap_desc { /* cnt of node checked */ uint8_t check_cnt; /* flag to mark if check completed */ uint8_t complete; } iot_sg_sta_power_on_addrmap_desc_t; /* hw tsfm info descriptor */ typedef struct _iot_sg_sta_hw_tsfm { /* uart handle for read hw tsfm info form extenal IC */ iot_uart_h uart_tsfm_h; /* flag to mark tsfm mode. 1 is hardware support tsfm, 0 is normal */ uint8_t tsfm_mode : 2, /* cnt of read tsfm info */ read_cnt : 6; /* tsfm topo rec phase info * bit0 represent phase A * bit1 represent phase B * bit2 represent phase C */ uint8_t topo_phase_rec; /* tsfm topo rec energy */ uint32_t topo_energy_rec[IOT_PLC_PHASE_CNT]; /* tsfm topo info */ iot_sg_sta_topo_info_t tsfm_topo_info; /* tsfm send control information */ iot_sg_sta_tsfm_send_ctrl_t tsfm_send_ctrl; /* tsfm report control infomation */ iot_sg_sta_tsfm_rpt_ctrl_t tsfm_rpt_ctrl; } iot_sg_sta_hw_tsfm_t; /* descriptor for node register request */ typedef struct _iot_sg_sta_node_reg_global { /* flag to mark if secondary node register is ongoing */ uint8_t node_reg_on :1, /* flag to mark if last_node_reg_s_seq is valid */ last_node_reg_s_seq_valid :1, /* reserved for future */ reserved :6; /* the timestamp of the last node register result, unit is 1ms */ uint64_t last_node_reg_ts; /* last node reg start request sequence. used to detect duplicate request */ uint32_t last_node_reg_s_seq; } iot_sg_sta_node_reg_global_t; /* sta upgrade info */ typedef struct _iot_sg_sta_upgrade_info { /* drive upgrade state, see IOT_SG_STA_DRV_UPGRADE_STATE_XXX */ uint8_t drv_upgrde_state :1, /* need upgrade external device flag */ ext_dev_need_upgrade_flag :1, /* reserved for future */ reserved :6; /* upgrading block size */ uint32_t block_size; /* received block count */ uint32_t rec_blk_cnt; /* total block count of the upgrading file */ uint32_t block_cnt; /* upgrading file size */ uint32_t file_size; /* CRC of the whole upgrading file from CCo */ uint32_t file_crc; /* it's upgrade id in gw proto, while file id in nw proto. * for file id is regarded as upgrade id for nw upgrading. */ uint32_t upgrade_id; /* upgrade time window in minutes */ uint16_t upgrade_time_win; /* wait duration for reset */ uint16_t reset_wait_dur; /* trail run duration */ uint32_t trail_run_dur; /* timer to handle upgrade window / reset wait duration / reset duration */ timer_id_t upgrade_timer; /* upgrade state */ uint16_t state; /* CRC calculated from received data block */ uint32_t calc_crc; /* pkt to cache the 1st block. alloc when * upgrading and free when upgrade finish. */ iot_pkt_t *cache; /* current running partition info */ uint32_t current_crc; /* crc of running partition */ uint32_t current_len; /* length of running partition */ uint32_t current_part; /* current running part */ uint32_t current_bk_size;/* upgrade block size in current runing part */ /* upgrade sequence number for nw protocol */ uint16_t upgrade_sn; /* indicate if STA shall skip upgrading because of * invalid upgrading file. */ uint8_t skip :1, /* if STA received the 1st data block. */ header_recved :1, exit_reason :3, /* current upgrade exit reason */ /* upgrade session type see - IOT_SG_STA_UPGRADE_SESSION_TYPE_XXX */ session_type :3; #if IOT_SG_STA_UPGRADE_EXT_DEV_ENABLE /* timer to handle upgrade external device */ timer_id_t ext_dev_upgrade_timer; /* external device upgrade start offset */ uint32_t ext_dev_start_offset; /* external device upgrade last send length */ uint32_t ext_dev_last_send_len; /* external device upgrade send data lenght */ uint32_t ext_dev_send_len; /* external device upgrade file size */ uint32_t ext_dev_file_size; /* external device upgrade file crc */ uint32_t ext_dev_file_crc; /* external device upgrade send block index */ uint16_t ext_dev_upgrade_block_index; /* external device upgrade command retry count */ uint8_t ext_dev_upgrade_retry_cnt; /* if the external upgrade fail restart again */ uint8_t ext_dev_restart_flag :1, /* external device upgrade state */ ext_dev_state :7; #endif /* IOT_SG_STA_UPGRADE_EXT_DEV_ENABLE */ }iot_sg_sta_upgrade_info_t; /* smart grid sta meter read global descriptor */ typedef struct _iot_sg_sta_mr_global { /* flag to mark if meter read is ongoing */ uint32_t meter_read_on :1, /* flag to mark if resend the 645 frame if no response */ timeout_retry :1, /* flag to mark if resend the 645 frame if get nack */ nack_retry :1, /* max retry count allowed */ max_retry :4, /* current frame retry count */ retry_cnt :4, /* flag to mark if last successful meter reading */ last_mr_valid :1, /* meter reading data type. see GW_APP_DATA_TYPE_XXX */ data_type :4, /* flag to mark if connectionless last meter reading valid */ last_conn_less_mr_valid :1, /* flag to mark if crtl last meter reading valid */ last_crtl_mr_valid :1, /* flag to mark if enable address filtering when reading */ addr_filter_en :1, /* reserved for future */ reserved :13; /* meter reading baud rate */ uint32_t mr_baud; /* meter reading timeout, uint is 1ms */ uint32_t mr_timeout; /* min meter reading timeout, uint is 1ms */ uint32_t mr_timeout_min; /* meter reading interval, uint is 1ms */ uint16_t mr_interval; /* total 645 frames in current meter read request */ uint8_t frame_cnt; /* current frames being handled */ uint8_t frame_idx; /* type of the last successful meter reading */ uint8_t last_mr_type; /* the sequence number of the last successful meter reading */ uint16_t last_mr_seq; /* the timestamp of the last successful meter reading */ uint64_t last_mr_ts; /* the data pkt for the last successful meter reading */ iot_pkt_t *last_mr_data_pkt; /* meter read ack status. each bit reflect ack status for a frame. * the lowest bit corresponding to the first frame in the read request. */ uint16_t read_ack; /* frame pointer array for each read request */ uint8_t* frame_data[IOT_SG_STA_MAX_FRAME_PER_READ]; /* frame length array for each read request */ uint16_t frame_len[IOT_SG_STA_MAX_FRAME_PER_READ]; /* the last connectionless meter reading src address */ uint8_t last_conn_less_src[IOT_MAC_ADDR_LEN]; /* connectionless last meter address */ uint8_t last_conn_less_mr_addr[IOT_MAC_ADDR_LEN]; /* pending meter read respond packet */ iot_pkt_t *read_rsp; /* pointer to app_header_t in read_rsp */ uint8_t *app_hdr; /* meter read related statistics */ iot_sg_sta_mr_stats_t mr_info; } iot_sg_sta_mr_global_t; /* smart grid sta query local plc info descriptor */ typedef struct _iot_sg_sta_query_plc_global { /* flag to mark if query neighbor node is ongoing */ uint8_t neig_info_query_on :1, /* flag to mark if request is broadcast, only for nw protocol */ flag_broadcast :1, /* query neighbor node timeout, uint is 1s */ neig_info_timeout :6; } iot_sg_sta_query_plc_global_t; /* smart grid event global descriptor */ typedef struct _iot_sg_sta_evt_global { /* flag to mark if event report is pending */ uint8_t event_rpt_pending :1, /* flag to mark if event report is enable */ event_rpt_on :1, /* flag to mark if power on event report is pending */ power_on_rpt_pending :1, /* power on event report cnt */ power_on_rpt_cnt :5; /* sm done event report counter */ uint8_t sm_done_rpt_cnt :7, /* sm done flag */ sm_done :1; /* all aa sm done flag */ uint8_t aa_sm_done :1, /* power on event reporting in progress */ power_on_reporting :1, /* flag to mark if production test is detected */ pt_detected :1, /* reserved for future */ reserved :5; /* power down event valid time for fujian, uint is 1s */ uint8_t fj_pd_valid_time; /* sm done event report sequence */ uint16_t sm_done_evt_rpt_seq; /* event report sequence. used to detect obsolete cco response */ uint16_t event_rpt_seq; /* meter event report sequence. used to detect obsolete cco response */ uint16_t pm_evt_rpt_seq; /* power off event report status, see IOT_SG_STA_POWEROFF_XXX */ uint8_t power_off_rpt_status; /* power off event report cnt */ uint8_t power_off_send_cnt; /* power on event report or forward sequence. used to repeat report */ uint16_t power_off_rpt_seq; /* power on event report sequence. used to repeat report */ uint16_t power_on_rpt_seq; /* sta power off event bitmap */ iot_sg_sta_power_off_bm_t power_off_bm; /* address version power down information control structure */ iot_sg_sta_pd_addrs_ctrl_t pd_addr_ctrl; /* power on event addrmap descriptor */ iot_sg_sta_power_on_addrmap_desc_t pu_addr_ctrl; /* module event report retry cnt */ uint8_t retry_cnt :2, /* abnormal phase sequence in Three-phase power meter. * if lack phase first bit setting 1, for example 0x001. * if reversed phase second bit setting 1, for example 0x010. * if L/N reversed third bit setting 1, for example 0x100. */ abn_ps :3, /* historical records of abnormal phase sequences */ his_abn_ps :3; /* historical records of the zc status report sn */ uint8_t his_zc_status_sn; /* number of meters to be reported scoring results */ uint8_t score_rpt_cnt; /* report event type, see IOT_SG_STA_RPT_XXX_XXX_EVT */ uint8_t rpt_type; /* clock skew interval between concentrator and meter */ int64_t clock_interval; /* event report mode for fujian, see IOT_SG_STA_FJ_EVT_RPT_MODE_XXX */ uint8_t fj_evt_rpt_mode :2, /* event report type for fujian, see IOT_SG_STA_FJ_EVT_RPT_TYPE_XXX */ fj_evt_rpt_type :1, /* enable event report or not when report mode is external, 1 - enable */ fj_evt_rpt_en :1, /* reserved for future */ reserved_2 :4; } iot_sg_sta_evt_global_t; /* smart grid sta properties descriptor */ typedef struct _iot_sg_sta_properties_global { /* physical phase of the device, bit0-2 means phaseA/B/C, set "1" to * indicate which phase the device belongs to. */ uint8_t phase :3, /* flag to mark if L/N reversed in Single-phase power meter or phase * sequence reversed in Three-phase power meter. */ opposite_phase :1, /* flag to mark if physical phase identification done */ detect_state :1, /** logical phase of the device, see IOT_PLC_PHASE_XXX */ logic_phase :2, /** flag to mark if L/N reversed in Three-phase power meter */ opposite_3p :1; /* connection position of N-wire if L/N of three-phase meter is reversed. * see IOT_PLC_PHASE_XXX. * Note: the position refers to the physical phase terminal. */ uint8_t opposite_3p_pos :2, /* flag to mark if the 3phase device have the zc repeat phase */ zc_repeat_3p :1, /* reserved for future */ reserved1 :5; } iot_sg_sta_properties_global_t; /* meter data */ typedef struct _iot_sg_sta_ext_meter_data { /* voltage */ proto_645_v_t v; /* current */ proto_645_07_a_t a; /* GND current */ uint8_t gnd_a[PROTO_645_07_A_LEN]; /* active power */ proto_645_07_p_t ap; /* reactive power */ proto_645_07_p_t rp; /* apparent power */ proto_645_07_p_t atp; /* power factor */ proto_645_07_pf_t pf; /* positive active energy */ proto_645_07_energy_data_t pae; /* negative active energy */ proto_645_07_energy_data_t nae; /* combined active energy */ proto_645_07_energy_data_t cae; /* combined reactive energy data 1 */ proto_645_07_energy_data_t cre1; /* combined reactive energy data 2 */ proto_645_07_energy_data_t cre2; /* reactive energy data in the first quadrant */ proto_645_07_energy_data_t re_1st; /* reactive energy data in the second quadrant */ proto_645_07_energy_data_t re_2st; /* reactive energy data in the third quadrant */ proto_645_07_energy_data_t re_3st; /* reactive energy data in the fourth quadrant */ proto_645_07_energy_data_t re_4st; /* current active power demand */ uint8_t ept_demand[PROTO_645_07_P_LEN]; /* current reactive power demand */ uint8_t eqt_demand[PROTO_645_07_P_LEN]; /* current total pos-active power demand data with time */ iot_sg_meter_max_demand_and_ht_t pos_ap_demand; /* current total neg-active power demand data with time */ iot_sg_meter_max_demand_and_ht_t neg_ap_demand; /* current total combined reactive 1 demand data with time */ iot_sg_meter_max_demand_and_ht_t cre1_demand; /* current total combined reactive 2 demand data with time */ iot_sg_meter_max_demand_and_ht_t cre2_demand; /* frozen time */ proto_645_07_frozen_time_t frozen_time; /* current meter time */ proto_645_07_time_t time; /* running status word */ iot_sg_meter_rs_word_t rs_word; /* phase angle */ proto_645_07_phase_angle_t phase_angle; /* voltage waveform distortion */ proto_645_07_waveform_dis_t v_waveform_dis; /* current waveform distortion */ proto_645_07_waveform_dis_t i_waveform_dis; /* a phase voltage harmonic content */ proto_645_07_harmonic_cont_t a_v_hc; /* b phase voltage harmonic content */ proto_645_07_harmonic_cont_t b_v_hc; /* c phase voltage harmonic content */ proto_645_07_harmonic_cont_t c_v_hc; /* a current voltage harmonic content */ proto_645_07_harmonic_cont_t a_i_hc; /* b current voltage harmonic content */ proto_645_07_harmonic_cont_t b_i_hc; /* c current voltage harmonic content */ proto_645_07_harmonic_cont_t c_i_hc; /* frequency data */ proto_645_freq_t freq; /* 1 min average power */ uint8_t average_p[PROTO_645_07_P_LEN]; /* apparent power demand */ uint8_t at_demand[PROTO_645_07_P_LEN]; /* temperature */ uint8_t temperature[PROTO_645_TEMPERATURE_LEN]; /* clock battery voltage */ uint8_t clock_battery_v[PROTO_645_V_LEN]; /* meter read battery voltage */ uint8_t mr_battery_v[PROTO_645_V_LEN]; /* interior battery work time */ uint8_t work_time[PROTO_645_INTER_BATTERY_TIME_LEN]; /* positive active a phase energy */ uint8_t pos_a[PROTO_645_07_ENERGY_DATA_LEN]; /* positive active b phase energy */ uint8_t pos_b[PROTO_645_07_ENERGY_DATA_LEN]; /* positive active c phase energy */ uint8_t pos_c[PROTO_645_07_ENERGY_DATA_LEN]; } iot_sg_sta_ext_meter_data_t; /* sta extended load curve configuration structure */ typedef struct _iot_sg_sta_ext_lc_cfg { /* start time */ iot_time_tm_t tm; /* acquisition interval, unit is 1s */ uint16_t interval; /* load curve data id cnt in di_buf */ uint8_t cnt; /* load curve data id buf */ uint32_t di_buf[IOT_SG_STA_EXT_LR_DI_CNT_MAX]; } iot_sg_sta_ext_lc_cfg_t; /* sta extended load curve info */ typedef struct _iot_sg_sta_ext_lc_info { /* default cfg id */ uint8_t cfg_index; /* last broadcast froze time */ iot_time_tm_t last_froze_tm; /* broadcast froze time */ iot_time_tm_t froze_tm; /* configuration information */ const iot_sg_sta_ext_lc_cfg_t *cfg; /* current lr id index in di_buf */ uint8_t index; /* 698 msg last lr id index in di_buf */ uint8_t last_index_698; /* current state */ uint8_t state; /* read time cnt, unit is IOT_SG_STA_EXT_SM_DELAY */ uint8_t timeout_cnt; /* flag of repeat cnt */ uint8_t repeat_cnt : 2, /* flag of response */ flag_resp : 1, /* reserved for future */ reserved : 5; } iot_sg_sta_ext_lc_info_t; /* sta extended collect param */ typedef struct _iot_sg_sta_ext_clct_param { /* flag of update */ uint8_t flag_update : 1, /* 0 - disabled, 1 - enabled */ enabled : 1, /* resever */ resever : 6; /* collect configuration cache structure */ iot_sg_sta_ext_lc_cfg_t cfg_cache; /* collect configuration structure */ iot_sg_sta_ext_lc_cfg_t cfg; } iot_sg_sta_ext_clct_param; typedef struct _iot_sg_sta_ext_clct_di_desc { /* control code */ uint8_t control_code; /* length of collection data */ uint8_t len_data; /* di of collection data */ uint32_t di; } iot_sg_sta_ext_clct_di_desc_t; /* sta extended collect task descriptor */ typedef struct _iot_sg_sta_ext_clct_task_desc { /* task id */ uint8_t id; /* start time */ iot_time_tm_t tm; /* protocol type, see IOT_SG_EXT_CLCT_TASK_PROTO_TYPE_XXX */ uint8_t proto_type; /* period type, see IOT_SG_EXT_CLCT_TASK_PERIOD_XXX */ uint8_t period_type; /* current di index in di_buf */ uint8_t idx; /* clct task info di cnt in di_buf */ uint8_t cnt; /* clct task info di buf */ iot_sg_sta_ext_clct_di_desc_t di_buf[IOT_SG_EXT_CLCT_TASK_DI_CNT_MAX]; } iot_sg_sta_ext_clct_task_desc_t; typedef struct _iot_sg_sta_ext_clct_task_info { /* current collection task state */ uint8_t state; /* current collection task timeout, unit is IOT_SG_STA_EXT_SM_DELAY */ uint8_t timeout_cnt; /* flag of response */ uint8_t flag_resp; /* current task cfg info */ iot_sg_sta_ext_clct_task_desc_t task_info; /* current task response data */ iot_pkt_t *resp_pkt; } iot_sg_sta_ext_clct_task_info_t; /* sta extended state score info */ typedef struct _iot_sg_sta_ext_state_score { /* enable */ uint8_t enable; /* score di index */ uint8_t di_index; /* timeout count */ uint8_t timeout_cnt; /* flag of response */ uint8_t flag_resp; /* send count */ uint8_t send_cnt; /* meter complete state score count */ uint8_t complete_cnt; /* fault flag */ uint8_t v_fault :1, /* program enable */ program_en :1, /* power down frequently */ pd_freq :1, /* reserved for future */ reserved :5; /* number of meters to be reported scoring results */ uint8_t score_rpt_cnt; /* state score enable time stamp, unit is 1s */ uint64_t score_en_ts; /* use 4 bytes of BCD code to represent last total energy value */ uint8_t last_total[PROTO_645_07_ENERGY_DATA_LEN]; /* state score bit map */ iot_sg_sta_drv_score_bit_map_t bit_map; } iot_sg_sta_ext_state_score_t; /* sta current data collection config for jiangsu protocol */ typedef struct _iot_sg_sta_ext_data_clct_config { /* flag of collection config is latest */ uint8_t cfg_is_latest : 1, /* reserved for future */ reserved :6; /* current function */ uint8_t cur_func; /* start time */ iot_time_tm_t start_time; /* execution interval */ int64_t exe_inter; /* collection delay time */ uint16_t delay; /* collection data identification bitmap, * see IOT_SG_STA_METER_TASK_DI_XXX. */ uint32_t di_bitmap; } iot_sg_sta_ext_data_clct_config_t; /* collection task monitoring for jiangsu protocol */ typedef struct _iot_sg_sta_ext_data_clct_monitor { /* the number of messages sent */ uint16_t msg_send_num; /* the number of messages receive */ uint16_t msg_recv_num; } iot_sg_sta_ext_data_clct_monitor_t; /* sta current data collection info for jiangsu protocol */ typedef struct _iot_sg_sta_ext_data_clct_info { /* current collection task state */ uint8_t cur_state; /* read time cnt, unit is IOT_SG_STA_EXT_SM_DELAY */ uint8_t timeout_cnt :4, /* current collection group di table index */ group_di_idx :4; /* current collection di, see IOT_SG_STA_METER_TASK_DI_XXX */ uint8_t cur_clct_di; /* flag of repeat cnt */ uint8_t repeat_cnt : 2, /* flag of response */ flag_resp : 1, /* flag of day freeze collection task enable */ df_en : 1, /* flag of month freeze collection task enable */ mf_en : 1, /* flag of 1 minute curve collection task enable */ cur_1m_en : 1, /* flag of 15 minute curve collection task enable */ cur_15m_en : 1, /* flag of data collection task initialization */ task_init : 1; /* flag of day freeze collection task executed. */ uint8_t df_done : 1, /* flag of month freeze collection task executed. */ mf_done : 1, /* flag of 15 minute curve collection task executed. */ cur_15m_done: 1, /* flag of 15 minute curve collection task executed. */ cur_1m_done : 1, /* flag to mark if search meter complete */ sm_complete : 1, /* flag to mark if last frozen time valid */ ft_valid : 1, /* current collection di is group di */ is_group_di : 1, /* reserved for future */ reserved : 1; /* sta current data collection config */ iot_sg_sta_ext_data_clct_config_t config; /* collection task monitoring */ iot_sg_sta_ext_data_clct_monitor_t monitor[IOT_SG_STA_METER_JS_CFG_TYPE_MAX]; } iot_sg_sta_ext_data_clct_info_t; /* sta collect data report info for jiangsu protocol */ typedef struct _iot_sg_sta_ext_clct_rpt_info { /* current rpt state, see IOT_SG_STA_COLL_DATA_RPT_STATE_XXX */ uint8_t cur_state; /* current seq */ uint8_t seq; /* last rpt info type, see IOT_SG_STA_CLCT_LAST_RPT_XXX */ uint8_t last_rpt_type; /* last rpt info */ iot_sg_sta_ext_clct_rpt_desc_t last_rpt_info; /* last multi meter rpt info */ iot_sg_sta_ext_clct_multi_rpt_desc_t last_multi_rpt_info; } iot_sg_sta_ext_clct_rpt_info_t; /* freeze task comment report cfg info structure for fujian protocol */ typedef struct _iot_sg_sta_ext_freeze_task_comm_rpt_cfg { /* task id */ uint8_t id; /* multiple report cnt */ uint8_t cnt; } iot_sg_sta_ext_freeze_task_comm_rpt_cfg_t; /* freeze task comment cfg info structure for fujian protocol */ typedef struct _iot_sg_sta_ext_freeze_task_comm_cfg { /* task data record unit max length */ uint8_t unit_max_len; /* task report max cnt within 24h */ uint8_t report_max_cnt; /* rpt random time, percentage of task cycles, uint is 1%, range 10~90 */ uint8_t random_rpt_time; /* num of retrans of frozen tasks whose cycle is less than 5 minutes. */ uint8_t retry_freeze : 4, /* num of retrans of non frozen or frozen tasks whose cycle is greater * than 5 minutes. */ retry_nonfreeze : 4; /* meter multiple data item * 0 meter nonsupport multiple data item * 1 meter support multiple data item */ uint8_t mult_data_item : 4, /* module report mode * 0 mean dl/t-645 protocol mode; * 1 mean dl/t-69845 protocol mode; */ rpt_mode : 4; /* meter add for multiple data item, little endian. */ uint8_t mult_di_addr[IOT_MAC_ADDR_LEN]; /* task cnt in task_rpt */ uint8_t cnt; /* task report config */ iot_sg_sta_ext_freeze_task_comm_rpt_cfg_t task_rpt[ IOT_SG_STA_EXT_FJ_FREEZE_TASK_MAX_CNT]; } iot_sg_sta_ext_freeze_task_comm_cfg_t; /* freeze task cfg info structure for fujian protocol */ typedef struct _iot_sg_sta_ext_freeze_task_merge_uint { /* merge pkt */ iot_pkt_t *merge_pkt; /* message cnt in merge pkt */ uint8_t msg_cnt : 7, /* report mode */ mode : 1; /* task id */ uint8_t task_id; /* meter address */ uint8_t addr[IOT_MAC_ADDR_LEN]; } iot_sg_sta_ext_freeze_task_merge_uint_t; /* freeze task cfg info structure for fujian protocol */ typedef struct _iot_sg_sta_ext_freeze_task_rpt_uint { /* report pkt */ iot_pkt_t *rpt_pkt; /* report cnt */ uint8_t rpt_cnt : 7, /* report mode * 0 mean dl/t-645 protocol mode; * 1 mean dl/t-69845 protocol mode; */ mode : 1; /* task id */ uint8_t task_id; /* report message cnt in rpt_pkt for dl/t-69845 protocol mode */ uint8_t msg_cnt; /* meter address */ uint8_t addr[IOT_MAC_ADDR_LEN]; /* random report time, uint is 1s */ uint16_t random_rpt_tm; /* report sequence number */ uint16_t seq; /* add time stamp, uint is 1s */ uint32_t tm; /* report time stamp, uint is 1s */ uint32_t rpt_tm; } iot_sg_sta_ext_freeze_task_rpt_uint_t; /* freeze exe cnt reamin info */ typedef struct _iot_sg_sta_ext_freeze_task_exe_cnt { /* freeze task id */ uint8_t task_id; /* last response data cnt in last_data */ uint8_t data_cnt; /* valid data length in last data */ uint8_t valid_len; /* number of remaining executable tasks */ uint16_t count; /* number of trigger tasks */ uint16_t trigger_cnt; /* report total cnt */ uint16_t rpt_total_cnt; /* report cnt */ uint16_t rpt_cnt; /* last data, see iot_sg_sta_drv_meter_fj_unit_data_t */ uint8_t last_data[IOT_SG_STA_METER_FJ_TASK_RECORD_UINT_LEN]; }iot_sg_sta_ext_freeze_task_exe_cnt_t; typedef struct _iot_sg_sta_ext_freeze_task_reset { /* reset task cnt */ uint8_t cnt; /* current reset task index */ uint8_t cur_idx; /* reset task id */ uint8_t task_id[IOT_SG_STA_EXT_FJ_FREEZE_TASK_MAX_CNT]; } iot_sg_sta_ext_freeze_task_reset_t; /* sta data freeze info for fujian protocol */ typedef struct _iot_sg_sta_ext_freeze_task_t { /* current task state, see IOT_SG_STA_EXT_FREEZR_STATE_XXX */ uint8_t cur_state; /* current task id 1 - 253 */ uint8_t cur_task_id; /* current di index */ uint8_t cur_di_idx; /* current mr di count */ uint8_t cur_mr_di_cnt; /* read time cnt, unit is IOT_SG_STA_EXT_SM_DELAY */ uint16_t timeout_cnt :4, /* flag of repeat cnt */ repeat_cnt :2, /* flag of response */ flag_resp :1, /* flag of nack response */ flag_nack_resp :1, /* flag of freeze data report */ flag_rpt :1, /* flag of cur task end */ task_end :1, /* flag of report task first execute */ first_rpt_task :1, /* led blink enable counter, unit is 1 refresh interval */ led_blink_en_cnt :2, /* reserved */ rsvd :3; /* freeze task handle bitmap */ uint16_t task_bm; /* task stop dur, unit is 1s */ uint32_t stop_dur :24, /* init task id */ init_task_id :8; /* current task response data */ iot_pkt_t *resp_pkt; /* task comment cfg info */ iot_sg_sta_ext_freeze_task_comm_cfg_t comm_cfg; /* task reset */ iot_sg_sta_ext_freeze_task_reset_t reset; /* task cfg valid id */ uint8_t valid_id[IOT_SG_STA_EXT_FJ_FREEZE_TASK_MAX_CNT]; /* Number of times the corresponding task can be executed */ iot_sg_sta_ext_freeze_task_exe_cnt_t exe_cnt_remain[IOT_SG_STA_EXT_FJ_FREEZE_TASK_MAX_CNT]; /* task rpt merge data */ iot_sg_sta_ext_freeze_task_merge_uint_t merge_list[ IOT_SG_STA_EXT_FJ_FREEZE_TASK_MAX_CNT]; /* task rpt data */ iot_sg_sta_ext_freeze_task_rpt_uint_t rpt_list[ IOT_SG_STA_EXT_FJ_FREEZE_TASK_MAX_CNT]; } iot_sg_sta_ext_freeze_task_t; /* sta extended load curve info for nw protocol */ typedef struct iot_sg_sta_ext_lc_info_nw { /* current state */ uint8_t state; /* read time cnt, unit is IOT_SG_STA_EXT_SM_DELAY */ uint8_t timeout_cnt; /* flag of repeat cnt */ uint8_t repeat_cnt : 2, /* flag of response */ flag_resp : 1, /* flag of multi di read response */ flag_multi_resp : 1, /* reserved for future */ reserved : 4; /* current lr id index */ uint8_t di_idx; /* multi di msg last lr id index in di_buf */ uint8_t last_di_idx; } iot_sg_sta_ext_lc_info_nw_t; /* sta extend neutralwire and livewire abnormal info */ typedef struct _iot_sg_sta_ext_nli_info { /* flag of repeat cnt */ uint8_t repeat_cnt : 2, /* flag of response */ flag_resp : 1, /* current state */ state : 2, /* reserved */ reserved : 3; /* read time cnt, unit is IOT_SG_STA_EXT_SM_DELAY */ uint8_t timeout_cnt; /* data read step, see IOT_SG_STA_EXT_NLI_READ_XXX */ uint8_t di_idx; /* next exec timestamp, uint is 1ms */ uint64_t next_time; }iot_sg_sta_ext_nli_info_t; /* abnormal electric current data for neutralwire and livewire */ typedef struct _iot_sg_sta_ext_nli_evt_data { /* power meter address, little endian */ uint8_t pm_addr[IOT_MAC_ADDR_LEN]; /* A phase current.use 3 bytes of BCD code to represent the current. * for example, 123.456A uses 3 bytes of BCD code to represent * the following 0x12, 0x34, 0x56. */ uint8_t phase_electric[GW_APP_ELECTRIC_CURRENT_LEN]; /* neutralwire electric current. bcd format, little endian */ uint8_t neutralwire_electric[GW_APP_ELECTRIC_CURRENT_LEN]; /* electric current for neutralwire and livewire, bcd format, little endian */ uint8_t nl_electric[GW_APP_ELECTRIC_CURRENT_LEN]; /* abnormal time, bcd format, little endian */ uint8_t time[GW_APP_ABNORMAL_TIME_DATA_LEN]; } iot_sg_sta_ext_nli_evt_data_t; typedef struct _iot_sg_sta_ext_nli_evt_data_field { /* report cnt */ uint16_t rpt_cnt; /* abnormal data for neutralwire and livewire */ iot_sg_sta_ext_nli_evt_data_t nli_data[0]; } iot_sg_sta_ext_nli_evt_data_field_t; /* sta extend neutralwire and livewire abnormal report info */ typedef struct _iot_sg_sta_ext_nli_evt_rpt_info { /* neutralwire and livewire abnormal event report sequence. * used to repeat report. */ uint16_t seq; /* report timeout count */ uint8_t timeout_cnt; /* report report count */ uint8_t report_cnt; /* neutralwire and livewire abnormal event data package */ iot_pkt_t *pkt; }iot_sg_sta_ext_nli_evt_rpt_info_t; /* sta ai management module topo data unit */ typedef struct _iot_sg_sta_ext_ai_topo_data_unit { /* voltage */ proto_645_v_t v; /* current */ proto_645_07_a_t i; /* power factor */ proto_645_07_pf_t pf; } iot_sg_sta_ext_ai_topo_data_unit_t; /* sta ai management module topo cfg info */ typedef struct _iot_sg_sta_ext_ai_topo_cfg { /* collection interval, unit is 1s. */ uint8_t interval; /* collected cnt */ uint16_t collected_cnt; /* flag of collection data */ uint8_t flag_v : 1, flag_i : 1, flag_pf : 1, /* reserved for future */ reserved : 5; /* start tm */ iot_time_tm_t start_tm; } iot_sg_sta_ext_ai_topo_cfg_t; /* sta ai management module topo collect data */ typedef struct _iot_sg_sta_ext_ai_topo_data { /* start idx data time stamp */ iot_time_tm_t first_tm; /* start index in list */ uint8_t start_idx; /* current index in list */ uint8_t end_idx; /* collect data */ iot_sg_sta_ext_ai_topo_data_unit_t list[ IOT_SG_STA_EXT_AI_TOPO_DATA_MAX]; } iot_sg_sta_ext_ai_topo_data_t; /* sta ai management module topo data info */ typedef struct _iot_sg_sta_ext_ai_topo_info { /* flag of topo collection */ uint8_t flag_enable : 1, /* flag of repeat cnt */ repeat_cnt : 2, /* flag of response */ flag_resp : 1, /* reserved for future */ reserved : 4; /* current cfg */ iot_sg_sta_ext_ai_topo_cfg_t curr_cfg; /* collection cnt */ uint16_t cnt; /* current seq */ uint16_t seq; /* state */ uint8_t state; /* response timeout, unit is 1s */ uint8_t timeout; /* 698 msg last lr id index in di_buf */ uint8_t last_idx; /* current di index in di_list */ uint8_t di_idx; /* di cnt */ uint8_t di_cnt; /* data */ uint32_t di_list[IOT_SG_STA_EXT_AI_TOPO_DI_MAX]; /* the timestamp of the next collection start */ iot_time_tm_t collect_tm; /* response cache data */ iot_sg_sta_ext_ai_topo_data_unit_t resp_data; /* collect data */ iot_sg_sta_ext_ai_topo_data_t topo_data; } iot_sg_sta_ext_ai_topo_info_t; /* sta ai management module line loss data info */ typedef struct _iot_sg_sta_ext_ai_ll_cfg { /* delta between meter clock and AI module clock, unit is 1s */ uint32_t delta : 30, /* flag with negative delta. 0 mean that delta is a positive number, * 1 mean that delta is a negative number */ neg_delta: 1, /* valid flag of delta. 0 mean that delta is invalid, * 1 mean that delta is valid */ valid : 1; /* collection interval, unit is 1s. */ uint16_t interval; /* collected cnt */ uint16_t collected_cnt; /* flag of collection data */ uint8_t flag_p : 1, flag_i : 1, flag_gi : 1, flag_v : 1, flag_pf : 1, flag_pos : 1, flag_neg : 1, flag_qtr : 1; /* start tm */ iot_time_tm_t start_tm; } iot_sg_sta_ext_ai_ll_cfg_t; /* meter data */ typedef struct _iot_sg_sta_ext_ai_ll_cache_data { /* voltage */ proto_645_v_t v; /* current */ proto_645_07_a_t i; /* GND current */ uint8_t gnd_a[PROTO_645_07_A_LEN]; /* active power */ proto_645_07_p_t ap; /* power factor */ proto_645_07_pf_t pf; /* positive active total energy */ uint8_t pos_total[PROTO_645_07_ENERGY_DATA_LEN]; /* positive active a phase energy */ uint8_t pos_a[PROTO_645_07_ENERGY_DATA_LEN]; /* positive active b phase energy */ uint8_t pos_b[PROTO_645_07_ENERGY_DATA_LEN]; /* positive active c phase energy */ uint8_t pos_c[PROTO_645_07_ENERGY_DATA_LEN]; /* negative active total energy */ uint8_t neg_total[PROTO_645_07_ENERGY_DATA_LEN]; /* negative active a phase energy */ uint8_t neg_a[PROTO_645_07_ENERGY_DATA_LEN]; /* negative active b phase energy */ uint8_t neg_b[PROTO_645_07_ENERGY_DATA_LEN]; /* negative active c phase energy */ uint8_t neg_c[PROTO_645_07_ENERGY_DATA_LEN]; /* reactive total energy in the first quadrant */ uint8_t re_1st_total[PROTO_645_07_ENERGY_DATA_LEN]; /* reactive total energy in the second quadrant */ uint8_t re_2st_total[PROTO_645_07_ENERGY_DATA_LEN]; /* reactive total energy in the third quadrant */ uint8_t re_3st_total[PROTO_645_07_ENERGY_DATA_LEN]; /* reactive total energy in the fourth quadrant */ uint8_t re_4st_total[PROTO_645_07_ENERGY_DATA_LEN]; } iot_sg_sta_ext_ai_ll_cache_data_t; /* sta ai management module line lose data info */ typedef struct _iot_sg_sta_ext_ai_ll_collect_info { /* flag of topo collection */ uint8_t flag_enable : 1, /* flag of repeat cnt */ repeat_cnt : 2, /* flag of response */ flag_resp : 1, /* reserved for future */ reserved : 4; /* collection cnt */ uint16_t cnt; /* current seq */ uint16_t seq; /* state */ uint8_t state; /* response timeout, unit is 1s */ uint8_t timeout; /* 698 msg last lr id index in di_buf */ uint8_t last_idx; /* current di index in di_list */ uint8_t di_idx; /* di cnt */ uint8_t di_cnt; /* data */ uint32_t di_list[IOT_SG_STA_EXT_AI_LL_DI_MAX]; /* the timestamp of the next collection start */ iot_time_tm_t collect_tm; /* response cache data */ iot_sg_sta_ext_ai_ll_cache_data_t resp_data; } iot_sg_sta_ext_ai_ll_collect_info_t; /* sta ai management module line lose data info */ typedef struct _iot_sg_sta_ext_ai_ll_info { /* flag of recover */ uint8_t flag_recover; /* cfg info */ iot_sg_sta_ext_ai_ll_cfg_t cfg; /* line lose collection data info */ iot_sg_sta_ext_ai_ll_collect_info_t collect_info; } iot_sg_sta_ext_ai_ll_info_t; /* sta ai management module topo data info */ typedef struct _iot_sg_sta_ext_ai_time { /* the time of system timestamp */ iot_time_tm_t sys_time; /* the timestamp of system, unit is 1s */ uint32_t sys_ts; } iot_sg_sta_ext_ai_time_t; /* sta ai management module function data structure */ typedef struct _iot_sg_sta_ext_ai_module { /* sta ai management module time data */ iot_sg_sta_ext_ai_time_t time; /* sta ai management module topo data info */ iot_sg_sta_ext_ai_topo_info_t topo_info; /* sta ai management module line lose data info */ iot_sg_sta_ext_ai_ll_info_t ll_info; } iot_sg_sta_ext_ai_module_t; /* sta data collection report unit info */ typedef struct _iot_sg_sta_ext_gw_clct_report_unit_info { /* point to unit head */ uint8_t *data; /* unit data report state, see IOT_SG_STA_EXT_GW_V28_UNIT_RPT_XXX */ uint32_t report_state : 2, /* 698 msg count */ msg_cnt : 6, /* unit data length */ len : 10, /* sequence of report data, * only for report_state == IOT_SG_STA_EXT_GW_V28_UNIT_RPT_ONGOING */ seq : 14; /* converge end time stamp, unit is 1s */ uint32_t end_ts; } iot_sg_sta_ext_gw_clct_report_unit_info_t; /* sta data collection report info */ typedef struct _iot_sg_sta_ext_gw_clct_report_info { /* timer used for report msg */ timer_id_t rpt_timer; /* report state, see IOT_SG_STA_EXT_GW_RPT_STATE_XXX */ uint8_t state : 7, /* flag of report enable */ flag_en : 1; /* report fail cnt */ uint8_t fail_cnt; /* report sequence */ uint16_t seq; /* report end ts, unit is 1ms */ uint64_t end_ts; /* report unit info */ iot_sg_sta_ext_gw_clct_report_unit_info_t unit_info[IOT_SG_STA_EXT_GW_V28_RPT_UNIT_CNT]; /* cache pkt */ iot_pkt_t *pkt[IOT_SG_STA_EXT_GW_V28_CACHE_PKT_CNT]; } iot_sg_sta_ext_gw_clct_report_info_t; /* sta current data collection info for gw protocol */ typedef struct _iot_sg_sta_ext_gw_clct_info { /* current task id 1 - 8 */ uint8_t cur_task_id; /* current lr id index in di_buf */ uint8_t index; /* 698 msg last lr id index in di_buf */ uint8_t last_index_698; /* read time cnt, unit is IOT_SG_STA_EXT_SM_DELAY */ uint8_t timeout_cnt; /* flag of repeat cnt */ uint8_t repeat_cnt : 2, /* flag of response */ flag_resp : 1, /* current state, see IOT_SG_STA_EXT_GW_CLCT_STATE_XXX */ state : 5; /* current 698 freeze msg seq */ uint8_t seq_698_msg; /* current 698 freeze msg pkt */ iot_pkt_t *freeze_698_pkt; /* current collection config */ iot_sg_sta_drv_meter_gw_clct_task_info_t cur_clct_cfg; /* freeze msg report info */ iot_sg_sta_ext_gw_clct_report_info_t report_info; } iot_sg_sta_ext_gw_clct_info_t; /* cache for current power meter edge computing */ typedef struct _iot_sg_sta_ext_ec_cache { /* use 4 bytes of BCD code to represent last total energy value */ uint8_t last_total[PROTO_645_07_ENERGY_DATA_LEN]; /* fault flag */ uint8_t v_fault : 1, /* program enable */ program_en : 1, /* power down frequently */ pd_freq : 1, /* reserved for future */ reserved : 5; /* score bitmaps */ iot_sg_sta_drv_score_bit_map_t bitmap; } iot_sg_sta_ext_ec_cache_t; typedef struct _iot_sg_sta_ext_ec_evt { /* current reported power meter address */ uint8_t addr[IOT_MAC_ADDR_LEN]; /* current upload event message serial number */ uint16_t seq; /* remain event message send count */ uint8_t send_cnt : 3, /* flag if event message in sending */ busy : 1, /* reserved bits */ rsvd : 4; /* current event message overtime, uint is 1s */ uint32_t rpt_tm; } iot_sg_sta_ext_ec_event_t; typedef struct _iot_sg_sta_ext_edge_computing { /* flag if overvoltage function enable */ uint32_t overvoltage_enable : 1, /* flag if undervoltage function enable */ undervoltage_enable : 1, /* flag if health check function enable */ health_enable : 1, /* flag if pulse check function enable */ pulse_check_enable : 1, /* flag of response */ respond : 1, /* current read di index */ index : 4, /* read di timeout count */ timeout : 4, /* count of edge computing dis */ di_cnt : 4, /* count of current package sent */ send_cnt : 3, /* flag if egde computing running */ health_run : 1, /* flag if undervoltage check running */ undervoltage_run : 1, /* flag if overvoltage check running */ overvoltage_run : 1, /* flag module second pulse event happend */ pulse_event : 1, /* flag undervoltage event happend */ undervoltage_event : 1, /* flag overvoltage event happend */ overvoltage_event : 1, /* flag health event happend */ health_event : 1, /* count of pulse exec times */ pulse_count : 3, /* flag if pulse check running */ pulse_run : 1; /* clock second pulse period difference value */ uint32_t pulse_err_value; /* next health check time */ iot_time_tm_t next_health_time; /* next pulse exec time, unit is 1s */ iot_time_tm_t next_pulse_time; /* next overvoltage check time, unit is 1s */ uint32_t next_ov_time; /* next undervoltage check time, unit is 1s */ uint32_t next_uv_time; /* health check complete meter count */ uint8_t health_complete_cnt; /* overvoltage check complete meter count */ uint8_t ov_complete_cnt; /* undervoltage check complete meter count */ uint8_t uv_complete_cnt; /* cache for current power meter edge computing */ iot_sg_sta_ext_ec_cache_t cache; /* event info for health */ iot_sg_sta_ext_ec_event_t health_evt_info; /* event info for overvoltage */ iot_sg_sta_ext_ec_event_t ov_evt_info; /* event info for undervoltage */ iot_sg_sta_ext_ec_event_t uv_evt_info; /* event info for pulse */ iot_sg_sta_ext_ec_event_t pulse_evt_info; } iot_sg_sta_ext_ec_t; /* sta extended neutralwire and livewire current abnormal detect info */ typedef struct _iot_sg_sta_ext_info { /* flag of sta extended function init */ uint8_t ext_init : 1, /* flag of sta extended function disabled */ ext_dis : 1, /* reserved for future */ rsvd : 6; /* timer to drive data extended function */ timer_id_t ext_timer; /* current meter mac */ uint8_t addr[IOT_MAC_ADDR_LEN]; /* current meter data */ iot_sg_sta_ext_meter_data_t meter_data; /* used for internal meter read with 698 protocol */ uint8_t sn_proto_698; /* flag of extend function time reset */ uint8_t flag_tm_reset : 1, /* flag to mark if meter data is frozen data */ frozen_data_flag : 1, /* reserved for future */ reserved : 6; /* sta extended load curve info */ iot_sg_sta_ext_lc_info_t lc_info; /* sta extended load curve collect param */ iot_sg_sta_ext_clct_param clct_param; /* sta current collection task info */ iot_sg_sta_ext_clct_task_info_t task_clct_info; /* state score info */ iot_sg_sta_ext_state_score_t score_info; /* sta current data collection info for jiangsu protocol */ iot_sg_sta_ext_data_clct_info_t data_clct; /* sta current data report info for jiangsu protocol */ iot_sg_sta_ext_clct_rpt_info_t data_rpt; /* freeze task info for fujian protocol, * only support single meter freeze task info */ iot_sg_sta_ext_freeze_task_t *freeze_task_info; /* sta extended load curve info for nw protocol */ iot_sg_sta_ext_lc_info_nw_t lc_info_nw; /* sta extended neutralwire and livewire abnormal detect info, * for xian protocol. */ iot_sg_sta_ext_nli_info_t nli_info; /* sta extend nli event report info, for xian protocol */ iot_sg_sta_ext_nli_evt_rpt_info_t nli_rpt_info; /* sta extend ai management module support, for xian protocol */ iot_sg_sta_ext_ai_module_t *ai_module_info; /* sta current data collection info for gw protocol */ iot_sg_sta_ext_gw_clct_info_t *gw_clct_info; /* edge computing info */ iot_sg_sta_ext_ec_t *ec_info; } iot_sg_sta_ext_info_t; /* power meter score info */ typedef struct _iot_sg_sta_pm_score_info { /* assessment score */ uint8_t score; /* trouble data item, 4 byte to 32 bit. * each bit corresponding to trouble data item. * example: D0 is trouble, set bit0 is 1. */ uint32_t err_bm; /* power meter mac address, little endian */ uint8_t pm_mac[IOT_MAC_ADDR_LEN]; } iot_sg_sta_pm_score_info_t; /* uart check info */ typedef struct _iot_sg_sta_uart_check_info { /* consecutive send cnt */ uint8_t send_cnt; /* once uart state, see 0 mean uart is normal, * 1 mean uart is abnormal */ uint8_t once_uart_state : 1, /* current uart state, see 0 mean uart is normal, * 1 mean uart is abnormal. */ curr_uart_state : 1, /* reserved for future */ reserved : 6; } iot_sg_sta_uart_check_info_t; /* sta state score info */ typedef struct _iot_sg_sta_score_info { /* meter score info count */ uint8_t meter_cnt; /* power meter score info */ iot_sg_sta_pm_score_info_t pm_info[0]; } iot_sg_sta_score_info_t; /* sta correct time record */ typedef struct _iot_sg_sta_ct_record { /* year */ uint16_t year; /* month */ uint8_t mon; /* day */ uint8_t day; } iot_sg_sta_ct_record_t; /* time management info */ typedef struct _iot_sg_sta_tm_info { /* 698 meter correct time mode, see IOT_SG_STA_698_CORR_TIME_MODE_XXX */ uint8_t tm_mode_698; /* cache time */ iot_time_tm_t cache_time; /* the timestamp of get cache time, uint is 1s */ uint32_t cache_time_ts; /* auto correct time flag */ uint8_t auto_flag; /* report time skew flag */ uint8_t rpt_flag; /* delta threshold, uint is 1s */ uint16_t threshold; /* auto correct delay time, uint is 1s */ uint32_t auto_delay; /* report time skew delay time, uint is 1s */ uint32_t rpt_delay; } iot_sg_sta_tm_info_t; /* zero-crossing detection info */ typedef struct iot_sg_sta_zc_check { /* total check time(unit is us) */ uint32_t total_time[IOT_PLC_PHASE_CNT]; /* last gpio trig ticks */ uint32_t pre_tick[IOT_PLC_PHASE_CNT]; /* gpio trig count */ uint8_t trig_cnt[IOT_PLC_PHASE_CNT]; /* gpio zc started flags */ uint8_t started_zc_bm; } iot_sg_sta_zc_check_t; /* cco black list infomation */ typedef struct _iot_sg_sta_cco_black_list_info { /* invalid time count, uint is 1min */ uint32_t invalid_tm_cnt; /* cco addr */ uint8_t addr[IOT_MAC_ADDR_LEN]; } iot_sg_sta_cco_black_list_info_t; /* periodic monitoring data of second pulse signal */ typedef struct _iot_sg_sta_ext_sec_pulse_info { /* callback when MF stop */ iot_sg_sta_ext_mf_sec_pulse_finish_handle callback; /* second start tick value, unit is 1us */ uint32_t start_tick; /* flag the second pulse cycle value is valid identification */ uint8_t complete : 1, /* start ticks valid */ valid : 1, /* reserve */ rsvd : 6; } iot_sg_sta_ext_sec_pulse_info_t; /* pulse signal counting information */ typedef struct _iot_sg_sta_ext_pulse_info { /* remaining execution time, unit is second */ uint32_t remain_time; /* currnt save index */ uint32_t index : 31, /* pulse count start pending waitting for timer */ pending : 1; /* pointer to periodic storage space */ uint32_t *buffer; /* cycle point count max */ uint32_t buffer_cnt; /* callback function when stopped */ iot_sg_sta_ext_mf_pulse_finish_handle callback; } iot_sg_sta_ext_pulse_info_t; /* define multifunctional data structure */ typedef struct _iot_sg_sta_ext_mf_glb { /* gpio number of multifunction signal input */ uint8_t gpio_num; /* is last ticks valid */ uint8_t tick_valid : 1, /* current check mode, @see IOT_SG_STA_EXT_MF_MODE_XXXX */ mode : 3, /* is multifunctional running now */ running : 1, /* reserve */ rsvd : 3; /* count of pulse since startup */ uint32_t pulse_count; /* last gpio interrupt tick value, unit is 1us */ uint32_t last_ticks; /* last gpio rising tick value, unit is 1us */ uint32_t rising_ticks; /* second pulse info or pulse count info */ union { /* cache in IOT_SG_STA_EXT_MF_MODE_PPS_CYCLE mode */ iot_sg_sta_ext_sec_pulse_info_t sec_pulse; /* cache in IOT_SG_STA_EXT_MF_MODE_PULSE_COUNT mode */ iot_sg_sta_ext_pulse_info_t pulse; } info; } iot_sg_sta_ext_mf_glb_t; /* smart grid sta role global descriptor */ typedef struct _iot_sg_sta_global { /* sta app proto type, see IOT_SG_STA_APP_PROTO_XX */ uint8_t proto; /* if the pib's esp is IOT_SG_STA_ESP_AUTO * then this esp is driver detecting value, * see IOT_SG_STA_ESP_XXX */ uint8_t real_esp; /* network sn */ uint8_t network_sn; /* number of sta_out gpio num */ uint8_t sta_out_gpio_num; /* mac address of CCo that STA last joined. */ uint8_t cco_addr[IOT_MAC_ADDR_LEN]; /* driver address type, see IOT_SG_STA_DRV_ADDR_TYPE_XXX */ uint8_t addr_type; /* nid that the STA last joined. */ uint32_t local_nid; /* sta pib handle */ iot_sg_sta_app_pib_t pib; /* state machine */ iot_sg_sta_sm_t sm; /* timer used for device detecting */ timer_id_t detect_timer; /* timer used by driver request */ timer_id_t driver_timer; /* timer used by read tsfm info */ timer_id_t read_tsfm_timer; /* timer used for event report */ timer_id_t event_rpt_timer; /* general timer fired regularly */ timer_id_t refresh_timer; /* timer used for power off event report */ timer_id_t power_off_timer; /* timer used for power on event report */ timer_id_t power_on_timer; /* timer used for sm done event report and check */ timer_id_t sm_evt_chk_timer; /* timer used for collect feature data */ timer_id_t collect_timer; /* timer used for STA-PIN output */ timer_id_t sta_out_timer; /* round count of detect device */ uint32_t detect_round; /* secondary node is in neighbor state query counter, * unit is 1min refresh interval */ uint8_t neighbor_cnt; /* poll time output counter, unit is 1 refresh interval */ uint8_t poll_cnt; /* debug info output counter, unit is 1 poll interval */ uint8_t debug_cnt; /* flag to mark if the address list of power meter have been changed */ uint8_t addr_list_change :1, /** flag to mark if the joined cco is from the same vendor as us for sta */ same_vendor :1, /* flag to mark if sta get into software record state */ soft_record_state:1, /* flag to mark if accur_corr_seq is valid */ flag_accur_valid :1, /* reserved for future */ rsvd0 :4; /* sta software record mode refresh counter, unit is 1s refresh interval */ uint8_t soft_record_cnt; /* last request id of setting address */ uint8_t last_addr_reqid; /* meter time output counter, unit is 1s */ uint32_t time_cnt; /* current driver indext that is detecting the device */ uint8_t detect_idx; /* flag indicate if swc link is ready */ uint8_t swc_link_ready; /* flag of get meter time done */ uint8_t get_time_done :1, /* flag of sta system time, 1 mean time is valid, 0 mean time is invalid */ time_flag :1, /* image crc check result, 0 mean succeed, 1 mean fail */ img_check_result :1, /* flag of image crc check done, 1 mean done */ flag_img_check :1, /* correct time count */ correct_time_cnt :2, /* flag to mark if ever tried to get meter time, 1 - tried, 0 - not tried */ pm_tm_tried :1, /* flag to mark if controller is connected to sta */ ctrl_proto_connected :1; /* sequence of last push data */ uint16_t seq_last_push; /* correct time receive counter, unit is 1 poll interval */ uint16_t sta_time_cnt; /* sequence of lock time command */ uint8_t lock_seq; /* sequence of accurate correcting time command */ uint8_t accur_corr_seq; /* controller transformation sequence number */ uint8_t ctrl_proto_sn; /* module pulled out msg last sequences number */ uint8_t pull_out_last_sn; /* module pulled out msg current sequences number */ uint8_t pull_out_cur_sn; /* pulled out check output counter, unit is 1 refresh interval */ uint8_t pull_out_cnt; /* moudle pulled out check start time stamp, uint is 1ms */ uint32_t pull_out_start_ts; /* sta joined time stamp */ uint64_t joined_ts; /* simple pair passcode value, little endian */ uint16_t passcode; /* module timer source type, default source type is net timer source * according to FJ, see PROTO_645_FJ_MOD_TM_SOC_XXX */ uint8_t tm_soc :1, /* flag to mark if br2 function enable, 0 - disabled, 1 - enable. */ br2_enable :1, /* flag to mark if br2 record init, 0 - uninitialized, 1 - initialized */ br2_record_init :1, /* flag to mark if rtc timer has synchronized with cctt timer, * 1 - sync, 0 - not sync */ rtc_sync_flag :1, /* flag to mark if cco black list update */ cco_bl_update_flag :1, /* flag to mark if Nanwang product testing is run */ nw_pt_detected :1, /* reserved for future */ rsvd :2; /* module correct time duration, unit is 1min */ uint16_t ct_dur; /* time stamp of the last general correct time, unit is 1s */ uint32_t last_gen_ct_ts; /* time stamp of the last ntb correct time, unit is 1s */ uint32_t last_ntb_ct_ts; /* cco black list invalid time, uint is 1min */ uint32_t cco_bl_invalid_time; /* cco black list infomation */ iot_sg_sta_cco_black_list_info_t cco_bl[IOT_SG_STA_BLACK_LIST_MAX_CNT]; /* sta correct time record */ iot_sg_sta_ct_record_t ct_rec; /* current meter time, get the time of meter every 10 minutes*/ iot_sg_sta_drv_time_t meter_time; /* pending request queue */ iot_sg_sta_req_queue_t queue; /* current req */ iot_sg_sta_req_t req; /* meter read info descriptor */ iot_sg_sta_mr_global_t mr; /* event info descriptor */ iot_sg_sta_evt_global_t evt; /* secondary node hash table */ iot_addr_hash_table_h node_table; /* black listed secondary node hash table */ iot_addr_hash_table_h node_bl_table; /* secondary node pointer array */ iot_sg_sta_node_desc_t *node_list[IOT_SG_STA_SEC_NODE_MAX]; /* invalid mac addr entry */ iot_sg_sta_invalid_addr_entry_t invalid_addr_list[IOT_SG_STA_INVALID_ADDR_LIST_SIZE]; /* driver descriptor being used if driver id in persistent storage * is invalid, will dynamically trigger each supported driver to detect * the device connected locally. once a device detected, the corresponding * driver will be used. */ iot_sg_sta_drv_t *drv; /* node register descriptor */ iot_sg_sta_node_reg_global_t node_reg; /* upgrade info */ iot_sg_sta_upgrade_info_t upgrade_info; /* hw tsfm info */ iot_sg_sta_hw_tsfm_t hw_tsfm_info; /* sta roperties info */ iot_sg_sta_properties_global_t node_properties; /* sta flash config info */ iot_sg_sta_flash_cfg_info_t flash_cfg_info; /* sta flash info */ iot_sg_sta_flash_info_t flash_info; /* tsfm status from plc lib */ iot_plc_tsfm_status_rpt_t tsfm_status; /* tsfm collect feature info */ iot_sg_sta_tsfm_collect_info_t tsfm_collect_info; /* sta extended function info */ iot_sg_sta_ext_info_t ext_info; /* sta uart state info */ iot_sg_sta_uart_check_info_t uart_state_info; /* local plc info query */ iot_sg_sta_query_plc_global_t plc_query; /* time management info */ iot_sg_sta_tm_info_t tm_info; /* zero-crossing detection info */ iot_sg_sta_zc_check_t check; /* multifunctional data */ iot_sg_sta_ext_mf_glb_t *mf; } iot_sg_sta_global_t; #if (PLC_SUPPORT_STA_ROLE && IOT_SMART_GRID_ENABLE) /* * iot_sg_sta_init() - init smart grid sta role device specific operation * * return: * 0 - for scuccess case * otherwise - error number */ uint32_t iot_sg_sta_init(); /* * iot_sg_sta_init() - deinit smart grid sta role device specific operation */ void iot_sg_sta_deinit(); /** * @brief: iot_sg_sta_handle_cus_cfg() - handling configuration info from * customer app. * @cfg node: pointer to the parameter to be configured. */ void iot_sg_sta_handle_cus_cfg(iot_sg_ext_cus_cfg_t *cfg); /** * @brief: iot_sg_sta_handle_cus_sync_node_list() - handling synchronize node * list from customer app. * @param node_list: pointer to the node list. */ void iot_sg_sta_handle_cus_sync_node_list( iot_sg_ext_node_list_sync_t *node_list); /** * @brief: iot_sg_sta_report_nli_event() - sta nli event report to CCO. * @param data: nli abnormal info. */ uint32_t iot_sg_sta_report_nli_event(iot_sg_sta_ext_nli_evt_data_field_t *data); #else /* PLC_SUPPORT_STA_ROLE && IOT_SMART_GRID_ENABLE */ #define iot_sg_sta_init() (ERR_NOSUPP) #define iot_sg_sta_deinit() #define iot_sg_sta_handle_cus_cfg(cfg) ((void)cfg) #define iot_sg_sta_handle_cus_sync_node_list(node_list) ((void)node_list) #define iot_sg_sta_report_nli_event(data) (ERR_NOSUPP) #endif /* PLC_SUPPORT_STA_ROLE && IOT_SMART_GRID_ENABLE */ /** * @brief: function callback to allow read tsfm info driver to request * smart grid app to start the read tsfm timer. * @param dur: duration of the timer. the unit is 1 ms. * @retval: 0 - for timer started successfully case * @retval: otherwise - error code */ uint32_t iot_sg_sta_start_read_tsfm_timer(uint32_t dur); /** * @brief: function callback to allow read tsfm infodriver to request * smart grid app to stop the tsfm timer. */ void iot_sg_sta_stop_read_tsfm_timer(); /** * @brief: iot_sg_sta_get_rw_pib - gets the entry position of station in PIB. * @retval: otherwise - the entry position of station in PIB * @retval: NULL - fail. */ iot_sg_sta_app_info_t *iot_sg_sta_get_rw_pib(void); /** * @brief: iot_sg_send_msdu - send a msdu to mac layer. It consumed the msdu_pkt. * @param msdu_pkt: an iot_pkt allocate by iot_plc_alloc_msdu. * @param prefer_link: preferred link type on which to send the msdu, * see IOT_SG_LINK_TYPE_XXX. * @retval: ERR_OK for success case. Other for failed case. */ uint32_t iot_sg_send_msdu(iot_pkt_t* msdu_pkt, uint32_t prefer_link); /** * @brief: check if cached data for the meter read request exist. * @param seq: sequence of the meter read request. * @param src_addr: original source mac address in the meter read request. * @param link_type: link type, see IOT_SG_LINK_TYPE_XXX. * @param mr_type: type of meter read request, IOT_SG_STA_MR_TYPE_XXX. * @retval: ERR_OK -- cache not exist * @retval: ERR_EXIST -- cache exist */ uint32_t iot_sg_sta_mr_cache_check(uint16_t seq, uint8_t *src_addr, uint8_t link_type, uint8_t mr_type); /** * @brief: parse a buffer to abstract mutiple 645 frames from the buffer. * @param data: pointer to the buffer. * @param len: length of buffer data. * @retval: ERR_OK -- parse buffer successfully * @retval: ERR_INVAL -- parse buffer failure */ uint32_t iot_sg_sta_parse_frame(uint8_t *data, uint16_t len); /** * @brief: iot_sg_sta_issue_frame - send an 645 frame to driver. */ uint32_t iot_sg_sta_issue_frame(void); /** * @brief: iot_sg_sta_start_next_app_other - start next request in the queue. */ void iot_sg_sta_start_next_app_other(void); /** * @brief: iot_sg_sta_node_reg_clear_all_obsolete - clear all obsolete node. */ void iot_sg_sta_node_reg_clear_all_obsolete(void); /** * @brief: iot_sg_sta_bitmap_merge - received bitmap merge to local bitmap. * @param bm: received bitmap. * @param first_tei: first tei in received bitmap. * @param length: length of received bitmap. * @param local_bm: local bitmap. */ void iot_sg_sta_bitmap_merge(uint8_t *bm, uint16_t first_tei, uint16_t length, iot_sg_sta_power_off_bm_t *local_bm); /** * @brief: power off pm address info merge to local power off pm address info. * @param pm: pointer to the header of pm info marged. * @param cnt: pm cnt. * @retval: 1 -- merge successfully * @retval: 0 -- merge false */ uint32_t iot_sg_sta_pd_addrs_merge( iot_sg_sta_pd_addrs_info_t *pm, uint16_t cnt); /** * @brief : get sequence number of event report message. * @retval: sequence number. */ uint16_t iot_sg_sta_get_event_rpt_seq(); /** * @brief: check sequence number of event report ack from cco. * @param seq: sequence number of event report ack from cco. * @retval: true -- sequence number is true. * @retval: false -- sequence number is false. */ bool_t iot_sg_sta_check_pm_event_rpt_seq(uint16_t seq); /** * @brief: iot_sg_sta_get_pd_bitmap_info - get sta power off bitmap info * @param bitmap: pointer to bitmap info cache. * @param update: pointer to flag of bitmap update. * @retval: ERR_OK -- get bitmap info successfully. * @retval: ERR_FAIL -- get bitmap info false. */ uint32_t iot_sg_sta_get_pd_bitmap_info( iot_sg_sta_pd_bitmap_desc_t *bitmap, uint8_t *update); /** * @brief: iot_sg_sta_event_ack_handle - handle event ack from cco. * @param fn: function of event ack from cco, see IOT_SG_STA_EVENT_RPT_XXX. * @retval: ERR_OK -- handle successfully * @retval: otherwise -- handle false, see ERR_XXX. */ uint32_t iot_sg_sta_event_ack_handle(uint8_t fn); /** * @brief: check whether sta is power off or not. * @retval: 1 -- sta is power off. * @retval: 0 -- sta isn't power off. */ uint8_t iot_sg_sta_power_off_check(void); /** * @brief: handle meter read request from cco. * this function always consume the pkt. * @param pkt: the iot_pkt with application protocol data in it. * @param hdr: the pointer to header of application protocol data. * @retval: ERR_PENDING and ERR_OK -- handle successfully * @retval: otherwise -- handle false, see ERR_XXX. */ uint32_t iot_sg_sta_meter_read(iot_pkt_t *pkt, uint8_t *hdr); /** * @brief: send get meter time request to driver. */ void iot_sg_sta_start_get_time(); /** * @brief: queue other port request. * this function always consume the pkt. * @param pkt: the iot_pkt with application protocol data in it. * @param link_type: type of low layer link type, see IOT_SG_LINK_TYPE_XXX. * @retval: ERR_OK -- handle success. * @retval: otherwise -- handle false, see ERR_XXX. */ uint32_t iot_sg_sta_queue_app_other(iot_pkt_t *pkt, uint8_t link_type); /** * @brief: handle app protocol for GW_APP_PORT_UPGRADE * this function always consume the pkt. * @param pkt: the iot_pkt with gw upgrade data in it. */ void iot_sg_sta_handle_app_upgrade(iot_pkt_t *pkt); /** * @brief: send a start ack reply to CCo * @param id: upgrading session id * @param msg_type: type for sending the message * @param result: result to the start upgrading command */ void iot_sg_sta_send_start_ack(uint32_t id, uint8_t msg_type, uint32_t result); /** * @brief: send query reply to STA * @param id: upgrading session id * @param start_seq: sn of the 1st block being queried * @param status: STA's upgrading status * @param cnt: number of available block in the bitmap * @param bitmap_pkt: an iot_pkt with bitmap in its data block * @param msg_type: msg_type used to send the reply * @param session_type: query upgrade status session proto type, * see - IOT_SG_STA_UPGRADE_SESSION_TYPE_XXX */ void iot_sg_sta_send_query_reply(uint32_t id, uint32_t start_seq, uint16_t status, uint16_t cnt, iot_pkt_t *bitmap_pkt, uint8_t msg_type, uint8_t session_type); /** * @brief: sta send meter reading response. * @param seq: sequence of meter reading response. * @param mr_type: type of meter reading response, IOT_SG_STA_MR_TYPE_XXX. */ void iot_sg_sta_send_mr_rsp(uint16_t seq, uint8_t mr_type); /** * @brief: start secondary node register. * @param reason: reason of start secondary node register. * see IOT_SG_STA_NODE_REG_REASON_XXX. */ void iot_sg_sta_start_sec_node_reg(uint8_t reason); /** * @brief: stop secondary node register. */ void iot_sg_sta_stop_sec_node_reg(void); /** * @brief: find node by meter mac address. * @param addr: node mac address. * @retval: otherwise -- the entry position of node. * @retval: NULL -- handle false. */ iot_sg_sta_node_desc_t *iot_sg_sta_node_find_by_addr(uint8_t *addr); /** * @brief: handle correct time pkt. * @param pkt: the iot_pkt with DL/T 645 correct * time data in it. function won't free the pkt. * @retval ERR_OK: handle success. * @retval ERR_FAIL: handle false. */ uint32_t iot_sg_sta_correct_time(iot_pkt_t *pkt); /** * @brief: delete request in queue by link_type. * @param link_type: type of low layer link type, see IOT_SG_LINK_TYPE_XXX. */ void iot_sg_sta_queue_app_del_by_type(uint8_t link_type); /** * @brief: delete request in queue by src_id. * @param src_id: id of request read meter source, * see IOT_SG_STA_MR_SRC_ID_XXX. */ void iot_sg_sta_queue_app_del_by_src(uint8_t src_id); /** * @brief: sta add a meter reading request. * @param id: id of request read meter source * @param mac: meter address. * @param seq: sequence of request. * @param proto_type: protocol type in data, * see IOT_SG_STA_DATA_TYPE_XXX. * @param data: meter reading message. * @param len: length of meter reading message. * @param timeout: meter read time out, unit is 100ms. * @retval: ERR_OK -- handle success. * @retval: otherwise -- handle false, see ERR_XXX. */ uint32_t iot_sg_sta_add_mr_req(uint8_t id, uint8_t *mac, uint16_t seq, uint8_t proto_type, uint8_t *data, uint16_t data_len, uint16_t timeout); /** * @brief: sta add a meter correct request. * @param data: meter reading message. * @param len: length of meter reading message. * @retval: ERR_OK -- handle success. * @retval: otherwise -- handle false, see ERR_XXX. */ uint32_t iot_sg_sta_add_corr_req(uint8_t *data, uint16_t data_len); /** * @brief: handle meter reading response. * @param data_type: type of data. * @param data: meter reading response data in it. * @param len: length of response data. */ void iot_sg_sta_handle_mr_resp(uint8_t data_type, uint8_t *data, uint16_t len); /** * @brief: start sta tsfm feature collect timer. * @param dur: duration of the timer. the unit is 1 ms. */ void iot_sg_sta_start_tsfm_feature_collect_timer(uint32_t dur); /** * @brief: stop sta tsfm feature collect timer. */ void iot_sg_sta_stop_tsfm_feature_collect_timer(void); /** * @brief : save time delta and addr into pib. * @param : delta - the time delta between correct time and RTC, unit is 1s. * @param : addr - point to the sta mac addr, big-endian. * @retval: ERR_OK - case successfully. * @retval: otherwise - error code. see ERR_XXX */ uint8_t iot_sg_sta_save_correct_tm_pib(int64_t delta, uint8_t *addr); /** * @brief: check sequence number of power on event report ack from cco. * @param seq: sequence number of event report ack from cco. * @retval: 1 -- sequence number is true. * @retval: 0 -- sequence number is false. */ uint8_t iot_sg_sta_check_power_on_rpt_seq(uint16_t seq); /** * @brief: check sequence number of power off forward ack from cco. * @param seq: sequence number of event forward ack from cco. * @retval: 1 -- sequence number is true. * @retval: 0 -- sequence number is false. */ uint8_t iot_sg_sta_check_power_off_fwd_seq(uint16_t seq); /** * @brief : handle power on event ack. */ void iot_sg_sta_power_on_ack_handle(void); /** * @brief: handle power off forward ack. * @param seq: sequence number of event forward ack from cco. */ void iot_sg_sta_power_off_fwd_ack_handle(uint16_t seq); /** * @brief : stop sm done event report. */ void iot_sg_sta_sm_done_evt_stop(void); /** * @brief: iot_sg_sta_sm_done_evt_check_seq() - check sequence number of sm done * event report ack from cco. * @param seq: sequence number of event report ack from cco. * @retval: 1 -- sequence number is true. * @retval: 0 -- sequence number is false. */ uint8_t iot_sg_sta_sm_done_evt_check_seq(uint16_t seq); /** * @brief: re-enable meter event report to update report config. * note: if event report is not enabled now, then calling this * function will not enable event report. */ void iot_sg_sta_module_report_re_enable(); /** * @brief: meter clock skew event report. * @param new_evt: new event flag. * @param interval: clock skew interval between concentrator and meter. */ void iot_sg_sta_clock_skew_report(uint8_t new_evt, int64_t interval); /** * @brief: sta net lock time save. * @param net_lock_time: net lock time, uint is 1min. 0 means no lock. * @param abn_lock_time: the lock time of abnormal leave net, uint is 1min. * 0 means no lock. */ void iot_sg_sta_lock_time_save(uint16_t net_lock_time, uint16_t abn_lock_time); /** * @brief: sta uart state get. * @retval: uart state, see IOT_SG_STA_UART_STATE_XXX. */ uint8_t iot_sg_sta_uart_state_get(void); /** * @brief: sta node valid check. * @param node: node checked. * @retval: reault. 1 mean node is valid, 0 mean node is invalid; */ uint8_t iot_sg_sta_node_valid_check(iot_sg_sta_node_desc_t *node); /** * @brief: sta modify locked tsfm addr. * @param tsfm_addr: modify locked tsfm addr, big-endian. */ void iot_sg_sta_modify_locked_tsfm_addr(uint8_t *tsfm_addr); /** * @brief: sta enable join certification. * @param join_check: sta join certification state: 0 - disabled, 1 - enable. * other values is invalid. */ void iot_sg_sta_set_join_check_state(uint8_t join_check); /** * @brief: sta search meter event report done. */ void iot_sg_sta_sm_evt_rpt_done(void); /** * @brief: change sta dev type to plc dev type. * @param dev_type: dev type. * @retval: plc dev type; */ uint8_t iot_sg_sta_to_plc_dev_type(uint8_t dev_type); /** * @brief: use current NTB correction time. * @param: old_ntb: old ntb. * @param: iot_ts: time. */ void iot_sg_sta_cur_ntb_correct_ts(uint32_t old_ntb, iot_time_tm_t *iot_ts); /** * @brief: iot_sg_sta_report_event_with_seq - send event message with seq. * @param addr: mac address of the power meter of the event * @param data_ptr: pointer to the event data. * @param len: length size of event data. * @param seq: message sequence. * @retval: ERR_OK - event sent out successfully. * @retval: otherwise - error code. see ERR_XXX */ uint32_t iot_sg_sta_report_event_with_seq(uint8_t *addr, uint8_t *data_ptr, uint32_t len, uint16_t seq); /** * @brief: module report state reset. * @param is_timeout: flag of timeout. */ void iot_sg_module_report_reset_status(uint8_t is_timeout); /** * @brief: report event with report type. * @param addr: mac address of the power meter of the event * @param data_ptr: pointer to the event data. * @param len: length size of event data. * @param new_evt: 0: the event isn't new, 1: the event is new. * @param rpt_type: type of report event, see IOT_SG_STA_RPT_MODULE_XXX * @retval: 0 - event sent out successfully. * @retval: otherwise - error code. see ERR_XXX. */ uint32_t iot_sg_sta_report_event_with_type(uint8_t *addr, uint8_t *data_ptr, uint32_t len, uint8_t new_evt, uint8_t rpt_type); /** * @brief iot_sg_sta_meter_read_done_framework() - function callback to allow * device framework to notify that the meter read operation done. * @param data_type: data type. See GW_APP_DATA_TYPE_XXX * @param rsp_pkt: iot packet of the response. */ void iot_sg_sta_meter_read_done_framework(uint8_t data_type, iot_pkt_t *rsp_pkt); /** * @brief iot_sg_sta_correct_time_compensate() - correct time compensate. * @param cco_ntb: ntb from cco * @param data: pointer to the correct time message. * @param length: length of data. */ void iot_sg_sta_correct_time_compensate( uint32_t cco_ntb, uint8_t *data, uint32_t length); /** * @brief iot_sg_sta_minute_clct_is_enable() - get minute clct enable flag. * @retval: 1 - enable minute clct. * @retval: 0 - disable minute clct. */ uint8_t iot_sg_sta_minute_clct_is_enable(); /** * @brief iot_sg_sta_br2_record_init() - br2 record init. */ void iot_sg_sta_br2_record_init(void); /** * @brief handle msdu msg. * @param pkt: need to handle msdu data pointer. * @param msdu: msdu data pointer. */ void iot_sg_sta_handle_msdu_msg(iot_pkt_t *pkt, iot_plc_msdu_recv_t *msdu); /** * @brief: sta add a meter reading request from customer app. * @param pkt: need to send data pkt * @param seq: sequence of request. * @param proto_type: protocol type in data, * see GW_APP_DATA_TYPE_XXX. * @param timeout: meter read time out, unit is 100ms. * @param flag_head: flag of add a new request after the req list head. * @retval: ERR_OK -- handle success. * @retval: otherwise -- handle false, see ERR_XXX. */ uint32_t iot_sg_sta_add_cus_mr_req(iot_pkt_t *pkt, uint16_t seq, uint8_t proto_type, uint16_t timeout, uint8_t flag_head); /** * @brief: handle meter reading response for customer app. * @param pkt: need to handle meter reading response data pointer. */ void iot_sg_sta_handle_cus_mr_resp(iot_pkt_t *pkt); /** * @brief: handle extend gw collection task data report message send. * @param data: report data. * @param len: length of report data. * @param cnt: dl/t698.45 message cnt in report data. * @param seq: sequence of report data. * @param send_done_func: send done callback function. * @retval: ERR_OK -- handle success. * @retval: otherwise -- handle false, see ERR_XXX. */ uint32_t iot_sg_sta_clct_data_rpt_send(uint8_t *data, uint16_t len, uint8_t cnt, uint16_t seq, iot_pkt_free_func_t send_done_func); /** * @brief report edge computing health event to cco. * * @param addr power meter address. * @param score meter score. * @param bitmap score desc bitmap. */ uint32_t iot_sg_sta_report_ec_health_event( uint8_t *addr, uint8_t score, iot_sg_sta_drv_score_bit_map_t *bitmap); /** * @brief report edge computing overvoltage event to cco. * * @param addr power meter address. * @param is_three_phase is three phase * @param av voltage value of phase-A, format is bin, unit is V * @param bv voltage value of phase-B, format is bin, unit is V * @param cv voltage value of phase-C, format is bin, unit is V */ uint32_t iot_sg_sta_report_ec_overvoltage_event(uint8_t *addr, uint8_t is_three_phase, uint16_t av, uint16_t bv, uint16_t cv); /** * @brief report edge computing undervoltage event to cco. * * @param addr power meter address. * @param is_three_phase is three phase * @param av voltage value of phase-A, format is bin, unit is V * @param bv voltage value of phase-B, format is bin, unit is V * @param cv voltage value of phase-C, format is bin, unit is V */ uint32_t iot_sg_sta_report_ec_undervoltage_event(uint8_t *addr, uint8_t is_three_phase, uint16_t av, uint16_t bv, uint16_t cv); /** * @brief report edge computing second pulse event to cco. * * @param addr power meter address. * @param err_val clock error value compare for 1s, * unit is 1us. */ uint32_t iot_sg_sta_report_ec_second_pulse_event( uint8_t *addr, uint16_t err_val); #ifdef __cplusplus } #endif #endif /* IOT_SG_STA_H */