Skip to content

Commit

Permalink
simulator add log-off
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Sep 23, 2024
1 parent 45775b0 commit 08cd3b3
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Portalum.Zvt.TerminalSimulator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,32 @@ class Program
static void Main(string[] args)
{
_tcpServer = new SimpleTcpServer("127.0.0.1", 20007);
_tcpServer.Events.ClientConnected += Events_ClientConnected;
_tcpServer.Events.ClientDisconnected += Events_ClientDisconnected;
_tcpServer.Events.DataReceived += Events_DataReceived;
_tcpServer.Start();

Console.WriteLine("Virtual Terminal ready on 127.0.0.1:20007");
Console.WriteLine("Wait for connections, press any key for quit");
Console.ReadLine();

_tcpServer.Events.ClientConnected -= Events_ClientConnected;
_tcpServer.Events.ClientDisconnected -= Events_ClientDisconnected;
_tcpServer.Events.DataReceived -= Events_DataReceived;
_tcpServer.Stop();
_tcpServer.Dispose();
}

private static void Events_ClientConnected(object? sender, ConnectionEventArgs e)
{
Console.WriteLine($"ClientConnected - {e.IpPort}");
}

private static void Events_ClientDisconnected(object? sender, ConnectionEventArgs e)
{
Console.WriteLine($"ClientDisconnected - {e.IpPort}");
}

private static void Events_DataReceived(object? sender, DataReceivedEventArgs e)
{
if (_tcpServer == null)
Expand Down Expand Up @@ -93,6 +107,19 @@ private static void Events_DataReceived(object? sender, DataReceivedEventArgs e)
return;
}

// Log-Off (06 02)
if (data.StartsWith(new byte[] { 0x06, 0x02 }))
{
Console.WriteLine($"Receive Log-Off - [{hexData}]");

Thread.Sleep(500);

Console.WriteLine("Send Command Completion");
_tcpServer.Send(e.IpPort, _commandCompletionPackage);

return;
}

Console.WriteLine($"Unknown command for simulator - [{hexData}]");
}
}

0 comments on commit 08cd3b3

Please sign in to comment.