|
|
@@ -19,17 +19,46 @@
|
|
|
#define QUERY_INTERVAL 5000000 // 查询间隔,毫秒
|
|
|
#define RECONNECT_INTERVAL 10000000 // 连接4G模组间隔,毫秒
|
|
|
#define RSSI2dBm_1 -113 // LTE、HSDPA网络最小信号值,对应RSSI值范围0-57
|
|
|
-#define RSSI2dBm_2 -116 // TD-SCDMA网络最小信号值,对应RSSI值范围100-199
|
|
|
-char g_ec200Buf[1024] = {0};
|
|
|
+#define RSSI2dBm_2 -116 // TD-SCDMA网络最小信号值,对应RSSI值范围100-199
|
|
|
|
|
|
+typedef struct {
|
|
|
+ char buf[1024];
|
|
|
|
|
|
-int set_serial_attributes(int fd, int speed)
|
|
|
+ int fd;
|
|
|
+ CellularManager *pcell;
|
|
|
+}cell_handle_t;
|
|
|
+static cell_handle_t ceHandle={0};
|
|
|
+
|
|
|
+
|
|
|
+#ifdef USE_CELL
|
|
|
+static void reset_var(cell_handle_t *h)
|
|
|
{
|
|
|
- if (fd < 0)
|
|
|
+ CellularManager *pcell=h->pcell;
|
|
|
+
|
|
|
+ //pcell->mode = 0;
|
|
|
+ pcell->Link_status = false; // 4G网络连接状态
|
|
|
+ pcell->Signal_strength = 0; // 4G信号强度
|
|
|
+ sprintf(pcell->Cellular_name, "-");
|
|
|
+ sprintf(pcell->Cellular_Num, "-");
|
|
|
+ //pcell->Cellular_IMEI[64]="-"; // IMEI号
|
|
|
+
|
|
|
+ // pcell->GPS_status = false; // GPS功能启用
|
|
|
+ pcell->GPS_latitude = 0.0; // GPS��度
|
|
|
+ pcell->GPS_longitude = 0.0; // GPS经度
|
|
|
+ pcell->GPS_altitude = 0.0; // GPS海��高度
|
|
|
+ pcell->GPS_speed = 0.0; // GPS速度,单位km/h
|
|
|
+ pcell->GPS_nsat = 0; // GPS��星数量
|
|
|
+ sprintf(pcell->GPS_utc, "-");
|
|
|
+
|
|
|
+ //pcell->SMS_status = false; // 短信功能启用
|
|
|
+}
|
|
|
+static int set_serial(cell_handle_t *h, int speed)
|
|
|
+{
|
|
|
+ if (h->fd < 0)
|
|
|
return -1;
|
|
|
struct termios tty;
|
|
|
|
|
|
- if (tcgetattr(fd, &tty) != 0)
|
|
|
+ if (tcgetattr(h->fd, &tty) != 0)
|
|
|
{
|
|
|
log_e("Read 4G Module tcgetattr!!!\n");
|
|
|
return -1;
|
|
|
@@ -55,27 +84,26 @@ int set_serial_attributes(int fd, int speed)
|
|
|
tty.c_cflag &= ~CSTOPB;
|
|
|
tty.c_cflag &= ~CRTSCTS;
|
|
|
|
|
|
- if (tcsetattr(fd, TCSANOW, &tty) != 0)
|
|
|
+ if (tcsetattr(h->fd, TCSANOW, &tty) != 0)
|
|
|
{
|
|
|
log_e("Read 4G Module tcsetattr!!!\n");
|
|
|
return -1;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
-void send_at_command(int fd, const char *cmd)
|
|
|
+static void send_at_cmd(cell_handle_t *h, const char *cmd)
|
|
|
{
|
|
|
- if (fd < 0)
|
|
|
+ if (h->fd < 0)
|
|
|
return;
|
|
|
- write(fd, cmd, strlen(cmd));
|
|
|
+ write(h->fd, cmd, strlen(cmd));
|
|
|
usleep(READ_TIMEOUT); // 等待响应
|
|
|
}
|
|
|
-
|
|
|
-int read_response(int fd, char *buf, size_t len)
|
|
|
+static int read_resp(cell_handle_t *h, char *buf, size_t len)
|
|
|
{
|
|
|
- if (fd < 0)
|
|
|
+ if (h->fd < 0)
|
|
|
return -1;
|
|
|
|
|
|
- int n = read(fd, buf, len - 1);
|
|
|
+ int n = read(h->fd, buf, len - 1);
|
|
|
if (n > 0)
|
|
|
{
|
|
|
buf[n] = '\0';
|
|
|
@@ -93,146 +121,136 @@ int read_response(int fd, char *buf, size_t len)
|
|
|
}
|
|
|
return n;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-/*
|
|
|
- @brief 发送AT命令
|
|
|
- @param pCmd -[in] 命令字符串
|
|
|
- @param pRes -[in] 需要检测的返回命令字符串
|
|
|
- @param timeOut -[in] 等待时间
|
|
|
- @param sendNum -[in] 命令发送次数
|
|
|
- @return 1 - 成功;0 - 失败
|
|
|
-*/
|
|
|
-uint8_t sendCmd(int fd, char *pCmd, char *pRes, uint32_t timeOut, uint8_t sendNum)
|
|
|
+static int send_cmd(cell_handle_t *h, char *cmd, char *key, int timeout, int times)
|
|
|
{
|
|
|
- uint8_t i = 0;
|
|
|
+ int i = 0;
|
|
|
uint32_t time;
|
|
|
- memset(g_ec200Buf, 0, sizeof(g_ec200Buf)); // 清空缓存
|
|
|
- for(i = 0; i < sendNum; i++)
|
|
|
+
|
|
|
+ memset(h->buf, 0, sizeof(h->buf)); // 清空缓存
|
|
|
+ for(i = 0; i < times; i++)
|
|
|
{
|
|
|
- time = timeOut * 10;
|
|
|
- send_at_command(fd, pCmd);
|
|
|
+ time = timeout * 10;
|
|
|
+ send_at_cmd(h, cmd);
|
|
|
while(time--)
|
|
|
{
|
|
|
- if(read_response(fd, g_ec200Buf, sizeof(g_ec200Buf))) // 如果串口接收完成
|
|
|
+ if(read_resp(h, h->buf, sizeof(h->buf))) // 如果串口接收完成
|
|
|
{
|
|
|
- if(strstr((const char *)g_ec200Buf, pRes) != NULL) // 如果检索到关键词
|
|
|
+ if(strstr((const char *)h->buf, pRes) != NULL) // 如果检索到关键词
|
|
|
{
|
|
|
return 1;
|
|
|
}
|
|
|
}
|
|
|
usleep(READ_TIMEOUT); // 等待响应 // 等待100毫秒
|
|
|
}
|
|
|
- memset(g_ec200Buf, 0, sizeof(g_ec200Buf));
|
|
|
+ memset(h->buf, 0, sizeof(h->buf));
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-uint8_t EC200_CheckOnce(int fd)
|
|
|
+static int cell_init(cell_handle_t *h)
|
|
|
{
|
|
|
- uint8_t result = 0;
|
|
|
- uint8_t step = 0;
|
|
|
+ int step=0,result = 0;
|
|
|
char buf[256];
|
|
|
+
|
|
|
switch(step)
|
|
|
{
|
|
|
case 0:
|
|
|
- if(sendCmd(fd,"AT\r\n","OK", 10, 5)) // 测试AT指令功能是否正常
|
|
|
+ if(send_cmd(fd,"AT\r\n","OK", 10, 5)) // 测试AT指令功能是否正常
|
|
|
{
|
|
|
step++;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
log_e("Err:AT\r\n");
|
|
|
- _globalCellularManager.Link_status=false;
|
|
|
- _globalCellularManager.RS_status=false;
|
|
|
+ h->pcell->Link_status=false;
|
|
|
+ h->pcell->RS_status=false;
|
|
|
break;
|
|
|
}
|
|
|
case 1:
|
|
|
- if (sendCmd(fd, "AT+CPIN?\r\n", "+CPIN: READY", 5, 1)) // 查询SIM卡是否正常,返回ready则表示SIM卡正常
|
|
|
+ if (send_cmd(fd, "AT+CPIN?\r\n", "+CPIN: READY", 5, 1)) // 查询SIM卡是否正常,返回ready则表示SIM卡正常
|
|
|
{
|
|
|
step++;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
log_e("Err:AT+CPIN?\r\n"); // 5秒内,无法识别SIM状态,重启模块
|
|
|
- _globalCellularManager.Link_status = false;
|
|
|
+ h->pcell->Link_status = false;
|
|
|
break;
|
|
|
}
|
|
|
case 2:
|
|
|
- if (sendCmd(fd, "AT+CREG?\r\n", "+CREG: 0,1", 5, 1)) // 查询模组是否注册上GSM网络
|
|
|
+ if (send_cmd(fd, "AT+CREG?\r\n", "+CREG: 0,1", 5, 1)) // 查询模组是否注册上GSM网络
|
|
|
{
|
|
|
step++;
|
|
|
- get_cops(fd);
|
|
|
- get_cimi(fd);
|
|
|
- get_APN(fd);
|
|
|
- get_rssi(fd);
|
|
|
+ get_cops(h);
|
|
|
+ get_cimi(h);
|
|
|
+ get_APN(h);
|
|
|
+ get_rssi(h);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
log_e("Err:AT+CREG?\r\n"); // 5秒内,没有注册上CS业务,
|
|
|
- _globalCellularManager.Link_status = false;
|
|
|
- Restart_4GModule(fd);
|
|
|
+ h->pcell->Link_status = false;
|
|
|
+ cellular_restart();
|
|
|
break;
|
|
|
}
|
|
|
case 3:
|
|
|
- if(sendCmd(fd,"AT+CGREG?\r\n","+CGREG: 0,1", 5, 1)) // 查询模组是否注册上GPRS网络
|
|
|
+ if(send_cmd(fd,"AT+CGREG?\r\n","+CGREG: 0,1", 5, 1)) // 查询模组是否注册上GPRS网络
|
|
|
{
|
|
|
step++;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
log_e("Err:AT+CGREG?\r\n"); // 60秒内,没有注册上PS业务
|
|
|
- _globalCellularManager.Link_status=false;
|
|
|
- Restart_4GModule(fd);
|
|
|
+ h->pcell->Link_status=false;
|
|
|
+ cellular_restart();
|
|
|
break;
|
|
|
}
|
|
|
case 4:
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
- sprintf(buf, "AT+QICSGP=1,1,\"%s\",\"\",\"\",1\r\n", _globalCellularManager.Cellular_APN);
|
|
|
- if(sendCmd(fd,buf, "OK", 10,2)) // 根据APN接入点配置场景,场景默认为1
|
|
|
+ sprintf(buf, "AT+QICSGP=1,1,\"%s\",\"\",\"\",1\r\n", h->pcell->Cellular_APN);
|
|
|
+ if(send_cmd(fd,buf, "OK", 10,2)) // 根据APN接入点配置场景,场景默认为1
|
|
|
{
|
|
|
result = 1;
|
|
|
- if (!_globalCellularManager.Link_status)
|
|
|
+ if (!h->pcell->Link_status)
|
|
|
{
|
|
|
- if (sendCmd(fd,"AT+QIDEACT=1\r\n", "OK", 5, 1)) // 在激活GPRS场景之前先关闭GPRS场景,确保连接正确
|
|
|
+ if (send_cmd(fd,"AT+QIDEACT=1\r\n", "OK", 5, 1)) // 在激活GPRS场景之前先关闭GPRS场景,确保连接正确
|
|
|
{
|
|
|
- if (sendCmd(fd,"AT+QIACT=1\r\n", "OK", 5, 1)) // 激活移动场景
|
|
|
+ if (send_cmd(fd,"AT+QIACT=1\r\n", "OK", 5, 1)) // 激活移动场景
|
|
|
{
|
|
|
- _globalCellularManager.Link_status=true;
|
|
|
+ h->pcell->Link_status=true;
|
|
|
}
|
|
|
else // 等待150秒后,没有响应重启模块
|
|
|
{
|
|
|
log_e("Err:AT+QIACT=1\r\n"); // 重启模块
|
|
|
- Restart_4GModule(fd);
|
|
|
+ cellular_restart();
|
|
|
}
|
|
|
}
|
|
|
else // 等待40秒后,没有响应重启模块
|
|
|
{
|
|
|
log_e("Err:AT+QIDEACT=1\r\n"); // 重启模块
|
|
|
- Restart_4GModule(fd);
|
|
|
+ cellular_restart();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
log_e("Err:AT+QICSGP=1,1\r\n"); // 如果3次都没停止成功或超过40秒没有回应,则重启模块
|
|
|
- _globalCellularManager.Link_status=false;
|
|
|
+ h->pcell->Link_status=false;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
-int get_rssi(int fd)
|
|
|
+static int get_rssi(cell_handle_t *h)
|
|
|
{
|
|
|
char buf[256];
|
|
|
|
|
|
// 1 发送AT+CSQ指令查询信号强度
|
|
|
const char *csq_cmd = "AT+CSQ\r";
|
|
|
- send_at_command(fd, csq_cmd);
|
|
|
+ send_at_cmd(h, csq_cmd);
|
|
|
// 读取响应
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
- read_response(fd, buf, sizeof(buf));
|
|
|
+ read_resp(h, buf, sizeof(buf));
|
|
|
// 解析响应(这里假设响应格式为"+CSQ: <rssi>,<ber>\r\nOK\r\n")
|
|
|
char *rssi_start = strstr(buf, "+CSQ: ");
|
|
|
if (rssi_start)
|
|
|
@@ -245,14 +263,14 @@ int get_rssi(int fd)
|
|
|
int rssi = atoi(rssi_start);
|
|
|
if (rssi < 57 && rssi >= 0)
|
|
|
{
|
|
|
- _globalCellularManager.Signal_strength = RSSI2dBm_1 + 2 * rssi;
|
|
|
+ h->pcell->Signal_strength = RSSI2dBm_1 + 2 * rssi;
|
|
|
}
|
|
|
else if (rssi < 199 && rssi >= 100)
|
|
|
{
|
|
|
- _globalCellularManager.Signal_strength = RSSI2dBm_2 + rssi - 100;
|
|
|
+ h->pcell->Signal_strength = RSSI2dBm_2 + rssi - 100;
|
|
|
}
|
|
|
else
|
|
|
- _globalCellularManager.Signal_strength = 0;
|
|
|
+ h->pcell->Signal_strength = 0;
|
|
|
|
|
|
log_i("Get 4G Signal Strength (RSSI): %d\n", rssi);
|
|
|
}
|
|
|
@@ -266,14 +284,14 @@ int get_rssi(int fd)
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-int get_cops(int fd)
|
|
|
+static int get_cops(cell_handle_t *h)
|
|
|
{
|
|
|
char buf[256];
|
|
|
// 2 发送AT+COPS指令查询运营商信息
|
|
|
const char *cops_cmd = "AT+COPS?\r";
|
|
|
- send_at_command(fd, cops_cmd);
|
|
|
+ send_at_command(h, cops_cmd);
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
- int n = read_response(fd, buf, sizeof(buf));
|
|
|
+ int n = read_resp(h, buf, sizeof(buf));
|
|
|
char *cops_start = strstr(buf, "+COPS: ");
|
|
|
if (cops_start)
|
|
|
{
|
|
|
@@ -296,14 +314,14 @@ int get_cops(int fd)
|
|
|
int len = strlen(token) - 1;
|
|
|
if (len >= 0 && len <= 64)
|
|
|
{
|
|
|
- strncpy(_globalCellularManager.Cellular_name, token + 1, len);
|
|
|
- _globalCellularManager.Cellular_name[len - 1] = '\0'; // 确保字符串以null结尾
|
|
|
+ strncpy(h->pcell->Cellular_name, token + 1, len);
|
|
|
+ h->pcell->Cellular_name[len - 1] = '\0'; // 确保字符串以null结尾
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// 如果格式不正确,则清空运营商名称
|
|
|
- sprintf(_globalCellularManager.Cellular_name, "-");
|
|
|
+ sprintf(h->pcell->Cellular_name, "-");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -318,15 +336,15 @@ int get_cops(int fd)
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-int get_cimi(int fd)
|
|
|
+static int get_cimi(cell_handle_t *h)
|
|
|
{
|
|
|
char buf[256];
|
|
|
// 3 发送AT+CIMI指令查询电话号码
|
|
|
const char *cimi_cmd = "AT+CIMI\r";
|
|
|
- send_at_command(fd, cimi_cmd);
|
|
|
+ send_at_command(h, cimi_cmd);
|
|
|
// 读取响应
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
- read_response(fd, buf, sizeof(buf));
|
|
|
+ read_resp(h, buf, sizeof(buf));
|
|
|
char *cimi_start = strstr(buf, "+CIMI");
|
|
|
if (cimi_start)
|
|
|
{
|
|
|
@@ -334,7 +352,7 @@ int get_cimi(int fd)
|
|
|
if (strstr(cimi_start, "+CME"))
|
|
|
{
|
|
|
// 如果获取到错误信息,则清空电话号码
|
|
|
- sprintf(_globalCellularManager.Cellular_Num, "-");
|
|
|
+ sprintf(h->pcell->Cellular_Num, "-");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -345,7 +363,7 @@ int get_cimi(int fd)
|
|
|
*(pos) = '\0';
|
|
|
}
|
|
|
int cimi_size = strlen(cimi_start);
|
|
|
- strncpy(_globalCellularManager.Cellular_Num, cimi_start, cimi_size);
|
|
|
+ strncpy(h->pcell->Cellular_Num, cimi_start, cimi_size);
|
|
|
}
|
|
|
log_i("Get 4G CIMI Information: %s\n", cimi_start);
|
|
|
}
|
|
|
@@ -354,7 +372,7 @@ int get_cimi(int fd)
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-int get_APN(int fd)
|
|
|
+static int get_APN(cell_handle_t *h)
|
|
|
{
|
|
|
/*
|
|
|
char buf[256];
|
|
|
@@ -375,53 +393,35 @@ int get_APN(int fd)
|
|
|
if (token != NULL)
|
|
|
{
|
|
|
int apn_size = strlen(token);
|
|
|
- strncpy(_globalCellularManager.Cellular_APN, token, apn_size);
|
|
|
+ strncpy(h->pcell->Cellular_APN, token, apn_size);
|
|
|
}
|
|
|
else return -1;
|
|
|
}
|
|
|
}*/
|
|
|
|
|
|
- if (strstr(_globalCellularManager.Cellular_name, "CHINA MOBILE") || strstr(_globalCellularManager.Cellular_name, "CMCC") || strstr(_globalCellularManager.Cellular_name, "46000"))
|
|
|
+ if (strstr(h->pcell->Cellular_name, "CHINA MOBILE") || strstr(h->pcell->Cellular_name, "CMCC") || strstr(h->pcell->Cellular_name, "46000"))
|
|
|
{
|
|
|
- strcpy(_globalCellularManager.Cellular_APN, "cmnet"); // 示例APN,实际可能不同
|
|
|
+ strcpy(h->pcell->Cellular_APN, "cmnet"); // 示例APN,实际可能不同
|
|
|
}
|
|
|
- else if (strstr(_globalCellularManager.Cellular_name, "CHN-UNICOM") || strstr(_globalCellularManager.Cellular_name, "UNICOM") || strstr(_globalCellularManager.Cellular_name, "46001"))
|
|
|
+ else if (strstr(h->pcell->Cellular_name, "CHN-UNICOM") || strstr(h->pcell->Cellular_name, "UNICOM") || strstr(h->pcell->Cellular_name, "46001"))
|
|
|
{
|
|
|
- strcpy(_globalCellularManager.Cellular_APN, "uninet"); // 示例APN,实际可能不同
|
|
|
+ strcpy(h->pcell->Cellular_APN, "uninet"); // 示例APN,实际可能不同
|
|
|
}
|
|
|
- else if (strstr(_globalCellularManager.Cellular_name, "CHN-CT") || strstr(_globalCellularManager.Cellular_name, "CT") || strstr(_globalCellularManager.Cellular_name, "46011"))
|
|
|
+ else if (strstr(h->pcell->Cellular_name, "CHN-CT") || strstr(h->pcell->Cellular_name, "CT") || strstr(h->pcell->Cellular_name, "46011"))
|
|
|
{
|
|
|
- strcpy(_globalCellularManager.Cellular_APN, "ctnet"); // 示例APN,实际可能不同
|
|
|
+ strcpy(h->pcell->Cellular_APN, "ctnet"); // 示例APN,实际可能不同
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- memset(_globalCellularManager.Cellular_APN, 0, sizeof(_globalCellularManager.Cellular_APN));
|
|
|
+ memset(h->pcell->Cellular_APN, 0, sizeof(h->pcell->Cellular_APN));
|
|
|
return -1; // 未知的运营商名称
|
|
|
}
|
|
|
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)
|
|
|
+static void* cellular_thread(void *arg)
|
|
|
{
|
|
|
int fd;
|
|
|
+ cell_handle_t *h=(cell_handle_t*)arg;
|
|
|
|
|
|
while (_globalCellularManager.mode)
|
|
|
{
|
|
|
@@ -434,19 +434,19 @@ static void* Cellular_thread(void *arg)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- if (set_serial_attributes(fd, BAUD_RATE) < 0)
|
|
|
+ if (set_serial(fd, BAUD_RATE) < 0)
|
|
|
{
|
|
|
close(fd);
|
|
|
log_e("Open 4G Module Failed!!!\n");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- _globalCellularManager.RS_status = true;
|
|
|
- _globalCellularManager.RS_fd=fd;
|
|
|
+ h->pcell->RS_status = true;
|
|
|
+ h->pcell->RS_fd=fd;
|
|
|
log_i("Open 4G Module Success!!!\n");
|
|
|
}
|
|
|
}
|
|
|
- if (!_globalCellularManager.RS_status)
|
|
|
+ if (!h->pcell->RS_status)
|
|
|
usleep(RECONNECT_INTERVAL);
|
|
|
else
|
|
|
usleep(QUERY_INTERVAL);
|
|
|
@@ -455,14 +455,14 @@ static void* Cellular_thread(void *arg)
|
|
|
{
|
|
|
if (fd < 0)
|
|
|
{
|
|
|
- InitCellularManager();
|
|
|
+ reset_var(h);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- EC200_CheckOnce(fd);
|
|
|
- if (!_globalCellularManager.Link_status)
|
|
|
+ EC200_CheckOnce(h);
|
|
|
+ if (!h->pcell->Link_status)
|
|
|
{
|
|
|
- _globalCellularManager.Signal_strength = 0; // 4G信号强度
|
|
|
+ h->pcell->Signal_strength = 0; // 4G信号强度
|
|
|
}
|
|
|
}
|
|
|
// 等待一段时间再进行下一次查询
|
|
|
@@ -471,40 +471,63 @@ static void* Cellular_thread(void *arg)
|
|
|
}
|
|
|
|
|
|
close(fd);
|
|
|
- Cellular_deinit();
|
|
|
pthread_exit(NULL);
|
|
|
}
|
|
|
+#endif
|
|
|
+
|
|
|
+int cellular_restart(void)
|
|
|
+{
|
|
|
+ int ret = -1;
|
|
|
+ cell_handle_t *h=&ceHandle;
|
|
|
+
|
|
|
+#ifdef USE_CELL
|
|
|
+ // 禁用模块
|
|
|
+ if (send_cmd(h, "AT+CFUN=0\r\n", "OK", 2, 1)) // 禁用模块
|
|
|
+ {
|
|
|
+ // 启用模块
|
|
|
+ if (send_cmd(h, "AT+CFUN=1\r\n", "OK", 2, 1)) // 启用模块
|
|
|
+ {
|
|
|
+ ret=0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+ return ret;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* @brief 初始化蜂窝通信模块
|
|
|
- *
|
|
|
* 该函数用于初始化蜂窝通信模块。
|
|
|
- *
|
|
|
* @return 初始化结果。如果初始化成功,返回0;如果初始化失败,返回-1。
|
|
|
*/
|
|
|
-int Cellular_init(void)
|
|
|
+int cellular_init(void)
|
|
|
{
|
|
|
- CellularManager *pcell=&_globalCellularManager;
|
|
|
+ cell_handle_t *h=&ceHandle;
|
|
|
|
|
|
#ifdef USE_CELL
|
|
|
- memset(pcell, 0, sizeof(CellularManager));
|
|
|
- pcell->mode = __globalDeviceManage._globalDevInfo.cell;
|
|
|
- if (0==thread_is_running(THREAD_ID_Cellular))
|
|
|
+ memset(h, 0, sizeof(cell_handle_t));
|
|
|
+ pcell->mode = __globalDeviceManage._globalDevInfo.cell
|
|
|
+ h->pcell = &_globalCellularManager;
|
|
|
+ if (0==thread_is_running(THREAD_ID_CELLULAR))
|
|
|
{
|
|
|
|
|
|
- thread_start(THREAD_ID_Cellular, Cellular_thread, &_globalCellularManager);
|
|
|
+ thread_start(THREAD_ID_CELLULAR, cellular_thread, h);
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-int Cellular_deinit(void)
|
|
|
+int cellular_deinit(void)
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+#ifdef USE_CELL
|
|
|
bool EC200_CreateTCPSocket(char *pIP,int pPort,bool openflag)
|
|
|
{
|
|
|
bool ret = false;
|
|
|
@@ -632,25 +655,5 @@ bool EC200S_SendUDPData(char *pData,char *pIP,int pPort)
|
|
|
}
|
|
|
return ret;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-void InitCellularManager()
|
|
|
-{
|
|
|
- //_globalCellularManager.mode = 0;
|
|
|
- _globalCellularManager.Link_status = false; // 4G网络连接状态
|
|
|
- _globalCellularManager.Signal_strength = 0; // 4G信号强度
|
|
|
- sprintf(_globalCellularManager.Cellular_name, "-");
|
|
|
- sprintf(_globalCellularManager.Cellular_Num, "-");
|
|
|
- //_globalCellularManager.Cellular_IMEI[64]="-"; // IMEI号
|
|
|
-
|
|
|
- // _globalCellularManager.GPS_status = false; // GPS功能启用
|
|
|
- _globalCellularManager.GPS_latitude = 0.0; // GPS��度
|
|
|
- _globalCellularManager.GPS_longitude = 0.0; // GPS经度
|
|
|
- _globalCellularManager.GPS_altitude = 0.0; // GPS海��高度
|
|
|
- _globalCellularManager.GPS_speed = 0.0; // GPS速度,单位km/h
|
|
|
- _globalCellularManager.GPS_nsat = 0; // GPS��星数量
|
|
|
- sprintf(_globalCellularManager.GPS_utc, "-");
|
|
|
-
|
|
|
- //_globalCellularManager.SMS_status = false; // 短信功能启用
|
|
|
-}
|
|
|
+#endif
|
|
|
|