Commit 74d50b40 authored by akari's avatar akari

fix: 更改SN格式

parent 266ba06d
......@@ -11,28 +11,28 @@ class MonitoringMockData {
static List<MonitoringMetricBO> getMockMetrics() {
return const [
MonitoringMetricBO(
value: '24.5',
value: '--',
unit: '℃',
label: '舱内温度',
borderColorValue: 0xFF00FF9D,
backgroundColorValue: 0x1A00FF9D,
),
MonitoringMetricBO(
value: '63',
value: '--',
unit: 'RH',
label: '舱内湿度',
borderColorValue: 0xFF00B8FF,
backgroundColorValue: 0x1A00B8FF,
),
MonitoringMetricBO(
value: '21',
value: '--',
unit: '%',
label: '氧气浓度',
borderColorValue: 0xFF00FF9D,
backgroundColorValue: 0x1A00FF9D,
),
MonitoringMetricBO(
value: '0.5',
value: '--',
unit: '%',
label: '二氧化碳',
borderColorValue: 0xFFFF7D00,
......
......@@ -366,6 +366,7 @@ class McuReportParser {
String hex2() => remainingPayloadBytes() >= 2 ? payload!.readHex(2) : '';
String ascii(int bytes) =>
remainingPayloadBytes() >= bytes ? payload!.readAscii(bytes) : '';
String snAscii(int bytes) => _normalizeSn(ascii(bytes));
return McuReport(
head: head,
......@@ -432,7 +433,7 @@ class McuReportParser {
pulseRate: highByte(),
xyyStatus: highByte(),
xyyError1: highByte(),
sn: ascii(10),
sn: snAscii(10),
topTempCorrect: highByte(),
midTempCorrect: highByte(),
o2OpenCorrectStart: highByte(),
......@@ -447,6 +448,22 @@ class McuReportParser {
return parseHex(_bytesToHex(bytes));
}
static String _normalizeSn(String value) {
if (value.isEmpty) return value;
final buffer = StringBuffer();
for (var index = 0; index < value.length; index += 2) {
if (index + 1 < value.length) {
buffer
..write(value[index + 1])
..write(value[index]);
} else {
buffer.write(value[index]);
}
}
return buffer.toString();
}
static String _bytesToHex(List<int> bytes) {
return bytes
.map((item) => item.toRadixString(16).padLeft(2, '0'))
......
......@@ -134,8 +134,10 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
'co2Set=${latestReport.co2Setting} '
'sn=${latestReport.sn.isEmpty ? '<EMPTY>' : latestReport.sn}',
);
final bluetoothReadInfo =
BluetoothReadModel.fromMcuReport(latestReport);
final reportSn = _appendBluetoothSideToSn(latestReport.sn);
final bluetoothReadInfo = BluetoothReadModel.fromMcuReport(
latestReport,
).copyWith(sn: reportSn.isEmpty ? null : reportSn);
if (bluetoothReadInfo.hasSn) {
await _storageService.saveBluetoothReadSn(bluetoothReadInfo.sn!);
await _connectMqttForDeviceSn(bluetoothReadInfo.sn!);
......@@ -175,6 +177,19 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
});
}
String _appendBluetoothSideToSn(String sn) {
final cleanSn = sn.trim();
if (cleanSn.isEmpty) return '';
final deviceName = state.boundBluetoothDeviceName?.trim();
if (deviceName == null || deviceName.isEmpty) return cleanSn;
final side = deviceName[deviceName.length - 1].toUpperCase();
if (side != 'L' && side != 'R') return cleanSn;
return cleanSn.toUpperCase().endsWith(side) ? cleanSn : '$cleanSn$side';
}
Future<void> _loadBoundBluetoothDevice() async {
final boundDevice = await _storageService.getBoundBluetoothDevice();
if (isClosed) return;
......@@ -192,7 +207,16 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
boundBluetoothDeviceName: boundDevice['deviceName'],
));
if (bluetoothReadInfo.hasSn) {
_connectMqttForDeviceSn(bluetoothReadInfo.sn!);
final sn = _appendBluetoothSideToSn(bluetoothReadInfo.sn!);
if (sn.isNotEmpty) {
if (sn != bluetoothReadInfo.sn) {
await _storageService.saveBluetoothReadSn(sn);
eventBus.emit(
BluetoothReadInfoChangedEvent(bluetoothReadInfo.copyWith(sn: sn)),
);
}
_connectMqttForDeviceSn(sn);
}
}
if (deviceId != null && deviceId.isNotEmpty) {
_isAutoReconnectEnabled = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment