#include "ml307a.h"
#include "mba32a.h"

uint8_t u4length=0;
uint8_t resetcount_4g=0;
bool u4RecvFlag = false;
bool ml307aFail = false;
uint8_t g_ML307A_8buf[2048]={0}; 
uint8_t g_ML307A_8buf_Down[2048]={0}; 


extern UART_HandleTypeDef huart3;
extern UART_HandleTypeDef huart4;

uint8_t sendCmd_4G(char *pCmd, char *pRes, uint32_t timeOut, uint8_t sendNum);

void ML307A_Init(void)
{
	
	HAL_Delay(2000);
	INIT_4G_FRAME();
	
	if(!sendCmd_4G("AT\r\n","OK",1,1))
	{
		ml307aFail=true;
		printf("4G模组异常！\r\n");
	}	
	
	if (ml307aFail)
	{
		printf("#4G模块初始化Fail");
	}
	else
	{
		HAL_Delay(2000);
		
		if (sendCmd_4G("AT+CPIN?\r\n", "+CME ERROR: 10", 1, 1)) // 00检测是否有SIM卡 <+CPIN: READY\r\nOK>
		{
			printf("\tERROR!-->未检测到SIM卡\r\n");
			OLED_ShowString(42,50,"NO_SIM",12,0);
		}

	}
}


uint8_t sendCmd_4G(char *pCmd, char *pRes, uint32_t timeOut, uint8_t sendNum)
{
    uint8_t i = 0;
    uint32_t time;          
    for(i = 0; i < sendNum; i++)
	{
        time = timeOut * 10;
        USART_SendString(&huart4, pCmd);
		HAL_Delay(50);
		printf("------->%s",g_ML307A_8buf_Down);
		
        while(time--)
		{
			if(strstr((const char *)g_ML307A_8buf_Down, pRes) != NULL)             // 如果检索到关键词
			{
				return 1;
			}
			HAL_Delay(100);
        }
    }
    return 0;
}







