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:
parent
6acb5e134b
commit
cee72bebe6
|
@ -16,7 +16,8 @@ dotnet publish \
|
|||
-r linux-x64
|
||||
|
||||
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
|
||||
rsync -v \
|
||||
|
|
|
@ -197,16 +197,17 @@ public static class Controller
|
|||
(calibrationChargeForced == CalibrationChargeType.RepetitivelyEvery && repetitiveCalibrationRequired);
|
||||
Console.WriteLine("Next Repetitive calibration charge date is "+statusRecord.Config.DayAndTimeForRepetitiveCalibration);
|
||||
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 (calibrationChargeForced == CalibrationChargeType.AdditionallyOnce && statusRecord.Battery.Eoc )
|
||||
{
|
||||
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);
|
||||
_hasRepetitiveCalibrationChargeChecked = false;
|
||||
|
@ -217,30 +218,41 @@ public static class Controller
|
|||
|
||||
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;
|
||||
}
|
||||
return false;
|
||||
_hasRepetitiveCalibrationChargeChecked = true;
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
private static Boolean AdditionalCalibrationDateHasBeenPassed(DateTime calibrationChargeDate)
|
||||
{
|
||||
if (!_hasAdditionalCalibrationChargeChecked)
|
||||
{
|
||||
// if (!_hasAdditionalCalibrationChargeChecked)
|
||||
// {
|
||||
if (DateTime.Now >= calibrationChargeDate )
|
||||
{
|
||||
_hasAdditionalCalibrationChargeChecked = true;
|
||||
//_hasAdditionalCalibrationChargeChecked = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
// }
|
||||
// return true;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ public static class MiddlewareAgent
|
|||
{
|
||||
public static UdpClient UdpListener = null!;
|
||||
private static IPAddress? _controllerIpAddress;
|
||||
private static EndPoint? _endPoint;
|
||||
|
||||
public static void InitializeCommunicationToMiddleware()
|
||||
{
|
||||
|
@ -21,11 +22,11 @@ public static class MiddlewareAgent
|
|||
}
|
||||
|
||||
const Int32 udpPort = 9000;
|
||||
var endPoint = new IPEndPoint(_controllerIpAddress, udpPort);
|
||||
_endPoint = new IPEndPoint(_controllerIpAddress, udpPort);
|
||||
|
||||
UdpListener = new UdpClient();
|
||||
UdpListener.Client.Blocking = false;
|
||||
UdpListener.Client.Bind(endPoint);
|
||||
UdpListener.Client.Bind(_endPoint);
|
||||
}
|
||||
|
||||
private static IPAddress FindVpnIp()
|
||||
|
@ -54,6 +55,7 @@ public static class MiddlewareAgent
|
|||
{
|
||||
if (UdpListener.Available > 0)
|
||||
{
|
||||
|
||||
IPEndPoint? serverEndpoint = null;
|
||||
|
||||
var replyMessage = "ACK";
|
||||
|
@ -72,6 +74,13 @@ public static class MiddlewareAgent
|
|||
return config;
|
||||
}
|
||||
|
||||
if (!_endPoint.Equals((IPEndPoint)UdpListener.Client.LocalEndPoint))
|
||||
{
|
||||
Console.WriteLine("UDP address has changed, rebinding...");
|
||||
InitializeCommunicationToMiddleware();
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#define Amax
|
||||
#undef Amax
|
||||
#undef GridLimit
|
||||
|
||||
using System.Reactive.Linq;
|
||||
|
|
Loading…
Reference in New Issue