231 lines
7.7 KiB
C
231 lines
7.7 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 _IOT_SUNSOLAR_TASK_H_
|
|
#define _IOT_SUNSOLAR_TASK_H_
|
|
|
|
/* os shim includes */
|
|
#include "os_timer_api.h"
|
|
|
|
/* common includes */
|
|
#include "iot_plc_api.h"
|
|
#include "iot_task_api.h"
|
|
#include "iot_uart_api.h"
|
|
#include "iot_pkt_api.h"
|
|
#include "iot_ipc_api.h"
|
|
#include "proto_645_vendor.h"
|
|
|
|
/* sunsolar internal header files */
|
|
#include "iot_sunsolar_sta.h"
|
|
#include "iot_sunsolar_cco.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* enable/disable sunsolar app data print */
|
|
#define IOT_SUNSOLAR_DEBUG (1)
|
|
|
|
#define iot_sunsolar_printf(fmt, ...) \
|
|
do { \
|
|
iot_cus_printf("[sunsolar]" fmt, ##__VA_ARGS__); \
|
|
}while(0)
|
|
|
|
#define TASK_NAME "[sunsolar]"
|
|
|
|
#define IOT_SUNSOLAR_TASK_UART_BUF_SIZE (2048 + 64)
|
|
#define IOT_SUNSOLAR_UART_BANDRATE (9600)
|
|
|
|
/** Message type defination: */
|
|
#define IOT_SUNSOLAR_MSG_TYPE_SG_APP 1 /* messages from sg app */
|
|
#define IOT_SUNSOLAR_MSG_TYPE_PLC 2 /* messages from PLC */
|
|
#define IOT_SUNSOLAR_MSG_TYPE_UART 3 /* messages from uart port */
|
|
#define IOT_SUNSOLAR_MSG_TYPE_TIMER 4 /* messages from timer */
|
|
#define IOT_SUNSOLAR_MSG_TYPE_INTERNAL 5 /* messages from internal */
|
|
|
|
/* event type definition */
|
|
#define IOT_SUNSOLAR_EVENT_PV0_LOW_VOLT (1 << 0) /* pv0 low volt event */
|
|
#define IOT_SUNSOLAR_EVENT_PV1_LOW_VOLT (1 << 1) /* pv1 low volt event */
|
|
|
|
/* SG_APP type message id definition */
|
|
#define IOT_SUNSOLAR_MSG_ID_SG_DATA 1 /* data from SG APP */
|
|
|
|
/* UART type message id definition */
|
|
#define IOT_SUNSOLAR_MSG_ID_UART_DATA 1 /* data delivered from UART */
|
|
|
|
/* PLC type message id definition */
|
|
#define IOT_SUNSOLAR_MSG_ID_PLC_PKT 1 /* pkt delivered from PLC */
|
|
|
|
/* message id for updating device info */
|
|
#define IOT_SUNSOLAR_TASK_MSG_ID_DEV_INFO_UPDATE (1)
|
|
|
|
#define IOT_SUNSOLAR_TASK_ID IOT_SUNSOLAR_MID
|
|
|
|
/* stack size of task */
|
|
#define IOT_SUNSOLAR_TASK_STACK_SIZE (0)
|
|
|
|
#define IOT_SUNSOLAR_TASK_PROTO_TASK_PRIO (6)
|
|
|
|
/* number of messages pending in queue. */
|
|
#if (IOT_PSRAM_ENABLE)
|
|
#define IOT_SUNSOLAR_TASK_POOL_SIZE (254)
|
|
#else
|
|
#define IOT_SUNSOLAR_TASK_POOL_SIZE (64)
|
|
#endif
|
|
|
|
/* sunsolar module protocol type definition */
|
|
#define IOT_SUNSOLAR_PROTO_TYPE_TRANSPARENT 0
|
|
#define IOT_SUNSOLAR_PROTO_TYPE_645_2007 1
|
|
|
|
/* sunsolar device link state */
|
|
#define SUNSOLAR_OFFLINE 0
|
|
#define SUNSOLAR_ONLINE 1
|
|
|
|
/* define the data transfer road */
|
|
#define IOT_SUNSOLAR_DATA_FROM_SG_APP 0
|
|
#define IOT_SUNSOLAR_DATA_FROM_UART 1
|
|
|
|
/* define WDG reset time, uint is 1min */
|
|
#define IOT_SG_STA_COLLECTOR_WDG_RESET_TIME (120)
|
|
|
|
/* define sunsolar alloc buffer size */
|
|
#define IOT_SUNSOLAR_BUFFER_SIZE (255)
|
|
|
|
/** sunsolar task message */
|
|
typedef struct _sunsolar_msg_t {
|
|
/* iot task message */
|
|
iot_task_msg_t task_msg;
|
|
/* pointer to message data */
|
|
void *data;
|
|
/* another data field */
|
|
uint32_t data2;
|
|
} sunsolar_msg_t;
|
|
|
|
typedef struct _g_sunsolar_t {
|
|
iot_task_config_t task_cfg;
|
|
/* task handle */
|
|
iot_task_h task;
|
|
/* uart handle */
|
|
iot_uart_h uart_h;
|
|
/* cfg role */
|
|
uint8_t role;
|
|
/* local mac address. */
|
|
uint8_t local_mac[IOT_MAC_ADDR_LEN];
|
|
/* cco mac */
|
|
uint8_t cco_mac[IOT_MAC_ADDR_LEN];
|
|
/* module joined network */
|
|
uint8_t plclink_state;
|
|
/* plc app regsiter configuration */
|
|
iot_plc_app_t app_cfg;
|
|
/* handle of registered IPC */
|
|
iot_ipc_h ipc_h;
|
|
/* handle of registered plc app */
|
|
iot_plc_app_h plc_app_h;
|
|
/* plc app register status. 1 means registered */
|
|
uint8_t app_reg;
|
|
/* msdu recv snr */
|
|
int8_t snr;
|
|
/* msdu recv rssi */
|
|
uint8_t rssi;
|
|
/* sunsolar message executing callback */
|
|
iot_task_msg_execute_func_t msg_exe_func;
|
|
/* sunsolar message canceling callback */
|
|
iot_task_msg_cancel_func_t msg_cancel_func;
|
|
/* sunsolar event executing callback */
|
|
iot_task_event_func_t event_exe_func;
|
|
union {
|
|
/* sta role specific global data */
|
|
iot_sunsolar_sta_global_t *sta;
|
|
/* cco role specific global data */
|
|
iot_sunsolar_cco_global_t *cco;
|
|
} desc;
|
|
} g_sunsolar_t;
|
|
|
|
/* sunsolar global internal structure */
|
|
extern g_sunsolar_t *p_gsunsolar;
|
|
|
|
/**
|
|
* @brief iot_sunsolar_data_print() - print data, format is hex.
|
|
* @param str: a short string to be printed before data
|
|
* @param buf: buffer contain data to be printed
|
|
* @param len: length of data in the buffer
|
|
*/
|
|
void iot_sunsolar_data_print(const char* str, uint8_t* buf, uint32_t len);
|
|
|
|
/**
|
|
* @brief iot_sunsolar_rtctime_to_time() - convert rtc time to integer timestamp.
|
|
* @param tm: pointer to the rtc time
|
|
* @retval: integer timestamp relative to 1970-1-1 00:00:00
|
|
*/
|
|
int32_t iot_sunsolar_rtctime_to_time(iot_time_tm_t *tm);
|
|
|
|
/**
|
|
* @brief iot_sunsolar_time_to_rtctime() - convert integer timestamp to rtc time.
|
|
* @param time: integer timestamp relative to 1970-1-1 00:00:00
|
|
* @param tm: return rtc time
|
|
*/
|
|
void iot_sunsolar_time_to_rtctime(uint32_t time, iot_time_tm_t *tm);
|
|
|
|
/**
|
|
* @brief iot_sunsolar_uart_config() - uart config setting.
|
|
* @param baud: baudrate
|
|
* @param parity: see IOT_UART_PARITY_XXX
|
|
* @param data: data bits
|
|
* @param stop: stop flag
|
|
* @param proto_type: proto type to set.
|
|
*/
|
|
void iot_sunsolar_uart_config(uint32_t baud, uint8_t parity,
|
|
uint8_t data, uint8_t stop, uint8_t proto_type);
|
|
|
|
/**
|
|
* @brief iot_sunsolar_send_data_to_sg_app() - send data to sg app.
|
|
* @param data : the data to send.
|
|
* @param data_len : the send data length.
|
|
*/
|
|
void iot_sunsolar_send_data_to_sg_app(uint8_t *data, uint8_t data_len);
|
|
|
|
/**
|
|
* @brief iot_sunsolar_task_msg_post() - post messages to sunsolar app queue
|
|
* @param msg_type: message type, see IOT_SUNSOLAR_MSG_TYPE_XXXX.
|
|
* @param msg_id: message id, see IOT_SUNSOLAR_MSG_ID_XXXX.
|
|
* @param prio: message prio.
|
|
* @param data: data pointer carried by message
|
|
* @param data2: integer data carried by messages
|
|
*/
|
|
void iot_sunsolar_task_msg_post(uint16_t msg_type, uint16_t msg_id,
|
|
uint8_t prio, void *data, uint32_t data2);
|
|
|
|
/**
|
|
* @brief iot_sunsolar_uart_send() - send data to uart port.
|
|
* @param p_pkt: packet for sending to uart port.
|
|
* @return: ERR_OK - send successfully.
|
|
* ERR_FAIL - send failed.
|
|
*/
|
|
uint32_t iot_sunsolar_uart_send(iot_pkt_t *p_pkt);
|
|
|
|
/**
|
|
* @brief iot_sunsolar_msdu_send() - send data to plc.
|
|
* @param addr : send data to dst address.
|
|
* @param data : send data.
|
|
* @param len : send data length.
|
|
*/
|
|
int8_t iot_sunsolar_msdu_send(uint8_t *addr, uint8_t *data, uint16_t len);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* _IOT_SUNSOLAR_TASK_H_ */
|