Shigeki KOMATSU / Mbed 2 deprecated Sparkfun_CC3000_WiFi_OSCreceiver

Dependencies:   cc3000_hostdriver_mbedsocket mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 
00003     CC3000 OSC message receiver
00004 
00005     Sparkfun CC3000 WiFi Shield meets mbed!
00006        
00007     This program supports the following mbed boards with Sparkfun CC3000 Sheild.
00008     '#define' switches board.(refer to source code)
00009     (1)FRDM-KL25Z (KL25Z)
00010     (2)ST Nucleo F401RE (STM32F401)
00011     (3)ST Nucleo F030R8 (STM32F030)
00012     (4)LPCXpresso1549 (LPC1549)
00013     (5)Seeduino-Arch-Pro (ARCH_PRO)
00014 
00015  Please push RESET button on CC3000 WiFi Shield to start the program.
00016 
00017   reference:  
00018     https://www.sparkfun.com/products/12071 for CC300 Shield
00019     http://opensoundcontrol.org/introduction-osc for OSC(Open Sound Control)
00020 
00021   date: 2014/8/31
00022   written by: xshige
00023   
00024 console out sample:
00025 ----------------------------------
00026 C3000 OSC receiver demo.
00027 IP address: 192.168.0.2
00028 
00029 Wait for packet...
00030 incomming OSC msg:
00031 /1 ,
00032 Received packet from: 192.168.0.23
00033 -------------------
00034 
00035 Wait for packet...
00036 incomming OSC msg:
00037 /1/fader3 ,f 0.565401
00038 Received packet from: 192.168.0.23
00039 -------------------
00040 
00041 Wait for packet...
00042 incomming OSC msg:
00043 /1/fader3 ,f 0.565401
00044 Received packet from: 192.168.0.23
00045 -------------------
00046 
00047 Wait for packet...
00048 incomming OSC msg:
00049 /4 ,
00050 Received packet from: 192.168.0.23
00051 -------------------
00052 
00053 Wait for packet...
00054 incomming OSC msg:
00055 /3 ,
00056 Received packet from: 192.168.0.23
00057 -------------------
00058 
00059 Wait for packet...
00060 incomming OSC msg:
00061 /3/xy ,ff 0.604869 0.505618
00062 Received packet from: 192.168.0.23
00063 -------------------
00064 
00065 Wait for packet...
00066 ----------------------------------  
00067 */
00068 
00069 #include "mbed.h"
00070 #include "cc3000.h"
00071 
00072 // define board you like (KL25Z, LPC1549, STM32F401, STM32F030 ...)
00073 //#define KL25Z
00074 #define STM32F401
00075 //#define STM32F030
00076 //#define LPC1549
00077 //#define ARCH_PRO
00078 
00079 // define SSID, PASSWORD you like
00080 #define SSID "ssid"
00081 #define PASSWORD "password"
00082 
00083 #include "UDPSocket.h"
00084 
00085 using namespace mbed_cc3000;
00086 
00087 /* cc3000 module declaration specific for user's board. */
00088 #if defined(KL25Z)
00089 // for KL25Z
00090 cc3000 wifi(PTD4, PTC9, PTD0, SPI(PTD2, PTD3, PTD1), SSID, PASSWORD, WPA2, false);
00091 Serial pc(USBTX, USBRX);
00092 #endif
00093 #if defined(STM32F401)
00094 // for Nucleo STM32F401
00095 cc3000 wifi(PA_10, PA_8, PB_6, SPI(PA_7, PA_6, PA_5), SSID, PASSWORD, WPA2, false);
00096 // for Nucleo STM32F401
00097 Serial pc(SERIAL_TX, SERIAL_RX);
00098 #endif
00099 #if defined(STM32F030)
00100 // for Nucleo STM32F030
00101 cc3000 wifi(PA_10, PA_8, PB_6, SPI(PA_7, PA_6, PA_5), SSID, PASSWORD, WPA2, false);
00102 // for Nucleo STM32F030
00103 Serial pc(SERIAL_TX, SERIAL_RX);
00104 #endif
00105 #if defined(LPC1549)
00106 // for LPC1549
00107 cc3000 wifi(P0_29, P0_0, P0_27, SPI(P0_28, P0_12, P0_16), SSID, PASSWORD, WPA2, false);
00108 Serial pc(USBTX, USBRX);
00109 #endif
00110 #if defined(ARCH_PRO)
00111 // for Seeed Studio Arch Pro
00112 cc3000 wifi(P0_4, P2_5, P0_6, SPI(P0_9, P0_8, P0_7), SSID, PASSWORD, WPA2, false);
00113 Serial pc(USBTX, USBRX);
00114 #endif
00115 
00116 // OSC related
00117 #include "OSCmsgCodec.h"
00118 
00119 #define INCOMMING_PORT 8000
00120 
00121 #define PACKET_SIZE 512
00122 #define RECBUF_SIZE 256
00123 #define PERIOD_BUZZER 10
00124 
00125 union OSCarg msg[10];
00126 char recbuf[RECBUF_SIZE],buff[PACKET_SIZE],packet[PACKET_SIZE];
00127 
00128 int main() {
00129     pc.baud(115200);
00130 
00131     printf("\n\nCC3000 OSC receiver demo. \n");
00132     wifi.init();
00133     if (wifi.connect() == -1) {
00134         printf("Failed to connect. Please verify connection details and try again. \n");
00135     } else {
00136         printf("IP address: %s \n", wifi.getIPAddress());
00137     }
00138     
00139     UDPSocket sock;
00140     sock.bind(INCOMMING_PORT);
00141     
00142     Endpoint receiver;
00143 
00144     while (true) {
00145         printf("\nWait for packet...\n");
00146         int n = sock.receiveFrom(receiver, recbuf, sizeof(recbuf));
00147         if (n > 0) {
00148             decOSCmsg(recbuf, msg);
00149             pc.printf("incomming OSC msg:\n%s %s", msg[0].address, msg[1].typeTag);
00150             for(int m=0; m < (strlen(msg[1].typeTag)-1); m++) {
00151                 if (msg[1].typeTag[m+1]=='f') pc.printf(" %f",msg[m+2].f);
00152                 if (msg[1].typeTag[m+1]=='i') pc.printf(" %d",msg[m+2].i);                
00153             }
00154             pc.printf("\n");
00155             printf("Received packet from: %s \n", receiver.get_address());
00156             printf("-------------------\n");
00157         };
00158     } // while
00159 }