1 wifimanager: Add operations for clockFrame(Qt UI).

This commit is contained in:
lijie02 2019-01-29 19:01:00 +08:00
parent aa5c16c3ff
commit 9e0dc36717
4 changed files with 271 additions and 16 deletions

View File

@ -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<<MODULE_CONTROLLER;
else mask = (1<<MODULE_BT)|(1<<MODULE_CONTROLLER);
if(0 == rsp_code)mask = 1<<MODULE_CONTROLLER | (1<<MODULE_CLOCK_FRAME);
else mask = (1<<MODULE_BT)|(1<<MODULE_CONTROLLER) | (1<<MODULE_CLOCK_FRAME);
status = api_wifi_module_cmd_send(mask,CMD_WIFI_CONF_RESP, (const char *)pResJson);
if(0 != status)
@ -984,7 +1046,7 @@ END_DO:
break;
case CMD_WIFI_AUTO_CONN:
{
{
LOG_EX(LOG_Debug, "====================Get cmd CMD_WIFI_AUTO_CONN==========================\r\n");
if(1== busy_conf || 1 == wifi_off_mode)
{
@ -1098,9 +1160,140 @@ END_DO:
}
break;
}
case CMD_WIFI_SCAN:
{
LOG_EX(LOG_Debug, "====================Get cmd CMD_WIFI_SCAN==========================\r\n");
char scan_results[4096] = {0};
int len = 4096;
event_label= WIFI_CONF_EVT_TAG;;
/*status = api_wifi_module_cmd_send((1<<MODULE_CLOCK_FRAME),CMD_WIFI_CHANGE_VALID_AP_RESP, NULL);
if(0 != status)
{
LOG_EX(LOG_Debug, "Wifi module send dbus msg to control er:%d\r\n",status);
}else
{
LOG_EX(LOG_Debug, "Wifi module is send wifi_auto msg to control module\r\n");
}*/
if(NULL == p_wifi_interface)
{
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
LOG_EX(LOG_Debug, "wifi on failed event 0x%x\n", aw_wifi_get_wifi_event());
busy_auto =0;
break;
}
}
while(aw_wifi_get_wifi_state() == CONNECTING || aw_wifi_get_wifi_state() == OBTAINING_IP){
LOG_EX(LOG_Debug, "wifi state busing,waiting\n");
usleep(2000000);
}
status = p_wifi_interface->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<<MODULE_CLOCK_FRAME;
status = api_wifi_module_cmd_send(mask,CMD_WIFI_SCAN_RESP, (const char *)pResJson);
if (0 != status)
{
LOG_EX(LOG_Debug, "Wifi module send dbus msg to clockFrame err:%d\r\n",status);
}
else
{
LOG_EX(LOG_Debug, "Wifi module is send msg : 0x%x to clockFrame module\r\n",pResJson);
}
}
else
{
LOG_EX(LOG_Debug, "Wifi module get scan results err\r\n");
}
if(NULL != pResJson)
{
free(pResJson);
pResJson = NULL;
}
break;
}
case CMD_WIFI_DISCONNECT:
{
LOG_EX(LOG_Debug, "====================Get cmd CMD_WIFI_DISCONNECT==========================\r\n");
event_label= WIFI_CONF_EVT_TAG;;
/*status = api_wifi_module_cmd_send((1<<MODULE_CLOCK_FRAME),CMD_WIFI_CHANGE_VALID_AP_RESP, NULL);
if(0 != status)
{
LOG_EX(LOG_Debug, "Wifi module send dbus msg to control er:%d\r\n",status);
}else
{
LOG_EX(LOG_Debug, "Wifi module is send wifi_auto msg to control module\r\n");
}*/
if(NULL == p_wifi_interface)
{
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
LOG_EX(LOG_Debug, "wifi on failed event 0x%x\n", aw_wifi_get_wifi_event());
busy_auto =0;
break;
}
}
while(aw_wifi_get_wifi_state() == CONNECTING || aw_wifi_get_wifi_state() == OBTAINING_IP){
LOG_EX(LOG_Debug, "wifi state busing,waiting\n");
usleep(2000000);
}
rsp_code = -1;
if(NETWORK_CONNECTED == aw_wifi_get_wifi_state())
{
rsp_code = p_wifi_interface->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<<MODULE_CLOCK_FRAME);
status = api_wifi_module_cmd_send(mask, CMD_WIFI_DISCONNECT_RESP, (const char *)pResJson);
if(0 != status)
{
LOG_EX(LOG_Debug, "Wifi module send dbus msg to clockFrame err:%d\r\n",status);
}else
{
LOG_EX(LOG_Debug, "Wifi module is send msg : 0x%x to clockFrame module\r\n",rsp_code);
}
}
else
{
LOG_EX(LOG_Debug, "Wifi module get res json err\r\n");
}
if(NULL != pResJson)
{
free(pResJson);
pResJson = NULL;
}
break;
}
case CMD_WIFI_STATE_REQ:
{
int rssi = 0;

View File

@ -12,6 +12,32 @@ void setMailBox(void)
mailbox = new DbusMailBox();
}
int DbusMailBox::s_wifiScan()
{
cJSON* pRoot = NULL;
char* msg = NULL;
int ret = FRAMER_OK;
pRoot=cJSON_CreateObject();
CHECKR_NULL(pRoot, FRAMER_ERR1);
msg = cJSON_Print(pRoot);
if(NULL == msg)
{
cJSON_Delete(pRoot);
return -1;
}
cJSON_Delete(pRoot);
ret = frameCmdSend(1<<MODULE_WIFI, CMD_WIFI_SCAN, msg);
free(msg);
msg = NULL;
return ret;
}
int DbusMailBox::s_wifiConnect(QString ssid, QString passwd)
{
cJSON* pRoot = NULL;
@ -44,5 +70,32 @@ int DbusMailBox::s_wifiConnect(QString ssid, QString passwd)
return ret;
}
int DbusMailBox::s_wifiDisconnect()
{
cJSON* pRoot = NULL;
char* msg = NULL;
int ret = FRAMER_OK;
pRoot=cJSON_CreateObject();
CHECKR_NULL(pRoot, FRAMER_ERR1);
msg = cJSON_Print(pRoot);
if(NULL == msg)
{
cJSON_Delete(pRoot);
return -1;
}
cJSON_Delete(pRoot);
ret = frameCmdSend(1<<MODULE_WIFI, CMD_WIFI_DISCONNECT, msg);
free(msg);
msg = NULL;
return ret;
}

View File

@ -57,5 +57,7 @@ public:
DbusMailBox(){}
~DbusMailBox(){}
Q_INVOKABLE int s_wifiConnect(QString ssid, QString passwd) override;
Q_INVOKABLE int s_wifiDisconnect() override;
Q_INVOKABLE int s_wifiScan() override;
};

View File

@ -13,9 +13,20 @@ PDBUS_MSG_PACK DBusOnMessage(uv_loop_t *pLoop, DBusConnection *pConn,PDBUS_MSG_P
return NULL;
}
LOG_EX(LOG_Debug, "Frame module get message: %s\r\n",pMsg->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);
}