#include "ml307a.h" #include "mba32a.h" #include "usart.h" ML307AStep ml307astep; bool u4RecvFlag = false; bool ml307aFail = false; bool reset4Gmodule = false; bool module4G_F = false; uint8_t u4length=0; uint8_t resetcount_4g=0; uint8_t g_ML307A_8buf[2048]={0}; uint8_t g_ML307A_8buf_Down[2048]={0}; uint8_t MLBSLOCcount = 0; extern UART_HandleTypeDef huart3; extern UART_HandleTypeDef huart4; extern Menu_table menu; void ML307AReset(void); uint8_t sendCmd_4G(char *pCmd, char *pRes, uint32_t timeOut, uint8_t sendNum); uint8_t ML307A_JD[13]={0}; uint8_t ML307A_WD[13]={0}; void loction_4G(void); /** * @breaf 4G初始化 */ void ML307A_Init(void) { printf("\t###02\t4G_init%d...\r\n",resetcount_4g); switch(ml307astep) { case ATOK: { if (sendCmd_4G("AT\r\n", "OK", 1, 2)) { printf("------->%s",g_ML307A_8buf_Down); printf("#4G模组正常\r\n"); ml307astep++; } else { ml307astep = ML307AStepReset; } } case CFUN: { if (sendCmd_4G("AT+CFUN=1\r\n", "OK", 1, 2)) { printf("------->%s",g_ML307A_8buf_Down); printf("#4G模组CFUN正常\r\n"); ml307astep++; } else { ml307astep = ML307AStepReset; } } case SIMH: { if (sendCmd_4G("AT+MCFG=\"simhot\",1\r\n", "OK", 1, 2)) { printf("------->%s",g_ML307A_8buf_Down); printf("#4G模组热插拔开启\r\n"); ml307astep++; } else { ml307astep = ML307AStepReset; } } case CPIN: { if (sendCmd_4G("AT+CPIN?\r\n", "+CPIN: READY", 1, 5)) { printf("------->%s",g_ML307A_8buf_Down); printf("#4G模组状态正常\r\n"); ml307astep++; } else { ml307astep = ML307AStepReset; } } case CEREG: { if (sendCmd_4G("AT+CEREG?\r\n", "+CEREG: 0,1", 1, 2)) { printf("------->%s",g_ML307A_8buf_Down); printf("#4G模组附着正常\r\n"); printf("#4G模组初始化完成\r\n"); ml307astep++; //break; } else { ml307astep = ML307AStepReset; } module4G_F=true; break; } // case MLB1: // { // if (sendCmd_4G("AT+MLBSCFG=\"method\",40\r\n", "OK", 1, 1)) // { // printf("------->%s",g_ML307A_8buf_Down); // ml307astep++; // } // else // { // ml307astep = ML307AStepReset; // } // } // // case MLB2: // { // if(!sendCmd_4G("AT+MLBSCFG=\"pid\"\r\n", "Not referenced", 1, 1)) // { // HAL_Delay(500); // printf("------->%s",g_ML307A_8buf_Down); // ml307astep++; // // } // // } // // case MLB3: // { // if (sendCmd_4G("AT+MLBSCFG=\"nearbtsen\",1\r\n", "OK", 1, 1)) // { // printf("------->%s",g_ML307A_8buf_Down); // memset(g_ML307A_8buf_Down,0,u4length); // ml307astep++; // } // else // { // ml307astep = ML307AStepReset; // } // module4G_F=true; // break; // } case ML307AStepReset: { ml307astep = ATOK; ML307AReset(); } } // menu.current=0;//回到初始 // refresh=true; } /** * @breaf 4G发送串口命令 */ 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; memset(g_ML307A_8buf_Down,0,u4length); USART_SendString(&huart4, pCmd); HAL_Delay(700); while(time--) { if(strstr((const char *)g_ML307A_8buf_Down, pRes) != NULL) // 如果检索到关键词 { return 1; } HAL_Delay(100); } } return 0; } /** @brief 重启模块 @param 无 @return 无 */ void ML307AReset(void) { reset4Gmodule=true; module4G_F=false; resetcount_4g+=1; printf("4G Module_Reset\n"); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_RESET); HAL_Delay(5000); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, GPIO_PIN_SET); } void loction_4G(void) { MLBSLOCcount+=1; if(module4G_F) { //定位状态码、精度、纬度、定位精度、具体位置信息 //sendCmd_4G("AT+MLBSLOC\r\n", "OK", 1, 1); {//MQTT 测试 sendCmd_4G("AT+MQTTCFG=?\r\n", "OK", 1, 1); HAL_Delay(10000); printf("%s",g_ML307A_8buf_Down); } //AL_Delay(5000); //printf("------->%s",g_ML307A_8buf_Down); memset(g_ML307A_8buf_Down,0,u4length); } }