|
|
@@ -169,8 +169,9 @@ uint8_t EC200_CheckOnce(int fd)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- log_e("Err:AT+CREG?\r\n"); // 5秒内,没有注册上CS业务,
|
|
|
- _globalCellularManager.Link_status=false;
|
|
|
+ log_e("Err:AT+CREG?\r\n"); // 5秒内,没有注册上CS业务,
|
|
|
+ _globalCellularManager.Link_status = false;
|
|
|
+ Restart_4GModule(fd);
|
|
|
break;
|
|
|
}
|
|
|
case 3:
|
|
|
@@ -182,6 +183,7 @@ uint8_t EC200_CheckOnce(int fd)
|
|
|
{
|
|
|
log_e("Err:AT+CGREG?\r\n"); // 60秒内,没有注册上PS业务
|
|
|
_globalCellularManager.Link_status=false;
|
|
|
+ Restart_4GModule(fd);
|
|
|
break;
|
|
|
}
|
|
|
case 4:
|
|
|
@@ -192,20 +194,22 @@ uint8_t EC200_CheckOnce(int fd)
|
|
|
result = 1;
|
|
|
if (!_globalCellularManager.Link_status)
|
|
|
{
|
|
|
- if (sendCmd(fd,"AT+QIDEACT=1\r\n", "OK", 40, 1)) // 在激活GPRS场景之前先关闭GPRS场景,确保连接正确
|
|
|
+ if (sendCmd(fd,"AT+QIDEACT=1\r\n", "OK", 5, 1)) // 在激活GPRS场景之前先关闭GPRS场景,确保连接正确
|
|
|
{
|
|
|
- if (sendCmd(fd,"AT+QIACT=1\r\n", "OK", 150, 1)) // 激活移动场景
|
|
|
+ if (sendCmd(fd,"AT+QIACT=1\r\n", "OK", 5, 1)) // 激活移动场景
|
|
|
{
|
|
|
- _globalCellularManager.Link_status=true;
|
|
|
+ _globalCellularManager.Link_status=true;
|
|
|
}
|
|
|
else // 等待150秒后,没有响应重启模块
|
|
|
{
|
|
|
log_e("Err:AT+QIACT=1\r\n"); // 重启模块
|
|
|
+ Restart_4GModule(fd);
|
|
|
}
|
|
|
}
|
|
|
else // 等待40秒后,没有响应重启模块
|
|
|
{
|
|
|
log_e("Err:AT+QIDEACT=1\r\n"); // 重启模块
|
|
|
+ Restart_4GModule(fd);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -396,6 +400,24 @@ int get_APN(int fd)
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
+int Restart_4GModule(int fd)
|
|
|
+{
|
|
|
+ int ret = -1;
|
|
|
+ // 禁用模块
|
|
|
+ if (sendCmd(fd, "AT+CFUN=0\r\n", "OK", 2, 1)) // 禁用模块
|
|
|
+ {
|
|
|
+ // 启用模块
|
|
|
+ if (sendCmd(fd, "AT+CFUN=1\r\n", "OK", 2, 1)) // 启用模块
|
|
|
+ {
|
|
|
+ ret=0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ return ret;
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
static void* Cellular_thread(void *arg)
|
|
|
{
|
|
|
@@ -438,6 +460,10 @@ static void* Cellular_thread(void *arg)
|
|
|
else
|
|
|
{
|
|
|
EC200_CheckOnce(fd);
|
|
|
+ if (!_globalCellularManager.Link_status)
|
|
|
+ {
|
|
|
+ _globalCellularManager.Signal_strength = 0; // 4G信号强度
|
|
|
+ }
|
|
|
}
|
|
|
// 等待一段时间再进行下一次查询
|
|
|
usleep(QUERY_INTERVAL);
|
|
|
@@ -479,22 +505,38 @@ int Cellular_deinit(void)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-bool EC200_CreateTCPSocket(char *pIP,int pPort)
|
|
|
+bool EC200_CreateTCPSocket(char *pIP,int pPort,bool openflag)
|
|
|
{
|
|
|
bool ret = false;
|
|
|
char buf[256];
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
- sprintf(buf, "AT+QIOPEN=1,0,\"TCP\",\"%s\",%d,0,0\r\n", pIP, pPort);
|
|
|
|
|
|
- if (sendCmd(_globalCellularManager.RS_fd, buf, "+QIOPEN:", 150, 5))
|
|
|
+ if (openflag)
|
|
|
{
|
|
|
- ret = true;
|
|
|
- log_i("Create 4G TCPSocket Success\r\n");
|
|
|
+ sprintf(buf, "AT+QIOPEN=1,0,\"TCP\",\"%s\",%d,0,0\r\n", pIP, pPort);
|
|
|
+
|
|
|
+ if (sendCmd(_globalCellularManager.RS_fd, buf, "+QIOPEN:", 5, 1))
|
|
|
+ {
|
|
|
+ ret = true;
|
|
|
+ log_i("Create 4G TCPSocket Success\r\n");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ log_e("Err:Create 4G TCPSocket Failed\r\n");
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- log_e("Err:Create 4G TCPSocket Failed\r\n");
|
|
|
+ sprintf(buf, "AT+QICLOSE=0\r\n");
|
|
|
+ if (sendCmd(_globalCellularManager.RS_fd, buf, "OK", 5, 1))
|
|
|
+ {
|
|
|
+ ret = true;
|
|
|
+ log_i("Close 4G TCPSocket Success\r\n");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ log_e("Err:Close 4G TCPSocket Failed\r\n");
|
|
|
+ }
|
|
|
}
|
|
|
return ret;
|
|
|
}
|