Files
kunlun/app/iot_cus_at_app/common/app_main.h
2024-09-28 14:24:04 +08:00

199 lines
7.1 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_MAIN_H_
#define _APP_MAIN_H_
#include "app_common.h"
#include "app_types.h"
#include "app_config.h"
#ifdef __cplusplus
extern "C" {
#endif
#define APP_WORK_MODE_DISABLE 0
#define APP_WORK_MODE_ENABLE 1
#define APP_WORK_MODE_BYPASS 0
#define APP_WORK_MODE_AT 2
#define APP_WORK_MODE_PROTO 1
#define APP_WORK_MODE_MAX 2
#define APP_ENABLE_DUMP_PKT_INFO 1
#define APP_SW_VERSION_R 02 /* app software version, maximum is 0x0F */
#define APP_BOOT_VER 01
#define WQ_CHIP3011 0x3011 /* Chip Type */
#define MANU_CODE 0x02D0 /* Manu Code */
#define SDK_SW_VERSION "WQ_PLC_3011"
#define APP_DATA_BUF_SIZE (2048)
#define APP_PLC_CMD_PRIO 3
#define APP_TASK_MSG_PRIO 0
#define APP_MSG_HANDLE_TASK_PRIO 7
#define APP_MSG_TASK_PRIO_QUE 1
#define APP_MSG_PENDING_LIMIT 64
#define APP_LINK_ID 2
#define CHECK_ATCMD_BUF_SIZE 3
#define STA_OFFLINE_EVENT 0
#define STA_ONLINE_EVENT 1
/* use for iot_print_config */
#define ENABLE_PLC_LIB_LOG (1)
/* iot module board, stamps package, 22 pins */
#define APP_BOARD_STAMP_22P (41)
/* iot module board, goldenfinger package, 17 pins */
#define APP_BOARD_GOLDFINGER_17P (42)
#define APP_PKT_INFO_TIMER_PERIOD (60*1000) /* unit is ms */
/* interval to show signal led state, unit is ms */
#define IOT_PLC_SIGNAL_LED_SHOW_INTVAL (2000)
/* interval to check if all stas have joined the network, unit is ms */
#define IOT_PLC_NET_DONE_CHECK_INTVAL (500)
/* snr good minimum threshold, below this value is weak */
#define IOT_SNR_GOOD_MIN_THR (5)
/* snr strong minimum threshold */
#define IOT_SNR_STRONG_MIN_THR (20)
/* sta support max groups */
#define IOT_STA_SUPPORT_MAX_GROUP (32)
#define IOT_STA_GROUP_MAX_NUM (256)
#define IOT_STA_GROUP_BITMAP ((IOT_STA_GROUP_MAX_NUM+7)/8)
typedef enum {
E_CMD_ID_START,
E_CMD_ID_RCV_FROM_PLC,
E_CMD_ID_RCV_FROM_UART,
E_CMD_ID_RCV_FROM_ETHERNET,
E_CMD_ID_RCV_FROM_PLC_CONNLESS,
E_CMD_ID_RCV_FROM_UDP_SOCKET,
E_CMD_ID_RCV_FROM_TCP_SOCKET,
E_CMD_ID_RCV_FROM_CLI,
E_CMD_ID_UART_TO_UDP4,
E_CMD_ID_UART_TO_UDP6,
E_CMD_ID_UART_TO_TCP4,
E_CMD_ID_UART_TO_TCP6,
E_CMD_ID_PLC_PROTO,
E_CMD_ID_SEND_DATA_TO_PLC,
E_CMD_ID_END
} app_cmd_id_e;
typedef enum {
E_APP_MSG_START = 0,
E_APP_MSG_FROM_MAC,
E_APP_MSG_PROCESS,
E_APP_MSG_TIMER,
E_APP_MSG_END
} app_msg_id_e;
#define APP_MSG_VALID(msg) ((msg) > E_APP_MSG_START && (msg) < E_APP_MSG_END)
typedef struct {
uint16_t rx_length;
uint8_t buffer[APP_DATA_BUF_SIZE];
} app_data_buf;
typedef struct {
iot_task_msg_t msg; /* The main entity of message. */
void *data; /* The user data inside this message. */
} app_msg_t;
typedef struct {
iot_task_h handle; /* Task handle. */
iot_task_config_t cfg; /* Keep the task configuration. */
} app_msg_task_h;
typedef struct {
uint16_t group_cnt; /* valid group count */
uint8_t group[IOT_STA_GROUP_BITMAP]; /* group list */
} sta_group_list_t;
typedef struct {
uint8_t rmt_valid; /* Indicates if the remote device is ready. */
uint8_t link_id;
uint8_t dev_ready; /* Indicates if this local device is ready. */
uint8_t dev_role; /* This local device role, CCO or STA ... */
uint8_t mac_addr[IOT_MAC_ADDR_LEN]; /* MAC of this local device. */
uint8_t cco_addr[IOT_MAC_ADDR_LEN]; /* MAC of CCO in this topo. */
uint8_t rmt_addr[IOT_MAC_ADDR_LEN]; /* MAC of remote device we communicate with. */
uint32_t nid; /* The network ID of this topo. */
uint8_t cco_net_done; /* cco network done */
sta_group_list_t sta_group; /* sta group info */
} app_dev_info;
/** plc recv data information */
typedef struct _recv_info_t {
uint8_t mac[IOT_MAC_ADDR_LEN]; /* src mac */
uint8_t recv_flag; /* recv plc msg flag, 0: connless 1: conn */
int8_t recv_snr; /* received plc packet snr */
int8_t recv_rssi; /* received plc packet rssi */
} recv_info_t;
typedef void (*app_data_parser_func) (uint8_t * buf, uint32_t len, app_source_e source);
typedef void (*app_data_handle_func) (uint16_t data_id, app_source_e data_src,
const uint8_t *data, uint32_t data_len, void *info);
typedef void (*app_onoffline_stat_report) (uint8_t *dev_mac, uint8_t status);
typedef struct {
uint8_t enable;
app_data_parser_func data_parser;
app_data_handle_func data_handle;
app_onoffline_stat_report on_off_report;
} app_work_mode_t;
typedef struct {
app_config app_cfg;
iot_uart_h cmd_uart;
app_msg_task_h msg_task; /* This task will process all messages
and events that from this very module. */
uint8_t work_mode_now;
app_work_mode_t work_mode_reg[APP_WORK_MODE_MAX + 1];
iot_plc_app_h app_hdl; /* The handle of this cus at APP. */
iot_plc_app_h sila_nhm_hdl; /* The handle of non header mode. */
uint32_t app_reg; /* Indicates if this APP has registered
to PLC-layer. */
app_dev_info dev; /* Device information. */
uint8_t * out_buf; /* for save out buffer */
uint32_t receivetime; /* the time when get data from plc */
int8_t u_snr; /* record last recv msdu snr */
uint16_t cco_bcast_per_cnt; /* cco bcast period count */
/* flag of net enable, 1 mean enable, 0 mena disable. */
uint8_t net_enable;
uint8_t user_type; /* user type */
} app_entity_t;
uint32_t app_post_msg(uint16_t msg_type, uint16_t msg_id, void *data);
app_entity_t *app_get_main_entry();
uint8_t app_work_mode_register(uint8_t work_mode, void *parser_func,
void *data_handle_func, void* reporter_func);
uint8_t app_work_mode_unregister(uint8_t work_mode);
uint8_t app_set_work_mode(uint8_t work_mode);
uint8_t app_get_work_mode();
#ifdef __cplusplus
}
#endif
#endif /* _APP_MAIN_H_ */