394 lines
13 KiB
C
394 lines
13 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 _APP_PROTO_PROC_H_
|
|
#define _APP_PROTO_PROC_H_
|
|
|
|
#include "app_types.h"
|
|
#include "app_proto.h"
|
|
#include "app_common.h"
|
|
#include "app_config.h"
|
|
#include "app_upg.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define PROTO_RET_CODE_SUCCESS 0x00
|
|
#define PROTO_RET_CODE_FAILED 0x01
|
|
|
|
/* Abnormal status code */
|
|
#define PROTO_REASON_NORMAL 0x00 /* The status is normal. */
|
|
#define PROTO_REASON_TIMEOUT 0x01 /* communication timeout */
|
|
#define PROTO_REASON_FORMAT 0x02 /* format error */
|
|
#define PROTO_REASON_BUSY 0x03 /* node busy */
|
|
#define PROTO_REASON_OTHER 0xFF /* Other errors */
|
|
|
|
#define PROTO_1S_CONVERT_MS 1000
|
|
#define PROTO_DELAY_MIN_TIME_MS 500
|
|
#define PROTO_PAD_LEN1 2
|
|
#define PROTO_PAD_LEN2 3
|
|
#define PROTO_CRC_HIGH_BIT_OFFSET 8
|
|
#define PROTO_MANU_CODE_LEN 2
|
|
#define PROTO_CHIP_TYPE_LEN 2
|
|
|
|
#define PROTO_MAX_RSP_DATA_LEN 512
|
|
|
|
typedef enum {
|
|
ID_PROTO_CMD_GET_VERSION = 0x0001,
|
|
ID_PROTO_CMD_GET_MAC_ADDR,
|
|
ID_PROTO_CMD_GET_DEV_ADDR,
|
|
ID_PROTO_CMD_SET_DEV_ADDR,
|
|
ID_PROTO_CMD_REBOOT_MODULE,
|
|
ID_PROTO_CMD_TRANS_FILE,
|
|
ID_PROTO_CMD_QRY_ONPOWER_TIME,
|
|
|
|
ID_PROTO_CMD_GET_WLIST_NUM = 0x0010,
|
|
ID_PROTO_CMD_GET_WLIST_INFO,
|
|
ID_PROTO_CMD_ADD_WLIST_NODE,
|
|
ID_PROTO_CMD_DEL_WLIST_NODE,
|
|
ID_PROTO_CMD_CLEAR_WLIST,
|
|
ID_PROTO_CMD_ENABLE_SELF_IDY,
|
|
ID_PROTO_CMD_SET_WLIST_STATE,
|
|
ID_PROTO_CMD_GET_WLIST_STATE,
|
|
|
|
ID_PROTO_CMD_GET_TOPO_NUM = 0x0020,
|
|
ID_PROTO_CMD_GET_TOPO_INFO,
|
|
ID_PROTO_CMD_GET_TOPO_INO_EX,
|
|
|
|
ID_PROTO_CMD_SET_GPIO = 0x0023,
|
|
ID_PROTO_CMD_GET_GPIO,
|
|
|
|
ID_PROTO_CMD_REPORT_ONOFFLINE = 0x0030,
|
|
|
|
ID_PROTO_CMD_GET_CALC_VALI = 0x0040,
|
|
|
|
ID_PROTO_CMD_GET_WORK_BAND = 0x0050, /* query work band */
|
|
ID_PROTO_CMD_SET_WORK_BAND, /* set work band */
|
|
ID_PROTO_CMD_GET_SCAN_BAND, /* query frequency band bitmap */
|
|
ID_PROTO_CMD_SET_SCAN_BAND, /* set frequency band bitmap */
|
|
|
|
ID_PROTO_CMD_GET_NBNET_INFO = 0x0060,
|
|
|
|
ID_PROTO_CMD_GET_UART_PARAM = 0x0070, /* query uart parameter */
|
|
ID_PROTO_CMD_SET_UART_PARAM, /* set uart parameter */
|
|
|
|
ID_PROTO_CMD_DATA_TRANS_TX = 0x0100,
|
|
ID_PROTO_CMD_DATA_TRANS_RX,
|
|
|
|
ID_PROTO_CMD_REMOTE_CMD_TX = 0x0110,
|
|
ID_PROTO_CMD_REMOTE_CMD_RX,
|
|
ID_PROTO_CMD_SYSCTRL_DATA_TRANS = 0x0120, /* for system control */
|
|
//ID_PROTO_CMD_DUT_SET_ADDR = 0x1000, /* set mac for dut, it will be lose after power-off */
|
|
//ID_PROTO_CMD_SET_WORK_MODE = 0x1201, /* set nv 0x3 revesed[0] */
|
|
|
|
ID_PROTO_CMD_GET_NV_MAC_ADDR = 0x1203, /* get nv 0x3 mac */
|
|
ID_PROTO_CMD_SET_NV_MAC_ADDR = 0x1204, /* set nv 0x3 mac */
|
|
} id_proto_cmd;
|
|
|
|
/* pack for the structures in the whole file */
|
|
#pragma pack(push) // save the pack status
|
|
#pragma pack(1) // 1 byte align
|
|
|
|
/* Acknowledgement/Negative acknowledgment structure */
|
|
typedef struct {
|
|
uint8_t ret_code; /* Error code. 0: success; 1: failure */
|
|
uint8_t reason; /* Cause of the error */
|
|
uint8_t reserved[PROTO_PAD_LEN1];
|
|
} proto_reply_ind;
|
|
|
|
/* Response structure for reading the version information */
|
|
typedef struct {
|
|
uint8_t manu_code[PROTO_MANU_CODE_LEN]; /* vendor code: HS (4853H) */
|
|
uint8_t chip_type[PROTO_CHIP_TYPE_LEN]; /* Chip model: 3011H */
|
|
uint16_t version; /* Version number */
|
|
uint16_t reserved;
|
|
} proto_get_version_ind;
|
|
|
|
/* Structure of the response to the request for reading the MAC address */
|
|
typedef struct {
|
|
uint8_t addr[IOT_MAC_ADDR_LEN]; /* address */
|
|
uint8_t reserved[PROTO_PAD_LEN1];
|
|
} proto_get_mac_addr_ind;
|
|
|
|
/* Structure of the response to set device address*/
|
|
typedef proto_reply_ind proto_set_dev_addr_ind;
|
|
|
|
/* Structure of the module restart request */
|
|
typedef struct {
|
|
uint8_t delay; /* Delay restart time, in seconds */
|
|
uint8_t reserved[PROTO_PAD_LEN2];
|
|
} proto_module_reboot_req;
|
|
|
|
/* Structure of the module restart response */
|
|
typedef proto_reply_ind proto_module_reboot_ind;
|
|
|
|
/* Structure of the response to the request for reading the MAC address */
|
|
typedef struct {
|
|
uint8_t addr[IOT_MAC_ADDR_LEN]; /* address */
|
|
uint16_t frame_index;
|
|
uint32_t on_power_ms_time;
|
|
} proto_qry_on_power_time_ind;
|
|
|
|
typedef struct {
|
|
uint8_t pin_num; /* GPIO pin */
|
|
uint8_t type; /* pin type <0:unknow, 1:GPIO, 2:PWM> */
|
|
uint8_t state; /* GPIO state <0:low level, 1:high level(pwm 0-100)> */
|
|
uint8_t pwm_freq; /* pwm frequency (unit:kHz) */
|
|
uint8_t pwm_ctl_mode; /* pwm ctl mode <0:real-time, 1:linear, 2:logar> */
|
|
uint8_t pwm_adjust_time; /* pwm gradient duration */
|
|
} proto_pin_info;
|
|
|
|
typedef struct {
|
|
uint8_t ret_code; /* status: 0-success, 1-failed */
|
|
uint8_t reason; /* failed reason */
|
|
uint8_t rsv[2];
|
|
} proto_set_gpio_ind;
|
|
|
|
typedef struct {
|
|
uint16_t cnt;
|
|
uint8_t rsv[2];
|
|
proto_pin_info gpio_info[0];
|
|
} proto_get_gpio_ind;
|
|
|
|
/*
|
|
* Channel forwarding command
|
|
* Structure of a data sending request
|
|
*/
|
|
typedef struct {
|
|
uint8_t dst_addr[IOT_MAC_ADDR_LEN]; /* destination communication address;
|
|
* FFFFFFFFFFFF indicates the network-wide broadcast */
|
|
uint16_t data_length; /* User data length */
|
|
uint8_t data[0]; /* User data */
|
|
} proto_data_transmit_tx_req;
|
|
|
|
/* Structure of the data transmission response */
|
|
typedef proto_reply_ind proto_data_transmit_tx_ind;
|
|
|
|
/* Structure of the request for receiving data */
|
|
typedef struct {
|
|
uint8_t src_addr[IOT_MAC_ADDR_LEN]; /* transmit device communication address */
|
|
uint16_t data_length; /* User data length */
|
|
uint8_t data[0]; /* User data */
|
|
} proto_data_transmit_rx_req;
|
|
|
|
typedef struct {
|
|
uint8_t dst_addr[IOT_MAC_ADDR_LEN]; /* destination communication address;
|
|
* FFFFFFFFFFFF indicates the network-wide broadcast */
|
|
uint16_t data_length; /* User data length */
|
|
uint8_t data[0]; /* User data */
|
|
} proto_sysctrl_data_from_uart;
|
|
|
|
typedef struct {
|
|
uint8_t src_addr[IOT_MAC_ADDR_LEN]; /* transmit device communication address */
|
|
uint16_t data_length; /* User data length */
|
|
uint8_t data[0]; /* User data */
|
|
} proto_sysctrl_data_to_uart;
|
|
|
|
/*
|
|
* Read the info of neibhourhood.
|
|
*/
|
|
typedef struct {
|
|
/* cco mac地址 */
|
|
uint8_t cco_mac[IOT_MAC_ADDR_LEN];
|
|
/* 当前网络的nid */
|
|
uint32_t nid;
|
|
/* 三相信噪比 */
|
|
int8_t snr[IOT_PLC_PHASE_CNT];
|
|
} iot_plc_nb_info;
|
|
|
|
/*
|
|
* Read all the info of cco nbnet.
|
|
*/
|
|
typedef struct {
|
|
uint8_t nb_num;
|
|
uint8_t rsv[3];
|
|
iot_plc_nb_info data[0];
|
|
} proto_get_nbnet_info_ind;
|
|
|
|
/*
|
|
* Whitelist operation
|
|
* Read the number of nodes in the whitelist.
|
|
*/
|
|
typedef struct {
|
|
uint16_t num; /* Number of Nodes */
|
|
uint16_t reserved;
|
|
} proto_get_whitelist_num_ind;
|
|
|
|
/* Number of nodes */
|
|
typedef struct {
|
|
uint16_t start; /* Start sequence number, starting from 1 */
|
|
uint16_t count; /* Number of nodes to be queried */
|
|
} proto_get_whitelist_info_req;
|
|
|
|
/* Structure of the response to the request for reading the whitelist information */
|
|
typedef struct {
|
|
uint16_t total; /* Total number of nodes */
|
|
uint16_t start; /* Start sequence number, starting from 1 */
|
|
uint16_t count; /* Number of nodes to be queried */
|
|
uint16_t reserved;
|
|
uint8_t data[0]; /* Length of the data reported by the current frame */
|
|
} proto_get_whitelist_info_ind;
|
|
|
|
/* Request structure for adding a node to the whitelist */
|
|
typedef struct {
|
|
uint16_t count; /* Number of nodes */
|
|
uint8_t data[0]; /* Whitelist data */
|
|
} proto_add_whitelist_req;
|
|
|
|
/* Response structure for adding a node to the whitelist */
|
|
typedef proto_reply_ind proto_add_whitelist_ind;
|
|
|
|
/* Response structure for deleting a node to the whitelist */
|
|
typedef proto_reply_ind proto_del_whitelist_ind;
|
|
|
|
/* Clear the whitelist response structure. */
|
|
typedef proto_reply_ind proto_clear_whitelist_ind;
|
|
|
|
/* Enable network identify response structure. */
|
|
typedef proto_reply_ind proto_enable_ni_ind;
|
|
|
|
/*whitelist state*/
|
|
typedef struct {
|
|
uint8_t state; /* whitelist state */
|
|
uint8_t rsv[3];
|
|
} proto_get_whitelist_state_ind;
|
|
|
|
/* Request structure for setting whitelist state */
|
|
typedef proto_get_whitelist_state_ind proto_set_whitelist_state_req;
|
|
|
|
/* Response structure for setting whitelist state */
|
|
typedef proto_reply_ind proto_set_whitelist_state_ind;
|
|
|
|
/*
|
|
* Topology operations
|
|
* Read the number of nodes in the topology.
|
|
*/
|
|
typedef proto_get_whitelist_num_ind proto_get_topo_num_ind;
|
|
|
|
/* Structure of the request for reading topology information */
|
|
typedef proto_get_whitelist_info_req proto_get_topo_info_req;
|
|
|
|
/* Structure of the response to the request for reading topology information */
|
|
typedef proto_get_whitelist_info_ind proto_get_topo_info_ind;
|
|
|
|
/* Structure of the response to the request for frequency band */
|
|
typedef struct {
|
|
uint8_t band; /* work band */
|
|
uint8_t rsv[3];
|
|
} proto_get_work_band_ind;
|
|
|
|
/* Request structure for setting frequency band */
|
|
typedef proto_get_work_band_ind proto_set_work_band_req;
|
|
|
|
/* Response structure for setting frequency band */
|
|
typedef proto_reply_ind proto_set_work_band_ind;
|
|
|
|
/* Structure of the response to the request for scan band bitmap */
|
|
typedef struct {
|
|
uint8_t fb_bitmap[IOT_PLC_BAND_BITMAP_SIZE];
|
|
} proto_get_fb_bitmap_ind;
|
|
|
|
/* Request structure for setting scan band bitmap */
|
|
typedef proto_get_fb_bitmap_ind proto_set_fb_bitmap_req;
|
|
|
|
/* Response structure for setting scan band bitmap */
|
|
typedef proto_reply_ind proto_set_fb_bitmap_ind;
|
|
|
|
/* Structure of the response to the request for reading calc data validity */
|
|
typedef struct {
|
|
uint8_t state;
|
|
uint8_t rsv[3];
|
|
} proto_get_calc_vali_ind;
|
|
|
|
/* Structure of the response to the request for uart parameter */
|
|
typedef struct {
|
|
uint32_t baudrate;
|
|
uint8_t data_bits;
|
|
uint8_t stop_bits;
|
|
uint8_t parity;
|
|
uint32_t threshold_value;
|
|
uint8_t rsv;
|
|
} proto_get_uart_param_ind;
|
|
|
|
/* Request structure for setting uart parameter */
|
|
typedef proto_get_uart_param_ind proto_set_uart_param_req;
|
|
|
|
/* Response structure for setting uart parameter */
|
|
typedef proto_reply_ind proto_set_uart_param_ind;
|
|
|
|
/* Structure of the response to the received data */
|
|
typedef proto_reply_ind proto_data_transmit_rx_ind;
|
|
|
|
typedef proto_data_transmit_rx_req proto_remote_cmd_rx_req;
|
|
typedef proto_data_transmit_rx_ind proto_remote_cmd_rx_ind;
|
|
|
|
typedef struct {
|
|
uint8_t mac[IOT_MAC_ADDR_LEN]; /* MAC address */
|
|
uint16_t tei; /* Node ID */
|
|
uint16_t proxy; /* Proxy node ID */
|
|
uint8_t level : 4; /* Network layer: 0 indicates layer 0, and so on. */
|
|
uint8_t role : 4; /* Network role. */
|
|
uint8_t reserved;
|
|
} proto_topo_node;
|
|
|
|
/*
|
|
* Remote commissioning command
|
|
* Remotely send a command.
|
|
*/
|
|
typedef proto_data_transmit_tx_req proto_remote_cmd_tx_req;
|
|
typedef proto_data_transmit_tx_ind proto_remote_cmd_tx_ind;
|
|
|
|
/* PLC frame data structure */
|
|
typedef struct {
|
|
uint16_t crc_16; /* CRC16 check: CRC16-CCITT */
|
|
uint16_t data_length; /* Data field length */
|
|
uint8_t data[0];
|
|
} app_plc_trans_frame;
|
|
|
|
typedef struct {
|
|
uint8_t dev_addr[6]; /* dev mac addr */
|
|
uint8_t status; /* 0:offline, 1:online */
|
|
uint8_t reserved;
|
|
} proto_onoffline_info;
|
|
|
|
/***************************** defination for upgrade ****************/
|
|
|
|
typedef struct {
|
|
uint8_t virsion1; /* virsion1 */
|
|
uint8_t virsion2; /* virsion2 */
|
|
uint16_t seq_num; /* sequence number */
|
|
uint8_t fun_code; /* function code */
|
|
uint8_t status_code; /* status code */
|
|
uint16_t dev_addr; /* device address */
|
|
uint8_t data[0]; /* data body */
|
|
} proto_sysctrl_data_header;
|
|
|
|
#pragma pack(pop) /* restore the pack status */
|
|
|
|
void fill_proto_frame_fixed_info(app_proto_frame_head *head, uint16_t cmd, uint16_t seq, uint16_t data_length);
|
|
uint16_t app_proto_get_nbnet_info(app_proto_frame_head *frame, uint8_t * out_buffer, uint16_t *length);
|
|
uint16_t app_proto_data_transmit(uint8_t * data, uint16_t data_length, uint8_t * src_addr);
|
|
uint16_t app_proto_sysctrl_data_process(uint8_t * data, uint16_t data_length, uint8_t * src_addr, uint8_t * dst_addr);
|
|
uint16_t app_proto_frame_rx(uint8_t * data, uint16_t data_length, app_source_e source, uint8_t * src_addr);
|
|
uint16_t app_proto_onoffline_report(uint8_t *mac, uint8_t flag);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _APP_PROTO_PROC_H_ */
|
|
|