feat: 实现TCP Server
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace app\net\parsers;
|
||||
|
||||
|
||||
/**
|
||||
* 无线读卡器报文解析器(长度56)
|
||||
*/
|
||||
class WirelessReaderParser implements PacketParserInterface
|
||||
{
|
||||
public function supports(string $hexString): bool
|
||||
{
|
||||
return strlen($hexString) === 56;
|
||||
}
|
||||
|
||||
public function parse(string $hexString): array
|
||||
{
|
||||
$pattern = '/^5A(.{12})(.{26})(.{12})(.{2})A5$/';
|
||||
if (preg_match($pattern, $hexString, $matches)) {
|
||||
return [
|
||||
'hexType' => 2,
|
||||
'isMatched' => true,
|
||||
'gateway' => $matches[1],
|
||||
'card' => $matches[2],
|
||||
'reader' => $matches[3],
|
||||
'batteryLevel' => (hexdec($matches[4]) + 200) / 100,
|
||||
];
|
||||
}
|
||||
return ['isMatched' => false];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user