Skip to content

Commit

Permalink
Remove editor view of variables
Browse files Browse the repository at this point in the history
Since all variables other than the port and sampling frequency are handled by the header of each packet, they are removed from the editor view.
Scale and offset are removed from the processing as well. A future plugin may provide scale/offset transformation of data streams.
  • Loading branch information
bparks13 committed Mar 11, 2024
1 parent d4e04c2 commit 5a16037
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 318 deletions.
86 changes: 8 additions & 78 deletions Source/EphysSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ DataThread* EphysSocket::createDataThread(SourceNode *sn)
EphysSocket::EphysSocket(SourceNode* sn) : DataThread(sn)
{
port = DEFAULT_PORT;
num_channels = DEFAULT_NUM_CHANNELS;
num_samp = DEFAULT_NUM_SAMPLES;
data_offset = DEFAULT_DATA_OFFSET;
data_scale = DEFAULT_DATA_SCALE;
sample_rate = DEFAULT_SAMPLE_RATE;

total_samples = DEFAULT_TOTAL_SAMPLES;
eventState = DEFAULT_EVENT_STATE;

depth = U16;
element_size = 2;
num_bytes = 32678;
num_channels = DEFAULT_NUM_CHANNELS;
num_samp = DEFAULT_NUM_SAMPLES;
depth = DEFAULT_DEPTH;
element_size = DEFAULT_ELEMENT_SIZE;
num_bytes = DEFAULT_NUM_BYTES;

full_flag = false;
stop_flag = false;
Expand Down Expand Up @@ -142,7 +141,7 @@ void EphysSocket::updateSettings(OwnedArray<ContinuousChannel>* continuousChanne
"Channel acquired via network stream",
"ephyssocket.continuous",

data_scale,
1, // NB: Data scale

sourceStreams->getFirst()
};
Expand Down Expand Up @@ -235,7 +234,7 @@ void EphysSocket::convertData()
int k = 0;
for (int i = 0; i < num_samp; i++) {
for (int j = 0; j < num_channels; j++) {
convbuf[k++] = data_scale * (float)(buf[j * num_samp + i]) - data_offset;
convbuf[k++] = (float)buf[j * num_samp + i];
}
}
}
Expand Down Expand Up @@ -357,72 +356,3 @@ bool EphysSocket::updateBuffer()
else
return true;
}

String EphysSocket::handleConfigMessage(String msg)
{
// Available commands:
// ES INFO - Returns info on current variables that can be modified over HTTP
// ES SCALE <data_scale> - Updates the data scale to data_scale
// ES OFFSET <data_offset> - Updates the offset to data_offset

if (CoreServices::getAcquisitionStatus()) {
return "Ephys Socket plugin cannot update settings while acquisition is active.";
}

StringArray parts = StringArray::fromTokens(msg, " ", "");

if (parts.size() > 0)
{
if (parts[0].equalsIgnoreCase("ES"))
{
if (parts.size() == 3)
{
if (parts[1].equalsIgnoreCase("SCALE"))
{
float scale = parts[2].getFloatValue();

if (scale > MIN_DATA_SCALE && scale < MAX_DATA_SCALE)
{
data_scale = scale;
LOGD("Scale updated to: ", scale);
return "SUCCESS";
}

return "Invalid scale requested. Scale can be set between '" + String(MIN_DATA_SCALE) + "' and '" + String(MAX_DATA_SCALE) + "'";
}
else if (parts[1].equalsIgnoreCase("OFFSET"))
{
float offset = parts[2].getFloatValue();

if (offset >= MIN_DATA_OFFSET && offset < MAX_DATA_OFFSET)
{
data_offset = offset;
LOGD("Offset updated to: ", offset);
return "SUCCESS";
}

return "Invalid offset requested. Offset can be set between '" + String(MIN_DATA_OFFSET) + "' and '" + String(MIN_DATA_OFFSET) + "'";
}
else
{
return "ES command " + parts[1] + "not recognized.";
}
}
else if (parts.size() == 2)
{
if (parts[1].equalsIgnoreCase("INFO"))
{
return "Scale = " + String(data_scale) + ". Offset = " + String(data_offset) + ".";
}
else
{
return "ES command " + parts[1] + "not recognized.";
}
}

return "Unknown number of inputs given.";
}

return "Command not recognized.";
}
}
30 changes: 10 additions & 20 deletions Source/EphysSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ namespace EphysSocketNode
/** Default parameters */
const int DEFAULT_PORT = 9001;
const float DEFAULT_SAMPLE_RATE = 30000.0f;
const float DEFAULT_DATA_SCALE = 0.195f;
const uint16_t DEFAULT_DATA_OFFSET = 32768;
const int DEFAULT_NUM_SAMPLES = 256;
const int DEFAULT_NUM_CHANNELS = 64;
const int DEFAULT_TOTAL_SAMPLES = 0;
const int DEFAULT_EVENT_STATE = 0;

/** Parameter limits */
const float MIN_DATA_SCALE = 0.0f;
const float MAX_DATA_SCALE = 9999.9f;
const float MIN_DATA_OFFSET = 0;
const float MAX_DATA_OFFSET = 65536;

/** Constructor */
EphysSocket(SourceNode* sn);
Expand Down Expand Up @@ -67,17 +55,22 @@ namespace EphysSocketNode
/** Network stream parameters (must match features of incoming data) */
int port;
float sample_rate;
float data_scale;
float data_offset;
int num_samp;
int num_channels;
Depth depth;

private:

/** Socket parameters */
const int MAX_PACKET_SIZE = 65506;
const int HEADER_SIZE = 22;
/** Default socket parameters */
const int DEFAULT_NUM_SAMPLES = 256;
const int DEFAULT_NUM_CHANNELS = 64;
const Depth DEFAULT_DEPTH = U16;
const int DEFAULT_ELEMENT_SIZE = 2;
const int DEFAULT_NUM_BYTES = 32678; // NB: 256 * 64 * 2

/** Default parameters */
const int DEFAULT_TOTAL_SAMPLES = 0;
const int DEFAULT_EVENT_STATE = 0;

/** Variables that are part of the incoming header */
int num_bytes;
Expand All @@ -92,9 +85,6 @@ namespace EphysSocketNode
/** Stops thread */
bool stopAcquisition() override;

/** Handles incoming HTTP messages */
String handleConfigMessage(String msg) override;

/** Compares a newly parsed header to existing variables */
bool compareHeaders(Header header) const;

Expand Down
Loading

0 comments on commit 5a16037

Please sign in to comment.