390 lines
12 KiB
C
Executable File
390 lines
12 KiB
C
Executable File
/****************************************************************************
|
||
|
||
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
||
|
||
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
||
be copied by any method or incorporated into another program without
|
||
the express written consent of Aerospace C.Power. This Information or any portion
|
||
thereof remains the property of Aerospace C.Power. The Information contained herein
|
||
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
||
liability for its use in any way and conveys no license or title under
|
||
any patent or copyright and makes no representation or warranty that this
|
||
Information is free from patent or copyright infringement.
|
||
|
||
****************************************************************************/
|
||
|
||
#ifndef IOT_PLC_SYNC_API_H
|
||
#define IOT_PLC_SYNC_API_H
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#define IOT_SYNC_TASK_PARSER_STRUCT_LEN (255)
|
||
|
||
/* command id */
|
||
#define IOT_SYNC_API_CMD_IDLE (0)
|
||
/* cco 查询topo */
|
||
#define IOT_SYNC_API_CMD_CCO_QUERY_TOPO (1)
|
||
/* cco 设置白名单 */
|
||
#define IOT_SYNC_API_CMD_CCO_SET_WL (2)
|
||
/* cco 查询白名单 */
|
||
#define IOT_SYNC_API_CMD_CCO_GET_WL (3)
|
||
/* cco 查询白名单状态 */
|
||
#define IOT_SYNC_API_CMD_CCO_GET_WL_STATE (4)
|
||
/* cco 设置nid */
|
||
#define IOT_SYNC_API_CMD_CCO_SET_NID (5)
|
||
/* cco 查询nid */
|
||
#define IOT_SYNC_API_CMD_CCO_GET_NID (6)
|
||
/* sta 查询与指定节点间的snr */
|
||
#define IOT_SYNC_API_CMD_STA_GET_SNR (7)
|
||
/* sta 查询指定节点通信成功率 */
|
||
#define IOT_SYNC_API_CMD_STA_GET_TF_SR (8)
|
||
/* sta 查询与指定节点间的信道衰减 */
|
||
#define IOT_SYNC_API_CMD_STA_GET_ATTEN (9)
|
||
/* sta/cco 查询载波通信频段 */
|
||
#define IOT_SYNC_API_CMD_QUERY_BAND (10)
|
||
/* sta/cco 设置载波通信发射功率 */
|
||
#define IOT_SYNC_API_CMD_SET_TX_POWER (11)
|
||
/* sta 查询指定节点的相位 */
|
||
#define IOT_SYNC_API_CMD_GET_PHASE (12)
|
||
/* sta 查询指定节点的节点信息 */
|
||
#define IOT_SYNC_API_CMD_GET_TOPO_NODE (13)
|
||
/* sta/cco 查询邻居网络 */
|
||
#define IOT_SYNC_API_CMD_QUERY_NBNET (14)
|
||
/* cco 设置白名单带相位 */
|
||
#define IOT_SYNC_API_CMD_CCO_SET_WL_EXT (15)
|
||
/* cco 查询白名单带相位 */
|
||
#define IOT_SYNC_API_CMD_CCO_GET_WL_EXT (16)
|
||
/* sta/cco set work band */
|
||
#define IOT_SYNC_API_CMD_SET_BAND (17)
|
||
|
||
typedef uint32_t(* POST_MSG_CB)(void *data);
|
||
|
||
/* pack for the structures in the whole file */
|
||
#pragma pack(push) // save the pack status
|
||
#pragma pack(1) // 1 byte align
|
||
|
||
typedef struct _iot_plc_band_info {
|
||
/** 载波通信频段. see PLC_LIB_FREQ_BAND_XXX */
|
||
uint8_t freq_band;
|
||
/** 当前频段的噪声. unit is 1dbm */
|
||
uint8_t noise_floor;
|
||
/** 发射功率. 0 means no tx power cap. unit is 1dbm */
|
||
uint8_t power_cap;
|
||
} iot_plc_freq_band_info;
|
||
|
||
typedef struct _iot_plc_nid_info {
|
||
/** 当前网络的nid */
|
||
uint32_t nid;
|
||
} iot_plc_nid_info;
|
||
|
||
typedef struct _iot_plc_topo_node_info {
|
||
/** MAC address */
|
||
uint8_t mac[IOT_MAC_ADDR_LEN];
|
||
/** 所在层级 */
|
||
uint8_t level;
|
||
/** 代理节点的TEI */
|
||
uint16_t proxy_tei;
|
||
/** role CCO: 4. Proxy: 2. STA: 1. Unknown:0. */
|
||
uint8_t role;
|
||
/** sta 自身tei */
|
||
uint16_t sta_tei;
|
||
/** physical phase of the station */
|
||
uint8_t phy_phase1 :2,
|
||
phy_phase2 :2,
|
||
phy_phase3 :2,
|
||
reserved :2;
|
||
} iot_plc_topo_node_info;
|
||
|
||
typedef struct _iot_plc_nbcco_info
|
||
{
|
||
/* cco mac地址 */
|
||
uint8_t cco_mac[IOT_MAC_ADDR_LEN];
|
||
/* 当前网络的nid */
|
||
uint32_t nid;
|
||
/* 三相信噪比 */
|
||
int8_t snr[IOT_PLC_PHASE_CNT];
|
||
} iot_plc_nbcco_info;
|
||
|
||
typedef struct _iot_plc_nbnet_info
|
||
{
|
||
/* 邻居网络总数量 */
|
||
uint8_t count;
|
||
/* 单个邻居网络信息 */
|
||
iot_plc_nbcco_info nbnet_info[0];
|
||
} iot_plc_nbnet_info;
|
||
|
||
typedef struct _iot_plc_topo_info {
|
||
uint16_t total_cnt;
|
||
uint8_t cur_cnt;
|
||
iot_plc_topo_node_info topo_info[0];
|
||
} iot_plc_topo_info;
|
||
|
||
typedef struct _iot_plc_white_info {
|
||
/* 白名单总数量 */
|
||
uint16_t total;
|
||
/* 本次返回数量 */
|
||
uint8_t cur_cnt;
|
||
/* mac 地址列表 */
|
||
uint8_t mac_list[0][IOT_MAC_ADDR_LEN];
|
||
} iot_plc_white_info;
|
||
|
||
typedef struct _white_info {
|
||
/* mac 地址 */
|
||
uint8_t mac[IOT_MAC_ADDR_LEN];
|
||
/* 对应相位 */
|
||
uint8_t phase:2,
|
||
revd:6;
|
||
} white_info;
|
||
|
||
typedef struct _iot_plc_white_info_ext {
|
||
/* 白名单总数量 */
|
||
uint16_t total;
|
||
/* 本次返回数量 */
|
||
uint8_t cur_cnt;
|
||
/* mac phase列表 */
|
||
white_info white_info[0];
|
||
} iot_plc_white_info_ext;
|
||
|
||
#pragma pack(pop) /* restore the pack status */
|
||
|
||
/**
|
||
* @function_name:iot_plc_query_band
|
||
* @brief : 查询载波频段信息.
|
||
* @param[out] band_info: 回复band信息
|
||
* @note sta/cco查询band信息
|
||
**/
|
||
void iot_plc_query_band(iot_plc_freq_band_info **band_info);
|
||
|
||
/**
|
||
* @function_name:iot_plc_set_band
|
||
* @brief : 设置载波通信工作频段.
|
||
* @param[in] band: band
|
||
* @note sta/cco设置载波band
|
||
**/
|
||
uint8_t iot_plc_set_band(uint8_t band);
|
||
|
||
/**
|
||
* @function_name:iot_plc_set_tx_power
|
||
* @brief : 设置载波通信发射功率.
|
||
* @param[in] power: power
|
||
* @note sta/cco设置发射功率
|
||
**/
|
||
uint8_t iot_plc_set_tx_power(uint8_t power);
|
||
|
||
/**
|
||
* @function_name:iot_plc_cco_set_nid
|
||
* @brief : 设置nid.
|
||
* @param[in] new_nid: nid
|
||
* @note cco端设置nid
|
||
**/
|
||
uint8_t iot_plc_cco_set_nid(uint32_t new_nid);
|
||
|
||
/**
|
||
* @function_name:iot_plc_cco_get_nid
|
||
* @brief : 查询nid信息.
|
||
* @param[out] nid_info: 回复nid信息
|
||
* @note cco端查询nid信息
|
||
**/
|
||
void iot_plc_cco_get_nid(iot_plc_nid_info **nid_info);
|
||
|
||
/**
|
||
* @function_name:iot_plc_cco_query_node_level
|
||
* @brief : 查询节点层级.
|
||
* @param[in] sta_mac: 节点mac地址.
|
||
* @return 返回: 0 - 失败, 其他 - 层级
|
||
* @note cco端查询topo层级信息
|
||
**/
|
||
uint8_t iot_plc_cco_query_node_level(uint8_t *sta_mac);
|
||
|
||
/**
|
||
* @function_name:iot_plc_cco_query_nw_topo
|
||
* @brief : 查询topo信息.
|
||
* @param[out] topo_info: 回复topo信息
|
||
* @param[in] start: 开始读取位置.
|
||
* @param[in] count: 最多读取个数.
|
||
* @note cco端查询topo信息
|
||
**/
|
||
void iot_plc_cco_query_nw_topo(iot_plc_topo_info **topo_info,
|
||
uint16_t start, uint8_t count);
|
||
|
||
/**
|
||
* @function_name:iot_plc_query_nbnet
|
||
* @brief : 查询邻居网络信息.
|
||
* @param[out] nbnet_info: 邻居网络信息
|
||
* @note cco/sta查询邻居信息
|
||
**/
|
||
void iot_plc_query_nbnet(iot_plc_nbnet_info **nbnet_info);
|
||
|
||
/**
|
||
* @function_name: iot_plc_cco_set_whitelist_func
|
||
* @brief :设置白名单
|
||
* @param[in] action:删除:IOT_PLC_WL_DEL
|
||
添加:IOT_PLC_WL_ADD
|
||
添加:IOT_PLC_WL_ADD_PA添加A相
|
||
添加:IOT_PLC_WL_ADD_PB添加B相
|
||
添加:IOT_PLC_WL_ADD_PC添加C相
|
||
清空:IOT_PLC_WL_DEL_ALL
|
||
禁用:IOT_PLC_WL_DISABLE(即关闭)
|
||
使能:IOT_PLC_WL_ENABLE(即开启)
|
||
* @param[in] count:设置多少个,当action为清空、禁用、使能时,该参数为0.
|
||
* @param[in] mac_addr_array:添加/删除的MAC地址.当action为清空、禁用、使能时,该参数为0.
|
||
* 添加/删除的MAC地址为小端模式.
|
||
* @return 返回: 0 - 成功, 其他 - 失败
|
||
* @note cco端设置白名单
|
||
**/
|
||
uint8_t iot_plc_cco_set_whitelist_func(uint8_t action,uint16_t count,
|
||
uint8_t *mac_addr_array);
|
||
|
||
/**
|
||
* @function_name: iot_plc_cco_get_whiltlist_state_func
|
||
* @brief 获取白名单状态
|
||
* @param[in] NULL
|
||
* @return 0:关闭 1:开启
|
||
* @note cco端查询白名单状态
|
||
**/
|
||
uint8_t iot_plc_cco_get_whiltlist_state_func(void);
|
||
|
||
/**
|
||
* @function_name: iot_plc_cco_get_whitelist_info_func
|
||
* @brief: 获取白名单信息
|
||
* @param[out] whitelist_info:获取到的白名单信息
|
||
* @param[in] start:查询白名单开始位置,从0开始
|
||
* @param[in] count:查询白名单个数
|
||
* @return 返回白名单数量.
|
||
* @note cco端查询白名单
|
||
**/
|
||
uint8_t iot_plc_cco_get_whitelist_info_func(iot_plc_white_info **whitelist_info,
|
||
uint16_t start, uint8_t count);
|
||
|
||
/**
|
||
* @function_name: iot_plc_cco_get_whitelist_info_ext_func
|
||
* @brief: 获取扩展白名单信息-带相位信息
|
||
* @param[out] whitelist_info:获取到的白名单信息
|
||
* @param[in] start:查询白名单开始位置,从0开始
|
||
* @param[in] count:查询白名单个数
|
||
* @return 返回白名单数量.
|
||
* @note cco端查询白名单
|
||
**/
|
||
uint8_t iot_plc_cco_get_wl_info_ext_func(iot_plc_white_info_ext **whitelist_info,
|
||
uint16_t start, uint8_t count);
|
||
|
||
/**
|
||
* @function_name: iot_plc_sta_get_atten_by_tei_func
|
||
* @brief 查询与代理节点间的信道衰减.
|
||
* @param[in] tei:指定的TEI
|
||
* @return 指定tei的信道衰减
|
||
* @note sta端获取与代理节点之间的信道衰减
|
||
**/
|
||
uint8_t iot_plc_sta_get_atten_by_tei_func(uint16_t tei);
|
||
|
||
/**
|
||
* @function_name: iot_plc_sta_get_snr_by_tei_func
|
||
* @brief 查询与代理节点间的SNR.
|
||
* @param[in] tei:指定的TEI
|
||
* @return 指定tei的信噪比
|
||
* @note sta端获取与代理节点之间的snr
|
||
**/
|
||
uint8_t iot_plc_sta_get_snr_by_tei_func(uint16_t tei);
|
||
|
||
/**
|
||
* @function_name: iot_plc_sta_get_snr_by_addr_func
|
||
* @brief query the snr attenuation between the agent node.
|
||
* @param[in] addr: node mac addr.
|
||
* @return snr value.
|
||
* @note only for cco.
|
||
**/
|
||
uint8_t iot_plc_sta_get_snr_by_addr_func(uint8_t *addr);
|
||
|
||
/**
|
||
* @function_name: iot_plc_sta_get_tf_sr_by_tei_func
|
||
* @brief 查询指定TEI的通信成功率.
|
||
* @param[in] tei:指定的TEI
|
||
* @return 回复指定tei的信道通信成功率
|
||
* @note sta端获取与代理节点之间的通信成功率
|
||
**/
|
||
uint8_t iot_plc_sta_get_tf_sr_by_tei_func(uint16_t tei);
|
||
|
||
/**
|
||
* @function_name: iot_plc_sta_get_tf_sr_by_addr_func
|
||
* @brief query the communication success rate of a node.
|
||
* @param[in] addr: node mac addr.
|
||
* @return communication success rate.
|
||
* @note only for cco.
|
||
**/
|
||
uint8_t iot_plc_sta_get_tf_sr_by_addr_func(uint8_t *addr);
|
||
|
||
/**
|
||
* @function_name: iot_plc_sta_get_phase_by_tei_func
|
||
* @brief 查询指定TEI的相位.
|
||
* @param[in] tei:指定的TEI
|
||
* @return 回复指定tei的相位
|
||
* @note sta端获取相位
|
||
**/
|
||
uint8_t iot_plc_sta_get_phase_by_tei_func(uint16_t tei);
|
||
|
||
/**
|
||
* @function_name: iot_plc_sta_get_phase_by_addr_func
|
||
* @brief query node phase information.
|
||
* @param[in] addr: node mac addr.
|
||
* @return phase info.
|
||
* @note only for cco.
|
||
**/
|
||
uint8_t iot_plc_sta_get_phase_by_addr_func(uint8_t *addr);
|
||
|
||
/**
|
||
* @function_name: iot_plc_sta_get_cco_flag_func
|
||
* @brief 查询系统中有无CCO.
|
||
* @param[in] NULL
|
||
* @return true:有, false:无
|
||
* @note sta端检查模块是否加入cco网络
|
||
**/
|
||
uint8_t iot_plc_sta_get_cco_flag_func(void);
|
||
|
||
/**
|
||
* @function_name: iot_plc_sta_get_proxy_tei_func
|
||
* @brief 查询代理节点tei.
|
||
* @param[in] NULL
|
||
* @return 0:查询失败, others:代理节点tei
|
||
* @note sta端检查查询代理节点tei,入网后才能查到.
|
||
**/
|
||
uint16_t iot_plc_sta_get_proxy_tei_func(void);
|
||
|
||
/**
|
||
* @function_name:iot_plc_sta_is_online
|
||
* @brief 查看对应地址的sta是否入网.
|
||
* @param mac: sta的mac.
|
||
* @return: true - sta is joined, false -sta is not joined
|
||
**/
|
||
uint8_t iot_plc_sta_is_online(uint8_t* mac);
|
||
|
||
/**
|
||
* @function_name:sync_api_msg_from_mac_handle
|
||
* @brief plc mac messages handle function.
|
||
* @param pkt: message data pkt.
|
||
* @return : true - command is executed, false - not executed
|
||
**/
|
||
uint8_t sync_api_msg_from_mac_handle(iot_pkt_t *pkt);
|
||
|
||
/**
|
||
* @function_name:iot_sync_api_init_app_hdl
|
||
* @brief 初始化app handle
|
||
* @param handle: 设置sync api 使用的app handle.
|
||
* @param module_id: 设置sync api 使用的module_id.
|
||
* @param clicb: 传递从CLI接收到的消息.
|
||
* @return : true - init success, else false.
|
||
**/
|
||
uint8_t iot_sync_api_init_app_hdl(iot_plc_app_h handle, module_id_t module_id,
|
||
POST_MSG_CB clicb);
|
||
|
||
/**
|
||
* @brief: handle cli message.
|
||
*/
|
||
void iot_app_handle_cli_msg(iot_pkt_t *pkt);
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif /* IOT_PLC_SYNC_API_H */ |