diff --git a/Source/EphysSocket.cpp b/Source/EphysSocket.cpp index b8c353b..ee7dbc3 100644 --- a/Source/EphysSocket.cpp +++ b/Source/EphysSocket.cpp @@ -47,7 +47,7 @@ void EphysSocket::registerParameters() void EphysSocket::disconnectSocket() { socket.signalThreadShouldExit(); - socket.waitForThreadToExit(1000); + socket.waitForThreadToExit (1000); socket.disconnectSocket(); getParameter ("port")->setEnabled (true); @@ -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 - Updates the data scale to data_scale // ES OFFSET - Updates the offset to data_offset // ES PORT - Updates the port number that EphysSocket connects to // ES FREQUENCY - 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) @@ -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(); @@ -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."; diff --git a/Source/EphysSocket.h b/Source/EphysSocket.h index e15ef07..6f6cd86 100644 --- a/Source/EphysSocket.h +++ b/Source/EphysSocket.h @@ -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); @@ -34,7 +38,7 @@ class EphysSocket : public DataThread ~EphysSocket(); /** Creates custom editor */ - std::unique_ptr createEditor (SourceNode* sn); + std::unique_ptr createEditor (SourceNode* sn) override; /** Create the DataThread object*/ static DataThread* createDataThread (SourceNode* sn); @@ -51,13 +55,13 @@ class EphysSocket : public DataThread OwnedArray* spikeChannels, OwnedArray* sourceStreams, OwnedArray* devices, - OwnedArray* configurationObjects); + OwnedArray* 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(); diff --git a/Source/OpenEphysLib.cpp b/Source/OpenEphysLib.cpp index f2c7f8c..c9e7100 100644 --- a/Source/OpenEphysLib.cpp +++ b/Source/OpenEphysLib.cpp @@ -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; }