commit b8e05f0b1e7ff1e5a55b5d811edd3984a3a8593d Author: BlubbFish Date: Mon Aug 3 13:53:03 2026 +0200 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d70d24 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vs +KeyboardBot/bin +KeyboardBot/obj \ No newline at end of file diff --git a/KeyboardBot.slnx b/KeyboardBot.slnx new file mode 100644 index 0000000..a3a194b --- /dev/null +++ b/KeyboardBot.slnx @@ -0,0 +1,7 @@ + + + + + + + diff --git a/KeyboardBot/KeyboardBot.csproj b/KeyboardBot/KeyboardBot.csproj new file mode 100644 index 0000000..2528ce1 --- /dev/null +++ b/KeyboardBot/KeyboardBot.csproj @@ -0,0 +1,14 @@ + + + + Exe + net10.0 + enable + enable + + + + + + + diff --git a/KeyboardBot/KeyboardRunner.cs b/KeyboardBot/KeyboardRunner.cs new file mode 100644 index 0000000..b4065e3 --- /dev/null +++ b/KeyboardBot/KeyboardRunner.cs @@ -0,0 +1,17 @@ +using BlubbFish.Utils.IoT.Bots; +using BlubbFish.Utils.IoT.Connector; + +namespace KeyboardBot { + internal class KeyboardRunner : MultiSourceBot { + public KeyboardRunner(String[] args, Boolean fileLogging, String configSearchPath, Dictionary sources, Dictionary settings) : base(args, fileLogging, configSearchPath, sources, settings) { + this.sources["udp"].MessageIncomming += this.KeyboardRunner_MessageIncomming; + this.WaitForShutdown(); + } + + private void KeyboardRunner_MessageIncomming(Object sender, BlubbFish.Utils.IoT.Events.BackendEvent e) { + if(this.sources["mqtt"] is not null and ADataBackend aDataBackend) { + aDataBackend.Send("barcodescanner", e.Message); + } + } + } +} diff --git a/KeyboardBot/Program.cs b/KeyboardBot/Program.cs new file mode 100644 index 0000000..36f1b22 --- /dev/null +++ b/KeyboardBot/Program.cs @@ -0,0 +1,67 @@ +using BlubbFish.Utils.IoT.Bots; +using System.Net; +using System.Net.Sockets; +using System.Text; +using System; + +namespace KeyboardBot { + internal class Program : ABot { + static void Main(String[] args) => _ = new Program(args, true, "bsparser"); + + public Program(String[] args, Boolean fileLogging, String configSearchPath) : base(args, fileLogging, configSearchPath) { + Console.WriteLine("Hello, World!"); + UdpListener server = new(); + + //start listening for messages and copy the messages back to the client + _ = Task.Factory.StartNew(async () => { + while(true) { + Received received = await server.Receive(); + //server.Reply("copy " + received.Message, received.Sender); + Console.WriteLine($"Read message {DateTime.Now}: \"{received.Message}\""); + + /*if(received.Message == "quit") + break;*/ + } + }); + this.WaitForShutdown(); + } + } + + //Server + class UdpListener : UdpBase { + private readonly IPEndPoint _listenOn; + + public UdpListener() : this(new IPEndPoint(IPAddress.Any, 58627)) { + } + + public UdpListener(IPEndPoint endpoint) { + this._listenOn = endpoint; + this.Client = new UdpClient(this._listenOn); + } + + /*public void Reply(string message, IPEndPoint endpoint) { + var datagram = Encoding.ASCII.GetBytes(message); + Client.Send(datagram, datagram.Length, endpoint); + }*/ + + } + + abstract class UdpBase { + protected UdpClient Client; + + protected UdpBase() => this.Client = new UdpClient(); + + public async Task Receive() { + UdpReceiveResult result = await this.Client.ReceiveAsync(); + return new Received() { + Message = Encoding.UTF8.GetString(result.Buffer, 0, result.Buffer.Length), + Sender = result.RemoteEndPoint + }; + } + } + + public struct Received { + public IPEndPoint Sender; + public String Message; + } +} \ No newline at end of file