Test serial console demonstrating various API functions of WiConnect library.

Dependencies:   WiConnect mbed

Committer:
dan_ackme
Date:
Mon Aug 11 13:55:39 2014 -0700
Revision:
3:dddd476d5967
Parent:
1:5137ec8f4c45
Child:
12:3dd3a1be40c1
use static buffers instead of malloc since default heap is so small

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dan_ackme 0:836c9a6383e0 1 /*
dan_ackme 0:836c9a6383e0 2 * Copyright 2014, ACKme Networks
dan_ackme 0:836c9a6383e0 3 * All Rights Reserved.
dan_ackme 0:836c9a6383e0 4 *
dan_ackme 0:836c9a6383e0 5 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks;
dan_ackme 0:836c9a6383e0 6 * the contents of this file may not be disclosed to third parties, copied
dan_ackme 0:836c9a6383e0 7 * or duplicated in any form, in whole or in part, without the prior
dan_ackme 0:836c9a6383e0 8 * written permission of ACKme Networks.
dan_ackme 0:836c9a6383e0 9 */
dan_ackme 0:836c9a6383e0 10
dan_ackme 0:836c9a6383e0 11
dan_ackme 0:836c9a6383e0 12 #include "tests/Tests.h"
dan_ackme 0:836c9a6383e0 13 #include "Wiconnect.h"
dan_ackme 0:836c9a6383e0 14
dan_ackme 0:836c9a6383e0 15
dan_ackme 0:836c9a6383e0 16
dan_ackme 0:836c9a6383e0 17 static void printScanResults(const ScanResultList &scanResultList);
dan_ackme 0:836c9a6383e0 18
dan_ackme 0:836c9a6383e0 19
dan_ackme 0:836c9a6383e0 20
dan_ackme 0:836c9a6383e0 21
dan_ackme 0:836c9a6383e0 22 /*************************************************************************************************/
dan_ackme 0:836c9a6383e0 23 WiconnectResult networkScanCommand(int argc, char **argv)
dan_ackme 0:836c9a6383e0 24 {
dan_ackme 0:836c9a6383e0 25 WiconnectResult result = WICONNECT_BAD_ARG;
dan_ackme 0:836c9a6383e0 26 Wiconnect *wiconnect = Wiconnect::getInstance();
dan_ackme 3:dddd476d5967 27 ScanResultList scanResultList(TEST_BUFFER_LENGTH, TEST_BUFFER);
dan_ackme 0:836c9a6383e0 28 uint8_t channelList[16];
dan_ackme 0:836c9a6383e0 29 const char* ssid = NULL;
dan_ackme 0:836c9a6383e0 30 uint8_t *channelListPtr = NULL;
dan_ackme 0:836c9a6383e0 31
dan_ackme 0:836c9a6383e0 32 if(argc > 0)
dan_ackme 0:836c9a6383e0 33 {
dan_ackme 0:836c9a6383e0 34 if(strcmp(argv[0], "all") != 0)
dan_ackme 0:836c9a6383e0 35 {
dan_ackme 0:836c9a6383e0 36 char *ch_tok;
dan_ackme 0:836c9a6383e0 37 char *chListPtr = argv[0];
dan_ackme 0:836c9a6383e0 38 uint8_t ch_count = 0;
dan_ackme 0:836c9a6383e0 39
dan_ackme 0:836c9a6383e0 40 while((ch_tok = strtok(chListPtr, ",")) != NULL)
dan_ackme 0:836c9a6383e0 41 {
dan_ackme 0:836c9a6383e0 42 intmax_t x;
dan_ackme 0:836c9a6383e0 43
dan_ackme 0:836c9a6383e0 44 if(!StringUtil::parseInt(ch_tok, &x, 1, 14))
dan_ackme 0:836c9a6383e0 45 {
dan_ackme 0:836c9a6383e0 46 return WICONNECT_BAD_ARG;
dan_ackme 0:836c9a6383e0 47 }
dan_ackme 0:836c9a6383e0 48 channelList[ch_count++] = (uint8_t)x;
dan_ackme 0:836c9a6383e0 49 chListPtr = NULL;
dan_ackme 0:836c9a6383e0 50 }
dan_ackme 0:836c9a6383e0 51 channelList[ch_count] = 0;
dan_ackme 0:836c9a6383e0 52 channelListPtr = channelList;
dan_ackme 0:836c9a6383e0 53 }
dan_ackme 0:836c9a6383e0 54 --argc;
dan_ackme 0:836c9a6383e0 55 ++argv;
dan_ackme 0:836c9a6383e0 56 }
dan_ackme 0:836c9a6383e0 57
dan_ackme 0:836c9a6383e0 58 if(argc > 0)
dan_ackme 0:836c9a6383e0 59 {
dan_ackme 0:836c9a6383e0 60 ssid = argv[0];
dan_ackme 0:836c9a6383e0 61 }
dan_ackme 0:836c9a6383e0 62
dan_ackme 0:836c9a6383e0 63 if(!WICONNECT_FAILED(result, wiconnect->scan(scanResultList, channelListPtr, ssid)))
dan_ackme 0:836c9a6383e0 64 {
dan_ackme 0:836c9a6383e0 65 printScanResults(scanResultList);
dan_ackme 0:836c9a6383e0 66 }
dan_ackme 0:836c9a6383e0 67
dan_ackme 0:836c9a6383e0 68 return result;
dan_ackme 0:836c9a6383e0 69 }
dan_ackme 0:836c9a6383e0 70
dan_ackme 0:836c9a6383e0 71
dan_ackme 0:836c9a6383e0 72
dan_ackme 0:836c9a6383e0 73 /*************************************************************************************************/
dan_ackme 0:836c9a6383e0 74 static void printScanResults(const ScanResultList &scanResultList)
dan_ackme 0:836c9a6383e0 75 {
dan_ackme 0:836c9a6383e0 76 SsidStrBuffer ssidBuffer;
dan_ackme 0:836c9a6383e0 77 MacAddressStrBuffer macBuffer;
dan_ackme 0:836c9a6383e0 78 char rateBuffer[16];
dan_ackme 0:836c9a6383e0 79 int i = 1;
dan_ackme 0:836c9a6383e0 80
dan_ackme 0:836c9a6383e0 81 LOG_INFO("Scan result count: %d", scanResultList.getCount());
dan_ackme 0:836c9a6383e0 82 for(const ScanResult *res = scanResultList.getListHead(); res != NULL; res = res->getNext(), ++i)
dan_ackme 0:836c9a6383e0 83 {
dan_ackme 0:836c9a6383e0 84 LOG_INFO("------------------------\r\n"
dan_ackme 0:836c9a6383e0 85 "%d: %s\r\n"
dan_ackme 0:836c9a6383e0 86 "\tChannel: %d\r\n"
dan_ackme 0:836c9a6383e0 87 "\tSignal: %s\r\n"
dan_ackme 0:836c9a6383e0 88 "\tSecurity: %s\r\n"
dan_ackme 0:836c9a6383e0 89 "\tRate: %s\r\n"
dan_ackme 0:836c9a6383e0 90 "\tBSSID: %s",
dan_ackme 0:836c9a6383e0 91 i, Wiconnect::ssidToStr(res->getSsid(), ssidBuffer),
dan_ackme 0:836c9a6383e0 92 res->getChannel(),
dan_ackme 0:836c9a6383e0 93 Wiconnect::signalStrengthToStr(res->getSignalStrength()),
dan_ackme 0:836c9a6383e0 94 Wiconnect::networkSecurityToStr(res->getSecurityType()),
dan_ackme 0:836c9a6383e0 95 res->getRateStr(rateBuffer),
dan_ackme 0:836c9a6383e0 96 Wiconnect::macAddressToStr(res->getMacAddress(), macBuffer));
dan_ackme 0:836c9a6383e0 97 }
dan_ackme 0:836c9a6383e0 98
dan_ackme 0:836c9a6383e0 99 }