diff --git a/package/allwinner/wifimanager/smartaudio/app_wifi_manager.cpp b/package/allwinner/wifimanager/smartaudio/app_wifi_manager.cpp index edec508a2..8e4e4cc6b 100755 --- a/package/allwinner/wifimanager/smartaudio/app_wifi_manager.cpp +++ b/package/allwinner/wifimanager/smartaudio/app_wifi_manager.cpp @@ -322,6 +322,68 @@ char * api_wifi_res_json_get(int res) return p; } +char * api_wifi_scan_result_json_get(char *scan_results, int len) +{ + cJSON *pRoot = NULL; + cJSON *pArrayItem = NULL; + cJSON *pArrayItem2 = NULL; + char *p=NULL; + char *pCh = NULL; + const char *split1 = "\n"; + const char *split2 = "\t"; + + LOG_EX(LOG_Debug, "Scan result: %s\n", scan_results); + + pRoot = cJSON_CreateArray(); + if(NULL == pRoot) + return NULL; + + // Skip title + pCh = strtok(scan_results, split1); + // Skip mac + pCh = strtok(NULL, split2); + while (pCh != NULL) + { + pArrayItem = cJSON_CreateObject(); + if(NULL == pArrayItem) + { + cJSON_Delete(pRoot); + return NULL; + } + // Skip Freq + pCh = strtok(NULL, split2); + // Signal level + pCh = strtok(NULL, split2); + cJSON_AddItemToObject(pArrayItem, "Strength", cJSON_CreateString(pCh)); + // Flags + pCh = strtok(NULL, split2); + cJSON_AddItemToObject(pArrayItem, "Security", cJSON_CreateString(pCh)); + // SSID + pCh = strtok(NULL, split1); + cJSON_AddItemToObject(pArrayItem, "Ssid", cJSON_CreateString(pCh)); + // Freq, support only 2.4GHz currently. + cJSON_AddItemToObject(pArrayItem, "Frequence", cJSON_CreateString("2.4GHz")); + + cJSON_AddItemToArray(pRoot, pArrayItem); + + // Skip next mac + pCh = strtok(NULL, split2); + } + + p = cJSON_Print(pRoot); + + if(NULL == p) + { + cJSON_Delete(pRoot); + return NULL; + } + + cJSON_Delete(pRoot); + + return p; +} + + char * api_wifi_state_json_get(char * p_key,int res) { cJSON* pRoot = NULL; @@ -750,7 +812,7 @@ int api_wifi_get_str_raw(char **p_str_brace) -#define WIFI_INFO_BASE64 1 +#define WIFI_INFO_BASE64 0 PDBUS_MSG_PACK DBusOnMessage(uv_loop_t *pLoop, DBusConnection *pConn, @@ -943,8 +1005,8 @@ PDBUS_MSG_PACK DBusOnMessage(uv_loop_t *pLoop, DBusConnection *pConn, pResJson = (uint8_t *)api_wifi_res_json_get(rsp_code); if(NULL != pResJson) { - if(0 == rsp_code)mask = 1<get_scan_results(scan_results, &len); + if(status < 0) + { + break; + } + + pResJson = (uint8_t *)api_wifi_scan_result_json_get(scan_results, len); + if(NULL != pResJson) + { + mask = 1<disconnect_ap(event_label); + if(0 != rsp_code) + { + LOG_EX(LOG_Debug, "ERROR:wifi disconnect event 0x%x\n", aw_wifi_get_wifi_event()); + }else + { + LOG_EX(LOG_Debug, "Disconnect the wifi connected ap\r\n"); + } + } + + LOG_EX(LOG_Debug, "wifi module CMD_WIFI_CONF rsp_code 0x%x.\r\n", rsp_code); + pResJson = (uint8_t *)api_wifi_res_json_get(rsp_code); + if(NULL != pResJson) + { + mask = (1<pMsg); switch (pMsg->busCmd) { - //case CMD_SPLAYER_SFIFO_TEST: - // break; + case CMD_WIFI_SCAN_RESP: + mailbox->recvWifiScanResult(QByteArray(pMsg->pMsg)); + break; + case CMD_WIFI_CONF_RESP: + mailbox->recvWifiConfResult(QByteArray(pMsg->pMsg)); + break; + case CMD_WIFI_STATE_NTF: + mailbox->recvWifiConfResult(QByteArray(pMsg->pMsg)); + break; + case CMD_WIFI_DISCONNECT_RESP: + mailbox->recvWifiDisconnectResult(QByteArray(pMsg->pMsg)); + break; default: break; } @@ -45,25 +56,21 @@ int main(int argc, char *argv[]) DBusConnection* pBus = NULL; uv_loop_t* pLoop = uv_default_loop(); + //为界面设置mailbox,使用子类dbusMailBox实例化 + setMailBox(); + g_pDBusInterfaceName = g_pModInfoTable[MODULE_CLOCK_FRAME].modAliase; - - LOG_EX(LOG_Debug, "\r\nStart the clockFrame communocation,module number is %d\r\n",MODULE_CLOCK_FRAME); - - pBus = DBusWithLibuvInit(pLoop, g_pDBusInterfaceName, DBusOnMessage, NULL, NULL, &ret); - if(pBus == NULL) { fprintf(stderr, "%s(%d): DBusWithLibuvInit Error: %d\n", g_pDBusInterfaceName, MODULE_CLOCK_FRAME, ret); return 0; - } + } + LOG_EX(LOG_Debug, "\r\nStart the clockFrame communocation,module number is %d\r\n",MODULE_CLOCK_FRAME); thdDbusLoop = std::thread(RunUVLoop, pLoop); thdDbusLoop.detach(); - //为界面设置mailbox,使用子类dbusMailBox实例化 - setMailBox(); - return frameShow(argc, argv); } \ No newline at end of file