summaryrefslogtreecommitdiff
path: root/Libraries/OSC
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/OSC')
-rw-r--r--Libraries/OSC/OSCEncoder.cpp111
-rw-r--r--Libraries/OSC/OSCEncoder.h34
2 files changed, 145 insertions, 0 deletions
diff --git a/Libraries/OSC/OSCEncoder.cpp b/Libraries/OSC/OSCEncoder.cpp
new file mode 100644
index 0000000..66dd383
--- /dev/null
+++ b/Libraries/OSC/OSCEncoder.cpp
@@ -0,0 +1,111 @@
+/*
+
+ ArdOSC - OSC Library for Arduino.
+
+ -------- Lisence -----------------------------------------------------------
+
+ ArdOSC
+
+ The MIT License
+
+ Copyright (c) 2009 - 2010 recotana( http://recotana.com ) All right reserved
+
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "OSCcommon.h"
+#include "OSCEncoder.h"
+
+
+
+int16_t OSCEncoder::encode( OSCMessage::OSCMessage *mes ,uint8_t *sendData ){
+
+
+ uint8_t *packStartPtr=sendData;
+
+
+//=========== OSC Address(String) -> BIN Encode ===========
+
+ memcpy( sendData ,mes->oscAddress ,mes->oscAdrSize);
+ packStartPtr += mes->oscAdrPacSize;
+ mes->allPackSize = mes->oscAdrPacSize;
+
+//=========== TypeTag(String) -> BIN Encode ===========
+
+ *packStartPtr=',';
+ memcpy(packStartPtr+1 ,mes->typeTag ,mes->argsNum);
+ packStartPtr += mes->typeTagPacSize;
+
+ mes->allPackSize += mes->typeTagPacSize;
+
+
+//=========== Auguments -> BIN Encode ==================
+
+
+ uint8_t *tmpPtr;
+
+ uint32_t tmpInt;
+
+#ifdef _USE_FLOAT_
+ float tmpFloat;
+#endif
+
+#ifdef _USE_STRING_
+ uint16_t strSize;
+#endif
+
+ for (int i=0; i< mes->argsNum; i++) {
+
+ switch ( mes->typeTag[i] ) {
+
+ case 'i':
+
+ tmpInt = mes->getInteger32(i);
+ tmpPtr =(uint8_t*)(&tmpInt);
+
+ *packStartPtr++=*(tmpPtr+3);
+ *packStartPtr++=*(tmpPtr+2);
+ *packStartPtr++=*(tmpPtr+1);
+ *packStartPtr++=*tmpPtr;
+
+ mes->allPackSize += 4;
+ break;
+
+#ifdef _USE_FLOAT_
+ case 'f':
+
+ tmpFloat = mes->getFloat(i);
+ tmpPtr=(uint8_t*)(&tmpFloat);
+
+ *packStartPtr++=*(tmpPtr+3);
+ *packStartPtr++=*(tmpPtr+2);
+ *packStartPtr++=*(tmpPtr+1);
+ *packStartPtr++=*tmpPtr;
+
+ mes->allPackSize += 4;
+ break;
+#endif
+
+#ifdef _USE_STRING_
+ case 's':
+ strSize = strlen(mes->getString(i));
+
+ if(strSize > kMaxStringCharactor){
+
+ DBG_LOGLN("encode max str err");
+ return 1;
+ }
+
+ memcpy( (char*)packStartPtr ,mes->getString(i) ,strSize );
+ packStartPtr += mes->getPackSize(strSize);
+
+ mes->allPackSize += mes->getPackSize(strSize);
+ break;
+#endif
+
+ }
+ }
+ return 0;
+}
diff --git a/Libraries/OSC/OSCEncoder.h b/Libraries/OSC/OSCEncoder.h
new file mode 100644
index 0000000..5361c86
--- /dev/null
+++ b/Libraries/OSC/OSCEncoder.h
@@ -0,0 +1,34 @@
+/*
+
+ ArdOSC - OSC Library for Arduino.
+
+ -------- Lisence -----------------------------------------------------------
+
+ ArdOSC
+
+ The MIT License
+
+ Copyright (c) 2009 - 2010 recotana( http://recotana.com ) All right reserved
+
+ */
+
+
+#ifndef OSCEncoder_h
+#define OSCEncoder_h
+
+
+
+#include "OSCMessage.h"
+
+class OSCEncoder{
+
+private:
+
+
+public:
+
+ int16_t encode( OSCMessage::OSCMessage *mes ,uint8_t *sendData );
+
+};
+
+#endif \ No newline at end of file