Commit 74d50b40 authored by akari's avatar akari

fix: 更改SN格式

parent 266ba06d
...@@ -11,28 +11,28 @@ class MonitoringMockData { ...@@ -11,28 +11,28 @@ class MonitoringMockData {
static List<MonitoringMetricBO> getMockMetrics() { static List<MonitoringMetricBO> getMockMetrics() {
return const [ return const [
MonitoringMetricBO( MonitoringMetricBO(
value: '24.5', value: '--',
unit: '℃', unit: '℃',
label: '舱内温度', label: '舱内温度',
borderColorValue: 0xFF00FF9D, borderColorValue: 0xFF00FF9D,
backgroundColorValue: 0x1A00FF9D, backgroundColorValue: 0x1A00FF9D,
), ),
MonitoringMetricBO( MonitoringMetricBO(
value: '63', value: '--',
unit: 'RH', unit: 'RH',
label: '舱内湿度', label: '舱内湿度',
borderColorValue: 0xFF00B8FF, borderColorValue: 0xFF00B8FF,
backgroundColorValue: 0x1A00B8FF, backgroundColorValue: 0x1A00B8FF,
), ),
MonitoringMetricBO( MonitoringMetricBO(
value: '21', value: '--',
unit: '%', unit: '%',
label: '氧气浓度', label: '氧气浓度',
borderColorValue: 0xFF00FF9D, borderColorValue: 0xFF00FF9D,
backgroundColorValue: 0x1A00FF9D, backgroundColorValue: 0x1A00FF9D,
), ),
MonitoringMetricBO( MonitoringMetricBO(
value: '0.5', value: '--',
unit: '%', unit: '%',
label: '二氧化碳', label: '二氧化碳',
borderColorValue: 0xFFFF7D00, borderColorValue: 0xFFFF7D00,
......
...@@ -366,6 +366,7 @@ class McuReportParser { ...@@ -366,6 +366,7 @@ class McuReportParser {
String hex2() => remainingPayloadBytes() >= 2 ? payload!.readHex(2) : ''; String hex2() => remainingPayloadBytes() >= 2 ? payload!.readHex(2) : '';
String ascii(int bytes) => String ascii(int bytes) =>
remainingPayloadBytes() >= bytes ? payload!.readAscii(bytes) : ''; remainingPayloadBytes() >= bytes ? payload!.readAscii(bytes) : '';
String snAscii(int bytes) => _normalizeSn(ascii(bytes));
return McuReport( return McuReport(
head: head, head: head,
...@@ -432,7 +433,7 @@ class McuReportParser { ...@@ -432,7 +433,7 @@ class McuReportParser {
pulseRate: highByte(), pulseRate: highByte(),
xyyStatus: highByte(), xyyStatus: highByte(),
xyyError1: highByte(), xyyError1: highByte(),
sn: ascii(10), sn: snAscii(10),
topTempCorrect: highByte(), topTempCorrect: highByte(),
midTempCorrect: highByte(), midTempCorrect: highByte(),
o2OpenCorrectStart: highByte(), o2OpenCorrectStart: highByte(),
...@@ -447,6 +448,22 @@ class McuReportParser { ...@@ -447,6 +448,22 @@ class McuReportParser {
return parseHex(_bytesToHex(bytes)); 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) { static String _bytesToHex(List<int> bytes) {
return bytes return bytes
.map((item) => item.toRadixString(16).padLeft(2, '0')) .map((item) => item.toRadixString(16).padLeft(2, '0'))
......
...@@ -134,8 +134,10 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -134,8 +134,10 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
'co2Set=${latestReport.co2Setting} ' 'co2Set=${latestReport.co2Setting} '
'sn=${latestReport.sn.isEmpty ? '<EMPTY>' : latestReport.sn}', 'sn=${latestReport.sn.isEmpty ? '<EMPTY>' : latestReport.sn}',
); );
final bluetoothReadInfo = final reportSn = _appendBluetoothSideToSn(latestReport.sn);
BluetoothReadModel.fromMcuReport(latestReport); final bluetoothReadInfo = BluetoothReadModel.fromMcuReport(
latestReport,
).copyWith(sn: reportSn.isEmpty ? null : reportSn);
if (bluetoothReadInfo.hasSn) { if (bluetoothReadInfo.hasSn) {
await _storageService.saveBluetoothReadSn(bluetoothReadInfo.sn!); await _storageService.saveBluetoothReadSn(bluetoothReadInfo.sn!);
await _connectMqttForDeviceSn(bluetoothReadInfo.sn!); await _connectMqttForDeviceSn(bluetoothReadInfo.sn!);
...@@ -175,6 +177,19 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -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 { Future<void> _loadBoundBluetoothDevice() async {
final boundDevice = await _storageService.getBoundBluetoothDevice(); final boundDevice = await _storageService.getBoundBluetoothDevice();
if (isClosed) return; if (isClosed) return;
...@@ -192,7 +207,16 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -192,7 +207,16 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
boundBluetoothDeviceName: boundDevice['deviceName'], boundBluetoothDeviceName: boundDevice['deviceName'],
)); ));
if (bluetoothReadInfo.hasSn) { 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) { if (deviceId != null && deviceId.isNotEmpty) {
_isAutoReconnectEnabled = true; _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