Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions Source/EphysSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void EphysSocket::registerParameters()
void EphysSocket::disconnectSocket()
{
socket.signalThreadShouldExit();
socket.waitForThreadToExit(1000);
socket.waitForThreadToExit (1000);
socket.disconnectSocket();

getParameter ("port")->setEnabled (true);
Expand Down Expand Up @@ -278,22 +278,20 @@ bool EphysSocket::updateBuffer()
String EphysSocket::handleConfigMessage (const String& msg)
{
// Available commands:
// ES INFO - Returns info on current variables that can be modified over HTTP
// 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
// ES PORT <port> - Updates the port number that EphysSocket connects to
// ES FREQUENCY <sample_rate> - Updates the sampling rate
// ES CONNECTION_STATE - Returns the connection state (CONNECTED/DISCONNECTED)
// ES CONNECT - Connect the socket
// ES DISCCONNECT - Disconnect the socket

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

if (socket.isConnected())
{
return "Ephys Socket plugin cannot update settings while connected to an active socket.";
}

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

if (parts.size() > 0)
Expand All @@ -302,6 +300,11 @@ String EphysSocket::handleConfigMessage (const String& msg)
{
if (parts.size() == 3)
{
if (socket.isConnected())
{
return "Ephys Socket plugin cannot update settings while connected to an active socket.";
}

if (parts[1].equalsIgnoreCase ("SCALE"))
{
float scale = parts[2].getFloatValue();
Expand Down Expand Up @@ -365,6 +368,23 @@ String EphysSocket::handleConfigMessage (const String& msg)
{
return "Port = " + String (port) + ". Sample rate = " + String (sample_rate) + "Scale = " + String (data_scale) + ". Offset = " + String (data_offset) + ".";
}
else if (parts[1].equalsIgnoreCase ("CONNECTION_STATUS"))
{
return socket.isConnected() ? CONNECTION_STATE_CONNECTED : CONNECTION_STATE_DISCONNECTED;
}
else if (parts[1].equalsIgnoreCase ("CONNECT"))
{
LOGC ("Request socket connect");
const auto connected = connectSocket();
LOGC (connected ? "Connection success" : "Connection failed");
return connected ? CONNECTION_STATE_CONNECTED : CONNECTION_STATE_DISCONNECTED;
}
else if (parts[1].equalsIgnoreCase ("DISCONNECT"))
{
disconnectSocket();
LOGC ("Socket disconnected");
return CONNECTION_STATE_DISCONNECTED;
}
else
{
return "ES command " + parts[1] + "not recognized.";
Expand Down
34 changes: 19 additions & 15 deletions Source/EphysSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,25 @@ namespace EphysSocketNode
class EphysSocket : public DataThread
{
public:
/** Connection states */
static const constexpr char* CONNECTION_STATE_CONNECTED { "CONNECTED" };
static const constexpr char* CONNECTION_STATE_DISCONNECTED { "DISCONNECTED" };

/** Default parameters */
const int DEFAULT_PORT = 9001;
const float DEFAULT_SAMPLE_RATE = 30000.0f;
const float DEFAULT_DATA_SCALE = 1.0f; // 0.195f for Intan devices
const float DEFAULT_DATA_OFFSET = 0.0f; // 32768.0f for Intan devices
static constexpr int DEFAULT_PORT { 9001 };
static constexpr float DEFAULT_SAMPLE_RATE { 30000.0f };
static constexpr float DEFAULT_DATA_SCALE { 1.0f }; // 0.195f for Intan devices
static constexpr float DEFAULT_DATA_OFFSET { 0.0f }; // 32768.0f for Intan devices

/** 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;
const float MIN_PORT = 1023;
const float MAX_PORT = 65535;
const float MIN_SAMPLE_RATE = 0;
const float MAX_SAMPLE_RATE = 50000.0f;
static constexpr float MIN_DATA_SCALE { 0.0f };
static constexpr float MAX_DATA_SCALE { 9999.9f };
static constexpr float MIN_DATA_OFFSET { 0 };
static constexpr float MAX_DATA_OFFSET { 65536 };
static constexpr float MIN_PORT { 1023 };
static constexpr float MAX_PORT { 65535 };
static constexpr float MIN_SAMPLE_RATE { 0 };
static constexpr float MAX_SAMPLE_RATE { 50000.0f };

/** Constructor */
EphysSocket (SourceNode* sn);
Expand All @@ -34,7 +38,7 @@ class EphysSocket : public DataThread
~EphysSocket();

/** Creates custom editor */
std::unique_ptr<GenericEditor> createEditor (SourceNode* sn);
std::unique_ptr<GenericEditor> createEditor (SourceNode* sn) override;

/** Create the DataThread object*/
static DataThread* createDataThread (SourceNode* sn);
Expand All @@ -51,13 +55,13 @@ class EphysSocket : public DataThread
OwnedArray<SpikeChannel>* spikeChannels,
OwnedArray<DataStream>* sourceStreams,
OwnedArray<DeviceInfo>* devices,
OwnedArray<ConfigurationObject>* configurationObjects);
OwnedArray<ConfigurationObject>* configurationObjects) override;

/** Handles parameter value changes */
void parameterValueChanged (Parameter* parameter) override;

/** Resizes buffers when input parameters are changed*/
void resizeBuffers();
void resizeBuffers() override;

/** Disconnects the socket */
void disconnectSocket();
Expand Down
2 changes: 1 addition & 1 deletion Source/OpenEphysLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extern "C" EXPORT void getLibInfo (Plugin::LibraryInfo* info)
{
info->apiVersion = PLUGIN_API_VER;
info->name = "Ephys Socket";
info->libVersion = "1.0.0";
info->libVersion = "1.1.0";
info->numPlugins = NUM_PLUGINS;
}

Expand Down