Neues Ladestationsmodul mit ocpp Modul erstellt.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
class PhaseManager
|
||||
{
|
||||
public static function normalizePhaseCount(int $phases): int
|
||||
{
|
||||
if ($phases <= 1) {
|
||||
return 1;
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
|
||||
public static function wattsFromCurrent(float $currentA, int $phases, float $voltage = 230.0): int
|
||||
{
|
||||
$phaseCount = self::normalizePhaseCount($phases);
|
||||
return (int)round($currentA * $voltage * $phaseCount);
|
||||
}
|
||||
|
||||
public static function currentFromPower(float $powerW, int $phases, float $voltage = 230.0): float
|
||||
{
|
||||
$phaseCount = self::normalizePhaseCount($phases);
|
||||
if ($voltage <= 0 || $phaseCount <= 0) {
|
||||
return 0.0;
|
||||
}
|
||||
return round($powerW / ($voltage * $phaseCount), 2);
|
||||
}
|
||||
|
||||
public static function choosePhaseToUse(array $phaseCurrents): int
|
||||
{
|
||||
$bestPhase = 1;
|
||||
$bestCurrent = null;
|
||||
foreach ([1, 2, 3] as $phase) {
|
||||
$value = isset($phaseCurrents[$phase]) ? (float)$phaseCurrents[$phase] : null;
|
||||
if ($value === null) {
|
||||
continue;
|
||||
}
|
||||
if ($bestCurrent === null || $value < $bestCurrent) {
|
||||
$bestCurrent = $value;
|
||||
$bestPhase = $phase;
|
||||
}
|
||||
}
|
||||
return $bestPhase;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user