feat: 实现TCP Server
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?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];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user