1
0

Initial commit

This commit is contained in:
2023-06-21 13:51:38 +02:00
commit 957670ce42
45 changed files with 1894 additions and 0 deletions

67
Testation/Program.cs Normal file
View File

@@ -0,0 +1,67 @@
using System.Globalization;
using System.Text.Json;
using MoniteurBaie.DataModels;
using StackExchange.Redis;
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
using var redis = ConnectionMultiplexer.Connect("mercedes.hbsha.re:6379", opts =>
{
opts.ClientName = "Testation";
});
var packetChannel = redis.GetSubscriber().Subscribe("batCtrlPackets");
packetChannel.OnMessage(OnPacketMessage);
using var cancel = new AutoResetEvent(false);
void ctrlC(object? sender, ConsoleCancelEventArgs e)
{
e.Cancel = true;
Console.CancelKeyPress -= ctrlC;
cancel.Set();
}
Console.CancelKeyPress += ctrlC;
cancel.WaitOne();
static void OnPacketMessage(ChannelMessage channelMessage)
{
BatteryControllerPacket? batCtrlPacket;
try
{
batCtrlPacket = JsonSerializer.Deserialize(channelMessage.Message.ToString(), BatteryControllerPacketContext.Default.BatteryControllerPacket);
}
catch (Exception ex)
{
Console.WriteLine("Invalid packet.");
Console.WriteLine(ex);
return;
}
if (batCtrlPacket is null)
{
Console.WriteLine("Null packet.");
return;
}
SerialDataPacket packet;
try
{
packet = PacketParser.ParseSerialDataPacket(batCtrlPacket.SerialData);
}
catch (Exception ex)
{
Console.WriteLine("Invalid data packet.");
Console.WriteLine(ex);
throw;
}
if (packet.Temp_alim < 0 || packet.Temp_bat < 0 || packet.Temp_cha < 0)
{
Console.WriteLine($"[{batCtrlPacket.Timestamp:yyyy/MM/dd HH:mm:ss}] {batCtrlPacket.SerialData}");
}
}

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifier>linux-arm64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Remove="publish\**" />
<EmbeddedResource Remove="publish\**" />
<None Remove="publish\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StackExchange.Redis" Version="2.6.70" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DataModels\DataModels.csproj" />
<ProjectReference Include="..\Utils\Utils.csproj" />
</ItemGroup>
</Project>