Test serial console demonstrating various API functions of WiConnect library.

Dependencies:   WiConnect mbed

Committer:
dan_ackme
Date:
Wed Aug 13 04:42:11 2014 -0700
Revision:
12:3dd3a1be40c1
Parent:
7:b3cbb18422e4
updated copyright

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dan_ackme 12:3dd3a1be40c1 1 /**
dan_ackme 12:3dd3a1be40c1 2 * ACKme WiConnect Host Library is licensed under the BSD licence:
dan_ackme 12:3dd3a1be40c1 3 *
dan_ackme 12:3dd3a1be40c1 4 * Copyright (c)2014 ACKme Networks.
dan_ackme 12:3dd3a1be40c1 5 * All rights reserved.
dan_ackme 12:3dd3a1be40c1 6 *
dan_ackme 12:3dd3a1be40c1 7 * Redistribution and use in source and binary forms, with or without modification,
dan_ackme 12:3dd3a1be40c1 8 * are permitted provided that the following conditions are met:
dan_ackme 12:3dd3a1be40c1 9 *
dan_ackme 12:3dd3a1be40c1 10 * 1. Redistributions of source code must retain the above copyright notice,
dan_ackme 12:3dd3a1be40c1 11 * this list of conditions and the following disclaimer.
dan_ackme 12:3dd3a1be40c1 12 * 2. Redistributions in binary form must reproduce the above copyright notice,
dan_ackme 12:3dd3a1be40c1 13 * this list of conditions and the following disclaimer in the documentation
dan_ackme 12:3dd3a1be40c1 14 * and/or other materials provided with the distribution.
dan_ackme 12:3dd3a1be40c1 15 * 3. The name of the author may not be used to endorse or promote products
dan_ackme 12:3dd3a1be40c1 16 * derived from this software without specific prior written permission.
dan_ackme 12:3dd3a1be40c1 17 *
dan_ackme 12:3dd3a1be40c1 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR IMPLIED
dan_ackme 12:3dd3a1be40c1 19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
dan_ackme 12:3dd3a1be40c1 20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
dan_ackme 12:3dd3a1be40c1 21 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
dan_ackme 12:3dd3a1be40c1 22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
dan_ackme 12:3dd3a1be40c1 23 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
dan_ackme 12:3dd3a1be40c1 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
dan_ackme 12:3dd3a1be40c1 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
dan_ackme 12:3dd3a1be40c1 26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
dan_ackme 12:3dd3a1be40c1 27 * OF SUCH DAMAGE.
dan_ackme 0:836c9a6383e0 28 */
dan_ackme 0:836c9a6383e0 29
dan_ackme 0:836c9a6383e0 30 #include "tests/Tests.h"
dan_ackme 0:836c9a6383e0 31 #include "Wiconnect.h"
dan_ackme 0:836c9a6383e0 32
dan_ackme 0:836c9a6383e0 33
dan_ackme 0:836c9a6383e0 34
dan_ackme 0:836c9a6383e0 35 /*************************************************************************************************/
dan_ackme 0:836c9a6383e0 36 WiconnectResult networkStatsCommand(int argc, char **argv)
dan_ackme 0:836c9a6383e0 37 {
dan_ackme 0:836c9a6383e0 38 WiconnectResult result;
dan_ackme 0:836c9a6383e0 39 Wiconnect *wiconnect = Wiconnect::getInstance();
dan_ackme 0:836c9a6383e0 40 NetworkStatus status;
dan_ackme 0:836c9a6383e0 41 NetworkSignalStrength signal;
dan_ackme 0:836c9a6383e0 42 uint32_t ip, nm, gw;
dan_ackme 7:b3cbb18422e4 43 bool dhcpEnabled;
dan_ackme 0:836c9a6383e0 44
dan_ackme 0:836c9a6383e0 45 if(WICONNECT_FAILED(result, wiconnect->getIpSettings(&ip, &nm, &gw)))
dan_ackme 0:836c9a6383e0 46 {
dan_ackme 0:836c9a6383e0 47 LOG_INFO("Failed to get IP Settings");
dan_ackme 0:836c9a6383e0 48 }
dan_ackme 7:b3cbb18422e4 49 else if(WICONNECT_FAILED(result, wiconnect->getDhcpEnabled(&dhcpEnabled)))
dan_ackme 0:836c9a6383e0 50 {
dan_ackme 0:836c9a6383e0 51 LOG_INFO("Failed to get DHCP setting");
dan_ackme 0:836c9a6383e0 52 }
dan_ackme 0:836c9a6383e0 53 else if(WICONNECT_FAILED(result, wiconnect->getNetworkStatus(&status)))
dan_ackme 0:836c9a6383e0 54 {
dan_ackme 0:836c9a6383e0 55 LOG_INFO("Failed to get network status");
dan_ackme 0:836c9a6383e0 56 }
dan_ackme 0:836c9a6383e0 57 else if(WICONNECT_FAILED(result, wiconnect->getSignalStrength(&signal)))
dan_ackme 0:836c9a6383e0 58 {
dan_ackme 0:836c9a6383e0 59 LOG_INFO("Failed to get signal strength");
dan_ackme 0:836c9a6383e0 60 }
dan_ackme 0:836c9a6383e0 61 else
dan_ackme 0:836c9a6383e0 62 {
dan_ackme 0:836c9a6383e0 63 char ipStr[16], gwStr[16], nmStr[16];
dan_ackme 0:836c9a6383e0 64
dan_ackme 0:836c9a6383e0 65 LOG_INFO("\r\n------------------------\r\n"
dan_ackme 0:836c9a6383e0 66 "IP: %s\r\n"
dan_ackme 0:836c9a6383e0 67 "Netmask: %s\r\n"
dan_ackme 0:836c9a6383e0 68 "Gateway: %s\r\n"
dan_ackme 0:836c9a6383e0 69 "DHCP enabled: %s\r\n"
dan_ackme 0:836c9a6383e0 70 "Status: %s\r\n"
dan_ackme 0:836c9a6383e0 71 "Signal: %s\r\n"
dan_ackme 0:836c9a6383e0 72 "------------------------",
dan_ackme 0:836c9a6383e0 73 Wiconnect::ipToStr(ip, ipStr),
dan_ackme 0:836c9a6383e0 74 Wiconnect::ipToStr(nm, nmStr),
dan_ackme 0:836c9a6383e0 75 Wiconnect::ipToStr(gw, gwStr),
dan_ackme 0:836c9a6383e0 76 dhcpEnabled ? "true" : "false",
dan_ackme 0:836c9a6383e0 77 Wiconnect::networkStatusToStr(status),
dan_ackme 0:836c9a6383e0 78 Wiconnect::signalStrengthToStr(signal));
dan_ackme 0:836c9a6383e0 79
dan_ackme 0:836c9a6383e0 80 }
dan_ackme 0:836c9a6383e0 81
dan_ackme 0:836c9a6383e0 82 return result;
dan_ackme 0:836c9a6383e0 83 }
dan_ackme 0:836c9a6383e0 84
dan_ackme 0:836c9a6383e0 85 /*************************************************************************************************/
dan_ackme 0:836c9a6383e0 86 WiconnectResult networkPingCommand(int argc, char **argv)
dan_ackme 0:836c9a6383e0 87 {
dan_ackme 0:836c9a6383e0 88 WiconnectResult result;
dan_ackme 0:836c9a6383e0 89 Wiconnect *wiconnect = Wiconnect::getInstance();
dan_ackme 0:836c9a6383e0 90
dan_ackme 0:836c9a6383e0 91 uint32_t pingTimeMs;
dan_ackme 0:836c9a6383e0 92 const char *domain = (argc > 0) ? argv[0] : NULL;
dan_ackme 0:836c9a6383e0 93
dan_ackme 0:836c9a6383e0 94 if(!WICONNECT_FAILED(result, wiconnect->ping(domain, &pingTimeMs)))
dan_ackme 0:836c9a6383e0 95 {
dan_ackme 0:836c9a6383e0 96 LOG_INFO("Ping reply: %dms", pingTimeMs);
dan_ackme 0:836c9a6383e0 97 }
dan_ackme 0:836c9a6383e0 98 return result;
dan_ackme 0:836c9a6383e0 99 }
dan_ackme 0:836c9a6383e0 100
dan_ackme 0:836c9a6383e0 101 /*************************************************************************************************/
dan_ackme 0:836c9a6383e0 102 WiconnectResult networkLookupCommand(int argc, char **argv)
dan_ackme 0:836c9a6383e0 103 {
dan_ackme 0:836c9a6383e0 104 WiconnectResult result;
dan_ackme 0:836c9a6383e0 105 Wiconnect *wiconnect = Wiconnect::getInstance();
dan_ackme 0:836c9a6383e0 106
dan_ackme 0:836c9a6383e0 107 if(argc != 1)
dan_ackme 0:836c9a6383e0 108 {
dan_ackme 0:836c9a6383e0 109 return WICONNECT_BAD_ARG;
dan_ackme 0:836c9a6383e0 110 }
dan_ackme 0:836c9a6383e0 111
dan_ackme 0:836c9a6383e0 112 uint32_t ipAddress;
dan_ackme 0:836c9a6383e0 113
dan_ackme 0:836c9a6383e0 114 if(!WICONNECT_FAILED(result, wiconnect->lookup(argv[0], &ipAddress)))
dan_ackme 0:836c9a6383e0 115 {
dan_ackme 0:836c9a6383e0 116 IpStrBuffer buffer;
dan_ackme 0:836c9a6383e0 117 LOG_INFO("IP Address: %s", Wiconnect::ipToStr(ipAddress, buffer));
dan_ackme 0:836c9a6383e0 118 }
dan_ackme 0:836c9a6383e0 119 return result;
dan_ackme 0:836c9a6383e0 120 }