ADC using MODDMA and then sending the sampled value encapsulated in an OSC message
Dependencies: EthernetNetIf mbed
mbedOSC.h@0:c6ffbdc6661d, 2012-06-25 (annotated)
- Committer:
- Wahaj
- Date:
- Mon Jun 25 13:12:34 2012 +0000
- Revision:
- 0:c6ffbdc6661d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wahaj | 0:c6ffbdc6661d | 1 | /* mbed OSC Library |
Wahaj | 0:c6ffbdc6661d | 2 | This is an Open Sound Control library for the mbed, created to be compatible with Recotana's OSCClass library (http://recotana.com) for the |
Wahaj | 0:c6ffbdc6661d | 3 | Arduino with Ethernet shield. It also uses parts of the OSC Transceiver(Sender/Receiver) code by xshige |
Wahaj | 0:c6ffbdc6661d | 4 | written by: Alvaro Cassinelli, October 2011 |
Wahaj | 0:c6ffbdc6661d | 5 | tweaked by: Toby Harris / *spark audio-visual, March 2012 |
Wahaj | 0:c6ffbdc6661d | 6 | |
Wahaj | 0:c6ffbdc6661d | 7 | This library is free software; you can redistribute it and/or |
Wahaj | 0:c6ffbdc6661d | 8 | modify it under the terms of the GNU Lesser General Public |
Wahaj | 0:c6ffbdc6661d | 9 | License version 2.1 as published by the Free Software Foundation. |
Wahaj | 0:c6ffbdc6661d | 10 | Open Sound Control http://opensoundcontrol.org/ |
Wahaj | 0:c6ffbdc6661d | 11 | */ |
Wahaj | 0:c6ffbdc6661d | 12 | |
Wahaj | 0:c6ffbdc6661d | 13 | #ifndef mbedOSC_h |
Wahaj | 0:c6ffbdc6661d | 14 | #define mbedOSC_h |
Wahaj | 0:c6ffbdc6661d | 15 | |
Wahaj | 0:c6ffbdc6661d | 16 | #include "mbed.h" |
Wahaj | 0:c6ffbdc6661d | 17 | #include "EthernetNetIf.h" |
Wahaj | 0:c6ffbdc6661d | 18 | #include "UDPSocket.h" |
Wahaj | 0:c6ffbdc6661d | 19 | |
Wahaj | 0:c6ffbdc6661d | 20 | // setup IP of destination (computer): |
Wahaj | 0:c6ffbdc6661d | 21 | #define DEFAULT_SEND_PORT 12000 |
Wahaj | 0:c6ffbdc6661d | 22 | //Host sendHost(IpAddr(10, 0, 0, 1), DEFAULT_SEND_PORT, NULL); // Send Port |
Wahaj | 0:c6ffbdc6661d | 23 | // set IP of origin of UDP packets - the mbed acts as a SERVER here, and needs to bind the socket to the "client" (the computer) |
Wahaj | 0:c6ffbdc6661d | 24 | #define DEFAULT_RECEIVE_PORT 57130 |
Wahaj | 0:c6ffbdc6661d | 25 | //Host recHost(IpAddr(10, 0, 0, 1), DEFAULT_RECEIVE_PORT, NULL); // Receive Port |
Wahaj | 0:c6ffbdc6661d | 26 | //UDPSocket udpRec,udpSend; |
Wahaj | 0:c6ffbdc6661d | 27 | |
Wahaj | 0:c6ffbdc6661d | 28 | |
Wahaj | 0:c6ffbdc6661d | 29 | #define MAX_ADDRESS 2 |
Wahaj | 0:c6ffbdc6661d | 30 | #define MAX_ARG 2 |
Wahaj | 0:c6ffbdc6661d | 31 | |
Wahaj | 0:c6ffbdc6661d | 32 | #define TYPE_INT 1 |
Wahaj | 0:c6ffbdc6661d | 33 | #define TYPE_FLOAT 2 |
Wahaj | 0:c6ffbdc6661d | 34 | |
Wahaj | 0:c6ffbdc6661d | 35 | |
Wahaj | 0:c6ffbdc6661d | 36 | /** Container class for OSC messages (receiving or sending) |
Wahaj | 0:c6ffbdc6661d | 37 | @note mbedOSC version 0.1 Specification (similar to Recotana's OSCClass library) |
Wahaj | 0:c6ffbdc6661d | 38 | Example of an OSC message: "/mbed/test1, if 50 32.4" |
Wahaj | 0:c6ffbdc6661d | 39 | ie. "Address TypeTag Args" |
Wahaj | 0:c6ffbdc6661d | 40 | Address : max 2 |
Wahaj | 0:c6ffbdc6661d | 41 | "/ard" |
Wahaj | 0:c6ffbdc6661d | 42 | "/ard/output" |
Wahaj | 0:c6ffbdc6661d | 43 | --address[0]="/ard" :max 15character |
Wahaj | 0:c6ffbdc6661d | 44 | --address[1]="/output" :max 15character |
Wahaj | 0:c6ffbdc6661d | 45 | TypeTag : max 2 |
Wahaj | 0:c6ffbdc6661d | 46 | "i" - long or unsigned long |
Wahaj | 0:c6ffbdc6661d | 47 | "f" - double |
Wahaj | 0:c6ffbdc6661d | 48 | arg : max 2 |
Wahaj | 0:c6ffbdc6661d | 49 | (Note: The byte string as seen here is not sent as UDP packet directly - there are no spaces, and arguments are in binary, BIG ENDIAN) |
Wahaj | 0:c6ffbdc6661d | 50 | */ |
Wahaj | 0:c6ffbdc6661d | 51 | class OSCMessage{ |
Wahaj | 0:c6ffbdc6661d | 52 | |
Wahaj | 0:c6ffbdc6661d | 53 | private: |
Wahaj | 0:c6ffbdc6661d | 54 | |
Wahaj | 0:c6ffbdc6661d | 55 | char *address[MAX_ADDRESS]; // these are strings (as char*) |
Wahaj | 0:c6ffbdc6661d | 56 | uint8_t addressNum; // current number of addresses in the message (ex: "/ard/test" --> the number of the addresses is 2) |
Wahaj | 0:c6ffbdc6661d | 57 | |
Wahaj | 0:c6ffbdc6661d | 58 | char typeTag[MAX_ARG]; |
Wahaj | 0:c6ffbdc6661d | 59 | |
Wahaj | 0:c6ffbdc6661d | 60 | void *arg[MAX_ARG]; |
Wahaj | 0:c6ffbdc6661d | 61 | uint8_t argNum; |
Wahaj | 0:c6ffbdc6661d | 62 | |
Wahaj | 0:c6ffbdc6661d | 63 | // Information about the connection: |
Wahaj | 0:c6ffbdc6661d | 64 | //uint8_t ip[4]; |
Wahaj | 0:c6ffbdc6661d | 65 | //uint16_t port; |
Wahaj | 0:c6ffbdc6661d | 66 | Host host; |
Wahaj | 0:c6ffbdc6661d | 67 | |
Wahaj | 0:c6ffbdc6661d | 68 | public: |
Wahaj | 0:c6ffbdc6661d | 69 | /** Create a container for an OSC message to be received or sent */ |
Wahaj | 0:c6ffbdc6661d | 70 | OSCMessage(); |
Wahaj | 0:c6ffbdc6661d | 71 | |
Wahaj | 0:c6ffbdc6661d | 72 | /** Return the IpAddr object */ |
Wahaj | 0:c6ffbdc6661d | 73 | const IpAddr& getIp(); |
Wahaj | 0:c6ffbdc6661d | 74 | /** Return the port */ |
Wahaj | 0:c6ffbdc6661d | 75 | const int& getPort(); |
Wahaj | 0:c6ffbdc6661d | 76 | |
Wahaj | 0:c6ffbdc6661d | 77 | /** Gets the address string of the OSC message |
Wahaj | 0:c6ffbdc6661d | 78 | * |
Wahaj | 0:c6ffbdc6661d | 79 | * @param[in] _index The index of the address string (byte) |
Wahaj | 0:c6ffbdc6661d | 80 | * @return pointer of the address string (char *) |
Wahaj | 0:c6ffbdc6661d | 81 | * @note ex. "/ard/test"<br> |
Wahaj | 0:c6ffbdc6661d | 82 | * getAddress(0) = "/ard"<br> |
Wahaj | 0:c6ffbdc6661d | 83 | * getAddress(1) = "/test" |
Wahaj | 0:c6ffbdc6661d | 84 | * @attention It is maximum number of the addresses is 2<br> |
Wahaj | 0:c6ffbdc6661d | 85 | * In this case "/ard/test1/test2"<br> |
Wahaj | 0:c6ffbdc6661d | 86 | * ignore it after "/test2" |
Wahaj | 0:c6ffbdc6661d | 87 | */ |
Wahaj | 0:c6ffbdc6661d | 88 | char *getAddress(uint8_t _index); //retturn address |
Wahaj | 0:c6ffbdc6661d | 89 | |
Wahaj | 0:c6ffbdc6661d | 90 | /** Gets the TopAddress string of the OSC message (this is just the address with index 0) |
Wahaj | 0:c6ffbdc6661d | 91 | @return pointer of the TopAddress string (char *), i.e. address[0] |
Wahaj | 0:c6ffbdc6661d | 92 | Example: In the case "/ard/test", getTopAddress() = "/ard" (WITH the slash "/") |
Wahaj | 0:c6ffbdc6661d | 93 | */ |
Wahaj | 0:c6ffbdc6661d | 94 | char *getTopAddress(); //return address[0] :"/ard" |
Wahaj | 0:c6ffbdc6661d | 95 | |
Wahaj | 0:c6ffbdc6661d | 96 | /** |
Wahaj | 0:c6ffbdc6661d | 97 | Gets the "SubAddress" string of the OSC message (this is just the address with index 1) |
Wahaj | 0:c6ffbdc6661d | 98 | @return pointer of the SubAddress string (char *), i.e. address[1] |
Wahaj | 0:c6ffbdc6661d | 99 | Example: in the case "/ard/test", getSubAddress() = "/test" (WITH the slash "/") |
Wahaj | 0:c6ffbdc6661d | 100 | */ |
Wahaj | 0:c6ffbdc6661d | 101 | char *getSubAddress(); //return address[1] :"/test" |
Wahaj | 0:c6ffbdc6661d | 102 | |
Wahaj | 0:c6ffbdc6661d | 103 | /** |
Wahaj | 0:c6ffbdc6661d | 104 | Gets the number of the OSC message address |
Wahaj | 0:c6ffbdc6661d | 105 | @return number of the OSC message address (byte) |
Wahaj | 0:c6ffbdc6661d | 106 | Examples: "/ard" --> the number of the addresses is 1 |
Wahaj | 0:c6ffbdc6661d | 107 | "/ard/test" --> the number of the addresses is 2 |
Wahaj | 0:c6ffbdc6661d | 108 | Attention: the maximum number of addresses is 2 (MAX_ADDRESS) |
Wahaj | 0:c6ffbdc6661d | 109 | */ |
Wahaj | 0:c6ffbdc6661d | 110 | uint8_t getAddressNum(); //return 2 |
Wahaj | 0:c6ffbdc6661d | 111 | |
Wahaj | 0:c6ffbdc6661d | 112 | /** |
Wahaj | 0:c6ffbdc6661d | 113 | Gets the TypeTag string (with index) of the OSC message |
Wahaj | 0:c6ffbdc6661d | 114 | @param[in] _index The index of the TypeTag string (byte) |
Wahaj | 0:c6ffbdc6661d | 115 | @return: TypeTag char (char) |
Wahaj | 0:c6ffbdc6661d | 116 | Example: in the case of a total typetag string equal to "if", getTypeTag(0) = 'i' and getTypeTag(1) = 'f' |
Wahaj | 0:c6ffbdc6661d | 117 | Attention: MAX_ARG is maximum number of the args, if the index argument is larger, it will be constrained to this max. |
Wahaj | 0:c6ffbdc6661d | 118 | */ |
Wahaj | 0:c6ffbdc6661d | 119 | char getTypeTag(uint8_t _index); //_index=0 ->'i' |
Wahaj | 0:c6ffbdc6661d | 120 | //_index=1 ->'f' |
Wahaj | 0:c6ffbdc6661d | 121 | |
Wahaj | 0:c6ffbdc6661d | 122 | /** |
Wahaj | 0:c6ffbdc6661d | 123 | Gets the number of the OSC message args |
Wahaj | 0:c6ffbdc6661d | 124 | @return number of the args (byte) |
Wahaj | 0:c6ffbdc6661d | 125 | Example: "i" 123 --> number of the OSC message args is 1 |
Wahaj | 0:c6ffbdc6661d | 126 | "if" 123 54.24 --> number of the OSC message args is 2 |
Wahaj | 0:c6ffbdc6661d | 127 | Attention: the maximum number of args is 2 (MAX_ARG) |
Wahaj | 0:c6ffbdc6661d | 128 | */ |
Wahaj | 0:c6ffbdc6661d | 129 | uint8_t getArgNum(); //return 2 |
Wahaj | 0:c6ffbdc6661d | 130 | |
Wahaj | 0:c6ffbdc6661d | 131 | /** |
Wahaj | 0:c6ffbdc6661d | 132 | Get the args of the OSC message with an integer value |
Wahaj | 0:c6ffbdc6661d | 133 | @param[in] _index An int or uint8_t corresponding to the index of the args (byte) |
Wahaj | 0:c6ffbdc6661d | 134 | @return: integer value (long, or int32_t) |
Wahaj | 0:c6ffbdc6661d | 135 | Example: in the case "if" 123 54.24, getArgInt(0) = 123 |
Wahaj | 0:c6ffbdc6661d | 136 | Noe: "i" is integer, but the return type is "long" |
Wahaj | 0:c6ffbdc6661d | 137 | Note: When a index is bigger than the number of the args, it is set to the number of the args |
Wahaj | 0:c6ffbdc6661d | 138 | */ |
Wahaj | 0:c6ffbdc6661d | 139 | int32_t getArgInt(uint8_t _index); //_index=0 -> 123 |
Wahaj | 0:c6ffbdc6661d | 140 | |
Wahaj | 0:c6ffbdc6661d | 141 | /** |
Wahaj | 0:c6ffbdc6661d | 142 | Get the args of the OSC message with a float value |
Wahaj | 0:c6ffbdc6661d | 143 | @param[in] _index The index of the args |
Wahaj | 0:c6ffbdc6661d | 144 | @return: float value (double) |
Wahaj | 0:c6ffbdc6661d | 145 | note: In this case "if" 123 54.24, getArgFloat(1) = 54.24 |
Wahaj | 0:c6ffbdc6661d | 146 | attention: arg declared as float, but return value cast as "double" |
Wahaj | 0:c6ffbdc6661d | 147 | attention: When index is bigger than the number of the args, it is set to the number of the args |
Wahaj | 0:c6ffbdc6661d | 148 | */ |
Wahaj | 0:c6ffbdc6661d | 149 | double getArgFloat(uint8_t _index); //_index=1 -> 54.21 |
Wahaj | 0:c6ffbdc6661d | 150 | |
Wahaj | 0:c6ffbdc6661d | 151 | |
Wahaj | 0:c6ffbdc6661d | 152 | /** |
Wahaj | 0:c6ffbdc6661d | 153 | Set TopAddress string of OSC Message |
Wahaj | 0:c6ffbdc6661d | 154 | @param[in] _address A string pointer for the TopAddress String (char *). NOTE: is this a good idea? why not pass as const, and do allocation here? |
Wahaj | 0:c6ffbdc6661d | 155 | Example: if the complete address string is "/ard/test", we set the topaddress as follows: char top[]="/ard" (allocation done here!), then setTopAddress(top) |
Wahaj | 0:c6ffbdc6661d | 156 | */ |
Wahaj | 0:c6ffbdc6661d | 157 | void setTopAddress(char *_address); //set address[0] |
Wahaj | 0:c6ffbdc6661d | 158 | |
Wahaj | 0:c6ffbdc6661d | 159 | /** |
Wahaj | 0:c6ffbdc6661d | 160 | Set SubAddress string of the OSC Message |
Wahaj | 0:c6ffbdc6661d | 161 | @param[in] _address A string pointer for the SubAddress String (char *) |
Wahaj | 0:c6ffbdc6661d | 162 | Example: if the complete address string is "/ard/test", we set the subaddress as follows: char sub[]="/test" (allocation done here!), then setSubAddress(sub) |
Wahaj | 0:c6ffbdc6661d | 163 | Attention: we should call first setTopAddress, and then setSubAddress. The order is important. This does not seems like a good idea... |
Wahaj | 0:c6ffbdc6661d | 164 | */ |
Wahaj | 0:c6ffbdc6661d | 165 | void setSubAddress(char *_address); //set address[1] |
Wahaj | 0:c6ffbdc6661d | 166 | |
Wahaj | 0:c6ffbdc6661d | 167 | /** |
Wahaj | 0:c6ffbdc6661d | 168 | Set the complete Address string of the OSC Message (top and sub addresses) |
Wahaj | 0:c6ffbdc6661d | 169 | @param[in] _topAddress, _subAddress The string pointers to top and sub addresses (char *) |
Wahaj | 0:c6ffbdc6661d | 170 | Example: in the case "/ard/test", we need to do: char top[]="/ard", char sub[]="/test", and then setAddress(top,sub) |
Wahaj | 0:c6ffbdc6661d | 171 | Reminder: in this implementation, the maximum number of addresses is MAX_ADDRESS=2 |
Wahaj | 0:c6ffbdc6661d | 172 | */ |
Wahaj | 0:c6ffbdc6661d | 173 | void setAddress(char *_topAddress, |
Wahaj | 0:c6ffbdc6661d | 174 | char *_subAddress); |
Wahaj | 0:c6ffbdc6661d | 175 | |
Wahaj | 0:c6ffbdc6661d | 176 | /** |
Wahaj | 0:c6ffbdc6661d | 177 | Set address string using index (here 0 or 1) |
Wahaj | 0:c6ffbdc6661d | 178 | Example: "/ard/test", char adr[]="/ard", setAddress(0,adr), char adr2[]="/test", setAddress(1,adr) |
Wahaj | 0:c6ffbdc6661d | 179 | */ |
Wahaj | 0:c6ffbdc6661d | 180 | void setAddress(uint8_t _index, //set 0,address[0] |
Wahaj | 0:c6ffbdc6661d | 181 | char *_address); |
Wahaj | 0:c6ffbdc6661d | 182 | //set 1,address[1] |
Wahaj | 0:c6ffbdc6661d | 183 | |
Wahaj | 0:c6ffbdc6661d | 184 | /** |
Wahaj | 0:c6ffbdc6661d | 185 | Set IP Address of the OSC Message (for SENDING messages - for receiving this will be done when receiving something ) |
Wahaj | 0:c6ffbdc6661d | 186 | @param[in] _ip Pointer of IP Address array (byte *) |
Wahaj | 0:c6ffbdc6661d | 187 | Example: IP=192.168.0.99, then we have to do: ip[]={192,168,0,1}, then setIp(ip) |
Wahaj | 0:c6ffbdc6661d | 188 | */ |
Wahaj | 0:c6ffbdc6661d | 189 | void setIp( uint8_t *_ip ); //set ip |
Wahaj | 0:c6ffbdc6661d | 190 | |
Wahaj | 0:c6ffbdc6661d | 191 | /** |
Wahaj | 0:c6ffbdc6661d | 192 | Set IP Address to the OSC Message container (not through pointer) |
Wahaj | 0:c6ffbdc6661d | 193 | Example: IP=192.168.0.99 => setIp(192,168,0,99) |
Wahaj | 0:c6ffbdc6661d | 194 | */ |
Wahaj | 0:c6ffbdc6661d | 195 | void setIp(uint8_t _ip1, //set(192, |
Wahaj | 0:c6ffbdc6661d | 196 | uint8_t _ip2, // 168, |
Wahaj | 0:c6ffbdc6661d | 197 | uint8_t _ip3, // 0, |
Wahaj | 0:c6ffbdc6661d | 198 | uint8_t _ip4); // 100) |
Wahaj | 0:c6ffbdc6661d | 199 | |
Wahaj | 0:c6ffbdc6661d | 200 | /* |
Wahaj | 0:c6ffbdc6661d | 201 | Set PortNo for the OSC Message |
Wahaj | 0:c6ffbdc6661d | 202 | @param[in] _port PortNo (unsigned int) |
Wahaj | 0:c6ffbdc6661d | 203 | @return None |
Wahaj | 0:c6ffbdc6661d | 204 | */ |
Wahaj | 0:c6ffbdc6661d | 205 | void setPort( uint16_t _port ); |
Wahaj | 0:c6ffbdc6661d | 206 | |
Wahaj | 0:c6ffbdc6661d | 207 | /** |
Wahaj | 0:c6ffbdc6661d | 208 | Set TypeTag and args to the OSC Message container |
Wahaj | 0:c6ffbdc6661d | 209 | @param[in] types TypeTag string "i"(integer) or"f"(float) (char *) |
Wahaj | 0:c6ffbdc6661d | 210 | @param[in] ... Pointer of the Args(variable argument) .. |
Wahaj | 0:c6ffbdc6661d | 211 | @Example: |
Wahaj | 0:c6ffbdc6661d | 212 | (1) integer 123: (NOTE: integers are LONG) |
Wahaj | 0:c6ffbdc6661d | 213 | long v1=123; sendMes.setArgs("i",&v1) |
Wahaj | 0:c6ffbdc6661d | 214 | (2)integer:123 and float:52.14 |
Wahaj | 0:c6ffbdc6661d | 215 | long v1=123; double v2=52.14; sendMes.setArgs("if",&v1,&v2) |
Wahaj | 0:c6ffbdc6661d | 216 | Attention: in this implementation, the maximum number of the args is 2 |
Wahaj | 0:c6ffbdc6661d | 217 | (if setArgs("iff",&v1,&v2,&v3), data is ignored after &v3) |
Wahaj | 0:c6ffbdc6661d | 218 | */ |
Wahaj | 0:c6ffbdc6661d | 219 | void setArgs( char *types , ... ); //set ("if",&v1,&v2) |
Wahaj | 0:c6ffbdc6661d | 220 | |
Wahaj | 0:c6ffbdc6661d | 221 | friend class OSCClass; |
Wahaj | 0:c6ffbdc6661d | 222 | |
Wahaj | 0:c6ffbdc6661d | 223 | }; |
Wahaj | 0:c6ffbdc6661d | 224 | |
Wahaj | 0:c6ffbdc6661d | 225 | |
Wahaj | 0:c6ffbdc6661d | 226 | |
Wahaj | 0:c6ffbdc6661d | 227 | /* ==================================== OSCClass for sending and receiving OSC messages using UDP protocol ===================================== */ |
Wahaj | 0:c6ffbdc6661d | 228 | |
Wahaj | 0:c6ffbdc6661d | 229 | #include "UDPSocket.h" |
Wahaj | 0:c6ffbdc6661d | 230 | |
Wahaj | 0:c6ffbdc6661d | 231 | /** Wraps the UDP functions to send and receive OSC messages */ |
Wahaj | 0:c6ffbdc6661d | 232 | class OSCClass { |
Wahaj | 0:c6ffbdc6661d | 233 | |
Wahaj | 0:c6ffbdc6661d | 234 | private: |
Wahaj | 0:c6ffbdc6661d | 235 | |
Wahaj | 0:c6ffbdc6661d | 236 | UDPSocket udpRec,udpSend; |
Wahaj | 0:c6ffbdc6661d | 237 | char rcvBuff[256]; // raw buffer for UDP packets (udpRec.recvfrom( buf, 256, &host ) )) |
Wahaj | 0:c6ffbdc6661d | 238 | int buflength; |
Wahaj | 0:c6ffbdc6661d | 239 | |
Wahaj | 0:c6ffbdc6661d | 240 | OSCMessage *receiverMessage; |
Wahaj | 0:c6ffbdc6661d | 241 | OSCMessage *sendContainer; |
Wahaj | 0:c6ffbdc6661d | 242 | |
Wahaj | 0:c6ffbdc6661d | 243 | char tempAddress[MAX_ADDRESS][16]; |
Wahaj | 0:c6ffbdc6661d | 244 | uint8_t tempArg[MAX_ARG][4]; |
Wahaj | 0:c6ffbdc6661d | 245 | |
Wahaj | 0:c6ffbdc6661d | 246 | void onUDPSocketEvent(UDPSocketEvent e); |
Wahaj | 0:c6ffbdc6661d | 247 | |
Wahaj | 0:c6ffbdc6661d | 248 | void decodePacket( OSCMessage *_mes); // makes OSC message from packet |
Wahaj | 0:c6ffbdc6661d | 249 | |
Wahaj | 0:c6ffbdc6661d | 250 | public: |
Wahaj | 0:c6ffbdc6661d | 251 | |
Wahaj | 0:c6ffbdc6661d | 252 | friend class UDPSocket; |
Wahaj | 0:c6ffbdc6661d | 253 | |
Wahaj | 0:c6ffbdc6661d | 254 | /** Create an object to send and receive OSC messages */ |
Wahaj | 0:c6ffbdc6661d | 255 | OSCClass(); |
Wahaj | 0:c6ffbdc6661d | 256 | |
Wahaj | 0:c6ffbdc6661d | 257 | /** |
Wahaj | 0:c6ffbdc6661d | 258 | This sets "binds" the received message to the receiver container of the communication object |
Wahaj | 0:c6ffbdc6661d | 259 | @param[in] _mes A pointer to the "receiveing" OSC message (OSCMessage *) |
Wahaj | 0:c6ffbdc6661d | 260 | */ |
Wahaj | 0:c6ffbdc6661d | 261 | OSCClass(OSCMessage *_mes); // set the receiver message container |
Wahaj | 0:c6ffbdc6661d | 262 | |
Wahaj | 0:c6ffbdc6661d | 263 | /** |
Wahaj | 0:c6ffbdc6661d | 264 | This initializes the OSC communication object with default receiving port (DEFAULT_REC_PORT) |
Wahaj | 0:c6ffbdc6661d | 265 | */ |
Wahaj | 0:c6ffbdc6661d | 266 | void begin(); |
Wahaj | 0:c6ffbdc6661d | 267 | |
Wahaj | 0:c6ffbdc6661d | 268 | /** |
Wahaj | 0:c6ffbdc6661d | 269 | Initialize an OSC object with arbitrary listening port |
Wahaj | 0:c6ffbdc6661d | 270 | @param[in] _recievePort The listening ("receiving") Port No (unsigned int) |
Wahaj | 0:c6ffbdc6661d | 271 | */ |
Wahaj | 0:c6ffbdc6661d | 272 | void begin(uint16_t _recievePort); |
Wahaj | 0:c6ffbdc6661d | 273 | |
Wahaj | 0:c6ffbdc6661d | 274 | /** |
Wahaj | 0:c6ffbdc6661d | 275 | Stop OSC communication (in fact, only the receiver - the server side) |
Wahaj | 0:c6ffbdc6661d | 276 | */ |
Wahaj | 0:c6ffbdc6661d | 277 | void stop(); |
Wahaj | 0:c6ffbdc6661d | 278 | |
Wahaj | 0:c6ffbdc6661d | 279 | /** |
Wahaj | 0:c6ffbdc6661d | 280 | Returns whether there is new OSC data in the receiver message container. |
Wahaj | 0:c6ffbdc6661d | 281 | */ |
Wahaj | 0:c6ffbdc6661d | 282 | bool newMessage; |
Wahaj | 0:c6ffbdc6661d | 283 | |
Wahaj | 0:c6ffbdc6661d | 284 | /** |
Wahaj | 0:c6ffbdc6661d | 285 | Set a OSC receive message container |
Wahaj | 0:c6ffbdc6661d | 286 | @param[in] _mes Pointer to the OSC receive message container (OSCMessage *) |
Wahaj | 0:c6ffbdc6661d | 287 | */ |
Wahaj | 0:c6ffbdc6661d | 288 | void setReceiveMessage( OSCMessage *_mes ); //set receive OSCmessage container (note: the message has a "host" object from which we get the upd packets) |
Wahaj | 0:c6ffbdc6661d | 289 | |
Wahaj | 0:c6ffbdc6661d | 290 | /** |
Wahaj | 0:c6ffbdc6661d | 291 | Get the received OSC message (note: this is another way to access the message directly from the OSCClass object). |
Wahaj | 0:c6ffbdc6661d | 292 | The advantage is that we will signal that we read the message, and will be able to query if a NEW message arrived |
Wahaj | 0:c6ffbdc6661d | 293 | (Alternatively, one could have a function pointer to pass to the OSC object, that will be called each time a new packet is received: TO DO) |
Wahaj | 0:c6ffbdc6661d | 294 | */ |
Wahaj | 0:c6ffbdc6661d | 295 | OSCMessage *getMessage(); //return received OSCmessage |
Wahaj | 0:c6ffbdc6661d | 296 | |
Wahaj | 0:c6ffbdc6661d | 297 | /** |
Wahaj | 0:c6ffbdc6661d | 298 | Send an OSC Message (message contain the host ip and port where the message data has to be sent) |
Wahaj | 0:c6ffbdc6661d | 299 | @param[in] _mes Pointer to the OSC message container (OSCMessage *) |
Wahaj | 0:c6ffbdc6661d | 300 | */ |
Wahaj | 0:c6ffbdc6661d | 301 | void sendOsc( OSCMessage *_mes ); //set&send OSCmessage (note: it will be sent to the host defined in the message container) |
Wahaj | 0:c6ffbdc6661d | 302 | |
Wahaj | 0:c6ffbdc6661d | 303 | /** |
Wahaj | 0:c6ffbdc6661d | 304 | A function pointer to be set by host program that will be called on receipt of an OSC message |
Wahaj | 0:c6ffbdc6661d | 305 | @code |
Wahaj | 0:c6ffbdc6661d | 306 | osc.messageReceivedCallback.attach(&processOSC); |
Wahaj | 0:c6ffbdc6661d | 307 | @endcode |
Wahaj | 0:c6ffbdc6661d | 308 | */ |
Wahaj | 0:c6ffbdc6661d | 309 | FunctionPointer messageReceivedCallback; |
Wahaj | 0:c6ffbdc6661d | 310 | }; |
Wahaj | 0:c6ffbdc6661d | 311 | |
Wahaj | 0:c6ffbdc6661d | 312 | #endif |