Skip to content
Open
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
10 changes: 10 additions & 0 deletions Palmtree/Palmtree.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@
<Reference Include="System.Data" />
<Reference Include="System.Windows.Forms.DataVisualization" />
<Reference Include="System.Xml" />
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="websocket-sharp, Version=1.0.1.0, Culture=neutral, PublicKeyToken=5660b08a1845a91e, processorArchitecture=MSIL">
<HintPath>..\packages\WebSocketSharp-netstandard.1.0.1\lib\net45\websocket-sharp.dll</HintPath>
</Reference>
<Reference Include="System.Text.Json, Version=5.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Json.5.0.2\lib\net461\System.Text.Json.dll</HintPath>
</Reference>
<Reference Include="Windows, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>dependencies\Windows.winmd</HintPath>
Expand Down Expand Up @@ -131,6 +140,7 @@
<Compile Include="src\Core\Params\ParamSeperator.cs" />
<Compile Include="src\Filters\RedistributionFilter.cs" />
<Compile Include="src\Filters\FlexKeySequenceFilter.cs" />
<Compile Include="src\Filters\WSIO.cs" />
<Compile Include="src\Filters\WSIOFilter.cs" />
<Compile Include="src\GUI\GUIMore.cs">
<SubType>Form</SubType>
Expand Down
3 changes: 3 additions & 0 deletions Palmtree/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
<package id="OpenTK.GLControl" version="3.1.0" targetFramework="net48" />
<package id="SharpGL" version="2.4.0.0" targetFramework="net452" />
<package id="SharpGL.WinForms" version="2.4.0.0" targetFramework="net452" />
<package id="WebSocketSharp-netstandard" version="1.0.1" targetFramework="net48" />
<package id="System.Memory" version="4.5.4" targetFramework="net48" />
<package id="System.Text.Json" version="5.0.2" targetFramework="net48" />
</packages>
6 changes: 5 additions & 1 deletion Palmtree/src/Core/DataIO/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace Palmtree.Core.DataIO {
/// providing slightly better performance (important since the Data class is called upon very frequently)
/// </summary>
public static class Data {
public delegate void OnEventLogged(string eventMessage);
public static event OnEventLogged eventLogged;

private const string CLASS_NAME = "Data";
private const int CLASS_VERSION = 3;
Expand Down Expand Up @@ -1442,7 +1444,9 @@ public static void logEvent(int level, string text, string value) {

// construct event String
string eventOut = eventTime.ToString("yyyyMMdd_HHmmss_fff") + " " + eventRunElapsedTime + " " + strsourceSamplePackageCounter + " " + strDataSampleCounter + " " + text + " " + value;

if(eventLogged != null) {
eventLogged(eventOut);
}
// write event to event file
if (eventStreamWriters.Count > levelIndex && eventStreamWriters[levelIndex] != null) {

Expand Down
31 changes: 31 additions & 0 deletions Palmtree/src/Filters/WSIO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using NLog;
using Palmtree.Core;
using Palmtree.Core.DataIO;
using Palmtree.Core.Params;
using Palmtree.Filters;
using System;
using System.Linq;
using WebSocketSharp;
using WebSocketSharp.Server;
using System.Text.Json;

namespace Palmtree.Filters
{

public class WSIO : WebSocketBehavior
{
private static NLog.Logger logger = LogManager.GetLogger("Data");

public class DataStruct
{
public string eventState { get; set; }
public string eventCode { get; set; }
}

protected override void OnMessage(MessageEventArgs e)
{
DataStruct dataStruct = JsonSerializer.Deserialize<DataStruct>(e.Data);
Data.logEvent(1, dataStruct.eventState, dataStruct.eventCode);
}
}
}
95 changes: 71 additions & 24 deletions Palmtree/src/Filters/WSIOFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
using NLog;
using Palmtree.Core;
using Palmtree.Core.Params;
using Palmtree.Core.DataIO;
using WebSocketSharp.Server;
using System;
using System.Linq;

namespace Palmtree.Filters {

Expand All @@ -25,6 +28,8 @@ namespace Palmtree.Filters {
/// ...
/// </summary>
public class WSIOFilter : FilterBase, IFilter {
public static WebSocketServer wssv_data;
public static WebSocketServer wssv_event;

private new const int CLASS_VERSION = 1;

Expand All @@ -41,21 +46,29 @@ public WSIOFilter(string filterName) {
parameters = ParameterManager.GetParameters(filterName, Parameters.ParamSetTypes.Filter);

// define the parameters
parameters.addParameter <bool> (
parameters.addParameter<bool>(
"EnableFilter",
"Enable TimeSmoothing Filter",
"Enable WSIO Filter",
"1");

parameters.addParameter<bool>(
"LogDataStreams",
"Log the filter's intermediate and output data streams. See 'Data' tab for more settings on sample stream logging.",
"0");

// message
logger.Info("Filter created (version " + CLASS_VERSION + ")");
parameters.addParameter<double>(
"Data_WebsocketPort",
"Port to send data out onto",
"21111");
parameters.addParameter<double>(
"Event_WebsocketPort",
"Port to send data out onto",
"21112");

Data.eventLogged += Data_onEventLogged;

}

/**
* Configure the filter. Checks the values and application logic of the
* parameters and, if valid, transfers the configuration parameters to local variables
Expand Down Expand Up @@ -83,7 +96,7 @@ public bool configure(ref SamplePackageFormat input, out SamplePackageFormat out
// store a references to the input and output format
inputFormat = input;
outputFormat = output;

// check the values and application logic of the parameters
if (!checkParameters(parameters)) return false;

Expand All @@ -106,7 +119,7 @@ public bool configure(ref SamplePackageFormat input, out SamplePackageFormat out
/// <param name="resetOption">Filter reset options. 0 will reset the minimum; 1 will perform a complete reset of filter information. > 1 for custom resets.</param>
/// <returns>A boolean, either true for a succesfull re-configuration, or false upon failure</returns>
public bool configureRunningFilter(Parameters newParameters, int resetOption) {

// check if new parameters are given (only a reset is also an option)
if (newParameters != null) {

Expand Down Expand Up @@ -163,7 +176,7 @@ public bool configureRunningFilter(Parameters newParameters, int resetOption) {

// TODO: take resetFilter into account (currently always resets the buffers on initialize
// but when set not to reset, the buffers should be resized while retaining their values!)


// initialize the variables
initialize();
Expand All @@ -187,7 +200,7 @@ private bool checkParameters(Parameters newParameters) {

// check if the filter is enabled
if (newEnableFilter) {


}

Expand All @@ -206,7 +219,7 @@ private void transferParameters(Parameters newParameters) {

// check if the filter is enabled
if (mEnableFilter) {

}

}
Expand All @@ -228,20 +241,27 @@ public bool initialize() {

// check if the filter is enabled
if (mEnableFilter) {
double wsPort_data = parameters.getValue<double>("Data_WebsocketPort");
double wsPort_event = parameters.getValue<double>("Event_WebsocketPort");


wssv_data = new WebSocketServer("ws://localhost:" + wsPort_data);
wssv_event = new WebSocketServer("ws://localhost:" + wsPort_event);

wssv_data.AddWebSocketService<WSIO>("/");
wssv_event.AddWebSocketService<WSIO>("/");
}

// return success
return true;

}

public void start() {

wssv_data.Start();
wssv_event.Start();
}

public void stop() {
wssv_data.Stop();
wssv_event.Stop();

}

Expand All @@ -250,28 +270,55 @@ public bool isStarted() {
}

public void process(double[] input, out double[] output) {

// create the output package
output = new double[input.Length];

// check if the filter is enabled
output = input;
if (mEnableFilter) {
// filter enabled

// TODO: send input-package to anywhere...


byte[] result = new byte[0];
output.Select(n =>
{
BitConverter.GetBytes(n).ToArray().Select(m =>
{
result = result.Append(m).ToArray();

return m;
}).ToArray();

return n;
}).ToArray();

result = result.Prepend(Convert.ToByte(outputFormat.packageRate)).ToArray();
result = result.Prepend(Convert.ToByte(outputFormat.numSamples)).ToArray();
result = result.Prepend(Convert.ToByte(outputFormat.numChannels)).ToArray();

if (wssv_data.IsListening)
{
wssv_data.WebSocketServices["/"].Sessions.Broadcast(result);
}
}

// pass reference
output = input;

// handle the data logging of the output (both to file and for visualization)
processOutputLogging(output);

}


private void Data_onEventLogged(string message)
{
if (wssv_event.IsListening)
{
wssv_event.WebSocketServices["/"].Sessions.Broadcast(message);
}
}

public void destroy() {
wssv_data.Stop();
wssv_event.Stop();


// stop the filter
// Note: At this point stop will probably have been called from the mainthread before destroy, however there is a slight
Expand Down