Test serial console demonstrating various API functions of WiConnect library.

Dependencies:   WiConnect mbed

Committer:
dan_ackme
Date:
Mon Aug 11 04:53:00 2014 -0700
Revision:
2:2f222449973a
Parent:
1:5137ec8f4c45
Child:
7:b3cbb18422e4
warning fixes

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 /*************************************************************************************************/
dan_ackme 0:836c9a6383e0 18 WiconnectResult networkStatsCommand(int argc, char **argv)
dan_ackme 0:836c9a6383e0 19 {
dan_ackme 0:836c9a6383e0 20 WiconnectResult result;
dan_ackme 0:836c9a6383e0 21 Wiconnect *wiconnect = Wiconnect::getInstance();
dan_ackme 0:836c9a6383e0 22 NetworkStatus status;
dan_ackme 0:836c9a6383e0 23 NetworkSignalStrength signal;
dan_ackme 0:836c9a6383e0 24 uint32_t ip, nm, gw;
dan_ackme 2:2f222449973a 25 bool dhcpEnabled = false;
dan_ackme 0:836c9a6383e0 26
dan_ackme 0:836c9a6383e0 27 if(WICONNECT_FAILED(result, wiconnect->getIpSettings(&ip, &nm, &gw)))
dan_ackme 0:836c9a6383e0 28 {
dan_ackme 0:836c9a6383e0 29 LOG_INFO("Failed to get IP Settings");
dan_ackme 0:836c9a6383e0 30 }
dan_ackme 0:836c9a6383e0 31 else if(WICONNECT_FAILED(result, wiconnect->setDhcpEnabled(&dhcpEnabled)))
dan_ackme 0:836c9a6383e0 32 {
dan_ackme 0:836c9a6383e0 33 LOG_INFO("Failed to get DHCP setting");
dan_ackme 0:836c9a6383e0 34 }
dan_ackme 0:836c9a6383e0 35 else if(WICONNECT_FAILED(result, wiconnect->getNetworkStatus(&status)))
dan_ackme 0:836c9a6383e0 36 {
dan_ackme 0:836c9a6383e0 37 LOG_INFO("Failed to get network status");
dan_ackme 0:836c9a6383e0 38 }
dan_ackme 0:836c9a6383e0 39 else if(WICONNECT_FAILED(result, wiconnect->getSignalStrength(&signal)))
dan_ackme 0:836c9a6383e0 40 {
dan_ackme 0:836c9a6383e0 41 LOG_INFO("Failed to get signal strength");
dan_ackme 0:836c9a6383e0 42 }
dan_ackme 0:836c9a6383e0 43 else
dan_ackme 0:836c9a6383e0 44 {
dan_ackme 0:836c9a6383e0 45 char ipStr[16], gwStr[16], nmStr[16];
dan_ackme 0:836c9a6383e0 46
dan_ackme 0:836c9a6383e0 47 LOG_INFO("\r\n------------------------\r\n"
dan_ackme 0:836c9a6383e0 48 "IP: %s\r\n"
dan_ackme 0:836c9a6383e0 49 "Netmask: %s\r\n"
dan_ackme 0:836c9a6383e0 50 "Gateway: %s\r\n"
dan_ackme 0:836c9a6383e0 51 "DHCP enabled: %s\r\n"
dan_ackme 0:836c9a6383e0 52 "Status: %s\r\n"
dan_ackme 0:836c9a6383e0 53 "Signal: %s\r\n"
dan_ackme 0:836c9a6383e0 54 "------------------------",
dan_ackme 0:836c9a6383e0 55 Wiconnect::ipToStr(ip, ipStr),
dan_ackme 0:836c9a6383e0 56 Wiconnect::ipToStr(nm, nmStr),
dan_ackme 0:836c9a6383e0 57 Wiconnect::ipToStr(gw, gwStr),
dan_ackme 0:836c9a6383e0 58 dhcpEnabled ? "true" : "false",
dan_ackme 0:836c9a6383e0 59 Wiconnect::networkStatusToStr(status),
dan_ackme 0:836c9a6383e0 60 Wiconnect::signalStrengthToStr(signal));
dan_ackme 0:836c9a6383e0 61
dan_ackme 0:836c9a6383e0 62 }
dan_ackme 0:836c9a6383e0 63
dan_ackme 0:836c9a6383e0 64 return result;
dan_ackme 0:836c9a6383e0 65 }
dan_ackme 0:836c9a6383e0 66
dan_ackme 0:836c9a6383e0 67 /*************************************************************************************************/
dan_ackme 0:836c9a6383e0 68 WiconnectResult networkPingCommand(int argc, char **argv)
dan_ackme 0:836c9a6383e0 69 {
dan_ackme 0:836c9a6383e0 70 WiconnectResult result;
dan_ackme 0:836c9a6383e0 71 Wiconnect *wiconnect = Wiconnect::getInstance();
dan_ackme 0:836c9a6383e0 72
dan_ackme 0:836c9a6383e0 73 uint32_t pingTimeMs;
dan_ackme 0:836c9a6383e0 74 const char *domain = (argc > 0) ? argv[0] : NULL;
dan_ackme 0:836c9a6383e0 75
dan_ackme 0:836c9a6383e0 76 if(!WICONNECT_FAILED(result, wiconnect->ping(domain, &pingTimeMs)))
dan_ackme 0:836c9a6383e0 77 {
dan_ackme 0:836c9a6383e0 78 LOG_INFO("Ping reply: %dms", pingTimeMs);
dan_ackme 0:836c9a6383e0 79 }
dan_ackme 0:836c9a6383e0 80 return result;
dan_ackme 0:836c9a6383e0 81 }
dan_ackme 0:836c9a6383e0 82
dan_ackme 0:836c9a6383e0 83 /*************************************************************************************************/
dan_ackme 0:836c9a6383e0 84 WiconnectResult networkLookupCommand(int argc, char **argv)
dan_ackme 0:836c9a6383e0 85 {
dan_ackme 0:836c9a6383e0 86 WiconnectResult result;
dan_ackme 0:836c9a6383e0 87 Wiconnect *wiconnect = Wiconnect::getInstance();
dan_ackme 0:836c9a6383e0 88
dan_ackme 0:836c9a6383e0 89 if(argc != 1)
dan_ackme 0:836c9a6383e0 90 {
dan_ackme 0:836c9a6383e0 91 return WICONNECT_BAD_ARG;
dan_ackme 0:836c9a6383e0 92 }
dan_ackme 0:836c9a6383e0 93
dan_ackme 0:836c9a6383e0 94 uint32_t ipAddress;
dan_ackme 0:836c9a6383e0 95
dan_ackme 0:836c9a6383e0 96 if(!WICONNECT_FAILED(result, wiconnect->lookup(argv[0], &ipAddress)))
dan_ackme 0:836c9a6383e0 97 {
dan_ackme 0:836c9a6383e0 98 IpStrBuffer buffer;
dan_ackme 0:836c9a6383e0 99 LOG_INFO("IP Address: %s", Wiconnect::ipToStr(ipAddress, buffer));
dan_ackme 0:836c9a6383e0 100 }
dan_ackme 0:836c9a6383e0 101 return result;
dan_ackme 0:836c9a6383e0 102 }