![](/media/cache/profiles/c355b4406b42f9ae5b0199a6e111e85a.jpg.50x50_q85.jpg)
Wifi Pressure Sensor
Dependencies: HTTPClient MPL3115A2 NTPClient TMP102 USBDevice cc3000_hostdriver_mbedsocket mbed
main.cpp@0:0bce3a738bcb, 2013-11-04 (annotated)
- Committer:
- SolderSplashLabs
- Date:
- Mon Nov 04 19:55:00 2013 +0000
- Revision:
- 0:0bce3a738bcb
- Child:
- 2:8f5776c287c5
Test Project, USB CDC and CC3000 Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SolderSplashLabs | 0:0bce3a738bcb | 1 | |
SolderSplashLabs | 0:0bce3a738bcb | 2 | #include "mbed.h" |
SolderSplashLabs | 0:0bce3a738bcb | 3 | #include "cc3000.h" |
SolderSplashLabs | 0:0bce3a738bcb | 4 | #include "wifi.h" |
SolderSplashLabs | 0:0bce3a738bcb | 5 | #include "UDPSocket.h" |
SolderSplashLabs | 0:0bce3a738bcb | 6 | #include "tcpTests.h" |
SolderSplashLabs | 0:0bce3a738bcb | 7 | #include "main.h" |
SolderSplashLabs | 0:0bce3a738bcb | 8 | #include "USBSerial.h" |
SolderSplashLabs | 0:0bce3a738bcb | 9 | #include "NTPClient.h" |
SolderSplashLabs | 0:0bce3a738bcb | 10 | #include <time.h> |
SolderSplashLabs | 0:0bce3a738bcb | 11 | |
SolderSplashLabs | 0:0bce3a738bcb | 12 | using namespace mbed_cc3000; |
SolderSplashLabs | 0:0bce3a738bcb | 13 | |
SolderSplashLabs | 0:0bce3a738bcb | 14 | /* cc3000 module declaration specific for user's board. Check also init() */ |
SolderSplashLabs | 0:0bce3a738bcb | 15 | #if (MY_BOARD == WIGO) |
SolderSplashLabs | 0:0bce3a738bcb | 16 | cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), PORTA_IRQn); |
SolderSplashLabs | 0:0bce3a738bcb | 17 | #elif (MY_BOARD == WIFI_DIPCORTEX) |
SolderSplashLabs | 0:0bce3a738bcb | 18 | cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37), PIN_INT0_IRQn); |
SolderSplashLabs | 0:0bce3a738bcb | 19 | Serial uart(p19, p20); |
SolderSplashLabs | 0:0bce3a738bcb | 20 | USBSerial pc; // USB CDC serial port |
SolderSplashLabs | 0:0bce3a738bcb | 21 | #else |
SolderSplashLabs | 0:0bce3a738bcb | 22 | |
SolderSplashLabs | 0:0bce3a738bcb | 23 | #endif |
SolderSplashLabs | 0:0bce3a738bcb | 24 | |
SolderSplashLabs | 0:0bce3a738bcb | 25 | #ifndef CC3000_UNENCRYPTED_SMART_CONFIG |
SolderSplashLabs | 0:0bce3a738bcb | 26 | const uint8_t smartconfigkey[] = {0x73,0x6d,0x61,0x72,0x74,0x63,0x6f,0x6e,0x66,0x69,0x67,0x41,0x45,0x53,0x31,0x36}; |
SolderSplashLabs | 0:0bce3a738bcb | 27 | #else |
SolderSplashLabs | 0:0bce3a738bcb | 28 | const uint8_t smartconfigkey = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 29 | #endif |
SolderSplashLabs | 0:0bce3a738bcb | 30 | |
SolderSplashLabs | 0:0bce3a738bcb | 31 | const int ECHO_SERVER_PORT_UDP = 81; |
SolderSplashLabs | 0:0bce3a738bcb | 32 | uint8_t *HostToPing = (uint8_t *)"google.com"; |
SolderSplashLabs | 0:0bce3a738bcb | 33 | tNetappIpconfigRetArgs ipinfo; |
SolderSplashLabs | 0:0bce3a738bcb | 34 | extern char tmpBuffer[512]; |
SolderSplashLabs | 0:0bce3a738bcb | 35 | |
SolderSplashLabs | 0:0bce3a738bcb | 36 | MENU_LEVEL currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 37 | |
SolderSplashLabs | 0:0bce3a738bcb | 38 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 39 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 40 | @brief Resolve a hostname and ping it |
SolderSplashLabs | 0:0bce3a738bcb | 41 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 42 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 43 | void PingTest ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 44 | { |
SolderSplashLabs | 0:0bce3a738bcb | 45 | uint32_t ip; |
SolderSplashLabs | 0:0bce3a738bcb | 46 | int32_t resolveRetCode = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 47 | |
SolderSplashLabs | 0:0bce3a738bcb | 48 | pc.printf("Get an IP address for %s\r\n",HostToPing); |
SolderSplashLabs | 0:0bce3a738bcb | 49 | resolveRetCode = wifi._socket.gethostbyname(HostToPing,strlen((const char *)HostToPing), &ip); |
SolderSplashLabs | 0:0bce3a738bcb | 50 | pc.printf("gethostbyname Returned code : %i \r\n", resolveRetCode); |
SolderSplashLabs | 0:0bce3a738bcb | 51 | |
SolderSplashLabs | 0:0bce3a738bcb | 52 | if (resolveRetCode > -1) |
SolderSplashLabs | 0:0bce3a738bcb | 53 | { |
SolderSplashLabs | 0:0bce3a738bcb | 54 | uint8_t add0 = (ip >> 24); |
SolderSplashLabs | 0:0bce3a738bcb | 55 | uint8_t add1 = (ip >> 16); |
SolderSplashLabs | 0:0bce3a738bcb | 56 | uint8_t add2 = (ip >> 8); |
SolderSplashLabs | 0:0bce3a738bcb | 57 | uint8_t add3 = (ip >> 0); |
SolderSplashLabs | 0:0bce3a738bcb | 58 | pc.printf("IP address of %s: %d.%d.%d.%d \r\n", HostToPing, add0, add1, add2, add3); |
SolderSplashLabs | 0:0bce3a738bcb | 59 | |
SolderSplashLabs | 0:0bce3a738bcb | 60 | pc.printf("Sending ping\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 61 | uint32_t reply_count = wifi.ping(ip, 5, 500, 32); |
SolderSplashLabs | 0:0bce3a738bcb | 62 | pc.printf("Received %d replies\r\n", reply_count); |
SolderSplashLabs | 0:0bce3a738bcb | 63 | pc.printf("Ping complete.\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 64 | } |
SolderSplashLabs | 0:0bce3a738bcb | 65 | else |
SolderSplashLabs | 0:0bce3a738bcb | 66 | { |
SolderSplashLabs | 0:0bce3a738bcb | 67 | pc.printf("Failed to resolve\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 68 | } |
SolderSplashLabs | 0:0bce3a738bcb | 69 | } |
SolderSplashLabs | 0:0bce3a738bcb | 70 | |
SolderSplashLabs | 0:0bce3a738bcb | 71 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 72 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 73 | @brief Test the NTP library |
SolderSplashLabs | 0:0bce3a738bcb | 74 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 75 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 76 | void NtpTest ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 77 | { |
SolderSplashLabs | 0:0bce3a738bcb | 78 | NTPClient ntp; |
SolderSplashLabs | 0:0bce3a738bcb | 79 | struct tm *currentTime; |
SolderSplashLabs | 0:0bce3a738bcb | 80 | if (ntp.setTime("0.pool.ntp.org",123,10000) == 0) |
SolderSplashLabs | 0:0bce3a738bcb | 81 | { |
SolderSplashLabs | 0:0bce3a738bcb | 82 | pc.printf("\r\nGot the time successfully\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 83 | currentTime = localtime(&ntp.NTPLastResult); |
SolderSplashLabs | 0:0bce3a738bcb | 84 | pc.printf("NTP Response : %s\r\n", asctime(currentTime)); |
SolderSplashLabs | 0:0bce3a738bcb | 85 | } |
SolderSplashLabs | 0:0bce3a738bcb | 86 | else |
SolderSplashLabs | 0:0bce3a738bcb | 87 | { |
SolderSplashLabs | 0:0bce3a738bcb | 88 | pc.printf("NTP Update Failed\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 89 | } |
SolderSplashLabs | 0:0bce3a738bcb | 90 | } |
SolderSplashLabs | 0:0bce3a738bcb | 91 | |
SolderSplashLabs | 0:0bce3a738bcb | 92 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 93 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 94 | @brief Send a UDP Packet, wait for response |
SolderSplashLabs | 0:0bce3a738bcb | 95 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 96 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 97 | void UdpClientTest ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 98 | { |
SolderSplashLabs | 0:0bce3a738bcb | 99 | UDPSocket socket; |
SolderSplashLabs | 0:0bce3a738bcb | 100 | int n = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 101 | Endpoint outEndpoint; |
SolderSplashLabs | 0:0bce3a738bcb | 102 | Endpoint inEndpoint; |
SolderSplashLabs | 0:0bce3a738bcb | 103 | |
SolderSplashLabs | 0:0bce3a738bcb | 104 | if (0 == socket.bind(ECHO_SERVER_PORT_UDP) ) |
SolderSplashLabs | 0:0bce3a738bcb | 105 | { |
SolderSplashLabs | 0:0bce3a738bcb | 106 | |
SolderSplashLabs | 0:0bce3a738bcb | 107 | // 2 second timeout |
SolderSplashLabs | 0:0bce3a738bcb | 108 | socket.set_blocking(false, 2000); |
SolderSplashLabs | 0:0bce3a738bcb | 109 | |
SolderSplashLabs | 0:0bce3a738bcb | 110 | pc.printf("\r\n!! Press any key to stop !!\r\n\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 111 | |
SolderSplashLabs | 0:0bce3a738bcb | 112 | while (1) |
SolderSplashLabs | 0:0bce3a738bcb | 113 | { |
SolderSplashLabs | 0:0bce3a738bcb | 114 | if( outEndpoint.set_address(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT_UDP) < 0 ) |
SolderSplashLabs | 0:0bce3a738bcb | 115 | { |
SolderSplashLabs | 0:0bce3a738bcb | 116 | pc.printf("Failed to set endpoint address.\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 117 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 118 | } |
SolderSplashLabs | 0:0bce3a738bcb | 119 | else |
SolderSplashLabs | 0:0bce3a738bcb | 120 | { |
SolderSplashLabs | 0:0bce3a738bcb | 121 | if ( socket.sendTo( outEndpoint, hello, sizeof(hello) ) < 0 ) |
SolderSplashLabs | 0:0bce3a738bcb | 122 | { |
SolderSplashLabs | 0:0bce3a738bcb | 123 | pc.printf("Failed to send the packet.\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 124 | } |
SolderSplashLabs | 0:0bce3a738bcb | 125 | else |
SolderSplashLabs | 0:0bce3a738bcb | 126 | { |
SolderSplashLabs | 0:0bce3a738bcb | 127 | // Message sent, recv reply |
SolderSplashLabs | 0:0bce3a738bcb | 128 | pc.printf("UDP Socket Sent : %s \r\n", hello); |
SolderSplashLabs | 0:0bce3a738bcb | 129 | n = socket.receiveFrom( inEndpoint, tmpBuffer, sizeof(tmpBuffer) ); |
SolderSplashLabs | 0:0bce3a738bcb | 130 | if ( n < 0 ) |
SolderSplashLabs | 0:0bce3a738bcb | 131 | { |
SolderSplashLabs | 0:0bce3a738bcb | 132 | pc.printf("Failed to recv the UDP packet.\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 133 | } |
SolderSplashLabs | 0:0bce3a738bcb | 134 | else |
SolderSplashLabs | 0:0bce3a738bcb | 135 | { |
SolderSplashLabs | 0:0bce3a738bcb | 136 | tmpBuffer[n] = '\0'; |
SolderSplashLabs | 0:0bce3a738bcb | 137 | pc.printf("UDP Socket Recv'd : %s \r\n", tmpBuffer); |
SolderSplashLabs | 0:0bce3a738bcb | 138 | } |
SolderSplashLabs | 0:0bce3a738bcb | 139 | } |
SolderSplashLabs | 0:0bce3a738bcb | 140 | } |
SolderSplashLabs | 0:0bce3a738bcb | 141 | |
SolderSplashLabs | 0:0bce3a738bcb | 142 | // Should we stop? |
SolderSplashLabs | 0:0bce3a738bcb | 143 | if ( pc.readable() ) |
SolderSplashLabs | 0:0bce3a738bcb | 144 | { |
SolderSplashLabs | 0:0bce3a738bcb | 145 | pc.getc(); |
SolderSplashLabs | 0:0bce3a738bcb | 146 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 147 | } |
SolderSplashLabs | 0:0bce3a738bcb | 148 | } |
SolderSplashLabs | 0:0bce3a738bcb | 149 | |
SolderSplashLabs | 0:0bce3a738bcb | 150 | if ( wifi.is_connected() ) |
SolderSplashLabs | 0:0bce3a738bcb | 151 | { |
SolderSplashLabs | 0:0bce3a738bcb | 152 | socket.close(); |
SolderSplashLabs | 0:0bce3a738bcb | 153 | } |
SolderSplashLabs | 0:0bce3a738bcb | 154 | } |
SolderSplashLabs | 0:0bce3a738bcb | 155 | else |
SolderSplashLabs | 0:0bce3a738bcb | 156 | { |
SolderSplashLabs | 0:0bce3a738bcb | 157 | // Failed to bind to the socket |
SolderSplashLabs | 0:0bce3a738bcb | 158 | } |
SolderSplashLabs | 0:0bce3a738bcb | 159 | } |
SolderSplashLabs | 0:0bce3a738bcb | 160 | |
SolderSplashLabs | 0:0bce3a738bcb | 161 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 162 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 163 | @brief Listen on a UDP port for messages |
SolderSplashLabs | 0:0bce3a738bcb | 164 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 165 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 166 | void UdpServerTest ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 167 | { |
SolderSplashLabs | 0:0bce3a738bcb | 168 | UDPSocket socket; |
SolderSplashLabs | 0:0bce3a738bcb | 169 | Endpoint client; |
SolderSplashLabs | 0:0bce3a738bcb | 170 | int n = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 171 | |
SolderSplashLabs | 0:0bce3a738bcb | 172 | if (0 == socket.bind(ECHO_SERVER_PORT_UDP) ) |
SolderSplashLabs | 0:0bce3a738bcb | 173 | { |
SolderSplashLabs | 0:0bce3a738bcb | 174 | pc.printf("\r\n!! Press any key to stop listening !!\r\n\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 175 | |
SolderSplashLabs | 0:0bce3a738bcb | 176 | while (true) |
SolderSplashLabs | 0:0bce3a738bcb | 177 | { |
SolderSplashLabs | 0:0bce3a738bcb | 178 | pc.printf("Waiting for packet...\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 179 | n = socket.receiveFrom(client, tmpBuffer, sizeof(tmpBuffer)); |
SolderSplashLabs | 0:0bce3a738bcb | 180 | |
SolderSplashLabs | 0:0bce3a738bcb | 181 | pc.printf("Received packet from: %s\n", client.get_address()); |
SolderSplashLabs | 0:0bce3a738bcb | 182 | socket.sendTo(client, tmpBuffer, n); |
SolderSplashLabs | 0:0bce3a738bcb | 183 | |
SolderSplashLabs | 0:0bce3a738bcb | 184 | // Should we stop? |
SolderSplashLabs | 0:0bce3a738bcb | 185 | if ( pc.readable() ) |
SolderSplashLabs | 0:0bce3a738bcb | 186 | { |
SolderSplashLabs | 0:0bce3a738bcb | 187 | pc.getc(); |
SolderSplashLabs | 0:0bce3a738bcb | 188 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 189 | } |
SolderSplashLabs | 0:0bce3a738bcb | 190 | } |
SolderSplashLabs | 0:0bce3a738bcb | 191 | } |
SolderSplashLabs | 0:0bce3a738bcb | 192 | } |
SolderSplashLabs | 0:0bce3a738bcb | 193 | |
SolderSplashLabs | 0:0bce3a738bcb | 194 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 195 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 196 | @brief Print menu header |
SolderSplashLabs | 0:0bce3a738bcb | 197 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 198 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 199 | void Menu_PrintHeader ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 200 | { |
SolderSplashLabs | 0:0bce3a738bcb | 201 | if (( wifi.is_enabled() ) && ( wifi.is_dhcp_configured() )) |
SolderSplashLabs | 0:0bce3a738bcb | 202 | { |
SolderSplashLabs | 0:0bce3a738bcb | 203 | wifi.get_ip_config(&ipinfo); |
SolderSplashLabs | 0:0bce3a738bcb | 204 | } |
SolderSplashLabs | 0:0bce3a738bcb | 205 | |
SolderSplashLabs | 0:0bce3a738bcb | 206 | pc.printf("\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 207 | pc.printf("+-------------------------------------------+\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 208 | pc.printf("| WiFi DipCortex / CC3000 Kitchen Sink |\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 209 | pc.printf("+-------------------------------------------+\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 210 | if (! wifi.is_enabled() ) |
SolderSplashLabs | 0:0bce3a738bcb | 211 | { |
SolderSplashLabs | 0:0bce3a738bcb | 212 | pc.printf("| CC3000 Disabled |\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 213 | } |
SolderSplashLabs | 0:0bce3a738bcb | 214 | else if ( wifi.is_dhcp_configured() ) |
SolderSplashLabs | 0:0bce3a738bcb | 215 | { |
SolderSplashLabs | 0:0bce3a738bcb | 216 | pc.printf("| SSID : %-33s|\r\n", ipinfo.uaSSID); |
SolderSplashLabs | 0:0bce3a738bcb | 217 | pc.printf("| IP : %-35s|\r\n", wifi.getIPAddress()); |
SolderSplashLabs | 0:0bce3a738bcb | 218 | } |
SolderSplashLabs | 0:0bce3a738bcb | 219 | else if ( wifi.is_connected() ) |
SolderSplashLabs | 0:0bce3a738bcb | 220 | { |
SolderSplashLabs | 0:0bce3a738bcb | 221 | pc.printf("| Connecting, waiting for DHCP |\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 222 | } |
SolderSplashLabs | 0:0bce3a738bcb | 223 | else |
SolderSplashLabs | 0:0bce3a738bcb | 224 | { |
SolderSplashLabs | 0:0bce3a738bcb | 225 | pc.printf("| Not Connected |\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 226 | } |
SolderSplashLabs | 0:0bce3a738bcb | 227 | pc.printf("+-------------------------------------------+\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 228 | pc.printf("\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 229 | } |
SolderSplashLabs | 0:0bce3a738bcb | 230 | |
SolderSplashLabs | 0:0bce3a738bcb | 231 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 232 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 233 | @brief Control the wifi connection |
SolderSplashLabs | 0:0bce3a738bcb | 234 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 235 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 236 | char WaitForSerialCommand ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 237 | { |
SolderSplashLabs | 0:0bce3a738bcb | 238 | char charIn = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 239 | char prevCharIn; |
SolderSplashLabs | 0:0bce3a738bcb | 240 | |
SolderSplashLabs | 0:0bce3a738bcb | 241 | pc.printf("Enter command character : "); |
SolderSplashLabs | 0:0bce3a738bcb | 242 | |
SolderSplashLabs | 0:0bce3a738bcb | 243 | while (1) |
SolderSplashLabs | 0:0bce3a738bcb | 244 | { |
SolderSplashLabs | 0:0bce3a738bcb | 245 | prevCharIn = charIn; |
SolderSplashLabs | 0:0bce3a738bcb | 246 | charIn = pc.getc(); |
SolderSplashLabs | 0:0bce3a738bcb | 247 | |
SolderSplashLabs | 0:0bce3a738bcb | 248 | pc.printf("%c", charIn); |
SolderSplashLabs | 0:0bce3a738bcb | 249 | if ((charIn == '\n') || (charIn == '\r')) |
SolderSplashLabs | 0:0bce3a738bcb | 250 | { |
SolderSplashLabs | 0:0bce3a738bcb | 251 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 252 | } |
SolderSplashLabs | 0:0bce3a738bcb | 253 | } |
SolderSplashLabs | 0:0bce3a738bcb | 254 | |
SolderSplashLabs | 0:0bce3a738bcb | 255 | return ( prevCharIn ); |
SolderSplashLabs | 0:0bce3a738bcb | 256 | } |
SolderSplashLabs | 0:0bce3a738bcb | 257 | |
SolderSplashLabs | 0:0bce3a738bcb | 258 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 259 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 260 | @brief Configure the module for smart connect mode allow configuration over the air |
SolderSplashLabs | 0:0bce3a738bcb | 261 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 262 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 263 | void SmartConfig ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 264 | { |
SolderSplashLabs | 0:0bce3a738bcb | 265 | // We dont want to auto reconnect to an access point |
SolderSplashLabs | 0:0bce3a738bcb | 266 | wifi._wlan.ioctl_set_connection_policy(0, 0, 0); |
SolderSplashLabs | 0:0bce3a738bcb | 267 | |
SolderSplashLabs | 0:0bce3a738bcb | 268 | // start smart config will disconnect, set the prefix |
SolderSplashLabs | 0:0bce3a738bcb | 269 | // wait for a message via a SmartConfig app, store it to the profile list |
SolderSplashLabs | 0:0bce3a738bcb | 270 | // finally it will reenable auto connection, triggering the module to connect to the new access point |
SolderSplashLabs | 0:0bce3a738bcb | 271 | wifi.start_smart_config(0); |
SolderSplashLabs | 0:0bce3a738bcb | 272 | } |
SolderSplashLabs | 0:0bce3a738bcb | 273 | |
SolderSplashLabs | 0:0bce3a738bcb | 274 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 275 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 276 | @brief Print cc3000 information |
SolderSplashLabs | 0:0bce3a738bcb | 277 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 278 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 279 | void print_cc3000_info() { |
SolderSplashLabs | 0:0bce3a738bcb | 280 | uint8_t myMAC[8]; |
SolderSplashLabs | 0:0bce3a738bcb | 281 | uint8_t buffer[2]; |
SolderSplashLabs | 0:0bce3a738bcb | 282 | int32_t status = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 283 | tNetappIpconfigRetArgs ipinfo2; |
SolderSplashLabs | 0:0bce3a738bcb | 284 | tUserFS cc_user_info; |
SolderSplashLabs | 0:0bce3a738bcb | 285 | const char * WIFI_STATUS[] = {"Disconnected", "Scanning", "Connecting", "Connected"}; |
SolderSplashLabs | 0:0bce3a738bcb | 286 | |
SolderSplashLabs | 0:0bce3a738bcb | 287 | wifi.get_user_file_info((uint8_t *)&cc_user_info, sizeof(cc_user_info)); |
SolderSplashLabs | 0:0bce3a738bcb | 288 | wifi.get_mac_address(myMAC); |
SolderSplashLabs | 0:0bce3a738bcb | 289 | pc.printf(" MAC address : %02x:%02x:%02x:%02x:%02x:%02x\r\n", myMAC[0], myMAC[1], myMAC[2], myMAC[3], myMAC[4], myMAC[5]); |
SolderSplashLabs | 0:0bce3a738bcb | 290 | |
SolderSplashLabs | 0:0bce3a738bcb | 291 | if (! wifi._nvmem.read_sp_version( (unsigned char*)&buffer ) ) |
SolderSplashLabs | 0:0bce3a738bcb | 292 | { |
SolderSplashLabs | 0:0bce3a738bcb | 293 | pc.printf(" CC3000 Firmware Version : %u.%u \r\n", buffer[0], buffer[1]); |
SolderSplashLabs | 0:0bce3a738bcb | 294 | } |
SolderSplashLabs | 0:0bce3a738bcb | 295 | else |
SolderSplashLabs | 0:0bce3a738bcb | 296 | { |
SolderSplashLabs | 0:0bce3a738bcb | 297 | pc.printf(" CC3000 Read nvmem failed!"); |
SolderSplashLabs | 0:0bce3a738bcb | 298 | } |
SolderSplashLabs | 0:0bce3a738bcb | 299 | |
SolderSplashLabs | 0:0bce3a738bcb | 300 | status = wifi._wlan.ioctl_statusget(); |
SolderSplashLabs | 0:0bce3a738bcb | 301 | if (( status > -1 ) && ( status < 4 )) |
SolderSplashLabs | 0:0bce3a738bcb | 302 | { |
SolderSplashLabs | 0:0bce3a738bcb | 303 | pc.printf(" Wifi Status : %s\r\n", WIFI_STATUS[status]); |
SolderSplashLabs | 0:0bce3a738bcb | 304 | } |
SolderSplashLabs | 0:0bce3a738bcb | 305 | else |
SolderSplashLabs | 0:0bce3a738bcb | 306 | { |
SolderSplashLabs | 0:0bce3a738bcb | 307 | pc.printf(" Wifi Status : %d\r\n", status); |
SolderSplashLabs | 0:0bce3a738bcb | 308 | } |
SolderSplashLabs | 0:0bce3a738bcb | 309 | |
SolderSplashLabs | 0:0bce3a738bcb | 310 | if ( wifi.is_dhcp_configured() ) |
SolderSplashLabs | 0:0bce3a738bcb | 311 | { |
SolderSplashLabs | 0:0bce3a738bcb | 312 | wifi.get_ip_config(&ipinfo2); |
SolderSplashLabs | 0:0bce3a738bcb | 313 | pc.printf(" Connected to : %s \r\n", ipinfo2.uaSSID); |
SolderSplashLabs | 0:0bce3a738bcb | 314 | pc.printf(" IP : %d.%d.%d.%d \r\n", ipinfo2.aucIP[3], ipinfo2.aucIP[2], ipinfo2.aucIP[1], ipinfo2.aucIP[0]); |
SolderSplashLabs | 0:0bce3a738bcb | 315 | pc.printf(" Gateway : %d.%d.%d.%d \r\n", ipinfo2.aucDefaultGateway[3], ipinfo2.aucDefaultGateway[2], ipinfo2.aucDefaultGateway[1], ipinfo2.aucDefaultGateway[0]); |
SolderSplashLabs | 0:0bce3a738bcb | 316 | pc.printf(" Subnet : %d.%d.%d.%d \r\n", ipinfo2.aucSubnetMask[3], ipinfo2.aucSubnetMask[2], ipinfo2.aucSubnetMask[1], ipinfo2.aucSubnetMask[0]); |
SolderSplashLabs | 0:0bce3a738bcb | 317 | pc.printf(" DNS : %d.%d.%d.%d \r\n", ipinfo2.aucDNSServer[3], ipinfo2.aucDNSServer[2], ipinfo2.aucDNSServer[1], ipinfo2.aucDNSServer[0]); |
SolderSplashLabs | 0:0bce3a738bcb | 318 | |
SolderSplashLabs | 0:0bce3a738bcb | 319 | pc.printf(" Cached IP : %s \r\n", wifi.getIPAddress()); |
SolderSplashLabs | 0:0bce3a738bcb | 320 | pc.printf(" Cached Gateway : %s \r\n", wifi.getGateway()); |
SolderSplashLabs | 0:0bce3a738bcb | 321 | pc.printf(" Cached Subnet : %s \r\n", wifi.getNetworkMask()); |
SolderSplashLabs | 0:0bce3a738bcb | 322 | |
SolderSplashLabs | 0:0bce3a738bcb | 323 | } |
SolderSplashLabs | 0:0bce3a738bcb | 324 | else |
SolderSplashLabs | 0:0bce3a738bcb | 325 | { |
SolderSplashLabs | 0:0bce3a738bcb | 326 | pc.printf(" Not connected \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 327 | } |
SolderSplashLabs | 0:0bce3a738bcb | 328 | } |
SolderSplashLabs | 0:0bce3a738bcb | 329 | |
SolderSplashLabs | 0:0bce3a738bcb | 330 | |
SolderSplashLabs | 0:0bce3a738bcb | 331 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 332 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 333 | @brief Control the wifi connection |
SolderSplashLabs | 0:0bce3a738bcb | 334 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 335 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 336 | void Menu_ConnectionControl ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 337 | { |
SolderSplashLabs | 0:0bce3a738bcb | 338 | uint32_t ip = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 339 | Menu_PrintHeader(); |
SolderSplashLabs | 0:0bce3a738bcb | 340 | pc.printf(" 1 - Enable auto connect to any previous access point\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 341 | pc.printf(" 2 - Disable auto connect \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 342 | pc.printf(" 3 - Connect to %s \r\n", SSID); |
SolderSplashLabs | 0:0bce3a738bcb | 343 | pc.printf(" 4 - Disconnect \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 344 | pc.printf(" 5 - Start SmartConfig \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 345 | pc.printf(" 6 - Erase profiles \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 346 | pc.printf(" 7 - Get Status \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 347 | pc.printf(" x - Top Menu \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 348 | |
SolderSplashLabs | 0:0bce3a738bcb | 349 | pc.printf("\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 350 | |
SolderSplashLabs | 0:0bce3a738bcb | 351 | switch(WaitForSerialCommand()) |
SolderSplashLabs | 0:0bce3a738bcb | 352 | { |
SolderSplashLabs | 0:0bce3a738bcb | 353 | case '1': |
SolderSplashLabs | 0:0bce3a738bcb | 354 | wifi._wlan.ioctl_set_connection_policy(0, 0, 1); |
SolderSplashLabs | 0:0bce3a738bcb | 355 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 356 | |
SolderSplashLabs | 0:0bce3a738bcb | 357 | case '2': |
SolderSplashLabs | 0:0bce3a738bcb | 358 | wifi._wlan.ioctl_set_connection_policy(0, 0, 0); |
SolderSplashLabs | 0:0bce3a738bcb | 359 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 360 | |
SolderSplashLabs | 0:0bce3a738bcb | 361 | case '3': |
SolderSplashLabs | 0:0bce3a738bcb | 362 | |
SolderSplashLabs | 0:0bce3a738bcb | 363 | //wifi.start(0); |
SolderSplashLabs | 0:0bce3a738bcb | 364 | |
SolderSplashLabs | 0:0bce3a738bcb | 365 | // Enable DHCP |
SolderSplashLabs | 0:0bce3a738bcb | 366 | wifi._netapp.dhcp(&ip, &ip, &ip, &ip); |
SolderSplashLabs | 0:0bce3a738bcb | 367 | |
SolderSplashLabs | 0:0bce3a738bcb | 368 | if ( AP_SECURITY == NONE ) |
SolderSplashLabs | 0:0bce3a738bcb | 369 | { |
SolderSplashLabs | 0:0bce3a738bcb | 370 | wifi.connect_non_blocking((uint8_t *)SSID, 0, AP_SECURITY); |
SolderSplashLabs | 0:0bce3a738bcb | 371 | } |
SolderSplashLabs | 0:0bce3a738bcb | 372 | else |
SolderSplashLabs | 0:0bce3a738bcb | 373 | { |
SolderSplashLabs | 0:0bce3a738bcb | 374 | pc.printf("\r\n Connecting to : %s key : %s", SSID, AP_KEY ); |
SolderSplashLabs | 0:0bce3a738bcb | 375 | wifi.connect_non_blocking((uint8_t *)SSID, (uint8_t *)AP_KEY, AP_SECURITY); |
SolderSplashLabs | 0:0bce3a738bcb | 376 | |
SolderSplashLabs | 0:0bce3a738bcb | 377 | } |
SolderSplashLabs | 0:0bce3a738bcb | 378 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 379 | |
SolderSplashLabs | 0:0bce3a738bcb | 380 | case '4' : |
SolderSplashLabs | 0:0bce3a738bcb | 381 | // Stop the module re-connecting |
SolderSplashLabs | 0:0bce3a738bcb | 382 | wifi._wlan.ioctl_set_connection_policy(0, 0, 0); |
SolderSplashLabs | 0:0bce3a738bcb | 383 | // Then disconnect |
SolderSplashLabs | 0:0bce3a738bcb | 384 | wifi.disconnect(); |
SolderSplashLabs | 0:0bce3a738bcb | 385 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 386 | |
SolderSplashLabs | 0:0bce3a738bcb | 387 | case '5' : |
SolderSplashLabs | 0:0bce3a738bcb | 388 | SmartConfig(); |
SolderSplashLabs | 0:0bce3a738bcb | 389 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 390 | |
SolderSplashLabs | 0:0bce3a738bcb | 391 | case '6' : |
SolderSplashLabs | 0:0bce3a738bcb | 392 | wifi._wlan.ioctl_del_profile(255); |
SolderSplashLabs | 0:0bce3a738bcb | 393 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 394 | |
SolderSplashLabs | 0:0bce3a738bcb | 395 | case '7' : |
SolderSplashLabs | 0:0bce3a738bcb | 396 | print_cc3000_info(); |
SolderSplashLabs | 0:0bce3a738bcb | 397 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 398 | |
SolderSplashLabs | 0:0bce3a738bcb | 399 | case '8': |
SolderSplashLabs | 0:0bce3a738bcb | 400 | //wifi._spi.manualIrqCheck(); |
SolderSplashLabs | 0:0bce3a738bcb | 401 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 402 | |
SolderSplashLabs | 0:0bce3a738bcb | 403 | case 'x': |
SolderSplashLabs | 0:0bce3a738bcb | 404 | currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 405 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 406 | } |
SolderSplashLabs | 0:0bce3a738bcb | 407 | } |
SolderSplashLabs | 0:0bce3a738bcb | 408 | |
SolderSplashLabs | 0:0bce3a738bcb | 409 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 410 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 411 | @brief |
SolderSplashLabs | 0:0bce3a738bcb | 412 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 413 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 414 | void Menu_UdpControl ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 415 | { |
SolderSplashLabs | 0:0bce3a738bcb | 416 | Menu_PrintHeader(); |
SolderSplashLabs | 0:0bce3a738bcb | 417 | |
SolderSplashLabs | 0:0bce3a738bcb | 418 | pc.printf(" 1 - UDP Client, Connect to %s:%d\r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT_UDP); |
SolderSplashLabs | 0:0bce3a738bcb | 419 | pc.printf(" 2 - UDP Server \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 420 | pc.printf(" 3 - NTP Client \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 421 | pc.printf(" x - Exit to top menu \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 422 | |
SolderSplashLabs | 0:0bce3a738bcb | 423 | pc.printf("\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 424 | |
SolderSplashLabs | 0:0bce3a738bcb | 425 | switch(WaitForSerialCommand()) |
SolderSplashLabs | 0:0bce3a738bcb | 426 | { |
SolderSplashLabs | 0:0bce3a738bcb | 427 | case '1': |
SolderSplashLabs | 0:0bce3a738bcb | 428 | UdpClientTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 429 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 430 | case '2': |
SolderSplashLabs | 0:0bce3a738bcb | 431 | UdpServerTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 432 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 433 | case '3': |
SolderSplashLabs | 0:0bce3a738bcb | 434 | NtpTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 435 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 436 | case '0': |
SolderSplashLabs | 0:0bce3a738bcb | 437 | case 'x': |
SolderSplashLabs | 0:0bce3a738bcb | 438 | currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 439 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 440 | } |
SolderSplashLabs | 0:0bce3a738bcb | 441 | } |
SolderSplashLabs | 0:0bce3a738bcb | 442 | |
SolderSplashLabs | 0:0bce3a738bcb | 443 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 444 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 445 | @brief |
SolderSplashLabs | 0:0bce3a738bcb | 446 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 447 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 448 | void Menu_TcpControl ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 449 | { |
SolderSplashLabs | 0:0bce3a738bcb | 450 | Menu_PrintHeader(); |
SolderSplashLabs | 0:0bce3a738bcb | 451 | |
SolderSplashLabs | 0:0bce3a738bcb | 452 | pc.printf(" 1 - TCP Client, Connect to %s:%d\r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT_TCP); |
SolderSplashLabs | 0:0bce3a738bcb | 453 | pc.printf(" 2 - TCP Server, listen on %d.%d.%d.%d:%d\r\n", ipinfo.aucIP[3], ipinfo.aucIP[2], ipinfo.aucIP[1], ipinfo.aucIP[0], ECHO_SERVER_PORT_TCP); |
SolderSplashLabs | 0:0bce3a738bcb | 454 | pc.printf(" 3 - Web Socket Write \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 455 | pc.printf(" 4 - Web Socket Read \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 456 | pc.printf(" 5 - HTTP Client \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 457 | pc.printf(" 6 - Xively Post ADC's \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 458 | pc.printf(" x - Exit to top menu "); |
SolderSplashLabs | 0:0bce3a738bcb | 459 | pc.printf("\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 460 | |
SolderSplashLabs | 0:0bce3a738bcb | 461 | switch(WaitForSerialCommand()) |
SolderSplashLabs | 0:0bce3a738bcb | 462 | { |
SolderSplashLabs | 0:0bce3a738bcb | 463 | case '1': |
SolderSplashLabs | 0:0bce3a738bcb | 464 | TcpClientTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 465 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 466 | case '2': |
SolderSplashLabs | 0:0bce3a738bcb | 467 | TcpServerTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 468 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 469 | case '3': |
SolderSplashLabs | 0:0bce3a738bcb | 470 | WebSocketTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 471 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 472 | case '4': |
SolderSplashLabs | 0:0bce3a738bcb | 473 | |
SolderSplashLabs | 0:0bce3a738bcb | 474 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 475 | case '5': |
SolderSplashLabs | 0:0bce3a738bcb | 476 | HttpClientTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 477 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 478 | case '6': |
SolderSplashLabs | 0:0bce3a738bcb | 479 | XivelySimpleTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 480 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 481 | case '0': |
SolderSplashLabs | 0:0bce3a738bcb | 482 | case 'x': |
SolderSplashLabs | 0:0bce3a738bcb | 483 | currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 484 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 485 | } |
SolderSplashLabs | 0:0bce3a738bcb | 486 | } |
SolderSplashLabs | 0:0bce3a738bcb | 487 | |
SolderSplashLabs | 0:0bce3a738bcb | 488 | |
SolderSplashLabs | 0:0bce3a738bcb | 489 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 490 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 491 | @brief Display a menu to the user |
SolderSplashLabs | 0:0bce3a738bcb | 492 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 493 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 494 | void Menu_Top ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 495 | { |
SolderSplashLabs | 0:0bce3a738bcb | 496 | Menu_PrintHeader(); |
SolderSplashLabs | 0:0bce3a738bcb | 497 | |
SolderSplashLabs | 0:0bce3a738bcb | 498 | pc.printf(" 1 - Connection control menu \r\n" ); |
SolderSplashLabs | 0:0bce3a738bcb | 499 | pc.printf(" 2 - TCP test menu \r\n" ); |
SolderSplashLabs | 0:0bce3a738bcb | 500 | pc.printf(" 3 - UDP test menu \r\n" ); |
SolderSplashLabs | 0:0bce3a738bcb | 501 | pc.printf(" 4 - Connection status \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 502 | pc.printf(" 5 - Ping - %s \r\n", HostToPing); |
SolderSplashLabs | 0:0bce3a738bcb | 503 | pc.printf(" x - Top Menu \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 504 | |
SolderSplashLabs | 0:0bce3a738bcb | 505 | pc.printf("\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 506 | |
SolderSplashLabs | 0:0bce3a738bcb | 507 | switch(WaitForSerialCommand()) |
SolderSplashLabs | 0:0bce3a738bcb | 508 | { |
SolderSplashLabs | 0:0bce3a738bcb | 509 | case '1': |
SolderSplashLabs | 0:0bce3a738bcb | 510 | currentMenu = MENU_CONNECTION; |
SolderSplashLabs | 0:0bce3a738bcb | 511 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 512 | case '2': |
SolderSplashLabs | 0:0bce3a738bcb | 513 | currentMenu = MENU_TCP; |
SolderSplashLabs | 0:0bce3a738bcb | 514 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 515 | case '3': |
SolderSplashLabs | 0:0bce3a738bcb | 516 | currentMenu = MENU_UDP; |
SolderSplashLabs | 0:0bce3a738bcb | 517 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 518 | case '4': |
SolderSplashLabs | 0:0bce3a738bcb | 519 | print_cc3000_info(); |
SolderSplashLabs | 0:0bce3a738bcb | 520 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 521 | case '5': |
SolderSplashLabs | 0:0bce3a738bcb | 522 | PingTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 523 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 524 | case 'x': |
SolderSplashLabs | 0:0bce3a738bcb | 525 | currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 526 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 527 | } |
SolderSplashLabs | 0:0bce3a738bcb | 528 | } |
SolderSplashLabs | 0:0bce3a738bcb | 529 | |
SolderSplashLabs | 0:0bce3a738bcb | 530 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 531 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 532 | @brief Pick which menu to display |
SolderSplashLabs | 0:0bce3a738bcb | 533 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 534 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 535 | void MenuSwitch ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 536 | { |
SolderSplashLabs | 0:0bce3a738bcb | 537 | bool connected = false; |
SolderSplashLabs | 0:0bce3a738bcb | 538 | |
SolderSplashLabs | 0:0bce3a738bcb | 539 | if ( wifi.is_dhcp_configured() ) |
SolderSplashLabs | 0:0bce3a738bcb | 540 | { |
SolderSplashLabs | 0:0bce3a738bcb | 541 | connected = true; |
SolderSplashLabs | 0:0bce3a738bcb | 542 | } |
SolderSplashLabs | 0:0bce3a738bcb | 543 | |
SolderSplashLabs | 0:0bce3a738bcb | 544 | switch ( currentMenu ) |
SolderSplashLabs | 0:0bce3a738bcb | 545 | { |
SolderSplashLabs | 0:0bce3a738bcb | 546 | case MENU_TOP : |
SolderSplashLabs | 0:0bce3a738bcb | 547 | Menu_Top(); |
SolderSplashLabs | 0:0bce3a738bcb | 548 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 549 | |
SolderSplashLabs | 0:0bce3a738bcb | 550 | case MENU_CONNECTION : |
SolderSplashLabs | 0:0bce3a738bcb | 551 | Menu_ConnectionControl(); |
SolderSplashLabs | 0:0bce3a738bcb | 552 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 553 | |
SolderSplashLabs | 0:0bce3a738bcb | 554 | case MENU_TCP : |
SolderSplashLabs | 0:0bce3a738bcb | 555 | if (connected) |
SolderSplashLabs | 0:0bce3a738bcb | 556 | { |
SolderSplashLabs | 0:0bce3a738bcb | 557 | Menu_TcpControl(); |
SolderSplashLabs | 0:0bce3a738bcb | 558 | } |
SolderSplashLabs | 0:0bce3a738bcb | 559 | else |
SolderSplashLabs | 0:0bce3a738bcb | 560 | { |
SolderSplashLabs | 0:0bce3a738bcb | 561 | currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 562 | } |
SolderSplashLabs | 0:0bce3a738bcb | 563 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 564 | |
SolderSplashLabs | 0:0bce3a738bcb | 565 | case MENU_UDP : |
SolderSplashLabs | 0:0bce3a738bcb | 566 | if (connected) |
SolderSplashLabs | 0:0bce3a738bcb | 567 | { |
SolderSplashLabs | 0:0bce3a738bcb | 568 | Menu_UdpControl(); |
SolderSplashLabs | 0:0bce3a738bcb | 569 | } |
SolderSplashLabs | 0:0bce3a738bcb | 570 | else |
SolderSplashLabs | 0:0bce3a738bcb | 571 | { |
SolderSplashLabs | 0:0bce3a738bcb | 572 | currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 573 | } |
SolderSplashLabs | 0:0bce3a738bcb | 574 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 575 | |
SolderSplashLabs | 0:0bce3a738bcb | 576 | default : |
SolderSplashLabs | 0:0bce3a738bcb | 577 | pc.printf("Unknown command\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 578 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 579 | } |
SolderSplashLabs | 0:0bce3a738bcb | 580 | } |
SolderSplashLabs | 0:0bce3a738bcb | 581 | |
SolderSplashLabs | 0:0bce3a738bcb | 582 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 583 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 584 | @brief Init |
SolderSplashLabs | 0:0bce3a738bcb | 585 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 586 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 587 | void init() |
SolderSplashLabs | 0:0bce3a738bcb | 588 | { |
SolderSplashLabs | 0:0bce3a738bcb | 589 | NVIC_SetPriority(SSP1_IRQn, 0x0); |
SolderSplashLabs | 0:0bce3a738bcb | 590 | NVIC_SetPriority(PIN_INT0_IRQn, 0x1); |
SolderSplashLabs | 0:0bce3a738bcb | 591 | |
SolderSplashLabs | 0:0bce3a738bcb | 592 | // SysTick set to lower priority than Wi-Fi SPI bus interrupt |
SolderSplashLabs | 0:0bce3a738bcb | 593 | NVIC_SetPriority(SysTick_IRQn, 0x2); |
SolderSplashLabs | 0:0bce3a738bcb | 594 | } |
SolderSplashLabs | 0:0bce3a738bcb | 595 | |
SolderSplashLabs | 0:0bce3a738bcb | 596 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 597 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 598 | @brief main loop |
SolderSplashLabs | 0:0bce3a738bcb | 599 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 600 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 601 | int main( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 602 | { |
SolderSplashLabs | 0:0bce3a738bcb | 603 | // Initalise the WiFi Module |
SolderSplashLabs | 0:0bce3a738bcb | 604 | init(); |
SolderSplashLabs | 0:0bce3a738bcb | 605 | |
SolderSplashLabs | 0:0bce3a738bcb | 606 | uart.baud(SERIAL_BAUD_RATE); |
SolderSplashLabs | 0:0bce3a738bcb | 607 | |
SolderSplashLabs | 0:0bce3a738bcb | 608 | wait(1); |
SolderSplashLabs | 0:0bce3a738bcb | 609 | wifi.start(0); |
SolderSplashLabs | 0:0bce3a738bcb | 610 | |
SolderSplashLabs | 0:0bce3a738bcb | 611 | wait_ms(750); |
SolderSplashLabs | 0:0bce3a738bcb | 612 | |
SolderSplashLabs | 0:0bce3a738bcb | 613 | while (1) |
SolderSplashLabs | 0:0bce3a738bcb | 614 | { |
SolderSplashLabs | 0:0bce3a738bcb | 615 | MenuSwitch(); |
SolderSplashLabs | 0:0bce3a738bcb | 616 | } |
SolderSplashLabs | 0:0bce3a738bcb | 617 | } |