comparison include/NetworkSend.h @ 111:9928b6366227 scope-refactoring

Refactored the Scope class into NetworkSend and Scope classes. No need for a global pointer anymore!
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 19 Aug 2015 22:40:05 +0100
parents include/Scope.h@ad8a93cd7c39
children 7dfae7b7ab12
comparison
equal deleted inserted replaced
110:fb56681ab1d6 111:9928b6366227
1 //scope.cpp
2 #ifndef SCOPE_H_
3 #define SCOPE_H_
4
5 #include <BeagleRT.h>
6 #include <rtdk.h>
7 #include <cmath>
8 #include <UdpClient.h>
9 #include <vector>
10
11 #define NETWORK_AUDIO_BUFFER_SIZE 302
12
13 struct NetworkBuffer{
14 int timestamp;
15 int channelNumber;
16 int activeBuffer;
17 int index;
18 float buffers[2][NETWORK_AUDIO_BUFFER_SIZE];
19 bool doneOnTime;
20 bool readyToBeSent;
21 static const int headerLength=2;
22 };
23
24 class NetworkSend {
25 int sampleCount;
26 float sampleRate;
27 UdpClient udpClient;
28 static bool staticConstructed;
29 static void staticConstructor();
30 static AuxiliaryTask transmitAudioTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope)
31 static std::vector<NetworkSend *> objAddrs;
32 public:
33 NetworkBuffer channel;
34 NetworkSend();
35 ~NetworkSend();
36 void setup(float aSampleRate);
37 void setup(float aSampleRate, int aChannelNumber, int aPort, const char *aServer);
38 void sendData();
39 void log(float value);
40 void setPort(int aPort);
41 void setServer(const char* aServer);
42 void setChannelNumber(int aChannelNumber);
43 int getChannelNumber();
44 static int getNumInstances();
45 static void sendAllData();
46 };
47
48 /**
49 * An array of NetworkSend objects with some default parameters
50 *
51 * All sending on the same port (defaults to 9999)
52 * All sending to the same server (defaults to 127.0.0.1)
53 */
54 class Scope {
55 std::vector<NetworkSend> channels;
56 void deallocate();
57 public:
58 Scope(int aNumChannels);
59 ~Scope();
60 void log(int channel, float value);
61 void setup();
62 void setup(float sampleRate, int aPort, const char* aServer);
63 void sendData();
64 void setPort();
65 int getNumChannels();
66 };
67 #endif /* SCOPE_H */