Skip to content

Commit

Permalink
Prepare to test the csharp library; removed all the dependencies from…
Browse files Browse the repository at this point in the history
… the PinakothekDrawing c#-project
  • Loading branch information
Andrei Costinescu committed May 22, 2021
1 parent f3ed26b commit 4332d86
Show file tree
Hide file tree
Showing 9 changed files with 648 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
*__pycache__*
*.pyc

*.vs

csharp/*.sln
csharp/*.csproj
csharp/bin
csharp/obj
490 changes: 490 additions & 0 deletions csharp/Client.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion csharp/Comm/communication/Communicator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Comm.data;
using Comm.socket;
using DesignAIRobotics.Utils;
using Comm.utils;
using System;
using System.Diagnostics;

Expand Down
2 changes: 1 addition & 1 deletion csharp/Comm/socket/Socket.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Comm.utils;
using DesignAIRobotics.Utils;
// using DesignAIRobotics.Utils;
using System;
using System.Diagnostics;
using System.Net;
Expand Down
28 changes: 28 additions & 0 deletions csharp/Comm/utils/DebugUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;

namespace Comm.utils {
public class DebugUtils {
private static DebugUtils defaultDebugUtilsImplementation = new DebugUtils();
private static DebugUtils debugUtilsImplementation;

public virtual void SetOutputImpl(string message) {
Console.WriteLine(message);
}

public static void SetDebugImplementation(DebugUtils debugUtilsImplementation) {
DebugUtils.debugUtilsImplementation = debugUtilsImplementation;
}

public static void ResetDebugImplementation() {
DebugUtils.debugUtilsImplementation = null;
}

public static void SetOutput(string message) {
if (DebugUtils.debugUtilsImplementation == null) {
DebugUtils.defaultDebugUtilsImplementation.SetOutputImpl(message);
} else {
DebugUtils.debugUtilsImplementation.SetOutputImpl(message);
}
}
}
}
13 changes: 13 additions & 0 deletions csharp/Comm/utils/Reference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Comm.utils {
public class Reference<T> {
private T v;
public T Value {
get => this.v;
set {
this.v = value;
}
}

public Reference() { }
}
}
65 changes: 65 additions & 0 deletions csharp/CommunicatorApplication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using Comm.communication;
using Comm.data;
using Comm.socket;
using Comm.utils;
using System;

namespace Comm {
public class CommunicatorApplication {
public CommunicatorApplication() {
this.quit = false;
this.state = CommunicatorState.COMMUNICATOR_IDLE;
this.dataCollection = new DataCollection();
}

~CommunicatorApplication() { }

public virtual void main() {
while (!this.quit) {
this._preMain();
try {
this._main();
} catch (Exception e) {
Console.WriteLine("Exception caught: " + e.ToString());
}
this._postMain();
}
}

public virtual void stop() {
this.quit = true;
}

protected bool send(Communication comm, SocketType socketType, CommunicationData data, int retries = 0, bool verbose = false) {
return Communicator.send(comm, socketType, data, false, true, retries, verbose);
}

protected bool send(Communication comm, SocketType socketType, byte[] data, int dataSize, int retries = 0, bool verbose = false) {
return Communicator.send(comm, socketType, data, dataSize, retries, verbose);
}

protected bool syphon(Communication comm, SocketType socketType, ref MessageType messageType, CommunicationData data, int retries = 0, bool verbose = false, int syphonRetries = 10) {
return Communicator.syphon(comm, socketType, ref messageType, data, ref this.quit, retries, verbose);
}

protected bool listen(Communication comm, SocketType socketType, ref MessageType messageType, ref DataCollection _dataCollection, int retries = 0, bool verbose = false) {
return Communicator.listen(comm, socketType, ref messageType, ref _dataCollection, ref this.quit, retries, verbose);
}

protected bool listenFor(Communication comm, SocketType socketType, CommunicationData data,
Reference<bool> timeoutResult = null, int countIgnoreOther = -1,
int countOther = -1, int retries = 0, bool verbose = false) {
return Communicator.listenFor(comm, socketType, data, ref this.quit, timeoutResult, countIgnoreOther, countOther, retries, verbose);
}

protected virtual void _preMain() { }

protected virtual void _main() { }

protected virtual void _postMain() { }

protected bool quit;
protected CommunicatorState state;
protected DataCollection dataCollection;
};
}
43 changes: 43 additions & 0 deletions csharp/CoordinateGetter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Comm.data;
using System;

namespace Comm {
public class CoordinateGetter {
public CoordinateGetter() {
this.x = 0.5;
this.y = 0.5;
this.touch = true;
this.buttonFwd = false;
this.buttonDwn = false;
this.startTime = DateTime.Now;
}

~CoordinateGetter() { }

public void resetDrawingArea(bool withTimeReset = true) {
if (withTimeReset) {
this.startTime = DateTime.Now;
}
}

public void setData(float x, float y, bool touch) {
this.x = x;
this.y = y;
this.touch = touch;
}

public bool getData(CoordinateData data) {
data.set("touch", this.touch);
data.set("buttonFwd", this.buttonFwd);
data.set("buttonDwn", this.buttonDwn);
data.set("x", x);
data.set("y", y);
data.set("time", (long)(DateTime.Now - this.startTime).Milliseconds);
return true;
}

double x, y;
bool buttonFwd, buttonDwn, touch;
DateTime startTime;
};
}
3 changes: 1 addition & 2 deletions csharp/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Comm.communication;
using Comm.data;
using Comm.socket;
using DesignAIRobotics.Client;
using System;
using System.Diagnostics;
using System.Net;
Expand Down Expand Up @@ -671,7 +670,7 @@ public static void test() {
}

public static class Tester {
static void test(string[] args) {
static void Main(string[] args) {
Console.WriteLine("Hello World!");

TestClient.test();
Expand Down

0 comments on commit 4332d86

Please sign in to comment.