osc test
Dependencies: EthernetNetIf mbed mbed
Fork of OSC by
Revision 2:b5af09b0d540, committed 2013-10-04
- Comitter:
- itotaka
- Date:
- Fri Oct 04 12:19:39 2013 +0000
- Parent:
- 1:63b72e393989
- Commit message:
- to share
Changed in this revision
diff -r 63b72e393989 -r b5af09b0d540 EthernetNetIf.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetNetIf.lib Fri Oct 04 12:19:39 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mamezu/code/EthernetNetIf/#0f6c82fcde82
diff -r 63b72e393989 -r b5af09b0d540 example-processing.h --- a/example-processing.h Fri Jul 26 22:10:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,52 +0,0 @@ -/* EXAMPLE SEND/RECEIVE on PROCESSING: - -// oscP5sendreceive by andreas schlegel -// example shows how to send and receive osc messages. -// oscP5 website at http://www.sojamo.de/oscP5 - -*/ - -import oscP5.*; -import netP5.*; - -OscP5 oscP5; -NetAddress myRemoteLocation; - -void setup() { - size(400,400); - frameRate(25); - // start oscP5, listening for incoming messages at port 12000 - oscP5 = new OscP5(this,12000); - - // myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters, - // an ip address and a port number. myRemoteLocation is used as parameter in - // oscP5.send() when sending osc packets to another computer, device, - // application. usage see below. for testing purposes the listening port - // and the port of the remote location address are the same, hence you will - // send messages back to this sketch. - myRemoteLocation = new NetAddress("10.0.0.2",10000); -} - - -void draw() { - background(0); -} - -void mousePressed() { - // in the following different ways of creating osc messages are shown by example - OscMessage myMessage = new OscMessage("/mbed/test1"); - - myMessage.add(123); // add an int to the osc message - - // send the message - oscP5.send(myMessage, myRemoteLocation); -} - - -// incoming osc message are forwarded to the oscEvent method. -void oscEvent(OscMessage theOscMessage) { - // print the address pattern and the typetag of the received OscMessage - print("### received an osc message."); - print(" addrpattern: "+theOscMessage.addrPattern()); - println(" typetag: "+theOscMessage.typetag()); -}
diff -r 63b72e393989 -r b5af09b0d540 example.h --- a/example.h Fri Jul 26 22:10:20 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,117 +0,0 @@ -#include "mbed.h" -#include "mbedOSC.h" - -//// ETHERNET - -// Ethernet can be created with *either* an address assigned by DHCP or a static IP address. Uncomment the define line for DHCP -//#define DHCP -#ifdef DHCP -EthernetNetIf eth; -#else -EthernetNetIf eth( - IpAddr(10,0,0,2), //IP Address - IpAddr(255,255,255,0), //Network Mask - IpAddr(10,0,0,1), //Gateway - IpAddr(10,0,0,1) //DNS -); -#endif - -//// OSC - -// The object to do the work of sending and receiving -OSCClass osc; - -// The message objects to send and receive with -OSCMessage recMes; -OSCMessage sendMes; - -// Setting - The port we're listening to on the mbed for OSC messages -int mbedListenPort = 10000; - -// Setting - The address and port we're going to send to, from the mbed -uint8_t destIp[] = { 10, 0, 0, 1}; -int destPort = 12000; - -//// mbed input - -DigitalIn button(p21); -bool buttonLastState; - -//// Our messageReceivedCallback function -void processOSC() { - - // If this function has been called, the OSC message just received will have been parsed into our recMes OSCMessage object - // Note we can access recMes here, outside of the main loop, as we created it as a global variable. - - // TASK: If this message one we want, do something about it. - // In this example we're listening for messages with a top address of "mbed". - // Note the strcmp function returns 0 if identical, so !strcmp is true if the two strings are the same - if ( !strcmp( recMes.getAddress(0) , "mbed" ) ) { - printf("OSC Message received addressed to mbed \r\n"); - if ( !strcmp( recMes.getAddress(1) , "test1" ) ) - printf("Received subAddress= test1 \r\n"); - - // Send some osc message: - sendMes.setTopAddress("/working..."); - osc.sendOsc(&sendMes); - } -} - -//// M A I N -int main() { - - //// TASK: Set up the Ethernet port - printf("Setting up ethernet...\r\n"); - EthernetErr ethErr = eth.setup(); - if (ethErr) { - printf("Ethernet Failed to setup. Error: %d\r\n", ethErr); - return -1; - } - printf("Ethernet OK\r\n"); - - //// TASK: Set up OSC message sending - - // In the OSC message container we've made for send messages, set where we want it to go: - sendMes.setIp( destIp ); - sendMes.setPort( destPort ); - - //// TASK: Set up OSC message receiving - - // In the OSC send/receive object... - // Set the OSC message container for it to parse received messages into - osc.setReceiveMessage(&recMes); - - // Tell it to begin listening for OSC messages at the port specified (the IP address we know already, it's the mbed's!). - osc.begin(mbedListenPort); - - // Rather than constantly checking to see whether there are new messages waiting, the object can call some code of ours to run when a message is received. - // This line does that, attaching a callback function we've written before getting to this point, in this case it's called processOSC - // For more info how this works, see http://mbed.org/cookbook/FunctionPointer - osc.messageReceivedCallback.attach(&processOSC); - - //// TASK: Prime button change detection - buttonLastState = button; - - //// TASK: GO! - - // We've finished setting up, now loop this forever... - while (true) { - // This polls the network connection for new activity, without keeping on calling this you won't receive any OSC! - Net::poll(); - - // Has the button changed? - if (button != buttonLastState) { - // If so, lets update the lastState variable and then send an OSC message - buttonLastState = button; - - sendMes.setTopAddress("/mbed"); - sendMes.setSubAddress("/button"); - sendMes.setArgs("i", (long)button); // The payload will be the button state as an integer, ie. 0 or 1. We need to cast to 'long' for ints (and 'double' for floats).// The payload will be the button state as an integer, ie. 0 or 1. We need to cast to 'long' for ints (and 'double' for floats). - osc.sendOsc(&sendMes); - - printf("Sent OSC message /mbed/button \r\n"); - } - - // ... Do whatever needs to be done by your mbed otherwise. If an OSC message is received, your messageReceivedCallback will run (in this case, processOSC()). - } -} \ No newline at end of file
diff -r 63b72e393989 -r b5af09b0d540 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Oct 04 12:19:39 2013 +0000 @@ -0,0 +1,126 @@ +#include "mbed.h" +#include "mbedOSC.h" + +//// ETHERNET + +// Ethernet can be created with *either* an address assigned by DHCP or a static IP address. Uncomment the define line for DHCP +//#define DHCP +#ifdef DHCP +EthernetNetIf eth; +#else +EthernetNetIf eth( + IpAddr(10,0,0,2), //IP Address + IpAddr(255,255,255,0), //Network Mask + IpAddr(10,0,0,1), //Gateway + IpAddr(10,0,0,1) //DNS +); +#endif + +//// OSC + +// The object to do the work of sending and receiving +OSCClass osc; + +// The message objects to send and receive with +OSCMessage recMes; +OSCMessage sendMes; + +// Setting - The port we're listening to on the mbed for OSC messages +int mbedListenPort = 10000; + +// Setting - The address and port we're going to send to, from the mbed +uint8_t destIp[] = { 10, 0, 0, 5}; +int destPort = 12000; + +//// mbed input + +DigitalIn button(p21); +bool buttonLastState; + +//// Our messageReceivedCallback function +void processOSC() { + + // If this function has been called, the OSC message just received will have been parsed into our recMes OSCMessage object + // Note we can access recMes here, outside of the main loop, as we created it as a global variable. + + // TASK: If this message one we want, do something about it. + // In this example we're listening for messages with a top address of "mbed". + // Note the strcmp function returns 0 if identical, so !strcmp is true if the two strings are the same + if ( !strcmp( recMes.getAddress(0) , "mbed" ) ) { + printf("OSC Message received addressed to mbed \r\n"); + if ( !strcmp( recMes.getAddress(1) , "test1" ) ) + printf("Received subAddress= test1 \r\n"); + + int na = recMes.getArgNum(); + printf("numArgs: %d \r\n", na); + + for (int i = 0; i < na; i++) { + int v = recMes.getArgInt(i); + printf("%d, \r\n", v); + } + + // Send some osc message: + sendMes.setTopAddress("/working..."); +// sendMes.setArgs("i", &v1); + osc.sendOsc(&sendMes); + } +} + +//// M A I N +int main() { + + //// TASK: Set up the Ethernet port + printf("Setting up ethernet...\r\n"); + EthernetErr ethErr = eth.setup(); + if (ethErr) { + printf("Ethernet Failed to setup. Error: %d\r\n", ethErr); + return -1; + } + printf("Ethernet OK\r\n"); + + //// TASK: Set up OSC message sending + + // In the OSC message container we've made for send messages, set where we want it to go: + sendMes.setIp( destIp ); + sendMes.setPort( destPort ); + + //// TASK: Set up OSC message receiving + + // In the OSC send/receive object... + // Set the OSC message container for it to parse received messages into + osc.setReceiveMessage(&recMes); + + // Tell it to begin listening for OSC messages at the port specified (the IP address we know already, it's the mbed's!). + osc.begin(mbedListenPort); + + // Rather than constantly checking to see whether there are new messages waiting, the object can call some code of ours to run when a message is received. + // This line does that, attaching a callback function we've written before getting to this point, in this case it's called processOSC + // For more info how this works, see http://mbed.org/cookbook/FunctionPointer + osc.messageReceivedCallback.attach(&processOSC); + + //// TASK: Prime button change detection + buttonLastState = button; + + //// TASK: GO! + + // We've finished setting up, now loop this forever... + while (true) { + // This polls the network connection for new activity, without keeping on calling this you won't receive any OSC! + Net::poll(); + + // Has the button changed? + if (button != buttonLastState) { + // If so, lets update the lastState variable and then send an OSC message + buttonLastState = button; + + sendMes.setTopAddress("/mbed"); + sendMes.setSubAddress("/button"); + sendMes.setArgs("i", (long)button); // The payload will be the button state as an integer, ie. 0 or 1. We need to cast to 'long' for ints (and 'double' for floats).// The payload will be the button state as an integer, ie. 0 or 1. We need to cast to 'long' for ints (and 'double' for floats). + osc.sendOsc(&sendMes); + + printf("Sent OSC message /mbed/button \r\n"); + } + + // ... Do whatever needs to be done by your mbed otherwise. If an OSC message is received, your messageReceivedCallback will run (in this case, processOSC()). + } +} \ No newline at end of file
diff -r 63b72e393989 -r b5af09b0d540 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Oct 04 12:19:39 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ \ No newline at end of file
diff -r 63b72e393989 -r b5af09b0d540 mbed.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.lib Fri Oct 04 12:19:39 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/itotaka/code/mbed/#b749145a7bb1
diff -r 63b72e393989 -r b5af09b0d540 mbedOSC.h --- a/mbedOSC.h Fri Jul 26 22:10:20 2013 +0000 +++ b/mbedOSC.h Fri Oct 04 12:19:39 2013 +0000 @@ -27,7 +27,7 @@ #define MAX_ADDRESS 2 -#define MAX_ARG 2 +#define MAX_ARG 80 #define TYPE_INT 1 #define TYPE_FLOAT 2