|
|
@@ -453,9 +453,6 @@ static void conn_init(cell_handle_t *h, mqtt_conn_t *conn);
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-#ifdef USE_CELL
|
|
|
static int port_setup(cell_handle_t *h, int speed);
|
|
|
|
|
|
static void msleep(int ms)
|
|
|
@@ -588,39 +585,52 @@ static int send_cmd(cell_handle_t *h, int cmd, char *para, char *rcv, int rcvlen
|
|
|
sprintf(buf, "%s%s\r", pcmd->cmd, para?para:"");
|
|
|
|
|
|
LOGD("[tx]: %s\n", buf);
|
|
|
- for(i=0; i<RETRY_TIMES; i++) {
|
|
|
+ for (i = 0; i < RETRY_TIMES; i++)
|
|
|
+ {
|
|
|
tout = 0;
|
|
|
port_write(h, buf, strlen(buf));
|
|
|
- while(tout<pcmd->timeout) {
|
|
|
+ while (tout < pcmd->timeout)
|
|
|
+ {
|
|
|
l = port_wait(h, wait_step);
|
|
|
- if(l>0) {
|
|
|
- if(rcv && rcvlen>0) {
|
|
|
+ if (l > 0)
|
|
|
+ {
|
|
|
+ if (rcv && rcvlen > 0)
|
|
|
+ {
|
|
|
pbuf = rcv;
|
|
|
buflen = rcvlen;
|
|
|
}
|
|
|
- else {
|
|
|
+ else
|
|
|
+ {
|
|
|
pbuf = buf;
|
|
|
buflen = sizeof(buf);
|
|
|
}
|
|
|
|
|
|
- l = port_read(h, pbuf+tlen, buflen);
|
|
|
- if(l>0) {
|
|
|
- tlen += l; pbuf[tlen] = 0;
|
|
|
+ l = port_read(h, pbuf + tlen, buflen);
|
|
|
+ if (l > 0)
|
|
|
+ {
|
|
|
+ tlen += l;
|
|
|
+ pbuf[tlen] = 0;
|
|
|
|
|
|
LOGD("[rx]: %s\n", pbuf);
|
|
|
- if(pcmd->ok && strlen(pcmd->ok) && strstr(pbuf, pcmd->ok)) {
|
|
|
+ if (pcmd->ok && strlen(pcmd->ok) && strstr(pbuf, pcmd->ok))
|
|
|
+ {
|
|
|
return AT_OK;
|
|
|
}
|
|
|
-
|
|
|
- if(pcmd->err && strlen(pcmd->err) && strstr(pbuf, pcmd->err)) {
|
|
|
+
|
|
|
+ if (pcmd->err && strlen(pcmd->err) && strstr(pbuf, pcmd->err))
|
|
|
+ {
|
|
|
return AT_ERR;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
tout += wait_step;
|
|
|
+ usleep(1000);
|
|
|
}
|
|
|
}
|
|
|
- cell_reset(h);
|
|
|
+ if (cmd != AT_CMD_CFUN )
|
|
|
+ {
|
|
|
+ cell_reset(h);
|
|
|
+ }
|
|
|
|
|
|
return AT_TOUT;
|
|
|
}
|
|
|
@@ -654,11 +664,12 @@ static int send_data(cell_handle_t *h, void *data, int len, int timeout)
|
|
|
static int cell_reset(cell_handle_t *h)
|
|
|
{
|
|
|
int r;
|
|
|
-
|
|
|
+ reset_var(h);
|
|
|
+ h->stat = AT_STAT_UNINIT;
|
|
|
r = send_cmd(h, AT_CMD_CFUN, "=1,1", NULL, 0);
|
|
|
- if(r==AT_OK) {
|
|
|
- h->stat = AT_STAT_UNINIT;
|
|
|
- }
|
|
|
+ // if(r==AT_OK) {
|
|
|
+ // h->stat = AT_STAT_UNINIT;
|
|
|
+ //}
|
|
|
return (r==AT_OK)?0:-1;
|
|
|
}
|
|
|
static int cell_init(cell_handle_t *h)
|
|
|
@@ -697,11 +708,14 @@ static int cell_init(cell_handle_t *h)
|
|
|
}
|
|
|
static int cell_deinit(cell_handle_t *h)
|
|
|
{
|
|
|
- if(h->stat==AT_STAT_UNINIT) {
|
|
|
- return -1;
|
|
|
+ int r=-1;
|
|
|
+ char buf[400];
|
|
|
+ r = send_cmd(h, AT_CMD_QIDEACT, NULL, buf, sizeof(buf));
|
|
|
+ if(r==AT_OK) {
|
|
|
+ return r;
|
|
|
}
|
|
|
|
|
|
- return 0;
|
|
|
+ return r;
|
|
|
}
|
|
|
static int cell_get_info(cell_handle_t *h, cell_info_t *info)
|
|
|
{
|
|
|
@@ -802,7 +816,7 @@ static int cell_get_ping(cell_handle_t *h, cell_stat_t *stat)
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
- r = send_cmd(h, AT_CMD_QPING, "=1,\"163.com\",3,2,", buf, sizeof(buf));
|
|
|
+ r = send_cmd(h, AT_CMD_QPING, "=1,\"www.baidu.com\",3,2,", buf, sizeof(buf));
|
|
|
if(r!=AT_OK) {
|
|
|
return -1;
|
|
|
}
|
|
|
@@ -811,6 +825,8 @@ static int cell_get_ping(cell_handle_t *h, cell_stat_t *stat)
|
|
|
if(r<1) {
|
|
|
return -1;
|
|
|
}
|
|
|
+
|
|
|
+ LOGD("QPING: %d\n", ret);
|
|
|
if(ret==0) {
|
|
|
stat->linked = 1;
|
|
|
}
|
|
|
@@ -1286,6 +1302,7 @@ static void* cellular_thread(void *arg)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
+ //if(cnt%5==0) cell_deinit(h);
|
|
|
reset_var(h);
|
|
|
}
|
|
|
UpdateCellularManager(&h->all);
|
|
|
@@ -1296,17 +1313,13 @@ static void* cellular_thread(void *arg)
|
|
|
|
|
|
pthread_exit(NULL);
|
|
|
}
|
|
|
-#endif
|
|
|
+
|
|
|
|
|
|
int cellular_reset(void)
|
|
|
{
|
|
|
int r=-1;
|
|
|
cell_handle_t *h=&ceHandle;
|
|
|
-
|
|
|
-#ifdef USE_CELL
|
|
|
r = cell_reset(h);
|
|
|
-#endif
|
|
|
-
|
|
|
return r;
|
|
|
}
|
|
|
|
|
|
@@ -1317,17 +1330,18 @@ int cellular_init(void)
|
|
|
int r;
|
|
|
cell_handle_t *h=&ceHandle;
|
|
|
|
|
|
-#ifdef USE_CELL
|
|
|
- memset(h, 0, sizeof(cell_handle_t));
|
|
|
-
|
|
|
- h->dm = &__globalDeviceManage;
|
|
|
- h->pcell = &h->dm->_globalDevInfo.cell;
|
|
|
- h->prod_id = h->dm->_globalDevInfo.product.id;
|
|
|
- h->lck = lock_d_init();
|
|
|
- nic_set(NIC_USB, 1);
|
|
|
+ if (__globalDeviceManage._globalDevInfo.cell.Cellular_enable)
|
|
|
+ {
|
|
|
+ memset(h, 0, sizeof(cell_handle_t));
|
|
|
|
|
|
- thread_start(THREAD_ID_CELLULAR, cellular_thread, h);
|
|
|
-#endif
|
|
|
+ h->dm = &__globalDeviceManage;
|
|
|
+ h->pcell = &h->dm->_globalDevInfo.cell;
|
|
|
+ h->prod_id = h->dm->_globalDevInfo.product.id;
|
|
|
+ h->lck = lock_d_init();
|
|
|
+ nic_set(NIC_USB, 1);
|
|
|
+
|
|
|
+ thread_start(THREAD_ID_CELLULAR, cellular_thread, h);
|
|
|
+ }
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -1336,10 +1350,11 @@ int cellular_deinit(void)
|
|
|
{
|
|
|
cell_handle_t *h=&ceHandle;
|
|
|
|
|
|
-#ifdef USE_CELL
|
|
|
- lock_d_deinit(h->lck);
|
|
|
- thread_stop(THREAD_ID_CELLULAR);
|
|
|
-#endif
|
|
|
+ if (__globalDeviceManage._globalDevInfo.cell.Cellular_enable)
|
|
|
+ {
|
|
|
+ lock_d_deinit(h->lck);
|
|
|
+ thread_stop(THREAD_ID_CELLULAR);
|
|
|
+ }
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
@@ -1350,12 +1365,10 @@ int cellular_get_all(cell_all_t *all)
|
|
|
int r=-1;
|
|
|
cell_handle_t *h=&ceHandle;
|
|
|
|
|
|
-#ifdef USE_CELL
|
|
|
if(all) {
|
|
|
*all = h->all;
|
|
|
r = 0;
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
return r;
|
|
|
}
|
|
|
@@ -1366,9 +1379,10 @@ int cellular_is_connected(void)
|
|
|
int r=0;
|
|
|
cell_handle_t *h=&ceHandle;
|
|
|
|
|
|
-#ifdef USE_CELL
|
|
|
- r = h->all.stat.linked;
|
|
|
-#endif
|
|
|
+ if (__globalDeviceManage._globalDevInfo.cell.Cellular_enable)
|
|
|
+ {
|
|
|
+ r = h->all.stat.linked;
|
|
|
+ }
|
|
|
|
|
|
return r;
|
|
|
}
|
|
|
@@ -1392,9 +1406,7 @@ int cellular_test(void)
|
|
|
{
|
|
|
cell_handle_t *h=&ceHandle;
|
|
|
|
|
|
-#ifdef USE_CELL
|
|
|
cell_test(h);
|
|
|
-#endif
|
|
|
|
|
|
return 0;
|
|
|
}
|