Mercurial > hg > beaglert
comparison core/OSCServer.cpp @ 270:de37582ce6f3 prerelease
Added OSCServer and OSCClient
author | Liam Donovan <l.b.donovan@qmul.ac.uk> |
---|---|
date | Tue, 17 May 2016 15:56:18 +0100 |
parents | |
children | e4392164b458 |
comparison
equal
deleted
inserted
replaced
260:afdddd5f189f | 270:de37582ce6f3 |
---|---|
1 /***** OSCServer.cpp *****/ | |
2 #include <OSCServer.h> | |
3 | |
4 // constructor | |
5 OSCServer::OSCServer(){} | |
6 | |
7 // static method for checking messages | |
8 // called by messageCheckTask with pointer to OSCServer instance as argument | |
9 void OSCServer::checkMessages(void* ptr){ | |
10 OSCServer *instance = (OSCServer*)ptr; | |
11 instance->messageCheck(); | |
12 } | |
13 | |
14 void OSCServer::setup(int _port){ | |
15 port = _port; | |
16 if(!socket.init(port)) | |
17 rt_printf("socket not initialised\n"); | |
18 createAuxTasks(); | |
19 } | |
20 | |
21 void OSCServer::createAuxTasks(){ | |
22 char name [30]; | |
23 sprintf (name, "OSCRecieveTask %i", port); | |
24 OSCRecieveTask = BeagleRT_createAuxiliaryTask(OSCServer::checkMessages, BEAGLERT_AUDIO_PRIORITY-5, name, this, true); | |
25 } | |
26 | |
27 void OSCServer::messageCheck(){ | |
28 if (socket.waitUntilReady(true, UDP_RECIEVE_TIMEOUT_MS)){ | |
29 int msgLength = socket.read(&inBuffer, UDP_RECIEVE_MAX_LENGTH, false); | |
30 pr.init(inBuffer, msgLength); | |
31 oscpkt::Message *inmsg; | |
32 while (pr.isOk() && (inmsg = pr.popMessage()) != 0) { | |
33 inQueue.push(*inmsg); | |
34 } | |
35 } | |
36 } | |
37 | |
38 bool OSCServer::messageWaiting(){ | |
39 return !inQueue.empty(); | |
40 } | |
41 | |
42 oscpkt::Message OSCServer::popMessage(){ | |
43 if (!inQueue.empty()){ | |
44 poppedMessage = inQueue.front(); | |
45 inQueue.pop(); | |
46 } else { | |
47 poppedMessage.init("/error"); | |
48 } | |
49 return poppedMessage; | |
50 } | |
51 | |
52 void OSCServer::recieveMessageNow(int timeout){ | |
53 if (socket.waitUntilReady(true, timeout)){ | |
54 int msgLength = socket.read(&inBuffer, UDP_RECIEVE_MAX_LENGTH, false); | |
55 pr.init(inBuffer, msgLength); | |
56 oscpkt::Message *inmsg; | |
57 while (pr.isOk() && (inmsg = pr.popMessage()) != 0) { | |
58 inQueue.push(*inmsg); | |
59 } | |
60 } | |
61 } | |
62 | |
63 | |
64 | |
65 |