From b5db4d36697ca0adac7e6a7f54f813655d61c269 Mon Sep 17 00:00:00 2001 From: recotana Date: Mon, 17 Oct 2011 10:36:32 +0900 Subject: [PATCH] first commit --- .gitignore | 1 + ArdOSC.h | 60 ++++ Example/OSCArguments/OSCArguments.ino | 94 +++++++ .../OSCArguments_p5/OSCArguments_p5.pde | 60 ++++ Example/SImpleRecieve/SImpleRecieve.ino | 51 ++++ .../SimpleRecieve_p5/SimpleRecieve_p5.pde | 91 ++++++ .../SImpleRecieveLEDToggle.ino | 66 +++++ .../SImpleRecieveLEDToggle_p5.pde | 55 ++++ .../LoopBackSender_P5/LoopBackSender_P5.pde | 60 ++++ Example/loopback/loopback.ino | 89 ++++++ Example/multicallback/multicallback.ino | 135 +++++++++ .../multicallback_p5/multicallback_p5.pde | 66 +++++ .../SimpleSend_P5/SimpleSend_P5.pde | 35 +++ Example/simplesend/simplesend.ino | 81 ++++++ Lisence.txt | 29 ++ OSCArg.cpp | 70 +++++ OSCClient.cpp | 102 +++++++ OSCDecoder.cpp | 66 +++++ OSCEncoder.cpp | 68 +++++ OSCMessage.cpp | 261 ++++++++++++++++++ OSCServer.cpp | 97 +++++++ OSCcommon/OSCArg.h | 51 ++++ OSCcommon/OSCClient.h | 56 ++++ OSCcommon/OSCDecoder.h | 34 +++ OSCcommon/OSCEncoder.h | 36 +++ OSCcommon/OSCMessage.h | 122 ++++++++ OSCcommon/OSCServer.h | 57 ++++ OSCcommon/OSCcommon.h | 43 +++ OSCcommon/Pattern.h | 50 ++++ Pattern.cpp | 48 ++++ README | 30 ++ keywords.txt | 57 ++++ 32 files changed, 2221 insertions(+) create mode 100644 .gitignore create mode 100644 ArdOSC.h create mode 100644 Example/OSCArguments/OSCArguments.ino create mode 100644 Example/OSCArguments/OSCArguments_p5/OSCArguments_p5.pde create mode 100644 Example/SImpleRecieve/SImpleRecieve.ino create mode 100644 Example/SImpleRecieve/SimpleRecieve_p5/SimpleRecieve_p5.pde create mode 100644 Example/SImpleRecieveLEDToggle/SImpleRecieveLEDToggle.ino create mode 100644 Example/SImpleRecieveLEDToggle/SImpleRecieveLEDToggle_p5/SImpleRecieveLEDToggle_p5.pde create mode 100644 Example/loopback/LoopBackSender_P5/LoopBackSender_P5.pde create mode 100644 Example/loopback/loopback.ino create mode 100644 Example/multicallback/multicallback.ino create mode 100644 Example/multicallback/multicallback_p5/multicallback_p5.pde create mode 100644 Example/simplesend/SimpleSend_P5/SimpleSend_P5.pde create mode 100644 Example/simplesend/simplesend.ino create mode 100644 Lisence.txt create mode 100644 OSCArg.cpp create mode 100644 OSCClient.cpp create mode 100644 OSCDecoder.cpp create mode 100644 OSCEncoder.cpp create mode 100644 OSCMessage.cpp create mode 100644 OSCServer.cpp create mode 100644 OSCcommon/OSCArg.h create mode 100644 OSCcommon/OSCClient.h create mode 100644 OSCcommon/OSCDecoder.h create mode 100644 OSCcommon/OSCEncoder.h create mode 100644 OSCcommon/OSCMessage.h create mode 100644 OSCcommon/OSCServer.h create mode 100644 OSCcommon/OSCcommon.h create mode 100644 OSCcommon/Pattern.h create mode 100644 Pattern.cpp create mode 100644 README create mode 100644 keywords.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..496ee2c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store \ No newline at end of file diff --git a/ArdOSC.h b/ArdOSC.h new file mode 100644 index 0000000..17444f8 --- /dev/null +++ b/ArdOSC.h @@ -0,0 +1,60 @@ +/* + + ArdOSC - OSC Library for Arduino. + + This library works with arduino firmware0018. + + 2010/02/01 version 2.0 changed Project OSCClass -> ArdOSC + 2009/03/22 version 1.0.1 add errror process。change Doc. + 2009/03/21 version 1.0.0 + + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2010 recotana( http://recotana.com ) All right reserved + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + + + Thanks "Open Sound Control org" http://opensoundcontrol.org/ + + */ + +#ifndef ArdOSC_h +#define ArdOSC_h + + + + + +#include "OSCCommon/OSCcommon.h" +#include "OSCCommon/OSCMessage.h" + + +#include "OSCCommon/OSCClient.h" +#include "OSCCommon/OSCServer.h" + + + +#endif \ No newline at end of file diff --git a/Example/OSCArguments/OSCArguments.ino b/Example/OSCArguments/OSCArguments.ino new file mode 100644 index 0000000..d0c3cc0 --- /dev/null +++ b/Example/OSCArguments/OSCArguments.ino @@ -0,0 +1,94 @@ +#include +#include + +#include + +byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +byte myIp[] = { 192, 168, 0, 177 }; +int serverPort = 10000; + +int destPort=12000; + +char oscadr[]="/ard/aaa"; + +OSCServer server; +OSCClient client; + + +void setup(){ + +// Serial.begin(19200); + + Ethernet.begin(myMac ,myIp); + server.begin(serverPort); + + //set callback function + server.addCallback(oscadr,&func1); + +} + +void loop(){ + if(server.aviableCheck()>0){ +// Serial.println("alive! "); + } +} + + +void func1(OSCMessage *_mes){ + + logIp(_mes); + logOscAddress(_mes); + + //get source ip address + byte *sourceIp = _mes->getIpAddress(); + + //get 1st argument(int32) + int tmpI=_mes->getArgInt32(0); + + //get 2nd argument(float) + float tmpF=_mes->getArgFloat(1); + + //get 3rd argument(string) + int strSize=_mes->getArgStringSize(2); + char tmpStr[strSize]; //string memory allocation + _mes->getArgString(2,tmpStr); + + + + //create new osc message + OSCMessage newMes; + + //set destination ip address & port no + newMes.setAddress(sourceIp,destPort); + + //set argument + newMes.beginMessage(oscadr); + newMes.addArgInt32(tmpI+1); + newMes.addArgFloat(tmpF+0.1); + newMes.addArgString(tmpStr); + + //send osc message + client.send(&newMes); + +} + + + + +void logIp(OSCMessage *_mes){ + byte *ip = _mes->getIpAddress(); + Serial.print("IP:"); + Serial.print(ip[0],DEC); + Serial.print("."); + Serial.print(ip[1],DEC); + Serial.print("."); + Serial.print(ip[2],DEC); + Serial.print("."); + Serial.print(ip[3],DEC); + Serial.print(" "); +} + +void logOscAddress(OSCMessage *_mes){ + Serial.println(_mes->getOSCAddress()); +} + diff --git a/Example/OSCArguments/OSCArguments_p5/OSCArguments_p5.pde b/Example/OSCArguments/OSCArguments_p5/OSCArguments_p5.pde new file mode 100644 index 0000000..db6636f --- /dev/null +++ b/Example/OSCArguments/OSCArguments_p5/OSCArguments_p5.pde @@ -0,0 +1,60 @@ +/** + * oscP5oscArgument by andreas schlegel + * example shows how to parse incoming osc messages "by hand". + * it is recommended to take a look at oscP5plug for an alternative way to parse messages. + * oscP5 website at http://www.sojamo.de/oscP5 + */ + +import oscP5.*; +import netP5.*; + +OscP5 oscP5; +NetAddress myRemoteLocation; + +int a; +float b; + +void setup() { + background(0); + + oscP5 = new OscP5(this,12000); + + +// myRemoteLocation = new NetAddress("192.168.0.177",10000); + myRemoteLocation = new NetAddress("224.0.0.0",10000); //multicast address + + + a=0; + b=0.0; + +} + +void draw() { + + sender(); + + delay(1000); + +} + +void sender(){ + a+=1; + b+=0.1; + if(a>999) a=0; + if(b>999.0) b=0.0; + + OscMessage myMessage = new OscMessage("/ard/aaa"); + + myMessage.add(a); + myMessage.add(b); + myMessage.add("some text"); + oscP5.send(myMessage, myRemoteLocation); +} + + + +void oscEvent(OscMessage theOscMessage) { + print("### received an osc message."); + + theOscMessage.print(); +} diff --git a/Example/SImpleRecieve/SImpleRecieve.ino b/Example/SImpleRecieve/SImpleRecieve.ino new file mode 100644 index 0000000..419a7e9 --- /dev/null +++ b/Example/SImpleRecieve/SImpleRecieve.ino @@ -0,0 +1,51 @@ +#include +#include + +#include + +byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +byte myIp[] = { 192, 168, 0, 177 }; +int serverPort = 10000; + +int ledPin = 9; + +int t=100; + +OSCServer server; + +void setup(){ + + Serial.begin(19200); + + Ethernet.begin(myMac ,myIp); + server.begin(serverPort); + + //set callback function + server.addCallback("/ard/aaa",&func1); + + pinMode(ledPin, OUTPUT); + +} + +void loop(){ + if(server.aviableCheck()>0){ + // Serial.println("alive! "); + } + + digitalWrite(ledPin, HIGH); + delay(50); + digitalWrite(ledPin, LOW); + delay(t); +} + + +void func1(OSCMessage *_mes){ + + //get 1st argument(int32) + t = _mes->getArgInt32(0); + + + +} + + diff --git a/Example/SImpleRecieve/SimpleRecieve_p5/SimpleRecieve_p5.pde b/Example/SImpleRecieve/SimpleRecieve_p5/SimpleRecieve_p5.pde new file mode 100644 index 0000000..1b57497 --- /dev/null +++ b/Example/SImpleRecieve/SimpleRecieve_p5/SimpleRecieve_p5.pde @@ -0,0 +1,91 @@ +/** + * Mouse Functions. + * + * Click on the box and drag it across the screen. + */ + +import oscP5.*; +import netP5.*; + +OscP5 oscP5; +NetAddress myRemoteLocation; + +int bx; +int by; +int bs = 20; +boolean bover = false; +boolean locked = false; +int bdifx = 0; +int bdify = 0; +int oldv; + +void setup() +{ + size(200, 400); + bx = width/2; + by = height/2; + rectMode(RADIUS); + + oscP5 = new OscP5(this,12000); + myRemoteLocation = new NetAddress("224.0.0.0",10000); + +} + +void draw() +{ + background(0); + + // Test if the cursor is over the box + if (mouseX > bx-bs && mouseX < bx+bs && + mouseY > by-bs && mouseY < by+bs) { + bover = true; + if(!locked) { + stroke(255); + fill(153); + } + } else { + stroke(153); + fill(153); + bover = false; + } + + // Draw the box + rect(bx, by, bs, bs); +} + +void mousePressed() { + if(bover) { + locked = true; + fill(255, 255, 255); + } else { + locked = false; + } +// bdifx = mouseX-bx; + bdify = mouseY-by; + +} + +void mouseDragged() { + if(locked) { + if(mouseY>360) by = 360; + else if(mouseY<30) by = 60; + else by = mouseY-bdify; + print(by+"\n"); + + int value=by; + value = int(value/100)*100; + if(oldv==value) return; + OscMessage myMessage = new OscMessage("/ard/aaa"); + + myMessage.add(value); + oscP5.send(myMessage, myRemoteLocation); + + oldv=value; + } + +} + +void mouseReleased() { + locked = false; +} + diff --git a/Example/SImpleRecieveLEDToggle/SImpleRecieveLEDToggle.ino b/Example/SImpleRecieveLEDToggle/SImpleRecieveLEDToggle.ino new file mode 100644 index 0000000..506f1fa --- /dev/null +++ b/Example/SImpleRecieveLEDToggle/SImpleRecieveLEDToggle.ino @@ -0,0 +1,66 @@ +#include +#include + +#include + +byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +byte myIp[] = { 192, 168, 0, 177 }; +int serverPort = 10000; +int destPort=12000; +int ledPin = 9; + +int flag=0; + +OSCServer server; +OSCClient client; + +void setup(){ + + Serial.begin(19200); + + Ethernet.begin(myMac ,myIp); + server.begin(serverPort); + + //set callback function & oscaddress + server.addCallback("/ard/aaa",&func1); + + pinMode(ledPin, OUTPUT); + +} + +void loop(){ + + if(server.aviableCheck()>0){ + // Serial.println("alive! "); + } + +} + + +void func1(OSCMessage *_mes){ + int value = _mes->getArgInt32(0); + if(value!=1) return; + + //create new osc message + OSCMessage newMes; + + //set destination ip address & port no + newMes.setAddress(_mes->getIpAddress(),destPort); + newMes.beginMessage("/ard/aaa"); + + if(flag==1){ + flag=0; + digitalWrite(ledPin, LOW); + } + else{ + flag=1; + digitalWrite(ledPin, HIGH); + } + newMes.addArgInt32(flag); + + //send osc message + client.send(&newMes); + +} + + diff --git a/Example/SImpleRecieveLEDToggle/SImpleRecieveLEDToggle_p5/SImpleRecieveLEDToggle_p5.pde b/Example/SImpleRecieveLEDToggle/SImpleRecieveLEDToggle_p5/SImpleRecieveLEDToggle_p5.pde new file mode 100644 index 0000000..eab20d6 --- /dev/null +++ b/Example/SImpleRecieveLEDToggle/SImpleRecieveLEDToggle_p5/SImpleRecieveLEDToggle_p5.pde @@ -0,0 +1,55 @@ +/** + * oscP5oscArgument by andreas schlegel + * example shows how to parse incoming osc messages "by hand". + * it is recommended to take a look at oscP5plug for an alternative way to parse messages. + * oscP5 website at http://www.sojamo.de/oscP5 + */ + +import oscP5.*; +import netP5.*; + +OscP5 oscP5; +NetAddress myRemoteLocation; + + +void setup() { + background(0); + + oscP5 = new OscP5(this,12000); + + +// myRemoteLocation = new NetAddress("192.168.0.177",10000); + myRemoteLocation = new NetAddress("224.0.0.0",10000); //multicast address + + +} + +void draw() { + + +} +void mousePressed(){ + println("send!!"); + sender(); +} + +void sender(){ + OscMessage myMessage = new OscMessage("/ard/aaa"); + myMessage.add(1); + oscP5.send(myMessage, myRemoteLocation); +} + + + +void oscEvent(OscMessage theOscMessage) { + print("### received an osc message."); + + theOscMessage.print(); + if(theOscMessage.checkAddrPattern("/ard/aaa")==true) { + if(theOscMessage.checkTypetag("i")) { + int firstValue = theOscMessage.get(0).intValue(); + if(firstValue==1) background(100,100,0); + else background(0,0,0); + } + } +} diff --git a/Example/loopback/LoopBackSender_P5/LoopBackSender_P5.pde b/Example/loopback/LoopBackSender_P5/LoopBackSender_P5.pde new file mode 100644 index 0000000..db6636f --- /dev/null +++ b/Example/loopback/LoopBackSender_P5/LoopBackSender_P5.pde @@ -0,0 +1,60 @@ +/** + * oscP5oscArgument by andreas schlegel + * example shows how to parse incoming osc messages "by hand". + * it is recommended to take a look at oscP5plug for an alternative way to parse messages. + * oscP5 website at http://www.sojamo.de/oscP5 + */ + +import oscP5.*; +import netP5.*; + +OscP5 oscP5; +NetAddress myRemoteLocation; + +int a; +float b; + +void setup() { + background(0); + + oscP5 = new OscP5(this,12000); + + +// myRemoteLocation = new NetAddress("192.168.0.177",10000); + myRemoteLocation = new NetAddress("224.0.0.0",10000); //multicast address + + + a=0; + b=0.0; + +} + +void draw() { + + sender(); + + delay(1000); + +} + +void sender(){ + a+=1; + b+=0.1; + if(a>999) a=0; + if(b>999.0) b=0.0; + + OscMessage myMessage = new OscMessage("/ard/aaa"); + + myMessage.add(a); + myMessage.add(b); + myMessage.add("some text"); + oscP5.send(myMessage, myRemoteLocation); +} + + + +void oscEvent(OscMessage theOscMessage) { + print("### received an osc message."); + + theOscMessage.print(); +} diff --git a/Example/loopback/loopback.ino b/Example/loopback/loopback.ino new file mode 100644 index 0000000..a1bd7c3 --- /dev/null +++ b/Example/loopback/loopback.ino @@ -0,0 +1,89 @@ +#include +#include + +#include + +byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +byte myIp[] = { 192, 168, 0, 177 }; +int serverPort = 10000; + +int destPort=12000; + +OSCServer server; +OSCClient client; + + +void setup(){ + + Serial.begin(19200); + + Ethernet.begin(myMac ,myIp); + server.begin(serverPort); + + //set callback function + server.addCallback("/ard/aaa",&func1); + +} + +void loop(){ + if(server.aviableCheck()>0){ + Serial.println("alive! "); + } +} + + +void func1(OSCMessage *_mes){ + + logIp(_mes); + logOscAddress(_mes); + + //get source ip address + byte *sourceIp = _mes->getIpAddress(); + + //get 1st argument(int32) + int tmpI=_mes->getArgInt32(0); + + //get 2nd argument(float) + float tmpF=_mes->getArgFloat(1); + + //get 3rd argument(string) + int strSize=_mes->getArgStringSize(2); + char tmpStr[strSize]; //string memory allocation + _mes->getArgString(2,tmpStr); + + //create new osc message + OSCMessage newMes; + + //set destination ip address & port no + newMes.setAddress(sourceIp,destPort); + + //set argument + newMes.beginMessage("/ard/aaa"); + newMes.addArgInt32(tmpI+1); + newMes.addArgFloat(tmpF+0.1); + newMes.addArgString(tmpStr); + + //send osc message + client.send(&newMes); + +} + + + + +void logIp(OSCMessage *_mes){ + byte *ip = _mes->getIpAddress(); + Serial.print("IP:"); + Serial.print(ip[0],DEC); + Serial.print("."); + Serial.print(ip[1],DEC); + Serial.print("."); + Serial.print(ip[2],DEC); + Serial.print("."); + Serial.print(ip[3],DEC); + Serial.print(" "); +} +void logOscAddress(OSCMessage *_mes){ + Serial.println(_mes->getOSCAddress()); +} + diff --git a/Example/multicallback/multicallback.ino b/Example/multicallback/multicallback.ino new file mode 100644 index 0000000..3983832 --- /dev/null +++ b/Example/multicallback/multicallback.ino @@ -0,0 +1,135 @@ +#include +#include + +#include + +byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +byte myIp[] = { 192, 168, 0, 177 }; +int serverPort = 10000; + +int destPort=12000; + +OSCServer server; +OSCClient client; + +int v1=0; +int v2=10; +int v3=20; + +void setup(){ + + Serial.begin(19200); + + Ethernet.begin(myMac ,myIp); + server.begin(serverPort); + + //set callback function + server.addCallback("/ard/aaa",&func1); + server.addCallback("/ard/bbb",&func2); + server.addCallback("/ard/abcde",&func3); +} + +void loop(){ + + int result = server.aviableCheck(); + + if(result>0){ + //callback after process + Serial.println("alive! "); + } + +} + + +void func1(OSCMessage *_mes){ +// logMes(_mes); + + //create new osc message + OSCMessage newMes; + + //set destination ip address & port no + newMes.setAddress(_mes->getIpAddress(),destPort); + + if(v1++>1000) v1=0; + //set argument + newMes.beginMessage("/ard/aaa"); + newMes.addArgInt32(v1); + newMes.addArgString("function1!"); + //send osc message + client.send(&newMes); + +} + +void func2(OSCMessage *_mes){ + // logMes(_mes); + + //create new osc message + OSCMessage newMes; + + //set destination ip address & port no + newMes.setAddress(_mes->getIpAddress(),destPort); + + if(v2++>1000) v2=0; + + //set argument + newMes.beginMessage("/ard/bbb"); + newMes.addArgInt32(v2); + newMes.addArgString("function2!"); + + //send osc message + client.send(&newMes); +} + +void func3(OSCMessage *_mes){ + // logMes(_mes); + + //create new osc message + OSCMessage newMes; + + //set destination ip address & port no + newMes.setAddress(_mes->getIpAddress(),destPort); + + if(v3++>1000) v3=0; + + //set argument + newMes.beginMessage("/ard/abcde"); + newMes.addArgInt32(v3); + newMes.addArgString("function3!"); + + //send osc message + client.send(&newMes); + +} + + +void logMes(OSCMessage *_mes){ + logIp(_mes); + logOscAddress(_mes); + + //get source ip address + byte *sourceIp = _mes->getIpAddress(); + + //get 1st argument(string) + int strSize=_mes->getArgStringSize(0); + char tmpStr[strSize]; //string memory allocation + _mes->getArgString(0,tmpStr); + + Serial.println(tmpStr); +} + +void logIp(OSCMessage *_mes){ + byte *ip = _mes->getIpAddress(); + Serial.print("IP:"); + Serial.print(ip[0],DEC); + Serial.print("."); + Serial.print(ip[1],DEC); + Serial.print("."); + Serial.print(ip[2],DEC); + Serial.print("."); + Serial.print(ip[3],DEC); + Serial.print(" "); +} +void logOscAddress(OSCMessage *_mes){ + Serial.println(_mes->getOSCAddress()); +} + diff --git a/Example/multicallback/multicallback_p5/multicallback_p5.pde b/Example/multicallback/multicallback_p5/multicallback_p5.pde new file mode 100644 index 0000000..438c7fe --- /dev/null +++ b/Example/multicallback/multicallback_p5/multicallback_p5.pde @@ -0,0 +1,66 @@ +/** + * oscP5oscArgument by andreas schlegel + * example shows how to parse incoming osc messages "by hand". + * it is recommended to take a look at oscP5plug for an alternative way to parse messages. + * oscP5 website at http://www.sojamo.de/oscP5 + */ + +import oscP5.*; +import netP5.*; + +OscP5 oscP5; +NetAddress myRemoteLocation; + + +void setup() { + background(0); + + oscP5 = new OscP5(this,12000); + + +// myRemoteLocation = new NetAddress("192.168.0.177",10000); + myRemoteLocation = new NetAddress("224.0.0.0",10000); //multicast address + + +} + +void draw() { + println("send1"); + sender1(); + delay(500); + + println("send2"); + sender2(); + delay(500); + + println("send3"); + sender3(); + delay(500); + +} + +void sender1(){ + OscMessage myMessage = new OscMessage("/ard/aaa"); + myMessage.add(1); + oscP5.send(myMessage, myRemoteLocation); +} + +void sender2(){ + OscMessage myMessage = new OscMessage("/ard/bbb"); + myMessage.add("send function2"); + oscP5.send(myMessage, myRemoteLocation); +} + +void sender3(){ + OscMessage myMessage = new OscMessage("/ard/abcde"); + myMessage.add("send function3"); + oscP5.send(myMessage, myRemoteLocation); +} + + + +void oscEvent(OscMessage theOscMessage) { + print("### received an osc message."); + + theOscMessage.print(); +} diff --git a/Example/simplesend/SimpleSend_P5/SimpleSend_P5.pde b/Example/simplesend/SimpleSend_P5/SimpleSend_P5.pde new file mode 100644 index 0000000..f5589a3 --- /dev/null +++ b/Example/simplesend/SimpleSend_P5/SimpleSend_P5.pde @@ -0,0 +1,35 @@ +/** + * oscP5oscArgument by andreas schlegel + * example shows how to parse incoming osc messages "by hand". + * it is recommended to take a look at oscP5plug for an alternative way to parse messages. + * oscP5 website at http://www.sojamo.de/oscP5 + */ + +import oscP5.*; +import netP5.*; + +OscP5 oscP5; +NetAddress myRemoteLocation; + +int a; +float b; + +void setup() { + background(0); + + oscP5 = new OscP5(this,12000); + +} + +void draw() { + +} + + + + +void oscEvent(OscMessage theOscMessage) { + print("### received an osc message."); + + theOscMessage.print(); +} diff --git a/Example/simplesend/simplesend.ino b/Example/simplesend/simplesend.ino new file mode 100644 index 0000000..ac59035 --- /dev/null +++ b/Example/simplesend/simplesend.ino @@ -0,0 +1,81 @@ +#include +#include + +#include + +byte myMac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +byte myIp[] = { 192, 168, 0, 177 }; + + +int destPort=12000; +byte destIp[] = { 192, 168, 0, 2 }; + +OSCClient client; + +//create new osc message +OSCMessage global_mes; + +int v3=10; +float v4=10.0; +char str1[]="simple send 1!"; + +int v1=0; +float v2=0.0; + +void setup(){ + + + Ethernet.begin(myMac ,myIp); + + +} + +void loop(){ + + global_mes.setAddress(destIp,destPort); + + global_mes.beginMessage("/ard/send1"); + global_mes.addArgInt32(v1); + global_mes.addArgFloat(v2); + global_mes.addArgString(str1); + + client.send(&global_mes); + + global_mes.flush(); //object data clear + + delay(500); + + + + send2(); + + delay(500); + + v1++; + v2 += 0.1; + + +} + + + +void send2(){ + //loacal_mes,str is release by out of scope + OSCMessage loacal_mes; + + loacal_mes.setAddress(destIp,destPort); + + loacal_mes.beginMessage("/ard/send2"); + loacal_mes.addArgInt32(v3); + loacal_mes.addArgFloat(v4); + + char str[]="simple send2 !!"; + loacal_mes.addArgString(str); + + client.send(&loacal_mes); + + v3++; + v4 += 0.1; +} + + diff --git a/Lisence.txt b/Lisence.txt new file mode 100644 index 0000000..4f24453 --- /dev/null +++ b/Lisence.txt @@ -0,0 +1,29 @@ + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + + + Thanks "Open Sound Control org" http://opensoundcontrol.org/ \ No newline at end of file diff --git a/OSCArg.cpp b/OSCArg.cpp new file mode 100644 index 0000000..110e3fc --- /dev/null +++ b/OSCArg.cpp @@ -0,0 +1,70 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + +#include "OSCcommon/OSCArg.h" +#include "OSCCommon/OSCMessage.h" +#include +#include + +OSCArg::OSCArg(void){ + _typeTag = 0; + _argData = 0; + _dataSize = 0; + _alignmentSize = 0; +} + +OSCArg::OSCArg(char _tag){ + _typeTag = _tag; + _argData = 0; + _dataSize = 0; + _alignmentSize = 0; +} + + +OSCArg::OSCArg( char _tag , void *_data , uint16_t _size , bool _packSizeCulc ) { + + _typeTag = _tag; + + if( _typeTag == kTagBlob ) _typeTag = _size+4; + else _dataSize = _size; + + if( _packSizeCulc ) _alignmentSize = CULC_ALIGNMENT(_size); + else _alignmentSize = _size; + + if( _size == 0 ) return; + + _argData = calloc( 1, _alignmentSize ); + + memcpy( (uint8_t*)_argData , _data , _size ); + + +} + +OSCArg::~OSCArg(void){ + + if( _typeTag != 0 ) flush(); + +} + +void OSCArg::flush(void){ + + if( _dataSize > 0 ) free(_argData); + + _dataSize = 0; + _alignmentSize = 0; + _typeTag = 0; +} + + + diff --git a/OSCClient.cpp b/OSCClient.cpp new file mode 100644 index 0000000..02c91f2 --- /dev/null +++ b/OSCClient.cpp @@ -0,0 +1,102 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + + + +#include + +#include "OSCCommon/OSCClient.h" + +#include +#include + + +OSCClient::OSCClient(void){ + _sock = MAX_SOCK_NUM; +} + +OSCClient::~OSCClient(void){ + flushSendData(); +} + + +int16_t OSCClient::sockOpen(void){ + + if ( _sock != MAX_SOCK_NUM ) return -1; + + for ( int i = 0 ; i < MAX_SOCK_NUM ; i++ ) { + uint8_t s = W5100.readSnSR(i); + if ( s == SnSR::CLOSED || s == SnSR::FIN_WAIT ) { + _sock = i; + break; + } + } + + if ( _sock == MAX_SOCK_NUM ) return -1; + + socket( _sock, SnMR::UDP , kDummyPortNumber , 0 ); + + return 1; +} + +void OSCClient::sockClose(void){ + + if ( _sock == MAX_SOCK_NUM ) return; + + close(_sock); + + _sock = MAX_SOCK_NUM; + +} + + + +int16_t OSCClient::send(OSCMessage *_message){ + + uint16_t result=0; + + flushSendData(); + + _sendData = ( uint8_t*)calloc( _message->getMessageSize() ,1 ); + + + if( encoder.encode( _message , _sendData ) < 0 ){ + flushSendData(); + return -1; + } + + + if( sockOpen()<0 ) return -1; //socket open check + + + result = sendto( _sock , _sendData , _message->getMessageSize() , _message->getIpAddress(), _message->getPortNumber() ); + + sockClose(); + + flushSendData(); + + return result; + +} + + +void OSCClient::flushSendData(void){ + + free(_sendData); + _sendData=0; + +} + + + diff --git a/OSCDecoder.cpp b/OSCDecoder.cpp new file mode 100644 index 0000000..90aa1f4 --- /dev/null +++ b/OSCDecoder.cpp @@ -0,0 +1,66 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + +#include +#include + +#include "OSCcommon/OSCcommon.h" +#include "OSCcommon/OSCDecoder.h" +#include "OSCcommon/OSCArg.h" + + +int16_t OSCDecoder::decode( OSCMessage::OSCMessage *_newMes , const uint8_t *_binData ){ + + + const uint8_t *packStartPtr = _binData; + + _newMes->beginMessage( (char*)packStartPtr ); + packStartPtr += _newMes->_oscAdrAlignmentSize; + + + + + char *tmpTag = (char*)(packStartPtr+1); + uint8_t argsNum = strlen(tmpTag); + uint16_t typeTagAlignSize = CULC_ALIGNMENT(argsNum+1); + + packStartPtr += typeTagAlignSize; + + + for (uint8_t i=0 ; i< argsNum ; i++) { + + + switch ( tmpTag[i] ) { + + case kTagInt32: + packStartPtr += _newMes->setArgData( kTagInt32 , (void*)packStartPtr , 4 , false ); + break; + + case kTagFloat: + packStartPtr += _newMes->setArgData( kTagFloat , (void*)packStartPtr , 4 , false ); + break; + + case kTagString: + packStartPtr += _newMes->setArgData( kTagString , (void*)packStartPtr , strlen((char*)packStartPtr) , true ); + break; + + default: + break; + } + } + + return 1; + +} + diff --git a/OSCEncoder.cpp b/OSCEncoder.cpp new file mode 100644 index 0000000..a0e7602 --- /dev/null +++ b/OSCEncoder.cpp @@ -0,0 +1,68 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + +#include +#include + +#include "OSCcommon/OSCcommon.h" +#include "OSCCommon/OSCEncoder.h" +#include "OSCCommon/OSCArg.h" + + +int16_t OSCEncoder::encode( OSCMessage::OSCMessage *_newMes ,uint8_t *_binData ){ + + uint8_t *packStartPtr = _binData; + +//=========== OSC Address(String) -> BIN Encode =========== + + memcpy( _binData , _newMes->_oscAddress , _newMes->_oscAdrSize ); + + packStartPtr += _newMes->_oscAdrAlignmentSize; + + +//=========== TypeTag(String) -> BIN Encode =========== + + *packStartPtr = ','; + + for ( uint8_t i=0 ; i<_newMes->_argsNum ; i++ ) packStartPtr[i+1] = _newMes->getArgTypeTag(i); + + packStartPtr += _newMes->_typeTagAlignmentSize; + + +//=========== Auguments -> BIN Encode ================== + + + for ( uint8_t i=0 ; i < _newMes->_argsNum ; i++ ) { + + switch ( _newMes->getArgTypeTag(i) ) { + + case kTagInt32: + case kTagFloat: + case kTagString: + memcpy( packStartPtr, _newMes->_args[i]->_argData, _newMes->getArgAlignmentSize(i) ); + break; + + default: + + break; + + } + packStartPtr += _newMes->getArgAlignmentSize(i); + } + + + return 1; + +} + diff --git a/OSCMessage.cpp b/OSCMessage.cpp new file mode 100644 index 0000000..a6a7e0f --- /dev/null +++ b/OSCMessage.cpp @@ -0,0 +1,261 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + +#include +#include +#include + +#include "OSCcommon/OSCcommon.h" +#include "OSCCommon/OSCMessage.h" + + +OSCMessage::OSCMessage(void) +{ + _oscAddress = NULL; + _oscAdrSize = 0; + _oscAdrAlignmentSize = 0; + _argsNum = 0; + _argsAlignmentSize = 0; + _port = 0; +} + +OSCMessage::OSCMessage(const char *_oscAddr) +{ + _argsNum = 0; + _argsAlignmentSize = 0; + _port = 0; + + setOSCAddress(_oscAddr); +} + +OSCMessage::~OSCMessage(void) +{ + flush(); +} + + +void OSCMessage::flush(void){ + + if ( _oscAdrSize == 0 ) return; + + free(_oscAddress); + _oscAddress = NULL; + _oscAdrSize = 0; + _oscAdrAlignmentSize = 0; + + OSCArg *tmp; + + for ( uint8_t i = 0 ; i<_argsNum ; i++ ){ + tmp = _args[i]; + delete tmp; + } + + _argsNum = 0; + _argsAlignmentSize = 0; + _port = 0; + +} + +void OSCMessage::setAddress(uint8_t *_ipAddr , uint16_t _portNum){ + setIpAddress(_ipAddr); + _port = _portNum; +} + + +void OSCMessage::setIpAddress(uint8_t *_ipAddr){ + memcpy( _ip , _ipAddr , 4 ); +} + +uint8_t* OSCMessage::getIpAddress(void){ + return _ip; +} + + +void OSCMessage::setPortNumber(uint16_t _portNum){ + _port = _portNum; +} + +uint16_t OSCMessage::getPortNumber(){ + return _port; +} + + + +int16_t OSCMessage::setOSCAddress(const char *_address){ + + _oscAdrSize = (uint16_t)strlen(_address); + + if( _oscAdrSize > kMaxOSCAdrCharactor ){ + flush(); + return -1; + } + + if( _oscAddress != NULL ) free(_oscAddress); + + _oscAddress = (char*)calloc(1,_oscAdrSize+1); + strcpy( _oscAddress , _address) ; + + _oscAdrAlignmentSize = CULC_ALIGNMENT(_oscAdrSize); + + return 1; + +} + + +uint16_t OSCMessage::getMessageSize(void){ + return _oscAdrAlignmentSize + _typeTagAlignmentSize + _argsAlignmentSize; +} + +uint16_t OSCMessage::getArgAlignmentSize(uint8_t _index){ + return _args[_index]->_alignmentSize; +} + +char *OSCMessage::getOSCAddress(void){ + return _oscAddress; +} + +int16_t OSCMessage::getArgsNum(void){ + return _argsNum; +} + +char OSCMessage::getArgTypeTag(int16_t _index) { + + if(_index>_argsNum) return -1; + + return _args[_index]->_typeTag; + +} + + +void OSCMessage::swap(uint8_t *data1, uint8_t *data2){ + data1[0] = data2[3]; + data1[1] = data2[2]; + data1[2] = data2[1]; + data1[3] = data2[0]; +} + + + + + + +int16_t OSCMessage::beginMessage(const char *_address){ + flush(); + return setOSCAddress(_address); +} + +int16_t OSCMessage::setArgData(char _type , void *_value , uint8_t _byte,bool _enableAlignment){ + + _args[_argsNum]= new OSCArg( _type , _value , _byte , _enableAlignment ); + + uint16_t alignSize = _args[_argsNum]->_alignmentSize; + + _argsAlignmentSize += alignSize; + + _argsNum++; + + _typeTagAlignmentSize = CULC_ALIGNMENT( _argsNum + 1 ); + + return alignSize; +} + + + + +int16_t OSCMessage::addArgInt32(int32_t _value){ + + if( _argsNum > kMaxAugument ) return -1; + + uint8_t tmpValue[4]; + uint8_t *data = (uint8_t*)&_value; + swap( tmpValue , data ); + + setArgData( kTagInt32 , tmpValue , 4 , false ); + + return 1; + +} + +int32_t OSCMessage::getArgInt32(int16_t _index){ + + if ( _index > _argsNum ) return -1; + + + uint8_t tmpValue[4]; + uint8_t *_bin = (uint8_t*)_args[_index]->_argData; + swap( tmpValue , _bin ); + + return *(int32_t*)tmpValue; +} + + + +#ifdef _USE_FLOAT_ + +int16_t OSCMessage::addArgFloat(float _value){ + + if( _argsNum > kMaxAugument ) return -1; + + uint8_t tmpValue[4]; + uint8_t *data = (uint8_t*)&_value; + swap( tmpValue , data ); + + setArgData( kTagFloat , tmpValue , 4 , false ); + + return 1; +} + +float OSCMessage::getArgFloat(int16_t _index){ + + if ( _index > _argsNum ) return -1; + + + uint8_t tmpValue[4]; + uint8_t *_bin = (uint8_t*)_args[_index]->_argData; + swap( tmpValue , _bin ); + + return *(float*)tmpValue; + +} +#endif + + + +#ifdef _USE_STRING_ +int16_t OSCMessage::addArgString(const char* _value){ + + if (_argsNum > kMaxAugument ) return -1; + + setArgData( kTagString , (void*)_value , strlen(_value) , true ); + + return 1; +} + +int16_t OSCMessage::getArgString(int16_t _index , char *_rcvstr){ + + if ( _index > _argsNum ) return -1; + + strcpy( _rcvstr , (char*)_args[_index]->_argData ); + + return 1; + +} +int16_t OSCMessage::getArgStringSize(int16_t _index){ + + if ( _index > _argsNum ) return -1; + + return _args[_index]->_dataSize+1; +} +#endif + diff --git a/OSCServer.cpp b/OSCServer.cpp new file mode 100644 index 0000000..b5bf724 --- /dev/null +++ b/OSCServer.cpp @@ -0,0 +1,97 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + +#include +#include +#include "OSCcommon/OSCServer.h" +#include "OSCcommon/OSCcommon.h" +#include "OSCCommon/OSCMessage.h" + +#include +#include + + +OSCServer::OSCServer(void){ + _sock = MAX_SOCK_NUM; +} + +OSCServer::~OSCServer(void){ + stop(); + +} + +int16_t OSCServer::begin(uint16_t _recievePort){ + + if ( _sock != MAX_SOCK_NUM ) return -1; + + for (int i = 0 ; i < MAX_SOCK_NUM ; i++) { + uint8_t s = W5100.readSnSR(i); + if ( s == SnSR::CLOSED || s == SnSR::FIN_WAIT ) { + _sock = i; + break; + } + } + + if (_sock == MAX_SOCK_NUM) return -1; + + _port=_recievePort; + + if( socket( _sock , SnMR::UDP , _port, 0 ) ) return -1; + + rcvFlush(); + + return 1; + +} + + +void OSCServer::stop(void){ + + if (_sock == MAX_SOCK_NUM) return; + close(_sock); + _sock = MAX_SOCK_NUM; + +} + +int16_t OSCServer::aviableCheck(void){ + + if( !( W5100.readSnIR(_sock) && SnIR::RECV ) ) return -1; + if( W5100.getRXReceivedSize(_sock) == 0 ) return -1; + + OSCMessage rcvMes; + + if ( recvfrom( _sock , _rcvData , 1 , rcvMes._ip , &rcvMes._port ) > kMaxRecieveData ) return -1; + + if( _decoder.decode( &rcvMes ,_rcvData ) < 0 ) return -1; + + _adrMatch.paternComp(&rcvMes); + + return 1; +} + + + +void OSCServer::rcvFlush(void){ + + uint8_t byte; + + while ( W5100.getRXReceivedSize(_sock) ) recv( _sock , &byte , 1); + +} + + +void OSCServer::addCallback(char *_adr , Pattern::AdrFunc _func ){ + _adrMatch.addOscAddress( _adr , _func ); +} + diff --git a/OSCcommon/OSCArg.h b/OSCcommon/OSCArg.h new file mode 100644 index 0000000..a5ac9dd --- /dev/null +++ b/OSCcommon/OSCArg.h @@ -0,0 +1,51 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + +#ifndef ArdOSC_OSCArg_h +#define ArdOSC_OSCArg_h + +#include "OSCcommon.h" + + +class OSCArg{ + +private: + + char _typeTag; + + void* _argData; + + uint16_t _dataSize; + uint16_t _alignmentSize; + + +public: + + OSCArg(void); + OSCArg(char _tag); + OSCArg(char _tag, void *_data, uint16_t _size, bool _packSizeCulc); + + ~OSCArg(void); + + void flush(void); + + + friend class OSCDecoder; + friend class OSCEncoder; + friend class OSCMessage; + +}; + + +#endif diff --git a/OSCcommon/OSCClient.h b/OSCcommon/OSCClient.h new file mode 100644 index 0000000..10f3687 --- /dev/null +++ b/OSCcommon/OSCClient.h @@ -0,0 +1,56 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + + +#ifndef OSCClient_h +#define OSCClient_h + +#include "OSCcommon.h" +#include "OSCMessage.h" +#include "OSCEncoder.h" + +#define kDummyPortNumber 10000 + + + +class OSCClient{ + +private: + + uint8_t _sock; + + + uint8_t *_sendData; + + OSCEncoder::OSCEncoder encoder; + + int16_t sockOpen(void); + void sockClose(void); + + void flushSendData(void); + + +public: + + OSCClient(void); + ~OSCClient(void); + + + int16_t send( OSCMessage *_message); + + +}; + + +#endif \ No newline at end of file diff --git a/OSCcommon/OSCDecoder.h b/OSCcommon/OSCDecoder.h new file mode 100644 index 0000000..6e2b3df --- /dev/null +++ b/OSCcommon/OSCDecoder.h @@ -0,0 +1,34 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + +#ifndef OSCDecoder_h +#define OSCDecoder_h + + +#include "OSCMessage.h" + +class OSCDecoder{ + +private: + + + int16_t decode( OSCMessage::OSCMessage *_mes ,const uint8_t *_binData ); + +public: + + + friend class OSCServer; +}; + +#endif \ No newline at end of file diff --git a/OSCcommon/OSCEncoder.h b/OSCcommon/OSCEncoder.h new file mode 100644 index 0000000..b21894b --- /dev/null +++ b/OSCcommon/OSCEncoder.h @@ -0,0 +1,36 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + + +#ifndef OSCEncoder_h +#define OSCEncoder_h + + + +#include "OSCMessage.h" + +class OSCEncoder{ + +private: + + int16_t encode( OSCMessage::OSCMessage *mes ,uint8_t *_binData ); + + +public: + + + friend class OSCClient; +}; + +#endif \ No newline at end of file diff --git a/OSCcommon/OSCMessage.h b/OSCcommon/OSCMessage.h new file mode 100644 index 0000000..359fdad --- /dev/null +++ b/OSCcommon/OSCMessage.h @@ -0,0 +1,122 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + + + + +#ifndef OSCMessage_h +#define OSCMessage_h + + +#include "OSCcommon.h" +#include "OSCArg.h" + +#define kTagInt32 'i' +#define kTagFloat 'f' +#define kTagString 's' +#define kTagBlob 'b' + +#define kTagMidi 'm' +#define kTagRgba 'r' + +#define kTagTrue 'T' +#define kTagFalse 'F' + + + + + + +class OSCMessage{ + +private: + + uint8_t _ip[4]; + uint16_t _port; + + char *_oscAddress; + uint16_t _oscAdrSize; + uint16_t _oscAdrAlignmentSize; + + + uint16_t _typeTagAlignmentSize; + uint16_t _argsAlignmentSize; + + uint16_t _argsNum; + + OSCArg * _args[kMaxAugument]; + + + uint16_t getMessageSize(void); + uint16_t getArgAlignmentSize(uint8_t _index); + + int16_t setArgData( char _type , void *_value , uint8_t _byte, bool _enableAlignment ); + void swap(uint8_t *data1, uint8_t *data2); +// void get4ByteData(int16_t _index , uint8_t *_data); + +public: + + OSCMessage(void); + OSCMessage(const char *_oscAddr); + + ~OSCMessage(void); + + + void flush(void); + + void setAddress(uint8_t *_ip , uint16_t _port); + + void setIpAddress( uint8_t *_ip ); + uint8_t* getIpAddress(void); + + void setPortNumber(uint16_t _port); + uint16_t getPortNumber(void); + + int16_t setOSCAddress(const char *_addr); + char * getOSCAddress(void); + + + int16_t beginMessage( const char *_addr); + + int16_t getArgsNum(void); + char getArgTypeTag(int16_t _index); + + int16_t addArgInt32(int32_t _value); + int32_t getArgInt32(int16_t _index); + +#ifdef _USE_FLOAT_ + int16_t addArgFloat(float _value); + float getArgFloat(int16_t _index); +#endif + +#ifdef _USE_STRING_ + int16_t addArgString(const char* _value); + int16_t getArgString(int16_t _index, char *_rcvstr); + int16_t getArgStringSize(int16_t _index); + +#endif + + + + friend class OSCServer; + friend class OSCClient; + friend class OSCDecoder; + friend class OSCEncoder; + friend class Pattern; + + +}; + + +#endif diff --git a/OSCcommon/OSCServer.h b/OSCcommon/OSCServer.h new file mode 100644 index 0000000..8031f36 --- /dev/null +++ b/OSCcommon/OSCServer.h @@ -0,0 +1,57 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + +#ifndef ArdOSC_OSCServer2_h +#define ArdOSC_OSCServer2_h + + +#include "OSCDecoder.h" +#include "Pattern.h" + +class OSCServer{ + +private: + int16_t _sock; + uint16_t _port; + + uint8_t _rcvData[kMaxRecieveData]; + + + OSCDecoder::OSCDecoder _decoder; + Pattern::Pattern _adrMatch; + + + void rcvFlush(void); + + + +public: + + OSCServer(void); + ~OSCServer(void); + + int16_t begin(uint16_t _recievePort); + void stop(void); + + + int16_t aviableCheck(void); + + + //_adr osc address string pointer - "/ard/aaa" + //_func callback function pointer + void addCallback(char *_adr , Pattern::AdrFunc _func ); + +}; + +#endif diff --git a/OSCcommon/OSCcommon.h b/OSCcommon/OSCcommon.h new file mode 100644 index 0000000..ef38bc9 --- /dev/null +++ b/OSCcommon/OSCcommon.h @@ -0,0 +1,43 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + + + +#ifndef OSCcommon_h +#define OSCcommon_h + +extern "C" { +#include +} + +#define kMaxAugument 16 +#define kMaxRecieveData 100 +#define kMaxOSCAdrCharactor 255 + +#define CULC_ALIGNMENT(x) (x+4)&0xfffc + + +//======== user define ============== + +#define _USE_FLOAT_ + +#define _USE_STRING_ + + +//======== user define end ======== + + + + +#endif diff --git a/OSCcommon/Pattern.h b/OSCcommon/Pattern.h new file mode 100644 index 0000000..d43f328 --- /dev/null +++ b/OSCcommon/Pattern.h @@ -0,0 +1,50 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + +#ifndef ArdOSC_patternmatch_h +#define ArdOSC_patternmatch_h + +#define kMaxPatternMatch 50 + +#include "OSCMessage.h" + + + +class Pattern{ + +private: + + typedef void (*AdrFunc)(OSCMessage*); + + AdrFunc adrFunc[kMaxPatternMatch]; + + char *addr[kMaxPatternMatch]; + + uint8_t patternNum; + +public: + + Pattern(); + ~Pattern(); + + void addOscAddress(char *_adr , AdrFunc _func ); + void execFunc(uint8_t _index,OSCMessage *_mes); + + void paternComp(OSCMessage *_mes); + + friend class OSCServer; +}; + + +#endif diff --git a/Pattern.cpp b/Pattern.cpp new file mode 100644 index 0000000..60a6410 --- /dev/null +++ b/Pattern.cpp @@ -0,0 +1,48 @@ +/* + + ArdOSC 2.1 - OSC Library for Arduino. + + -------- Lisence ----------------------------------------------------------- + + ArdOSC + + The MIT License + + Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved + + */ + +#include +#include +#include "OSCcommon/OSCServer.h" +#include "OSCcommon/OSCcommon.h" +#include "OSCCommon/OSCMessage.h" + +#include "OSCCommon/Pattern.h" + + + +Pattern::Pattern(){ + patternNum=0; + +} +Pattern::~Pattern(){ +} + +void Pattern::addOscAddress(char *_adr , AdrFunc _func){ + adrFunc[patternNum] = _func; + addr[patternNum] = _adr; + patternNum++; +} + +void Pattern::execFunc(uint8_t _index,OSCMessage *_mes){ + adrFunc[_index](_mes); +} + +void Pattern::paternComp(OSCMessage *_mes){ + + for (uint8_t i=0 ; i_oscAddress ) == 0 ) execFunc( i , _mes ); + + } +} \ No newline at end of file diff --git a/README b/README new file mode 100644 index 0000000..762312a --- /dev/null +++ b/README @@ -0,0 +1,30 @@ +for Arduino firmware 1.0rc-1 + +tested Arduino Ethernet +http://www.arduino.cc/en/Main/ArduinoBoardEthernet + +Installation +ArdOSC folder into .. + +Mac +~/Documents/Arduino/libraries/ + +Win +MyDocuments\Arduino\libraries\ + +http://www.arduino.cc/en/Hacking/Libraries + + + +=================================================== + + ArdOSC 2.1 - OSC Library for Arduino. + + This library works with arduino firmware0022. + 2011/09/19 version 2.1 added callback function + added osc message argument function + 2010/02/01 version 2.0 changed Project OSCClass -> ArdOSC + 2009/03/22 version 1.0.1 add errror process。change Doc. + 2009/03/21 version 1.0.0 + + diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..a783a4e --- /dev/null +++ b/keywords.txt @@ -0,0 +1,57 @@ +####################################### +# Syntax Coloring Map For ArdOSC +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +OSCClient KEYWORD1 +OSCServer KEYWORD1 +OSCMessage KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + + + +send KEYWORD2 + +begin KEYWORD2 +stop KEYWORD2 +aviableCheck KEYWORD2 +addCallback KEYWORD2 + +flush KEYWORD2 +setAddress KEYWORD2 + +setIpAddress KEYWORD2 +getIpAddress KEYWORD2 + +setPortNumber KEYWORD2 +getPortNumber KEYWORD2 + +setOSCAddress KEYWORD2 +getOSCAddress KEYWORD2 + +beginMessage KEYWORD2 +getArgsNum KEYWORD2 +getArgTypeTag KEYWORD2 + +addArgInt32 KEYWORD2 +getArgInt32 KEYWORD2 + +addArgFloat KEYWORD2 +getArgFloat KEYWORD2 + +addArgString KEYWORD2 +getArgString KEYWORD2 +getArgStringSize KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### + + +