/**
 * @file wh_lte_7s4_v2.h
 * @author Chen Jihang (embedded@eseaoptics.com)
 * @brief WH LTE 7S4 V2驱动
 * @version 0.1
 * @date 2022-07-18
 * 
 * @copyright ESEA (c) 2020
 * 
 */
#ifndef WH_LTE_7S4_V2_H_
#define WH_LTE_7S4_V2_H_
#include "stdint.h"
#include "config.h"
#include "myuart.h"
// typedef int (*wh_lte_7s4_send_fun)(void *send_obj,char *buf,uint32_t size);
// typedef struct wh_lte_7s4_buff
typedef struct  
{
    MYUART_TypeDef *myuart;
    uint8_t receive_err_code;
    uint8_t receive_ok_flag;
    uint8_t receive_a_flag;
    uint8_t receive_para_num;
    uint32_t receive_size;
    char receive_para[8][32];
    char send_args_buf[64];   /* 组装命令 */
    uint8_t receive_buf[1024];
    uint32_t timebase;
    uint32_t timeout;
    uint8_t step; 
    // void *send_obj;
    // wh_lte_7s4_send_fun send_fun;

}WH_LTE_7S4_Typedef;
enum wh_lte_7s4_cmd_state{
    WH_LTE_7S4_CMD_STATE_OFF=0,
    WH_LTE_7S4_CMD_STATE_ON=1
};
enum wh_lte_7s4_cmd_work_mode{
    WH_LTE_7S4_CMD_WORK_MODE_NET=0,
    WH_LTE_7S4_CMD_WORK_MODE_HTTPD=1,
    WH_LTE_7S4_CMD_WORK_MODE_UDC=0,
};
enum wh_lte_7s4_cmd_uart_parity{
    WH_LTE_7S4_CMD_UART_PARITY_NONE=0,
    WH_LTE_7S4_CMD_UART_PARITY_ODD=1,
    WH_LTE_7S4_CMD_UART_PARITY_EVEN=2
};
enum wh_lte_7s4_cmd_sockasl{
    WH_LTE_7S4_CMD_SOCKASL_SHORT=0,
    WH_LTE_7S4_CMD_SOCKASL_LONG=1
};
enum wh_lte_7s4_cmd_protocol{
    WH_LTE_7S4_CMD_PROTOCOL_TCP,
    WH_LTE_7S4_CMD_PROTOCOL_UDP
};

WH_LTE_7S4_Typedef *wh_lte_7s4_init( );
int __wh_lte_7s4_send(WH_LTE_7S4_Typedef *wh_lte_7s4, uint8_t *buf, uint16_t size);
int __wh_lte_7s4_receive(WH_LTE_7S4_Typedef *wh_lte_7s4, uint8_t *buf, uint16_t size);

void  wh_lte_7s4_receive_callback(WH_LTE_7S4_Typedef *wh_lte_7s4 );
void  wh_lte_7s4_receive_error_callback(WH_LTE_7S4_Typedef *wh_lte_7s4 );

int wh_lte_7s4_ppp(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_a(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_test(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t size);
int wh_lte_7s4_inquire(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t size);
int wh_lte_7s4_run(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t size);
int wh_lte_7s4_set(WH_LTE_7S4_Typedef *wh_lte_7s4,char *cmd,uint32_t cmd_size,char *args,uint32_t args_size);
int wh_lte_7s4_at_help(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_z(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_reboot(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_echo(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_echo(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state echo_state);
int wh_lte_7s4_at_entm(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_workmode(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_work_mode work_mode);
int wh_lte_7s4_at_get_workmode(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_csq(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_system_info(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_reload(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_clear(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_sn(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_iccid(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_imei(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_local_ip(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_uart(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_uart(WH_LTE_7S4_Typedef *wh_lte_7s4,uint32_t baud,uint8_t data,uint8_t stop,enum wh_lte_7s4_cmd_uart_parity parity);
int wh_lte_7s4_at_get_uartft(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_uartft(WH_LTE_7S4_Typedef *wh_lte_7s4,uint32_t ft);
int wh_lte_7s4_at_get_uartfl(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_uartfl(WH_LTE_7S4_Typedef *wh_lte_7s4,uint32_t len);
int wh_lte_7s4_at_get_socka(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_socka(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_protocol protocol,char *remote_ip,uint32_t remote_ip_size,uint16_t port);
int wh_lte_7s4_at_get_sockb(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sockb(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_protocol protocol,char *remote_ip,uint32_t remote_ip_size,uint16_t port);
int wh_lte_7s4_at_get_socka_en(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_socka_en(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state state);
int wh_lte_7s4_at_get_sockb_en(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sockb_en(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state state);
int wh_lte_7s4_at_get_sockasl(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sockasl(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_sockasl type);
int wh_lte_7s4_at_get_sockbsl(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sockbsl(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_sockasl type);
int wh_lte_7s4_at_get_sockalk(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_sockblk(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_get_sdpen(WH_LTE_7S4_Typedef *wh_lte_7s4);
int wh_lte_7s4_at_set_sdpen(WH_LTE_7S4_Typedef *wh_lte_7s4,enum wh_lte_7s4_cmd_state new_state);
int wh_lte_7s4_at_get_cclk(WH_LTE_7S4_Typedef *wh_lte_7s4);
void wh_lte_7s4_receive_unpack(WH_LTE_7S4_Typedef *wh_lte_7s4,char *buf,uint32_t size);

unsigned convert_u_2_s(unsigned integer,char *str,unsigned length);

#endif


/**
 * wh_lte_7s4 封装
 * 
 at  : AT\r
 test : AT+[cmd]+?\r\n
 inquire: AT+[cmd]=?\r\n
 run: AT+[cmd]\r\n
 set: AT+[cmd]=[args]\r\n
 
wh_lte_7s4_buff  :
封装myuart
初始化
port
回调 - 空闲回调
常用组合操作任务，
*/