Test serial console demonstrating various API functions of WiConnect library.

Dependencies:   WiConnect mbed

Revision:
0:836c9a6383e0
Child:
1:5137ec8f4c45
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/blocking/network/ScanNetworkTest.cpp	Mon Aug 11 11:31:32 2014 +0000
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2014, ACKme Networks
+ * All Rights Reserved.
+ *
+ * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks;
+ * the contents of this file may not be disclosed to third parties, copied
+ * or duplicated in any form, in whole or in part, without the prior
+ * written permission of ACKme Networks.
+ */
+
+
+#include "tests/Tests.h"
+#include "Wiconnect.h"
+
+
+
+static void printScanResults(const ScanResultList &scanResultList);
+
+
+
+
+/*************************************************************************************************/
+WiconnectResult networkScanCommand(int argc, char **argv)
+{
+    WiconnectResult result = WICONNECT_BAD_ARG;
+    Wiconnect *wiconnect = Wiconnect::getInstance();
+    ScanResultList scanResultList;
+    uint8_t channelList[16];
+    const char* ssid = NULL;
+    uint8_t *channelListPtr = NULL;
+
+    if(argc > 0)
+    {
+        if(strcmp(argv[0], "all") != 0)
+        {
+            char *ch_tok;
+            char *chListPtr = argv[0];
+            uint8_t ch_count = 0;
+
+            while((ch_tok = strtok(chListPtr, ","))  != NULL)
+            {
+                intmax_t x;
+
+                if(!StringUtil::parseInt(ch_tok, &x, 1, 14))
+                {
+                    return WICONNECT_BAD_ARG;
+                }
+                channelList[ch_count++] = (uint8_t)x;
+                chListPtr = NULL;
+            }
+            channelList[ch_count] = 0;
+            channelListPtr = channelList;
+        }
+        --argc;
+        ++argv;
+    }
+
+    if(argc > 0)
+    {
+        ssid = argv[0];
+    }
+
+    if(!WICONNECT_FAILED(result, wiconnect->scan(scanResultList, channelListPtr, ssid)))
+    {
+        printScanResults(scanResultList);
+    }
+
+    return result;
+}
+
+
+
+/*************************************************************************************************/
+static void printScanResults(const ScanResultList &scanResultList)
+{
+    SsidStrBuffer ssidBuffer;
+    MacAddressStrBuffer macBuffer;
+    char rateBuffer[16];
+    int i = 1;
+
+    LOG_INFO("Scan result count: %d", scanResultList.getCount());
+    for(const ScanResult *res = scanResultList.getListHead(); res != NULL; res = res->getNext(), ++i)
+    {
+        LOG_INFO("------------------------\r\n"
+                "%d: %s\r\n"
+                 "\tChannel: %d\r\n"
+                 "\tSignal: %s\r\n"
+                 "\tSecurity: %s\r\n"
+                 "\tRate: %s\r\n"
+                 "\tBSSID: %s",
+                 i, Wiconnect::ssidToStr(res->getSsid(), ssidBuffer),
+                 res->getChannel(),
+                 Wiconnect::signalStrengthToStr(res->getSignalStrength()),
+                 Wiconnect::networkSecurityToStr(res->getSecurityType()),
+                 res->getRateStr(rateBuffer),
+                 Wiconnect::macAddressToStr(res->getMacAddress(), macBuffer));
+    }
+
+}
+