Skip to content

Commit 35f7a3c

Browse files
tzijngeTimon Zijnge
andauthored
#26 allow connecting through http server (#28)
* #26 Allow connecting through HTTP server * Added additional string parameter 'connection_state'. Allow modifying it through the HTTP config interface to connect/disconnect the socket * #26 Allow connecting through HTTP server * Cleanup and a small clarification * #26 Allow connecting through HTTP server * Cleanup * #26 Allow connecting through HTTP server * Addressing review comments. Removed parameter to simplify code and process of connecting and disconnecting remotely * Update library version * #26 Allow connecting through HTTP server * revert unrelated changes --------- Co-authored-by: Timon Zijnge <timon.zijnge@imec.nl>
1 parent 69c5e40 commit 35f7a3c

File tree

3 files changed

+47
-23
lines changed

3 files changed

+47
-23
lines changed

Source/EphysSocket.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void EphysSocket::registerParameters()
4747
void EphysSocket::disconnectSocket()
4848
{
4949
socket.signalThreadShouldExit();
50-
socket.waitForThreadToExit(1000);
50+
socket.waitForThreadToExit (1000);
5151
socket.disconnectSocket();
5252

5353
getParameter ("port")->setEnabled (true);
@@ -278,22 +278,20 @@ bool EphysSocket::updateBuffer()
278278
String EphysSocket::handleConfigMessage (const String& msg)
279279
{
280280
// Available commands:
281-
// ES INFO - Returns info on current variables that can be modified over HTTP
281+
// ES INFO - Returns info on current variables that can be modified over HTTP
282282
// ES SCALE <data_scale> - Updates the data scale to data_scale
283283
// ES OFFSET <data_offset> - Updates the offset to data_offset
284284
// ES PORT <port> - Updates the port number that EphysSocket connects to
285285
// ES FREQUENCY <sample_rate> - Updates the sampling rate
286+
// ES CONNECTION_STATE - Returns the connection state (CONNECTED/DISCONNECTED)
287+
// ES CONNECT - Connect the socket
288+
// ES DISCCONNECT - Disconnect the socket
286289

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

292-
if (socket.isConnected())
293-
{
294-
return "Ephys Socket plugin cannot update settings while connected to an active socket.";
295-
}
296-
297295
StringArray parts = StringArray::fromTokens (msg, " ", "");
298296

299297
if (parts.size() > 0)
@@ -302,6 +300,11 @@ String EphysSocket::handleConfigMessage (const String& msg)
302300
{
303301
if (parts.size() == 3)
304302
{
303+
if (socket.isConnected())
304+
{
305+
return "Ephys Socket plugin cannot update settings while connected to an active socket.";
306+
}
307+
305308
if (parts[1].equalsIgnoreCase ("SCALE"))
306309
{
307310
float scale = parts[2].getFloatValue();
@@ -365,6 +368,23 @@ String EphysSocket::handleConfigMessage (const String& msg)
365368
{
366369
return "Port = " + String (port) + ". Sample rate = " + String (sample_rate) + "Scale = " + String (data_scale) + ". Offset = " + String (data_offset) + ".";
367370
}
371+
else if (parts[1].equalsIgnoreCase ("CONNECTION_STATUS"))
372+
{
373+
return socket.isConnected() ? CONNECTION_STATE_CONNECTED : CONNECTION_STATE_DISCONNECTED;
374+
}
375+
else if (parts[1].equalsIgnoreCase ("CONNECT"))
376+
{
377+
LOGC ("Request socket connect");
378+
const auto connected = connectSocket();
379+
LOGC (connected ? "Connection success" : "Connection failed");
380+
return connected ? CONNECTION_STATE_CONNECTED : CONNECTION_STATE_DISCONNECTED;
381+
}
382+
else if (parts[1].equalsIgnoreCase ("DISCONNECT"))
383+
{
384+
disconnectSocket();
385+
LOGC ("Socket disconnected");
386+
return CONNECTION_STATE_DISCONNECTED;
387+
}
368388
else
369389
{
370390
return "ES command " + parts[1] + "not recognized.";

Source/EphysSocket.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,25 @@ namespace EphysSocketNode
1111
class EphysSocket : public DataThread
1212
{
1313
public:
14+
/** Connection states */
15+
static const constexpr char* CONNECTION_STATE_CONNECTED { "CONNECTED" };
16+
static const constexpr char* CONNECTION_STATE_DISCONNECTED { "DISCONNECTED" };
17+
1418
/** Default parameters */
15-
const int DEFAULT_PORT = 9001;
16-
const float DEFAULT_SAMPLE_RATE = 30000.0f;
17-
const float DEFAULT_DATA_SCALE = 1.0f; // 0.195f for Intan devices
18-
const float DEFAULT_DATA_OFFSET = 0.0f; // 32768.0f for Intan devices
19+
static constexpr int DEFAULT_PORT { 9001 };
20+
static constexpr float DEFAULT_SAMPLE_RATE { 30000.0f };
21+
static constexpr float DEFAULT_DATA_SCALE { 1.0f }; // 0.195f for Intan devices
22+
static constexpr float DEFAULT_DATA_OFFSET { 0.0f }; // 32768.0f for Intan devices
1923

2024
/** Parameter limits */
21-
const float MIN_DATA_SCALE = 0.0f;
22-
const float MAX_DATA_SCALE = 9999.9f;
23-
const float MIN_DATA_OFFSET = 0;
24-
const float MAX_DATA_OFFSET = 65536;
25-
const float MIN_PORT = 1023;
26-
const float MAX_PORT = 65535;
27-
const float MIN_SAMPLE_RATE = 0;
28-
const float MAX_SAMPLE_RATE = 50000.0f;
25+
static constexpr float MIN_DATA_SCALE { 0.0f };
26+
static constexpr float MAX_DATA_SCALE { 9999.9f };
27+
static constexpr float MIN_DATA_OFFSET { 0 };
28+
static constexpr float MAX_DATA_OFFSET { 65536 };
29+
static constexpr float MIN_PORT { 1023 };
30+
static constexpr float MAX_PORT { 65535 };
31+
static constexpr float MIN_SAMPLE_RATE { 0 };
32+
static constexpr float MAX_SAMPLE_RATE { 50000.0f };
2933

3034
/** Constructor */
3135
EphysSocket (SourceNode* sn);
@@ -34,7 +38,7 @@ class EphysSocket : public DataThread
3438
~EphysSocket();
3539

3640
/** Creates custom editor */
37-
std::unique_ptr<GenericEditor> createEditor (SourceNode* sn);
41+
std::unique_ptr<GenericEditor> createEditor (SourceNode* sn) override;
3842

3943
/** Create the DataThread object*/
4044
static DataThread* createDataThread (SourceNode* sn);
@@ -51,13 +55,13 @@ class EphysSocket : public DataThread
5155
OwnedArray<SpikeChannel>* spikeChannels,
5256
OwnedArray<DataStream>* sourceStreams,
5357
OwnedArray<DeviceInfo>* devices,
54-
OwnedArray<ConfigurationObject>* configurationObjects);
58+
OwnedArray<ConfigurationObject>* configurationObjects) override;
5559

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

5963
/** Resizes buffers when input parameters are changed*/
60-
void resizeBuffers();
64+
void resizeBuffers() override;
6165

6266
/** Disconnects the socket */
6367
void disconnectSocket();

Source/OpenEphysLib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern "C" EXPORT void getLibInfo (Plugin::LibraryInfo* info)
3838
{
3939
info->apiVersion = PLUGIN_API_VER;
4040
info->name = "Ephys Socket";
41-
info->libVersion = "1.0.0";
41+
info->libVersion = "1.1.0";
4242
info->numPlugins = NUM_PLUGINS;
4343
}
4444

0 commit comments

Comments
 (0)