![](/media/cache/profiles/68a15b5278e4f7c4c056df9d5f1d3b1f.jpg.50x50_q85.jpg)
save loops
mbedOSC.cpp@0:df6fdd9b99f0, 2014-12-02 (annotated)
- Committer:
- mbedalvaro
- Date:
- Tue Dec 02 04:39:15 2014 +0000
- Revision:
- 0:df6fdd9b99f0
this new version of skinGames will have a function that stops scanning as the laser reaches the same position (i.e., loops) with a certain precision. It is for extracting contours for Takashita project. It can then save on a file or send on osc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:df6fdd9b99f0 | 1 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 2 | mbedOSC.cpp |
mbedalvaro | 0:df6fdd9b99f0 | 3 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 4 | |
mbedalvaro | 0:df6fdd9b99f0 | 5 | #include "mbed.h" |
mbedalvaro | 0:df6fdd9b99f0 | 6 | #include "mbedOSC.h" |
mbedalvaro | 0:df6fdd9b99f0 | 7 | #include "stdarg.h" |
mbedalvaro | 0:df6fdd9b99f0 | 8 | |
mbedalvaro | 0:df6fdd9b99f0 | 9 | OSCMessage::OSCMessage() { |
mbedalvaro | 0:df6fdd9b99f0 | 10 | // Initialize host address and port by default (as if this where the receiver message): |
mbedalvaro | 0:df6fdd9b99f0 | 11 | // host=new Host(IpAddr(10, 0, 0, 1), DEFAULT_RECEIVE_PORT, NULL); |
mbedalvaro | 0:df6fdd9b99f0 | 12 | } |
mbedalvaro | 0:df6fdd9b99f0 | 13 | |
mbedalvaro | 0:df6fdd9b99f0 | 14 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 15 | Set PortNo for the OSC Message |
mbedalvaro | 0:df6fdd9b99f0 | 16 | @param[in] _port PortNo (unsigned int) |
mbedalvaro | 0:df6fdd9b99f0 | 17 | @return None |
mbedalvaro | 0:df6fdd9b99f0 | 18 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 19 | void OSCMessage::setPort(uint16_t _port){ |
mbedalvaro | 0:df6fdd9b99f0 | 20 | host.setPort(_port); |
mbedalvaro | 0:df6fdd9b99f0 | 21 | } |
mbedalvaro | 0:df6fdd9b99f0 | 22 | |
mbedalvaro | 0:df6fdd9b99f0 | 23 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 24 | Set IP Address of the OSC Message (for SENDING messages - for receiving this will be done when receiving something ) |
mbedalvaro | 0:df6fdd9b99f0 | 25 | param[in] <-- _ip pointer of IP Address array (byte *) |
mbedalvaro | 0:df6fdd9b99f0 | 26 | Example: IP=192.168.0.99, then we have to do: ip[]={192,168,0,1}, then setIp(ip) |
mbedalvaro | 0:df6fdd9b99f0 | 27 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 28 | void OSCMessage::setIp(uint8_t *_ip){ |
mbedalvaro | 0:df6fdd9b99f0 | 29 | host.setIp(IpAddr(_ip[0], _ip[1], _ip[2], _ip[3])); |
mbedalvaro | 0:df6fdd9b99f0 | 30 | } |
mbedalvaro | 0:df6fdd9b99f0 | 31 | |
mbedalvaro | 0:df6fdd9b99f0 | 32 | |
mbedalvaro | 0:df6fdd9b99f0 | 33 | /*! |
mbedalvaro | 0:df6fdd9b99f0 | 34 | Set IP Address to the OSC Message container (not through pointer) |
mbedalvaro | 0:df6fdd9b99f0 | 35 | Example: IP=192.168.0.99 => setIp(192,168,0,99) |
mbedalvaro | 0:df6fdd9b99f0 | 36 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 37 | void OSCMessage::setIp( uint8_t _ip1, |
mbedalvaro | 0:df6fdd9b99f0 | 38 | uint8_t _ip2, |
mbedalvaro | 0:df6fdd9b99f0 | 39 | uint8_t _ip3, |
mbedalvaro | 0:df6fdd9b99f0 | 40 | uint8_t _ip4 ){ |
mbedalvaro | 0:df6fdd9b99f0 | 41 | |
mbedalvaro | 0:df6fdd9b99f0 | 42 | host.setIp(IpAddr(_ip1, _ip2, _ip3, _ip4)); |
mbedalvaro | 0:df6fdd9b99f0 | 43 | } |
mbedalvaro | 0:df6fdd9b99f0 | 44 | |
mbedalvaro | 0:df6fdd9b99f0 | 45 | const IpAddr& OSCMessage::getIp(){ |
mbedalvaro | 0:df6fdd9b99f0 | 46 | return host.getIp(); |
mbedalvaro | 0:df6fdd9b99f0 | 47 | } |
mbedalvaro | 0:df6fdd9b99f0 | 48 | |
mbedalvaro | 0:df6fdd9b99f0 | 49 | |
mbedalvaro | 0:df6fdd9b99f0 | 50 | const int& OSCMessage::getPort(){ |
mbedalvaro | 0:df6fdd9b99f0 | 51 | return host.getPort(); |
mbedalvaro | 0:df6fdd9b99f0 | 52 | } |
mbedalvaro | 0:df6fdd9b99f0 | 53 | |
mbedalvaro | 0:df6fdd9b99f0 | 54 | |
mbedalvaro | 0:df6fdd9b99f0 | 55 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 56 | Gets the number of the OSC message address |
mbedalvaro | 0:df6fdd9b99f0 | 57 | param[in] None |
mbedalvaro | 0:df6fdd9b99f0 | 58 | return number of the OSC message address (byte) |
mbedalvaro | 0:df6fdd9b99f0 | 59 | Examples: "/ard" --> the number of the addresses is 1 |
mbedalvaro | 0:df6fdd9b99f0 | 60 | "/ard/test" --> the number of the addresses is 2 |
mbedalvaro | 0:df6fdd9b99f0 | 61 | Attention: the maximum number of addresses is 2 (MAX_ADDRESS) |
mbedalvaro | 0:df6fdd9b99f0 | 62 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 63 | uint8_t OSCMessage::getAddressNum(){ |
mbedalvaro | 0:df6fdd9b99f0 | 64 | |
mbedalvaro | 0:df6fdd9b99f0 | 65 | return addressNum; |
mbedalvaro | 0:df6fdd9b99f0 | 66 | } |
mbedalvaro | 0:df6fdd9b99f0 | 67 | |
mbedalvaro | 0:df6fdd9b99f0 | 68 | |
mbedalvaro | 0:df6fdd9b99f0 | 69 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 70 | Gets the number of the OSC message args |
mbedalvaro | 0:df6fdd9b99f0 | 71 | param[in] None |
mbedalvaro | 0:df6fdd9b99f0 | 72 | return number of the args (byte) |
mbedalvaro | 0:df6fdd9b99f0 | 73 | Example: "i" 123 --> number of the OSC message args is 1 |
mbedalvaro | 0:df6fdd9b99f0 | 74 | "if" 123 54.24 --> number of the OSC message args is 2 |
mbedalvaro | 0:df6fdd9b99f0 | 75 | Attention: the maximum number of args is 2 (MAX_ARG) |
mbedalvaro | 0:df6fdd9b99f0 | 76 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 77 | uint8_t OSCMessage::getArgNum(){ |
mbedalvaro | 0:df6fdd9b99f0 | 78 | |
mbedalvaro | 0:df6fdd9b99f0 | 79 | return argNum; |
mbedalvaro | 0:df6fdd9b99f0 | 80 | } |
mbedalvaro | 0:df6fdd9b99f0 | 81 | |
mbedalvaro | 0:df6fdd9b99f0 | 82 | |
mbedalvaro | 0:df6fdd9b99f0 | 83 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 84 | Gets the address string of the OSC message |
mbedalvaro | 0:df6fdd9b99f0 | 85 | param [in] <-- _index is the index of the address string (byte) |
mbedalvaro | 0:df6fdd9b99f0 | 86 | return pointer of the address string (char *) |
mbedalvaro | 0:df6fdd9b99f0 | 87 | @note ex. "/ard/test"<br> |
mbedalvaro | 0:df6fdd9b99f0 | 88 | getAddress(0) = "/ard"<br> |
mbedalvaro | 0:df6fdd9b99f0 | 89 | getAddress(1) = "/test" |
mbedalvaro | 0:df6fdd9b99f0 | 90 | @attention It is maximum number of the addresses is 2<br> |
mbedalvaro | 0:df6fdd9b99f0 | 91 | In this case "/ard/test1/test2"<br> |
mbedalvaro | 0:df6fdd9b99f0 | 92 | ignore it after "/test2" |
mbedalvaro | 0:df6fdd9b99f0 | 93 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 94 | char * OSCMessage::getAddress(uint8_t _index){ |
mbedalvaro | 0:df6fdd9b99f0 | 95 | if(_index>MAX_ADDRESS) _index=MAX_ADDRESS-1; |
mbedalvaro | 0:df6fdd9b99f0 | 96 | return address[_index]; |
mbedalvaro | 0:df6fdd9b99f0 | 97 | |
mbedalvaro | 0:df6fdd9b99f0 | 98 | } |
mbedalvaro | 0:df6fdd9b99f0 | 99 | |
mbedalvaro | 0:df6fdd9b99f0 | 100 | |
mbedalvaro | 0:df6fdd9b99f0 | 101 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 102 | Gets the TopAddress string of the OSC message (this is just the address with index 0) |
mbedalvaro | 0:df6fdd9b99f0 | 103 | param[in] None |
mbedalvaro | 0:df6fdd9b99f0 | 104 | return pointer of the TopAddress string (char *), i.e. address[0] |
mbedalvaro | 0:df6fdd9b99f0 | 105 | Example: In the case "/ard/test", getTopAddress() = "/ard" (WITH the slash "/") |
mbedalvaro | 0:df6fdd9b99f0 | 106 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 107 | char * OSCMessage::getTopAddress(){ |
mbedalvaro | 0:df6fdd9b99f0 | 108 | |
mbedalvaro | 0:df6fdd9b99f0 | 109 | return getAddress(0); |
mbedalvaro | 0:df6fdd9b99f0 | 110 | |
mbedalvaro | 0:df6fdd9b99f0 | 111 | } |
mbedalvaro | 0:df6fdd9b99f0 | 112 | |
mbedalvaro | 0:df6fdd9b99f0 | 113 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 114 | Gets the "SubAddress" string of the OSC message (this is just the address with index 1) |
mbedalvaro | 0:df6fdd9b99f0 | 115 | param[in] None |
mbedalvaro | 0:df6fdd9b99f0 | 116 | return pointer of the SubAddress string (char *), i.e. address[1] |
mbedalvaro | 0:df6fdd9b99f0 | 117 | Example: in the case "/ard/test", getSubAddress() = "/test" (WITH the slash "/") |
mbedalvaro | 0:df6fdd9b99f0 | 118 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 119 | char * OSCMessage::getSubAddress(){ |
mbedalvaro | 0:df6fdd9b99f0 | 120 | |
mbedalvaro | 0:df6fdd9b99f0 | 121 | return getAddress(1); |
mbedalvaro | 0:df6fdd9b99f0 | 122 | |
mbedalvaro | 0:df6fdd9b99f0 | 123 | } |
mbedalvaro | 0:df6fdd9b99f0 | 124 | |
mbedalvaro | 0:df6fdd9b99f0 | 125 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 126 | Gets the TypeTag string (with index) of the OSC message |
mbedalvaro | 0:df6fdd9b99f0 | 127 | param[in] <--_index is the index of the TypeTag string (byte) |
mbedalvaro | 0:df6fdd9b99f0 | 128 | return: TypeTag char (char) |
mbedalvaro | 0:df6fdd9b99f0 | 129 | Example: in the case of a total typetag string equal to "if", getTypeTag(0) = 'i' and getTypeTag(1) = 'f' |
mbedalvaro | 0:df6fdd9b99f0 | 130 | Attention: MAX_ARG is maximum number of the args, if the index argument is larger, it will be constrained to this max. |
mbedalvaro | 0:df6fdd9b99f0 | 131 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 132 | char OSCMessage::getTypeTag(uint8_t _index){ |
mbedalvaro | 0:df6fdd9b99f0 | 133 | if(_index>MAX_ARG) _index=MAX_ARG-1; |
mbedalvaro | 0:df6fdd9b99f0 | 134 | return typeTag[_index]; |
mbedalvaro | 0:df6fdd9b99f0 | 135 | } |
mbedalvaro | 0:df6fdd9b99f0 | 136 | |
mbedalvaro | 0:df6fdd9b99f0 | 137 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 138 | Get the args of the OSC message with an integer value |
mbedalvaro | 0:df6fdd9b99f0 | 139 | param[in] <--_index is (an int, or uint8_t), corresponding to the index of the args (byte) |
mbedalvaro | 0:df6fdd9b99f0 | 140 | return: integer value (long, or int32_t) |
mbedalvaro | 0:df6fdd9b99f0 | 141 | Example: in the case "if" 123 54.24, getArgInt(0) = 123 |
mbedalvaro | 0:df6fdd9b99f0 | 142 | Noe: "i" is integer, but the return type is "long" |
mbedalvaro | 0:df6fdd9b99f0 | 143 | Note: When a index is bigger than the number of the args, it is set to the number of the args |
mbedalvaro | 0:df6fdd9b99f0 | 144 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 145 | int32_t OSCMessage::getArgInt(uint8_t _index){ |
mbedalvaro | 0:df6fdd9b99f0 | 146 | int32_t *value; |
mbedalvaro | 0:df6fdd9b99f0 | 147 | if(_index > argNum) _index=argNum; |
mbedalvaro | 0:df6fdd9b99f0 | 148 | value = (int32_t *)arg[_index]; // cast to int32_t |
mbedalvaro | 0:df6fdd9b99f0 | 149 | return *value; |
mbedalvaro | 0:df6fdd9b99f0 | 150 | } |
mbedalvaro | 0:df6fdd9b99f0 | 151 | |
mbedalvaro | 0:df6fdd9b99f0 | 152 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 153 | Get the args of the OSC message with a float value |
mbedalvaro | 0:df6fdd9b99f0 | 154 | param[in] <--_index is the index of the args |
mbedalvaro | 0:df6fdd9b99f0 | 155 | return: float value (double) |
mbedalvaro | 0:df6fdd9b99f0 | 156 | note: In this case "if" 123 54.24, getArgFloat(1) = 54.24 |
mbedalvaro | 0:df6fdd9b99f0 | 157 | attention: arg declared as float, but return value cast as "double" |
mbedalvaro | 0:df6fdd9b99f0 | 158 | attention: When index is bigger than the number of the args, it is set to the number of the args |
mbedalvaro | 0:df6fdd9b99f0 | 159 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 160 | double OSCMessage::getArgFloat(uint8_t _index){ |
mbedalvaro | 0:df6fdd9b99f0 | 161 | double *value; |
mbedalvaro | 0:df6fdd9b99f0 | 162 | if(_index > argNum) _index=argNum; |
mbedalvaro | 0:df6fdd9b99f0 | 163 | value = (double *)arg[_index]; |
mbedalvaro | 0:df6fdd9b99f0 | 164 | return *value; |
mbedalvaro | 0:df6fdd9b99f0 | 165 | } |
mbedalvaro | 0:df6fdd9b99f0 | 166 | |
mbedalvaro | 0:df6fdd9b99f0 | 167 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 168 | Set TopAddress string of OSC Message |
mbedalvaro | 0:df6fdd9b99f0 | 169 | param[in] <-- _address is a string pointer for the TopAddress String (char *). NOTE: is this a good idea? why not pass as const, and do allocation here? |
mbedalvaro | 0:df6fdd9b99f0 | 170 | return: None |
mbedalvaro | 0:df6fdd9b99f0 | 171 | Example: if the complete address string is "/ard/test", we set the topaddress as follows: char top[]="/ard" (allocation done here!), then setTopAddress(top) |
mbedalvaro | 0:df6fdd9b99f0 | 172 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 173 | void OSCMessage::setTopAddress(char *_address){ |
mbedalvaro | 0:df6fdd9b99f0 | 174 | address[0]=_address; |
mbedalvaro | 0:df6fdd9b99f0 | 175 | address[1]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 176 | addressNum=1; // Note: this "erases" the subaddress! (is this a good idea?) |
mbedalvaro | 0:df6fdd9b99f0 | 177 | } |
mbedalvaro | 0:df6fdd9b99f0 | 178 | |
mbedalvaro | 0:df6fdd9b99f0 | 179 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 180 | Set SubAddress string of the OSC Message |
mbedalvaro | 0:df6fdd9b99f0 | 181 | param[in] <-- _address is a string pointer for the SubAddress String (char *) |
mbedalvaro | 0:df6fdd9b99f0 | 182 | return: None |
mbedalvaro | 0:df6fdd9b99f0 | 183 | Example: if the complete address string is "/ard/test", we set the subaddress as follows: char sub[]="/test" (allocation done here!), then setSubAddress(sub) |
mbedalvaro | 0:df6fdd9b99f0 | 184 | Attention: we should call first setTopAddress, and then setSubAddress. The order is important. This does not seems like a good idea... |
mbedalvaro | 0:df6fdd9b99f0 | 185 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 186 | void OSCMessage::setSubAddress(char *_address){ |
mbedalvaro | 0:df6fdd9b99f0 | 187 | address[1]=_address; |
mbedalvaro | 0:df6fdd9b99f0 | 188 | addressNum=2; // Note: this assumes the top address was already set! |
mbedalvaro | 0:df6fdd9b99f0 | 189 | } |
mbedalvaro | 0:df6fdd9b99f0 | 190 | |
mbedalvaro | 0:df6fdd9b99f0 | 191 | |
mbedalvaro | 0:df6fdd9b99f0 | 192 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 193 | Set the complete Address string of the OSC Message (top and sub addresses) |
mbedalvaro | 0:df6fdd9b99f0 | 194 | param[in] <-- _topAddress and _subAddress are the string pointers to top and sub addresses (char *) |
mbedalvaro | 0:df6fdd9b99f0 | 195 | return: None |
mbedalvaro | 0:df6fdd9b99f0 | 196 | Example: in the case "/ard/test", we need to do: char top[]="/ard", char sub[]="/test", and then setAddress(top,sub) |
mbedalvaro | 0:df6fdd9b99f0 | 197 | Reminder: in this implementation, the maximum number of addresses is MAX_ADDRESS=2 |
mbedalvaro | 0:df6fdd9b99f0 | 198 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 199 | void OSCMessage::setAddress(char *_topAddress,char *_subAddress){ |
mbedalvaro | 0:df6fdd9b99f0 | 200 | setTopAddress(_topAddress); |
mbedalvaro | 0:df6fdd9b99f0 | 201 | setSubAddress(_subAddress); |
mbedalvaro | 0:df6fdd9b99f0 | 202 | addressNum=2; // (unnecessary...) |
mbedalvaro | 0:df6fdd9b99f0 | 203 | } |
mbedalvaro | 0:df6fdd9b99f0 | 204 | |
mbedalvaro | 0:df6fdd9b99f0 | 205 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 206 | Set address string using index (here 0 or 1) |
mbedalvaro | 0:df6fdd9b99f0 | 207 | Example: "/ard/test", char adr[]="/ard", setAddress(0,adr), char adr2[]="/test", setAddress(1,adr) |
mbedalvaro | 0:df6fdd9b99f0 | 208 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 209 | void OSCMessage::setAddress(uint8_t _index, char *_address){ |
mbedalvaro | 0:df6fdd9b99f0 | 210 | if(_index>MAX_ADDRESS) _index=MAX_ADDRESS-1; |
mbedalvaro | 0:df6fdd9b99f0 | 211 | address[_index]=_address; |
mbedalvaro | 0:df6fdd9b99f0 | 212 | addressNum=_index+1; |
mbedalvaro | 0:df6fdd9b99f0 | 213 | } |
mbedalvaro | 0:df6fdd9b99f0 | 214 | |
mbedalvaro | 0:df6fdd9b99f0 | 215 | |
mbedalvaro | 0:df6fdd9b99f0 | 216 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 217 | Set TypeTag and args to the OSC Message container |
mbedalvaro | 0:df6fdd9b99f0 | 218 | @param[in] types TypeTag string "i"(integer) or"f"(float) (char *) |
mbedalvaro | 0:df6fdd9b99f0 | 219 | @param[in] ... Pointer of the Args(variable argument) .. |
mbedalvaro | 0:df6fdd9b99f0 | 220 | @return None |
mbedalvaro | 0:df6fdd9b99f0 | 221 | @Example: |
mbedalvaro | 0:df6fdd9b99f0 | 222 | (1) integer 123: (NOTE: integers are LONG) |
mbedalvaro | 0:df6fdd9b99f0 | 223 | long v1=123; sendMes.setArgs("i",&v1) |
mbedalvaro | 0:df6fdd9b99f0 | 224 | (2)integer:123 and float:52.14 |
mbedalvaro | 0:df6fdd9b99f0 | 225 | long v1=123; double v2=52.14; sendMes.setArgs("if",&v1,&v2) |
mbedalvaro | 0:df6fdd9b99f0 | 226 | Attention: in this implementation, the maximum number of the args is 2 |
mbedalvaro | 0:df6fdd9b99f0 | 227 | (if setArgs("iff",&v1,&v2,&v3), data is ignored after &v3) |
mbedalvaro | 0:df6fdd9b99f0 | 228 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 229 | void OSCMessage::setArgs(char *types,...){ |
mbedalvaro | 0:df6fdd9b99f0 | 230 | |
mbedalvaro | 0:df6fdd9b99f0 | 231 | va_list argList; |
mbedalvaro | 0:df6fdd9b99f0 | 232 | |
mbedalvaro | 0:df6fdd9b99f0 | 233 | argNum = strlen(types); |
mbedalvaro | 0:df6fdd9b99f0 | 234 | if(argNum>MAX_ARG) argNum=MAX_ARG-1; |
mbedalvaro | 0:df6fdd9b99f0 | 235 | |
mbedalvaro | 0:df6fdd9b99f0 | 236 | va_start( argList, types ); |
mbedalvaro | 0:df6fdd9b99f0 | 237 | for(uint8_t i=0 ; i < argNum ; i++){ |
mbedalvaro | 0:df6fdd9b99f0 | 238 | |
mbedalvaro | 0:df6fdd9b99f0 | 239 | typeTag[i]=types[i]; |
mbedalvaro | 0:df6fdd9b99f0 | 240 | |
mbedalvaro | 0:df6fdd9b99f0 | 241 | switch(types[i]) { |
mbedalvaro | 0:df6fdd9b99f0 | 242 | case 'i': |
mbedalvaro | 0:df6fdd9b99f0 | 243 | arg[i]=(uint32_t *)va_arg(argList, uint32_t *); |
mbedalvaro | 0:df6fdd9b99f0 | 244 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 245 | case 'f': |
mbedalvaro | 0:df6fdd9b99f0 | 246 | arg[i]=va_arg(argList, double *); |
mbedalvaro | 0:df6fdd9b99f0 | 247 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 248 | // case 'b': // blob |
mbedalvaro | 0:df6fdd9b99f0 | 249 | // arg[i]=va_arg(argList, double *); |
mbedalvaro | 0:df6fdd9b99f0 | 250 | // break; |
mbedalvaro | 0:df6fdd9b99f0 | 251 | } |
mbedalvaro | 0:df6fdd9b99f0 | 252 | |
mbedalvaro | 0:df6fdd9b99f0 | 253 | } |
mbedalvaro | 0:df6fdd9b99f0 | 254 | |
mbedalvaro | 0:df6fdd9b99f0 | 255 | } |
mbedalvaro | 0:df6fdd9b99f0 | 256 | |
mbedalvaro | 0:df6fdd9b99f0 | 257 | void OSCMessage::clearArgs() { |
mbedalvaro | 0:df6fdd9b99f0 | 258 | argNum=0; |
mbedalvaro | 0:df6fdd9b99f0 | 259 | } |
mbedalvaro | 0:df6fdd9b99f0 | 260 | |
mbedalvaro | 0:df6fdd9b99f0 | 261 | // ================================================================================================================================================ |
mbedalvaro | 0:df6fdd9b99f0 | 262 | // ==================================== OSCClass for sending and receiving OSC messages using UDP protocol ======================================= |
mbedalvaro | 0:df6fdd9b99f0 | 263 | // ================================================================================================================================================ |
mbedalvaro | 0:df6fdd9b99f0 | 264 | //The class define an object wrapping the UDP functions to send and receive OSC messages |
mbedalvaro | 0:df6fdd9b99f0 | 265 | |
mbedalvaro | 0:df6fdd9b99f0 | 266 | OSCClass::OSCClass(){ |
mbedalvaro | 0:df6fdd9b99f0 | 267 | newMessage=false; |
mbedalvaro | 0:df6fdd9b99f0 | 268 | } |
mbedalvaro | 0:df6fdd9b99f0 | 269 | |
mbedalvaro | 0:df6fdd9b99f0 | 270 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 271 | This sets "binds" the received message to the receiver container of the communication object |
mbedalvaro | 0:df6fdd9b99f0 | 272 | param[in]<--_mes is a pointer to the "receiveing" OSC message (OSCMessage *) |
mbedalvaro | 0:df6fdd9b99f0 | 273 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 274 | OSCClass::OSCClass(OSCMessage *_mes){ |
mbedalvaro | 0:df6fdd9b99f0 | 275 | receiverMessage = _mes; // note: receiverMessage MUST be a pointer to the message, because we will modify things in it |
mbedalvaro | 0:df6fdd9b99f0 | 276 | newMessage=false; |
mbedalvaro | 0:df6fdd9b99f0 | 277 | } |
mbedalvaro | 0:df6fdd9b99f0 | 278 | |
mbedalvaro | 0:df6fdd9b99f0 | 279 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 280 | This initializes the OSC communication object with default receiving port (DEFAULT_REC_PORT) |
mbedalvaro | 0:df6fdd9b99f0 | 281 | param[in]: None |
mbedalvaro | 0:df6fdd9b99f0 | 282 | return: None |
mbedalvaro | 0:df6fdd9b99f0 | 283 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 284 | void OSCClass::begin(void (*pcallbackOnPacketArrival)(UDPSocketEvent)) |
mbedalvaro | 0:df6fdd9b99f0 | 285 | { |
mbedalvaro | 0:df6fdd9b99f0 | 286 | // setup receiver udp socket, as well as callback function: |
mbedalvaro | 0:df6fdd9b99f0 | 287 | udpRec.bind(receiverMessage->host); |
mbedalvaro | 0:df6fdd9b99f0 | 288 | udpRec.setOnEvent(pcallbackOnPacketArrival); // note: onUDPSocketEvent is a member of OSCClass |
mbedalvaro | 0:df6fdd9b99f0 | 289 | } |
mbedalvaro | 0:df6fdd9b99f0 | 290 | |
mbedalvaro | 0:df6fdd9b99f0 | 291 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 292 | Initialize an OSC object with arbitrary listening port |
mbedalvaro | 0:df6fdd9b99f0 | 293 | param[in] <-- _recievePort, is the listening ("receiving") Port No (unsigned int) |
mbedalvaro | 0:df6fdd9b99f0 | 294 | return: None |
mbedalvaro | 0:df6fdd9b99f0 | 295 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 296 | void OSCClass::begin(uint16_t _recievePort, void (*pcallbackOnPacketArrival)(UDPSocketEvent)) |
mbedalvaro | 0:df6fdd9b99f0 | 297 | { |
mbedalvaro | 0:df6fdd9b99f0 | 298 | receiverMessage->host.setPort(_recievePort); |
mbedalvaro | 0:df6fdd9b99f0 | 299 | // setup receiver udp socket, as well as callback function: |
mbedalvaro | 0:df6fdd9b99f0 | 300 | udpRec.bind(receiverMessage->host); |
mbedalvaro | 0:df6fdd9b99f0 | 301 | udpRec.setOnEvent(pcallbackOnPacketArrival); |
mbedalvaro | 0:df6fdd9b99f0 | 302 | } |
mbedalvaro | 0:df6fdd9b99f0 | 303 | |
mbedalvaro | 0:df6fdd9b99f0 | 304 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 305 | Set a OSC receive message container |
mbedalvaro | 0:df6fdd9b99f0 | 306 | param[in] _mes Pointer to the OSC receive message container (OSCMessage *) |
mbedalvaro | 0:df6fdd9b99f0 | 307 | return None |
mbedalvaro | 0:df6fdd9b99f0 | 308 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 309 | void OSCClass::setReceiveMessage(OSCMessage *_mes){ |
mbedalvaro | 0:df6fdd9b99f0 | 310 | receiverMessage = _mes; |
mbedalvaro | 0:df6fdd9b99f0 | 311 | } |
mbedalvaro | 0:df6fdd9b99f0 | 312 | |
mbedalvaro | 0:df6fdd9b99f0 | 313 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 314 | callback function when an upd message arrives (it will be transformed as OSC message) |
mbedalvaro | 0:df6fdd9b99f0 | 315 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 316 | void OSCClass::onUDPSocketEvent(UDPSocketEvent e) |
mbedalvaro | 0:df6fdd9b99f0 | 317 | { |
mbedalvaro | 0:df6fdd9b99f0 | 318 | switch(e) |
mbedalvaro | 0:df6fdd9b99f0 | 319 | { |
mbedalvaro | 0:df6fdd9b99f0 | 320 | case UDPSOCKET_READABLE: //The only event for now |
mbedalvaro | 0:df6fdd9b99f0 | 321 | //char buf[256] = {0}; |
mbedalvaro | 0:df6fdd9b99f0 | 322 | Host auxhost; |
mbedalvaro | 0:df6fdd9b99f0 | 323 | buflength = udpRec.recvfrom( rcvBuff, 256, &auxhost ); // QUESTION: auxhost should be equal to the receiver host I guess... |
mbedalvaro | 0:df6fdd9b99f0 | 324 | if ( buflength > 0 ) { |
mbedalvaro | 0:df6fdd9b99f0 | 325 | //printf("\r\nFrom %d.%d.%d.%d:\r\n", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3]); |
mbedalvaro | 0:df6fdd9b99f0 | 326 | decodePacket(receiverMessage); // convert to OSC message, and save it in receiverMessage |
mbedalvaro | 0:df6fdd9b99f0 | 327 | newMessage=true; |
mbedalvaro | 0:df6fdd9b99f0 | 328 | } |
mbedalvaro | 0:df6fdd9b99f0 | 329 | break; |
mbedalvaro | 0:df6fdd9b99f0 | 330 | } |
mbedalvaro | 0:df6fdd9b99f0 | 331 | } |
mbedalvaro | 0:df6fdd9b99f0 | 332 | |
mbedalvaro | 0:df6fdd9b99f0 | 333 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 334 | Decode UDP packet and save it in the OSCMessage structure |
mbedalvaro | 0:df6fdd9b99f0 | 335 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 336 | void OSCClass::decodePacket( OSCMessage *_mes) { |
mbedalvaro | 0:df6fdd9b99f0 | 337 | |
mbedalvaro | 0:df6fdd9b99f0 | 338 | //uint16_t lenBuff; |
mbedalvaro | 0:df6fdd9b99f0 | 339 | uint8_t d; |
mbedalvaro | 0:df6fdd9b99f0 | 340 | uint8_t messagePos=0; |
mbedalvaro | 0:df6fdd9b99f0 | 341 | uint8_t adrCount=0; |
mbedalvaro | 0:df6fdd9b99f0 | 342 | uint8_t adrMesPos=0; |
mbedalvaro | 0:df6fdd9b99f0 | 343 | uint8_t packetCount=0; |
mbedalvaro | 0:df6fdd9b99f0 | 344 | uint8_t packetPos=4; |
mbedalvaro | 0:df6fdd9b99f0 | 345 | |
mbedalvaro | 0:df6fdd9b99f0 | 346 | |
mbedalvaro | 0:df6fdd9b99f0 | 347 | //W5100.writeSn(socketNo, SnIR, SnIR::RECV); |
mbedalvaro | 0:df6fdd9b99f0 | 348 | //lenBuff=recvfrom(socketNo, rcvBuff, 1, receiverMessage->ip, &receiverMessage->port); |
mbedalvaro | 0:df6fdd9b99f0 | 349 | |
mbedalvaro | 0:df6fdd9b99f0 | 350 | receiverMessage->address[0]=tempAddress[0]; |
mbedalvaro | 0:df6fdd9b99f0 | 351 | |
mbedalvaro | 0:df6fdd9b99f0 | 352 | //(1) address process start ========================================= |
mbedalvaro | 0:df6fdd9b99f0 | 353 | do{ |
mbedalvaro | 0:df6fdd9b99f0 | 354 | d=rcvBuff[messagePos]; |
mbedalvaro | 0:df6fdd9b99f0 | 355 | |
mbedalvaro | 0:df6fdd9b99f0 | 356 | |
mbedalvaro | 0:df6fdd9b99f0 | 357 | if( (d=='/') && (messagePos>0) ){ |
mbedalvaro | 0:df6fdd9b99f0 | 358 | |
mbedalvaro | 0:df6fdd9b99f0 | 359 | if(adrCount<MAX_ADDRESS){ |
mbedalvaro | 0:df6fdd9b99f0 | 360 | tempAddress[adrCount][adrMesPos]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 361 | |
mbedalvaro | 0:df6fdd9b99f0 | 362 | adrCount++; |
mbedalvaro | 0:df6fdd9b99f0 | 363 | adrMesPos=0; |
mbedalvaro | 0:df6fdd9b99f0 | 364 | |
mbedalvaro | 0:df6fdd9b99f0 | 365 | receiverMessage->address[adrCount]=tempAddress[adrCount]; |
mbedalvaro | 0:df6fdd9b99f0 | 366 | } |
mbedalvaro | 0:df6fdd9b99f0 | 367 | |
mbedalvaro | 0:df6fdd9b99f0 | 368 | } |
mbedalvaro | 0:df6fdd9b99f0 | 369 | |
mbedalvaro | 0:df6fdd9b99f0 | 370 | if(adrCount<MAX_ADDRESS){ |
mbedalvaro | 0:df6fdd9b99f0 | 371 | //Added this in to remove the slashes out of final output |
mbedalvaro | 0:df6fdd9b99f0 | 372 | if(d!='/'){ |
mbedalvaro | 0:df6fdd9b99f0 | 373 | tempAddress[adrCount][adrMesPos]=d; |
mbedalvaro | 0:df6fdd9b99f0 | 374 | |
mbedalvaro | 0:df6fdd9b99f0 | 375 | if(packetCount>3) { |
mbedalvaro | 0:df6fdd9b99f0 | 376 | packetCount=0; |
mbedalvaro | 0:df6fdd9b99f0 | 377 | packetPos+=4; |
mbedalvaro | 0:df6fdd9b99f0 | 378 | } |
mbedalvaro | 0:df6fdd9b99f0 | 379 | |
mbedalvaro | 0:df6fdd9b99f0 | 380 | adrMesPos++; |
mbedalvaro | 0:df6fdd9b99f0 | 381 | } |
mbedalvaro | 0:df6fdd9b99f0 | 382 | } |
mbedalvaro | 0:df6fdd9b99f0 | 383 | messagePos++; |
mbedalvaro | 0:df6fdd9b99f0 | 384 | packetCount++; |
mbedalvaro | 0:df6fdd9b99f0 | 385 | |
mbedalvaro | 0:df6fdd9b99f0 | 386 | }while(d!=0); |
mbedalvaro | 0:df6fdd9b99f0 | 387 | |
mbedalvaro | 0:df6fdd9b99f0 | 388 | |
mbedalvaro | 0:df6fdd9b99f0 | 389 | if(adrCount<MAX_ADDRESS) adrCount++; |
mbedalvaro | 0:df6fdd9b99f0 | 390 | receiverMessage->addressNum=adrCount; |
mbedalvaro | 0:df6fdd9b99f0 | 391 | |
mbedalvaro | 0:df6fdd9b99f0 | 392 | messagePos=packetPos; |
mbedalvaro | 0:df6fdd9b99f0 | 393 | |
mbedalvaro | 0:df6fdd9b99f0 | 394 | //(2) type tag process starts ========================================= |
mbedalvaro | 0:df6fdd9b99f0 | 395 | packetCount=0; |
mbedalvaro | 0:df6fdd9b99f0 | 396 | packetPos+=4; |
mbedalvaro | 0:df6fdd9b99f0 | 397 | |
mbedalvaro | 0:df6fdd9b99f0 | 398 | uint8_t typeTagPos=0; |
mbedalvaro | 0:df6fdd9b99f0 | 399 | uint8_t tempArgNum=0; |
mbedalvaro | 0:df6fdd9b99f0 | 400 | |
mbedalvaro | 0:df6fdd9b99f0 | 401 | while(rcvBuff[messagePos]!=0 ){ |
mbedalvaro | 0:df6fdd9b99f0 | 402 | |
mbedalvaro | 0:df6fdd9b99f0 | 403 | if(rcvBuff[messagePos] != ',') { |
mbedalvaro | 0:df6fdd9b99f0 | 404 | |
mbedalvaro | 0:df6fdd9b99f0 | 405 | if(typeTagPos<MAX_ARG){ |
mbedalvaro | 0:df6fdd9b99f0 | 406 | receiverMessage->typeTag[tempArgNum]=rcvBuff[messagePos]; |
mbedalvaro | 0:df6fdd9b99f0 | 407 | tempArgNum++; |
mbedalvaro | 0:df6fdd9b99f0 | 408 | } |
mbedalvaro | 0:df6fdd9b99f0 | 409 | typeTagPos++; |
mbedalvaro | 0:df6fdd9b99f0 | 410 | |
mbedalvaro | 0:df6fdd9b99f0 | 411 | } |
mbedalvaro | 0:df6fdd9b99f0 | 412 | |
mbedalvaro | 0:df6fdd9b99f0 | 413 | packetCount++; |
mbedalvaro | 0:df6fdd9b99f0 | 414 | |
mbedalvaro | 0:df6fdd9b99f0 | 415 | if(packetCount>3) { |
mbedalvaro | 0:df6fdd9b99f0 | 416 | packetCount=0; |
mbedalvaro | 0:df6fdd9b99f0 | 417 | packetPos+=4; |
mbedalvaro | 0:df6fdd9b99f0 | 418 | } |
mbedalvaro | 0:df6fdd9b99f0 | 419 | |
mbedalvaro | 0:df6fdd9b99f0 | 420 | messagePos++; |
mbedalvaro | 0:df6fdd9b99f0 | 421 | } |
mbedalvaro | 0:df6fdd9b99f0 | 422 | |
mbedalvaro | 0:df6fdd9b99f0 | 423 | receiverMessage->argNum=tempArgNum; |
mbedalvaro | 0:df6fdd9b99f0 | 424 | |
mbedalvaro | 0:df6fdd9b99f0 | 425 | messagePos=packetPos; |
mbedalvaro | 0:df6fdd9b99f0 | 426 | |
mbedalvaro | 0:df6fdd9b99f0 | 427 | //(3) tempArg process starts ========================================= |
mbedalvaro | 0:df6fdd9b99f0 | 428 | for(int i=0;i<tempArgNum;i++){ |
mbedalvaro | 0:df6fdd9b99f0 | 429 | |
mbedalvaro | 0:df6fdd9b99f0 | 430 | adrMesPos=3; |
mbedalvaro | 0:df6fdd9b99f0 | 431 | |
mbedalvaro | 0:df6fdd9b99f0 | 432 | receiverMessage->arg[i]=tempArg[i]; |
mbedalvaro | 0:df6fdd9b99f0 | 433 | |
mbedalvaro | 0:df6fdd9b99f0 | 434 | for(int j=0;j<4;j++){ |
mbedalvaro | 0:df6fdd9b99f0 | 435 | |
mbedalvaro | 0:df6fdd9b99f0 | 436 | tempArg[i][adrMesPos]=rcvBuff[messagePos]; |
mbedalvaro | 0:df6fdd9b99f0 | 437 | |
mbedalvaro | 0:df6fdd9b99f0 | 438 | messagePos++; |
mbedalvaro | 0:df6fdd9b99f0 | 439 | adrMesPos--; |
mbedalvaro | 0:df6fdd9b99f0 | 440 | } |
mbedalvaro | 0:df6fdd9b99f0 | 441 | |
mbedalvaro | 0:df6fdd9b99f0 | 442 | } |
mbedalvaro | 0:df6fdd9b99f0 | 443 | |
mbedalvaro | 0:df6fdd9b99f0 | 444 | |
mbedalvaro | 0:df6fdd9b99f0 | 445 | } |
mbedalvaro | 0:df6fdd9b99f0 | 446 | |
mbedalvaro | 0:df6fdd9b99f0 | 447 | |
mbedalvaro | 0:df6fdd9b99f0 | 448 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 449 | Get the received OSC message (note: this is another way to access the message directly from the OSCClass object). |
mbedalvaro | 0:df6fdd9b99f0 | 450 | The advantage is that we will signal that we read the message, and will be able to query if a NEW message arrived |
mbedalvaro | 0:df6fdd9b99f0 | 451 | (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) |
mbedalvaro | 0:df6fdd9b99f0 | 452 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 453 | OSCMessage * OSCClass::getMessage(){ |
mbedalvaro | 0:df6fdd9b99f0 | 454 | newMessage=false; // this indicate the user READ the message |
mbedalvaro | 0:df6fdd9b99f0 | 455 | return receiverMessage; |
mbedalvaro | 0:df6fdd9b99f0 | 456 | } |
mbedalvaro | 0:df6fdd9b99f0 | 457 | |
mbedalvaro | 0:df6fdd9b99f0 | 458 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 459 | Send an OSC Message (message contain the host ip and port where the message data has to be sent) |
mbedalvaro | 0:df6fdd9b99f0 | 460 | param[in] _mes Pointer to the OSC message container (OSCMessage *) |
mbedalvaro | 0:df6fdd9b99f0 | 461 | return None |
mbedalvaro | 0:df6fdd9b99f0 | 462 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 463 | void OSCClass::sendOsc( OSCMessage *_mes ) |
mbedalvaro | 0:df6fdd9b99f0 | 464 | { |
mbedalvaro | 0:df6fdd9b99f0 | 465 | uint8_t lengthEnd; |
mbedalvaro | 0:df6fdd9b99f0 | 466 | uint8_t lengthStart; |
mbedalvaro | 0:df6fdd9b99f0 | 467 | char buff[128]; |
mbedalvaro | 0:df6fdd9b99f0 | 468 | |
mbedalvaro | 0:df6fdd9b99f0 | 469 | sendContainer = _mes; |
mbedalvaro | 0:df6fdd9b99f0 | 470 | |
mbedalvaro | 0:df6fdd9b99f0 | 471 | //バッファ初期値 |
mbedalvaro | 0:df6fdd9b99f0 | 472 | buff[0]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 473 | |
mbedalvaro | 0:df6fdd9b99f0 | 474 | //1) Add name spaces: |
mbedalvaro | 0:df6fdd9b99f0 | 475 | for(int i=0;i<sendContainer->addressNum;i++){ |
mbedalvaro | 0:df6fdd9b99f0 | 476 | |
mbedalvaro | 0:df6fdd9b99f0 | 477 | strcat(buff,sendContainer->address[i]); // note: an address is for instance: "/test" (including the "/") |
mbedalvaro | 0:df6fdd9b99f0 | 478 | |
mbedalvaro | 0:df6fdd9b99f0 | 479 | } |
mbedalvaro | 0:df6fdd9b99f0 | 480 | |
mbedalvaro | 0:df6fdd9b99f0 | 481 | // pad with 0s to align in multiples of 4: |
mbedalvaro | 0:df6fdd9b99f0 | 482 | lengthStart=strlen(buff); |
mbedalvaro | 0:df6fdd9b99f0 | 483 | lengthEnd=lengthStart+(4-(lengthStart%4)); |
mbedalvaro | 0:df6fdd9b99f0 | 484 | for(int i=lengthStart ; i<lengthEnd; i++){ |
mbedalvaro | 0:df6fdd9b99f0 | 485 | buff[i]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 486 | } |
mbedalvaro | 0:df6fdd9b99f0 | 487 | |
mbedalvaro | 0:df6fdd9b99f0 | 488 | lengthStart=lengthEnd; |
mbedalvaro | 0:df6fdd9b99f0 | 489 | |
mbedalvaro | 0:df6fdd9b99f0 | 490 | //2) Add TypeTag: |
mbedalvaro | 0:df6fdd9b99f0 | 491 | buff[lengthEnd++]=','; // Note: type tag is for instance: ",if" |
mbedalvaro | 0:df6fdd9b99f0 | 492 | for(int i=0;i<sendContainer->argNum;i++){ |
mbedalvaro | 0:df6fdd9b99f0 | 493 | buff[lengthEnd++]=sendContainer->typeTag[i]; |
mbedalvaro | 0:df6fdd9b99f0 | 494 | } |
mbedalvaro | 0:df6fdd9b99f0 | 495 | |
mbedalvaro | 0:df6fdd9b99f0 | 496 | // pad with 0s to align in multiples of 4: |
mbedalvaro | 0:df6fdd9b99f0 | 497 | lengthStart=lengthEnd; |
mbedalvaro | 0:df6fdd9b99f0 | 498 | lengthEnd=lengthStart+(4-(lengthStart%4)); |
mbedalvaro | 0:df6fdd9b99f0 | 499 | for(int i=lengthStart ; i<lengthEnd; i++){ |
mbedalvaro | 0:df6fdd9b99f0 | 500 | buff[i]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 501 | } |
mbedalvaro | 0:df6fdd9b99f0 | 502 | |
mbedalvaro | 0:df6fdd9b99f0 | 503 | //3) add argument values (Note: here only big endian, this is, FIRST the MOST SIGNIFICANT BYTE): |
mbedalvaro | 0:df6fdd9b99f0 | 504 | uint8_t *v; |
mbedalvaro | 0:df6fdd9b99f0 | 505 | for(int i=0;i<sendContainer->argNum;i++){ |
mbedalvaro | 0:df6fdd9b99f0 | 506 | uint8_t valuePos=3; |
mbedalvaro | 0:df6fdd9b99f0 | 507 | v=(uint8_t *)sendContainer->arg[i]; |
mbedalvaro | 0:df6fdd9b99f0 | 508 | |
mbedalvaro | 0:df6fdd9b99f0 | 509 | buff[lengthEnd++]=v[valuePos--]; |
mbedalvaro | 0:df6fdd9b99f0 | 510 | buff[lengthEnd++]=v[valuePos--]; |
mbedalvaro | 0:df6fdd9b99f0 | 511 | buff[lengthEnd++]=v[valuePos--]; |
mbedalvaro | 0:df6fdd9b99f0 | 512 | buff[lengthEnd++]=v[valuePos]; |
mbedalvaro | 0:df6fdd9b99f0 | 513 | |
mbedalvaro | 0:df6fdd9b99f0 | 514 | } |
mbedalvaro | 0:df6fdd9b99f0 | 515 | |
mbedalvaro | 0:df6fdd9b99f0 | 516 | //4) Send udp packet: |
mbedalvaro | 0:df6fdd9b99f0 | 517 | //sendto( socketNo, (uint8_t *)buff, lengthEnd, sendContainer->ip, sendContainer->port ); |
mbedalvaro | 0:df6fdd9b99f0 | 518 | udpSend.sendto(buff , lengthEnd, &(sendContainer->host)); |
mbedalvaro | 0:df6fdd9b99f0 | 519 | } |
mbedalvaro | 0:df6fdd9b99f0 | 520 | |
mbedalvaro | 0:df6fdd9b99f0 | 521 | // this is bad, should be integrated on the above, but no time: |
mbedalvaro | 0:df6fdd9b99f0 | 522 | void OSCClass::sendOscBlob( uint8_t * myblob, int sizeblob, OSCMessage *_mes ) |
mbedalvaro | 0:df6fdd9b99f0 | 523 | { |
mbedalvaro | 0:df6fdd9b99f0 | 524 | |
mbedalvaro | 0:df6fdd9b99f0 | 525 | // esto es mamarrachezco: |
mbedalvaro | 0:df6fdd9b99f0 | 526 | sendContainer = _mes; |
mbedalvaro | 0:df6fdd9b99f0 | 527 | |
mbedalvaro | 0:df6fdd9b99f0 | 528 | uint8_t lengthEnd; |
mbedalvaro | 0:df6fdd9b99f0 | 529 | uint8_t lengthStart; |
mbedalvaro | 0:df6fdd9b99f0 | 530 | |
mbedalvaro | 0:df6fdd9b99f0 | 531 | char buff[50+sizeblob]; |
mbedalvaro | 0:df6fdd9b99f0 | 532 | buff[0]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 533 | |
mbedalvaro | 0:df6fdd9b99f0 | 534 | //1) Add name spaces (will be just '/posblob' for the blob) |
mbedalvaro | 0:df6fdd9b99f0 | 535 | strcat(buff,"/posblob"); |
mbedalvaro | 0:df6fdd9b99f0 | 536 | |
mbedalvaro | 0:df6fdd9b99f0 | 537 | // pad with 0s to align in multiples of 4: |
mbedalvaro | 0:df6fdd9b99f0 | 538 | lengthStart=strlen(buff); |
mbedalvaro | 0:df6fdd9b99f0 | 539 | lengthEnd=lengthStart+(4-(lengthStart%4)); |
mbedalvaro | 0:df6fdd9b99f0 | 540 | for(int i=lengthStart ; i<lengthEnd; i++){ |
mbedalvaro | 0:df6fdd9b99f0 | 541 | buff[i]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 542 | } |
mbedalvaro | 0:df6fdd9b99f0 | 543 | |
mbedalvaro | 0:df6fdd9b99f0 | 544 | lengthStart=lengthEnd; |
mbedalvaro | 0:df6fdd9b99f0 | 545 | |
mbedalvaro | 0:df6fdd9b99f0 | 546 | //2) Add TypeTag: |
mbedalvaro | 0:df6fdd9b99f0 | 547 | buff[lengthEnd++]=','; //here type tag is just ",b" (one blob) |
mbedalvaro | 0:df6fdd9b99f0 | 548 | buff[lengthEnd++]='b'; |
mbedalvaro | 0:df6fdd9b99f0 | 549 | |
mbedalvaro | 0:df6fdd9b99f0 | 550 | // pad with 0s to align in multiples of 4: |
mbedalvaro | 0:df6fdd9b99f0 | 551 | lengthStart=lengthEnd; |
mbedalvaro | 0:df6fdd9b99f0 | 552 | lengthEnd=lengthStart+(4-(lengthStart%4)); |
mbedalvaro | 0:df6fdd9b99f0 | 553 | for(int i=lengthStart ; i<lengthEnd; i++){ |
mbedalvaro | 0:df6fdd9b99f0 | 554 | buff[i]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 555 | } |
mbedalvaro | 0:df6fdd9b99f0 | 556 | |
mbedalvaro | 0:df6fdd9b99f0 | 557 | //3) add blob (Note: here it is up to the user to get the values right - big endian?): |
mbedalvaro | 0:df6fdd9b99f0 | 558 | // First the size (as an int32, where the type int32 is a 32-bit big-endian two's complement integer) |
mbedalvaro | 0:df6fdd9b99f0 | 559 | buff[lengthEnd++]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 560 | buff[lengthEnd++]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 561 | buff[lengthEnd++]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 562 | buff[lengthEnd++]=(char)sizeblob; // note: the loops always have less than 255 points... |
mbedalvaro | 0:df6fdd9b99f0 | 563 | // Add blob data: |
mbedalvaro | 0:df6fdd9b99f0 | 564 | memcpy(&(buff[lengthEnd]), myblob, sizeblob); |
mbedalvaro | 0:df6fdd9b99f0 | 565 | // pad with 0s to align in multiples of 4: |
mbedalvaro | 0:df6fdd9b99f0 | 566 | lengthStart=lengthEnd+sizeblob; |
mbedalvaro | 0:df6fdd9b99f0 | 567 | lengthEnd=lengthStart+(4-(lengthStart%4)); |
mbedalvaro | 0:df6fdd9b99f0 | 568 | for(int i=lengthStart ; i<lengthEnd; i++){ |
mbedalvaro | 0:df6fdd9b99f0 | 569 | buff[i]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 570 | } |
mbedalvaro | 0:df6fdd9b99f0 | 571 | |
mbedalvaro | 0:df6fdd9b99f0 | 572 | //4) Send udp packet: |
mbedalvaro | 0:df6fdd9b99f0 | 573 | //sendto( socketNo, (uint8_t *)buff, lengthEnd, sendContainer->ip, sendContainer->port ); |
mbedalvaro | 0:df6fdd9b99f0 | 574 | udpSend.sendto(buff , lengthEnd, &(sendContainer->host)); |
mbedalvaro | 0:df6fdd9b99f0 | 575 | } |
mbedalvaro | 0:df6fdd9b99f0 | 576 | |
mbedalvaro | 0:df6fdd9b99f0 | 577 | // NOT FINISHED!!!! |
mbedalvaro | 0:df6fdd9b99f0 | 578 | void OSCClass::sendOscString( uint8_t * myblob, int sizeblob, OSCMessage *_mes ) |
mbedalvaro | 0:df6fdd9b99f0 | 579 | { |
mbedalvaro | 0:df6fdd9b99f0 | 580 | uint8_t lengthEnd; |
mbedalvaro | 0:df6fdd9b99f0 | 581 | uint8_t lengthStart; |
mbedalvaro | 0:df6fdd9b99f0 | 582 | |
mbedalvaro | 0:df6fdd9b99f0 | 583 | char buff[50+sizeblob]; |
mbedalvaro | 0:df6fdd9b99f0 | 584 | buff[0]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 585 | |
mbedalvaro | 0:df6fdd9b99f0 | 586 | //1) Add name spaces (will be just '/posblob' for the blob) |
mbedalvaro | 0:df6fdd9b99f0 | 587 | strcat(buff,"/posString"); |
mbedalvaro | 0:df6fdd9b99f0 | 588 | |
mbedalvaro | 0:df6fdd9b99f0 | 589 | // pad with 0s to align in multiples of 4: |
mbedalvaro | 0:df6fdd9b99f0 | 590 | lengthStart=strlen(buff); |
mbedalvaro | 0:df6fdd9b99f0 | 591 | lengthEnd=lengthStart+(4-(lengthStart%4)); |
mbedalvaro | 0:df6fdd9b99f0 | 592 | for(int i=lengthStart ; i<lengthEnd; i++){ |
mbedalvaro | 0:df6fdd9b99f0 | 593 | buff[i]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 594 | } |
mbedalvaro | 0:df6fdd9b99f0 | 595 | |
mbedalvaro | 0:df6fdd9b99f0 | 596 | lengthStart=lengthEnd; |
mbedalvaro | 0:df6fdd9b99f0 | 597 | |
mbedalvaro | 0:df6fdd9b99f0 | 598 | //2) Add TypeTag: |
mbedalvaro | 0:df6fdd9b99f0 | 599 | buff[lengthEnd++]=','; //here type tag is just ",b" (one blob) |
mbedalvaro | 0:df6fdd9b99f0 | 600 | buff[lengthEnd++]='s'; |
mbedalvaro | 0:df6fdd9b99f0 | 601 | |
mbedalvaro | 0:df6fdd9b99f0 | 602 | // pad with 0s to align in multiples of 4: |
mbedalvaro | 0:df6fdd9b99f0 | 603 | lengthStart=lengthEnd; |
mbedalvaro | 0:df6fdd9b99f0 | 604 | lengthEnd=lengthStart+(4-(lengthStart%4)); |
mbedalvaro | 0:df6fdd9b99f0 | 605 | for(int i=lengthStart ; i<lengthEnd; i++){ |
mbedalvaro | 0:df6fdd9b99f0 | 606 | buff[i]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 607 | } |
mbedalvaro | 0:df6fdd9b99f0 | 608 | |
mbedalvaro | 0:df6fdd9b99f0 | 609 | // Add blob data: |
mbedalvaro | 0:df6fdd9b99f0 | 610 | memcpy(&(buff[lengthEnd]), myblob, sizeblob); |
mbedalvaro | 0:df6fdd9b99f0 | 611 | // pad with 0s to align in multiples of 4: |
mbedalvaro | 0:df6fdd9b99f0 | 612 | lengthStart=lengthEnd+sizeblob; |
mbedalvaro | 0:df6fdd9b99f0 | 613 | lengthEnd=lengthStart+(4-(lengthStart%4)); |
mbedalvaro | 0:df6fdd9b99f0 | 614 | for(int i=lengthStart ; i<lengthEnd; i++){ |
mbedalvaro | 0:df6fdd9b99f0 | 615 | buff[i]=0; |
mbedalvaro | 0:df6fdd9b99f0 | 616 | } |
mbedalvaro | 0:df6fdd9b99f0 | 617 | |
mbedalvaro | 0:df6fdd9b99f0 | 618 | //4) Send udp packet: |
mbedalvaro | 0:df6fdd9b99f0 | 619 | //sendto( socketNo, (uint8_t *)buff, lengthEnd, sendContainer->ip, sendContainer->port ); |
mbedalvaro | 0:df6fdd9b99f0 | 620 | udpSend.sendto(buff , lengthEnd, &(sendContainer->host)); |
mbedalvaro | 0:df6fdd9b99f0 | 621 | } |
mbedalvaro | 0:df6fdd9b99f0 | 622 | |
mbedalvaro | 0:df6fdd9b99f0 | 623 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 624 | flush a receive buffer |
mbedalvaro | 0:df6fdd9b99f0 | 625 | void OSCClass::flush() { |
mbedalvaro | 0:df6fdd9b99f0 | 626 | while ( available() ){} |
mbedalvaro | 0:df6fdd9b99f0 | 627 | } |
mbedalvaro | 0:df6fdd9b99f0 | 628 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 629 | |
mbedalvaro | 0:df6fdd9b99f0 | 630 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 631 | Stop OSC communication (in fact, only the receiver - the server side) |
mbedalvaro | 0:df6fdd9b99f0 | 632 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 633 | void OSCClass::stop() { |
mbedalvaro | 0:df6fdd9b99f0 | 634 | //close( socketNo ); |
mbedalvaro | 0:df6fdd9b99f0 | 635 | udpSend.resetOnEvent(); // disables callback |
mbedalvaro | 0:df6fdd9b99f0 | 636 | } |
mbedalvaro | 0:df6fdd9b99f0 | 637 | |
mbedalvaro | 0:df6fdd9b99f0 | 638 |