first commit

This commit is contained in:
BlubbFish 2026-08-03 13:53:03 +02:00
commit b8e05f0b1e
5 changed files with 108 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.vs
KeyboardBot/bin
KeyboardBot/obj

7
KeyboardBot.slnx Normal file
View File

@ -0,0 +1,7 @@
<Solution>
<Project Path="../Librarys/litjson/litjson/litjson.csproj" />
<Project Path="../Utils/Bot-Utils/Bot-Utils/Bot-Utils.csproj" />
<Project Path="../Utils/Utils-IoT/Utils-IoT/Utils-IoT.csproj" />
<Project Path="../Utils/Utils/Utils/Utils.csproj" />
<Project Path="KeyboardBot/KeyboardBot.csproj" />
</Solution>

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\Utils\Bot-Utils\Bot-Utils\Bot-Utils.csproj" />
</ItemGroup>
</Project>

View File

@ -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<String, ABackend> sources, Dictionary<String, String> 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);
}
}
}
}

67
KeyboardBot/Program.cs Normal file
View File

@ -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<Received> 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;
}
}