xshige & Radio Junk Box's OSCReceiver modded version(#define INPUT_PORT >> extern) http://mbed.org/users/radiojunkbox/code/KAMUI_OSC-CV_Example/ http://mbed.org/users/xshige/programs/OSCReceiver/
Diff: OSCReceiver.cpp
- Revision:
- 2:6dab18e1eb37
- Parent:
- 1:3d6dc580b565
- Child:
- 3:ff3e4aee583e
--- a/OSCReceiver.cpp Sat Mar 23 11:15:37 2013 +0000 +++ b/OSCReceiver.cpp Thu Oct 16 14:12:42 2014 +0000 @@ -28,58 +28,85 @@ */ +#pragma O3 +#pragma Otime + #include "mbed.h" #include "OSCReceiver.h" // Add by RadioJunkBox 2012/05/16 -// added retrun by casiotone401 2013/03/23 +inline int getOSCmsg(char , union OSCarg); +inline size_t strlength(const char *); + +size_t strlength(const char *s) +{ + size_t len = 0; -int getOSCmsg(char *packet , union OSCarg *msg){ + for(;;) + { + unsigned x = *(unsigned*)s; + if((x & 0xFF) == 0) return len; + if((x & 0xFF00) == 0) return len + 1; + if((x & 0xFF0000) == 0) return len + 2; + if((x & 0xFF000000) == 0) return len + 3; + s += 4, len += 4; + } +} + +int getOSCmsg(const char *packet , union OSCarg *msg) +{ // Caution: the returned result points to packet as blobs or strings (not newly allocatd) - char *p, *typeTag; char c; - + char *p, *typeTag; + static char c; + int n, str1 = 0; + + if(packet[0] != '/') + { + return -1; + } + msg[0].address = packet; // address - msg[1].typeTag = packet+4*(strlen(msg[0].s)/4+1);//typeTag - typeTag=msg[1].s+1; // skip ',' - p= msg[1].s+4*(strlen(msg[1].s)/4+1); + msg[1].typeTag = packet+4*(strlength(msg[0].s)/4+1);//typeTag + typeTag = msg[1].s+1; // skip ',' + p = msg[1].s+4*(strlength(msg[1].s)/4+1); - int str1 = strlen(typeTag); + str1 = strlength(typeTag); - for(int n=0; n<str1; n++) + for(n = 0; n<str1; ++n) { c = typeTag[n]; - if (('s'==c)) { + if (('s' == c)) + { msg[n+2].s=p; - p += 4*(strlen(msg[n+2].s)/4+1); + p += 4*(strlength(msg[n+2].s)/4+1); - } else if (('i'==c)||('f'==c)) { + } else if (('i' == c) || ('f' == c)) { // chang endian (big to little) msg[n+2]._b[3]=p[0]; msg[n+2]._b[2]=p[1]; msg[n+2]._b[1]=p[2]; msg[n+2]._b[0]=p[3]; - p +=4; + p += 4; - } else if ('b'==c) { + } else if ('b' == c) { // chang endian (big to little) // get lenth of blog (copy to msg[n].blog.len) msg[n+2]._b[3]=p[0]; msg[n+2]._b[2]=p[1]; msg[n+2]._b[1]=p[2]; msg[n+2]._b[0]=p[3]; - p +=4; + p += 4; // get ponter of blog (copy to msg[n].blog.p) msg[n+2].blob.p=p; p += 4*(msg[n+2].blob.len/4+1); - break; - } else if ('m'==c) { + } else if ('m' == c) { // get midi data (copy to msg[n].m[]) msg[n+2].m[0]=p[0]; msg[n+2].m[1]=p[1]; msg[n+2].m[2]=p[2]; msg[n+2].m[3]=p[3]; - p +=4; + p += 4; } else { @@ -88,4 +115,4 @@ }; return 1; -} +} \ No newline at end of file