Mercurial > hg > beaglert
annotate 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 |
rev | line source |
---|---|
andrewm@71 | 1 //scope.cpp |
giuliomoro@109 | 2 #ifndef SCOPE_H_ |
giuliomoro@109 | 3 #define SCOPE_H_ |
giuliomoro@109 | 4 |
andrewm@71 | 5 #include <BeagleRT.h> |
andrewm@71 | 6 #include <rtdk.h> |
andrewm@71 | 7 #include <cmath> |
andrewm@71 | 8 #include <UdpClient.h> |
giuliomoro@111 | 9 #include <vector> |
andrewm@71 | 10 |
giuliomoro@107 | 11 #define NETWORK_AUDIO_BUFFER_SIZE 302 |
giuliomoro@109 | 12 |
giuliomoro@109 | 13 struct NetworkBuffer{ |
andrewm@71 | 14 int timestamp; |
giuliomoro@109 | 15 int channelNumber; |
giuliomoro@109 | 16 int activeBuffer; |
andrewm@71 | 17 int index; |
andrewm@71 | 18 float buffers[2][NETWORK_AUDIO_BUFFER_SIZE]; |
giuliomoro@109 | 19 bool doneOnTime; |
giuliomoro@109 | 20 bool readyToBeSent; |
giuliomoro@111 | 21 static const int headerLength=2; |
andrewm@71 | 22 }; |
andrewm@71 | 23 |
giuliomoro@111 | 24 class NetworkSend { |
andrewm@71 | 25 int sampleCount; |
andrewm@71 | 26 float sampleRate; |
giuliomoro@111 | 27 UdpClient udpClient; |
giuliomoro@111 | 28 static bool staticConstructed; |
giuliomoro@111 | 29 static void staticConstructor(); |
giuliomoro@111 | 30 static AuxiliaryTask transmitAudioTask; //TODO: allow different AuxiliaryTasks for different priorities (e.g.: audio vs scope) |
giuliomoro@111 | 31 static std::vector<NetworkSend *> objAddrs; |
andrewm@71 | 32 public: |
giuliomoro@109 | 33 NetworkBuffer channel; |
giuliomoro@111 | 34 NetworkSend(); |
giuliomoro@111 | 35 ~NetworkSend(); |
giuliomoro@109 | 36 void setup(float aSampleRate); |
giuliomoro@111 | 37 void setup(float aSampleRate, int aChannelNumber, int aPort, const char *aServer); |
giuliomoro@109 | 38 void sendData(); |
giuliomoro@109 | 39 void log(float value); |
giuliomoro@109 | 40 void setPort(int aPort); |
giuliomoro@111 | 41 void setServer(const char* aServer); |
giuliomoro@109 | 42 void setChannelNumber(int aChannelNumber); |
giuliomoro@109 | 43 int getChannelNumber(); |
giuliomoro@111 | 44 static int getNumInstances(); |
giuliomoro@111 | 45 static void sendAllData(); |
andrewm@71 | 46 }; |
andrewm@71 | 47 |
giuliomoro@111 | 48 /** |
giuliomoro@111 | 49 * An array of NetworkSend objects with some default parameters |
giuliomoro@111 | 50 * |
giuliomoro@111 | 51 * All sending on the same port (defaults to 9999) |
giuliomoro@111 | 52 * All sending to the same server (defaults to 127.0.0.1) |
giuliomoro@111 | 53 */ |
giuliomoro@109 | 54 class Scope { |
giuliomoro@111 | 55 std::vector<NetworkSend> channels; |
giuliomoro@109 | 56 void deallocate(); |
giuliomoro@109 | 57 public: |
giuliomoro@109 | 58 Scope(int aNumChannels); |
giuliomoro@109 | 59 ~Scope(); |
giuliomoro@109 | 60 void log(int channel, float value); |
giuliomoro@111 | 61 void setup(); |
giuliomoro@111 | 62 void setup(float sampleRate, int aPort, const char* aServer); |
giuliomoro@109 | 63 void sendData(); |
giuliomoro@111 | 64 void setPort(); |
giuliomoro@111 | 65 int getNumChannels(); |
giuliomoro@109 | 66 }; |
giuliomoro@109 | 67 #endif /* SCOPE_H */ |