Files
tcpserver-flow/app/net/parsers/CurrentCollectorParser.php
T
2026-03-08 22:58:56 +08:00

36 lines
1.1 KiB
PHP

<?php
namespace app\net\parsers;
/**
* 电流采集器报文解析器(长度78)
*/
class CurrentCollectorParser implements PacketParserInterface
{
public function supports(string $hexString): bool
{
return strlen($hexString) === 78;
}
public function parse(string $hexString): array
{
$pattern = '/^BBBB([0-9A-F]{12})([0-9A-F]{10})([0-9A-F]{10})(24[0-9A-F]{8})(01[0-9A-F]{2})(02[0-9A-F]{2})(03[0-9A-F]{2})(04[0-9A-F]{2})(05[0-9A-F]{2})(06[0-9A-F]{2})([0-9A-F]{8})$/';
if (preg_match($pattern, $hexString, $matches)) {
return [
'hexType' => 3,
'isMatched' => true,
'card' => $matches[3],
'reader' => $matches[2],
'detectionDevice' => $matches[4],
'channel1' => $matches[5],
'channel2' => $matches[6],
'channel3' => $matches[7],
'channel4' => $matches[8],
'channel5' => $matches[9],
'channel6' => $matches[10],
];
}
return ['isMatched' => false];
}
}