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/

Dependents:   OSCtoCVConverter

Files at this revision

API Documentation at this revision

Comitter:
casiotone401
Date:
Thu Feb 25 11:21:14 2016 +0000
Parent:
2:6dab18e1eb37
Commit message:
minor change

Changed in this revision

OSCReceiver.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 6dab18e1eb37 -r ff3e4aee583e OSCReceiver.cpp
--- a/OSCReceiver.cpp	Thu Oct 16 14:12:42 2014 +0000
+++ b/OSCReceiver.cpp	Thu Feb 25 11:21:14 2016 +0000
@@ -52,12 +52,11 @@
     }
 }
     
-int getOSCmsg(const char *packet , union OSCarg *msg)
+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; 
-    static char c;
-    int n, str1 = 0;
+    uint8_t n, str1 = 0;
     
     if(packet[0] != '/')
     {
@@ -65,52 +64,60 @@
     }
     
     msg[0].address = packet; // address
-    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);
+    msg[1].typeTag = packet + (((strlength(msg[0].s) >> 2) + 1) << 2);//typeTag
+    typeTag = msg[1].s + 1;   // skip ','
+    p = msg[1].s + (((strlength(msg[1].s) >> 2) + 1) << 2);
     
     str1 = strlength(typeTag);
-    
-    for(n = 0; n<str1; ++n)
+        
+    for(n = 0; n < str1; ++n)
     {
-        c = typeTag[n];
-        
-        if (('s' == c)) 
+        switch (typeTag[n])
         {
-            msg[n+2].s=p;
-            p += 4*(strlength(msg[n+2].s)/4+1);
-            
-        } 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;
+            case 's':
+                msg[n+2].s = p;
+                p += (((strlength(msg[n+2].s) >> 2) + 1) << 2);
+                break;
+        
+            case 'i':
+            case 'f':
+                // 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;
+                break;
+                
+            case 'b':
+                // 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;  
+                // get ponter of blog (copy to msg[n].blog.p)
+                msg[n+2].blob.p = p;
+        
+                p += (((msg[n+2].blob.len >> 2) + 1) << 2);
+                break;
+        
+            case 'm':
+                // 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; 
+                break;
             
-        } 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;  
-            // 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);
+            default:
+                return -1;
             
-        } 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; 
-            
-        } else {
-            
-            return -1;
         }
     };