166 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			166 lines
		
	
	
		
			5.0 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_TASK_H_
 | 
						|
#define _APP_MAIN_TASK_H_
 | 
						|
 | 
						|
#include "app_common.h"
 | 
						|
#include "app_types.h"
 | 
						|
#include "app_config.h"
 | 
						|
#include "proto_645.h"
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
  extern "C" {
 | 
						|
#endif
 | 
						|
 | 
						|
#define APP_ENABLE_DUMP_PKT_INFO        (1)
 | 
						|
 | 
						|
#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)
 | 
						|
 | 
						|
/* use for iot_print_config */
 | 
						|
#define ENABLE_PLC_LIB_LOG              (1)
 | 
						|
 | 
						|
/* unit is ms */
 | 
						|
#define APP_PKT_INFO_TIMER_PERIOD       (60*1000)
 | 
						|
/* 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)
 | 
						|
 | 
						|
/* message type for main task*/
 | 
						|
typedef enum {
 | 
						|
    E_MAIN_MSG_START = 0,
 | 
						|
    /* main task message from plc layer. */
 | 
						|
    E_MAIN_MSG_FROM_PLCMAC,
 | 
						|
    /* main task message from customer task. */
 | 
						|
    E_MAIN_MSG_FROM_CUSTASK,
 | 
						|
    /* main task message from main task. */
 | 
						|
    E_MAIN_MSG_FROM_MAINTASK,
 | 
						|
    /* main task message from timer. */
 | 
						|
    E_MAIN_MSG_FROM_TIMER,
 | 
						|
    E_MAIN_MSG_END
 | 
						|
} iot_main_task_msg_e;
 | 
						|
 | 
						|
/* message id for main task */
 | 
						|
typedef enum {
 | 
						|
    E_MAIN_MSG_ID_START,
 | 
						|
    /* main task receive data from cli app*/
 | 
						|
    E_MAIN_MSG_ID_CLIAPP_RECV,
 | 
						|
    /* main task receive data from plc layer */
 | 
						|
    E_MAIN_MSG_ID_PLCMAC_RECV,
 | 
						|
    /* main task receive dlt645 frame form customer task or plc layer */
 | 
						|
    E_MAIN_MSG_ID_645PKT_RECV,
 | 
						|
    /* main task send dlt645 frame to plc layer */
 | 
						|
    E_MAIN_MSG_ID_645PKT_TO_PLC,
 | 
						|
    E_MAIN_MSG_ID_END
 | 
						|
} iot_main_task_msg_id_e;
 | 
						|
 | 
						|
#define APP_MAIN_MSG_VALID(msg) ((msg)>E_MAIN_MSG_START && (msg)<E_MAIN_MSG_END)
 | 
						|
 | 
						|
typedef struct {
 | 
						|
    /* The main entity of message. */
 | 
						|
    iot_task_msg_t msg;
 | 
						|
    /* The user data inside this message. */
 | 
						|
    void           *data;
 | 
						|
} app_msg_t;
 | 
						|
 | 
						|
typedef struct {
 | 
						|
    /* Task handle. */
 | 
						|
    iot_task_h        handle;
 | 
						|
    /* Keep the task configuration. */
 | 
						|
    iot_task_config_t cfg;
 | 
						|
} app_msg_task_h;
 | 
						|
 | 
						|
typedef struct {
 | 
						|
    uint8_t          link_id;
 | 
						|
    /* Indicates if this local device is ready. */
 | 
						|
    uint8_t          dev_ready;
 | 
						|
    /* This local device role, CCO or STA ... */
 | 
						|
    uint8_t          dev_role;
 | 
						|
    /* MAC of this local device. */
 | 
						|
    uint8_t          mac_addr[IOT_MAC_ADDR_LEN];
 | 
						|
    /* MAC of CCO in this topo. */
 | 
						|
    uint8_t          cco_addr[IOT_MAC_ADDR_LEN];
 | 
						|
    /* The network ID of this topo. */
 | 
						|
    uint32_t         nid;
 | 
						|
    /* cco network done */
 | 
						|
    uint8_t          cco_net_done;
 | 
						|
} app_dev_info;
 | 
						|
 | 
						|
typedef struct {
 | 
						|
    app_config     app_cfg;
 | 
						|
    /* This task will process all messages and events that from this very
 | 
						|
     * module.
 | 
						|
     */
 | 
						|
    app_msg_task_h msg_task;
 | 
						|
    /* The handle of this APP. */
 | 
						|
    iot_plc_app_h  app_hdl;
 | 
						|
    /* Indicates if this APP has registered to PLC-layer. */
 | 
						|
    uint32_t       app_reg;
 | 
						|
    /* Device information. */
 | 
						|
    app_dev_info   dev;
 | 
						|
    /* the time when get data from plc */
 | 
						|
    uint32_t       receivetime;
 | 
						|
    /* record last recv msdu snr */
 | 
						|
    int8_t         u_snr;
 | 
						|
}app_entity_t;
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief app_iot_dl645_entry() - Entry of iot dlt645 app.
 | 
						|
 *
 | 
						|
 * @param None.
 | 
						|
 *
 | 
						|
 * @return ERR_OK : create app done;
 | 
						|
 * @return ERR_PENDING : create app failed;
 | 
						|
 */
 | 
						|
uint32_t app_iot_dl645_entry(void);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_main_get_app_entry() - Get entry of iot dlt645 app.
 | 
						|
 *
 | 
						|
 * @param None.
 | 
						|
 *
 | 
						|
 * @return app_entity_t : app entry;
 | 
						|
 */
 | 
						|
app_entity_t * iot_main_get_app_entry(void);
 | 
						|
 | 
						|
/**
 | 
						|
 * @brief iot_main_task_msg_post() - Post message to main task.
 | 
						|
 *
 | 
						|
 * @param [in] msg_type : message type, see iot_cus_task_msg_e.
 | 
						|
 * @param [in] msg_id : message id, see iot_cus_task_msg_id_e.
 | 
						|
 * @param [in] data : message data.
 | 
						|
 *
 | 
						|
 * @return ERR_OK : message post done;
 | 
						|
 * @return ERR_FAIL : message post failed;
 | 
						|
 */
 | 
						|
uint32_t iot_main_task_msg_post(uint16_t msg_type, uint16_t msg_id, void *data);
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif  /* _APP_MAIN_TASK_H_ */
 |