OSC meeseage receiver for Sparkfun CC3000 WiFi Shield. Supports the following boards: FRDM-KL25Z,ST Nucleo F401RE,ST Nucleo F030R8,LPCXpresso1549,Seeduino-Arch-Pro.
Dependencies: cc3000_hostdriver_mbedsocket mbed
main.cpp@0:1c9ac526d377, 2014-08-31 (annotated)
- Committer:
- xshige
- Date:
- Sun Aug 31 04:28:50 2014 +0000
- Revision:
- 0:1c9ac526d377
OSC receiver(Sparkfun CC3000 WiFi Sheild meets mbed!) Supports the following boards with CC3000 Shield.; FRDM-KL25Z,ST Nucleo F401RE,ST Nucleo F030R8,LPCXpresso1549,Seeduino-Arch-Pro
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
xshige | 0:1c9ac526d377 | 1 | /* |
xshige | 0:1c9ac526d377 | 2 | |
xshige | 0:1c9ac526d377 | 3 | CC3000 OSC message receiver |
xshige | 0:1c9ac526d377 | 4 | |
xshige | 0:1c9ac526d377 | 5 | Sparkfun CC3000 WiFi Shield meets mbed! |
xshige | 0:1c9ac526d377 | 6 | |
xshige | 0:1c9ac526d377 | 7 | This program supports the following mbed boards with Sparkfun CC3000 Sheild. |
xshige | 0:1c9ac526d377 | 8 | '#define' switches board.(refer to source code) |
xshige | 0:1c9ac526d377 | 9 | (1)FRDM-KL25Z (KL25Z) |
xshige | 0:1c9ac526d377 | 10 | (2)ST Nucleo F401RE (STM32F401) |
xshige | 0:1c9ac526d377 | 11 | (3)ST Nucleo F030R8 (STM32F030) |
xshige | 0:1c9ac526d377 | 12 | (4)LPCXpresso1549 (LPC1549) |
xshige | 0:1c9ac526d377 | 13 | (5)Seeduino-Arch-Pro (ARCH_PRO) |
xshige | 0:1c9ac526d377 | 14 | |
xshige | 0:1c9ac526d377 | 15 | Please push RESET button on CC3000 WiFi Shield to start the program. |
xshige | 0:1c9ac526d377 | 16 | |
xshige | 0:1c9ac526d377 | 17 | reference: |
xshige | 0:1c9ac526d377 | 18 | https://www.sparkfun.com/products/12071 for CC300 Shield |
xshige | 0:1c9ac526d377 | 19 | http://opensoundcontrol.org/introduction-osc for OSC(Open Sound Control) |
xshige | 0:1c9ac526d377 | 20 | |
xshige | 0:1c9ac526d377 | 21 | date: 2014/8/31 |
xshige | 0:1c9ac526d377 | 22 | written by: xshige |
xshige | 0:1c9ac526d377 | 23 | |
xshige | 0:1c9ac526d377 | 24 | console out sample: |
xshige | 0:1c9ac526d377 | 25 | ---------------------------------- |
xshige | 0:1c9ac526d377 | 26 | C3000 OSC receiver demo. |
xshige | 0:1c9ac526d377 | 27 | IP address: 192.168.0.2 |
xshige | 0:1c9ac526d377 | 28 | |
xshige | 0:1c9ac526d377 | 29 | Wait for packet... |
xshige | 0:1c9ac526d377 | 30 | incomming OSC msg: |
xshige | 0:1c9ac526d377 | 31 | /1 , |
xshige | 0:1c9ac526d377 | 32 | Received packet from: 192.168.0.23 |
xshige | 0:1c9ac526d377 | 33 | ------------------- |
xshige | 0:1c9ac526d377 | 34 | |
xshige | 0:1c9ac526d377 | 35 | Wait for packet... |
xshige | 0:1c9ac526d377 | 36 | incomming OSC msg: |
xshige | 0:1c9ac526d377 | 37 | /1/fader3 ,f 0.565401 |
xshige | 0:1c9ac526d377 | 38 | Received packet from: 192.168.0.23 |
xshige | 0:1c9ac526d377 | 39 | ------------------- |
xshige | 0:1c9ac526d377 | 40 | |
xshige | 0:1c9ac526d377 | 41 | Wait for packet... |
xshige | 0:1c9ac526d377 | 42 | incomming OSC msg: |
xshige | 0:1c9ac526d377 | 43 | /1/fader3 ,f 0.565401 |
xshige | 0:1c9ac526d377 | 44 | Received packet from: 192.168.0.23 |
xshige | 0:1c9ac526d377 | 45 | ------------------- |
xshige | 0:1c9ac526d377 | 46 | |
xshige | 0:1c9ac526d377 | 47 | Wait for packet... |
xshige | 0:1c9ac526d377 | 48 | incomming OSC msg: |
xshige | 0:1c9ac526d377 | 49 | /4 , |
xshige | 0:1c9ac526d377 | 50 | Received packet from: 192.168.0.23 |
xshige | 0:1c9ac526d377 | 51 | ------------------- |
xshige | 0:1c9ac526d377 | 52 | |
xshige | 0:1c9ac526d377 | 53 | Wait for packet... |
xshige | 0:1c9ac526d377 | 54 | incomming OSC msg: |
xshige | 0:1c9ac526d377 | 55 | /3 , |
xshige | 0:1c9ac526d377 | 56 | Received packet from: 192.168.0.23 |
xshige | 0:1c9ac526d377 | 57 | ------------------- |
xshige | 0:1c9ac526d377 | 58 | |
xshige | 0:1c9ac526d377 | 59 | Wait for packet... |
xshige | 0:1c9ac526d377 | 60 | incomming OSC msg: |
xshige | 0:1c9ac526d377 | 61 | /3/xy ,ff 0.604869 0.505618 |
xshige | 0:1c9ac526d377 | 62 | Received packet from: 192.168.0.23 |
xshige | 0:1c9ac526d377 | 63 | ------------------- |
xshige | 0:1c9ac526d377 | 64 | |
xshige | 0:1c9ac526d377 | 65 | Wait for packet... |
xshige | 0:1c9ac526d377 | 66 | ---------------------------------- |
xshige | 0:1c9ac526d377 | 67 | */ |
xshige | 0:1c9ac526d377 | 68 | |
xshige | 0:1c9ac526d377 | 69 | #include "mbed.h" |
xshige | 0:1c9ac526d377 | 70 | #include "cc3000.h" |
xshige | 0:1c9ac526d377 | 71 | |
xshige | 0:1c9ac526d377 | 72 | // define board you like (KL25Z, LPC1549, STM32F401, STM32F030 ...) |
xshige | 0:1c9ac526d377 | 73 | //#define KL25Z |
xshige | 0:1c9ac526d377 | 74 | #define STM32F401 |
xshige | 0:1c9ac526d377 | 75 | //#define STM32F030 |
xshige | 0:1c9ac526d377 | 76 | //#define LPC1549 |
xshige | 0:1c9ac526d377 | 77 | //#define ARCH_PRO |
xshige | 0:1c9ac526d377 | 78 | |
xshige | 0:1c9ac526d377 | 79 | // define SSID, PASSWORD you like |
xshige | 0:1c9ac526d377 | 80 | #define SSID "ssid" |
xshige | 0:1c9ac526d377 | 81 | #define PASSWORD "password" |
xshige | 0:1c9ac526d377 | 82 | |
xshige | 0:1c9ac526d377 | 83 | #include "UDPSocket.h" |
xshige | 0:1c9ac526d377 | 84 | |
xshige | 0:1c9ac526d377 | 85 | using namespace mbed_cc3000; |
xshige | 0:1c9ac526d377 | 86 | |
xshige | 0:1c9ac526d377 | 87 | /* cc3000 module declaration specific for user's board. */ |
xshige | 0:1c9ac526d377 | 88 | #if defined(KL25Z) |
xshige | 0:1c9ac526d377 | 89 | // for KL25Z |
xshige | 0:1c9ac526d377 | 90 | cc3000 wifi(PTD4, PTC9, PTD0, SPI(PTD2, PTD3, PTD1), SSID, PASSWORD, WPA2, false); |
xshige | 0:1c9ac526d377 | 91 | Serial pc(USBTX, USBRX); |
xshige | 0:1c9ac526d377 | 92 | #endif |
xshige | 0:1c9ac526d377 | 93 | #if defined(STM32F401) |
xshige | 0:1c9ac526d377 | 94 | // for Nucleo STM32F401 |
xshige | 0:1c9ac526d377 | 95 | cc3000 wifi(PA_10, PA_8, PB_6, SPI(PA_7, PA_6, PA_5), SSID, PASSWORD, WPA2, false); |
xshige | 0:1c9ac526d377 | 96 | // for Nucleo STM32F401 |
xshige | 0:1c9ac526d377 | 97 | Serial pc(SERIAL_TX, SERIAL_RX); |
xshige | 0:1c9ac526d377 | 98 | #endif |
xshige | 0:1c9ac526d377 | 99 | #if defined(STM32F030) |
xshige | 0:1c9ac526d377 | 100 | // for Nucleo STM32F030 |
xshige | 0:1c9ac526d377 | 101 | cc3000 wifi(PA_10, PA_8, PB_6, SPI(PA_7, PA_6, PA_5), SSID, PASSWORD, WPA2, false); |
xshige | 0:1c9ac526d377 | 102 | // for Nucleo STM32F030 |
xshige | 0:1c9ac526d377 | 103 | Serial pc(SERIAL_TX, SERIAL_RX); |
xshige | 0:1c9ac526d377 | 104 | #endif |
xshige | 0:1c9ac526d377 | 105 | #if defined(LPC1549) |
xshige | 0:1c9ac526d377 | 106 | // for LPC1549 |
xshige | 0:1c9ac526d377 | 107 | cc3000 wifi(P0_29, P0_0, P0_27, SPI(P0_28, P0_12, P0_16), SSID, PASSWORD, WPA2, false); |
xshige | 0:1c9ac526d377 | 108 | Serial pc(USBTX, USBRX); |
xshige | 0:1c9ac526d377 | 109 | #endif |
xshige | 0:1c9ac526d377 | 110 | #if defined(ARCH_PRO) |
xshige | 0:1c9ac526d377 | 111 | // for Seeed Studio Arch Pro |
xshige | 0:1c9ac526d377 | 112 | cc3000 wifi(P0_4, P2_5, P0_6, SPI(P0_9, P0_8, P0_7), SSID, PASSWORD, WPA2, false); |
xshige | 0:1c9ac526d377 | 113 | Serial pc(USBTX, USBRX); |
xshige | 0:1c9ac526d377 | 114 | #endif |
xshige | 0:1c9ac526d377 | 115 | |
xshige | 0:1c9ac526d377 | 116 | // OSC related |
xshige | 0:1c9ac526d377 | 117 | #include "OSCmsgCodec.h" |
xshige | 0:1c9ac526d377 | 118 | |
xshige | 0:1c9ac526d377 | 119 | #define INCOMMING_PORT 8000 |
xshige | 0:1c9ac526d377 | 120 | |
xshige | 0:1c9ac526d377 | 121 | #define PACKET_SIZE 512 |
xshige | 0:1c9ac526d377 | 122 | #define RECBUF_SIZE 256 |
xshige | 0:1c9ac526d377 | 123 | #define PERIOD_BUZZER 10 |
xshige | 0:1c9ac526d377 | 124 | |
xshige | 0:1c9ac526d377 | 125 | union OSCarg msg[10]; |
xshige | 0:1c9ac526d377 | 126 | char recbuf[RECBUF_SIZE],buff[PACKET_SIZE],packet[PACKET_SIZE]; |
xshige | 0:1c9ac526d377 | 127 | |
xshige | 0:1c9ac526d377 | 128 | int main() { |
xshige | 0:1c9ac526d377 | 129 | pc.baud(115200); |
xshige | 0:1c9ac526d377 | 130 | |
xshige | 0:1c9ac526d377 | 131 | printf("\n\nCC3000 OSC receiver demo. \n"); |
xshige | 0:1c9ac526d377 | 132 | wifi.init(); |
xshige | 0:1c9ac526d377 | 133 | if (wifi.connect() == -1) { |
xshige | 0:1c9ac526d377 | 134 | printf("Failed to connect. Please verify connection details and try again. \n"); |
xshige | 0:1c9ac526d377 | 135 | } else { |
xshige | 0:1c9ac526d377 | 136 | printf("IP address: %s \n", wifi.getIPAddress()); |
xshige | 0:1c9ac526d377 | 137 | } |
xshige | 0:1c9ac526d377 | 138 | |
xshige | 0:1c9ac526d377 | 139 | UDPSocket sock; |
xshige | 0:1c9ac526d377 | 140 | sock.bind(INCOMMING_PORT); |
xshige | 0:1c9ac526d377 | 141 | |
xshige | 0:1c9ac526d377 | 142 | Endpoint receiver; |
xshige | 0:1c9ac526d377 | 143 | |
xshige | 0:1c9ac526d377 | 144 | while (true) { |
xshige | 0:1c9ac526d377 | 145 | printf("\nWait for packet...\n"); |
xshige | 0:1c9ac526d377 | 146 | int n = sock.receiveFrom(receiver, recbuf, sizeof(recbuf)); |
xshige | 0:1c9ac526d377 | 147 | if (n > 0) { |
xshige | 0:1c9ac526d377 | 148 | decOSCmsg(recbuf, msg); |
xshige | 0:1c9ac526d377 | 149 | pc.printf("incomming OSC msg:\n%s %s", msg[0].address, msg[1].typeTag); |
xshige | 0:1c9ac526d377 | 150 | for(int m=0; m < (strlen(msg[1].typeTag)-1); m++) { |
xshige | 0:1c9ac526d377 | 151 | if (msg[1].typeTag[m+1]=='f') pc.printf(" %f",msg[m+2].f); |
xshige | 0:1c9ac526d377 | 152 | if (msg[1].typeTag[m+1]=='i') pc.printf(" %d",msg[m+2].i); |
xshige | 0:1c9ac526d377 | 153 | } |
xshige | 0:1c9ac526d377 | 154 | pc.printf("\n"); |
xshige | 0:1c9ac526d377 | 155 | printf("Received packet from: %s \n", receiver.get_address()); |
xshige | 0:1c9ac526d377 | 156 | printf("-------------------\n"); |
xshige | 0:1c9ac526d377 | 157 | }; |
xshige | 0:1c9ac526d377 | 158 | } // while |
xshige | 0:1c9ac526d377 | 159 | } |