Files
kunlun/app/smart_grid/inc/iot_sg_sta_drv_api.h

1010 lines
36 KiB
C
Raw Normal View History

2024-09-28 14:24:04 +08:00
/****************************************************************************
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_DRV_H
#define IOT_SG_STA_DRV_H
/* os shim includes */
#include "os_types_api.h"
/* common includes */
#include "iot_rtc_api.h"
#include "iot_pkt_api.h"
#include "iot_uart_api.h"
#include "iot_sg_drv_api.h"
#include "iot_sg_cfg.h"
#include "iot_sg_ext_sta_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/* define driver id */
#define IOT_SG_STA_DRV_ID_INVALID 0x0000
#define IOT_SG_STA_DRV_ID_645_PM 0x0001
#define IOT_SG_STA_DRV_ID_CT1 0x0002
#define IOT_SG_STA_DRV_ID_CT2 0x0003
#define IOT_SG_STA_DRV_ID_TEST 0x0004
#define IOT_SG_STA_DRV_ID_1662_PM 0x0005
#define IOT_SG_STA_DRV_ID_QSXJ_PM 0x0006
#define IOT_SG_STA_DRV_ID_HX_DLMS_PM 0x0007
#define IOT_SG_STA_DRV_ID_WAPPER_PM 0x0008
#define IOT_SG_STA_DRV_ID_IEC_PM 0x0009
#define IOT_SG_STA_DRV_ID_MAX IOT_SG_STA_DRV_ID_IEC_PM
/* define driver load mode */
#define IOT_SG_STA_DRV_LOAD_MODE_STATIC 0x0001
#define IOT_SG_STA_DRV_LOAD_MODE_DYNAMIC 0x0002
/* define maximum number of drivers in the table */
#define IOT_SG_STA_DRV_TABLE_SIZE 9
/* define event report result */
/* event delivered to cco successfully */
#define IOT_SG_STA_EVENT_RPT_OK 0
/* event buffer is full in cco side */
#define IOT_SG_STA_EVENT_RPT_BUF_FULL 1
/* event delivery timeout */
#define IOT_SG_STA_EVENT_RPT_TIMEOUT 2
/* event report disabled */
#define IOT_SG_STA_EVENT_RPT_DISABLED 3
/* event report enabled */
#define IOT_SG_STA_EVENT_RPT_ENABLED 4
/* define protocol data type between sta and meter */
#define IOT_SG_STA_DATA_TYPE_TRANS 0
#define IOT_SG_STA_DATA_TYPE_645_97 1
#define IOT_SG_STA_DATA_TYPE_645_07 2
#define IOT_SG_STA_DATA_TYPE_69845 3
/* define data type mask between sta and meter */
#define IOT_SG_STA_DATA_TYPE_MASK_TRANS (1 << IOT_SG_STA_DATA_TYPE_TRANS)
#define IOT_SG_STA_DATA_TYPE_MASK_645_97 (1 << IOT_SG_STA_DATA_TYPE_645_97)
#define IOT_SG_STA_DATA_TYPE_MASK_645_07 (1 << IOT_SG_STA_DATA_TYPE_645_07)
#define IOT_SG_STA_DATA_TYPE_MASK_69845 (1 << IOT_SG_STA_DATA_TYPE_69845)
/* define device type */
#define IOT_SG_STA_DEV_TYPE_POWER_METER 0
#define IOT_SG_STA_DEV_TYPE_COLLECTOR_T1 1
#define IOT_SG_STA_DEV_TYPE_COLLECTOR_T2 2
#define IOT_SG_STA_DEV_TYPE_COLLECTOR_T3 3
/* define driver address type */
#define IOT_SG_STA_DRV_ADDR_TYPE_DEFAULT 0
#define IOT_SG_STA_DRV_ADDR_TYPE_METER 1
#define IOT_SG_STA_DRV_ADDR_TYPE_COLLECTOR 2
#define IOT_SG_STA_DRV_ADDR_TYPE_REPEATER 3
#define IOT_SG_STA_DRV_ADDR_TYPE_FOLLOW 4
#define IOT_SG_STA_VENDOR_INFO_TYPE_INVALID 0
#define IOT_SG_STA_VENDOR_INFO_TYPE_VERSION 1
/* station transformer detect result */
#define IOT_SG_STA_TSFM_DETECT_RET_UNKNOWN (0)
#define IOT_SG_STA_TSFM_DETECT_RET_SAME (1)
#define IOT_SG_STA_TSFM_DETECT_RET_DIFFERENT (2)
/* define type of app proto, gw */
#define IOT_SG_STA_APP_PROTO_GW 0
/* define type of app proto, nw */
#define IOT_SG_STA_APP_PROTO_NW 1
/* define secondary node register report type */
#define IOT_SG_STA_NODE_RPT_TYPE_NO_EXIST (0)
#define IOT_SG_STA_NODE_RPT_TYPE_EXIST (1)
#define IOT_SG_STA_NODE_RPT_TYPE_UPDATE (2)
/* define secondary node register report type */
#define IOT_SG_STA_PM_INFO_TYPE_UNKNOW (0)
#define IOT_SG_STA_PM_INFO_TYPE_PF_PO (1)
/* define module pull out state unknown */
#define IOT_SG_STA_PO_CHECK_UNKNOWN (0)
/* define module state not pulled out */
#define IOT_SG_STA_PO_CHECK_NO (1)
/* define module state pulled out */
#define IOT_SG_STA_PO_CHECK_YES (2)
/* define drv event type */
#define IOT_SG_STA_NET_STATE_JOINING (0)
#define IOT_SG_STA_NET_STATE_JOINED (1)
#define IOT_SG_STA_NET_STATE_LEAVE (2)
/* define drive upgrade state */
#define IOT_SG_STA_DRV_UPGRADE_STATE_IDLE (0)
#define IOT_SG_STA_DRV_UPGRADE_STATE_START (1)
/* define sta plc comm type */
#define IOT_SG_STA_PLC_COMM_TYPE_HPLC_MODE (0)
#define IOT_SG_STA_PLC_COMM_TYPE_DUAL_MODE (1)
/* define 698 meter correct time mode */
#define IOT_SG_STA_698_CORR_TIME_MODE_NO_RN (0)
#define IOT_SG_STA_698_CORR_TIME_MODE_WITH_RN (1)
/* station device info descriptor */
typedef struct _iot_sg_sta_dev_info {
/* device ID */
uint8_t dev_id[IOT_MAC_ADDR_LEN];
/* reset number */
uint16_t reset_cnt;
} iot_sg_sta_dev_info_t;
/* station plc_state info descriptor */
typedef struct _iot_sg_sta_plc_info {
/* sta mac, big-endian */
uint8_t sta_mac[IOT_MAC_ADDR_LEN];
/* cco mac, big-endian */
uint8_t cco_mac[IOT_MAC_ADDR_LEN];
/* net state, see IOT_SG_STA_NET_STATE_XXX */
uint8_t net_state;
/* snr */
int16_t snr;
/* number of times to join the network */
uint16_t join_cnt;
/* app data forward total count */
uint32_t app_data_fwd_cnt;
} iot_sg_sta_plc_info_t;
/* transformer info result */
typedef struct _iot_sg_sta_tsfm_result {
/* 0 - transformer detect in progress, 1 - transformer detect done */
uint8_t hw_tsfm_done;
/* real transformer mac address, big-endian */
uint8_t hw_tsfm_addr[IOT_MAC_ADDR_LEN];
/* tsfm detect result see - IOT_SG_STA_TSFM_DETECT_RET_XXX */
uint8_t hw_tsfm_result;
/* 0 - transformer detect in progress, 1 - transformer detect done */
uint8_t sw_tsfm_done;
/* real transformer mac address, big-endian */
uint8_t sw_tsfm_addr[IOT_MAC_ADDR_LEN];
/* tsfm detect result see - IOT_SG_STA_TSFM_DETECT_RET_XXX */
uint8_t sw_tsfm_result;
} iot_sg_sta_tsfm_result_t;
typedef struct _iot_sg_sta_drv_time {
uint8_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t mintue;
uint8_t second;
} iot_sg_sta_drv_time_t;
/* query secondary node register payload from cco to sta */
typedef struct _iot_sg_sta_drv_node_info {
/* power meter mac address */
uint8_t pm_addr[IOT_MAC_ADDR_LEN];
/* power meter data type. see IOT_SG_STA_DATA_TYPE_XXX */
uint8_t data_type;
/* module type. see 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 meter support load record */
supp_lr :1,
/* suspected status of the meter, 1 - power off, 0 - power on */
sus_pof :1,
/* flag to mark if node is double protocol */
double_proto :1,
/* reserved for future */
reserved :4;
} iot_sg_sta_drv_node_info_t;
typedef struct _iot_sg_sta_drv_fj_evt_rpt_cfg {
/* 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_drv_fj_evt_rpt_cfg_t;
/* pack for the structures in the whole file */
#pragma pack(push) /* save the pack status */
#pragma pack(1) /* 1 byte align */
/* meter list base element */
typedef struct _iot_sg_sta_drv_meter_info_t {
/* meter address */
uint8_t meter_addr[IOT_MAC_ADDR_LEN];
/* reserved for future, default set as 0 */
uint16_t reserved;
} iot_sg_sta_drv_meter_info_t;
/* sta frame add meter list to driver */
typedef struct _iot_sg_sta_drv_meter_list {
/* meter count */
uint8_t meter_count;
/* reserved for future, default set as 0 */
uint8_t rsvd[3];
/* meter information */
iot_sg_sta_drv_meter_info_t meter_info[0];
} iot_sg_sta_drv_meter_list_t;
/* map list base element */
typedef struct _iot_sg_sta_drv_map_list_info {
/* login address */
uint8_t login_addr[IOT_MAC_ADDR_LEN];
/* meter address */
uint8_t meter_addr[IOT_METER_ADDR_LEN];
} iot_sg_sta_drv_map_list_info_t;
/* sta frame add addr map list to driver */
typedef struct _iot_sg_sta_drv_map_list {
/* map list count */
uint8_t list_count;
/* reserved for future, default set as 0 */
uint8_t rsvd[3];
/* map list information */
iot_sg_sta_drv_map_list_info_t map_info[0];
} iot_sg_sta_drv_map_list_t;
/* IOT_SG_STA_PM_INFO_TYPE_PF_PO data structure */
typedef struct _iot_sg_sta_drv_pf_po_info {
/* power off time, same as event start time
* second defined in last uint32_t
*/
uint32_t pf_year :7,
pf_month :4,
pf_day :5,
pf_hour :5,
pf_min :6,
/* flag to mark if the meter power off has been reported */
pf_rpt :1,
/* flag to mark if the meter received ack after power off reported */
pf_rpt_ok :1,
/* reserved for further use */
rsvd1 :3;
/* power on time, same as event end time
* second defined in last uint32_t
*/
uint32_t po_year :7,
po_month :4,
po_day :5,
po_hour :5,
po_min :6,
/* flag to mark if the meter power on has been reported */
po_rpt :1,
/* flag to mark if the meter received ack after power on reported */
po_rpt_ok :1,
/* reserved for further use */
rsvd2 :3;
/* power off time, second */
uint16_t pf_sec :6,
/* power on time, second */
po_sec :6,
/* suspected status of the meter, 1 - power off, 0 - power on */
status :1,
/* reserved for further use */
rsvd3 :3;
} iot_sg_sta_drv_pf_po_info_t;
#pragma pack(pop) /* restore the pack status */
/* function callback to init driver
* return:
* 0 - success
* otherwise - error code
*/
typedef uint32_t (*iot_sg_sta_drv_init_func_t)();
/* function callback to deinit driver */
typedef void (*iot_sg_sta_drv_deinit_func_t)();
/* function callback to start device detect
* return:
* 0 - success
* otherwise - error code
*/
typedef uint32_t (*iot_sg_sta_drv_start_detect_func_t)();
/* function callback to stop device detect
* return:
* 0 - device detected
* otherwise - error code
*/
typedef uint32_t (*iot_sg_sta_drv_stop_detect_func_t)();
/* function callback to get detected device type
* return:
* device type of detected device. see GW_APP_DEV_TYPE_XXX
*/
typedef uint32_t (*iot_sg_sta_drv_get_device_type_t)();
/* function callback to get device address
* return:
* device address.
*/
typedef void (*iot_sg_sta_drv_get_device_addr_t)(uint8_t *addr);
/* function callback to get the detected mac address used by the driver to login
* return:
* mac address of detected device
*/
typedef void (*iot_sg_sta_drv_get_login_addr_t)(uint8_t *addr);
/* function callback to get login address type
* return:
* type of logic address. see IOT_SG_STA_DRV_ADDR_TYPE_XXX
*/
typedef uint32_t (*iot_sg_sta_drv_get_login_addr_type_t)();
/* function callback to handle meter read request. once the handling is
* finished, driver should call iot_sg_sta_meter_read_done to deliver the
* response back.
* @data_type: data type. See GW_APP_DATA_TYPE_XXX
* @req_pkt: iot packet of the request. the ownership will be transferred
* to driver.
* @time_dur: duration, unit is 1ms.
* @interval: interval, uint is 1ms.
* @baud: baud rate.
*
* return:
* 0 - request handled successfully
* otherwise - error code
*/
typedef uint32_t (*iot_sg_sta_drv_meter_r_func_t)(uint8_t data_type,
iot_pkt_t *req_pkt, uint32_t time_dur, uint32_t interval, uint32_t baud);
/* function callback to cancel current meter read request */
typedef void (*iot_sg_sta_drv_meter_r_cancel_func_t)();
/* function callback to start secondary node register */
typedef void (*iot_sg_sta_drv_start_node_reg_func_t)();
/* function callback to stop secondary node register */
typedef void (*iot_sg_sta_drv_stop_node_reg_func_t)();
/* function callback to notify driver that its detected login address is
* invalidy.
*/
typedef void (*iot_sg_sta_drv_invalid_addr_notify_func_t)();
/* function callback to notify driver that timer fired */
typedef void (*iot_sg_sta_drv_timer_func_t)();
/* function callback to notify driver that refresh timer fired. framework will
* call this function periodically.
* @period: the periodic value of the timer, uint is 1ms.
*/
typedef void (*iot_sg_sta_drv_refresh_timer_func_t)(uint32_t period);
/* function callback to notify driver the received data from UART
* @good_frame: non-zero to mark the packet contain an integrated good frame.
* @pkt: iot packet of the uart data. the ownership will be transferred
* to driver.
*/
typedef void (*iot_sg_sta_drv_uart_func_t)(uint32_t good_frame, iot_pkt_t *pkt);
/* function callback to handle correct time request.
* @pkt: iot packet of the request. the ownership will be transferred
* to driver.
* @is_ntb_corr:0 - not NTB correct time, 1 - is NTB correct time.
* return:
* 0 - request handled successfully
* otherwise - error code
*/
typedef uint32_t (*iot_sg_sta_drv_correct_time_func_t)(iot_pkt_t *pkt,
uint8_t is_ntb_corr);
/* function callback to notify driver to enable events reports function.
*/
typedef void (*iot_sg_sta_drv_enable_event_rpt_func_t)();
/* function callback to notify driver to disable events reports function.
*/
typedef void (*iot_sg_sta_drv_disable_event_rpt_func_t)();
/* function callback to notify driver the event report result
* @result: event report result. See IOT_SG_STA_EVENT_RPT_XXX
*/
typedef void (*iot_sg_sta_drv_event_rpt_ack_func_t)(uint8_t result);
/* function callback to handle communication test request from cco.
* @data_type: data type. See GW_APP_DATA_TYPE_XXX
* @pkt: iot packet of the request. the ownership will be transferred
* to driver.
*/
typedef void (*iot_sg_sta_drv_comm_test_func_t)(uint8_t data_type,
iot_pkt_t *pkt);
/* function callback to handle private action for driver.
* @data: driver private integer data.
* @data_load: driver private pointer type data.
*/
typedef void(*iot_sg_sta_drv_private_func_t)(uint32_t data, void *data_load);
/* function callback to start get node time */
typedef void (*iot_sg_sta_drv_get_time_func_t)();
/* function callback to notice drv checking pm status. */
typedef uint32_t (*iot_sg_sta_drv_pm_check_func_t)(uint8_t *addr,
uint8_t date_type, uint32_t dur, uint8_t delay_flag);
/* function callback to add a list of meter to be searched */
typedef uint32_t (*iot_sg_sta_drv_add_sm_list_func_t)
(iot_sg_sta_drv_meter_list_t *);
/* function callback to add a login addr map list */
typedef uint32_t (*iot_sg_sta_drv_add_map_list_func_t)
(iot_sg_sta_drv_map_list_t *);
/**
* @brief function callback to handle get vendor info request.
* @param info_type: type of vendor info data.
* See IOT_SG_STA_VENDOR_INFO_TYPE_XXX.
* @param data: vendor info data cache.
* @param data_len: vendor info data cache length.
* @param length: length of vendor info data.
* @retval: 0 -- request handled successfully.
* @retval: otherwise -- error code.
*/
typedef uint32_t (*iot_sg_sta_drv_get_vendor_info_t)(uint8_t info_type,
uint8_t *data, uint16_t data_len, uint16_t *length);
/**
* @brief function callback to handle push data request.
* @param pkt: iot packet of the request. the ownership will be transferred
* to driver.
* @param data_type: data type, see IOT_SG_STA_DATA_TYPE_XXX.
* @param baud: uart baud, 0 mean use current uart baud.
* @param addr: address of meter address.
* @param seq: sequence of request.
* @retval: 0 - request handled successfully
* @retval: otherwise - error code
*/
typedef uint32_t (*iot_sg_sta_drv_push_data_func_t)(iot_pkt_t *pkt,
uint8_t data_type, uint32_t baud, uint8_t *addr, uint16_t seq);
/* function callback to get pm information in driver
* @param: addr - address of get pm
* @param: type - type of data, see IOT_SG_STA_PM_INFO_TYPE_XXX
* @param: data - pointer to cache data buffer.
* @param: data_len - length of data buffer
* @retval: ERR_OK - case successfully
* @retval: otherwise - error code, see ERR_XXX
*/
typedef uint32_t (*iot_sg_sta_drv_get_pm_info_t)(
uint8_t *addr, uint8_t data_type, uint8_t *data,
uint16_t data_len);
/* function callback to check module pulled out status */
typedef void (*iot_sg_sta_drv_pull_out_check)();
/* function callback to set the login address.
* @param: addr - login address.
*/
typedef void (*iot_sg_sta_drv_set_login_addr)(uint8_t *addr);
/* function callback to synchronize power meter list */
typedef void (*iot_sg_sta_drv_sync_node_func_t)(
iot_sg_ext_node_list_sync_t *node_list);
/**
* @brief function callback to get driver state count values.
* @param list: Pointer to an integer array that save counts.
* @param cnt: The size of the array.
* @retval: The number of counts get.
*/
typedef uint32_t(*iot_sg_sta_drv_get_state_cnt_func_t)(uint32_t *list,
uint8_t cnt);
/* smart grid sta role driver descriptor */
typedef struct _iot_sg_sta_drv {
/* id of the driver. see IOT_SG_STA_DRV_ID_INVALID */
uint16_t drv_id;
/* id of the driver load mode. see IOT_SG_STA_DRV_LOAD_MODE_XXX */
uint16_t drv_load_mode;
/* driver supported data type mask. see GW_APP_DATA_TYPE_MASK_XXX */
uint16_t data_type_mask;
/* device type. see GW_APP_DEV_TYPE_XXX */
uint8_t dev_type;
/* driver required headroom for each request packet. smart grid app will
* make sure every iot packet delivered to driver has such headroom
* reserved.
*/
uint8_t headroom;
/* Driver detect time required for the device, unit is 1ms */
uint32_t detect_time;
/* driver operation function callbacks */
iot_sg_sta_drv_init_func_t init;
iot_sg_sta_drv_deinit_func_t deinit;
iot_sg_sta_drv_start_detect_func_t start_detect;
iot_sg_sta_drv_stop_detect_func_t stop_detect;
iot_sg_sta_drv_get_device_type_t get_device_type;
iot_sg_sta_drv_get_device_addr_t get_device_addr;
iot_sg_sta_drv_get_login_addr_t get_login_addr;
iot_sg_sta_drv_get_login_addr_type_t get_login_type;
iot_sg_sta_drv_invalid_addr_notify_func_t nodify_invalid_addr;
iot_sg_sta_drv_meter_r_func_t meter_read;
iot_sg_sta_drv_start_node_reg_func_t start_node_reg;
iot_sg_sta_drv_stop_node_reg_func_t stop_node_reg;
iot_sg_sta_drv_correct_time_func_t correct_time;
iot_sg_sta_drv_enable_event_rpt_func_t enable_event_rpt;
iot_sg_sta_drv_disable_event_rpt_func_t disable_event_rpt;
iot_sg_sta_drv_event_rpt_ack_func_t event_rpt_ack;
iot_sg_sta_drv_comm_test_func_t comm_test;
iot_sg_sta_drv_timer_func_t timer_func;
iot_sg_sta_drv_refresh_timer_func_t refresh_timer_func;
iot_sg_sta_drv_uart_func_t uart_func;
iot_sg_sta_drv_private_func_t private_func;
iot_sg_sta_drv_get_time_func_t get_time;
iot_sg_sta_drv_pm_check_func_t pm_check;
iot_sg_sta_drv_add_sm_list_func_t add_sm_list;
iot_sg_sta_drv_add_map_list_func_t add_map_list;
iot_sg_sta_drv_get_vendor_info_t get_vendor_info;
iot_sg_sta_drv_push_data_func_t push_data;
iot_sg_sta_drv_get_pm_info_t get_pm_info;
iot_sg_sta_drv_pull_out_check pull_out_check;
iot_sg_sta_drv_set_login_addr set_login_addr;
iot_sg_sta_drv_sync_node_func_t sync_node_func;
iot_sg_sta_drv_get_state_cnt_func_t get_state_cnt;
} iot_sg_sta_drv_t;
extern iot_sg_sta_drv_t *g_sta_drv_table[IOT_SG_STA_DRV_TABLE_SIZE];
/* @brief iot_sg_sta_meter_read_done() - function callback to allow device
* driver to notify that the meter read
* operation done.
* @paam data_type: data type. See GW_APP_DATA_TYPE_XXX
* @param rsp_pkt: iot packet of the response, the ownership of the pkt will
* be transferred from driver to smart grid app.
* if rsp_pkt == NULL, means driver meter read timeout.
*/
void iot_sg_sta_meter_read_done(uint8_t data_type, iot_pkt_t *rsp_pkt);
/* iot_sg_sta_drv_detect_done - function callback to allow device driver to
* notify that the detect operation done.
*/
void iot_sg_sta_drv_detect_done(void);
/**
* @brief iot_sg_sta_get_time_done() - function callback to allow device
* driver to notify that the get meter
* time operation done.
* @param time: time of the response, point to time of meter.
* if time == NULL, means driver get time failed.
*/
void iot_sg_sta_get_time_done(iot_sg_sta_drv_time_t *time_t);
/* iot_sg_sta_drv_private_call_req - function callback to allow device driver to
* request framework to call its private
* interface in framework thread context.
* Sometimes, driver may receive input in
* context other than framework thread context.
* While most of driver operations like meter
* reading are handled inside the framework
* thread context. To serialize multiple
* driver operations in the framework
* thread context, driver can call this API.
* framework will call driver's private
* function callback later in framework thread
* context.
* @data: driver private integer data.
* @pkt: iot packet for loading driver private data.
*/
void iot_sg_sta_drv_private_call_req(uint32_t data, iot_pkt_t *pkt);
/**
* @brief iot_sg_sta_drv_private_call_req_cancel - function callback to allow
* device driver to request
* framework to cancel its
* pending private call request
* if any.
*/
void iot_sg_sta_drv_private_call_req_cancel(void);
/* @brief function callback to allow device driver to report secondary
* node register event.
* @param node_info: secondary node info
* @param rpt_type: report type, see IOT_SG_STA_NODE_RPT_TYPE_XXX.
*/
void iot_sg_sta_node_reg_report(iot_sg_sta_drv_node_info_t *node_info,
uint8_t rpt_type);
/**
* @brief function callback to allow device driver to deregister secondary
* node info.
* @param addr: pointer to addr of secondary node.
*/
void iot_sg_sta_node_reg_deregister(uint8_t *addr);
/**
* @brief function callback to allow device driver to deregister
* all secondary node info.
*/
void iot_sg_sta_node_reg_deregister_all(void);
/* @brief function callback to allow device driver to check if a node is
* being black listed
* @param addr: mac address of the node to be checked.
*
* @return
* 0 - not black listed
* otherwise - black listed
*/
uint32_t iot_sg_sta_is_bl_node(uint8_t *addr);
/* @brief function callback to allow device driver to add a node into black
* list.
* @param addr: mac address of the node to be black listed.
* @param dur: time out value to remove the node from black list. unit is 1s.
*/
void iot_sg_sta_bl_node_add(uint8_t *addr, uint32_t dur);
/**
* @brief function callback to allow device driver to remove node from black
* list.
* @param addr: pointer to addr of secondary node.
*/
void iot_sg_sta_bl_node_rm(uint8_t *addr);
/**
* @brief function callback to allow device driver to remove all nodes from
* black list.
*/
void iot_sg_sta_bl_node_rm_all(void);
/* iot_sg_sta_node_reg_done - function callback to allow device driver to
* notify that the secondary node register done.
*/
void iot_sg_sta_node_reg_done();
/* iot_sg_sta_report_event - function callback to allow device driver to
* deliver event to cco.
* @addr: mac address of the power meter of the event
* @data_ptr: pointer to the event data.
* @len: length size of event data.
* @new_evt 0: the event isn't new, 1: the event is new.
* return:
* 0 - event sent out successfully. smart grid app will deliver
* the final result to driver through event_rpt_ack callback.
* otherwise - error code. see ERR_XXX
*/
uint32_t iot_sg_sta_report_event(uint8_t *addr, uint8_t *data_ptr,
uint32_t len, uint8_t new_evt);
/* iot_sg_sta_start_driver_timer - function callback to allow device driver to
* request smart grid app to start the driver
* timer. once timer fired, smart grid app will
* call iot_sg_sta_drv_timer_func_t to notify
* driver.
* @dur: duration of the timer. the unit is 1 ms.
*
* return:
* 0 - for timer started successfully case
* otherwise - error code
*/
uint32_t iot_sg_sta_start_driver_timer(uint32_t dur);
/* iot_sg_sta_stop_driver_timer - function callback to allow device driver to
* request smart grid app to stop the driver
* timer.
*/
void iot_sg_sta_stop_driver_timer();
/* iot_sg_sta_send_uart - function callback to allow device driver to
* request smart grid app to send data through
* uart.
* @pkt: iot packet to be sent to the uart. the ownership will
* be transferred from device driver to smart grid app.
*
* return:
* 0 - for success case
* otherwise - error code
*/
uint32_t iot_sg_sta_send_uart(iot_pkt_t *pkt);
/**
* @brief iot_sg_sta_drv_config_uart - function callback to allow device driver to
* request smart grid app to config uart parameters.
* @param baud: baudrate
* @param parity: see IOT_UART_PARITY_XXX
* @param data: data bits
* @param stop: stop flag
* @param fmt: preferred rx frame format
* @param thrd: rx timeout, unit is byte
* @retval: 0 - for success case
* @retval: otherwise - error code
*/
uint32_t iot_sg_sta_config_uart(uint32_t baud, uint8_t parity,
uint8_t data, uint8_t stop, iot_frame_fmt *fmt, uint32_t thrd);
/**
* @brief iot_sg_sta_get_cmn_cfg - function callback to allow device driver to
* get common configuration info.
* @retval: NULL -- fail.
* @retval: otherwise -- pointer to common config info.
*/
iot_sg_sta_cmn_cfg_t *iot_sg_sta_get_cmn_cfg(void);
/**
* @brief iot_sg_sta_get_drv_pib - function callback to allow device driver to
* get the entry position of station driver in
* PIB.
* @param drv_pib_size: returns the size of the PIB space for the station
* driver, if success.
* @retval: NULL -- fail.
* @retval: otherwise -- entry position of station driver in PIB.
*/
uint8_t *iot_sg_sta_get_drv_pib(uint32_t *drv_pib_size);
/**
* @brief iot_sg_sta_get_dev_info - function callback to allow device driver to
* get the station device info.
* @param dev_info: returns station device info.
*/
void iot_sg_sta_get_dev_info(iot_sg_sta_dev_info_t *dev_info);
/**
* @brief iot_sg_sta_get_plc_info - function callback to allow device driver to
* get the station plc info.
* @param plc_info: returns station plc info.
*/
void iot_sg_sta_get_plc_info(iot_sg_sta_plc_info_t *plc_info);
/**
* @brief iot_sg_sta_get_fj_evt_cfg_info - function callback to allow device
* driver to get the station event info.
* @param plc_info: returns station event info.
*/
void iot_sg_sta_get_fj_evt_cfg_info(iot_sg_sta_drv_fj_evt_rpt_cfg_t *evt_cfg);
/**
* @brief iot_sg_sta_pd_check_done - function callback to allow device driver to
* notify that check pm power off status done.
* @param exist: exist is 1, not exist is 0.
* @param addr: pointer to address of pm checked.
*/
void iot_sg_sta_pd_check_done(uint8_t exist, uint8_t *addr);
/**
* @brief iot_sg_sta_power_on_check_done - function callback to allow device
* driver to notify that power on check completed.
*/
void iot_sg_sta_power_on_check_done();
/**
* @brief: iot_sg_node_reg_get_node_cnt - get node cnt.
* @retval: node cnt.
*/
uint8_t iot_sg_node_reg_get_node_cnt(void);
/**
* @brief iot_sg_sta_645_proto_to_drv - convert DT/L 645 protocol id to drv
* data type.
* @param p_id: id of DT/L 645 protocol, see PROTO_645_XXX_ID.
* @retval: drv data type, see IOT_SG_STA_DATA_TYPE_XXX.
*/
uint8_t iot_sg_sta_645_proto_to_drv(uint8_t p_id);
/**
* @brief iot_sg_sta_645_proto_to_drv - convert drv data type to DT/L 645
* protocol id.
* @param type: drv data type, see IOT_SG_STA_DATA_TYPE_XXX.
* @retval: id of DT/L 645 protocol, see PROTO_645_XXX_ID.
*/
uint8_t iot_sg_sta_drv_to_645_proto(uint8_t type);
/**
* @brief: check if current device is 3 phase power meter.
* @retval: 0 - module type is not three-phase.
* @retval: 1 - module type is three-phase.
*/
uint8_t iot_sg_sta_is_3p_module(void);
/**
* @brief: get current plc protocol type.
* @retval: plc protocol type - see IOT_SG_STA_APP_PROTO_XXX.
*/
uint8_t iot_sg_sta_get_proto_type(void);
/**
* @brief: check current command whether read sidle meter.
*
* @param data_type data type, @see IOT_SG_STA_DATA_TYPE_XXX
* @return 1 mean read sidle meter, 0 mean not read sidle meter.
*/
uint8_t iot_sg_sta_is_sidle_meter_read(uint8_t data_type);
/**
* @brief: get current user type.
* @retval: user type - see IOT_SG_STA_FLASH_STORAGE_MODE_XXX.
*/
uint8_t iot_sg_sta_get_user_type(void);
/**
* @brief: get flag to mark if cert test command ever detected.
* @retval: 1 mean detected, 0 mean no detected.
*/
uint8_t iot_sg_sta_get_cert_test_detected(void);
/**
* @brief: get flag to mark if Nanwang product testing is detected.
* @retval: 1 mean detected, 0 mean no detected.
*/
uint8_t iot_sg_sta_get_nw_pt_detected(void);
/**
* @brief: get tsfm result info.
* @param tsfm_info: returns station tsfm result info.
*/
void iot_sg_sta_get_tsfm_result(iot_sg_sta_tsfm_result_t *tsfm_result);
/**
* @brief: check phase event report flag.
* @retval: flag of phase event report flag.
* 1 mean enable, 0 mean disable.
*/
uint8_t iot_sg_sta_phase_rpt_enable_check(void);
/**
* @brief iot_sg_sta_set_hw_tsfm_addr() - set hardware tsfm addr.
* @param addr: addr to be set, little-endian.
*/
void iot_sg_sta_set_hw_tsfm_addr(uint8_t *addr);
/**
* @brief: start secondary node register.
*/
void iot_sg_sta_drv_start_sec_node_reg(void);
/**
* @brief: iot_sg_sta_pull_out_check_done() - module pulled out check done.
* @param result: check result, see IOT_SG_STA_PO_CHECK_XXX.
*/
void iot_sg_sta_pull_out_check_done(uint8_t result);
/**
* @brief: meter found in all A search meter stages.
*/
void iot_sg_sta_all_aa_sm_done(void);
/**
* @brief: start get meter time.
*/
void iot_sg_sta_drv_start_get_time();
/**
* @brief app sta rtc time set.
* @param tm: pointer to the time cache.
* @param sys_flag: flag of system time.
* @retval: ERR_OK - set rtc time successfully.
* @retval: otherwise - error code. see ERR_XXX
*/
void iot_sg_sta_rtc_set(iot_time_tm_t *tm, uint8_t sys_flag);
/**
* @brief app sta rtc time get.
* @param tm: pointer to the time cache.
* @param sys_flag: flag of system time.
* @retval: ERR_OK - get rtc time successfully.
* @retval: otherwise - error code. see ERR_XXX
*/
uint32_t iot_sg_sta_rtc_get(iot_time_tm_t *tm, uint8_t sys_flag);
/**
* @brief app sta rtc time valid check.
* @param sys_flag: pointer to the flag of system time cache.
* @retval: ERR_OK - rtc time valid.
* @retval: otherwise - error code. see ERR_XXX
*/
uint32_t iot_sg_sta_rtc_valid_check(uint8_t sys_flag);
/**
* @brief Clear rtc time flags.
* @param sys_flag: pointer to the flag of system time cache.
*/
void iot_sg_sta_rtc_clear(uint8_t sys_flag);
/**
* @brief app sta get meter time by rtc time.
* @param tm: pointer to the time cache.
* @param sys_flag: flag of system time.
* @retval: ERR_OK - get rtc time successfully.
* @retval: otherwise - error code. see ERR_XXX
*/
uint32_t iot_sg_sta_rtc_get_m_t(iot_time_tm_t *tm);
/**
* @brief cco black list invalid time set.
* @param time: invalid time, uint is 1min.
*/
void iot_sg_sta_cco_bl_invalid_time_set(uint32_t time);
/**
* @brief app sta node address valid check.
* @param addr: pointer to address.
* @retval: ERR_OK - address valid.
* @retval: otherwise - error code. see ERR_XXX
*/
uint8_t iot_sg_sta_node_addr_check(uint8_t *addr);
/**
* @brief drive upgrade state set.
* @param state: upgrade state, see IOT_SG_STA_DRV_UPGRADE_STATE_XXX.
*/
void iot_sg_sta_drv_upgrade_state_set(uint8_t state);
/**
* @brief 21 meter module mac get.
* @param mac: module mac.
*/
void iot_sg_sta_21meter_mode_mac_get(uint8_t *mac);
/**
* @brief: get physic link type.
* @return: see IOT_SG_STA_PLC_COMM_TYPE_XXX_MODE.
*/
uint8_t iot_sg_sta_get_phy_type();
/**
* @brief: cco black address list get.
* @param addr_buff: pointer to address buffer.
* @param buff_cnt: address buffer count.
* @return: cco black list address count.
*/
uint8_t iot_sg_sta_cco_bl_list_get(uint8_t *addr_buff, uint8_t buff_cnt);
/**
* @brief: cco black address list set.
* @param addr_buff: pointer to address buffer.
* @param buff_cnt: address buffer count.
*/
void iot_sg_sta_cco_bl_list_set(uint8_t *addr_buff, uint8_t buff_cnt);
/**
* @brief: cco black address list update flag get.
* @return: cco black address list update flag.
*/
uint8_t iot_sg_sta_cco_bl_update_flag_get();
/**
* @brief: cco black address list update flag clean;
*/
void iot_sg_sta_cco_bl_update_flag_clean();
/**
* @brief: repeater follow address set.
* @param flw_addr: pointer to follow address buffer.
*/
void iot_sg_sta_repeater_flw_addr_set(uint8_t *flw_addr);
/**
* @brief: nw new meter check.
* @retval: 1 - meter is nw new meter.
* @retval: 0 - meter isn't nw new meter.
*/
uint8_t iot_sg_sta_nw_new_meter_check();
#ifdef __cplusplus
}
#endif
#endif /* IOT_SG_STA_DRV_H */