初始提交

This commit is contained in:
2024-09-28 14:24:04 +08:00
commit c756587541
5564 changed files with 2413077 additions and 0 deletions

3372
app/dev_test/iot_app_dev_test.c Executable file

File diff suppressed because it is too large Load Diff

349
app/dev_test/iot_dev_test.h Executable file
View File

@@ -0,0 +1,349 @@
/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#ifndef _IOT_PLC_DEV_TEST_H
#define _IOT_PLC_DEV_TEST_H
#include "iot_task_api.h"
#include "iot_proto_dev_test.h"
#ifdef __cplusplus
extern "C" {
#endif
#define UART_0_BAUD_RATE 9600
/* define how many uart's baudrate is supported */
#define SUPPORTED_BAUD_CNT 4
/* default uart baudrate' index: 9600 */
#define DEFAULT_BAUDRATE_INDEX 2
/* define CKQ operation mode */
typedef enum {
IOT_DEV_TEST_APP_MODE_M2S = 0,
IOT_DEV_TEST_APP_MODE_M2M = 1,
IOT_DEV_TEST_APP_MODE_MAX
} iot_dev_test_app_mode;
/* indicate how long the collector's mac is vailid, unit: 250ms */
#define IOT_DEV_TEST_COLLECTOR_VAILID_CNT 80
/* indicate whether clear the clollector's mac automaticly or not */
#define IOT_DEV_TEST_COLLECTOR_AUTO_CLR 0
/* define flag to indicate switch to m2m mode or not */
#define IOT_DEV_TEST_M2M_MODE_SWITCH_DISABLE 0
#define IOT_DEV_TEST_M2M_MODE_SWITCH_ENABLE 1
/* indicate build CIU_TESTER or CIU */
#define IOT_DEV_TEST_BUILD_CIU_TESTER 0
/* indicate whether the dev_test support mutiband or not */
#define IOT_DEV_TEST_SUPPORT_MUTIBAND 0
/* indicate how to send mode cfg, broadcast or unicast,
* in HX's application, this should be 0
*/
#define IOT_DEV_TEST_BROADCAST_MODD_CFG 1
/* indicate whether the dev_test support pushed-data or not */
#define IOT_DEV_TEST_HANDLE_PUSH_DATA_EN 0
/* enable or disable to read the meter which belongs to the collector */
#define IOT_DEV_TEST_SUPPORT_CT_MR_EN 0
/* define flag indicating local m2m sub mode */
#define IOT_DEV_TEST_M2M_SUBMODE_CIU 0
#define IOT_DEV_TEST_M2M_SUBMODE_CIUTESTER 1
/* define flag to indicate CKQ addr is set or not */
#define IOT_DEV_TEST_ADDR_NOT_SET 0
#define IOT_DEV_TEST_ADDR_SET 1
/* define flag to indicate succeed to query CIU addr or not*/
#define IOT_DEV_TEST_QUERY_CIU_ADDR_FAIL 0
#define IOT_DEV_TEST_QUERY_CIU_ADDR_SUCC 1
/* define priorities for message to be handle */
#define IOT_DEV_TEST_TASK_QUEUE_HP 0
#define IOT_DEV_TEST_TASK_QUEUE_LP 1
#define IOT_DEV_TEST_TASK_QUEUE_MAX_PRIO 2
#define IOT_DEV_TEST_TASK_LINK_ID 2
#define IOT_DEV_TEST_TASK_POOL_SIZE 128
/* message type */
#define IOT_DEV_TEST_MAC_MSG 0
#define IOT_DEV_TEST_TIMER_MSG 1
#define IOT_DEV_TEST_UART_RECV_MSG 2
/* message id for timer */
#define IOT_DEV_TEST_TIMER_CHECK 1 /* check cache data in buffer */
#define IOT_DEV_TEST_TIMER_QUERY_ADDR 2 /* query addr at m2m ciu mode */
/* check cache data in sendq interval, unit is ms */
#define IOT_DEV_TEST_PERIODIC_TIMER_INTERVAL (250)
/* count for boardcast sta connection_less's mode config interval */
#define IOT_DEV_TEST_BCAST_TIMER_CNT 4
/* max life-span cnt, which decide how long will the buff keep the frame info */
#define IOT_DEV_TEST_MAX_LIFE_SPAN_CNT 24
/* parameter sent to sta for meter reading timeout config, uint is 100ms */
#define IOT_DEV_TEST_CFG_MR_TIMEOUT 16
/* query interval when query addr at m2m ciu mode, unit is ms */
#define IOT_DEV_TEST_QUERY_ADDR_TIMER_INTERVAL (1000)
/* max cnt for querying ciu addr at m2m ciu mode */
#define IOT_DEV_TEST_QUERY_ADDR_CNT_MAX 3
/* Macro to define msdu pkt pool number*/
#define IOT_DEV_TEST_POOL_NUM 8
/* UART received buffer size */
#define IOT_DEV_TEST_UART_RECV_BUF_SIZE 512
/* sta control configuring effective duration, unit is sec */
#define IOT_DEV_TEST_MODE_CFG_DUR 30
/* uart frame protocal */
#define IOT_DEV_TEST_PROTO_TYPE_TRANSPARENT 0
#define IOT_DEV_TEST_PROTO_TYPE_645_1997 1
#define IOT_DEV_TEST_PROTO_TYPE_645_2007 2
#define IOT_DEV_TEST_PROTO_TYPE_69845 3
/* define target device type ID */
#define IOT_DEV_TEST_TARGET_ID_CCO 0
#define IOT_DEV_TEST_TARGET_ID_STA 1
/* lenth of data buffer for DL/T 645-2007 cmd handling */
#define IOT_DEV_TEST_DATA_BUFF_LEN 200
/* defining target device type identifier mask */
#define IOT_DEV_TEST_TARGET_ID_MSK_CCO \
(1 << IOT_DEV_TEST_TARGET_ID_CCO)
#define IOT_DEV_TEST_TARGET_ID_MSK_STA \
(1 << IOT_DEV_TEST_TARGET_ID_STA)
/* rerty invterval , unit is IOT_DEV_TEST_PERIODIC_TIMER_INTERVAL */
#define IOT_DEV_TEST_APP_MAX_RETRY_INTV_CNT 4
/* magic code in flash head */
#define IOT_DEV_TEST_FLASHINFO_MAGIC1 0xAA55AA55
/* magic code in flash tail */
#define IOT_DEV_TEST_FLASHINFO_MAGIC2 0x55AA55AA
/* max retry count for sending bootup indication */
#define IOT_DEV_TEST_BOOT_IND_RETRY_MAX_CNT 3
/* retry interval for sending bootup indication, uint: 250ms */
#define IOT_DEV_TEST_BOOT_IND_RETRY_INTV 4
/* reserved flash size for future usage */
#define IOT_DEV_TEST_RESVD_FLASH_SIZE 55
#pragma pack(push) /* save the pack status */
#pragma pack(1) /* 1 byte align */
/* writable section layout in PIB */
typedef struct _iot_dev_test_pib_t {
/* 0xAA55AA55, the head of this struct */
uint32_t magic1;
/* mac addr for push-data filter */
uint8_t match_mac[IOT_MAC_ADDR_LEN];
/* counter of bootup */
uint8_t boot_cnt;
/* UART baudrate index */
uint8_t baud_index;
/* flag to mark if fix_ppm valid */
uint8_t ppm_valid : 1,
/* flag to mark if tool_ppm valid */
tool_ppm_valid : 1,
/* reserved for future usage */
rsvd : 6;
/* ppm value to be fixing */
int8_t fix_ppm;
/* target device address for ppm value */
uint8_t ppm_target_mac[IOT_MAC_ADDR_LEN];
/* ppm value from tool */
int8_t tool_ppm;
/* reserved for future usage */
uint8_t resv[IOT_DEV_TEST_RESVD_FLASH_SIZE];
/* 0x55AA55AA, the tail of this struct */
uint32_t magic2;
} iot_dev_test_pib_t;
#pragma pack(pop) /* restore the pack status */
/* store the frame and infor extracted from the frame */
typedef struct _frame_pkt_t {
/* msdu sequnce number */
uint16_t app_sn;
/* dst meter addresss */
uint8_t dst_mac[IOT_MAC_ADDR_LEN];
/* type of protocol, see CONN_LESS_PROTO_TYPE_XXX */
uint8_t p_type;
/* flag to mark if app_sn valid */
uint8_t sn_valid :1,
/* flag to mark if this package is used for ppm detect. */
ppm_detect :1,
/* reserved for future usage */
rsvd :6;
/* full 645/698 frame */
iot_pkt_t *data;
} frame_pkt_t;
/* frame infor extracted from the frame */
typedef struct _frame_info_t {
/* life-span counter */
uint16_t span_cnt;
/* msdu been sent counter, 0 means the buffer is not used */
uint8_t send_cnt;
/* frame data and releated infor */
frame_pkt_t frm;
} frame_info_t;
/* frame infor pool */
typedef struct _info_pool_t {
/* how many buffers are not used */
uint8_t remain_cnt;
/* infor extracted from the frame */
frame_info_t frm_info[IOT_DEV_TEST_POOL_NUM];
} info_pool_t;
/* ppm detect record info */
typedef struct _iot_dev_test_ppm_detect_info {
/* massage seq number */
uint16_t sn;
/* ppm for send */
int8_t fix_ppm;
} iot_dev_test_ppm_detect_info_t;
typedef struct _iot_dev_test_msg {
/* standard iot_task message */
iot_task_msg_t msg;
/* pointer to message data */
void *data;
}iot_dev_test_task_msg_t;
/* define ppm detect message info record buffer depth */
#define IOT_DEV_TEST_PPM_DETECT_REC_MAX 10
/* define PPM detect state */
#define PPM_DETECT_STATE_IDLE 0
#define PPM_DETECT_STATE_DONE 1
#define PPM_DETECT_STATE_DOING 2
/* define ppm detect step */
#define PPM_DETECT_STEP_VALUE 5
#define PPM_DETECT_STEP_MAX_CNT 4
/* ppm detect control descriptor */
typedef struct _iot_dev_test_ppm_detec_desc {
/* target address of the ppm detect */
uint8_t ppm_target_mac[IOT_MAC_ADDR_LEN];
/* pm value detected */
int8_t fix_ppm;
/* ppm detect state */
uint8_t ppm_detect_state;
/* ppm detect message info record buffer */
iot_dev_test_ppm_detect_info_t ppm_detect_rec[\
IOT_DEV_TEST_PPM_DETECT_REC_MAX];
/* update index for ppm_detect_rec */
uint8_t ppm_detect_rec_idx;
/* the number of valid information in "ppm_detect_rec" buffer */
uint8_t ppm_detect_rec_cnt;
/* detecting ppm index */
uint8_t ppm_detect_cnt;
} iot_dev_test_ppm_detec_desc_t;
typedef struct _iot_dev_test_task_data {
/* app sending sequnce number for msdu */
uint16_t app_sn;
/* sequence number for pushed-data pkt */
uint16_t pushed_seq;
/* sequence number for config data */
uint16_t config_seq;
/* handle of the ping iot_task */
iot_task_h task_handle;
/* a flag indicating if app registered successfully */
uint8_t app_registered;
/* link id used for sending msdu */
uint8_t link_id;
/* tx link type, see IOT_DEV_TEST_LINK_TYPE_XX */
uint8_t tx_link_type;
/* indication for device is ready for data transmition or not */
uint8_t dev_ready;
/* device type */
uint8_t dev_type;
/* role of local device */
uint8_t dev_role;
/* operation mode of local device */
uint8_t dev_mode;
/* flag indicating m2m test mode or not */
uint8_t m2m_sub_mode;
/* user type */
uint8_t user_type;
/* mac address of local device */
uint8_t mac_addr[IOT_MAC_ADDR_LEN];
/* mac address of qsxj meter */
uint8_t qsxj_addr[IOT_MAC_ADDR_LEN];
/* flag indicate in m2m mode, check receive pkt dst mac with self */
uint8_t m2m_check_addr;
/* flag indicate in m2m ciu mode, succeed to query ciu addr or not */
uint8_t m2m_ciu_query_addr;
/* frequency band value, see PLC_LIB_FREQ_BAND_X */
uint8_t band_id;
/* flag to mark if ext configuration is enabled.
* 1 means enable, 0 means disable
*/
uint8_t ext_cfg_en;
/* ext configuration */
dev_test_ext_cfg_t ext_cfg;
/* handle of this app */
iot_plc_app_h app_handle;
/* timer to call api periodically */
timer_id_t periodic_tm;
/* timer to query ciu addr periodically */
timer_id_t query_addr_tm;
/* counter for querying addr at m2m ciu mode */
uint8_t query_addr_cnt;
/* com for upper host */
void* host_com;
/* frame infor pool */
info_pool_t info_pool;
/* record the pib section's address */
uint8_t *section;
/* flash info stored in PIB */
iot_dev_test_pib_t flashinfo;
/* flag to indicate sending bootup indication is enabled or not */
uint32_t boot_ind_en;
/* app SN for msdu data reporting's de-reprocessing*/
uint32_t stored_app_sn;
/* collector's address */
uint8_t collector[IOT_MAC_ADDR_LEN];
/* indicate whether the collector's address is vaild or not */
uint16_t collector_vaild :1,
/* indicate how long the collector's address will be vaild */
collector_vaild_cnt :15;
/* ppm ctrl desc */
iot_dev_test_ppm_detec_desc_t ppm_desc;
/* dlt645-2007 data buffer */
uint8_t data_buf[IOT_DEV_TEST_DATA_BUFF_LEN];
}iot_dev_test_task_data_t;
/*
* brief: entry for dev_test app
* @return:
* @retval: ERR_PENDING - if app want to delay the plc network formation.
* @retval: other - plc network formation will be started automatically.
*/
uint32_t app_dev_test_entry();
#ifdef __cplusplus
}
#endif
#endif //_IOT_PLC_DEV_TEST_H

View File

@@ -0,0 +1,158 @@
/****************************************************************************
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_PROTO_DEV_TEST_H
#define _IOT_PROTO_DEV_TEST_H
#ifdef __cplusplus
extern "C" {
#endif
#pragma pack(push) /* save the pack status */
#pragma pack(1) /* 1 byte align */
/* FN code stands for CIU's ack for push-data */
#define IOT_DEV_TEST_645_FN_ACK_FROM_CIU 0x1F
/* FN code stands for bootup indication's response */
#define IOT_DEV_TEST_645_FN_RSP_BOOTUP_IND 0x13
/* indicate whether the debug infor should be printed or not */
#define IOT_DEV_TEST_DEBUG_EN 0
/* define the buffer length for debug infor printing */
#define IOT_DEV_TEST_LOG_BUF_LEN 128
enum dev_test_fn
{
/* set band Fn */
IOT_DEV_TEST_FN_SET_BAND = 0x01,
/* querry band Fn */
IOT_DEV_TEST_FN_QUERRY_BAND = 0x02,
/* querry software version Fn */
IOT_DEV_TEST_FN_QUERRY_VER = 0x03,
/* respons for querring band Fn */
IOT_DEV_TEST_FN_QUERRY_BAND_RSP = 0x04,
/* respons for querring software version Fn */
IOT_DEV_TEST_FN_QUERRY_VER_RSP = 0x05,
/* set local mac Fn */
IOT_DEV_TEST_FN_SET_MAC = 0x06,
/* querry local mac Fn */
IOT_DEV_TEST_FN_QUERRY_MAC = 0x07,
/* respons for querring mac Fn */
IOT_DEV_TEST_FN_QUERRY_MAC_RSP = 0x08,
/* set CKQ operation mode */
IOT_DEV_TEST_FN_SET_OP_MODE = 0x09,
/* query CKQ operation mode */
IOT_DEV_TEST_FN_QUERY_OP_MODE = 0x0A,
/* response for querying operation mode */
IOT_DEV_TEST_FN_QUERY_OP_MODE_RSP = 0x0B,
/* set UART baudrate */
IOT_DEV_TEST_FN_SET_UART_BAUDRATE = 0x0C,
/* query UART baudrate */
IOT_DEV_TEST_FN_QUERY_BAUDRATE = 0x0D,
/* response for querying UART baudrate */
IOT_DEV_TEST_FN_QUERY_BAUD_RSP = 0x0E,
/* set rf option and rf channel */
IOT_DEV_TEST_FN_SET_RF = 0x0F,
/* set rf tx power */
IOT_DEV_TEST_FN_SET_RF_TX_POWER = 0x10,
/* set hplc tx power */
IOT_DEV_TEST_FN_SET_HPLC_TX_POWER = 0x11,
/* set tx link type */
IOT_DEV_TEST_FN_SET_TX_LINK_TYPE = 0x12,
/* used Fn Max count */
IOT_DEV_TEST_FN_PRIVATE_MAX = IOT_DEV_TEST_FN_SET_TX_LINK_TYPE
};
/* minimal respons frame lenth */
#define IOT_DEV_TEST_RSP_FRAME_LEN_MIN 0x0C
/* response status */
#define IOT_DEV_TEST_RSP_OK 0x00
#define IOT_DEV_TEST_RSP_ERR 0x01
/* reaseon for response error */
enum dev_test_rsp_reason
{
/* no err */
IOT_DEV_TEST_REASON_OK = 0x00,
/* out of range */
IOT_DEV_TEST_REASON_OUT_RNG = 0x01,
/* double setting */
IOT_DEV_TEST_REASON_DUP_SET = 0x02,
/* not supporting */
IOT_DEV_TEST_REASON_NOT_SUPPORT = 0x03,
/* error mac */
IOT_DEV_TEST_REASON_MAC_INVALID = 0x04,
/* saving error */
IOT_DEV_TEST_REASON_SAVE_ERR = 0x05,
/* configuration invalid */
IOT_DEV_TEST_REASON_CFG_INVALID = 0x06
};
/* supporting max band */
#define IOT_DEV_TEST_MAX_BAND 0x04
/* data lenth in response frame's data field */
#define IOT_DEV_TEST_DATA_FIELD_LEN 0x04
typedef struct _dev_test_ext_cfg {
/* flag to mark if rf_option and rf_channel config is available */
uint8_t rf_valid :1,
/* flag to mark if rf_tx_power config is available */
rf_power_valid :1,
/* flag to mark if hplc_tx_power config is available */
hplc_power_valid :1,
/* rf tx only for app */
rf_tx_only :1,
/* reserved for future */
rsvd1 :4;
/* rf option, see IOT_PLC_RF_OPTION_XX */
uint8_t rf_option;
/* rf channel, see IOT_PLC_OPTION1_CHANNEL_ID_XX */
uint8_t rf_channel;
/* tx power of rf, unit is 1 dbm */
int8_t rf_tx_power;
/* tx power of hplc, unit is 1 dbuv */
uint8_t hplc_tx_power;
/* reserved for future */
uint8_t rsvd2[5];
} dev_test_ext_cfg_t;
typedef struct _dev_test_mode_cfg {
/* band ID to be configured, see PLC_LIB_FREQ_BAND_X */
uint8_t band_id;
/* configuring effective duration, uint is sec */
uint8_t dur;
/* the target device ID group that needs to respond to this command.
* see IOT_DEV_TEST_TARGET_ID_MSK_XXX.
*/
uint32_t target_id_mask :2,
/* reserved for future */
reserved :29,
/* flag to mark if ext configuration is enabled.
* 1 means enable, 0 means disable
*/
ext_cfg_en :1;
/* ext configuration */
dev_test_ext_cfg_t ext_cfg[0];
} dev_test_mode_cfg_t;
#pragma pack(pop) /* restore the pack status */
#ifdef __cplusplus
}
#endif
#endif //_IOT_PROTO_DEV_TEST_H