support OSC-string
Fork of OSC by
Diff: mbedOSC.h
- Revision:
- 2:507dea4cc97a
- Parent:
- 1:63b72e393989
- Child:
- 3:f4118f0bc1ab
--- a/mbedOSC.h Fri Jul 26 22:10:20 2013 +0000 +++ b/mbedOSC.h Sun Aug 02 09:56:26 2015 +0000 @@ -10,6 +10,9 @@ Open Sound Control http://opensoundcontrol.org/ */ +#pragma O3 +#pragma Otime + #ifndef mbedOSC_h #define mbedOSC_h @@ -27,10 +30,10 @@ #define MAX_ADDRESS 2 -#define MAX_ARG 2 +#define MAX_ARG 4 #define TYPE_INT 1 -#define TYPE_FLOAT 2 +#define TYPE_FLOAT 2 /** Container class for OSC messages (receiving or sending) @@ -53,12 +56,12 @@ private: char *address[MAX_ADDRESS]; // these are strings (as char*) - uint8_t addressNum; // current number of addresses in the message (ex: "/ard/test" --> the number of the addresses is 2) + uint8_t addressNum; // current number of addresses in the message (ex: "/ard/test" --> the number of the addresses is 2) - char typeTag[MAX_ARG]; + char typeTag[MAX_ARG]; void *arg[MAX_ARG]; - uint8_t argNum; + uint8_t argNum; // Information about the connection: //uint8_t ip[4]; @@ -70,7 +73,7 @@ OSCMessage(); /** Return the IpAddr object */ - const IpAddr& getIp(); + const IpAddr& getIp(); /** Return the port */ const int& getPort(); @@ -107,7 +110,7 @@ "/ard/test" --> the number of the addresses is 2 Attention: the maximum number of addresses is 2 (MAX_ADDRESS) */ - uint8_t getAddressNum(); //return 2 + uint8_t getAddressNum(); //return 2 /** Gets the TypeTag string (with index) of the OSC message @@ -126,17 +129,17 @@ "if" 123 54.24 --> number of the OSC message args is 2 Attention: the maximum number of args is 2 (MAX_ARG) */ - uint8_t getArgNum(); //return 2 + uint8_t getArgNum(); //return 2 /** Get the args of the OSC message with an integer value @param[in] _index An int or uint8_t corresponding to the index of the args (byte) - @return: integer value (long, or int32_t) + @return: integer value (long, or int16_t) Example: in the case "if" 123 54.24, getArgInt(0) = 123 Noe: "i" is integer, but the return type is "long" Note: When a index is bigger than the number of the args, it is set to the number of the args */ - int32_t getArgInt(uint8_t _index); //_index=0 -> 123 + int32_t getArgInt(uint8_t _index); //_index=0 -> 123 /** Get the args of the OSC message with a float value @@ -146,7 +149,7 @@ attention: arg declared as float, but return value cast as "double" attention: When index is bigger than the number of the args, it is set to the number of the args */ - double getArgFloat(uint8_t _index); //_index=1 -> 54.21 + double getArgFloat(uint8_t _index); //_index=1 -> 54.21 /** @@ -217,6 +220,29 @@ (if setArgs("iff",&v1,&v2,&v3), data is ignored after &v3) */ void setArgs( char *types , ... ); //set ("if",&v1,&v2) + + //## Cortex-M is little Endian + /* + based on http://stackoverflow.com/questions/809902/64-bit-ntohl-in-c + + if the system is little endian, it will flip the bits + if the system is big endian, it'll do nothing + */ + template<typename T> + static inline T BigEndian(const T& x) + { + const int one = 1; + const char sig = *(char*)&one; + if (sig == 0) return x; // for big endian machine just return the input + T ret; + int size = sizeof(T); + char* src = (char*)&x + sizeof(T) - 1; + char* dst = (char*)&ret; + while (size-- > 0){ + *dst++ = *src--; + } + return ret; + } friend class OSCClass; @@ -234,7 +260,7 @@ private: UDPSocket udpRec,udpSend; - char rcvBuff[256]; // raw buffer for UDP packets (udpRec.recvfrom( buf, 256, &host ) )) + char rcvBuff[128]; // raw buffer for UDP packets (udpRec.recvfrom( buf, 256, &host ) )) int buflength; OSCMessage *receiverMessage; @@ -307,6 +333,9 @@ @endcode */ FunctionPointer messageReceivedCallback; + + + }; #endif