135 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			135 lines
		
	
	
		
			4.2 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 COMMUNICATOR_H
 | 
						|
#define COMMUNICATOR_H
 | 
						|
 | 
						|
#include "os_types.h"
 | 
						|
#include "os_event.h"
 | 
						|
#include "os_lock.h"
 | 
						|
#include "iot_config.h"
 | 
						|
#include "iot_pkt_api.h"
 | 
						|
#include "iot_frame_parse.h"
 | 
						|
#include "cli_lwip_api.h"
 | 
						|
#if HW_PLATFORM == HW_PLATFORM_SIMU
 | 
						|
#include "os_socket.h"
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
extern "C" {
 | 
						|
#endif
 | 
						|
#endif
 | 
						|
 | 
						|
#define CLI_FTM_BAUD        (115200 * 8)
 | 
						|
#define CLI_FTM_PARITY      (0)
 | 
						|
#define CLI_FTM_DATA_BITS   (8)
 | 
						|
#define CLI_FTM_STOP_BITS   (1)
 | 
						|
 | 
						|
#define ARRAYLEN(a) (sizeof(a)/sizeof((a)[0]))
 | 
						|
typedef void(*communicator_rx_cb)(void* pdev, void *buffer, uint32_t len,
 | 
						|
    void* rxdesc);
 | 
						|
typedef void(*communicator_tx_comp_cb)(void* pdev, void *buffer, uint32_t len);
 | 
						|
 | 
						|
enum _commnunicator_port
 | 
						|
{
 | 
						|
    UDP_BROADCAST_PORT_NUMBER_START = 6514,
 | 
						|
    UDP_BROADCAST_PORT_NUMBER_RF = UDP_BROADCAST_PORT_NUMBER_START,
 | 
						|
    UDP_BROADCAST_PORT_NUMBER = 6515UL,
 | 
						|
    UDP_CHANNEL_SIMULATION_SEND_PORT,
 | 
						|
    UDP_CHANNEL_SIMULATION_RECV_PORT,
 | 
						|
    UDP_CLI_SEND_PORT,
 | 
						|
    UDP_CLI_RECV_PORT,
 | 
						|
    UDP_BROADCAST_PORT_NUMBER_END = UDP_CLI_RECV_PORT
 | 
						|
};
 | 
						|
 | 
						|
typedef enum _interface_type
 | 
						|
{
 | 
						|
    COMMUNICATOR_SOCKET,
 | 
						|
    COMMUNICATOR_UART,
 | 
						|
    COMMUNICATOR_LWIP_SOCKET,
 | 
						|
    COMMUNICATOR_BT,
 | 
						|
    COMMUNICATOR_APP,
 | 
						|
}interface_type_t;
 | 
						|
 | 
						|
typedef enum _caller_type
 | 
						|
{
 | 
						|
    CALLER_HW_SIMULATOR,
 | 
						|
    CALLER_PLC_CLI,
 | 
						|
}caller_type_t;
 | 
						|
 | 
						|
typedef struct _commnucator_t
 | 
						|
{
 | 
						|
    interface_type_t type;
 | 
						|
#if HW_PLATFORM == HW_PLATFORM_SIMU
 | 
						|
    os_socket_t udprecvsocket;
 | 
						|
    // for channel simulation
 | 
						|
    os_socket_t csrecvsock;
 | 
						|
    os_socket_t udpsendsocket;
 | 
						|
    os_socket_t clirecvsocket;
 | 
						|
#endif
 | 
						|
    int lwip_tcp_raw_socket;
 | 
						|
    int lwip_tcp_con_socket;
 | 
						|
    uint8_t com_num;
 | 
						|
    void* uart_handle;
 | 
						|
    iot_frame_fmt uart_frame;
 | 
						|
    communicator_rx_cb rx_ctrl_cb;
 | 
						|
    communicator_tx_comp_cb tx_comp_cb;
 | 
						|
    /* callback func for communicator sending data to cli */
 | 
						|
    communicator_tx_comp_cb ext_tx_cb;
 | 
						|
    uint8_t is_initiated;
 | 
						|
    void *ref_caller_ptr; // back pointer to the module that use this struct
 | 
						|
} commnucator_t;
 | 
						|
 | 
						|
typedef struct _commnucator_t *commnuicator_handle ;
 | 
						|
 | 
						|
uint8_t commnunicator_init(commnuicator_handle commnu, void *caller_module,
 | 
						|
    caller_type_t caller, uint8_t work_mode);
 | 
						|
uint8_t commnunicator_deinit(commnuicator_handle commnu);
 | 
						|
int commnuicator_register_callback_packet_recv(commnuicator_handle commnu,
 | 
						|
    communicator_rx_cb rx_cb);
 | 
						|
int commnuicator_deregister_callback_packet_recv(commnuicator_handle pcommnu);
 | 
						|
 | 
						|
int commnuicator_register_callback_tx_comp(commnuicator_handle commnu,
 | 
						|
    communicator_tx_comp_cb tx_comp_cb);
 | 
						|
 | 
						|
/* cli register callback func to communicator for data sending: from commu to cli */
 | 
						|
int commnuicator_register_cb_ext_tx_comp(commnuicator_handle pcommnu,
 | 
						|
    communicator_tx_comp_cb tx_comp_cb);
 | 
						|
 | 
						|
/*
 | 
						|
 * package_send() - send package to hardware layer.
 | 
						|
 *
 | 
						|
 * @commnuicator_handle:commnuicator_handle
 | 
						|
 * @buffer_to_send:     buffer to be sent
 | 
						|
 * @buffer_len:         length of buffer to be sent
 | 
						|
 * @need_free:          if the buffer need to be freed
 | 
						|
 *
 | 
						|
 */
 | 
						|
//int package_send(commnuicator_handle pcommnu, uint32_t port,
 | 
						|
//    const char * buffer_to_send, uint32_t buffer_len);
 | 
						|
int package_send(commnuicator_handle pcommnu, uint32_t port,
 | 
						|
    iot_pkt_t *pkt);
 | 
						|
 | 
						|
//this func only support ethernet inteface. for uart, it need premable, iot_pkt is
 | 
						|
//must-have.
 | 
						|
int package_send_with_rawdata(commnuicator_handle pcommnu, uint32_t port,
 | 
						|
    uint8_t* data, uint32_t data_len);
 | 
						|
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif // !COMMUNICATOR_H
 |