]> Git Repo - esp-hosted.git/commitdiff
minor improvement in test.c
authorYogesh Mantri <[email protected]>
Thu, 20 Jan 2022 10:56:25 +0000 (16:26 +0530)
committerYogesh Mantri <[email protected]>
Thu, 20 Jan 2022 11:03:55 +0000 (16:33 +0530)
host/linux/host_control/c_support/test.c

index fbd1c4b84ff1e1f967b616f1e424da271e4ef3c8..88c764eb910af0bb1098d423aad0055d69791f6f 100644 (file)
  */
 
 #include "test_api.h"
+#include <unistd.h>
+#include <sys/types.h>
 
 /***** Please Read *****/
 /* Before use test.c : User must enter user configuration parameter in "test_config.h" file */
+static void inline usage(char *argv[])
+{
+       printf("Usage: sudo %s [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s <Esp_binary_path>]\n",
+                       argv[0], SCAN, STA_CONNECT, STA_DISCONNECT, AP_START, AP_VENDOR_IE,
+                       STA_LIST, AP_STOP, WIFI_TX_POWER, OTA);
+       printf("For example: sudo %s %s %s %s %s %s %s %s %s %s <Esp_binary_path>\n",
+                       argv[0], SCAN, STA_CONNECT, STA_DISCONNECT, AP_START, AP_VENDOR_IE,
+                       STA_LIST, AP_STOP, WIFI_TX_POWER, OTA);
+}
 
 int main(int argc, char *argv[])
 {
-    /* Below APIs could be used by demo application */
+       /* Below APIs could be used by demo application */
+
+       int ret = SUCCESS;
 
        if(getuid()) {
                printf("Please re-run program with superuser access\n");
-               return FAILURE;
+               usage(argv);
+               exit(-1);
        }
 
-    int ret = control_path_platform_init();
-    if (ret != SUCCESS) {
-        printf("EXIT!!!!\n");
-        exit(0);
-    }
+       ret = control_path_platform_init();
+       if (ret != SUCCESS) {
+               printf("Failed to read serial driver file\n");
+               exit(0);
+       }
 
-    if (argc == 1) {
-        printf("Usage: %s [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] \n", argv[0],
-        STA_CONNECT, STA_DISCONNECT, AP_START, AP_STOP,
-        SCAN, STA_LIST, OTA, AP_VENDOR_IE, WIFI_TX_POWER);
-               return -1;
-    }
+       if (argc == 1) {
+               usage(argv);
+               exit(-1);
+       }
 
-    for (int i=1; i<argc; i++) {
-        if (0 == strncasecmp(STA_CONNECT, argv[i], sizeof(STA_CONNECT)))
-            test_station_mode_connect();
-        else if (0 == strncasecmp(STA_DISCONNECT, argv[i], sizeof(STA_DISCONNECT)))
-            test_station_mode_disconnect();
-        else if (0 == strncasecmp(AP_START, argv[i], sizeof(AP_START)))
-            test_softap_mode_start();
-        else if (0 == strncasecmp(AP_STOP, argv[i], sizeof(AP_STOP)))
-            test_softap_mode_stop();
-        else if (0 == strncasecmp(SCAN, argv[i], sizeof(SCAN)))
-            test_get_available_wifi();
-        else if (0 == strncasecmp(STA_LIST, argv[i], sizeof(STA_LIST)))
-            test_softap_mode_connected_clients_info();
-        else if (0 == strncasecmp(OTA, argv[i], sizeof(OTA)))
-            test_ota(argv[i+1]);
-        else if (0 == strncasecmp(WIFI_TX_POWER, argv[i], sizeof(WIFI_TX_POWER))) {
-            test_wifi_set_max_tx_power();
-            test_wifi_get_curr_tx_power();
-        }
-        else if (0 == strncasecmp(AP_VENDOR_IE, argv[i], sizeof(AP_VENDOR_IE)))
-            test_set_vendor_specific_ie();
-        else if ((0 == strncasecmp("--help", argv[i], sizeof("--help"))) ||
-                 (0 == strncasecmp("-h", argv[i], sizeof("-h")))) {
-            printf("Usage: %s [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] [%s] \n", argv[0],
-                STA_CONNECT, STA_DISCONNECT, AP_START, AP_STOP, SCAN, STA_LIST,
-                OTA, AP_VENDOR_IE, WIFI_TX_POWER);
+       for (int i=1; i<argc; i++) {
+               if (0 == strncasecmp(STA_CONNECT, argv[i], sizeof(STA_CONNECT)))
+                       test_station_mode_connect();
+               else if (0 == strncasecmp(STA_DISCONNECT, argv[i], sizeof(STA_DISCONNECT)))
+                       test_station_mode_disconnect();
+               else if (0 == strncasecmp(AP_START, argv[i], sizeof(AP_START)))
+                       test_softap_mode_start();
+               else if (0 == strncasecmp(AP_STOP, argv[i], sizeof(AP_STOP)))
+                       test_softap_mode_stop();
+               else if (0 == strncasecmp(SCAN, argv[i], sizeof(SCAN)))
+                       test_get_available_wifi();
+               else if (0 == strncasecmp(STA_LIST, argv[i], sizeof(STA_LIST)))
+                       test_softap_mode_connected_clients_info();
+               else if (0 == strncasecmp(OTA, argv[i], sizeof(OTA)))
+                       test_ota(argv[i+1]);
+               else if (0 == strncasecmp(WIFI_TX_POWER, argv[i], sizeof(WIFI_TX_POWER))) {
+                       test_wifi_set_max_tx_power();
+                       test_wifi_get_curr_tx_power();
+               }
+               else if (0 == strncasecmp(AP_VENDOR_IE, argv[i], sizeof(AP_VENDOR_IE)))
+                       test_set_vendor_specific_ie();
+               else if ((0 == strncasecmp("--help", argv[i], sizeof("--help"))) ||
+                               (0 == strncasecmp("-h", argv[i], sizeof("-h")))) {
+                       usage(argv);
                        return(0);
-        }
-    }
+               }
+       }
 
-    return 0;
+       return 0;
 }
This page took 0.030558 seconds and 4 git commands to generate.