/*** 
 * @Author: mbw
 * @Date: 2024-10-09 08:42:14
 * @LastEditors: mbw && 1600520629@qq.com
 * @LastEditTime: 2025-02-21 09:47:09
 * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\inc\at_device_ml307.h
 * @Description: 
 * @
 * @Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. 
 */
/***
 * @Author: mbw
 * @Date: 2024-10-09 08:42:14
 * @LastEditors: mbw && 1600520629@qq.com
 * @LastEditTime: 2024-10-14 14:25:58
 * @FilePath: \JT-DT-YD4N02A_RTT_MRS\bsp\inc\at_device_ml307.h
 * @Description:
 * @
 * @Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */

#ifndef __AT_DEVICE_ML307_H__
#define __AT_DEVICE_ML307_H__

#include <stdlib.h>

#include <at_device.h>
#include "completion.h"

/*娴嬭瘯鍦板潃*/
#if 0
#define TCP_SERVER_URL             ("8.135.10.183 ") //
#define TCP_SERVER_PORT            ("35383")
#endif

#define AT_NSONMI_MODE_1           1
#define AT_NSONMI_MODE_2           2
#define AT_NSONMI_MODE_3           3
#define AT_NSONMI_MODE_DEFAULT     AT_NSONMI_MODE_3

#define AT_SEND_MSOSD_FLAG_100     ("0x100")
#define AT_SEND_MSOSD_FLAG_200     ("0x200")
#define AT_SEND_MSOSD_FLAG_400     ("0x400")
#define AT_SEND_MSOSD_FLAG_DEFAULT AT_SEND_MSOSD_FLAG_100

#define TCP_GET_SOCKET_STATUS      ("AT+NSOSTATUS=%d")  
#define TCP_CONNECT_CMD            ("AT+MIPOPEN=%d,\"TCP\",\"%s\",%s")   //AT+MIPOPEN=0,"TCP","120.27.12.119",2040 
#define TCP_CONNECT_STATE           ("AT+MIPSTATE=%d")//AT+MIPSTATE=0 //
#define TCP_SEND_DATA              ("AT+MIPSEND=%d,%d,\"%s\"")
#define TCP_CLOSE_SOCKET           ("AT+MIPCLOSE=%d") /* close socket_id   */

#define AT_DEVICE_ML307_SOCKETS_NUM 5
/* The maximum number of sockets supported by the ml307 device */

struct at_device_ml307
{
    char *device_name;
    char *client_name;

    int pwr_en_pin;
    int power_pin;
    int rst_pin;
    int power_status_pin;
    size_t recv_line_num;
    struct at_device device;

    void *socket_data;
    void *user_data;

    rt_bool_t power_status;
    rt_bool_t sleep_status;
};

typedef struct __attribute__((packed))
{
    uint8_t imei[15];
    uint8_t iccid[20];
    uint8_t imsi[15];
    uint8_t rssi; // RSSI
    uint8_t rsrp; // RSRP
} ml307_sys_info;

extern ml307_sys_info ml307;
extern rt_uint8_t ml307_init_complate_flag;
extern volatile rt_uint8_t ntp_flag;
extern struct rt_completion ml307_init_complate;
int ml307_device_class_register(void);
int at_send_data(struct at_device *device, const char *data, rt_size_t size);
rt_err_t Ml307_Reset(struct at_device *device);
int Time_Calibration(struct at_device *device);
#endif /* __AT_DEVICE_ML307_H__ */
