ADC using MODDMA and then sending the sampled value encapsulated in an OSC message

Dependencies:   EthernetNetIf mbed

Committer:
Wahaj
Date:
Mon Jun 25 13:13:42 2012 +0000
Revision:
1:887b266205f3
Parent:
0:c6ffbdc6661d

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wahaj 0:c6ffbdc6661d 1 /*
Wahaj 0:c6ffbdc6661d 2 mbedOSC.cpp
Wahaj 0:c6ffbdc6661d 3 */
Wahaj 0:c6ffbdc6661d 4
Wahaj 0:c6ffbdc6661d 5 #include "mbed.h"
Wahaj 0:c6ffbdc6661d 6 #include "mbedOSC.h"
Wahaj 0:c6ffbdc6661d 7 #include "stdarg.h"
Wahaj 0:c6ffbdc6661d 8
Wahaj 0:c6ffbdc6661d 9 OSCMessage::OSCMessage() {
Wahaj 0:c6ffbdc6661d 10 // Initialize host address and port by default (as if this where the receiver message):
Wahaj 0:c6ffbdc6661d 11 // host=new Host(IpAddr(10, 0, 0, 1), DEFAULT_RECEIVE_PORT, NULL);
Wahaj 0:c6ffbdc6661d 12 }
Wahaj 0:c6ffbdc6661d 13
Wahaj 0:c6ffbdc6661d 14 void OSCMessage::setPort(uint16_t _port){
Wahaj 0:c6ffbdc6661d 15 host.setPort(_port);
Wahaj 0:c6ffbdc6661d 16 }
Wahaj 0:c6ffbdc6661d 17
Wahaj 0:c6ffbdc6661d 18
Wahaj 0:c6ffbdc6661d 19 void OSCMessage::setIp(uint8_t *_ip){
Wahaj 0:c6ffbdc6661d 20 host.setIp(IpAddr(_ip[0], _ip[1], _ip[2], _ip[3]));
Wahaj 0:c6ffbdc6661d 21 }
Wahaj 0:c6ffbdc6661d 22
Wahaj 0:c6ffbdc6661d 23
Wahaj 0:c6ffbdc6661d 24
Wahaj 0:c6ffbdc6661d 25 void OSCMessage::setIp( uint8_t _ip1,
Wahaj 0:c6ffbdc6661d 26 uint8_t _ip2,
Wahaj 0:c6ffbdc6661d 27 uint8_t _ip3,
Wahaj 0:c6ffbdc6661d 28 uint8_t _ip4 ){
Wahaj 0:c6ffbdc6661d 29
Wahaj 0:c6ffbdc6661d 30 host.setIp(IpAddr(_ip1, _ip2, _ip3, _ip4));
Wahaj 0:c6ffbdc6661d 31 }
Wahaj 0:c6ffbdc6661d 32
Wahaj 0:c6ffbdc6661d 33 const IpAddr& OSCMessage::getIp(){
Wahaj 0:c6ffbdc6661d 34 return host.getIp();
Wahaj 0:c6ffbdc6661d 35 }
Wahaj 0:c6ffbdc6661d 36
Wahaj 0:c6ffbdc6661d 37
Wahaj 0:c6ffbdc6661d 38 const int& OSCMessage::getPort(){
Wahaj 0:c6ffbdc6661d 39 return host.getPort();
Wahaj 0:c6ffbdc6661d 40 }
Wahaj 0:c6ffbdc6661d 41
Wahaj 0:c6ffbdc6661d 42
Wahaj 0:c6ffbdc6661d 43
Wahaj 0:c6ffbdc6661d 44 uint8_t OSCMessage::getAddressNum(){
Wahaj 0:c6ffbdc6661d 45
Wahaj 0:c6ffbdc6661d 46 return addressNum;
Wahaj 0:c6ffbdc6661d 47 }
Wahaj 0:c6ffbdc6661d 48
Wahaj 0:c6ffbdc6661d 49
Wahaj 0:c6ffbdc6661d 50 uint8_t OSCMessage::getArgNum(){
Wahaj 0:c6ffbdc6661d 51
Wahaj 0:c6ffbdc6661d 52 return argNum;
Wahaj 0:c6ffbdc6661d 53 }
Wahaj 0:c6ffbdc6661d 54
Wahaj 0:c6ffbdc6661d 55
Wahaj 0:c6ffbdc6661d 56
Wahaj 0:c6ffbdc6661d 57 char * OSCMessage::getAddress(uint8_t _index){
Wahaj 0:c6ffbdc6661d 58 if(_index>MAX_ADDRESS) _index=MAX_ADDRESS-1;
Wahaj 0:c6ffbdc6661d 59 return address[_index];
Wahaj 0:c6ffbdc6661d 60
Wahaj 0:c6ffbdc6661d 61 }
Wahaj 0:c6ffbdc6661d 62
Wahaj 0:c6ffbdc6661d 63
Wahaj 0:c6ffbdc6661d 64
Wahaj 0:c6ffbdc6661d 65 char * OSCMessage::getTopAddress(){
Wahaj 0:c6ffbdc6661d 66
Wahaj 0:c6ffbdc6661d 67 return getAddress(0);
Wahaj 0:c6ffbdc6661d 68
Wahaj 0:c6ffbdc6661d 69 }
Wahaj 0:c6ffbdc6661d 70
Wahaj 0:c6ffbdc6661d 71
Wahaj 0:c6ffbdc6661d 72 char * OSCMessage::getSubAddress(){
Wahaj 0:c6ffbdc6661d 73
Wahaj 0:c6ffbdc6661d 74 return getAddress(1);
Wahaj 0:c6ffbdc6661d 75
Wahaj 0:c6ffbdc6661d 76 }
Wahaj 0:c6ffbdc6661d 77
Wahaj 0:c6ffbdc6661d 78
Wahaj 0:c6ffbdc6661d 79 char OSCMessage::getTypeTag(uint8_t _index){
Wahaj 0:c6ffbdc6661d 80 if(_index>MAX_ARG) _index=MAX_ARG-1;
Wahaj 0:c6ffbdc6661d 81 return typeTag[_index];
Wahaj 0:c6ffbdc6661d 82 }
Wahaj 0:c6ffbdc6661d 83
Wahaj 0:c6ffbdc6661d 84
Wahaj 0:c6ffbdc6661d 85 int32_t OSCMessage::getArgInt(uint8_t _index){
Wahaj 0:c6ffbdc6661d 86 int32_t *value;
Wahaj 0:c6ffbdc6661d 87 if(_index > argNum) _index=argNum;
Wahaj 0:c6ffbdc6661d 88 value = (int32_t *)arg[_index]; // cast to int32_t
Wahaj 0:c6ffbdc6661d 89 return *value;
Wahaj 0:c6ffbdc6661d 90 }
Wahaj 0:c6ffbdc6661d 91
Wahaj 0:c6ffbdc6661d 92
Wahaj 0:c6ffbdc6661d 93 double OSCMessage::getArgFloat(uint8_t _index){
Wahaj 0:c6ffbdc6661d 94 double *value;
Wahaj 0:c6ffbdc6661d 95 if(_index > argNum) _index=argNum;
Wahaj 0:c6ffbdc6661d 96 value = (double *)arg[_index];
Wahaj 0:c6ffbdc6661d 97 return *value;
Wahaj 0:c6ffbdc6661d 98 }
Wahaj 0:c6ffbdc6661d 99
Wahaj 0:c6ffbdc6661d 100
Wahaj 0:c6ffbdc6661d 101 void OSCMessage::setTopAddress(char *_address){
Wahaj 0:c6ffbdc6661d 102 address[0]=_address;
Wahaj 0:c6ffbdc6661d 103 address[1]=0;
Wahaj 0:c6ffbdc6661d 104 addressNum=1; // Note: this "erases" the subaddress! (is this a good idea?)
Wahaj 0:c6ffbdc6661d 105 }
Wahaj 0:c6ffbdc6661d 106
Wahaj 0:c6ffbdc6661d 107
Wahaj 0:c6ffbdc6661d 108 void OSCMessage::setSubAddress(char *_address){
Wahaj 0:c6ffbdc6661d 109 address[1]=_address;
Wahaj 0:c6ffbdc6661d 110 addressNum=2; // Note: this assumes the top address was already set!
Wahaj 0:c6ffbdc6661d 111 }
Wahaj 0:c6ffbdc6661d 112
Wahaj 0:c6ffbdc6661d 113
Wahaj 0:c6ffbdc6661d 114
Wahaj 0:c6ffbdc6661d 115 void OSCMessage::setAddress(char *_topAddress,char *_subAddress){
Wahaj 0:c6ffbdc6661d 116 setTopAddress(_topAddress);
Wahaj 0:c6ffbdc6661d 117 setSubAddress(_subAddress);
Wahaj 0:c6ffbdc6661d 118 addressNum=2; // (unnecessary...)
Wahaj 0:c6ffbdc6661d 119 }
Wahaj 0:c6ffbdc6661d 120
Wahaj 0:c6ffbdc6661d 121
Wahaj 0:c6ffbdc6661d 122 void OSCMessage::setAddress(uint8_t _index, char *_address){
Wahaj 0:c6ffbdc6661d 123 if(_index>MAX_ADDRESS) _index=MAX_ADDRESS-1;
Wahaj 0:c6ffbdc6661d 124 address[_index]=_address;
Wahaj 0:c6ffbdc6661d 125 addressNum=_index+1;
Wahaj 0:c6ffbdc6661d 126 }
Wahaj 0:c6ffbdc6661d 127
Wahaj 0:c6ffbdc6661d 128
Wahaj 0:c6ffbdc6661d 129
Wahaj 0:c6ffbdc6661d 130 void OSCMessage::setArgs(char *types,...){
Wahaj 0:c6ffbdc6661d 131
Wahaj 0:c6ffbdc6661d 132 va_list argList;
Wahaj 0:c6ffbdc6661d 133
Wahaj 0:c6ffbdc6661d 134 argNum = strlen(types);
Wahaj 0:c6ffbdc6661d 135 if(argNum>MAX_ARG) argNum=MAX_ARG-1;
Wahaj 0:c6ffbdc6661d 136
Wahaj 0:c6ffbdc6661d 137 va_start( argList, types );
Wahaj 0:c6ffbdc6661d 138 for(uint8_t i=0 ; i < argNum ; i++){
Wahaj 0:c6ffbdc6661d 139
Wahaj 0:c6ffbdc6661d 140 typeTag[i]=types[i];
Wahaj 0:c6ffbdc6661d 141
Wahaj 0:c6ffbdc6661d 142 switch(types[i]) {
Wahaj 0:c6ffbdc6661d 143 case 'i':
Wahaj 0:c6ffbdc6661d 144 arg[i]=(uint32_t *)va_arg(argList, uint32_t *);
Wahaj 0:c6ffbdc6661d 145 break;
Wahaj 0:c6ffbdc6661d 146 case 'f':
Wahaj 0:c6ffbdc6661d 147 arg[i]=va_arg(argList, double *);
Wahaj 0:c6ffbdc6661d 148 break;
Wahaj 0:c6ffbdc6661d 149 }
Wahaj 0:c6ffbdc6661d 150
Wahaj 0:c6ffbdc6661d 151 }
Wahaj 0:c6ffbdc6661d 152
Wahaj 0:c6ffbdc6661d 153 }
Wahaj 0:c6ffbdc6661d 154
Wahaj 0:c6ffbdc6661d 155 // ================================================================================================================================================
Wahaj 0:c6ffbdc6661d 156 // ==================================== OSCClass for sending and receiving OSC messages using UDP protocol =======================================
Wahaj 0:c6ffbdc6661d 157 // ================================================================================================================================================
Wahaj 0:c6ffbdc6661d 158 //The class define an object wrapping the UDP functions to send and receive OSC messages
Wahaj 0:c6ffbdc6661d 159
Wahaj 0:c6ffbdc6661d 160 OSCClass::OSCClass(){
Wahaj 0:c6ffbdc6661d 161 udpRec.setOnEvent(this, &OSCClass::onUDPSocketEvent);
Wahaj 0:c6ffbdc6661d 162 newMessage=false;
Wahaj 0:c6ffbdc6661d 163 }
Wahaj 0:c6ffbdc6661d 164
Wahaj 0:c6ffbdc6661d 165 OSCClass::OSCClass(OSCMessage *_mes){
Wahaj 0:c6ffbdc6661d 166 udpRec.setOnEvent(this, &OSCClass::onUDPSocketEvent);
Wahaj 0:c6ffbdc6661d 167 receiverMessage = _mes; // note: receiverMessage MUST be a pointer to the message, because we will modify things in it
Wahaj 0:c6ffbdc6661d 168 newMessage=false;
Wahaj 0:c6ffbdc6661d 169 }
Wahaj 0:c6ffbdc6661d 170
Wahaj 0:c6ffbdc6661d 171 void OSCClass::begin()
Wahaj 0:c6ffbdc6661d 172 {
Wahaj 0:c6ffbdc6661d 173 // setup receiver udp socket:
Wahaj 0:c6ffbdc6661d 174 udpRec.bind(receiverMessage->host);
Wahaj 0:c6ffbdc6661d 175 }
Wahaj 0:c6ffbdc6661d 176
Wahaj 0:c6ffbdc6661d 177
Wahaj 0:c6ffbdc6661d 178 void OSCClass::begin(uint16_t _recievePort)
Wahaj 0:c6ffbdc6661d 179 {
Wahaj 0:c6ffbdc6661d 180 receiverMessage->host.setPort(_recievePort);
Wahaj 0:c6ffbdc6661d 181 // setup receiver udp socket:
Wahaj 0:c6ffbdc6661d 182 udpRec.bind(receiverMessage->host);
Wahaj 0:c6ffbdc6661d 183 }
Wahaj 0:c6ffbdc6661d 184
Wahaj 0:c6ffbdc6661d 185
Wahaj 0:c6ffbdc6661d 186 void OSCClass::setReceiveMessage(OSCMessage *_mes){
Wahaj 0:c6ffbdc6661d 187 receiverMessage = _mes;
Wahaj 0:c6ffbdc6661d 188 }
Wahaj 0:c6ffbdc6661d 189
Wahaj 0:c6ffbdc6661d 190 void OSCClass::onUDPSocketEvent(UDPSocketEvent e)
Wahaj 0:c6ffbdc6661d 191 {
Wahaj 0:c6ffbdc6661d 192 switch(e)
Wahaj 0:c6ffbdc6661d 193 {
Wahaj 0:c6ffbdc6661d 194 case UDPSOCKET_READABLE: //The only event for now
Wahaj 0:c6ffbdc6661d 195 //char buf[256] = {0};
Wahaj 0:c6ffbdc6661d 196 Host auxhost;
Wahaj 0:c6ffbdc6661d 197 buflength = udpRec.recvfrom( rcvBuff, 256, &auxhost ); // QUESTION: auxhost should be equal to the receiver host I guess...
Wahaj 0:c6ffbdc6661d 198 if ( buflength > 0 ) {
Wahaj 0:c6ffbdc6661d 199 //printf("\r\nFrom %d.%d.%d.%d:\r\n", host.getIp()[0], host.getIp()[1], host.getIp()[2], host.getIp()[3]);
Wahaj 0:c6ffbdc6661d 200 decodePacket(receiverMessage); // convert to OSC message, and save it in receiverMessage
Wahaj 0:c6ffbdc6661d 201 newMessage=true;
Wahaj 0:c6ffbdc6661d 202
Wahaj 0:c6ffbdc6661d 203 messageReceivedCallback.call();
Wahaj 0:c6ffbdc6661d 204 }
Wahaj 0:c6ffbdc6661d 205 break;
Wahaj 0:c6ffbdc6661d 206 }
Wahaj 0:c6ffbdc6661d 207 }
Wahaj 0:c6ffbdc6661d 208
Wahaj 0:c6ffbdc6661d 209 /*
Wahaj 0:c6ffbdc6661d 210 Decode UDP packet and save it in the OSCMessage structure
Wahaj 0:c6ffbdc6661d 211 */
Wahaj 0:c6ffbdc6661d 212 void OSCClass::decodePacket( OSCMessage *_mes) {
Wahaj 0:c6ffbdc6661d 213
Wahaj 0:c6ffbdc6661d 214 //uint16_t lenBuff;
Wahaj 0:c6ffbdc6661d 215 uint8_t d;
Wahaj 0:c6ffbdc6661d 216 uint8_t messagePos=0;
Wahaj 0:c6ffbdc6661d 217 uint8_t adrCount=0;
Wahaj 0:c6ffbdc6661d 218 uint8_t adrMesPos=0;
Wahaj 0:c6ffbdc6661d 219 uint8_t packetCount=0;
Wahaj 0:c6ffbdc6661d 220 uint8_t packetPos=4;
Wahaj 0:c6ffbdc6661d 221
Wahaj 0:c6ffbdc6661d 222
Wahaj 0:c6ffbdc6661d 223 //W5100.writeSn(socketNo, SnIR, SnIR::RECV);
Wahaj 0:c6ffbdc6661d 224 //lenBuff=recvfrom(socketNo, rcvBuff, 1, receiverMessage->ip, &receiverMessage->port);
Wahaj 0:c6ffbdc6661d 225
Wahaj 0:c6ffbdc6661d 226 receiverMessage->address[0]=tempAddress[0];
Wahaj 0:c6ffbdc6661d 227
Wahaj 0:c6ffbdc6661d 228 //(1) address process start =========================================
Wahaj 0:c6ffbdc6661d 229 do{
Wahaj 0:c6ffbdc6661d 230 d=rcvBuff[messagePos];
Wahaj 0:c6ffbdc6661d 231
Wahaj 0:c6ffbdc6661d 232
Wahaj 0:c6ffbdc6661d 233 if( (d=='/') && (messagePos>0) ){
Wahaj 0:c6ffbdc6661d 234
Wahaj 0:c6ffbdc6661d 235 if(adrCount<MAX_ADDRESS){
Wahaj 0:c6ffbdc6661d 236 tempAddress[adrCount][adrMesPos]=0;
Wahaj 0:c6ffbdc6661d 237
Wahaj 0:c6ffbdc6661d 238 adrCount++;
Wahaj 0:c6ffbdc6661d 239 adrMesPos=0;
Wahaj 0:c6ffbdc6661d 240
Wahaj 0:c6ffbdc6661d 241 receiverMessage->address[adrCount]=tempAddress[adrCount];
Wahaj 0:c6ffbdc6661d 242 }
Wahaj 0:c6ffbdc6661d 243
Wahaj 0:c6ffbdc6661d 244 }
Wahaj 0:c6ffbdc6661d 245
Wahaj 0:c6ffbdc6661d 246 if(adrCount<MAX_ADDRESS){
Wahaj 0:c6ffbdc6661d 247 //Added this in to remove the slashes out of final output
Wahaj 0:c6ffbdc6661d 248 if(d!='/'){
Wahaj 0:c6ffbdc6661d 249 tempAddress[adrCount][adrMesPos]=d;
Wahaj 0:c6ffbdc6661d 250
Wahaj 0:c6ffbdc6661d 251 if(packetCount>3) {
Wahaj 0:c6ffbdc6661d 252 packetCount=0;
Wahaj 0:c6ffbdc6661d 253 packetPos+=4;
Wahaj 0:c6ffbdc6661d 254 }
Wahaj 0:c6ffbdc6661d 255
Wahaj 0:c6ffbdc6661d 256 adrMesPos++;
Wahaj 0:c6ffbdc6661d 257 }
Wahaj 0:c6ffbdc6661d 258 }
Wahaj 0:c6ffbdc6661d 259 messagePos++;
Wahaj 0:c6ffbdc6661d 260 packetCount++;
Wahaj 0:c6ffbdc6661d 261
Wahaj 0:c6ffbdc6661d 262 }while(d!=0);
Wahaj 0:c6ffbdc6661d 263
Wahaj 0:c6ffbdc6661d 264
Wahaj 0:c6ffbdc6661d 265 if(adrCount<MAX_ADDRESS) adrCount++;
Wahaj 0:c6ffbdc6661d 266 receiverMessage->addressNum=adrCount;
Wahaj 0:c6ffbdc6661d 267
Wahaj 0:c6ffbdc6661d 268 messagePos=packetPos;
Wahaj 0:c6ffbdc6661d 269
Wahaj 0:c6ffbdc6661d 270 //(2) type tag process starts =========================================
Wahaj 0:c6ffbdc6661d 271 packetCount=0;
Wahaj 0:c6ffbdc6661d 272 packetPos+=4;
Wahaj 0:c6ffbdc6661d 273
Wahaj 0:c6ffbdc6661d 274 uint8_t typeTagPos=0;
Wahaj 0:c6ffbdc6661d 275 uint8_t tempArgNum=0;
Wahaj 0:c6ffbdc6661d 276
Wahaj 0:c6ffbdc6661d 277 while(rcvBuff[messagePos]!=0 ){
Wahaj 0:c6ffbdc6661d 278
Wahaj 0:c6ffbdc6661d 279 if(rcvBuff[messagePos] != ',') {
Wahaj 0:c6ffbdc6661d 280
Wahaj 0:c6ffbdc6661d 281 if(typeTagPos<MAX_ARG){
Wahaj 0:c6ffbdc6661d 282 receiverMessage->typeTag[tempArgNum]=rcvBuff[messagePos];
Wahaj 0:c6ffbdc6661d 283 tempArgNum++;
Wahaj 0:c6ffbdc6661d 284 }
Wahaj 0:c6ffbdc6661d 285 typeTagPos++;
Wahaj 0:c6ffbdc6661d 286
Wahaj 0:c6ffbdc6661d 287 }
Wahaj 0:c6ffbdc6661d 288
Wahaj 0:c6ffbdc6661d 289 packetCount++;
Wahaj 0:c6ffbdc6661d 290
Wahaj 0:c6ffbdc6661d 291 if(packetCount>3) {
Wahaj 0:c6ffbdc6661d 292 packetCount=0;
Wahaj 0:c6ffbdc6661d 293 packetPos+=4;
Wahaj 0:c6ffbdc6661d 294 }
Wahaj 0:c6ffbdc6661d 295
Wahaj 0:c6ffbdc6661d 296 messagePos++;
Wahaj 0:c6ffbdc6661d 297 }
Wahaj 0:c6ffbdc6661d 298
Wahaj 0:c6ffbdc6661d 299 receiverMessage->argNum=tempArgNum;
Wahaj 0:c6ffbdc6661d 300
Wahaj 0:c6ffbdc6661d 301 messagePos=packetPos;
Wahaj 0:c6ffbdc6661d 302
Wahaj 0:c6ffbdc6661d 303 //(3) tempArg process starts =========================================
Wahaj 0:c6ffbdc6661d 304 for(int i=0;i<tempArgNum;i++){
Wahaj 0:c6ffbdc6661d 305
Wahaj 0:c6ffbdc6661d 306 adrMesPos=3;
Wahaj 0:c6ffbdc6661d 307
Wahaj 0:c6ffbdc6661d 308 receiverMessage->arg[i]=tempArg[i];
Wahaj 0:c6ffbdc6661d 309
Wahaj 0:c6ffbdc6661d 310 for(int j=0;j<4;j++){
Wahaj 0:c6ffbdc6661d 311
Wahaj 0:c6ffbdc6661d 312 tempArg[i][adrMesPos]=rcvBuff[messagePos];
Wahaj 0:c6ffbdc6661d 313
Wahaj 0:c6ffbdc6661d 314 messagePos++;
Wahaj 0:c6ffbdc6661d 315 adrMesPos--;
Wahaj 0:c6ffbdc6661d 316 }
Wahaj 0:c6ffbdc6661d 317
Wahaj 0:c6ffbdc6661d 318 }
Wahaj 0:c6ffbdc6661d 319
Wahaj 0:c6ffbdc6661d 320
Wahaj 0:c6ffbdc6661d 321 }
Wahaj 0:c6ffbdc6661d 322
Wahaj 0:c6ffbdc6661d 323
Wahaj 0:c6ffbdc6661d 324
Wahaj 0:c6ffbdc6661d 325 OSCMessage * OSCClass::getMessage(){
Wahaj 0:c6ffbdc6661d 326 newMessage=false; // this indicate the user READ the message
Wahaj 0:c6ffbdc6661d 327 return receiverMessage;
Wahaj 0:c6ffbdc6661d 328 }
Wahaj 0:c6ffbdc6661d 329
Wahaj 0:c6ffbdc6661d 330
Wahaj 0:c6ffbdc6661d 331 void OSCClass::sendOsc( OSCMessage *_mes )
Wahaj 0:c6ffbdc6661d 332 {
Wahaj 0:c6ffbdc6661d 333 uint8_t lengthEnd;
Wahaj 0:c6ffbdc6661d 334 uint8_t lengthStart;
Wahaj 0:c6ffbdc6661d 335 char buff[128];
Wahaj 0:c6ffbdc6661d 336
Wahaj 0:c6ffbdc6661d 337 sendContainer = _mes;
Wahaj 0:c6ffbdc6661d 338
Wahaj 0:c6ffbdc6661d 339 //&#12496;&#12483;&#12501;&#12449;&#21021;&#26399;&#20516;
Wahaj 0:c6ffbdc6661d 340 buff[0]=0;
Wahaj 0:c6ffbdc6661d 341
Wahaj 0:c6ffbdc6661d 342 //1) Add name spaces:
Wahaj 0:c6ffbdc6661d 343 for(int i=0;i<sendContainer->addressNum;i++){
Wahaj 0:c6ffbdc6661d 344
Wahaj 0:c6ffbdc6661d 345 strcat(buff,sendContainer->address[i]); // note: an address is for instance: "/test" (including the "/")
Wahaj 0:c6ffbdc6661d 346
Wahaj 0:c6ffbdc6661d 347 }
Wahaj 0:c6ffbdc6661d 348
Wahaj 0:c6ffbdc6661d 349 // pad with 0s to align in multiples of 4:
Wahaj 0:c6ffbdc6661d 350 lengthStart=strlen(buff);
Wahaj 0:c6ffbdc6661d 351 lengthEnd=lengthStart+(4-(lengthStart%4));
Wahaj 0:c6ffbdc6661d 352 for(int i=lengthStart ; i<lengthEnd; i++){
Wahaj 0:c6ffbdc6661d 353 buff[i]=0;
Wahaj 0:c6ffbdc6661d 354 }
Wahaj 0:c6ffbdc6661d 355
Wahaj 0:c6ffbdc6661d 356 lengthStart=lengthEnd;
Wahaj 0:c6ffbdc6661d 357
Wahaj 0:c6ffbdc6661d 358 //2) Add TypeTag:
Wahaj 0:c6ffbdc6661d 359 buff[lengthEnd++]=','; // Note: type tag is for instance: ",if"
Wahaj 0:c6ffbdc6661d 360 for(int i=0;i<sendContainer->argNum;i++){
Wahaj 0:c6ffbdc6661d 361 buff[lengthEnd++]=sendContainer->typeTag[i];
Wahaj 0:c6ffbdc6661d 362 }
Wahaj 0:c6ffbdc6661d 363
Wahaj 0:c6ffbdc6661d 364 // pad with 0s to align in multiples of 4:
Wahaj 0:c6ffbdc6661d 365 lengthStart=lengthEnd;
Wahaj 0:c6ffbdc6661d 366 lengthEnd=lengthStart+(4-(lengthStart%4));
Wahaj 0:c6ffbdc6661d 367 for(int i=lengthStart ; i<lengthEnd; i++){
Wahaj 0:c6ffbdc6661d 368 buff[i]=0;
Wahaj 0:c6ffbdc6661d 369 }
Wahaj 0:c6ffbdc6661d 370
Wahaj 0:c6ffbdc6661d 371 //3) add argument values (Note: here only big endian):
Wahaj 0:c6ffbdc6661d 372 uint8_t *v;
Wahaj 0:c6ffbdc6661d 373 for(int i=0;i<sendContainer->argNum;i++){
Wahaj 0:c6ffbdc6661d 374 uint8_t valuePos=3;
Wahaj 0:c6ffbdc6661d 375 v=(uint8_t *)sendContainer->arg[i];
Wahaj 0:c6ffbdc6661d 376
Wahaj 0:c6ffbdc6661d 377 buff[lengthEnd++]=v[valuePos--];
Wahaj 0:c6ffbdc6661d 378 buff[lengthEnd++]=v[valuePos--];
Wahaj 0:c6ffbdc6661d 379 buff[lengthEnd++]=v[valuePos--];
Wahaj 0:c6ffbdc6661d 380 buff[lengthEnd++]=v[valuePos];
Wahaj 0:c6ffbdc6661d 381
Wahaj 0:c6ffbdc6661d 382 }
Wahaj 0:c6ffbdc6661d 383
Wahaj 0:c6ffbdc6661d 384 //4) Send udp packet:
Wahaj 0:c6ffbdc6661d 385 //sendto( socketNo, (uint8_t *)buff, lengthEnd, sendContainer->ip, sendContainer->port );
Wahaj 0:c6ffbdc6661d 386 udpSend.sendto(buff , lengthEnd, &(sendContainer->host));
Wahaj 0:c6ffbdc6661d 387 }
Wahaj 0:c6ffbdc6661d 388
Wahaj 0:c6ffbdc6661d 389
Wahaj 0:c6ffbdc6661d 390 /*
Wahaj 0:c6ffbdc6661d 391 flush a receive buffer
Wahaj 0:c6ffbdc6661d 392 void OSCClass::flush() {
Wahaj 0:c6ffbdc6661d 393 while ( available() ){}
Wahaj 0:c6ffbdc6661d 394 }
Wahaj 0:c6ffbdc6661d 395 */
Wahaj 0:c6ffbdc6661d 396
Wahaj 0:c6ffbdc6661d 397
Wahaj 0:c6ffbdc6661d 398 void OSCClass::stop() {
Wahaj 0:c6ffbdc6661d 399 //close( socketNo );
Wahaj 0:c6ffbdc6661d 400 udpSend.resetOnEvent(); // disables callback
Wahaj 0:c6ffbdc6661d 401 }