/*
*********************************************************************************************************
*                                       IAR Development Kits
*                                              on the
*
*                                    M451
*
* Filename      : drv_dtu.h
* Version       : V1.00
* Programmer(s) : Qian Xianghong
*********************************************************************************************************
*/

#ifndef  USER_DRV_DTU_PRESENT
#define  USER_DRV_DTU_PRESENT

#include "type.h"

// 是否打印DTU串口收到的字符
extern uint8_t DTU_uartPrint;

extern const uint16_t DTU_tmrQPendShort;

// 4G模块型号（决定是否基站定位等）
#define DTU_MODEL_NONE		0	// 无4G模块
#define DTU_MODEL_LIERDA	1	// 利尔达
#define DTU_MODEL_QUECTEL	2	// 移远
extern uint8_t DTU_model;

// 基站定位获取的经纬度
extern int32_t DTU_longitude, DTU_latitude;

// 模块上/关电
void DTU_PowerOn();
void DTU_PowerOff();
void DTU_Sleep();
void DTU_CheckSleep();

char *DTU_DecideAPN();
char *DTU_DecideAPNUser();
char *DTU_DecideAPNPwd();

// GPRS拨号
uint32_t Sim808_GPRSDial();
// 读取GPRS网络信息信息
uint32_t Sim808_ReadGPRS();
// 获取基站定位经纬度
uint32_t Sim808_GetCellLocPosition();

uint32_t Sim808_Connect(uint8_t ssl, char *server, int port);
uint32_t Sim808_SendAndRecv(uint8_t ssl, uint8_t *data, uint16_t len, uint16_t *recvLen, uint8_t *recvBuff, uint16_t recvSize);
uint32_t DTU_Connect(uint8_t ssl, char *server, short port);
uint32_t DTU_SendAndRecv(uint8_t ssl, uint8_t *data, uint16_t len, uint16_t *recvLen, uint8_t *recvBuff, uint16_t recvSize);
uint32_t DTU_Close(uint8_t ssl);

uint32_t Sim808_MqttConnect(const char *server, int port, char *product, char *device, char *secret);
uint32_t Sim808_MqttPublish(uint8_t *data, uint16_t len, char *product, char *device);
uint32_t MQTT_Close();

// 执行命令，等待结果
uint32_t DTU_ExecuteCmd(char *cmd, char *checkPattern, char *checkErrPattern, char *resultBuff, uint16_t waitSeconds);

#endif
