435 lines
17 KiB
C
435 lines
17 KiB
C
/****************************************************************************
|
|
|
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
|
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
be copied by any method or incorporated into another program without
|
|
the express written consent of Aerospace C.Power. This Information or any portion
|
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
liability for its use in any way and conveys no license or title under
|
|
any patent or copyright and makes no representation or warranty that this
|
|
Information is free from patent or copyright infringement.
|
|
|
|
****************************************************************************/
|
|
#ifndef IOT_SG_CCO_BUF_H
|
|
#define IOT_SG_CCO_BUF_H
|
|
|
|
/* iot common includes */
|
|
#include "iot_errno_api.h"
|
|
|
|
/* os shim includes */
|
|
#include "os_types_api.h"
|
|
|
|
/* smart grid internal header files */
|
|
#include "iot_sg_fr.h"
|
|
#include "iot_cco_buf.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* max sn count of one meter reading pkg */
|
|
#define IOT_SG_CCO_GW_SN_MAX_CNT (10)
|
|
|
|
/* command sender */
|
|
#define IOT_SG_CCO_CMD_SENDER_DRV (0)
|
|
#define IOT_SG_CCO_CMD_SENDER_INTERN_BR (1)
|
|
#define IOT_SG_CCO_CMD_SENDER_INTERN_TSFM (2)
|
|
#define IOT_SG_CCO_CMD_SENDER_PREDICT_MR (3)
|
|
#define IOT_SG_CCO_CMD_SENDER_INTERN_PW_TSFM (4)
|
|
|
|
/* sg read meter down link data */
|
|
typedef struct _iot_buf_read_meter_cmd {
|
|
/* sn of the meter reading command */
|
|
uint32_t sn_cmd[IOT_SG_CCO_GW_SN_MAX_CNT];
|
|
/* sn of cctt command */
|
|
uint16_t sn_cctt;
|
|
/* afn of the meter reading cmd */
|
|
uint8_t afn;
|
|
/* proto type of meter reading data */
|
|
uint8_t proto_type;
|
|
/* meter reading type, see IOT_SG_RMT_XXX */
|
|
uint8_t mr_type;
|
|
/* src mac address of the meter read command */
|
|
uint8_t src_mac[IOT_MAC_ADDR_LEN];
|
|
/* dest mac address of the meter read command */
|
|
uint8_t dest_mac[IOT_MAC_ADDR_LEN];
|
|
/* bcast or unicast, see IOT_PLC_MSG_TYPE_XXX. */
|
|
uint8_t plc_msg_type;
|
|
/* cli type or cctt type */
|
|
uint8_t intf_type :6,
|
|
/* if need to forward data */
|
|
forward :1,
|
|
/* if need reply */
|
|
need_reply :1;
|
|
/* if increase sn when retry the meter reading pkt */
|
|
uint8_t sn_inc_flag :1,
|
|
/* task priority */
|
|
prio :4,
|
|
/* command sender, IOT_SG_CCO_CMD_SENDER_XXX */
|
|
sender :3;
|
|
/* task id */
|
|
uint16_t task_id;
|
|
/* timeout value of this task, uint: s, cctt shall delete the task when
|
|
* timeout.
|
|
*/
|
|
uint16_t timeout;
|
|
/* timestamp when receive this command.
|
|
* it's the time since system boot up. unit is 1ms.
|
|
*/
|
|
uint32_t recv_ts;
|
|
}iot_buf_read_meter_cmd_t;
|
|
|
|
/* sg extension task down link data */
|
|
typedef struct _iot_buf_ext_task_cmd {
|
|
/* bcast or unicast, see IOT_PLC_MSG_TYPE_XXX. */
|
|
uint8_t plc_msg_type;
|
|
/* cli type or cctt type */
|
|
uint8_t intf_type;
|
|
/* task priority */
|
|
uint8_t prio :4,
|
|
/* command sender, IOT_SG_CCO_CMD_SENDER_XXX */
|
|
sender :4;
|
|
/* extension task type, see IOT_SG_CCO_EXT_TASK_TYPE_XXX */
|
|
uint8_t ext_task_type;
|
|
/* sn of cctt command */
|
|
uint16_t sn_cctt;
|
|
/* timeout value of this task, uint: s, cctt shall delete the task when
|
|
* timeout.
|
|
*/
|
|
uint16_t timeout;
|
|
/* task id */
|
|
uint32_t task_id;
|
|
/* sn of the app command */
|
|
uint32_t sn_cmd;
|
|
/* timestamp when receive this command.
|
|
* it's the time since system boot up. unit is 1ms.
|
|
*/
|
|
uint32_t recv_ts;
|
|
/* src mac address of the meter read command */
|
|
uint8_t src_mac[IOT_MAC_ADDR_LEN];
|
|
/* dest mac address of the meter read command */
|
|
uint8_t dest_mac[IOT_MAC_ADDR_LEN];
|
|
} iot_buf_ext_task_cmd_t;
|
|
|
|
/* sg read meter up link data */
|
|
typedef struct _iot_buf_meter_data {
|
|
/* sn of cctt command */
|
|
uint16_t sn;
|
|
/* afn of the command */
|
|
uint8_t afn;
|
|
/* proto type of meter reading data */
|
|
uint8_t proto_type;
|
|
/* meter reading type, see IOT_SG_RMT_XXX */
|
|
uint8_t mr_type;
|
|
/* src mac address of the meter read data */
|
|
uint8_t src_mac[IOT_MAC_ADDR_LEN];
|
|
/* dest mac address of the meter read data */
|
|
uint8_t dest_mac[IOT_MAC_ADDR_LEN];
|
|
/* bcast or unicast, see IOT_PLC_MSG_TYPE_XXX. */
|
|
uint8_t plc_msg_type;
|
|
/* cli type or cctt type */
|
|
uint8_t intf_type;
|
|
/* spg task id */
|
|
uint16_t task_id;
|
|
/* timeout value of this task, uint: s, cctt shall delete the task when
|
|
* timeout.
|
|
*/
|
|
uint16_t timeout;
|
|
/* flag to mark if read meter result, see IOT_SG_CCO_MR_xxx */
|
|
uint8_t mr_result;
|
|
/* time cost in plc for meter reading. unit is 1ms.
|
|
* start from adding read command to dl buf,
|
|
* end when meter data added to ul buf.
|
|
*/
|
|
uint32_t plc_cost;
|
|
}iot_buf_meter_data_t;
|
|
|
|
/* sg extension task up link data */
|
|
typedef struct _iot_buf_ext_task_data {
|
|
/* src mac address of the meter read data */
|
|
uint8_t src_mac[IOT_MAC_ADDR_LEN];
|
|
/* dest mac address of the meter read data */
|
|
uint8_t dest_mac[IOT_MAC_ADDR_LEN];
|
|
/* bcast or unicast, see IOT_PLC_MSG_TYPE_XXX. */
|
|
uint8_t plc_msg_type;
|
|
/* cli type or cctt type */
|
|
uint8_t intf_type;
|
|
/* extension task result, see IOT_SG_CCO_EXT_TASK_XXX */
|
|
uint8_t ext_result;
|
|
/* extension task type, see IOT_SG_CCO_EXT_TASK_TYPE_XXX */
|
|
uint8_t ext_task_type;
|
|
/* timeout value of this task, uint: s, cctt shall delete the task when
|
|
* timeout.
|
|
*/
|
|
uint16_t timeout;
|
|
/* sn of cctt command */
|
|
uint16_t sn;
|
|
/* spg task id */
|
|
uint32_t task_id;
|
|
/* time cost in plc for collect task. unit is 1ms.
|
|
* start from adding read command to dl buf,
|
|
* end when meter data added to ul buf.
|
|
*/
|
|
uint32_t plc_cost;
|
|
} iot_buf_ext_task_data_t;
|
|
|
|
/* sg event report data - up link data */
|
|
typedef struct _iot_buf_evt_data {
|
|
/* used for report data to cctt */
|
|
uint16_t sn;
|
|
/* device type, see IOT_SG_CCO_DEV_TYPE_XXX */
|
|
uint8_t dev_type;
|
|
/* protocol type */
|
|
uint8_t proto_type;
|
|
/* event type, see IOT_SG_CCO_EVENT_XXX */
|
|
uint8_t evt_type;
|
|
/* meter addr of event */
|
|
uint8_t pm_addr[IOT_MAC_ADDR_LEN];
|
|
}iot_buf_evt_data_t;
|
|
|
|
/* sg sec node info report data - up link data */
|
|
typedef struct _iot_buf_sec_node_data {
|
|
/* used for report data to cctt */
|
|
uint16_t sn;
|
|
uint16_t index;
|
|
/* cli type or cctt type */
|
|
uint8_t intf_type;
|
|
} iot_buf_sec_node_data_t;
|
|
|
|
/* sg state changed event - up link data */
|
|
typedef struct _iot_buf_state_chg_data {
|
|
/* used for report data to cctt */
|
|
uint16_t sn;
|
|
/* afn of the command */
|
|
uint8_t state;
|
|
/* caller, see IOT_SG_CALLER_TYPE_XXX */
|
|
uint8_t intf_type;
|
|
}iot_buf_state_chg_data_t;
|
|
|
|
/* sg sec node state changed event - up link data */
|
|
typedef struct _iot_buf_node_state_chg_data {
|
|
/* used for report data to cctt */
|
|
uint16_t sn;
|
|
}iot_buf_node_state_chg_data_t;
|
|
|
|
/* define this data struct for retrieving max ul data length.
|
|
* all ul buf entry type shall be added here.
|
|
*/
|
|
typedef union _iot_sg_ul_data {
|
|
iot_buf_meter_data_t meter_data;
|
|
iot_buf_evt_data_t event_data;
|
|
iot_buf_state_chg_data_t state_changed_rpt;
|
|
}iot_sg_ul_data_t;
|
|
|
|
/**
|
|
* @brief add meter reading cmd as an entry into iot_buf_pool.
|
|
* @param buf: the iot_buf_pool to cache data
|
|
* @param mr_type: meter reading type, see IOT_SG_RMT_XXX.
|
|
* @param sn: sequence number of the entry
|
|
* @param afn: afn of the entry
|
|
* @param proto_type: proto type of the meter reading command
|
|
* @param src_addr: src mac addr of the meter read command
|
|
* @param dest_addr: dest mac addr of the meter read command
|
|
* @param pkt: iot_pkt containing data
|
|
* @param intf_type: cctt type or cli type
|
|
* @param prio: priority of the task.
|
|
* @param timeout: timeout value of this task. cctt shall delete the task
|
|
* @param need_reply: flag to mark if need reply the task command.
|
|
* @param task_id: task id.
|
|
* @param sn_inc_flag: if increase sn when retry the meter reading pkt,
|
|
* 0 - sn don't inc, 1 - sn inc.
|
|
* @param sender: sender type, see IOT_SG_CCO_CMD_SENDER_XXX
|
|
* @param emergency: emergency flag
|
|
* @param forward: data forward flag
|
|
* @retval: ERR_OK for success case. Other value for failed case.
|
|
*/
|
|
uint32_t iot_sg_buf_pool_add_mr_cmd(iot_buf_pool_t *buf, uint8_t mr_type,
|
|
uint16_t sn, uint8_t afn, uint8_t proto_type, uint8_t *src_addr,
|
|
uint8_t *dest_addr, iot_pkt_t *pkt, uint8_t intf_type, uint8_t prio,
|
|
uint16_t timeout, uint8_t need_reply, uint16_t task_id,
|
|
uint8_t sn_inc_flag, uint8_t sender, uint8_t emergency, uint8_t forward);
|
|
|
|
/**
|
|
* @brief add extension task cmd as an entry into iot_buf_pool.
|
|
* @param buf: the iot_buf_pool to cache data
|
|
* @param ext_task_type: extension task type,
|
|
* see IOT_SG_CCO_EXT_TASK_TYPE_XXX.
|
|
* @param sn: sequence number of the entry
|
|
* @param src_addr: src mac addr of the meter read command
|
|
* @param dest_addr: dest mac addr of the meter read command
|
|
* @param pkt: iot_pkt containing data
|
|
* @param intf_type: cctt type or cli type
|
|
* @param prio: priority of the task.
|
|
* @param timeout: timeout value of this task. cctt shall delete the task
|
|
* @param task_id: task id.
|
|
* @param sender: sender type, see IOT_SG_CCO_CMD_SENDER_XXX
|
|
* @retval: ERR_OK for success case. Other value for failed case.
|
|
*/
|
|
uint32_t iot_sg_buf_pool_add_ext_task_cmd(iot_buf_pool_t *buf,
|
|
uint8_t ext_task_type, uint16_t sn, uint8_t *src_addr, uint8_t *dest_addr,
|
|
iot_pkt_t *pkt, uint8_t intf_type, uint8_t prio, uint16_t timeout,
|
|
uint32_t task_id, uint8_t sender);
|
|
|
|
/**
|
|
* @brief add empty meter data as an entry into iot_buf_pool.
|
|
* @param buf: the iot_buf_pool to cache data.
|
|
* @param prio: priority of the entry in buf_pool.
|
|
* @param read_cmd: the meter reading command.
|
|
* @return: ERR_OK for success case. Other value for failed case.
|
|
*/
|
|
uint32_t iot_sg_buf_pool_add_null_mr_data(iot_buf_pool_t *buf, uint8_t prio,
|
|
iot_buf_read_meter_cmd_t *read_cmd);
|
|
|
|
/**
|
|
* @brief add meter data as an entry into iot_buf_pool.
|
|
* @param buf: the iot_buf_pool to cache data.
|
|
* @param prio: priority of the entry in buf_pool.
|
|
* @param cmd_entry: entry of the meter reading command.
|
|
* @param pkt: iot_pkt containing data.
|
|
* @param mr_result: read meter result, see IOT_SG_CCO_MR_xxx.
|
|
* @return: ERR_OK for success case. Other value for failed case.
|
|
*/
|
|
uint32_t iot_sg_buf_pool_add_mr_data(iot_buf_pool_t *buf, uint8_t prio,
|
|
iot_buf_pool_entry_t *cmd_entry, iot_pkt_t *pkt, uint8_t mr_result);
|
|
|
|
/**
|
|
* @brief add extension task data as an entry into iot_buf_pool.
|
|
* @param buf: the iot_buf_pool to cache data.
|
|
* @param prio: priority of the entry in buf_pool.
|
|
* @param cmd_entry: entry of the extension task command.
|
|
* @param pkt: iot_pkt containing data.
|
|
* @param ext_result: extension task result, see IOT_SG_CCO_EXT_TASK_XXX.
|
|
* @param invalid_sn: flag to mark if the task sn is invalid.
|
|
* @return: ERR_OK for success case. Other value for failed case.
|
|
*/
|
|
uint32_t iot_sg_buf_pool_add_ext_task_data(iot_buf_pool_t *buf, uint8_t prio,
|
|
iot_buf_pool_entry_t *cmd_entry, iot_pkt_t *pkt, uint8_t ext_result,
|
|
uint8_t invalid_sn);
|
|
|
|
/**
|
|
* @brief add meter data as an entry into iot_buf_pool.
|
|
* @param buf: the iot_buf_pool to cache data.
|
|
* @param pm_addr: meter addr of the event reporting data.
|
|
* @param dev_type: device type, see IOT_SG_CCO_DEV_TYPE_XXX.
|
|
* @param proto_type: proto type of the event reporting data.
|
|
* @param evt_type: event type, see IOT_SG_CCO_EVENT_XXX.
|
|
* @param pkt: iot_pkt containing data in its data block
|
|
* @retval: ERR_OK for success case. Other value for failed case.
|
|
*/
|
|
uint32_t iot_sg_buf_pool_add_evt_data(iot_buf_pool_t *buf,
|
|
uint8_t *pm_addr, uint8_t dev_type, uint8_t proto_type,
|
|
uint8_t evt_type, iot_pkt_t *pkt);
|
|
|
|
/**
|
|
* @brief add meter data as an entry into iot_buf_pool.
|
|
* @param buf: the iot_buf_pool to cache data
|
|
* @param index: index of sta in table.
|
|
* @param pkt: iot_pkt containing secondary node info
|
|
* @param intf_type: cctt type or cli type
|
|
* @retval: ERR_OK for success case. Other value for failed case.
|
|
*/
|
|
uint32_t iot_sg_buf_pool_add_sec_node_data(iot_buf_pool_t *buf,
|
|
uint16_t index, iot_pkt_t *pkt, uint8_t intf_type);
|
|
|
|
/**
|
|
* @brief add meter data as an entry into iot_buf_pool.
|
|
* @param buf: the iot_buf_pool to cache data
|
|
* @param state: state to be report to cco
|
|
* @param intf_type: caller, see IOT_SG_CALLER_TYPE_XXX
|
|
* @retval: ERR_OK for success case. Other value for failed case.
|
|
*/
|
|
uint32_t iot_sg_buf_pool_add_state_chg_data(iot_buf_pool_t *buf,
|
|
uint32_t state, uint8_t intf_type);
|
|
|
|
/**
|
|
* @brief add sec node state change data as an entry into
|
|
* iot_buf_pool.
|
|
* @param buf: the iot_buf_pool to cache data
|
|
* @param pkt: iot_pkt containing secondary node info
|
|
* @retval: ERR_OK for success case. Other value for failed case.
|
|
*/
|
|
uint32_t iot_sg_buf_pool_add_node_state_chg_data(iot_buf_pool_t *buf,
|
|
iot_pkt_t *pkt);
|
|
|
|
/**
|
|
* @brief: find a entry by mac in the buffer pool
|
|
* @param buf: the buffer pool from which to search for data
|
|
* @param mac_addr: the target mac addr
|
|
* @param sender: sender type, see IOT_SG_CCO_CMD_SENDER_XXX
|
|
* @param data_type:entry data type, see IOT_BUF_DT_XXX
|
|
* @retval: NULL - if entry with specified mac address doesn't exist
|
|
* otherwise - the entry with the specified mac address
|
|
*/
|
|
iot_buf_pool_entry_t* iot_sg_buf_pool_find_by_mac(iot_buf_pool_t *buf,
|
|
uint8_t *mac_addr, uint8_t sender, uint8_t data_type);
|
|
|
|
/**
|
|
* @brief: find a extension task entry by mac in the buffer pool
|
|
* @param buf: the buffer pool from which to search for data
|
|
* @param mac_addr: the target mac addr
|
|
* @param ext_task_type: extension task type, see IOT_SG_CCO_EXT_TASK_TYPE_XXX.
|
|
* @retval: NULL - if entry with specified mac address doesn't exist
|
|
* otherwise - the entry with the specified mac address
|
|
*/
|
|
iot_buf_pool_entry_t* iot_sg_buf_pool_ext_task_find_by_mac(iot_buf_pool_t *buf,
|
|
uint8_t *mac_addr, uint8_t ext_task_type);
|
|
|
|
/**
|
|
* @brief: find a entry by mac in the buffer pool
|
|
* @param buf: the buffer pool from which to search for data
|
|
* @param sn: the target sn
|
|
* @param data_type:entry data type, see IOT_BUF_DT_XXX
|
|
* @retval: NULL - if entry with specified mac address doesn't exist
|
|
* otherwise - the entry with the specified mac address
|
|
*/
|
|
iot_buf_pool_entry_t* iot_sg_buf_pool_find_by_sn(iot_buf_pool_t *buf,
|
|
uint16_t sn, uint8_t data_type);
|
|
|
|
/**
|
|
* @brief: find an entry by task id in the buffer pool
|
|
* @param buf: the buffer pool from which to search for data
|
|
* @param task_id: the target task_id
|
|
* @retval: NULL - the entry with the specified task id doesn't exist
|
|
* otherwise - the entry with the specified task id exist
|
|
*/
|
|
iot_buf_pool_entry_t *iot_buf_pool_find_by_task_id(iot_buf_pool_t *buf,
|
|
uint16_t task_id);
|
|
|
|
/**
|
|
* @brief: find an entry by collect task id in the buffer pool
|
|
* @param buf: the buffer pool from which to search for data
|
|
* @param task_id: the target collect task_id
|
|
* @retval: NULL - the entry with the specified task id doesn't exist
|
|
* otherwise - the entry with the specified clct task id exist
|
|
*/
|
|
iot_buf_pool_entry_t *iot_sg_buf_pool_find_by_clct_task_id(iot_buf_pool_t *buf,
|
|
uint8_t task_id);
|
|
|
|
/**
|
|
* @brief: get task id start from specific offset.
|
|
* @param buf: the buffer pool from which to search for data
|
|
* @param start_index: start index of task buffer
|
|
* @param cnt: get count of task id
|
|
* @param taskid: buffer to store task id
|
|
* @retval: count of retrieved taskid
|
|
*/
|
|
uint16_t iot_buf_pool_get_task_listid(iot_buf_pool_t *buf,
|
|
uint16_t start_index, uint16_t cnt, uint16_t *task_id_buf);
|
|
|
|
/**
|
|
* @brief delete a task in iot_buf_pool by task id.
|
|
* @param buf: the iot_buf_pool to cache data.
|
|
* @task_id: the id that task will be deleted.
|
|
*/
|
|
uint32_t iot_buf_pool_del_task_by_task_id(iot_buf_pool_t *buf,
|
|
uint16_t task_id);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* IOT_SG_CCO_BUF_H */
|