451 lines
14 KiB
C
451 lines
14 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_CLI_PLC_NW
|
|
#define IOT_CLI_PLC_NW
|
|
|
|
/* os shim includes */
|
|
#include "os_types.h"
|
|
|
|
#include "iot_config.h"
|
|
#include "iot_cli_plc_module.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#pragma pack(push) /* save the pack status */
|
|
#pragma pack(1) /* 1 byte align */
|
|
|
|
#if PLC_SUPPORT_CCO_ROLE
|
|
|
|
/* plc mgr request topo data version */
|
|
/* topo data from IOT_PLC_CCO_TOPO_REQ_DATA_VER_V0 */
|
|
#define IOT_CLI_CCO_TOPO_VER0 0
|
|
/* topo data from IOT_PLC_CCO_TOPO_REQ_DATA_VER_V7 */
|
|
#define IOT_CLI_CCO_TOPO_VER1 1
|
|
|
|
/** IOT_PLC_MSG_NW_TOPO_QUERY format */
|
|
typedef struct _cli_host_nw_topo_query {
|
|
/** start tei of the query */
|
|
uint16_t start;
|
|
/** requested number of valid entries */
|
|
uint16_t count;
|
|
/** auto rpt topo data flag, 0 - auto rpt, 1 - no auto rpt */
|
|
uint8_t auto_rpt : 1,
|
|
/** topo version, see IOT_CLI_CCO_TOPO_VER_XXX */
|
|
ver : 2,
|
|
/** reserved for further use */
|
|
rsvd : 5;
|
|
} cli_host_nw_topo_query;
|
|
|
|
/** topo info */
|
|
typedef struct _cli_host_topo_info_t {
|
|
/** total number of valid tei */
|
|
uint16_t total_count;
|
|
/** number of valid tei in current message */
|
|
uint16_t count;
|
|
/** node len */
|
|
uint8_t node_len;
|
|
/** report done */
|
|
uint8_t done : 1,
|
|
/** error code, see IOT_PLC_CCO_QR_TOPO_DATA_XXX */
|
|
err_code : 2,
|
|
/** compatibility check flag */
|
|
compatibility_check : 1,
|
|
/** topo version, see IOT_CLI_CCO_TOPO_VER_XXX */
|
|
ver : 2,
|
|
/** reserved for future */
|
|
reserved : 2;
|
|
/** node info of each valid tei, see cli_host_node_info_t */
|
|
uint8_t data[0];
|
|
} cli_host_topo_info_t;
|
|
|
|
/** chip id information */
|
|
typedef struct _cli_chip_id_t {
|
|
/** check code */
|
|
uint8_t check_code[IOT_PLC_CHIP_ID_CRC_LEN];
|
|
/** equipment serial number */
|
|
uint8_t dev_code[IOT_PLC_CHIP_ID_SERIAL_NUM_LEN];
|
|
/** chip mode */
|
|
uint16_t chip_mode;
|
|
/** chip vendor code */
|
|
uint16_t vendor;
|
|
/** 1 - narrowband, 2 - broadband */
|
|
uint8_t dev_type;
|
|
/** fixed value: 0x01C1FB */
|
|
uint8_t hd4_3;
|
|
uint8_t hd4_2;
|
|
uint8_t hd4_1;
|
|
/** fixed value: 0x9C */
|
|
uint8_t hd3;
|
|
/** fixed value: 0x02 */
|
|
uint8_t hd2;
|
|
/** fixed value: 0x01 */
|
|
uint8_t hd1;
|
|
} cli_chip_id_t;
|
|
|
|
/** topo node info */
|
|
typedef struct _cli_host_node_info_t {
|
|
/** tei of the station */
|
|
uint16_t sta_tei;
|
|
/** tei of the proxy */
|
|
uint16_t proxy_tei;
|
|
/** level of the station */
|
|
uint8_t level;
|
|
/** role of the station */
|
|
uint8_t role;
|
|
/** uplink traffic success ratio */
|
|
uint8_t ul_tf_sr;
|
|
/** downlink traffic success ratio */
|
|
uint8_t dl_tf_sr;
|
|
/** rx snr from the node to its pco */
|
|
int8_t ul_snr;
|
|
/** mac address of the station */
|
|
uint8_t addr[IOT_MAC_ADDR_LEN];
|
|
/** device type. see PLC_DEV_TYPE_XXX */
|
|
uint8_t dev_type;
|
|
/** logical phase of the station */
|
|
uint8_t logic_phase1 : 2,
|
|
logic_phase2 : 2,
|
|
logic_phase3 : 2,
|
|
/** device communication type, see PLC_DEV_COMM_TYPE_XXX */
|
|
comm_type : 2;
|
|
/** physical phase of the station */
|
|
uint8_t phy_phase1 : 2,
|
|
phy_phase2 : 2,
|
|
phy_phase3 : 2,
|
|
/** 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 L/N reversed in Three-phase power meter */
|
|
opposite_3p : 1;
|
|
/** last boot up reason of the node */
|
|
uint8_t boot_reason;
|
|
/** build version of the node */
|
|
uint32_t build_ver;
|
|
/** software version of the node */
|
|
uint16_t sw_ver;
|
|
/** vendor of the node */
|
|
uint16_t vendor;
|
|
/** how many times received valid assoc request from the node since join
|
|
* the network.
|
|
*/
|
|
uint16_t assoc_rx_cnt;
|
|
/** how many times the node change proxy accepted since join the network */
|
|
uint16_t proxy_chg_accept_cnt;
|
|
/** how many times received valid proxy change request from the node
|
|
* since join the network.
|
|
*/
|
|
uint32_t proxy_chg_rx_cnt;
|
|
/** how much time the node have been in the network, unit is 1s */
|
|
uint32_t in_network_time;
|
|
/** how much time since last assoc request, unit is 1s */
|
|
uint32_t last_assoc_rx_time;
|
|
/** how much time since last proxy change, unit is 1s */
|
|
uint32_t last_proxy_chg_time;
|
|
/** how much time since last seen this device, unit is 1s */
|
|
uint32_t inactive_time;
|
|
/* rx snr from its pco to the node */
|
|
int8_t dl_snr;
|
|
/** mtd type of the peer */
|
|
int8_t mtd_type:4,
|
|
/** psram status of the peer */
|
|
psram :1,
|
|
/** firmware version type, 0 - release, 1 - debug */
|
|
ver_type:1,
|
|
/** reserved for future */
|
|
rsvd :2;
|
|
/* chip id */
|
|
cli_chip_id_t chip_id;
|
|
/* addr type */
|
|
int8_t addr_type;
|
|
/* 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,
|
|
/** link type between station and proxy, 0 - hplc, 1 - rf */
|
|
pco_link_rf : 1,
|
|
reserved : 5;
|
|
} cli_host_node_info_t;
|
|
|
|
/** cli node info format v7 */
|
|
typedef struct _cli_host_node_info_v7_t {
|
|
/** tei of the station */
|
|
uint16_t sta_tei;
|
|
/** tei of the proxy */
|
|
uint16_t proxy_tei;
|
|
/** level of the station */
|
|
uint8_t level : 4,
|
|
/** role of the station */
|
|
role : 4;
|
|
/** device type. See PLC_DEV_TYPE_XXX */
|
|
uint8_t dev_type;
|
|
/** mac address of the station: big endian */
|
|
uint8_t addr[IOT_MAC_ADDR_LEN];
|
|
/** software version */
|
|
uint16_t sw_ver;
|
|
/** software build time */
|
|
uint16_t build_time_y : 7,
|
|
build_time_m : 4,
|
|
build_time_d : 5;
|
|
/** module vendor ID */
|
|
uint16_t vendor_id;
|
|
/** chip code */
|
|
uint16_t chip_code;
|
|
/** build version of the node */
|
|
uint32_t build_ver;
|
|
} cli_host_node_info_v7_t;
|
|
|
|
/** set dl snr on */
|
|
typedef struct _cli_host_set_dl_snr
|
|
{
|
|
/** 1 means on */
|
|
uint8_t on;
|
|
} cli_host_set_dl_snr;
|
|
|
|
/** set dl snr ack */
|
|
typedef struct _cli_host_set_dl_snr_ack
|
|
{
|
|
/** set result */
|
|
uint8_t result;
|
|
} cli_host_set_dl_snr_ack;
|
|
|
|
/** cco status */
|
|
typedef struct _cli_host_cco_nw_status
|
|
{
|
|
/** network protocol see - IOT_SG_APP_PROTO_XX */
|
|
uint8_t proto : 2,
|
|
reserved : 6;
|
|
/** network formation done */
|
|
uint8_t nw_fmt_done;
|
|
/** route learning done */
|
|
uint8_t route_learn_done;
|
|
/** nid */
|
|
uint32_t nid;
|
|
} cli_host_cco_nw_status;
|
|
|
|
/** oppsite phase notification */
|
|
typedef struct _cli_host_oppsite_phase_notify
|
|
{
|
|
uint8_t sta[6];
|
|
uint8_t oppsite_phase;
|
|
} cli_host_oppsite_phase_notify;
|
|
|
|
typedef struct _cli_host_set_cli_upgrade_enabled
|
|
{
|
|
uint8_t enabled;
|
|
} cli_host_set_cli_upgrade_enabled;
|
|
|
|
typedef struct _cli_host_set_cli_upgrade_enabled_ack
|
|
{
|
|
uint8_t result;
|
|
} cli_host_set_cli_upgrade_enabled_ack;
|
|
|
|
typedef struct _cli_host_set_nid
|
|
{
|
|
uint32_t nid;
|
|
} cli_host_set_nid;
|
|
|
|
/** HPLC and RF tx power set */
|
|
typedef struct _cli_host_tx_power_set_t {
|
|
/** hplc tx power. unit is 1 dbuv */
|
|
uint8_t hplc_power;
|
|
/** rf tx power. unit is 1 dbm */
|
|
int8_t rf_power;
|
|
/** flag to mark if hplc power config is valid */
|
|
uint8_t hplc_valid :1,
|
|
/** flag to mark if rf power config is valid */
|
|
rf_valid :1,
|
|
/** reserved for future */
|
|
rsvd :6;
|
|
} cli_host_tx_power_set_t;
|
|
|
|
typedef struct _cli_host_set_nid_ack
|
|
{
|
|
uint8_t result;
|
|
} cli_host_set_nid_ack;
|
|
|
|
/** cli nw status query */
|
|
typedef struct _cli_nw_status_query_dl {
|
|
uint8_t control;
|
|
} cli_nw_status_query_dl;
|
|
#endif
|
|
|
|
/** neighbour network information */
|
|
typedef struct _cli_neighbor_nw_info {
|
|
/** nid of the neighbour network */
|
|
uint32_t nid;
|
|
/** bandwidth taken by neighbour network in millisecond */
|
|
uint32_t bandwidth;
|
|
/** cco mac address */
|
|
uint8_t addr[IOT_MAC_ADDR_LEN];
|
|
/** each phase snr of the network */
|
|
int8_t snr[IOT_PLC_PHASE_CNT];
|
|
/** beacon data info */
|
|
uint8_t bc_data[IOT_PLC_BEACON_DATA_MAX];
|
|
} cli_neighbor_nw_info;
|
|
|
|
/** cli neighbor nw rpt format */
|
|
typedef struct _cli_neighbor_nw_rpt {
|
|
/** total number of neighbour network */
|
|
uint16_t count;
|
|
/** neighbour network info entries */
|
|
cli_neighbor_nw_info nb_info[0];
|
|
} cli_neighbor_nw_rpt;
|
|
|
|
/** cli neighbor nw query */
|
|
typedef struct _cli_neighbor_nw_query_dl {
|
|
uint8_t control;
|
|
} cli_neighbor_nw_query_dl;
|
|
|
|
/** cli neighbor device info format */
|
|
typedef struct _cli_neighbor_node_info_t {
|
|
/** tei of the neighbor device */
|
|
uint16_t tei;
|
|
/** level of the station */
|
|
uint8_t level;
|
|
/** role of the station */
|
|
uint8_t role;
|
|
/** uplink traffic success ratio */
|
|
uint8_t ul_tf_sr;
|
|
/** downlink traffic success ratio */
|
|
uint8_t dl_tf_sr;
|
|
/** physical phase of the station */
|
|
uint16_t phase1 : 2,
|
|
phase2 : 2,
|
|
phase3 : 2,
|
|
/** flag to mark if device is direct sub sta */
|
|
d_sub_sta : 1,
|
|
/** flag to mark if device proxy of local device */
|
|
proxy : 1,
|
|
/** flag to mark if devie address is valid */
|
|
addr_valid : 1,
|
|
/** reserved for future */
|
|
reserved : 5;
|
|
/** rx snr from the node to local device */
|
|
int8_t snr;
|
|
/** mac address of the station */
|
|
uint8_t addr[IOT_MAC_ADDR_LEN];
|
|
} cli_neighbor_node_info_t;
|
|
|
|
/** cli neighbor dev rpt format */
|
|
typedef struct _cli_neighbor_info_t {
|
|
/** sta addr to query */
|
|
uint8_t sta_addr[IOT_MAC_ADDR_LEN];
|
|
/** total number of valid tei */
|
|
uint16_t total_cnt;
|
|
/** total direct sub sta of local device */
|
|
uint16_t total_d_sub_sta_cnt;
|
|
/** number of valid tei in current message */
|
|
uint16_t cnt;
|
|
/** report done */
|
|
uint16_t done;
|
|
/** node info of each valid tei */
|
|
cli_neighbor_node_info_t node[0];
|
|
} cli_neighbor_info_t;
|
|
|
|
/** cli neighbor info query format */
|
|
typedef struct _cli_neighbor_info_query_dl {
|
|
/** start idx of neighbor node */
|
|
uint16_t start;
|
|
/** count of neighbor nodes */
|
|
uint16_t cnt;
|
|
/** sta addr to query */
|
|
uint8_t sta_addr[IOT_MAC_ADDR_LEN];
|
|
} cli_neighbor_info_query_dl;
|
|
|
|
/** online response */
|
|
typedef struct _cli_host_online_response
|
|
{
|
|
/** is cco */
|
|
uint8_t cco : 1,
|
|
mt : 1,
|
|
reserved0 : 6;
|
|
#if PLC_SUPPORT_CCO_ROLE
|
|
/** nw status */
|
|
cli_host_cco_nw_status cco_nw_status;
|
|
#else
|
|
uint32_t sw_ver;
|
|
uint32_t reserved;
|
|
#endif
|
|
} cli_host_online_response_t;
|
|
|
|
/** switch boot part */
|
|
typedef struct _cli_host_switch_boot_part
|
|
{
|
|
/** switch dst */
|
|
uint8_t dst[6];
|
|
} cli_host_switch_boot_part;
|
|
|
|
/** switch boot part ack */
|
|
typedef struct _cli_host_switch_boot_part_ack
|
|
{
|
|
/** switch result */
|
|
uint8_t result;
|
|
/** switch dst */
|
|
uint8_t dst[6];
|
|
} cli_host_switch_boot_part_ack;
|
|
|
|
typedef struct _cli_set_rf_channel_dl {
|
|
/* rf option */
|
|
uint8_t option;
|
|
/* rf channel */
|
|
uint8_t channel;
|
|
/* flag to mark if enable rf channel coordination */
|
|
uint8_t rf_cod_enable;
|
|
} cli_set_rf_channel_dl_t;
|
|
|
|
void cli_handle_plc_msg(iot_pkt_t *pkt);
|
|
void cli_get_topo(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
void cli_online_handler(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
void cli_neighbor_info_query(
|
|
uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
void cli_switch_boot_part(
|
|
uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
|
|
#if PLC_SUPPORT_CCO_ROLE
|
|
void ci_nw_status_query(
|
|
uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
void cli_neighbor_nw_query(
|
|
uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
void cli_neighbor_info_response(
|
|
uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
void cli_set_pco_snr_config(
|
|
uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
void cli_set_nid(
|
|
uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
void cli_set_tx_power(
|
|
uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
void cli_set_cli_upgrade_enabled(
|
|
uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
/* changed plc mgr role */
|
|
void cli_chang_host_role(uint8_t *src_mac);
|
|
#endif
|
|
|
|
#if (PLC_SUPPORT_CCO_ROLE || (IOT_STA_CONTROL_MODE == IOT_STA_CONTROL_TYPE_STA))
|
|
void cli_get_band_id(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
void cli_set_band_id(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
void cli_set_rf_channel(uint8_t *buffer, uint32_t bufferlen, uint8_t *src_mac);
|
|
#endif
|
|
|
|
#pragma pack(pop) /* restore the pack status */
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif |