Files
Symcon_Belevo_Energiemanage…/Ladestation_OCPP/libs/OCPPTransport.php
T

33 lines
928 B
PHP

<?php
class OCPPTransport
{
public static function buildEnvelope(OCPPMessage $message, int $targetInstance = 0): array
{
return [
'TargetInstance' => $targetInstance,
'ChargePointId' => $message->chargePointId,
'Version' => $message->version,
'Frame' => $message->toJson(),
'Timestamp' => time()
];
}
public static function decodeEnvelope(string $json): array
{
$data = json_decode($json, true);
if (!is_array($data)) {
return [];
}
return [
'TargetInstance' => (int)($data['TargetInstance'] ?? 0),
'ChargePointId' => (string)($data['ChargePointId'] ?? ''),
'Version' => (string)($data['Version'] ?? 'auto'),
'Frame' => (string)($data['Frame'] ?? ''),
'Timestamp' => (int)($data['Timestamp'] ?? time())
];
}
}
?>