Mercurial > hg > beaglert
comparison projects/osc/render.cpp @ 271:fb9c28a4676b prerelease
Added osc example project and node script for testing
author | Liam Donovan <l.b.donovan@qmul.ac.uk> |
---|---|
date | Tue, 17 May 2016 16:01:06 +0100 |
parents | |
children | 5433c83ce04e |
comparison
equal
deleted
inserted
replaced
270:de37582ce6f3 | 271:fb9c28a4676b |
---|---|
1 #include <BeagleRT.h> | |
2 #include <OSCServer.h> | |
3 #include <OSCClient.h> | |
4 | |
5 OSCServer oscServer; | |
6 OSCClient oscClient; | |
7 | |
8 // this example is designed to be run alongside resources/osc/osc.js | |
9 | |
10 // parse messages recieved by OSC Server | |
11 // msg is Message class of oscpkt: http://gruntthepeon.free.fr/oscpkt/ | |
12 void parseMessage(oscpkt::Message msg){ | |
13 | |
14 rt_printf("recieved message to: %s\n", msg.addressPattern().c_str()); | |
15 | |
16 int intArg; | |
17 float floatArg; | |
18 if (msg.match("/osc-test").popInt32(intArg).popFloat(floatArg).isOkNoMoreArgs()){ | |
19 rt_printf("recieved int %i and float %f\n", intArg, floatArg); | |
20 } | |
21 | |
22 } | |
23 | |
24 bool setup(BeagleRTContext *context, void *userData) | |
25 { | |
26 // setup the OSC server to recieve on port 7562 | |
27 oscServer.setup(7562); | |
28 // setup the OSC client to send on port 7563 | |
29 oscClient.setup(7563); | |
30 | |
31 // the following code sends an OSC message to address /osc-setup | |
32 // then waits 1 second for a reply on /osc-setup-reply | |
33 bool handshakeRecieved = false; | |
34 oscClient.sendMessageNow(oscClient.newMessage.to("/osc-setup").end()); | |
35 oscServer.recieveMessageNow(1000); | |
36 while (oscServer.messageWaiting()){ | |
37 if (oscServer.popMessage().match("/osc-setup-reply")){ | |
38 handshakeRecieved = true; | |
39 } | |
40 } | |
41 | |
42 if (handshakeRecieved){ | |
43 rt_printf("handshake recieved!\n"); | |
44 } else { | |
45 rt_printf("timeout!\n"); | |
46 } | |
47 | |
48 return true; | |
49 } | |
50 | |
51 void render(BeagleRTContext *context, void *userData) | |
52 { | |
53 // recieve OSC messages, parse them, and send back an acknowledgment | |
54 while (oscServer.messageWaiting()){ | |
55 parseMessage(oscServer.popMessage()); | |
56 oscClient.queueMessage(oscClient.newMessage.to("/osc-acknowledge").add(5).add(4.2f).add(std::string("OSC message recieved")).end()); | |
57 } | |
58 } | |
59 | |
60 void cleanup(BeagleRTContext *context, void *userData) | |
61 { | |
62 | |
63 } |