-
Notifications
You must be signed in to change notification settings - Fork 8
/
OSCClient.cpp
78 lines (58 loc) · 1.76 KB
/
OSCClient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
ArdOSC 2.1 - OSC Library for Arduino.
--> Modifications made to the Version retrieved from https://github.com/watterott/RedFly-Shield
--> Adapted for the WiFlyHQ Library
--> Plenty of modifications have been made by Watterott and me, so most errors you will encounter are probably not the original authors fault...
-------- Lisence -----------------------------------------------------------
ArdOSC
The MIT License
Copyright (c) 2009 - 2011 recotana( http://recotana.com ) All right reserved
*/
#include <stdlib.h>
#include "OSCCommon/OSCClient.h"
OSCClient::OSCClient(WiFly* wiFly):
wiFly(wiFly)
{
wiFlyTimeoutMillis=3; //used to make sure that each package is flushed induvidually
lastSendMillis=0;
}
OSCClient::~OSCClient(void)
{
}
int OSCClient::send(OSCMessage *_message)
{
int result = 1;
uint16_t msgSize;
uint8_t *sendData;
msgSize = _message->getMessageSize();
sendData = (uint8_t*) calloc(msgSize, 1);
if( sendData == NULL )
{
return -1;
}
if( encoder.encode(_message, sendData) < 0 )
{
free(sendData);
return -2;
}
while(millis()-lastSendMillis<wiFlyTimeoutMillis){
if(lastSendMillis>millis())lastSendMillis=millis(); //be prepared for millis() overflow...
}; //wait until last package is flushed
wiFly->write(sendData, msgSize);
wiFly->flush();
free(sendData);
lastSendMillis=millis();
return result;
}
int OSCClient::sendInt(int value, char* adress){
OSCMessage loacal_mes;
loacal_mes.beginMessage(adress);
loacal_mes.addArgInt32(value);
return(this->send(&loacal_mes));
}
int OSCClient::sendFloat(float value, char* adress){
OSCMessage loacal_mes;
loacal_mes.beginMessage(adress);
loacal_mes.addArgFloat(value);
return(this->send(&loacal_mes));
}