|
|
@@ -534,8 +534,153 @@ static mqtt_conn_t* get_mqtt_conn_free(cell_handle_t *h)
|
|
|
}
|
|
|
return NULL;
|
|
|
}
|
|
|
+#define BGET(flag,mask) ((flag)&(1<<(mask)))
|
|
|
+#define BSET(flag,mask) ((flag)|=(1<<(mask)))
|
|
|
+
|
|
|
+static int get_date_time(char *d, char *t)
|
|
|
+{
|
|
|
+ time_t now;
|
|
|
+ struct tm* tm;
|
|
|
+
|
|
|
+ time(&now);
|
|
|
+ tm = localtime(&now);
|
|
|
+ if(!tm) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ sprintf(d, "%04d-%02d-%02d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
|
|
|
+ sprintf(t, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+static int get_serv(char *json)
|
|
|
+{
|
|
|
+ int i,flag=0;
|
|
|
+ cJSON* tmp=NULL;
|
|
|
+
|
|
|
+ if(json) {
|
|
|
+ cJSON* cjson=cJSON_Parse(json);
|
|
|
+ if(cjson) {
|
|
|
+ for(i=0; i<SERV_MAX; i++) {
|
|
|
+ tmp = cJSON_GetObjectItem(cjson, serv_str[i]);
|
|
|
+ if(tmp && tmp->valuestring) {
|
|
|
+ flag |= (atoi(tmp->valuestring)<<i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ cJSON_Delete(cjson);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if(thread_is_running(THREAD_ID_NTP)) {
|
|
|
+ BSET(flag, SERV_NTP);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(thread_is_running(THREAD_ID_MAIL)) {
|
|
|
+ BSET(flag, SERV_SMTP);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(thread_is_running(THREAD_ID_MQTT)) {
|
|
|
+ BSET(flag, SERV_MQTT);
|
|
|
+ }
|
|
|
+
|
|
|
+#if 0
|
|
|
+ if(thread_is_running(SERV_MESG)) {
|
|
|
+ BSET(flag, SERV_MESG);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(thread_is_running(THREAD_ID_CLOUD)) {
|
|
|
+ BSET(flag, SERV_CLOUD);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(thread_is_running(THREAD_ID_TELNET)) {
|
|
|
+ BSET(flag, SERV_TELNET);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+ if(sys_is_running("snmpd")) {
|
|
|
+ BSET(flag, SERV_NTP);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(thread_is_running(THREAD_ID_NTP)) {
|
|
|
+ BSET(flag, SERV_NTP);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return flag;
|
|
|
+}
|
|
|
+static int set_serv(int flag)
|
|
|
+{
|
|
|
+ if(BGET(flag,SERV_NTP)) {
|
|
|
+ if(!thread_is_running(THREAD_ID_NTP)) {
|
|
|
+ //thread_stop(THREAD_ID_NTP);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if(thread_is_running(THREAD_ID_NTP)) {
|
|
|
+ thread_stop(THREAD_ID_NTP);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(BGET(flag,SERV_SMTP)) {
|
|
|
+ if(!thread_is_running(THREAD_ID_MAIL)) {
|
|
|
+ //thread_stop(THREAD_ID_MAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ if(thread_is_running(THREAD_ID_MAIL)) {
|
|
|
+ thread_stop(THREAD_ID_MAIL);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(BGET(flag,SERV_MQTT)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(BGET(flag,SERV_MESG)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(BGET(flag,SERV_CLOUD)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(BGET(flag,SERV_TELNET)) {
|
|
|
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(BGET(flag,SERV_SNMP_V1) || BGET(flag,SERV_SNMP_V2C) || BGET(flag,SERV_SNMP_V3) || BGET(flag,SERV_SNMP_TRAP)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+static char *get_int_str(int n)
|
|
|
+{
|
|
|
+ static char tmp[32];
|
|
|
+ snprintf(tmp, sizeof(tmp), "%d", n);
|
|
|
+ return tmp;
|
|
|
+}
|
|
|
+static char *get_float_str(float n)
|
|
|
+{
|
|
|
+ static char tmp[32];
|
|
|
+ snprintf(tmp, sizeof(tmp), "%0.3f", n);
|
|
|
+ return tmp;
|
|
|
+}
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
@@ -687,14 +832,13 @@ static int send_cmd(cell_handle_t *h, at_cmd_t *pcmd, char *para, char *rcv, int
|
|
|
|
|
|
r = port_read(h, pbuf, buflen);
|
|
|
if(r>0) {
|
|
|
+ LOGD("___port_read: %s\n", pbuf);
|
|
|
if(pcmd->ok && strstr(pbuf, pcmd->ok)) {
|
|
|
- rsp = CELL_OK;
|
|
|
- break;
|
|
|
+ rsp = CELL_OK; break;
|
|
|
}
|
|
|
|
|
|
if(pcmd->err && strstr(pbuf, pcmd->err)) {
|
|
|
- rsp = CELL_ERR;
|
|
|
- break;
|
|
|
+ rsp = CELL_ERR; break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -734,6 +878,7 @@ static int cell_init(cell_handle_t *h)
|
|
|
{CMD_CGACT, "=1"},
|
|
|
{CMD_QGPSCFG, "=\"gpsnmeatype\",1"},
|
|
|
{CMD_QGPS, "=1"},
|
|
|
+ {CMD_QCFG, "=\"usbnet\",1"}, //set to ecm mode
|
|
|
{-1, NULL},
|
|
|
};
|
|
|
|
|
|
@@ -1265,221 +1410,96 @@ static int cell_mqtt_pub(mqtt_conn_t *conn, char *topic, void *data, int len)
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-/////////////////////////////////////////////////////////////////////////
|
|
|
-static int urc_handle(char *data, int len)
|
|
|
+static int mqttc_init(cell_handle_t *h)
|
|
|
{
|
|
|
- char *key=NULL;
|
|
|
+ int r=-1;
|
|
|
|
|
|
- key = "+QIURC: ";
|
|
|
- if(strstr(data, key)) {
|
|
|
+ r = cell_mqtt_init(h);
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- key = "+QMT";
|
|
|
- if(strstr(data, key)) {
|
|
|
+ return r;
|
|
|
+}
|
|
|
+static int get_host(mqtt_server_t *ser, mqtt_para_t *para)
|
|
|
+{
|
|
|
+ char *head="mqtts";
|
|
|
|
|
|
+ if(!ser->server[0] || !ser->port[0] || !ser->mode) {
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
+ para->port = atoi(ser->port);
|
|
|
+ if(para->port==1883) {
|
|
|
+ head = "mqtt";
|
|
|
+ }
|
|
|
+ else if(para->port==8883) {
|
|
|
+ head = "mqtts";
|
|
|
+ }
|
|
|
+ else if(para->port==8083) {
|
|
|
+ head = "ws";
|
|
|
+ }
|
|
|
+ else if(para->port==8884) {
|
|
|
+ head = "wss";
|
|
|
+ }
|
|
|
+ sprintf(para->host, "%s://%s", head, ser->server);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
-
|
|
|
-static void* cellular_thread(void *arg)
|
|
|
+static int mqttc_conn(cell_handle_t *h, int flag)
|
|
|
{
|
|
|
- int r;
|
|
|
- thread_handle_t *th=(thread_handle_t*)arg;
|
|
|
- cell_handle_t *h=(cell_handle_t*)th->arg;
|
|
|
-
|
|
|
- while (th->quit==0) {
|
|
|
- if(h->pcell->mode) {
|
|
|
+ int i,r;
|
|
|
+ char host[200];
|
|
|
+ uint16_t port;
|
|
|
+ mqtt_para_t para;
|
|
|
+ mqtt_server_t *ser=h->dm->mqttInfo.ser;
|
|
|
|
|
|
- r = port_recv(h, h->rxbuf, sizeof(h->rxbuf), QUERY_INTERVAL);
|
|
|
- if(r>0) {
|
|
|
- urc_handle(h->rxbuf, r);
|
|
|
+ if (flag) {
|
|
|
+ for(i=0; i<MQTT_MAX; i++) {
|
|
|
+ r = get_host(&ser[i], ¶);
|
|
|
+ if((r==0)) {
|
|
|
+ if(h->mq_conn[i].h==NULL) {
|
|
|
+ strcpy(para.username, ser->user);
|
|
|
+ strcpy(para.password, ser->password);
|
|
|
+ cell_mqtt_conn(h, ¶);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- else {
|
|
|
- msleep(1000);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ for(i=0; i<MQTT_MAX; i++) {
|
|
|
+ cell_mqtt_disconn(&h->mq_conn[i]);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
- port_deinit(h);
|
|
|
|
|
|
- pthread_exit(NULL);
|
|
|
+ return 0;
|
|
|
}
|
|
|
-#endif
|
|
|
-
|
|
|
-int cellular_reset(void)
|
|
|
+static int mqttc_sub_one(mqtt_conn_t *conn)
|
|
|
{
|
|
|
- int r=-1;
|
|
|
- char buf[100];
|
|
|
- cell_handle_t *h=&ceHandle;
|
|
|
-
|
|
|
-#ifdef USE_CELL
|
|
|
- at_cmd_t *pcmd = data_of(CMD_CFUN);
|
|
|
- r = send_cmd(h, pcmd, "=1,1", buf, sizeof(buf), 3);
|
|
|
-#endif
|
|
|
+ int i,r=-1;
|
|
|
+ char buf[200];
|
|
|
|
|
|
- return r;
|
|
|
-}
|
|
|
+ if(!conn->h) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ cell_handle_t *h=(cell_handle_t*)conn->h;
|
|
|
|
|
|
+ for(i=0; i<MQTT_SUB_MAX; i++) {
|
|
|
+ sprintf(buf, topic_sub[i], h->prod_id);
|
|
|
+ cell_mqtt_sub(conn, buf);
|
|
|
+ }
|
|
|
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+static int mqttc_sub(cell_handle_t *h)
|
|
|
+{
|
|
|
+ int i;
|
|
|
|
|
|
-int cellular_init(void)
|
|
|
+ for(i=0; i<MQTT_MAX; i++) {
|
|
|
+ mqttc_sub_one(&h->mq_conn[i]);
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+static int mqttc_pub(cell_handle_t *h, char *topic, char *data)
|
|
|
{
|
|
|
- int r;
|
|
|
- cell_handle_t *h=&ceHandle;
|
|
|
-
|
|
|
-#ifdef USE_CELL
|
|
|
- memset(h, 0, sizeof(cell_handle_t));
|
|
|
-
|
|
|
- port_init(h);
|
|
|
- h->dm = &__globalDeviceManage;
|
|
|
- h->pcell = &_globalCellularManager;
|
|
|
- h->pcell->mode = h->dm->_globalDevInfo.cell;
|
|
|
- h->prod_id = h->dm->_globalDevInfo.product.id;
|
|
|
- h->lck = lock_d_init();
|
|
|
-
|
|
|
- r = cell_init(h);
|
|
|
- if(r) {
|
|
|
- LOGE("__cell_init failed\n");
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- if (0==thread_is_running(THREAD_ID_CELLULAR)) {
|
|
|
- thread_start(THREAD_ID_CELLULAR, cellular_thread, h);
|
|
|
- }
|
|
|
-#endif
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-int cellular_deinit(void)
|
|
|
-{
|
|
|
- cell_handle_t *h=&ceHandle;
|
|
|
-
|
|
|
- lock_d_deinit(h->lck);
|
|
|
- cell_deinit(h);
|
|
|
- thread_stop(THREAD_ID_CELLULAR);
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-int cellular_get_info(cell_info_t *info)
|
|
|
-{
|
|
|
- int r=-1;
|
|
|
- cell_handle_t *h=&ceHandle;
|
|
|
-
|
|
|
-#ifdef USE_CELL
|
|
|
- r = cell_get_info(h, info);
|
|
|
-#endif
|
|
|
-
|
|
|
- return r;
|
|
|
-}
|
|
|
-
|
|
|
-int cellular_get_stat(cell_stat_t *stat)
|
|
|
-{
|
|
|
- int r=-1;
|
|
|
- cell_handle_t *h=&ceHandle;
|
|
|
-
|
|
|
-#ifdef USE_CELL
|
|
|
- r = cell_get_stat(h, stat);
|
|
|
-#endif
|
|
|
-
|
|
|
- return r;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-static int mqttc_init(cell_handle_t *h)
|
|
|
-{
|
|
|
- int r=-1;
|
|
|
-
|
|
|
- r = cell_mqtt_init(h);
|
|
|
-
|
|
|
- return r;
|
|
|
-}
|
|
|
-static int get_host(mqtt_server_t *ser, mqtt_para_t *para)
|
|
|
-{
|
|
|
- char *head="mqtts";
|
|
|
-
|
|
|
- if(!ser->server[0] || !ser->port[0] || !ser->mode) {
|
|
|
- return -1;
|
|
|
- }
|
|
|
-
|
|
|
- para->port = atoi(ser->port);
|
|
|
- if(para->port==1883) {
|
|
|
- head = "mqtt";
|
|
|
- }
|
|
|
- else if(para->port==8883) {
|
|
|
- head = "mqtts";
|
|
|
- }
|
|
|
- else if(para->port==8083) {
|
|
|
- head = "ws";
|
|
|
- }
|
|
|
- else if(para->port==8884) {
|
|
|
- head = "wss";
|
|
|
- }
|
|
|
- sprintf(para->host, "%s://%s", head, ser->server);
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-static int mqttc_conn(cell_handle_t *h, int flag)
|
|
|
-{
|
|
|
- int i,r;
|
|
|
- char host[200];
|
|
|
- uint16_t port;
|
|
|
- mqtt_para_t para;
|
|
|
- mqtt_server_t *ser=h->dm->mqttInfo.ser;
|
|
|
-
|
|
|
- if (flag) {
|
|
|
- for(i=0; i<MQTT_MAX; i++) {
|
|
|
- r = get_host(&ser[i], ¶);
|
|
|
- if((r==0)) {
|
|
|
- if(h->mq_conn[i].h==NULL) {
|
|
|
- strcpy(para.username, ser->user);
|
|
|
- strcpy(para.password, ser->password);
|
|
|
- cell_mqtt_conn(h, ¶);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- for(i=0; i<MQTT_MAX; i++) {
|
|
|
- cell_mqtt_disconn(&h->mq_conn[i]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-static int mqttc_sub_one(mqtt_conn_t *conn)
|
|
|
-{
|
|
|
- int i,r=-1;
|
|
|
- char buf[200];
|
|
|
-
|
|
|
- if(!conn->h) {
|
|
|
- return -1;
|
|
|
- }
|
|
|
- cell_handle_t *h=(cell_handle_t*)conn->h;
|
|
|
-
|
|
|
- for(i=0; i<MQTT_SUB_MAX; i++) {
|
|
|
- sprintf(buf, topic_sub[i], h->prod_id);
|
|
|
- cell_mqtt_sub(conn, buf);
|
|
|
- }
|
|
|
- return 0;
|
|
|
-}
|
|
|
-static int mqttc_sub(cell_handle_t *h)
|
|
|
-{
|
|
|
- int i;
|
|
|
-
|
|
|
- for(i=0; i<MQTT_MAX; i++) {
|
|
|
- mqttc_sub_one(&h->mq_conn[i]);
|
|
|
- }
|
|
|
- return 0;
|
|
|
-}
|
|
|
-static int mqttc_pub(cell_handle_t *h, char *topic, char *data)
|
|
|
-{
|
|
|
- int i,r=-1;
|
|
|
+ int i,r=-1;
|
|
|
|
|
|
for(i=0; i<MQTT_MAX; i++) {
|
|
|
if(h->mq_conn[i].h) {
|
|
|
@@ -1490,153 +1510,7 @@ static int mqttc_pub(cell_handle_t *h, char *topic, char *data)
|
|
|
}
|
|
|
|
|
|
|
|
|
-#define BGET(flag,mask) ((flag)&(1<<(mask)))
|
|
|
-#define BSET(flag,mask) ((flag)|=(1<<(mask)))
|
|
|
-
|
|
|
-static int get_date_time(char *d, char *t)
|
|
|
-{
|
|
|
- time_t now;
|
|
|
- struct tm* tm;
|
|
|
-
|
|
|
- time(&now);
|
|
|
- tm = localtime(&now);
|
|
|
- if(!tm) {
|
|
|
- return -1;
|
|
|
- }
|
|
|
- sprintf(d, "%04d-%02d-%02d", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday);
|
|
|
- sprintf(t, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
|
|
|
- return 0;
|
|
|
-}
|
|
|
-static int get_serv(char *json)
|
|
|
-{
|
|
|
- int i,flag=0;
|
|
|
- cJSON* tmp=NULL;
|
|
|
-
|
|
|
- if(json) {
|
|
|
- cJSON* cjson=cJSON_Parse(json);
|
|
|
- if(cjson) {
|
|
|
- for(i=0; i<SERV_MAX; i++) {
|
|
|
- tmp = cJSON_GetObjectItem(cjson, serv_str[i]);
|
|
|
- if(tmp && tmp->valuestring) {
|
|
|
- flag |= (atoi(tmp->valuestring)<<i);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- cJSON_Delete(cjson);
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- if(thread_is_running(THREAD_ID_NTP)) {
|
|
|
- BSET(flag, SERV_NTP);
|
|
|
- }
|
|
|
-
|
|
|
- if(thread_is_running(THREAD_ID_MAIL)) {
|
|
|
- BSET(flag, SERV_SMTP);
|
|
|
- }
|
|
|
-
|
|
|
- if(thread_is_running(THREAD_ID_MQTT)) {
|
|
|
- BSET(flag, SERV_MQTT);
|
|
|
- }
|
|
|
-
|
|
|
-#if 0
|
|
|
- if(thread_is_running(SERV_MESG)) {
|
|
|
- BSET(flag, SERV_MESG);
|
|
|
- }
|
|
|
-
|
|
|
- if(thread_is_running(THREAD_ID_CLOUD)) {
|
|
|
- BSET(flag, SERV_CLOUD);
|
|
|
- }
|
|
|
-
|
|
|
- if(thread_is_running(THREAD_ID_TELNET)) {
|
|
|
- BSET(flag, SERV_TELNET);
|
|
|
- }
|
|
|
-#endif
|
|
|
-
|
|
|
- if(sys_is_running("snmpd")) {
|
|
|
- BSET(flag, SERV_NTP);
|
|
|
- }
|
|
|
-
|
|
|
- if(thread_is_running(THREAD_ID_NTP)) {
|
|
|
- BSET(flag, SERV_NTP);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return flag;
|
|
|
-}
|
|
|
-static int set_serv(int flag)
|
|
|
-{
|
|
|
- if(BGET(flag,SERV_NTP)) {
|
|
|
- if(!thread_is_running(THREAD_ID_NTP)) {
|
|
|
- //thread_stop(THREAD_ID_NTP);
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- if(thread_is_running(THREAD_ID_NTP)) {
|
|
|
- thread_stop(THREAD_ID_NTP);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(BGET(flag,SERV_SMTP)) {
|
|
|
- if(!thread_is_running(THREAD_ID_MAIL)) {
|
|
|
- //thread_stop(THREAD_ID_MAIL);
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- if(thread_is_running(THREAD_ID_MAIL)) {
|
|
|
- thread_stop(THREAD_ID_MAIL);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(BGET(flag,SERV_MQTT)) {
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if(BGET(flag,SERV_MESG)) {
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if(BGET(flag,SERV_CLOUD)) {
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
- if(BGET(flag,SERV_TELNET)) {
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if(BGET(flag,SERV_SNMP_V1) || BGET(flag,SERV_SNMP_V2C) || BGET(flag,SERV_SNMP_V3) || BGET(flag,SERV_SNMP_TRAP)) {
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return 0;
|
|
|
-}
|
|
|
-static char *get_int_str(int n)
|
|
|
-{
|
|
|
- static char tmp[32];
|
|
|
- snprintf(tmp, sizeof(tmp), "%d", n);
|
|
|
- return tmp;
|
|
|
-}
|
|
|
-static char *get_float_str(float n)
|
|
|
-{
|
|
|
- static char tmp[32];
|
|
|
- snprintf(tmp, sizeof(tmp), "%0.3f", n);
|
|
|
- return tmp;
|
|
|
-}
|
|
|
static int mqttc_send_stat(cell_handle_t *h, int type)
|
|
|
{
|
|
|
int i,r=-1;
|
|
|
@@ -1952,12 +1826,142 @@ static int sock_test(void)
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
+/////////////////////////////////////////////////////////////////////////
|
|
|
+static int urc_handle(char *data, int len)
|
|
|
+{
|
|
|
+ char *key=NULL;
|
|
|
|
|
|
-int cellular_test(void)
|
|
|
+ key = "+QIURC: ";
|
|
|
+ if(strstr(data, key)) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ key = "+QMT";
|
|
|
+ if(strstr(data, key)) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static void* cellular_thread(void *arg)
|
|
|
+{
|
|
|
+ int r;
|
|
|
+ thread_handle_t *th=(thread_handle_t*)arg;
|
|
|
+ cell_handle_t *h=(cell_handle_t*)th->arg;
|
|
|
+
|
|
|
+ while (th->quit==0) {
|
|
|
+ if(h->pcell->mode) {
|
|
|
+
|
|
|
+ r = port_recv(h, h->rxbuf, sizeof(h->rxbuf), QUERY_INTERVAL);
|
|
|
+ if(r>0) {
|
|
|
+ urc_handle(h->rxbuf, r);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ msleep(1000);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ port_deinit(h);
|
|
|
+
|
|
|
+ pthread_exit(NULL);
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
+int cellular_reset(void)
|
|
|
+{
|
|
|
+ int r=-1;
|
|
|
+ char buf[100];
|
|
|
+ cell_handle_t *h=&ceHandle;
|
|
|
+
|
|
|
+#ifdef USE_CELL
|
|
|
+ at_cmd_t *pcmd = data_of(CMD_CFUN);
|
|
|
+ r = send_cmd(h, pcmd, "=1,1", buf, sizeof(buf), 3);
|
|
|
+#endif
|
|
|
+
|
|
|
+ return r;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+int cellular_init(void)
|
|
|
{
|
|
|
- //sock_test();
|
|
|
- mqttc_test();
|
|
|
+ int r;
|
|
|
+ cell_handle_t *h=&ceHandle;
|
|
|
|
|
|
+#ifdef USE_CELL
|
|
|
+ memset(h, 0, sizeof(cell_handle_t));
|
|
|
+
|
|
|
+ port_init(h);
|
|
|
+ h->dm = &__globalDeviceManage;
|
|
|
+ h->pcell = &_globalCellularManager;
|
|
|
+ h->pcell->mode = h->dm->_globalDevInfo.cell;
|
|
|
+ h->prod_id = h->dm->_globalDevInfo.product.id;
|
|
|
+ h->lck = lock_d_init();
|
|
|
+
|
|
|
+ r = cell_init(h);
|
|
|
+ if(r) {
|
|
|
+ LOGE("__cell_init failed\n");
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (0==thread_is_running(THREAD_ID_CELLULAR)) {
|
|
|
+ thread_start(THREAD_ID_CELLULAR, cellular_thread, h);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+int cellular_deinit(void)
|
|
|
+{
|
|
|
+ cell_handle_t *h=&ceHandle;
|
|
|
+
|
|
|
+#ifdef USE_CELL
|
|
|
+ lock_d_deinit(h->lck);
|
|
|
+ cell_deinit(h);
|
|
|
+ thread_stop(THREAD_ID_CELLULAR);
|
|
|
+#endif
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+int cellular_get_info(cell_info_t *info)
|
|
|
+{
|
|
|
+ int r=-1;
|
|
|
+ cell_handle_t *h=&ceHandle;
|
|
|
+
|
|
|
+#ifdef USE_CELL
|
|
|
+ r = cell_get_info(h, info);
|
|
|
+#endif
|
|
|
+
|
|
|
+ return r;
|
|
|
+}
|
|
|
+
|
|
|
+int cellular_get_stat(cell_stat_t *stat)
|
|
|
+{
|
|
|
+ int r=-1;
|
|
|
+ cell_handle_t *h=&ceHandle;
|
|
|
+
|
|
|
+#ifdef USE_CELL
|
|
|
+ r = cell_get_stat(h, stat);
|
|
|
+#endif
|
|
|
+
|
|
|
+ return r;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+int cellular_test(void)
|
|
|
+{
|
|
|
+#ifdef USE_CELL
|
|
|
+ sock_test();
|
|
|
+ //mqttc_test();
|
|
|
+#endif
|
|
|
|
|
|
return 0;
|
|
|
}
|