Przeglądaj źródła

1、优化4G数据结构并添加网页端处理

liyuezong 1 rok temu
rodzic
commit
ce83a7cb73

+ 5 - 3
pro/config/cfg.h

@@ -22,10 +22,10 @@
 //#define PRJ_HYPERTEC_AC_I3_O1
 //#define PRJ_SG_I3_O3
 //#define PRJ_TEST
-//#define PRJ_TEST_AC_I1_O1
+#define PRJ_TEST_AC_I1_O1
 //#define PRJ_TEST_AC_I3_O1
 //#define PRJ_TEST_AC_I3_O3
-#define PRJ_ESOUTH_DC_I1_O4_RGB5
+//#define PRJ_ESOUTH_DC_I1_O4_RGB5
 
 //#define PRJ_IP_AC_I3_O3
 //#define PRJ_INST2302_DC_OLED
@@ -47,8 +47,10 @@
 #define USE_MQTT
 #define MQTT_SERVER_BUILTIN
 
-//#define USE_CELL
+#define USE_CELL
 //#define USE_WIFI
+//#define GNSS_ENABLE               //EC200N-CN, ˛ťÖ§łÖgnss
+
 #define USE_BOARD_UPGRADE
 
 

+ 41 - 25
pro/src/Cellular.c

@@ -31,9 +31,6 @@
 #endif
 
 
-#define USE_CELL
-//#define GNSS_ENABLE               //EC200N-CN, 不支持gnss
-
 #define RETRY_TIMES                 3
 #define BUF_LEN                     2000
 #define AT_PORT                     "/dev/ttyUSB1"
@@ -393,11 +390,11 @@ static int rssi_to_dbm(int rssi)
 {
     int dbm=0;
 
-    if(rssi>=0 && rssi<=31) {
+    if(rssi>=0 && rssi<57) {
         dbm = RSSI_DBM_MIN1+rssi*2;
     }
-    else if(rssi>=100 && rssi<=191) {
-        dbm = RSSI_DBM_MIN2+rssi;
+    else if(rssi>=100 && rssi<199) {
+        dbm = RSSI_DBM_MIN2+rssi-100;
     }
     return dbm;
 }
@@ -465,24 +462,24 @@ static void msleep(int ms)
 {
     usleep(ms*1000);
 }
-static void reset_var(CellularManager *pcell)
+static void reset_var( cell_handle_t *h)
 {
-    //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; // 短信功能启用
+    h->stat=AT_STAT_UNINIT;
+
+    h->all.stat.dbm = 0;
+    h->all.stat.ber = 0;
+    h->all.stat.nsta = 0;
+    h->all.stat.altitude = 0;
+    sprintf(h->all.stat.latitude, "-");
+    sprintf(h->all.stat.longitude, "-");
+   h->all.stat.utctime = 0;
+    h->all.stat.linked = 0;
+
+    sprintf(h->all.info.apn, "-");
+    sprintf(h->all.info.cnum, "-");
+    sprintf(h->all.info.imsi, "-");
+    sprintf(h->all.info.imei, "-");
+    sprintf(h->all.info.isp, "-");
 }
 static int port_init(cell_handle_t *h)
 {
@@ -856,7 +853,7 @@ static int cell_get_stat(cell_handle_t *h, cell_stat_t *stat)
     cell_get_gnss(h, stat);
     cell_get_ping(h, stat);
     cell_get_time(h, stat);
-
+    
     return 0;
 }
 static int cell_sock_conn(cell_handle_t *h, int sock, char *host, uint16_t port, sock_conn_t *conn)
@@ -1283,9 +1280,15 @@ static void* cellular_thread(void *arg)
             }
 
             if(cnt%5==0) {
+                //cell_get_info(h, &h->all.info);
                 cell_get_stat(h, &h->all.stat);
             }
         }
+        else
+        {
+            reset_var(h);
+        }
+        UpdateCellularManager(&h->all);
         sleep(1);
     }
     cell_deinit(h);
@@ -1370,7 +1373,20 @@ int cellular_is_connected(void)
     return r;
 }
 
-
+int UpdateCellularManager( cell_all_t *all)
+{
+    int r = -1;
+    if (all)
+    {
+        __globalDeviceManage._globalDevInfo.cell.Link_status = all->stat.linked;
+        __globalDeviceManage._globalDevInfo.cell.Signal_strength =  all->stat.dbm;
+        strcpy(  __globalDeviceManage._globalDevInfo.cell.apn , all->info.apn);
+        strcpy(  __globalDeviceManage._globalDevInfo.cell.Cellular_name , all->info.isp);
+        strcpy(  __globalDeviceManage._globalDevInfo.cell.Cellular_Num , all->info.imei);
+        r=0;
+    }
+    return r;
+}
 
 int cellular_test(void)
 {

+ 3 - 0
pro/src/Cellular.h

@@ -204,4 +204,7 @@ int cellular_reset(void);
 int cellular_get_all(cell_all_t *all);
 int cellular_is_connected(void);
 
+int UpdateCellularManager( cell_all_t *all);
+
+
 #endif

+ 2 - 3
pro/src/appweb_handle.c

@@ -3890,12 +3890,11 @@ static void communicationManagement(void *conn)
 #ifdef USE_CELL
     else if (strcmp(reqInfo.type, "listfourgPZQuery") == 0) // 4G网络处理
     {
-        ack_str = communication_4G_ack_to_json(&_globalCellularManager,0);
+        ack_str = communication_4G_ack_to_json(& __globalDeviceManage._globalDevInfo.cell,0);
     }
     else if (strcmp(reqInfo.type, "fourgPZSave") == 0) // 4G网络处理
     {
-        _globalCellularManager.mode = reqInfo._4g_wifi_info.Cellular_mode;
-        __globalDeviceManage._globalDevInfo.cell.mode = _globalCellularManager.mode;
+        __globalDeviceManage._globalDevInfo.cell.mode = reqInfo._4g_wifi_info.Cellular_mode;
         paras_save();
 
         ack_str = ctrl_sts_ack_to_json(); 

+ 0 - 1
pro/src/common.c

@@ -30,7 +30,6 @@ char _GlobalUserToken[64];
 MenuAuthority _GlobalMenuAuthority;
 NTPManager _globalNTPManager;
 SNMPManager _globalSNMPManager;
-CellularManager  _globalCellularManager;
 WIFIManager _globalWIFIManager;
 
 

+ 23 - 29
pro/src/common.h

@@ -387,13 +387,30 @@ typedef struct {
     int         rotate;
 }MiscInfo_t;
 
-typedef struct {
-    int         mode;
-    char        apn[32];
-    char        username[32];
-    char        password[32];
-}CellInfo_t;
+// 4G网络及GPS信息
+typedef struct
+{
+    int mode;         // 4G模块启用状态
+    bool Link_status; // 4G网络连接状态
+    int Signal_strength; // 信号强度
+    char Cellular_name[32];// 4G网络运营商名称
+    char apn[32];// APN接入点名称
+    char username[32];
+    char password[32];
+    char Cellular_Num[32];// 电话号码
+	
+    
+	bool GPS_status; // GPS功能启用
+    char GPS_utc[64];// UTC时间
+    float GPS_latitude;// 纬度,范围-89.99999~89.99999
+    float GPS_longitude;// 精度,范围-179.99999~179.99999
+    float GPS_altitude;// 海拔高度,单位m
+    float GPS_speed;//地面速率,单位km/h
+    int GPS_nsat;//卫星数量
+
+    bool SMS_status; // 短信功能启用
 
+} CellInfo_t;
 
 typedef struct {
     char        name[256];
@@ -568,29 +585,7 @@ typedef struct
     struct list_head    list;  
 }GroupInfo;
 
-// 4G网络及GPS信息
-typedef struct
-{
-    int mode;         // 4G模块启用状态
-    bool Link_status; // 4G网络连接状态
-    bool RS_status; // 4G模组串口访问状态
-    int RS_fd; // 4G模组串口访问状态
-    float Signal_strength; // 信号强度
-    char Cellular_name[64];// 4G网络名称
-    char Cellular_APN[64];// APN接入点名称
-    char Cellular_Num[64];// 电话号码
-	
-	bool GPS_status; // GPS功能启用
-    char GPS_utc[64];// UTC时间
-    float GPS_latitude;// 纬度,范围-89.99999~89.99999
-    float GPS_longitude;// 精度,范围-179.99999~179.99999
-    float GPS_altitude;// 海拔高度,单位m
-    float GPS_speed;//地面速率,单位km/h
-    int GPS_nsat;//卫星数量
-
-    bool SMS_status; // 短信功能启用
 
-} CellularManager;
 
 //电源部分
 typedef struct 
@@ -1307,7 +1302,6 @@ extern MenuAuthority _GlobalMenuAuthority;////角色菜单权限
 extern NTPManager _globalNTPManager;
 extern SNMPManager _globalSNMPManager;
 
-extern CellularManager  _globalCellularManager;
 extern WIFIManager _globalWIFIManager;
 
 

+ 2 - 2
pro/src/json_handle.c

@@ -4632,7 +4632,7 @@ char* communication_rs_ack_to_json(ModbusInfo_t* _modbusInfo_t)
 /// @brief 返回RS485信息
 /// @param _networkInfo_t 
 /// @return 
-char* communication_4G_ack_to_json(CellularManager* _CellularManagerTemp,int nWSType)
+char* communication_4G_ack_to_json(CellInfo_t* _CellularManagerTemp,int nWSType)
 {
     char temp[32] = {0};
     char* str = NULL;
@@ -4677,7 +4677,7 @@ char* communication_4G_ack_to_json(CellularManager* _CellularManagerTemp,int nWS
     cJSON_AddStringToObject(data_root_array, "ljzt", temp);
 
     memset(temp, 0, sizeof(temp));
-    sprintf(temp, "%0.2f dBm", _CellularManagerTemp->Signal_strength);
+    sprintf(temp, "%d dBm", _CellularManagerTemp->Signal_strength);
     cJSON_AddStringToObject(data_root_array, "xhqd", temp);
 
     if (nWSType)

+ 1 - 1
pro/src/json_handle.h

@@ -632,7 +632,7 @@ char* communication_net_ack_to_json(NetworkInfo_t* _networkInfo_t);
 
 char* communication_rs_ack_to_json(ModbusInfo_t* _modbusInfo_t);
 
-char* communication_4G_ack_to_json(CellularManager* _CellularManagerTemp,int nWSType);
+char* communication_4G_ack_to_json(CellInfo_t* _CellularManagerTemp,int nWSType);
 
 char* communication_WIFI_ack_to_json(WIFIManager* _WIFIManagertemp,int nWSType);
 

+ 1 - 1
pro/src/websocket_handle.c

@@ -248,7 +248,7 @@ static int ws_Cellular_update(ws_handle_t *h)
     char *json;
 
 #ifdef USE_CELL
-    json = communication_4G_ack_to_json(&_globalCellularManager,1);
+    json = communication_4G_ack_to_json(& __globalDeviceManage._globalDevInfo.cell,1);
     if(json) {
         ws_send_data(h, json, strlen(json));
         cJSON_free(json);