Files
kunlun/export/inc/sg_lib/proto_3762.h
2024-09-28 14:24:04 +08:00

2594 lines
89 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 PROTO_3762_H
#define PROTO_3762_H
#include "os_types_api.h"
#include "iot_utils_api.h"
#include "iot_sg_ext_api.h"
#include "iot_cli_sg_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/* pack for the structures in the whole file */
#pragma pack(push) /* save the pack status */
#pragma pack(1) /* 1 byte align */
#define PROTO_3762_FIX_FIELD_LEN (6)
#define PROTO_3762_FRAME_MIN_LEN (15)
#define PROTO_3762_LENGTH_SIZE (2)
#define PROTO_3762_CTRL_OFFSET (PROTO_3762_LENGTH_SIZE + 1)
#define PROTO_3762_DATA_OFFSET (PROTO_3762_CTRL_OFFSET + 1)
#define PROTO_3762_CHECKSUM_LEN (1)
#define PROTO_3762_BACKCODE_LEN (1)
#define PROTO_3762_MAC_ADDR_LEN (6)
#define PROTO_3762_SOF_BYTE (0x68)
#define PROTO_3762_EOF_BYTE (0x16)
#define PROTO_3762_PHY_TYPE_RESERVE (0)
#define PROTO_3762_PHY_TYPE_C_RCC (1)
#define PROTO_3762_PHY_TYPE_D_RCC (2)
#define PROTO_3762_PHY_TYPE_PLC (3)
#define PROTO_3762_PHY_TYPE_DUAL_MODE (4)
#define PROTO_3762_PHY_TYPE_WIRELESS (10)
#define PROTO_3762_PHY_TYPE_ETHERNET (20)
#define PROTO_3762_COMM_TYPE_NARROWBAND (1)
#define PROTO_3762_COMM_TYPE_BROADBAND (2)
#define PROTO_3762_COMM_TYPE_MICRO_WIRL (3)
#define PROTO_3762_COMM_TYPE_DUAL_MODE (4)
#define PROTO_3762_DIR_DOWN_LINK (0)
#define PROTO_3762_DIR_UP_LINK (1)
#define PROTO_3762_PRM_MASTER (1)
#define PROTO_3762_PRM_SLAVE (0)
#define PROTO_3762_DEV_TYPE_COLLECTOR (0)
#define PROTO_3762_DEV_TYPE_METER (1)
#define PROTO_3762_DEV_TYPE_STA (2)
/* pw device type */
#define PROTO_3762_DEV_TYPE_BRANCH_MONITOR (0xF0)
#define PROTO_3762_DEV_TYPE_BREAKER (0xF1)
/* app function number definition */
#define PROTO_3762_AFN_00 (0x00)
#define PROTO_3762_AFN_01 (0x01)
#define PROTO_3762_AFN_02 (0x02)
#define PROTO_3762_AFN_03 (0x03)
#define PROTO_3762_AFN_04 (0x04)
#define PROTO_3762_AFN_05 (0x05)
#define PROTO_3762_AFN_06 (0x06)
#define PROTO_3762_AFN_10 (0x10)
#define PROTO_3762_AFN_11 (0x11)
#define PROTO_3762_AFN_12 (0x12)
#define PROTO_3762_AFN_13 (0x13)
#define PROTO_3762_AFN_14 (0x14)
#define PROTO_3762_AFN_15 (0x15) /* only for 1367.2 */
#define PROTO_3762_AFN_20 (0x20)
#define PROTO_3762_AFN_EA (0xEA)
#define PROTO_3762_AFN_EB (0xEB)
#define PROTO_3762_AFN_EC (0xEC)
#define PROTO_3762_AFN_ED (0xED)
#define PROTO_3762_AFN_F0 (0xF0) /* debug AFN */
#define PROTO_3762_AFN_F1 (0xF1) /* only for sg supplement */
#define PROTO_3762_AFN_F2 (0xF2)
/* function code for each command */
#define PROTO_3762_FN_INVALID (0)
#define PROTO_3762_F1 (1)
#define PROTO_3762_F2 (2)
#define PROTO_3762_F3 (3)
#define PROTO_3762_F4 (4)
#define PROTO_3762_F5 (5)
#define PROTO_3762_F6 (6)
#define PROTO_3762_F7 (7)
#define PROTO_3762_F8 (8)
#define PROTO_3762_F9 (9)
#define PROTO_3762_F10 (10)
#define PROTO_3762_F11 (11)
#define PROTO_3762_F12 (12)
#define PROTO_3762_F13 (13)
#define PROTO_3762_F14 (14)
#define PROTO_3762_F16 (16)
#define PROTO_3762_F17 (17)
#define PROTO_3762_F18 (18)
#define PROTO_3762_F19 (19)
#define PROTO_3762_F20 (20)
#define PROTO_3762_F21 (21)
#define PROTO_3762_F27 (27)
#define PROTO_3762_F30 (30)
#define PROTO_3762_F31 (31)
#define PROTO_3762_F32 (32)
#define PROTO_3762_F33 (33)
#define PROTO_3762_F40 (40)
#define PROTO_3762_F41 (41)
#define PROTO_3762_F56 (56)
#define PROTO_3762_F80 (80)
#define PROTO_3762_F81 (81)
#define PROTO_3762_F82 (82)
#define PROTO_3762_F90 (90)
#define PROTO_3762_F92 (92)
#define PROTO_3762_F93 (93)
#define PROTO_3762_F94 (94)
#define PROTO_3762_F100 (100)
#define PROTO_3762_F101 (101)
#define PROTO_3762_F102 (102)
#define PROTO_3762_F103 (103)
#define PROTO_3762_F104 (104)
#define PROTO_3762_F106 (106)
#define PROTO_3762_F111 (111)
#define PROTO_3762_F112 (112)
#define PROTO_3762_F120 (120)
#define PROTO_3762_F121 (121)
#define PROTO_3762_F126 (126)
#define PROTO_3762_F127 (127)
#define PROTO_3762_F130 (130)
#define PROTO_3762_F131 (131)
#define PROTO_3762_F150 (150)
#define PROTO_3762_F200 (200)
#define PROTO_3762_F201 (201)
#define PROTO_3762_F225 (225)
#define PROTO_3762_F230 (230)
#define PROTO_3762_F231 (231)
#define PROTO_3762_F232 (232)
#define PROTO_3762_F255 (255)
#define WORK_STATE_RNNING (0)
#define WORK_STATE_PAUSED (1)
#define PROTO_3762_2013_START_CHAR 0x68
#define PROTO_3762_2013_END_CHAR 0x16
/* invalid segment index. In 15H01F up link. */
#define PROTO_3762_INVALID_SEG_INDEX 0xFFFF
/* default channel state */
#define PROTO_3762_DEFAULT_CH_STATE 0x0
/* hunan channel state */
#define PROTO_3762_HUNAN_CH_STATE 0xFFFE
/* wait 0 seconds by default */
#define PROTO_3762_DEFAULT_WAIT_TIME (0)
/* wait 5 * 30 seconds for setting band */
#define PROTO_3762_SET_BAND_WAIT_TIME (5 * 60)
#define PROTO_3762_READ_PM_FAILED (0)
#define PROTO_3762_READ_PM_SUCCEED (1)
#define PROTO_3762_MAY_READ_PM (2)
#define PROTO_3762_DATETIME_LEN (6)
#define PROTO_3762_NID_LEN (3)
#define PROTO_3762_COMM_DELAY (1) // comm delay in seconds
#define PROTO_3762_15H_CLEAR_FILE (0x00)
#define PROTO_3762_15H_UPGRADE_LOCAL_MODULE (0x03)
#define PROTO_3762_15H_UPGRADE_STA_MODULE_ZHHW (0x04)
#define PROTO_3762_15H_UPGRADE_CCO_STA_MODULE (0x07)
#define PROTO_3762_15H_UPGRADE_STA_MODULE (0x08)
#define PROTO_3762_2013_READ_METER_STOP (0x01)
#define PROTO_3762_2013_SEARCH_METER_STOP (0x02)
#define PROTO_3762_2013_TSFM_DETECT_STOP (0x03)
/* defines secondary node registration time unit(1min), uins is 1s */
#define PROTO_3762_SEC_NODE_REG_TIME_UNIT_DUR (60)
#define PROTO_3762_CHIP_ID_SERIAL_NUM_LEN (5)
#define PROTO_3762_CHIP_ID_CRC_LEN (8)
/* proto 03f11 fn buf length */
#define PROTO_3762_03F11_FNLEN (32)
#define PROTO_3762_03F11_FNLEN_BITS (PROTO_3762_03F11_FNLEN << 3)
/* proto 10f100 network size */
#define PROTO_3762_10F100_MIN_NW_SIZE (2)
#define PROTO_3762_10F100_MAX_NW_SIZE (512)
#define PROTO_3762_10F100_DEFAULT_NW_SIZE (256)
/********* TSFM state of station define for hebei province *********/
/* different transformer and in white list */
#define PROTO_3762_HEBEI_PM_TO_TSFM_1 (1)
/* same transformer and not in white list */
#define PROTO_3762_HEBEI_PM_TO_TSFM_2 (2)
#define PROTO_3762_PRIM_VER_LEN (3)
/* device type defined in sx protocol */
/* invaild type */
#define PROTO_3762_DEV_TYPE_INVAILD (0)
/* meter controller */
#define PROTO_3762_DEV_TYPE_METER_CONTROLLER (1 << 0)
/* concentrator */
#define PROTO_3762_DEV_TYPE_CONCENTRATOR (1 << 1)
/* power meter */
#define PROTO_3762_DEV_TYPE_POWER_METER (1 << 2)
/* repeater */
#define PROTO_3762_DEV_TYPE_REPEATER (1 << 3)
/* collector II */
#define PROTO_3762_DEV_TYPE_COLLECTOR_2 (1 << 4)
/* collector I */
#define PROTO_3762_DEV_TYPE_COLLECTOR_1 (1 << 5)
/* tsfm detector */
#define PROTO_3762_DEV_TYPE_TSFM_DETECTOR (1 << 6)
/* bimodule */
#define PROTO_3762_DEV_TYPE_BIMODULE (1 << 7)
/* 485 meter */
#define PROTO_3762_DEV_TYPE_485_METER (1 << 8)
/* three phase power meter */
#define PROTO_3762_DEV_TYPE_POWER_METER_3P (1 << 9)
/* station dynamic state change type define in sx protocol */
#define PROTO_3762_STATE_OFFLINE_TO_ONLINE (0)
#define PROTO_3762_STATE_ONLINE_TO_OFFLINE (1)
/* alternate response 03hf1 with month and without month count */
#define PROTO_3762_ALTERNATE_RSP_03HF1_CNT 3
/* module id type */
#define PROTO_3762_MODULE_ID_TYPE_COMBINATION 0
#define PROTO_3762_MODULE_ID_TYPE_BCD 1
#define PROTO_3762_MODULE_ID_TYPE_BIN 2
#define PROTO_3762_MODULE_ID_TYPE_ASCII 3
/* module device type */
#define PROTO_3762_MODULE_DEV_TYPE_METER 0
#define PROTO_3762_MODULE_DEV_TYPE_COLLECTOR 1
#define PROTO_3762_MODULE_DEV_TYPE_UNKNOWN 15
/* module id information length */
#define PROTO_3762_MODULE_ID_INFO_LEN (11)
#define PROTO_3762_CHIP_ID_INFO_LEN (24)
/* id information type */
#define PROTO_3762_ID_INFO_TYPE_CHIP 1
#define PROTO_3762_ID_INFO_TYPE_MOD 2
/* node device type for 10H_F40 */
#define PROTO_3762_NODE_DEV_TYPE_METER_CONTROLLER 1
#define PROTO_3762_NODE_DEV_TYPE_CONCENTRATOR 2
#define PROTO_3762_NODE_DEV_TYPE_POWER_METER 3
#define PROTO_3762_NODE_DEV_TYPE_REPEATER 4
#define PROTO_3762_NODE_DEV_TYPE_COLLECTOR_2 5
#define PROTO_3762_NODE_DEV_TYPE_COLLECTOR_1 6
/* event type for other */
#define PROTO_3762_EVENT_NORMAL (0)
#define PROTO_3762_EVENT_POWER_DOWN (1)
#define PROTO_3762_EVENT_POWER_UP (2)
#define PROTO_3762_EVENT_POWER_DOWN_C (3)
#define PROTO_3762_EVENT_POWER_UP_C (4)
/* channel feature */
/* 1 phase power supply, 1 logical channel. */
#define PROTO_3762_PM_CH_FR_1PWR_1CH 1
/* 1 phase power supply, 2 logical channel. */
#define PROTO_3762_PM_CH_FR_1PWR_2CH 2
/* 1 phase power supply, 3 logical channel. */
#define PROTO_3762_PM_CH_FR_1PWR_3CH 3
/* 3 phase power supply, 3 logical channel. */
#define PROTO_3762_PM_CH_FR_3PWR_3CH 4
/* max report node count */
#define PROTO_3762_MAX_RPT_NODE_CNT 64
#define PROTO_3762_MODULE_ID_RPT_MAX_CNT 32
#define PROTO_3762_TOPO_RPT_MAX_CNT 64
/* max report topo info node count of sxhw and hx */
#define PROTO_3762_TOPO_RPT_MAX_CNT_SXHW_AND_HX 36
/* signal attenuation invalid value of sxhw */
#define PROTO_3762_INVALID_ATT_VALUE_SXHW 127
/* max set blacklist count */
#define PROTO_3762_BL_KICKOUT_METER_CNT 36
/* max set vendor device sn length of sxhw */
#define PROTE_3762_VENDOR_DEVICE_SN_LEN_MAX 32
/* CJ/T 188-2004 mac address length */
#define PROTO_3762_188_ADDR_LEN 7
/* meter time length */
#define PROTO_3762_188_METER_TIME_LEN 6
/* meter accumulative value length */
#define PROTO_3762_188_METER_ACC_VAL_LEN 4
/* transformer detect timeout for beijing, unit is 1s */
#define PROTO_3762_TSFM_DETECT_TIMEOUT_BEIJING (6 * 60 * 60)
/* set tsfm addr command type */
#define PROTO_3762_TSFM_ADDR_CMD_SET 0
#define PROTO_3762_TSFM_ADDR_CMD_DEL 1
/* secondary node network lock command type */
#define PROTO_3762_SEC_NODE_NW_CMD_LOCK 0
#define PROTO_3762_SEC_NODE_NW_CMD_UNLOCK 1
/* whole network set mode */
#define PROTO_3762_NW_SET_MODE_SINGLE (0x00)
#define PROTO_3762_NW_SET_MODE_ALL (0x01)
/* firmware sha1 check code value length */
#define PROTO_3762_SHA1_CHECK_LEN (20)
#define PRPTO_3762_ZHHW_AUTO_REG_ACTIVE_WHITELIST (0x5A)
#define PRPTO_3762_ZHHW_AUTO_REG_ACTIVE (0x5F)
/* sta collect parameter v2.8 task configuration result */
#define PRPTO_3762_CURVE_DATA_RET_SUCCESS (0)
#define PRPTO_3762_CURVE_DATA_RET_TASK_NO_EXIST (1)
#define PRPTO_3762_CURVE_DATA_RET_REPEAT (2)
#define PRPTO_3762_CURVE_DATA_RET_PROTO_INVALID (3)
#define PRPTO_3762_CURVE_DATA_RET_TASK_ERROR (4)
#define PRPTO_3762_CURVE_DATA_RET_CONF_DATA_ERROR (5)
/* sta collect parameter v2.8 task configuration node addr result */
#define PRPTO_3762_CURVE_DATA_NODE_RET_SUCCESS (0)
#define PRPTO_3762_CURVE_DATA_NODE_RET_TASK_INVALID (1)
#define PRPTO_3762_CURVE_DATA_NODE_RET_ADDR_INVALID (2)
/* sta collect parameter v2.8 task max task id */
#define PRPTO_3762_CURVE_DATA_MAX_TASK_ID (7)
#define PRPTO_3762_CURVE_DATA_ALL_TASK_ID (0xFF)
/* flag of minute collection config for v2.8-2 */
#define PRPTO_3762_MIN_CLCT_RPT_CFG_FLAG_INVALID (0)
#define PRPTO_3762_MIN_CLCT_RPT_CFG_FLAG_VALID (1)
/* minute collection config state for v2.8-2 */
#define PRPTO_3762_MIN_CLCT_CFG_SUCCESS (0)
#define PRPTO_3762_MIN_CLCT_CFG_FAIL (1)
/* set force link type for 3762 */
#define PROTO_3762_FORCE_LINK_TYPE_MIX (0)
#define PROTO_3762_FORCE_LINK_TYPE_HPLC (1)
#define PROTO_3762_FORCE_LINK_TYPE_RF (2)
typedef struct _module_hw_info {
uint16_t vendor_id; /* manufacture code */
uint16_t chip_code; /* chip code */
uint8_t day; /* day in BCD */
uint8_t month; /* month in BCD */
uint8_t year; /* year in BCD */
uint8_t version[2]; /* version in BCD */
}mod_hw_info_t;
typedef struct _module_hw_info_without_month {
uint16_t vendor_id; /* manufacture code */
uint16_t chip_code; /* chip code */
uint8_t day; /* day in BCD */
uint8_t year; /* year in BCD */
uint8_t version[2]; /* version in BCD */
}mod_hw_info_without_month_t;
typedef struct _proto_3762_ctrl {
uint8_t phy_type : 6; /* bit 0 - bit 5 */
uint8_t prm : 1; /* bit 6 */
uint8_t dir : 1; /* bit 7 */
}proto_3762_ctrl_t;
/* fixed resource info field for down link */
typedef struct _info_dl {
/* byte 1 */
uint8_t route_flag : 1; /* bit0: 0 - has route module; */
uint8_t has_sub_node : 1; /* bit1 */
uint8_t comm_module : 1; /* bit2: 0 - concentrator; 1 - meter */
uint8_t conflict_detect : 1;/* bit3: conflict detect flag*/
uint8_t rpter_level : 4; /* bit4 - bit 7: level of repeater */
/* byte 2 */
uint8_t channel_id : 4; /* bit0 - bit3 */
uint8_t ecc_type : 4; /* bit4 - bit7: error correcting code type
0 - no coding; 1 - RS coding*/
/* byte 3 */
uint8_t rsp_len; /* estimated length of response */
/* byte 4-5 */
uint16_t baud_rate : 15; /* bit0 - bit14*/
uint16_t rate_unit : 1; /* bit15: 0 - bps; 1 - kbps */
/* byte 6 */
uint8_t sn; /* sequence number for this packet*/
}dl_info_t;
/* fixed resource info field for up link */
typedef struct _info_ul {
/* byte 1 */
uint8_t route_flag : 1; /* bit0: 0 - has route module; */
uint8_t dummy1 : 1; /* bit1: dummy */
uint8_t comm_module : 1; /* bit2: 0 - concentrator; 1 - meter */
uint8_t dummy2 : 1; /* bit3: dummy */
uint8_t rpter_level : 4; /* bit4 - bit7: level of repeater */
/* byte 2 */
uint8_t channel_id : 4; /* bit0 - bit3 */
uint8_t dummy3 : 4; /* bit4 - bit7: dummy */
/* byte 3 */
uint8_t phy_phase : 4; /* bit0 - bit3: physical phase */
uint8_t meter_ch_ftr : 4; /* bit4 - bit7: meter channel feature */
/* byte 4 */
uint8_t cmd_snr : 4; /* bit0 - bit3 */
uint8_t rsp_snr : 4; /* bit4 - bit7 */
/* byte 5 */
uint8_t event_flag : 1; /* bit0 */
uint8_t line_flag : 1; /* bit1 */
uint8_t tsfm_status : 3; /* bit2 - bit4: transformer's status */
uint8_t reserved : 3; /* bit5 - bit7: reserved */
uint8_t sn; /* sequence number for the packet */
}ul_info_t;
/* structure of 376.2 frame
-------------
|----68H----| start of frame, 0x68
|----Len----| 2 byte for 376.2-2009, 2 byte for 376.2-2013
|----Ctrl---| 1 byte of control
|----Data---| data. length is variable
|----CS-----| checksum
|----16H----| end of frame, 0x16
-------------
*/
typedef struct _user_data {
union info {
dl_info_t dl_info;
ul_info_t ul_info;
}res;
uint8_t data[0];
}user_data_t;
typedef struct _pkt_3762_hdr {
uint8_t sof_byte;
uint16_t len;
proto_3762_ctrl_t ctrl_byte;
user_data_t user_data;
} pkt_3762_hdr_t;
typedef struct _proto_3762_app_data {
uint8_t afn;
uint16_t fn;
uint8_t data[0];
} proto_3762_app_data_t;
/* data struct for AFN 00 */
typedef struct _afn00_fn01_conf_09 {
/* 0 - cmd NOT handled. 1 - cmd handled. */
uint16_t cmd_state : 1;
/* 0 - channel is busy. 1 - idle */
uint16_t ch1_state : 1;
uint16_t ch2_state : 1;
uint16_t ch3_state : 1;
uint16_t ch4_state : 1;
uint16_t ch5_state : 1;
uint16_t ch6_state : 1;
uint16_t ch7_state : 1;
uint16_t ch8_state : 1;
uint16_t ch9_state : 1;
uint16_t ch10_state : 1;
uint16_t ch11_state : 1;
uint16_t ch12_state : 1;
uint16_t ch13_state : 1;
uint16_t ch14_state : 1;
uint16_t ch15_state : 1;
/* wait timeout limit in second */
uint16_t wait_duration;
}afn00_fn01_conf_09_t;
/* data struct for AFN 00 */
typedef struct _afn00_fn01_conf_13 {
/* 0 - cmd NOT handled. 1 - cmd handled. */
uint16_t cmd_state : 1;
/* 0 - channel is busy. 1 - idle */
uint16_t ch1_state : 1;
uint16_t ch2_state : 1;
uint16_t ch3_state : 1;
uint16_t ch4_state : 1;
uint16_t ch5_state : 1;
uint16_t ch6_state : 1;
uint16_t ch7_state : 1;
uint16_t ch8_state : 1;
uint16_t ch9_state : 1;
uint16_t ch10_state : 1;
uint16_t ch11_state : 1;
uint16_t ch12_state : 1;
uint16_t ch13_state : 1;
uint16_t ch14_state : 1;
uint16_t ch15_state : 1;
uint16_t reserved;
/* wait timeout limit in second */
uint16_t wait_duration;
}afn00_fn01_conf_13_t;
/* error no for reject packet */
#define COMM_TIMEOUT 0
#define INVALID_DATA 1
#define INVALID_DATA_LEN 2
#define VALIDATE_FAILED 3
#define INFO_TYPE_NOT_EXIST 4
#define INVALID_FORMAT 5
#define METER_NO_DUPLICATED 6
#define METER_NO_NOT_EXIST 7
#define METER_APP_NO_RSP 8
#define MASTER_IS_BUSY 9
#define MASTER_UNSUPPORTED_CMD 10
#define SLAVE_NO_RSP 11
#define SLAVE_NOT_IN_NW 12
#define EXCEED_MAX_CONCURRENT_COUNT 109
#define EXCEED_MAX_PKT_COUNT 110
#define METER_ALREADY_EXIST 111
#define PROTO_TYPE_RAW_DATA (0x00) /* transparent transmission */
#define PROTO_TYPE_645_1997 (0x01) /* 645 protocol, version 1997 */
#define PROTO_TYPE_645_2007 (0x02) /* 645 protocol, version 2007 */
#define PROTO_TYPE_698_45 (0x03) /* 698.45 protocol */
#define PROTO_TYPE_POWER_EVT (0x04) /* power down and power up event */
#define PROTO_TYPE_RPT_MOD_WM (0x04) /* report model water meter */
#define PROTO_TYPE_MR_MOD_WM (0x05) /* real-time MR model water meter */
#define PROTO_TYPE_GAS_METER (0x06) /* gas meter */
#define PROTO_TYPE_HEAT_METER (0x07) /* heat meter */
#define PROTO_TYPE_RSVD (0xFF) /* reserved */
/* route type: local module does not support route management */
#define RT_TYPE_LOCAL_NO_ROUTE_MNGT 0
/* route type: local module support route management */
#define RT_TYPE_LOCAL_ROUTE_MNGT 1
/* don't distribute slave info */
#define SLAVE_INFO_NO_DISTRUBITE 0
/* distribute slave info */
#define SLAVE_INFO_DISTRUBITE 1
/* type of meter checking period */
#define CHECK_PERIOD_CNCENTR 1
#define CHECK_PERIOD_ROUTER 2
#define CHECK_PERIOD_BOTH 3
/* uart baud rate number */
#define PROTO_3762_UART_BAUD_NUM_9600 (0)
#define PROTO_3762_UART_BAUD_NUM_19200 (1)
#define PROTO_3762_UART_BAUD_NUM_38400 (2)
#define PROTO_3762_UART_BAUD_NUM_57600 (3)
#define PROTO_3762_UART_BAUD_NUM_115200 (4)
/* data struct for AFN 02, fn 01. It's for both up link and down link */
typedef struct _afn02_fn01_data_fwd {
uint8_t proto_type;
uint8_t len;
uint8_t data[0];
}afn02_fn01_data_fwd_t;
typedef struct _afn02_fn02_data_fwd {
uint8_t proto_type;
uint16_t len;
uint8_t data[0];
}afn02_fn02_data_fwd_t;
typedef struct _afn00_fn02_reject {
uint8_t err_no;
}afn00_fn02_reject_t;
typedef struct _afn03_fn01_hw_info_without_month {
mod_hw_info_without_month_t info;
}afn03_fn01_hw_info_without_month_t;
typedef struct _afn03_fn01_hw_info {
mod_hw_info_t info;
}afn03_fn01_hw_info_t;
typedef struct _afn03_fn02_noise {
uint8_t noise : 4; /* noise level. 0 - 15 */
uint8_t reserved : 4;
}afn03_fn02_noise_t;
/* data struct for AFN 03 */
typedef struct _afn03_fn03_slave_listen_info_req {
uint8_t start_index;
uint8_t node_count;
}afn03_fn03_slave_listen_info_req_t;
typedef struct _slave_listen_info {
uint8_t mac[PROTO_3762_MAC_ADDR_LEN];
uint8_t repeater_level : 5;
uint8_t signal_level : 3;
uint8_t listen_count : 5;
uint8_t reserved : 3;
}slave_info_t;
typedef struct _afn03_fn03_slave_listen_info_rsp {
uint8_t slave_count;
uint8_t listend_slave_count;
slave_info_t info[0];
}afn03_fn03_slave_listen_info_rsp_t;
typedef struct _afn03_fn04_cco_mac {
uint8_t cco_mac[IOT_MAC_ADDR_LEN];
}afn03_fn04_cco_mac_t;
typedef struct _afn03_fn08_info_wf {
uint8_t channel_group;
uint8_t trans_power;
}afn03_fn08_info_wf_t;
typedef struct _data_rate {
uint16_t rate : 15;
uint16_t unit : 1;
}data_rate_t;
typedef struct _afn03_fn05_module_status_baudrate {
/* byte 1 */
uint8_t baudrate_num : 4;
uint8_t cco_channel_type : 2;
uint8_t check_period_type : 2;
/* byte 2 */
uint8_t channel_count : 4;
uint8_t reserved : 4;
data_rate_t data_rate; /*here we only support one rate*/
}afn03_fn05_module_status_baudrate_t;
typedef struct _afn03_fn06_master_interfere {
uint8_t duration;
}afn03_fn06_master_interfere_t;
typedef struct _afn03_fn08_wireless_param {
uint8_t channel_id;
uint8_t transmit_power;
}afn03_fn08_wireless_param_t;
typedef struct _afn03_fn09_data_len_query_dl {
uint8_t proto_type;
uint8_t frame_len;
uint8_t frame_data[0];
}afn03_fn09_data_len_query_dl_t;
typedef struct _afn03_fn09_data_len_query_ul {
uint16_t bacast_delay_time;
uint8_t proto_type;
uint8_t frame_len;
uint8_t frame_data[0];
}afn03_fn09_data_len_query_ul_t;
typedef struct _afn03_fn10_module_work_mode {
uint8_t phy_type : 4;
uint8_t route_type : 1;
uint8_t sec_node_info_type : 1;
uint8_t meter_read_mode : 2;
uint8_t defer_send_support : 3;
uint8_t failed_node_switch : 2;
uint8_t bcast_cmd_ack_type : 1;
uint8_t bcast_cmd_exe_type : 2;
uint8_t ch_count : 5;
uint8_t low_vol_grid_failed : 3;
uint8_t rate_count : 4,
/* minute collect flag for jiangsu */
js_minute_clct : 1,
/* gw v2.8 minute collect flag */
v28_minute_clct : 1,
reserved1 : 2;
uint16_t reserved2;
/* should be 1 byte which is different with 13 spec */
uint8_t node_monitor_max_dur;
uint16_t bcast_cmd_max_dur;
uint16_t datagram_mtu;
uint16_t file_send_mtu;
uint8_t upgrade_wait_dur;
uint8_t cco_mac[IOT_MAC_ADDR_LEN];
uint16_t sec_node_cnt_max;
uint16_t sec_node_cnt;
uint8_t proto_rel_date[3];
uint8_t proto_file_date[3];
mod_hw_info_t hw_info;
data_rate_t data_rate[0];
}afn03_fn10_mod_work_mode_t;
typedef struct _afn03_fn11_afn_query_dl {
uint8_t afn_index;
}afn03_fn11_afn_query_dl_t;
typedef struct _afn03_fn11_afn_query_ul {
uint8_t afn_index;
uint8_t fn_buf[PROTO_3762_03F11_FNLEN];
}afn03_fn11_afn_query_ul_t;
/* chip id information */
typedef struct _proto_3762_chip_id {
/* check code */
uint8_t check_code[PROTO_3762_CHIP_ID_CRC_LEN];
/* device serial */
uint8_t dev_code[PROTO_3762_CHIP_ID_SERIAL_NUM_LEN];
/* chip mode */
uint16_t chip_mode;
/* 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;
} proto_3762_chip_id_t;
typedef struct _proto_3762_module_info {
/* module manufacture code */
uint16_t module_mf_code;
/* module id length */
uint8_t module_id_len;
/* module id type, see PROTO_3762_MODULE_ID_TYPE_XXX */
uint8_t module_id_type;
/* module id information */
//uint8_t module_id_info[0];
} proto_3762_module_info_t;
typedef struct _afn03_fn12_main_node_query_ul {
proto_3762_module_info_t info;
}afn03_fn12_main_node_query_ul_t;
typedef struct _afn03_fn16_query_freq_band {
uint8_t freq_band;
}afn03_fn16_query_freq_band_t;
typedef struct _afn03_fn17_query_rf_channel {
/* rf option */
uint8_t option;
/* rf channel */
uint8_t channel;
/* flag to mark if enable rf channel coordination */
uint8_t rf_cod_enable;
}afn03_fn17_query_rf_channel_t;
typedef struct _afn03_fn17_query_vendor_device_sn_ul {
/* vendor device sn length, max length is 32 */
uint8_t sn_len;
/* vendor device sn info */
uint8_t vendor_device_sn[0];
}afn03_fn17_query_vendor_device_sn_ul_t;
typedef struct _afn03_fn18_query_force_link_type_ul {
/* force link type, 0 - defaule, 1 - force hplc, 2 - force rf */
uint8_t link_type;
}afn03_fn18_query_force_link_type_ul_t;
typedef struct _afn03_fn21_query_node_info_dl {
/* node address, little-endian */
uint8_t addr[IOT_MAC_ADDR_LEN];
}afn03_fn21_query_node_info_dl_t;
typedef struct _afn03_fn21_query_node_info_ul {
/* node information */
mod_hw_info_t info;
}afn03_fn21_query_node_info_ul_t;
typedef struct _afn03_fn30_query_lock_time_ul {
/* net lock time, uint is 1min. 0 means no lock. */
uint16_t net_lock_time;
/* the lock time of abnormal leave net, uint is 1min. 0 means no lock. */
uint16_t abn_lock_time;
} afn03_fn30_query_lock_time_ul;
typedef struct _afn03_fn56_query_uart_conf_ul {
/* uart config baud rate type */
uint8_t baud;
/* uart config max baud rate */
uint8_t max_baud;
/* auto recover default baud rate time, unit is 1min */
uint16_t rec_time;
} afn_03_fn56_query_uart_conf_ul_t;
typedef struct _afn03_fn112_query_chip_info_dl {
/* start index, 1 means major node */
uint16_t start_index;
/* query count */
uint8_t node_count;
} afn03_fn112_query_chip_info_dl_t;
/* node hardware information */
typedef struct _node_hw_info {
/* mac address, little endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* device type, see IOT_PLC_DEV_TYPE_XXX */
uint8_t dev_type;
/* chip id information */
proto_3762_chip_id_t chip_id;
/* software version */
uint16_t sw_version;
} node_hw_info_t;
typedef struct _afn03_fn112_query_chip_info_ul {
/* total count */
uint16_t total_node_cnt;
/* start index */
uint16_t start_index;
/* report count */
uint8_t ack_node_count;
/* node information */
node_hw_info_t node_info[0];
} afn03_fn112_query_chip_info_ul_t;
typedef struct _afn04_fn03_comm_test {
uint8_t rate_test;
uint8_t mac[IOT_MAC_ADDR_LEN];
uint8_t proto_type;
uint8_t data_len;
uint8_t data[0];
}afn04_fn03_comm_test_t;
typedef struct _afn05_fn01_set_master_address_req {
uint8_t mac[PROTO_3762_MAC_ADDR_LEN];
}afn05_fn01_set_master_address_req_t;
typedef struct _afn05_fn02_set_sec_node_rpt {
uint8_t rpt_allowed;
}afn05_fn02_set_sec_node_rpt_t;
typedef struct _datagram {
uint8_t data_len;
uint8_t data[0];
}datagram_t;
typedef struct _datagram2 {
uint16_t data_len;
uint8_t data[0];
}datagram2_t;
typedef struct _afn05_fn03_start_broadcast_req {
uint8_t proto_type;
datagram_t datagram; /* datagram to be broad cast */
}afn05_fn03_start_broadcast_req_t;
typedef struct _afn05_fn03_start_broadcast_req_zhhw {
uint8_t proto_type;
datagram2_t datagram; /* datagram to be broad cast */
}afn05_fn03_start_broadcast_req_zhhw_t;
typedef struct _afn05_fn04_set_sec_node_max_dur {
uint8_t max_dur;
}afn05_fn04_set_sec_node_max_dur_t;
typedef struct _afn05_fn04_set_auto_reg_active {
/* 0x5A - whitelist model,
* 0x5F and others - auto register active model(default)
* see PRPTO_3762_ZHHW_AUTO_REG_ACTIVE_XXX.
*/
uint8_t auto_reg_active;
}afn05_fn04_set_auto_reg_active_t;
typedef struct _afn05_fn06_tsfm_detect {
/* 0 - disable, 1 - enable */
uint8_t enabled;
}afn05_fn06_tsfm_detect_t;
typedef struct _afn05_fn10_set_serial_comm_rate {
/* serial communication rate number, see PROTO_3762_UART_BAUD_NUM_XXXX */
uint8_t comm_rate_num;
} afn05_fn10_set_serial_rate_t;
typedef struct _afn05_fn16_set_carrier_comm_para {
uint8_t freq_band;
}afn05_fn16_set_carrier_comm_para_t;
typedef struct _afn05_fn17_set_rf_band {
/* rf option */
uint8_t option;
/* rf channel */
uint8_t channel;
/* flag to mark if enable rf channel coordination */
uint8_t rf_cod_enable;
} afn05_fn17_set_rf_band_t;
typedef struct _afn05_fn18_set_force_link_type {
/* force link type, 0 - defaule, 1 - force hplc, 2 - force rf */
uint8_t link_type;
} afn05_fn18_set_force_link_type_t;
typedef struct _afn05_fn18_bl_kickout_meter {
/* node count */
uint8_t node_count;
/* node mac */
uint8_t node_mac[0][IOT_MAC_ADDR_LEN];
} afn05_fn18_bl_kickout_meter_t;
typedef struct _afn05_fn19_set_vendor_device_sn_info {
/* sxhw vendor device sn length */
uint8_t vendor_device_sn_len;
/* sxhw vendor device sn info */
uint8_t vendor_device_sn_info[0];
} afn05_fn19_set_vendor_device_sn_info_t;
/* transformer detect set lock time for zhejiang */
typedef struct _afn05_fn30_tsfm_detect_lock_set {
/* net lock time, uint is 1min.
* 0 means no lock.
*/
uint16_t net_lock_time;
/* the lock time of abnormal leave net, uint is 1min.
* 0 means no lock.
*/
uint16_t abn_lock_time;
} afn05_fn30_tsfm_detect_lock_set_t;
typedef struct _afn05_fn80_set_force_link_type {
/* link communication type, see PROTO_3762_FORCE_LINK_TYPE_XXX */
uint8_t link_type;
} afn05_fn80_set_force_link_type_t;
typedef struct _afn05_fn81_set_rf_band {
/* rf option */
uint8_t option;
/* rf channel */
uint8_t channel;
} afn05_fn81_set_rf_band_t;
typedef struct _afn05_fn90_clock_manager_set {
/* node addr, little endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* cmd type, 1 - auto correct time */
uint8_t cmd_type;
/* cmd state, 0 - disable, 1 - enable */
uint8_t cmd_state;
} afn05_fn90_clock_manager_set_t;
typedef struct _afn05_fn92_accurate_correct_time {
/* node addr, little endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* data len */
uint16_t data_len;
/* data */
uint8_t data[0];
} afn05_fn92_accurate_correct_time_t;
typedef struct _afn05_fn93_set_corr_time_period {
/* clock manager correct time period, unit is 1min */
uint16_t period;
} afn05_fn93_set_corr_time_period_t;
typedef struct _afn05_fn94_clock_err_threshold_set {
/* node addr, little endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* clock error report threshold, unit is 1min */
uint8_t threshold;
} afn05_fn94_clock_err_threshold_set_t;
typedef struct _afn05_fn102_correct_para {
/* broadcast period */
uint8_t bcast_period;
/* broadcast period unit, 1 is min, 2 is hour */
uint8_t period_unit;
}afn05_fn102_correct_para_t;
/* di and result length */
typedef struct _proto_3762_di_info {
/* di */
uint32_t di;
/* meter reading result length */
uint8_t di_result_len;
} proto_3762_di_info_t;
typedef struct _proto_3762_meter_clct_param {
/* 0 - single phase meter, 1 - three phase meter */
uint8_t pm_type;
/* di count of single phase meter */
uint8_t di_cnt;
/* di result total length of single phase meter */
uint8_t di_result_len;
/* di information of single phase meter */
proto_3762_di_info_t di_info[0];
} proto_3762_meter_clct_param_t;
typedef struct _proto_3762_meter_clct_param_v28 {
/* 0 - single phase meter, 1 - three phase meter */
uint8_t pm_type;
/* di count of single phase meter */
uint8_t di_cnt;
/* di result total length of single phase meter */
uint16_t di_result_len;
/* di information of single phase meter */
proto_3762_di_info_t di_info[0];
} proto_3762_meter_clct_param_v28_t;
/* sta collect parameter */
typedef struct _afn05_fn103_sta_curve_data {
/* 0 - disabled, 1 - enabled */
uint8_t enabled;
/* unit is 1min */
uint8_t clct_period;
/* 2 - DL/T645-2007, 3 - DL/T698.45, other - reserve, see PROTO_TYPE_XXX */
uint8_t proto_type;
/* collect parameter */
//proto_3762_meter_clct_param_t clct_param[0];
} afn05_fn103_sta_curve_data_t;
/* configure abnormal electric current event report */
typedef struct _afn05_fn104_nli_abnormal_cfg {
/* abnormal report enable flag, 0 - disable, 1 - enable */
uint8_t enable;
} afn05_fn104_nli_abnormal_cfg_t;
/* transformer detect for beijing */
typedef struct _afn05_fn130_tsfm_detect {
/* 0 - disable, 1 - enable */
uint8_t enabled;
} afn05_fn130_tsfm_detect_t;
/* set whitelist state for beijing */
typedef struct _afn05_fn131_set_wl_state {
/* whitelist status, 0 - disable, 1- enable */
uint8_t wl_state;
} afn05_fn131_set_wl_state_t;
/* new node event report */
typedef struct _afn05_fn200_new_node_rpt {
uint8_t rpt_allowed;
} afn05_fn200_new_node_rpt_t;
/* node leave network check event report */
typedef struct _afn05_fn201_leave_net_rpt {
uint8_t rpt_allowed;
} afn05_fn201_leave_net_rpt_t;
/* sta join certification for hunan */
typedef struct _afn05_fn201_join_check {
/* sta join certification state, 0 - disable, 1 - enable */
uint8_t check_enable;
} afn05_fn201_join_check_t;
typedef struct _sec_node_info_0601 {
uint8_t mac[IOT_MAC_ADDR_LEN];
uint8_t proto_type;
uint16_t node_index;
} sec_node_info_0601_t;
/* data type for IOT_SG_CCO_SEC_NODE_INFO */
typedef struct _afn06_fn01_sec_node_info {
uint8_t sec_node_count;
sec_node_info_0601_t node_info[0];
} afn06_fn01_sec_node_info_t;
typedef struct _afn06_fn02_router_data_fwd_2009 {
uint16_t node_index;
uint8_t proto_type;
uint8_t data_len;
uint8_t data[0]; // data len
}afn06_fn02_router_data_fwd_2009_t;
typedef struct _afn06_fn02_router_data_fwd_2013 {
uint16_t node_index;
uint8_t proto_type;
uint16_t comm_dur;
uint8_t data_len;
uint8_t data[0]; // data len
}afn06_fn02_router_data_fwd_2013_t;
typedef struct _sec_node_son_info
{
uint8_t meter_addr[IOT_MAC_ADDR_LEN];
uint8_t proto_type;
}sec_node_son_info_t;
typedef struct _afn06_fn03_router_info
{
uint8_t mission_change;
}afn06_fn03_router_info_t;
typedef struct _afn06_fn04_sec_node_info {
uint8_t sec_node_count;
uint8_t sta_addr[IOT_MAC_ADDR_LEN];
uint8_t proto_type;
uint16_t sec_node_index;
uint8_t device_type;
uint8_t total_child_cnt;
uint8_t send_child_cnt;
sec_node_son_info_t node_info[0];
}afn06_fn04_sec_node_info_t;
typedef struct _tsfm_chg_node_info {
uint8_t addr[IOT_MAC_ADDR_LEN];
uint8_t dev_type;
} tsfm_chg_node_info_t;
typedef struct _afn06_fn05_tsfm_chg_rpt {
uint8_t cnt;
tsfm_chg_node_info_t node_info[0];
} afn06_fn05_tsfm_chg_rpt_t;
typedef struct _afn06_fn05_node_evt_rpt {
uint8_t dev_type;
uint8_t proto_type;
uint8_t data_len;
uint8_t data[0];
}afn06_fn05_node_evt_rpt_t;
typedef struct _afn06_fn08_sec_node_info {
/* registered node mac addr, little endian*/
uint8_t mac_addr[IOT_MAC_ADDR_LEN];
/* short addr */
uint16_t tei;
} afn06_fn08_sec_node_info_t;
typedef struct _afn06_fn09_power_down_evt_rpt {
/* report power down meter count */
uint8_t cnt;
/* power meter address, little endian */
uint8_t mac_addr[0][IOT_MAC_ADDR_LEN];
} afn06_fn09_power_down_evt_rpt_t;
typedef struct dynamic_state_chg_info {
/* mac address of STA */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* see PROTO_3762_STATE_XXX */
uint8_t state_chg_type;
/* duration of STA offline, uint is 1s */
uint32_t dur;
/* see IOT_SG_STA_STATE_CHG_REASON_XXX */
uint8_t reason;
} dynamic_state_info_t;
typedef struct _afn06_fn10_sta_dynamic_state_rpt {
/* total STA count which state changed */
uint16_t total_sta;
/* report STA count */
uint8_t rpt_cnt;
/* start index of first secondary node reported in total STA count */
uint16_t start_index;
/* state change info of each STA */
dynamic_state_info_t state_chg_info[0];
}afn06_fn10_sta_dynamic_state_rpt_t;
typedef struct dynamic_state_chg_info_xian {
/* mac address of STA, little endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* state of change, see CCTT_DRV_SEC_NODE_STATE_CHANGE_TO_XXX */
uint8_t state_chg;
/* duration of STA offline, uint is 1s */
uint32_t dur;
/* see IOT_SG_STA_STATE_CHG_REASON_XXX */
uint8_t leave_reason;
/* chip id of STA */
proto_3762_chip_id_t chip_id;
} dynamic_state_info_xian_t;
typedef struct _afn06_fn10_sta_dynamic_state_xian_rpt {
/* total report STA count which state changed */
uint16_t rpt_total_cnt;
/* current report STA count */
uint8_t cur_rpt_cnt;
/* start index of first secondary node reported */
uint16_t start_index;
/* state change info of each STA */
dynamic_state_info_xian_t state_chg_info[0];
}afn06_fn10_sta_dynamic_state_rpt_xian_t;
typedef struct _afn06_fn230_clct_data_rpt {
/* sta collect parameter v2.8 task id */
uint8_t task_id;
/* power meter address, little endian */
uint8_t pm_mac[IOT_MAC_ADDR_LEN];
/* proto type, see PROTO_TYPE_XXX */
uint8_t proto_type;
/* time stamp, BCD code to represent */
uint8_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t min;
uint8_t sec;
/* sta collect data length */
uint16_t data_len;
/* sta collect data */
uint8_t data[0];
} afn06_fn230_clct_data_rpt;
typedef struct _afn06_fn255_node_evt_rpt_ex {
/* node device type */
uint8_t dev_type;
/* meter proto type */
uint8_t proto_type;
/* report data length */
uint16_t data_len;
/* report data*/
uint8_t data[0];
}afn06_fn255_node_evt_rpt_ex_t;
typedef struct _afn10_fn01_sec_node_num {
uint16_t sec_node_num;
uint16_t max_sec_node_num;
}afn10_fn01_sec_node_num_t;
typedef struct _afn10_fn02_sec_node_info_req {
uint16_t start_index;
uint8_t count;
}afn10_fn02_sec_node_info_req_t;
typedef struct _sec_node_info {
uint8_t sec_node_mac[IOT_MAC_ADDR_LEN];
uint16_t rpt_level : 4,
signal_level : 4,
phase : 3,
proto_type : 3,
/* if support minutes collect */
clct_min : 1,
reserved : 1;
}sec_node_info_t;
typedef struct _afn10_fn02_slave_info_rsp {
/* total count of secondary nodes */
uint16_t total_count;
/* count of secondary nodes returned in this packet */
uint8_t count;
/* secondary nodes info */
sec_node_info_t sec_node[0];
}afn10_fn02_sec_node_info_rsp_t;
typedef struct _afn10_fn03_father_node_route_info
{
uint8_t sec_node_count_for_route;
sec_node_info_t sec_node[0];
}afn10_fn03_father_node_route_info_t;
typedef struct _afn10_fn04_route_status_rsp {
/* run status work */
uint8_t route_finish_flag : 1;
uint8_t work_flag : 1;
uint8_t fwd_evt_flag : 1;
uint8_t reserved_1 : 1;
uint8_t ecc_type : 4; /* bit4 - bit7: error correcting code type */
/* slave node count */
uint16_t sec_node_count;
/* meter finished node count */
uint16_t meter_sec_node_count;
/* the slave node count of relay meter */
uint16_t relay_meter_sec_node_cout;
/* work switch */
uint8_t work_mode :1, /* 1 - studying, 0 - meter reading */
reg_allowed :1, /* 1 - reg allowed, 0 - not allowed */
evt_rpt_allowed :1, /* 1 - allow, 0 - not allow */
tsfm_detect_allowed :1, /* 1 - allow, 0 - not allow */
tsfm_detect_flag :1, /* see IOT_SG_CCO_TSFM_DETECT_XXX */
reserved_2 :1,
work_type :2; /* see IOT_SG_CCO_ROUTER_WORK_TYPE_XXX */
/* communication rate */
uint16_t rate;
/* relay level */
uint8_t phase1_phase_relay_level;
uint8_t phase2_phase_relay_level;
uint8_t phase3_phase_relay_level;
/* wrok step */
uint8_t phase1_work_step;
uint8_t phase2_work_step;
uint8_t phase3_work_step;
}afn10_fn04_route_status_rsp_t;
typedef struct _afn10_fn04_route_status_rsp_bj {
/* run status work */
uint8_t route_finish_flag : 1;
uint8_t work_flag : 1;
uint8_t fwd_evt_flag : 1;
uint8_t reserved_1 : 1;
uint8_t ecc_type : 4; /* bit4 - bit7: error correcting code type */
/* slave node count */
uint16_t sec_node_count;
/* meter finished node count */
uint16_t meter_sec_node_count;
/* the slave node count of relay meter */
uint16_t relay_meter_sec_node_cout;
/* work switch */
uint8_t work_mode : 1; /* bit0: 1 - studying, 0 - meter reading */
uint8_t reg_allowed : 1;/* bit1: 1 - reg allowed, 0 - not allowed */
uint8_t work_type : 2; /* see IOT_SG_CCO_ROUTER_WORK_TYPE_XXX */
uint8_t tsfm_detect_flag : 1; /* see IOT_SG_CCO_TSFM_DETECT_XXX */
uint8_t reserved_2 : 3;
/* communication rate */
uint16_t rate;
/* relay level */
uint8_t phase1_phase_relay_level;
uint8_t phase2_phase_relay_level;
uint8_t phase3_phase_relay_level;
/* wrok step */
uint8_t phase1_work_step;
uint8_t phase2_work_step;
uint8_t phase3_work_step;
}afn10_fn04_route_status_rsp_bj_t;
typedef struct _afn10_fn05_06_sec_node_info_dl {
uint16_t sec_node_start_index;
uint8_t sec_node_count;
}afn10_fn05_06_sec_node_info_dl_t;
typedef struct _afn10_fn05_06_sec_node_info_ul {
uint16_t sec_node_count;
uint8_t rsp_sec_node_count;
sec_node_info_t node_info[0];
}afn10_fn05_06_sec_node_info_ul_t;
typedef struct _afn10_fn7_sec_node_query_dl {
uint16_t start_index;
uint8_t node_count;
}afn10_fn7_sec_node_query_dl_t;
typedef struct _node_module_info {
/* node mac addr, little endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* node module type, see PROTO_3762_MODULE_DEV_TYPE_XXX */
uint8_t module_type :4,
/* flag to mark if node support minute collection for jiangsu */
minute_clct :1,
/* reserved */
rsvd :2,
/* 0 - update completed, 1 - not updated */
update_flag :1;
/* module info */
proto_3762_module_info_t module_info;
}node_module_info_t;
typedef struct _afn10_fn7_sec_node_query_ul {
uint16_t total_cnt;
uint8_t rpt_cnt;
node_module_info_t node_info[0];
}afn10_fn7_sec_node_query_ul_t;
typedef struct afn10_fn9_query_nw_size_ul_t {
uint16_t nw_size;
}afn10_fn9_query_nw_size_ul_t;
typedef struct _afn10_fn21_query_topo_dl {
uint16_t start_index;
uint8_t node_count;
}afn10_fn21_query_topo_dl_t;
typedef struct _sec_node_net_info {
uint16_t node_identity;
uint16_t pco_node_identity;
uint8_t node_level : 4;
uint8_t node_role : 4;
}sec_node_net_info_t;
/* sec node network topo info */
typedef struct _node_info_for_topo {
/* node mac address - little endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* node identity */
uint16_t tei :12,
/* communication type, for rf */
comm_type:4;
/* proxy node identity */
uint16_t pco_tei;
/* node level */
uint8_t level :4,
/* node role */
role :3,
/* pco link type, for rf */
pco_type :1;
}node_info_for_topo_t;
/* report topo info to cctt */
typedef struct _afn10_fn21_query_topo_ul {
/* total node count in network topo */
uint16_t node_count;
/* node start index in network topo */
uint16_t node_start_index;
/* acknowledge node count */
uint8_t ack_node_count;
/* network topo info list of the node */
node_info_for_topo_t node_info[0];
}afn10_fn21_query_topo_ul_t;
typedef struct _afn10_fn27_query_topo_sxhw_and_hx_dl {
/* start node index */
uint16_t start_index;
/* query node conut */
uint8_t node_count;
} afn10_fn27_query_topo_sxhw_and_hx_dl_t;
/* sec node network topo info for sxhw */
typedef struct _node_info_for_topo_sxhw {
/* node mac address - little endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* node identity */
uint16_t tei;
/* proxy node address - little endian */
uint8_t proxy_mac[IOT_MAC_ADDR_LEN];
/* node signal attenuation */
uint8_t node_att;
/* network state */
uint8_t net_state;
/* node longitude */
uint32_t longitude;
/* node latitude */
uint32_t latitude;
/* node phase */
uint8_t phase;
/* average snr */
int8_t snr;
} node_info_for_topo_sxhw_t;
typedef struct _afn10_fn27_query_topo_sxhw_ul {
/* node total count */
uint8_t total_count;
/* node topo info */
node_info_for_topo_sxhw_t node_info[0];
} afn10_fn27_query_topo_sxhw_ul_t;
/* sec node network topo info for hx */
typedef struct _node_info_for_topo_hx {
/* node mac address - little endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* node identity */
uint16_t tei;
/* proxy node address - little endian */
uint8_t proxy_mac[IOT_MAC_ADDR_LEN];
/* snr absolute value */
uint8_t snr;
/* network state */
uint8_t net_state;
/* node longitude */
uint32_t longitude;
/* node latitude */
uint32_t latitude;
/* node phase */
uint8_t phase;
} node_info_for_topo_hx_t;
typedef struct _afn10_fn27_query_topo_hx_ul {
/* node total count */
uint8_t total_count;
/* node topo info */
node_info_for_topo_hx_t node_info[0];
} afn10_fn27_query_topo_hx_ul_t;
typedef struct _afn10_fn28_query_wl_state_ul {
/* wl state value */
uint8_t wl_state;
} afn10_fn28_query_wl_state_ul_t;
typedef struct _afn10_fn31_query_phase_dl {
uint16_t start_index;
uint8_t node_count;
} afn10_fn31_query_phase_dl_t;
typedef struct _node_phase_info {
uint8_t mac[IOT_MAC_ADDR_LEN];
/* phase that device is connected to.
* bit0 set to 1 means device is connected to phase A.
* bit1 set to 1 means device is connected to phase B.
* bit2 set to 1 means device is connected to phase C.
*/
uint16_t phase : 3,
/* power meter type, 0: single phase, 1: three phase */
pm_type : 1,
/* flag to mark if opposite phase
* 0: line normal or not support identification.
* 1: line abnormal.
* it means neutral wire and live wire reversed when pm type is single
* phase.
* it means reverse phase sequence when pm type is three phase.
*/
opposite_phase : 1,
/* phase type of three phase meter, see IOT_SG_CCO_PHASE_SEQ_XXX */
phase_type : 3,
rsvd_2 : 8;
} node_phase_info_t;
typedef struct _afn10_fn31_query_phase_ul {
uint16_t total_node_cnt;
uint16_t start_index;
uint8_t ack_node_count;
node_phase_info_t node_info[0];
} afn10_fn31_query_phase_ul_t;
typedef struct _afn10_fn32_query_snr_dl {
uint16_t start_index;
uint8_t node_count;
} afn10_fn32_query_snr_dl_t;
typedef struct _node_snr_info {
uint8_t mac[IOT_MAC_ADDR_LEN];
uint8_t ul_snr;
uint8_t dl_snr;
} node_snr_info_t;
typedef struct _afn10_fn32_query_snr_ul {
uint16_t total_node_cnt;
uint16_t start_index;
uint8_t ack_node_count;
node_snr_info_t node_info[0];
} afn10_fn32_query_snr_ul_t;
typedef struct _afn10_fn33_query_node_id_dl {
uint16_t start_index;
uint8_t node_count;
} afn10_fn33_query_node_id_dl_t;
/* node hardware information */
typedef struct _node_id_info {
uint8_t mac[IOT_MAC_ADDR_LEN];
proto_3762_chip_id_t chip_id;
} node_id_info_t;
typedef struct _afn10h_fn33_query_node_id_ul {
uint16_t total_node_cnt;
uint16_t start_index;
uint8_t ack_node_count;
node_id_info_t node_info[0];
} afn10h_fn33_query_node_id_ul_t;
typedef struct _afn10h_fn40_query_node_id_dl {
/* node device type, see PROTO_3762_NODE_DEV_TYPE_xxx */
uint8_t dev_type;
/* mac address of the node: small endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* id information type, see PROTO_3762_ID_INFO_TYPE_xxx */
uint8_t id_type;
} afn10h_fn40_query_node_id_dl_t;
typedef struct _afn10h_fn40_query_node_id_ul {
/* node device type, see PROTO_3762_NODE_DEV_TYPE_xxx */
uint8_t dev_type;
/* mac address of the node: small endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* id information type, see PROTO_3762_ID_INFO_TYPE_xxx */
uint8_t id_type;
/* id information length */
uint8_t id_len;
/* id information */
uint8_t id_info[0];
} afn10h_fn40_query_node_id_ul_t;
typedef struct _afn10h_fn90_qr_clock_manager_param_dl {
/* node addr, little endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
} afn10h_fn90_qr_clock_manager_param_dl_t;
typedef struct _afn10h_fn90_qr_clock_manager_param_ul {
/* node addr, little endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* auto correct time state, 0 - disable, 1 - enable */
uint8_t auto_corr_state;
/* reserved */
uint8_t reserved;
/* clock error report threshold, unit is 1min */
uint8_t threshold;
} afn10h_fn90_qr_clock_manager_param_ul_t;
typedef struct _afn10h_fn93_qr_corr_time_period_ul {
/* clock manager correct time period, unit is 1min */
uint16_t period;
} afn10h_fn93_qr_corr_time_period_ul_t;
typedef struct _afn10_fn100_query_network_size_ul {
/* value is [2,512] */
uint16_t nw_size;
} afn10_fn100_query_nw_size_ul_t;
typedef struct _afn10_fn101_query_node_info_dl {
uint16_t start_index;
uint8_t node_count;
} afn10_fn101_query_node_info_dl_t;
typedef struct _f101_node_info {
uint8_t mac[IOT_MAC_ADDR_LEN];
uint16_t level : 4;
uint16_t snr : 4;
uint16_t phase : 3;
uint16_t proto_type : 3;
uint16_t rsvd : 2;
uint16_t app_ver;
uint8_t bootloader_ver;
} f101_node_info_t;
typedef struct _afn10_fn101_query_node_info_ul {
uint16_t total_node_cnt;
uint8_t ack_node_count;
f101_node_info_t node_info[0];
} afn10_fn101_query_node_info_ul_t;
/* command to query nodes information protocol */
typedef struct _afn10_fn102_query_node_info_dl {
/* start index */
uint16_t start_index;
/* query node count */
uint8_t node_count;
} afn10_fn102_query_node_info_dl_t;
typedef struct _node_phase_info_xiand {
/* node mac addr, little endian */
uint8_t node_addr[IOT_MAC_ADDR_LEN];
/* 0 - not in the whitelist, 1 - in the whitelist */
uint16_t in_wl : 1,
/* phase that device is connected to.
* bit0 set to 1 means device is connected to phase A.
* bit1 set to 1 means device is connected to phase B.
* bit2 set to 1 means device is connected to phase C.
*/
phase : 3,
/* flag to mark if L/N reversed in Single-phase power meter or phase
* sequence reversed in Three-phase power meter.
*/
opposite_phase : 1,
/* reserved */
rsvd : 3,
/* node phase */
phase3 : 2,
phase2 : 2,
phase1 : 2,
/* power meter type, 0 - single phase meter, 1 - three phase meter */
pm_type : 2;
} node_phase_info_xiand_t;
/* data to response for requesting nodes phase information for xi'an
* local electric.
*/
typedef struct _afn10_fn102_query_node_phase_info_ul {
/* total count of in network nodes */
uint16_t total_node_cnt;
/* current reported count of nodes */
uint8_t ack_node_count;
/* node phase information for xi'an*/
node_phase_info_xiand_t node_info[0];
} afn10_fn102_query_node_phase_info_ul_t;
/* command to query sta module configuration state for xian protocol. */
typedef struct _afn10_fn103_query_sta_cfg_state_dl {
/* start query index */
uint16_t start_index;
/* query node count */
uint8_t count;
} afn10_fn103_query_sta_cfg_state_dl_t;
typedef struct _sta_cfg_state {
/* node mac address, little endian */
uint8_t node_addr[IOT_MAC_ADDR_LEN];
/* configuration state, 0 fail, 1 success */
uint8_t cfg_state;
} sta_cfg_state_t;
/* data to response for requesting sta module configuration state. */
typedef struct _afn10_fn103_query_sta_cfg_state_ul {
/* total node count */
uint16_t total_count;
/* report count */
uint8_t rpt_count;
/* node configuration state info */
sta_cfg_state_t mod_cfg[0];
} afn10_fn103_query_sta_cfg_state_ul_t;
/* command to query nodes' mac and version information */
typedef struct _afn10_fn104_query_node_info_dl {
/* query start index - 0 is cco, others station */
uint16_t start_index;
/* query node count */
uint8_t total_cnt;
} afn10_fn104_query_node_info_dl_t;
typedef struct _node_info_ver_info {
/* mac address of the station: small endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* software version */
uint16_t sw_ver;
/* software version day */
uint8_t sw_ver_day;
/* software version month */
uint8_t sw_ver_month;
/* software version year */
uint8_t sw_ver_year;
/* node vendor id */
uint16_t vendor_id;
/* node chip id */
uint16_t chip_id;
} node_info_ver_info_t;
/* data to response for requesting nodes' information. */
typedef struct _afn10_fn104_query_node_info_ul {
/* total node count */
uint16_t ack_node_count;
/* rsp node count */
uint8_t rsp_cnt;
node_info_ver_info_t node_info[0];
}afn10_fn104_query_node_info_ul_t;
typedef struct _afn10h_fn111_net_info {
uint8_t total_node_cnt;
uint8_t local_nid[PROTO_3762_NID_LEN]; /* 3 bytes */
uint8_t local_mac[IOT_MAC_ADDR_LEN];
uint8_t nb_nid[0][PROTO_3762_NID_LEN];
}afn10h_fn111_net_info_t;
typedef struct _afn10_fn112_query_chip_info_dl {
/* start index, 1 means major node */
uint16_t start_index;
/* query count */
uint8_t node_count;
} afn10_fn112_query_chip_info_dl_t;
typedef struct _afn10_fn112_query_chip_info_ul {
/* total count */
uint16_t total_node_cnt;
/* start index */
uint16_t start_index;
/* report count */
uint8_t ack_node_count;
/* node information */
node_hw_info_t node_info[0];
} afn10_fn112_query_chip_info_ul_t;
/* command to query power meter information */
typedef struct _afn10_fn150_query_pm_info_dl {
/* query pm start index from 1 */
uint16_t start_index;
/* query pm count */
uint8_t pm_cnt;
} afn10_fn150_query_pm_info_dl_t;
typedef struct _afn10_fn150_pm_info {
/* device mac address, if the device type is collector,
* the mac is the collector mac address, little-endian.
*/
uint8_t dev_mac[IOT_MAC_ADDR_LEN];
/* mac address of the pm, little-endian */
uint8_t pm_mac[IOT_MAC_ADDR_LEN];
/* power meter proto type, see PROTO_TYPE_XXX */
uint8_t proto_type;
} afn10_fn150_pm_info_t;
/* data to response for requesting power meter information. */
typedef struct _afn10_fn150_query_pm_info_ul {
/* total pm count */
uint16_t total_pm_count;
/* report pm start index */
uint16_t start_index;
/* ack pm count */
uint8_t ack_cnt;
/* query pm info */
afn10_fn150_pm_info_t pm_info[0];
} afn10_fn150_query_pm_info_ul_t;
/* data to response for query collect parameter v2.8 task id . */
typedef struct _afn10_fn230_query_task_id_cnt_ul {
/* total task count */
uint8_t task_cnt;
/* clct task bitmap */
uint8_t task_bitmap[4];
} afn10_fn230_query_task_id_cnt_ul_t;
/* command to query curve collect parameter v2.8 configuration */
typedef struct _afn10_fn231_query_curve_node_conf_dl {
/* sta collect parameter v2.8 task id */
uint8_t task_id;
/* 2 - DL/T645-2007, 3 - DL/T698.45, other - reserve, see PROTO_TYPE_XXX */
uint8_t proto_type;
} afn10_fn231_query_curve_node_conf_dl_t;
/* data to response for query collect parameter v2.8 configuration */
typedef struct _afn10_fn231_query_curve_node_conf_ul {
/* sta collect parameter v2.8 task id */
uint8_t task_id;
/* 2 - DL/T645-2007, 3 - DL/T698.45, other - reserve, see PROTO_TYPE_XXX */
uint8_t proto_type;
/* collect period, unit is 1min */
uint8_t clct_period;
/* task configuration node count */
uint16_t task_node_cnt;
/* collect parameter */
uint8_t data[0];
} fn10_fn231_query_curve_node_conf_ul_t;
/* command to query collect parameter v2.8 task configuration address */
typedef struct _afn10_fn232_query_task_addr_dl {
/* sta collect parameter v2.8 task id */
uint8_t task_id;
/* start index */
uint16_t start_index;
/* query count */
uint8_t cnt;
} afn10_fn232_query_task_addr_dl_t;
/* data to response for query collect parameter v2.8 task configuration address */
typedef struct _afn10_fn232_query_task_addr_ul {
/* sta collect parameter v2.8 task id */
uint8_t task_id;
/* task configuration address total address count */
uint16_t total_cnt;
/* report address count */
uint8_t cnt;
/* power meter address, little endian */
uint8_t pm_mac[0][IOT_MAC_ADDR_LEN];
} afn10_fn232_query_task_addr_ul_t;
typedef struct _afn10_fn244_query_topo_dl {
/* start node index */
uint16_t start_index;
/* query node conut */
uint8_t node_count;
} afn10_fn244_query_topo_dl_t;
typedef struct _topo_hx_data {
/* node mac address - little endian */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* node identity */
uint16_t tei;
/* plc proxy node address - little endian */
uint8_t plc_proxy_mac[IOT_MAC_ADDR_LEN];
/* plc path level */
uint8_t plc_path_level;
/* plc snr absolute value */
uint8_t plc_snr;
/* plc network state */
uint8_t plc_net_state;
/* plc node phase */
uint8_t plc_phase;
/* rf proxy node address - little endian */
uint8_t rf_proxy_mac[IOT_MAC_ADDR_LEN];
/* rf path level */
uint8_t rf_path_level;
/* rf snr absolute value */
uint8_t rf_snr;
/* rf network state */
uint8_t rf_net_state;
/* node longitude */
uint8_t longitude[8];
/* node latitude */
uint8_t latitude[8];
} topo_hx_data;
/* data to response for query hx topo data */
typedef struct _afn10_fn244_query_topo_ul {
/* report node count */
uint8_t cnt;
/* node hx topo data */
topo_hx_data topo_data[0];
} afn10_fn244_query_topo_ul_t;
typedef struct _afn03_fn102_query_curve_data_dl {
/* 2 - DL/T645-2007, 3 - DL/T698.45, other - reserve, see PROTO_TYPE_XXX */
uint8_t proto_type;
} afn03_fn102_query_curve_data_dl_t;
typedef struct _afn03_fn102_query_curve_data_ul {
/* 2 - DL/T645-2007, 3 - DL/T698.45, other - reserve, see PROTO_TYPE_XXX */
uint8_t proto_type;
/* collect parameter */
//proto_3762_meter_clct_param_t clct_param[0];
} afn03_fn102_query_curve_data_ul_t;
/* query curve data for hunan */
typedef struct _afn03_fn102_query_curve_data_ex_ul {
/* 0 - disabled, 1 - enabled */
uint8_t enabled;
/* unit is 1min */
uint8_t clct_period;
/* 2 - DL/T645-2007, 3 - DL/T698.45, other - reserve, see PROTO_TYPE_XXX */
uint8_t proto_type;
/* collect parameter */
//proto_3762_meter_clct_param_t clct_param[0];
} afn03_fn102_query_curve_data_ex_ul_t;
typedef struct _afn03_fn102_query_auto_reg_active {
/* 0x5A - whitelist model,
* 0x5F and others - auto register active model(default)
* see PRPTO_3762_ZHHW_AUTO_REG_ACTIVE_XXX.
*/
uint8_t auto_reg_active;
} afn03_fn102_query_auto_reg_active_t;
typedef struct _afn03_fn130_fn120_query_build_info {
/* cpu number */
uint8_t cpu_number;
/* 2 bytes for vendor id */
uint16_t vendor_id;
/* reserved */
uint8_t rsvd :3,
/* version date day, BIN format */
ver_day :5;
/* version date month, BIN format */
uint16_t ver_mon :4,
/* version date year, BIN format */
ver_year :12;
/* hardware version, BCD format, for fn130. reserved for fn 120. */
uint16_t hw_ver;
/* software version, BCD format */
uint16_t sw_ver;
/* mcu type length */
uint8_t mcu_type_len;
/* mcu type */
uint8_t mcu_type[0];
} afn03_fn130_fn120_query_build_info_t;
typedef struct _afn03_fn131_fn121_query_compare_data_info_dl {
/* cpu number */
uint8_t cpu_number;
/* compare data start addr */
uint32_t start_addr;
/* compare data length */
uint16_t data_len;
} afn03_fn131_fn121_query_compare_data_info_dl_t;
typedef struct _afn03_fn131_fn121_query_compare_data_info_ul {
/* compare data */
uint8_t compare_data[PROTO_3762_SHA1_CHECK_LEN];
} afn03_fn131_fn121_query_compare_data_info_ul_t;
typedef struct _afn03_fn131_query_wl_state_ul {
/* flag to mark if whitelist enable, 0 - disable, 1 - enable */
uint8_t wl_task_flag;
} afn03_fn131_query_wl_state_ul_t;
typedef struct _slave_info_entry_2009 {
uint8_t mac[PROTO_3762_MAC_ADDR_LEN];
uint16_t node_index; /* just for 3762-2009 */
/* meter proto type, see PROTO_TYPE_XXX */
uint8_t proto_type;
}slave_info_entry_2009_t;
typedef struct _afn11_fn01_add_sec_node_req_2009 {
uint8_t sec_node_cnt; /* slave count*/
slave_info_entry_2009_t sec_node[0];
}afn11_fn01_add_sec_node_req_2009_t;
typedef struct _slave_info_entry_2013 {
uint8_t mac[PROTO_3762_MAC_ADDR_LEN];
/* meter proto type, see PROTO_TYPE_XXX */
uint8_t proto_type;
}slave_info_entry_2013_t;
typedef struct _afn11_fn01_add_sec_node_req_2013 {
uint8_t sec_node_cnt; /* slave count*/
slave_info_entry_2013_t sec_node[0];
}afn11_fn01_add_sec_node_req_2013_t;
typedef struct _afn11_fn02_rmv_sec_node_req {
uint8_t sec_node_cnt; /* node count*/
uint8_t mac_addr[0][IOT_MAC_ADDR_LEN];
} afn11_fn02_rmv_sec_node_req_t;
typedef struct _afn11_fn04_set_rt_mode {
/* bit0: 1 - studying, 0 - meter reading */
uint8_t work_mode :1,
/* bit1: 1 - reg allowed, 0 - not allowed */
reg_allowed :1,
/* bit2 - bit3: reserved */
reserved :2,
/* bit4 - bit7: error correcting code type
* 0 - no coding, 1 - RS coding */
ecc_type :4;
/* communication rate */
uint16_t comm_rate :15,
/* rata unit, 0 - bps, 1 - kbps */
rate_unit :1;
}afn11_fn04_set_rt_mode_t;
typedef struct _afn11_fn05_start_node_reg {
uint8_t start_time[PROTO_3762_DATETIME_LEN];
uint16_t duration; /* in minute */
uint8_t retry_cnt;
uint8_t wait_tick_cnt; /* each wait tick is 150ms */
}afn11_fn05_start_node_reg_t;
typedef struct _afn11_fn07_set_wl_state {
/* wl switch value, 1 - enable, 0 - disable. */
uint8_t wl_state;
} afn11_fn07_set_wl_state_t;
typedef struct _afn11_fn100_set_network_size_dl {
/* value is [2,512] */
uint16_t nw_size;
} afn11_fn100_set_nw_size_dl_t;
typedef struct _set_sec_node_tsfm_addr {
/* tsfm_address, little endian */
uint8_t tsfm_addr[IOT_MAC_ADDR_LEN];
/* whole network set mode, see PROTO_3762_NW_SET_MODE_XXX */
uint8_t set_mode;
/* reserved */
uint8_t rsvd[3];
/* secondary node addres, only valid in single set, little endian */
uint8_t sec_node_addr[IOT_MAC_ADDR_LEN];
} set_sec_node_tsfm_addr_t;
typedef struct _del_sec_node_tsfm_addr {
/* whole network set mode, see PROTO_3762_NW_SET_MODE_XXX */
uint8_t set_mode;
/* reserved */
uint8_t rsvd;
/* secondary node addres, only valid in single set, little endian */
uint8_t sec_node_addr[IOT_MAC_ADDR_LEN];
} del_sec_node_tsfm_addr_t;
typedef struct _afn11_fn127_set_tsfm_addr_dl {
/* set tsfm addr commad type, see PROTO_3762_TSFM_ADDR_CMD_XXX */
uint8_t cmd_type;
/* data length */
uint8_t data_len;
/* reserved */
uint16_t rsvd;
/* cmd data */
uint8_t data[0];
} afn11_fn127_set_tsfm_addr_dl_t;
typedef struct _sec_node_nw_lock_set_data {
/* whole network set mode, see PROTO_3762_NW_SET_MODE_XXX */
uint8_t set_mode;
/* reserved */
uint8_t rsvd;
/* secondary node addres, only valid in single set, little endian */
uint8_t sec_node_mac[IOT_MAC_ADDR_LEN];
} sec_node_nw_lock_set_data_t;
typedef struct _afn11_fn126_nw_lock_cmd {
/* command type, see PROTO_3762_SEC_NODE_NW_CMD_XXX */
uint8_t cmd_type;
/* data length */
uint8_t data_len;
/* reserved */
uint16_t rsvd;
/* command data */
uint8_t data[0];
} afn11_fn126_nw_lock_cmd_t;
/* start secondary node registration for hunan */
typedef struct _afn11_fn225_start_node_reg {
uint8_t start_time[PROTO_3762_DATETIME_LEN];
uint16_t duration; /* in minute */
uint8_t retry_cnt;
uint8_t wait_tick_cnt; /* each wait tick is 150ms */
}afn11_fn225_start_node_reg_t;
typedef struct _afn11_fn231_curve_data_conf {
/* sta collect parameter v2.8 task id */
uint8_t task_id;
/* 0 - disabled, 1 - enabled */
uint8_t enabled;
/* 2 - DL/T645-2007, 3 - DL/T698.45, other - reserve, see PROTO_TYPE_XXX */
uint8_t proto_type;
/* unit is 1min */
uint8_t clct_period;
/* collect parameter */
//proto_3762_meter_clct_param_t clct_param[0];
} afn11_fn231_curve_data_conf_t;
typedef struct _afn11_fn231_curve_data_conf_rpt {
/* sta collect parameter v2.8 task id */
uint8_t task_id;
/* 0 - disabled, 1 - enabled */
uint8_t enabled;
/* 2 - DL/T645-2007, 3 - DL/T698.45, other - reserve, see PROTO_TYPE_XXX */
uint8_t proto_type;
/* unit is 1min */
uint8_t clct_period;
/* configuration result, see PRPTO_3762_CURVE_DATA_RET_XXX */
uint8_t result;
} afn11_fn231_curve_data_conf_rpt_t;
typedef struct _afn11_fn232_curve_node_conf {
/* sta collect parameter v2.8 task id */
uint8_t task_id;
/* node addr count */
uint16_t cnt;
/* node addr, little endian */
uint8_t node_addr[0][IOT_MAC_ADDR_LEN];
} afn11_fn232_curve_node_conf_t;
typedef struct _afn11_fn232_curve_node_conf_rpt {
/* sta collect parameter v2.8 task id */
uint8_t task_id;
/* configuration result, see PRPTO_3762_CURVE_DATA_NODE_RET_XXX */
uint8_t result;
} afn11_fn232_curve_node_conf_rpt_t;
typedef struct _afn13_fn01_router_data_fwd_2009 {
uint8_t proto_type;
uint8_t sec_node_cnt;
uint8_t mac[0][PROTO_3762_MAC_ADDR_LEN];
//datagram_t datagram; /* datagram to be forward */
}afn13_fn01_router_data_fwd_2009_t;
typedef struct _afn13_fn01_router_data_fwd_2013 {
uint8_t proto_type;
uint8_t defer_flag;
uint8_t sec_node_cnt;
uint8_t mac[0][PROTO_3762_MAC_ADDR_LEN];
//datagram_t datagram; /* datagram to be forward */
}afn13_fn01_router_data_fwd_2013_t;
typedef struct _afn13_fn01_router_data_rpt_2009 {
uint8_t proto_type;
uint8_t data_len;
uint8_t data[0];
}afn13_fn01_router_data_rpt_2009_t;
typedef struct _afn13_fn01_router_data_rpt_2013 {
uint16_t comm_dur;
uint8_t proto_type;
uint8_t data_len;
uint8_t data[0];
}afn13_fn01_router_data_rpt_2013_t;
typedef struct _afn13_fn02_router_data_rpt_2013 {
uint16_t comm_dur;
uint8_t proto_type;
uint16_t data_len;
uint8_t data[0];
}afn13_fn02_router_data_rpt_2013_t;
typedef struct _afn14_fn01_rt_req_data {
uint8_t phase;
uint8_t meter_mac[IOT_MAC_ADDR_LEN];
uint16_t index;
}afn14_fn01_rt_req_data_t;
typedef struct _afn14_fn01_mac_info {
uint8_t mac_count;
uint8_t mac[0][IOT_MAC_ADDR_LEN];
} afn14_fn01_mac_info;
typedef struct _afn14_fn01_rt_req_data_rsp_2013 {
uint8_t read_flag;
uint8_t defer_flag;
uint8_t data_len;
uint8_t data[0];
//afn14_fn01_mac_info mac_info; /* mac info after data */
}afn14_fn01_rt_req_data_rsp_2013_t;
typedef struct _afn14_fn01_rt_req_data_rsp_2009 {
uint8_t read_flag;
uint8_t data_len;
uint8_t data[0];
//afn14_fn01_mac_info mac_info; /* mac info after data */
}afn14_fn01_rt_req_data_rsp_2009_t;
typedef struct _afn14_fn02_cctt_time {
uint8_t sec;
uint8_t min;
uint8_t hour;
uint8_t day;
uint8_t mon;
uint8_t year_l;
}afn14_fn02_cctt_time_t;
typedef struct _afn14_fn03_req_data_fix {
uint8_t mac_addr[IOT_MAC_ADDR_LEN];
uint16_t delay_second;
uint8_t data_len;
uint8_t data[0];
}afn14_fn03_req_data_fix_t;
typedef struct _afn14_fn03_req_data_fix_dl {
uint8_t data_len;
uint8_t data[0];
}afn14_fn03_req_data_fix_dl_t;
typedef struct _afn15_fn01_send_file_dl {
/* see PROTO_3762_15H_XXX */
uint8_t action;
/* 0x01 -end frame, 0x00 - other frame */
uint8_t is_last_seg;
/* file command, fixed value: 0x01 */
uint8_t file_cmd;
/* total segment count */
uint16_t total_seg_cnt;
/* segment index */
uint32_t seg_index;
/* current segment length */
uint16_t cur_seg_len;
/* data */
uint8_t data[0];
}afn15_fn01_send_file_dl_t;
typedef struct _afn15_fn01_send_file_ul {
/* segment index in down link afn15_fn01 */
uint32_t segment_index;
}afn15_fn01_send_file_ul_t;
typedef struct _lp_meter_rpt_info {
/* low power meter addr, little endian */
uint8_t mac_addr[PROTO_3762_188_ADDR_LEN];
/* low power meter report time */
uint8_t rpt_time[PROTO_3762_188_METER_TIME_LEN];
/* low power type */
uint8_t lp_meter_type;
/* accumulative value */
uint8_t acc_value[PROTO_3762_188_METER_ACC_VAL_LEN];
/* statistical time */
uint8_t stat_time;
/* last month accumulative value */
uint8_t last_mon_acc_value[PROTO_3762_188_METER_ACC_VAL_LEN];
/* meter undervoltage */
uint8_t uvp:1,
/* reserved */
rsvd:7;
/* release date */
uint8_t release_date;
} lp_meter_rpt_info_t;
typedef struct _afn20_fn03_rpt_water_meter_info {
/* report sequence */
uint8_t rpt_seq;
/* report low power meter count */
uint8_t rpt_cnt;
/* report low power meter info */
lp_meter_rpt_info_t rpt_info[0];
} afn20_fn03_rpt_lp_meter_info_t;
typedef struct _nw_level_info {
/* current level */
uint8_t level;
/* station counte of current level */
uint16_t sta_cnt;
} nw_level_info_t;
typedef struct _afnf0_fn100_nw_info_ul {
/* total station count in network */
uint16_t total_sta_cnt;
/* station count that are online */
uint16_t online_sta_cnt;
/* duration from CCO booting up to starting grouping network - unit 1s */
uint32_t boot_fmt_time;
/* network grouping time - unit 1s */
uint16_t fmt_dur;
/* beacon period - unit 1s */
uint8_t bc_period;
/* rout period - unit 1s */
uint16_t rt_period;
/* topo changing count */
uint16_t topo_change_cnt;
/* maximum topo level */
uint8_t max_level;
/* info of each level */
nw_level_info_t nw_level_info[0];
}afnf0_fn100_nw_info_ul_t;
/* command to query nodes information. */
typedef struct _afnf0_fn102_req_node_info_dl{
/* start index */
uint16_t start_index;
/* total queried node number */
uint8_t total_cnt;
}afnf0_fn102_req_node_info_dl_t;
typedef struct _afnf0_fn102_sec_node_info {
/* mac address of the meter: small endian */
uint8_t addr[IOT_MAC_ADDR_LEN];
/* proto type the meter supported, see PROTO_TYPE_XXX */
uint8_t proto_type;
/* device type: 01--485 meter, other--reserved */
uint8_t dev_type;
}afnf0_fn102_sec_node_info_t;
typedef struct _afnf0_sx_node_info {
/* mac address of the station: small endian */
uint8_t addr[IOT_MAC_ADDR_LEN];
/* 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 device */
role :4;
/* online flag */
uint8_t is_online :1,
/* beacon slot arranged flag */
is_slot_set :1,
/* in whitelist flag */
is_in_wl :1,
/* heart-beat received flag */
is_hb_rec :1,
/* counter of route period missed since last hb, dual mode set to 0 */
rt_period_miss :4;
/* device type, see PROTO_3762_DEV_TYPE_XXX */
uint16_t dev_type;
/* physical phase of the station */
uint8_t phy_phase;
/* how many times the node change proxy accepted since join the network */
uint16_t proxy_chg_accept_cnt;
/* how many times sta been kicked out */
uint16_t leave_cnt;
/* time span from the last time sta been kicked out to rejoin, unit is 1s */
uint32_t last_leave_dur;
/* max time span from sta been kicked out to rejoin, unit is 1s */
uint32_t max_leave_dur;
/* uplink traffic success ratio */
uint32_t ul_tf_sr;
/* downlink traffic success ratio */
uint32_t dl_tf_sr;
/* primary version */
uint8_t prim_ver[PROTO_3762_PRIM_VER_LEN];
/* secondary version */
uint16_t seco_ver;
/* next hop's infor */
uint16_t next_hop;
/* channel type: the comunication method between CCO and STA */
uint16_t chnnl_type;
/* protocal type, see PROTO_TYPE_XXX */
uint8_t proto_type;
/* transformer status, see PROTO_3762_TSFM_STATUS_X */
uint8_t tsfm_status;
/* transformer address: small endian*/
uint8_t tsfm_addr[IOT_MAC_ADDR_LEN];
/* total count of secondary node */
uint8_t total_sec_cnt;
}afnf0_sx_node_info_t;
/* data to response for requesting nodes information. */
typedef struct _afnf0_fn102_req_node_info_rsp_ul {
/* total counter of in network nodes */
uint16_t total_cnt;
/* current reported counter of nodes */
uint16_t rpt_cnt;
/* start index */
uint16_t start_index;
/* node infor */
afnf0_sx_node_info_t node[0];
}afnf0_fn102_req_node_info_rsp_ul_t;
/* command to query nominated nodes' information. */
typedef struct _afnf0_fn103_req_node_info_dl {
/* total node count */
uint8_t total_cnt;
/* nodes' address: small endian */
uint8_t mac[0][IOT_MAC_ADDR_LEN];
}afnf0_fn103_req_node_info_dl_t;
/* data to response for requesting nominated nodes' information. */
typedef struct _afnf0_fn103_node_info_rsp_ul {
/* current reported counter of nodes */
uint16_t rpt_cnt;
/* node info */
afnf0_sx_node_info_t node[0];
}afnf0_fn103_node_info_rsp_ul_t;
/* concurrent meter reading down link data */
typedef struct _afnf1_fn01_con_read_meter_dl {
uint8_t proto_type;
uint8_t revered;
uint16_t data_len;
uint8_t data[0];
}afnf1_fn01_con_read_meter_dl_t;
/* concurrent meter reading up link data */
typedef struct _afnf1_fn01_con_read_meter_ul {
uint8_t proto_type;
uint16_t data_len;
uint8_t data[0];
}afnf1_fn01_con_read_meter_ul_t;
/* minute collection task information */
typedef struct _afnf2_fn01_min_clct_task_info {
/* collection interval, unit is 1 minute */
uint8_t interval;
/* meter count */
uint16_t meter_cnt;
} afnf2_fn01_min_clct_task_info_t;
typedef struct _afnf2_fn01_min_clct_rpt_ctrl {
/* report control flag */
uint8_t rpt_flag;
/* task count */
uint8_t task_cnt;
/* task information */
afnf2_fn01_min_clct_task_info_t task_info[0];
} afnf2_fn01_min_clct_rpt_ctrl_t;
/* minute collect configuration information */
typedef struct _afnf2_min_clct_cfg_info {
/* dst meter address, little-endian */
uint8_t addr[IOT_MAC_ADDR_LEN];
/* collection interval, unit is 1 minute */
uint8_t interval;
/* flag of cfg, see PROTO_3762_MIN_CLCT_RPT_CFG_FLAG_XXX */
uint8_t flag;
/* proto data type. see PROTO_TYPE_XXX */
uint8_t proto_type;
/* master di, master di is 698 protocol frozen data di */
uint32_t m_di;
/* secondary di cnt */
uint8_t cnt;
/* secondary di, secondary di is 698 protocol data di */
uint32_t s_di[0];
} afnf2_min_clct_cfg_info_t;
typedef struct _afnf2_f02_min_clct_cfg_dl {
/* config information */
afnf2_min_clct_cfg_info_t cfg;
} afnf2_f02_min_clct_cfg_dl_t;
typedef struct _afnf2_f02_min_clct_cfg_ul {
/* see PRPTO_3762_MIN_CLCT_CFG_XXX. */
uint8_t state;
} afnf2_f02_min_clct_cfg_ul_t;
typedef struct _afnf2_f03_min_clct_cfg {
/* config information */
afnf2_min_clct_cfg_info_t cfg;
} afnf2_f03_min_clct_cfg_t;
/* minute collect con meter reading data structure */
typedef struct _afnf2_min_clct_con_mr_data {
/* proto data type. PROTO_TYPE_XXX */
uint8_t proto_type;
/* reserved */
uint8_t rsvd;
/* data length */
uint16_t len;
/* report data */
uint8_t data[0];
} afnf2_min_clct_con_mr_data_t;
typedef struct _afnf2_fn04_min_clct_con_req {
/* data request */
afnf2_min_clct_con_mr_data_t req;
} afnf2_fn04_min_clct_con_req_t;
typedef struct _afnf2_fn04_clct_con_rsp {
/* data respond */
afnf2_min_clct_con_mr_data_t rsp;
} afnf2_fn04_min_clct_rsp;
/* proto_3762_get_checksum - calculate the check sum according to 376.2 protocol
* @ctrl: ctrl byte for calculating checksum
* @data: data to calculate checksum
* @len: length of data
* @return: the checksum
*/
uint8_t proto_3762_get_checksum(uint8_t ctrl, uint8_t *data, uint32_t len);
/* proto_3762_get_fn_code - get function code according to 376.2 protocol
* @data: data buffer point to Fn of 376.2 packet
* @return: the Fn code
*/
uint8_t proto_3762_get_fn_code(uint8_t *data);
/**
* @brief sanity_check_2013 - check if a 376.2 packet is a valid
* @param data: packet data
* @param len: length of the packet data
* @retval: 0 -- sanity check passed
* @retval: INVALID_DATA -- invalid data
* @retval: INVALID_DATA_LEN -- invalid data length
* @retval: VALIDATE_FAILED -- validate failed
* @retval: INVALID_FORMAT -- invalid format
*/
uint32_t proto_3762_sanity_check(uint8_t* data, uint16_t len);
/**
* @brief proto_3762_convert_max_fn_to_bitmap() - convert a fn to a bitmap.
* each bit in the bitmap indicate if the corresponding fn is supported.
* assume all fn less than the max_fn are also supported.
* example max_fn = 64 means fn1 to fn64 are supported.
* set fn_bf[0] to fn_bf[7] is 0xff, set fn_bf[8] to fn_bf[31] is 0x00
*
* @param max_fn: the max fn of supports, value range: 1 - 255
* @param fn_buf: An array of 32 bytes
*/
void proto_3762_convert_max_fn_to_bitmap(uint16_t max_fn, uint8_t *fn_buf);
/* proto_3762_fn_index_add - add a fn support in bitmap
* @fn: the fn that need to support
* @fn_buf: the bitmap buf
*/
void proto_3762_fn_index_add(uint8_t fn, uint8_t *fn_buf);
/* proto_3762_fn_index_del - delete a fn nonsupport in bitmap
* @fn: the fn that need to nonsupport
* @fn_buf: the bitmap buf
*/
void proto_3762_fn_index_del(uint8_t fn, uint8_t *fn_buf);
/* 1 byte checksum , and 1 byte backcode */
#define PROTO_3762_CS_BCODE_LEN 2
/* 3762 data length before app data */
#define PROTO_3762_RSVD_LEN (sizeof(pkt_3762_hdr_t) + \
sizeof(proto_3762_app_data_t))
/* @brief: get header length before app data in 3762 pkt.
* @param mac_cnt: mac count of the 3762 proto
* @return: header length of the 3762 proto.
*/
static inline uint32_t proto_3762_get_header_len(uint32_t mac_cnt)
{
return PROTO_3762_RSVD_LEN + mac_cnt * PROTO_3762_MAC_ADDR_LEN;
}
/**
* @brief: get length to reserve before app data in 3762 pkt.
* it's the sum of header length and extra headroom.
* @param mac_cnt: mac count of the 3762 proto
* @return: length of 3762 UART packet header.
*/
static inline uint32_t proto_3762_get_rsvd_len(uint32_t mac_cnt)
{
return max(IOT_SG_EXT_HEADROOM, IOT_SG_CLI_CHANNEL_HEADROOM) +
proto_3762_get_header_len(mac_cnt);
}
/**
* @brief: get length of iot_pkt to alloc for sending the 3762 pkt
* to uart.
* @mac_cnt: mac count in address field in 3762
* @data_len: app data len in 3762 packet
* return: length of the 3762 UART packet
*/
static inline uint32_t proto_3762_get_pkt_len(uint32_t mac_cnt,
uint32_t data_len)
{
return proto_3762_get_rsvd_len(mac_cnt) + data_len +
PROTO_3762_CS_BCODE_LEN;
}
/**
* @brief proto_3762_nid_to_buf() - convert uint32_t's nid to 3 bytes
*
* @param nid: the value of uint32_t's network id
* @param p_nid: the pointer of 3 bytes buf
*/
void proto_3762_nid_to_buf(uint32_t nid, uint8_t *p_nid);
/**
* @brief proto_3762_check_frame_handler - check whether the frame is legitimate.
* @param buffer: the buffer containing 3762 data.
* @param buffer_len: len of the buffer.
* @param is_frame: false: the frame isn't legitimate; true: the frame is
* legitimate.
*/
void proto_3762_check_frame_handler(uint8_t* buffer, uint32_t buffer_len,
bool_t* is_frame);
#pragma pack(pop) /* restore the pack status */
#ifdef __cplusplus
}
#endif
#endif /* PROTO_3762_H */