forked from davidbouchard/arduino-osc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OscUDP.cpp
executable file
·90 lines (54 loc) · 1.89 KB
/
OscUDP.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
79
80
81
82
83
84
85
86
87
88
89
#include <OscUDP.h>
void oscEvent(OscMessage &);
//=============================================================================
// OSC_UDP Wrapper
//=============================================================================
// TODO: write similar wrapper class using the UDP interface
// waiting to solve the blocking kink on the Serial one first
OscUDP::OscUDP( ){
;
}
void OscUDP::begin(EthernetUDP &u){
udp = &u; // &u ? u
}
void OscUDP::send(OscMessage &msg, NetAddress &na){
OscUDP::send (msg, na.getIP(), na.getPort() );
}
void OscUDP::send(OscMessage &msg, IPAddress outIp, int outPort) {
// SEND BASED ON THIS :
// http://cnmat.berkeley.edu/library/oscuino/omessage
// we need to do some magic here
udp->beginPacket(outIp, outPort);
msg.send(*udp); // send the bytes to the SLIP stream
udp->endPacket(); // mark the end of the OSC Packet
msg.empty(); // free space occupied by message
}
void OscUDP::listen() {
// need a non-blocking method to read bytes from the UDP stream
// parsePacket us analogous to available
int UDPpacketSize;
if( (UDPpacketSize = udp->parsePacket()) > 0) {
while(UDPpacketSize--) msgIN.fill(udp->read());
} else {
return; // i am not sure that works but lets see
// i think it says if packet is <= 0 return
}
if (!msgIN.hasError()) {
oscEvent(msgIN);
}
msgIN.reset();
}
//=============================================================================
// NetAddress interface
//=============================================================================
NetAddress :: NetAddress (){;} // sets up object
void NetAddress::set(IPAddress _ip, int _port) {
destinationIP = _ip;
destinationPort = _port;
}
IPAddress NetAddress :: getIP (){
return destinationIP;
}
int NetAddress :: getPort(){
return destinationPort;
}