2023-07-27 14:52:40 +00:00
|
|
|
|
// dotnet publish BmsTunnel.csproj -c Release -r linux-arm -p:PublishSingleFile=true --self-contained true && \
|
2023-02-16 12:57:06 +00:00
|
|
|
|
// rsync -av bin/Release/net6.0/linux-arm/publish/ root@10.2.1.6:/home/root/tunnel && clear && \
|
|
|
|
|
// ssh root@10.2.1.6 /home/root/tunnel/BmsTunnel
|
|
|
|
|
|
|
|
|
|
using InnovEnergy.Lib.Utils;
|
|
|
|
|
using static System.String;
|
|
|
|
|
|
2023-02-25 14:53:58 +00:00
|
|
|
|
namespace InnovEnergy.App.BmsTunnel;
|
2023-02-16 12:57:06 +00:00
|
|
|
|
|
|
|
|
|
public static class Program
|
|
|
|
|
{
|
|
|
|
|
private const Byte DefaultNode = 2;
|
|
|
|
|
|
|
|
|
|
public static async Task<Int32> Main(String[] args)
|
|
|
|
|
{
|
2023-06-19 14:15:59 +00:00
|
|
|
|
var tty = await BatteryTty.GetTty();
|
2023-02-16 12:57:06 +00:00
|
|
|
|
|
2023-06-19 14:15:59 +00:00
|
|
|
|
if (tty is null)
|
2023-02-16 12:57:06 +00:00
|
|
|
|
return 2;
|
|
|
|
|
|
2023-06-19 14:15:59 +00:00
|
|
|
|
Console.WriteLine("\nstarting BMS tunnel\n");
|
2023-02-16 12:57:06 +00:00
|
|
|
|
|
2023-06-19 14:15:59 +00:00
|
|
|
|
using var tunnel = new BmsTunnel(tty, 2);
|
2023-02-16 12:57:06 +00:00
|
|
|
|
|
|
|
|
|
ExplainNode();
|
|
|
|
|
ExplainExit();
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
Console.Write($"node{tunnel.Node}> ");
|
|
|
|
|
|
|
|
|
|
var cmd = Console.ReadLine()?.ToUpper().Trim();
|
|
|
|
|
|
|
|
|
|
if (IsNullOrEmpty(cmd))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (cmd.StartsWith("/"))
|
|
|
|
|
{
|
|
|
|
|
var exit = ProcessLocalCommand(cmd);
|
|
|
|
|
if (exit)
|
|
|
|
|
break;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tunnel.SendCommand(cmd).Skip(1).ForEach(Console.WriteLine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Boolean ProcessLocalCommand(String cmd)
|
|
|
|
|
{
|
2023-06-19 14:15:59 +00:00
|
|
|
|
cmd = cmd.TrimStart('/').Trim().ToUpper();
|
2023-02-16 12:57:06 +00:00
|
|
|
|
|
|
|
|
|
if (cmd == "EXIT")
|
|
|
|
|
return true;
|
2023-06-19 14:15:59 +00:00
|
|
|
|
if (cmd.StartsWith("NODE "))
|
2023-02-16 12:57:06 +00:00
|
|
|
|
ChangeNode(cmd);
|
|
|
|
|
else
|
|
|
|
|
Console.WriteLine("unrecognized command");
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ChangeNode(String cmd)
|
|
|
|
|
{
|
|
|
|
|
var ndStr = cmd[5..].Trim();
|
|
|
|
|
|
|
|
|
|
if (!Byte.TryParse(ndStr, out var newNode))
|
|
|
|
|
{
|
|
|
|
|
ExplainNode();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tunnel.Node = newNode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ExplainExit() => Console.WriteLine("/exit exit bms cli");
|
|
|
|
|
private static void ExplainNode() => Console.WriteLine("/node <nb> change to node number <nb>");
|
|
|
|
|
}
|