1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76:
<?php
declare(strict_types=1);
namespace App\IqrfAppModule\Model;
use Nette;
class OsParser {
use Nette\SmartObject;
public function parse(string $packet) {
$data = explode('.', $packet);
$pcmd = $data[3];
switch ($pcmd) {
case '80':
return $this->parseReadInfo($packet);
}
}
public function parseReadInfo(string $packet) {
$data = [];
$trTypes = [0 => '52D', 1 => '58D-RJ', 2 => '72D', 3 => '53D', 8 => '54D', 9 => '55D', 10 => '56D', 11 => '76D'];
$mcuTypes = [3 => 'PIC16F886', 4 => 'PIC16F1938'];
$packetArray = explode('.', $packet);
$data['ModuleId'] = strtoupper($packetArray[11] . $packetArray[10] . $packetArray[9] . $packetArray[8]);
$data['OsVersion'] = (hexdec($packetArray[12]) >> 4) . '.0' . (hexdec($packetArray[12]) & 0x0f) . 'D';
$trType = hexdec($packetArray[13]) >> 4;
if (array_key_exists($trType, $trTypes)) {
$data['TrType'] = ((hexdec($packetArray[11]) & 0x80) ? 'DCTR-' : 'TR-') . $trTypes[$trType];
} else {
$data['TrType'] = 'UNKNOWN';
}
$mcuType = hexdec($packetArray[13]) & 7;
$data['McuType'] = array_key_exists($mcuType, $mcuTypes) ? $mcuTypes[$mcuType] : 'UNKNOWN';
$data['OsBuild'] = $packetArray[14] . $packetArray[15];
$data['Rssi'] = hexdec($packetArray[16]) - 130;
$data['SupplyVoltage'] = number_format((261.12 / (127 - hexdec($packetArray[17]))), 2, '.', '') . ' V';
$data['Flags'] = $packetArray[18];
$data['SlotLimits'] = $packetArray[19];
return $data;
}
}