#ifndef __AT_DEVICE_NT26K_H__
#define __AT_DEVICE_NT26K_H__

#include <stdlib.h>

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

 #define TCP_SERVER_URL             ("47.94.169.135") //
 #define TCP_SERVER_PORT            ("7150")

//#define TCP_SERVER_URL             ("8.135.10.183 ") //
//#define TCP_SERVER_PORT            ("35383")

#define AT_NT26K_FORMAT_MODE_0           0
#define AT_NSONMI_FORMAT_MODE_1           1
#define AT_NSONMI_MODE_DEFAULT     AT_NSONMI_FORMAT_MODE_1

#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_CONNECT_CMD            ("AT+QIOPEN=1,0,\"TCP\",\"%s\",%s")

#define TCP_READ_SET_CMD           ("AT+NSORF=%d,%d") /* socket_id,length */
#define TCP_SET_NSONMI             ("AT+NSONMI=%d")

#define TCP_SEND_DATA              ("AT+QISENDEX=%d,\"%s\"")
#define TCP_CLOSE_SOCKET           ("AT+QICLOSE=%d") /* close socket_id */

#define AT_DEVICE_NT26K_SOCKETS_NUM 5
/* The maximum number of sockets supported by the nt26k device */

struct at_device_nt26k
{
    char *device_name;
    char *client_name;

    int pwr_en_pin;
    int rst_pin;
    int pwr_key_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
    uint8_t rsrq; // RSRQ
    uint16_t pci; // PCI
    uint8_t snr;  // SNR
} nt26k_sys_info;

extern nt26k_sys_info nt26k;
extern rt_uint8_t nt26k_init_complate_flag;
extern struct rt_completion nt26k_init_complate;
int at_send_data(struct at_device *device, const char *data, rt_size_t size);
rt_err_t Nt26k_Reset(struct at_device *device);
int Time_Calibration(struct at_device *device);
#endif /* __AT_DEVICE_NT26K_H__ */
