Skip to content

Commit

Permalink
Reworked and updated the streams API; still a fair amount of debug co…
Browse files Browse the repository at this point in the history
…de in here that will need cleaning out before tag/release
  • Loading branch information
JohnVidler committed Mar 16, 2023
1 parent 30825b9 commit c918ffb
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 126 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*~
*.swp
.vscode
.DS_Store
27 changes: 14 additions & 13 deletions inc/streams/DataStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ namespace codal
class DataStream : public DataSource, public DataSink
{
ManagedBuffer stream[DATASTREAM_MAXIMUM_BUFFERS];
int bufferCount;
int bufferLength;
int preferredBufferSize;
int writers;
uint16_t spaceAvailableEventCode;
uint16_t pullRequestEventCode;
//int bufferCount;
//int bufferLength;
//int preferredBufferSize;
//int writers;
//uint16_t spaceAvailableEventCode;
//uint16_t pullRequestEventCode;
ManagedBuffer * nextBuffer;
bool isBlocking;

DataSink *downStream;
Expand Down Expand Up @@ -114,7 +115,7 @@ namespace codal
* @param position The index of the byte to read.
* @return The value of the byte at the given position, or DEVICE_INVALID_PARAMETER.
*/
int get(int position);
//int get(int position);

/**
* Sets the byte at the given index to value provided.
Expand All @@ -123,13 +124,13 @@ namespace codal
* @return DEVICE_OK, or DEVICE_INVALID_PARAMETER.
*
*/
int set(int position, uint8_t value);
//int set(int position, uint8_t value);

/**
* Gets number of bytes that are ready to be consumed in this data stream.
* @return The size in bytes.
*/
int length();
//int length();

/**
* Determines if any of the data currently flowing through this stream is held in non-volatile (FLASH) memory.
Expand Down Expand Up @@ -160,13 +161,13 @@ namespace codal
* Determine the number of bytes that are currnetly buffered before blocking subsequent push() operations.
* @return the current preferred buffer size for this DataStream
*/
int getPreferredBufferSize();
//int getPreferredBufferSize();

/**
* Define the number of bytes that should be buffered before blocking subsequent push() operations.
* @param size The number of bytes to buffer.
*/
void setPreferredBufferSize(int size);
//void setPreferredBufferSize(int size);

/**
* Determines if this stream acts in a synchronous, blocking mode or asynchronous mode. In blocking mode, writes to a full buffer
Expand All @@ -189,7 +190,7 @@ namespace codal
*
* @return true if there if the buffer is ful, and can accept no more data at this time. False otherwise.
*/
bool full();
///bool full();

/**
* Provide the next available ManagedBuffer to our downstream caller, if available.
Expand All @@ -209,7 +210,7 @@ namespace codal
/**
* Issue a deferred pull request to our downstream component, if one has been registered.
*/
void onDeferredPullRequest(Event);
//void onDeferredPullRequest(Event);

};
}
Expand Down
3 changes: 3 additions & 0 deletions inc/streams/LevelDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace codal{
int level; // The current, instantaneous level.
int sigma; // Running total of the samples in the current window.
bool activated; // Has this component been connected yet.
int ttl;


/**
Expand All @@ -86,6 +87,8 @@ namespace codal{
*/
int getValue();

void activateForEvents( bool state );

/**
* Set threshold to the given value. Events will be generated when these thresholds are crossed.
*
Expand Down
3 changes: 3 additions & 0 deletions inc/streams/LevelDetectorSPL.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ namespace codal{
bool activated; // Has this component been connected yet
bool enabled; // Is the component currently running
int unit; // The units to be returned from this level detector (e.g. dB or linear 8bit)
uint64_t timeout;

/**
* Creates a component capable of measuring and thresholding stream data
Expand Down Expand Up @@ -111,6 +112,8 @@ namespace codal{
*/
float getValue();

void activateForEvents( bool state );

/**
* Disable component
*/
Expand Down
4 changes: 2 additions & 2 deletions inc/streams/StreamNormalizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ namespace codal{
uint32_t orMask; // post processing step - or'd with each sample.
bool normalize; // If set, will recalculate a zero offset.
bool zeroOffsetValid; // Set to true after the first buffer has been processed.
bool outputEnabled; // When set any buffer processed will be forwarded downstream.
bool outputEnabled; // When set any bxuffer processed will be forwarded downstream.
DataSource &upstream; // The upstream component of this StreamNormalizer.
DataStream output; // The downstream output stream of this StreamNormalizer.
ManagedBuffer buffer; // The buffer being processed.
//ManagedBuffer buffer; // The buffer being processed.

static SampleReadFn readSample[9];
static SampleWriteFn writeSample[9];
Expand Down
4 changes: 3 additions & 1 deletion inc/streams/StreamRecording.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "DataStream.h"

// Pretty much the largest sensible number we can have on a v2
#define REC_MAX_BUFFERS 256
#define REC_MAX_BUFFERS 200

#define REC_STATE_STOPPED 0
#define REC_STATE_PLAYING 1
Expand Down Expand Up @@ -149,6 +149,8 @@ namespace codal
*/
bool isStopped();

virtual float getSampleRate();

};

}
Expand Down
17 changes: 12 additions & 5 deletions inc/streams/StreamSplitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ DEALINGS IN THE SOFTWARE.
#define SPLITTER_DEACTIVATE_CHANNEL 2
#define SPLITTER_CHANNEL_CONNECT 3
#define SPLITTER_CHANNEL_DISCONNECT 4
#define SPLITTER_ACTIVATE 5
#define SPLITTER_DEACTIVATE 6


/**
Expand Down Expand Up @@ -88,11 +90,12 @@ namespace codal{
{
private:
ManagedBuffer lastBuffer; // Buffer being processed
uint64_t __cycle;

public:
int numberChannels; // Current number of channels Splitter is serving
int numberActiveChannels; // Current number of /active/ channels this Splitter is serving
int processed; // How many downstream components have responded to pull request
public:
bool isActive; // Track if we need to emit activate/deactivate messages
int channels; // Current number of channels Splitter is serving
volatile int activeChannels; // Current number of /active/ channels this Splitter is serving
DataSource &upstream; // The upstream component of this Splitter
SplitterChannel * outputChannels[CONFIG_MAX_CHANNELS]; // Array of SplitterChannels the Splitter is serving

Expand All @@ -103,6 +106,8 @@ namespace codal{
*/
StreamSplitter(DataSource &source, uint16_t id = CodalComponent::generateDynamicID());

void periodicCallback();

/**
* Callback provided when data is ready.
*/
Expand All @@ -116,7 +121,9 @@ namespace codal{
/**
* Destructor.
*/
~StreamSplitter();
virtual ~StreamSplitter();

friend SplitterChannel;

};
}
Expand Down
1 change: 1 addition & 0 deletions source/driver-models/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Timer::Timer(LowLevelTimer& t, uint8_t ccPeriodChannel, uint8_t ccEventChannel)
{
// Register ourselves as the defualt timer - most recent timer wins.
system_timer = this;


this->ccPeriodChannel = ccPeriodChannel;
this->ccEventChannel = ccEventChannel;
Expand Down
Loading

0 comments on commit c918ffb

Please sign in to comment.