Changes to the backend/controller: Fixed timing bug in calibration charge, rebind to udp port when the endpoint changes ip

This commit is contained in:
Noe 2024-04-30 11:43:10 +02:00
parent 6acb5e134b
commit cee72bebe6
4 changed files with 41 additions and 19 deletions

View File

@ -16,7 +16,8 @@ dotnet publish \
-r linux-x64 -r linux-x64
echo -e "\n============================ Deploy ============================\n" echo -e "\n============================ Deploy ============================\n"
ip_addresses=("10.2.3.115" "10.2.3.104" "10.2.4.33" "10.2.4.32" "10.2.4.36" "10.2.4.35" "10.2.4.154" "10.2.4.113" "10.2.4.29" "10.2.4.211") ip_addresses=("10.2.3.115" "10.2.3.104" "10.2.4.33" "10.2.4.32" "10.2.4.36" "10.2.4.35" "10.2.4.154" "10.2.4.113" "10.2.4.29")
for ip_address in "${ip_addresses[@]}"; do for ip_address in "${ip_addresses[@]}"; do
rsync -v \ rsync -v \

View File

@ -197,16 +197,17 @@ public static class Controller
(calibrationChargeForced == CalibrationChargeType.RepetitivelyEvery && repetitiveCalibrationRequired); (calibrationChargeForced == CalibrationChargeType.RepetitivelyEvery && repetitiveCalibrationRequired);
Console.WriteLine("Next Repetitive calibration charge date is "+statusRecord.Config.DayAndTimeForRepetitiveCalibration); Console.WriteLine("Next Repetitive calibration charge date is "+statusRecord.Config.DayAndTimeForRepetitiveCalibration);
Console.WriteLine("Next Additional calibration charge date is "+statusRecord.Config.DayAndTimeForAdditionalCalibration); Console.WriteLine("Next Additional calibration charge date is "+statusRecord.Config.DayAndTimeForAdditionalCalibration);
//Console.WriteLine("Time now is "+DateTime.Now);
if (statusRecord.Battery is not null) if (statusRecord.Battery is not null)
{ {
if (calibrationChargeForced == CalibrationChargeType.AdditionallyOnce && statusRecord.Battery.Eoc ) if (calibrationChargeForced == CalibrationChargeType.AdditionallyOnce && statusRecord.Battery.Eoc )
{ {
statusRecord.Config.ForceCalibrationChargeState = CalibrationChargeType.RepetitivelyEvery; statusRecord.Config.ForceCalibrationChargeState = CalibrationChargeType.RepetitivelyEvery;
_hasAdditionalCalibrationChargeChecked = false; //_hasAdditionalCalibrationChargeChecked = false;
} }
else if (calibrationChargeForced == CalibrationChargeType.RepetitivelyEvery && statusRecord.Battery.Eoc ) else if (calibrationChargeForced == CalibrationChargeType.RepetitivelyEvery && statusRecord.Battery.Eoc && _hasRepetitiveCalibrationChargeChecked)
{ {
statusRecord.Config.DayAndTimeForRepetitiveCalibration = statusRecord.Config.DayAndTimeForRepetitiveCalibration.AddDays(7); statusRecord.Config.DayAndTimeForRepetitiveCalibration = statusRecord.Config.DayAndTimeForRepetitiveCalibration.AddDays(7);
_hasRepetitiveCalibrationChargeChecked = false; _hasRepetitiveCalibrationChargeChecked = false;
@ -217,30 +218,41 @@ public static class Controller
private static Boolean RepetitiveCalibrationDateHasBeenPassed(DateTime calibrationChargeDate) private static Boolean RepetitiveCalibrationDateHasBeenPassed(DateTime calibrationChargeDate)
{ {
if (!_hasRepetitiveCalibrationChargeChecked) // if (!_hasRepetitiveCalibrationChargeChecked)
// {
// if (DateTime.Now >= calibrationChargeDate )
// {
// _hasRepetitiveCalibrationChargeChecked = true;
// return true;
// }
// return false;
// }
// return true;
if (DateTime.Now >= calibrationChargeDate )
{ {
if (DateTime.Now >= calibrationChargeDate ) _hasRepetitiveCalibrationChargeChecked = true;
{ return true;
_hasRepetitiveCalibrationChargeChecked = true;
return true;
}
return false;
} }
return true; return false;
} }
private static Boolean AdditionalCalibrationDateHasBeenPassed(DateTime calibrationChargeDate) private static Boolean AdditionalCalibrationDateHasBeenPassed(DateTime calibrationChargeDate)
{ {
if (!_hasAdditionalCalibrationChargeChecked) // if (!_hasAdditionalCalibrationChargeChecked)
{ // {
if (DateTime.Now >= calibrationChargeDate ) if (DateTime.Now >= calibrationChargeDate )
{ {
_hasAdditionalCalibrationChargeChecked = true; //_hasAdditionalCalibrationChargeChecked = true;
return true; return true;
} }
return false; return false;
} // }
return true; // return true;
} }

View File

@ -11,6 +11,7 @@ public static class MiddlewareAgent
{ {
public static UdpClient UdpListener = null!; public static UdpClient UdpListener = null!;
private static IPAddress? _controllerIpAddress; private static IPAddress? _controllerIpAddress;
private static EndPoint? _endPoint;
public static void InitializeCommunicationToMiddleware() public static void InitializeCommunicationToMiddleware()
{ {
@ -21,11 +22,11 @@ public static class MiddlewareAgent
} }
const Int32 udpPort = 9000; const Int32 udpPort = 9000;
var endPoint = new IPEndPoint(_controllerIpAddress, udpPort); _endPoint = new IPEndPoint(_controllerIpAddress, udpPort);
UdpListener = new UdpClient(); UdpListener = new UdpClient();
UdpListener.Client.Blocking = false; UdpListener.Client.Blocking = false;
UdpListener.Client.Bind(endPoint); UdpListener.Client.Bind(_endPoint);
} }
private static IPAddress FindVpnIp() private static IPAddress FindVpnIp()
@ -54,6 +55,7 @@ public static class MiddlewareAgent
{ {
if (UdpListener.Available > 0) if (UdpListener.Available > 0)
{ {
IPEndPoint? serverEndpoint = null; IPEndPoint? serverEndpoint = null;
var replyMessage = "ACK"; var replyMessage = "ACK";
@ -72,6 +74,13 @@ public static class MiddlewareAgent
return config; return config;
} }
if (!_endPoint.Equals((IPEndPoint)UdpListener.Client.LocalEndPoint))
{
Console.WriteLine("UDP address has changed, rebinding...");
InitializeCommunicationToMiddleware();
}
return null; return null;
} }

View File

@ -1,4 +1,4 @@
#define Amax #undef Amax
#undef GridLimit #undef GridLimit
using System.Reactive.Linq; using System.Reactive.Linq;