فهرست منبع

优化设备连接的稳定性

loki.wu 1 سال پیش
والد
کامیت
dbdeed6b29

+ 86 - 0
lib/managers/device_controller_manager.dart

@@ -0,0 +1,86 @@
+import 'package:vitalapp/pages/medical/controllers/base.dart';
+import 'package:vnote_device_plugin/consts/status.dart';
+import 'package:vnote_device_plugin/consts/types.dart';
+import 'package:vnote_device_plugin/devices/base.dart';
+import 'package:fis_common/logger/logger.dart';
+import 'package:vnote_device_plugin/devices/heart.dart';
+import 'package:vnote_device_plugin/devices/ic_reader.dart';
+import 'package:vnote_device_plugin/devices/nibp.dart';
+import 'package:vnote_device_plugin/devices/sugar.dart';
+import 'package:vnote_device_plugin/devices/temp.dart';
+import 'package:vnote_device_plugin/devices/urine.dart';
+import 'package:vnote_device_plugin/devices/weight.dart';
+import 'package:vnote_device_plugin/events/event_type.dart';
+import 'package:vnote_device_plugin/models/exams/heart.dart';
+
+class DeviceControllerManager extends BaseDeviceController<DeviceWorkerBase> {
+  DeviceControllerManager(
+    this.type,
+    super.model,
+    super.mac,
+  ) : super();
+
+  final String type;
+
+  DeviceWorkerBase? deviceWorker;
+
+  @override
+  DeviceWorkerBase createWorker() {
+    if (deviceWorker != null) {
+      logger.i('DeviceControllerManager:$type disconnect start');
+      deviceWorker?.disconnect().then((value) {
+        logger.i('DeviceControllerManager:$type disconnect end');
+        deviceWorker?.dispose();
+        logger.i('DeviceControllerManager:$type dispose');
+      });
+    }
+    logger.i('DeviceControllerManager:$type create');
+    print('DeviceControllerManager:$type create');
+    return _createWorker();
+  }
+
+  @override
+  void dispose() {
+    super.dispose();
+    deviceWorker = null;
+    logger.i('DeviceControllerManager:$type dispose');
+    print('DeviceControllerManager:$type dispose');
+  }
+
+  DeviceWorkerBase _createWorker() {
+    switch (type) {
+      //体重
+      case DeviceTypes.WEIGHT:
+        deviceWorker = WeightDeviceWorker(mac: super.mac, model: model);
+        break;
+      //心率
+      case DeviceTypes.HEART:
+        deviceWorker = HeartDeviceWorker(mac: super.mac, model: model);
+        break;
+      //血压
+      case DeviceTypes.NIBP:
+        deviceWorker = NibpDeviceWorker(mac: super.mac, model: model);
+        break;
+      //血氧
+      case DeviceTypes.SPO2:
+        deviceWorker = NibpDeviceWorker(mac: super.mac, model: model);
+        break;
+      //血糖
+      case DeviceTypes.SUGAR:
+        deviceWorker = SugarDeviceWorker(mac: super.mac, model: model);
+        break;
+      //温度
+      case DeviceTypes.TEMP:
+        deviceWorker = TempDeviceWorker(mac: super.mac, model: model);
+        break;
+      //尿常规
+      case DeviceTypes.URINE:
+        deviceWorker = UrineDeviceWorker(mac: super.mac, model: model);
+        break;
+      case DeviceTypes.IC_READER:
+        deviceWorker = ICReaderDeviceWorker(mac: super.mac, model: model);
+        break;
+    }
+    return deviceWorker!;
+  }
+}

+ 5 - 4
lib/pages/check/widgets/exam_configurable/exam_urinalys.dart

@@ -1,6 +1,7 @@
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
 import 'package:vitalapp/components/dialog_input.dart';
+import 'package:vitalapp/managers/device_controller_manager.dart';
 import 'package:vitalapp/pages/check/widgets/device_controller.dart';
 import 'package:vitalapp/pages/mappers/urine.dart';
 import 'package:vitalapp/pages/medical/controllers/urinalysis.dart';
@@ -29,7 +30,7 @@ class ExamUrinalysis extends StatefulWidget {
 
 class _ExamUrinalysisState extends State<ExamUrinalysis> {
   final controller = Get.find<DeviceController>();
-  late UrinalysisController urinaly;
+  late DeviceControllerManager urinaly;
   late UrineDeviceWorker worker;
   UrineExamData? urineExamData;
   String? deviceType = MedicalController.typeConvertMap[DeviceTypes.URINE];
@@ -64,10 +65,10 @@ class _ExamUrinalysisState extends State<ExamUrinalysis> {
       connectStatus = WorkerStatus.unboundDevice;
       return;
     }
-    urinaly = UrinalysisController(device.model, device.mac);
-    worker = urinaly.worker;
+    urinaly =
+        DeviceControllerManager(DeviceTypes.URINE, device.model, device.mac);
+    worker = urinaly.worker as UrineDeviceWorker;
     connectStatus = urinaly.connectStatus;
-
     loadListeners();
   }
 

+ 1 - 0
lib/pages/medical/controllers/bmi.dart

@@ -1,6 +1,7 @@
 import 'package:vnote_device_plugin/devices/weight.dart';
 import 'package:vitalapp/pages/medical/controllers/base.dart';
 
+///BMI检测
 class BmiDeviceController extends BaseDeviceController<WeightDeviceWorker> {
   BmiDeviceController(super.model, super.mac);
 

+ 1 - 0
lib/pages/medical/controllers/heart.dart

@@ -1,6 +1,7 @@
 import 'package:vnote_device_plugin/devices/heart.dart';
 import 'package:vitalapp/pages/medical/controllers/base.dart';
 
+///心率检测
 class HeartDeviceController extends BaseDeviceController<HeartDeviceWorker> {
   HeartDeviceController(super.model, super.mac);
 

+ 1 - 0
lib/pages/medical/controllers/ic_read.dart

@@ -1,6 +1,7 @@
 import 'package:vnote_device_plugin/devices/ic_reader.dart';
 import 'package:vitalapp/pages/medical/controllers/base.dart';
 
+///读卡
 class IcReaderDeviceController
     extends BaseDeviceController<ICReaderDeviceWorker> {
   IcReaderDeviceController(super.model, super.mac);

+ 1 - 0
lib/pages/medical/controllers/nibp.dart

@@ -1,6 +1,7 @@
 import 'package:vnote_device_plugin/devices/nibp.dart';
 import 'package:vitalapp/pages/medical/controllers/base.dart';
 
+///血压
 class NibpDeviceController extends BaseDeviceController<NibpDeviceWorker> {
   NibpDeviceController(super.model, super.mac);
 

+ 1 - 0
lib/pages/medical/controllers/oxygen.dart

@@ -1,6 +1,7 @@
 import 'package:vnote_device_plugin/devices/sp_o2.dart';
 import 'package:vitalapp/pages/medical/controllers/base.dart';
 
+///血氧
 class SpO2DeviceController extends BaseDeviceController<SpO2DeviceWorker> {
   SpO2DeviceController(super.model, super.mac);
 

+ 1 - 0
lib/pages/medical/controllers/sugar.dart

@@ -1,6 +1,7 @@
 import 'package:vnote_device_plugin/devices/sugar.dart';
 import 'package:vitalapp/pages/medical/controllers/base.dart';
 
+///血糖
 class SugarDeviceController extends BaseDeviceController<SugarDeviceWorker> {
   SugarDeviceController(super.model, super.mac);
 

+ 1 - 0
lib/pages/medical/controllers/temp.dart

@@ -1,6 +1,7 @@
 import 'package:vnote_device_plugin/devices/temp.dart';
 import 'package:vitalapp/pages/medical/controllers/base.dart';
 
+///体温
 class TempDeviceController extends BaseDeviceController<TempDeviceWorker> {
   TempDeviceController(super.model, super.mac);
 

+ 1 - 0
lib/pages/medical/controllers/urinalysis.dart

@@ -1,6 +1,7 @@
 import 'package:vitalapp/pages/medical/controllers/base.dart';
 import 'package:vnote_device_plugin/devices/urine.dart';
 
+///尿常规
 class UrinalysisController extends BaseDeviceController<UrineDeviceWorker> {
   UrinalysisController(super.model, super.mac);
 

+ 83 - 62
lib/pages/medical/widgets/blood_pressure.dart

@@ -3,6 +3,7 @@ import 'dart:convert';
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
 import 'package:get/get.dart';
+import 'package:vitalapp/managers/device_controller_manager.dart';
 import 'package:vitalapp/pages/medical/widgets/device_status_position.dart';
 import 'package:vnote_device_plugin/consts/types.dart';
 import 'package:vnote_device_plugin/devices/nibp.dart';
@@ -189,7 +190,7 @@ class _ExamBloodPressureState extends State<BloodPressure> {
   PressureStatus pressureStatus = PressureStatus.left;
   PressureDeviceStatus pressureDeviceStatus = PressureDeviceStatus.start;
   bool isConnectFail = false;
-  late NibpDeviceController nibp;
+  late DeviceControllerManager nibp;
   NibpDeviceWorker? worker;
   int liveValue = 0;
   int errorCount = 0;
@@ -203,6 +204,11 @@ class _ExamBloodPressureState extends State<BloodPressure> {
     super.initState();
   }
 
+  @override
+  void didUpdateWidget(BloodPressure oldWidget) {
+    super.didUpdateWidget(oldWidget);
+  }
+
   Future<void> currentDevice() async {
     DeviceModel? device = await controller.getDevice(DeviceTypes.NIBP);
     if (device == null) {
@@ -211,8 +217,8 @@ class _ExamBloodPressureState extends State<BloodPressure> {
       setState(() {});
       return;
     }
-    nibp = NibpDeviceController(device.model, device.mac);
-    worker = nibp.worker;
+    nibp = DeviceControllerManager(DeviceTypes.NIBP, device.model, device.mac);
+    worker = nibp.worker as NibpDeviceWorker;
     _connectStatus = nibp.connectStatus;
 
     loadListeners();
@@ -245,6 +251,7 @@ class _ExamBloodPressureState extends State<BloodPressure> {
 
   @override
   void dispose() {
+    nibp.dispose();
     disconnect();
     worker?.dispose();
     super.dispose();
@@ -276,11 +283,16 @@ class _ExamBloodPressureState extends State<BloodPressure> {
 
   void _onConnectFail(sender, e) {
     logger.i("连接设备失败:${worker!.mac}");
+    print('连接设备失败:${worker!.mac},errorCount:$errorCount,${DateTime.now()}');
     if (errorCount < 3) {
+      print('连接设备失败:${worker!.mac},$errorCount,${DateTime.now()}');
+      logger.i('连接设备失败:${worker!.mac},$errorCount,${DateTime.now()}');
       errorCount++;
       disconnect();
       loadListeners();
     } else {
+      print('连接设备失败:${worker!.mac},$errorCount,${DateTime.now()}');
+      logger.i('连接设备失败:${worker!.mac},$errorCount,${DateTime.now()}');
       isConnectFail = true;
     }
     _connectStatus = WorkerStatus.connectionFailed;
@@ -289,7 +301,9 @@ class _ExamBloodPressureState extends State<BloodPressure> {
 
   void _onDisconnected(sender, e) {
     logger.i("设备连接中断:${worker!.mac}");
+    print('设备连接中断:${worker!.mac}');
     if (errorCount < 3) {
+      print('设备连接中断:${worker!.mac},$errorCount');
       errorCount++;
       disconnect();
       loadListeners();
@@ -302,10 +316,13 @@ class _ExamBloodPressureState extends State<BloodPressure> {
 
   void _onConnectSuccess(sender, e) {
     logger.i("设备连接成功:$e");
-    _connectStatus = WorkerStatus.connected;
-    errorCount = 0;
-    isConnectFail = false;
-    setState(() {});
+    print("设备连接成功:$e");
+
+    setState(() {
+      _connectStatus = WorkerStatus.connected;
+      errorCount = 0;
+      isConnectFail = false;
+    });
   }
 
   Widget _buildValue() {
@@ -330,64 +347,68 @@ class _ExamBloodPressureState extends State<BloodPressure> {
     return Stack(
       children: [
         ExamCard(
-            title: '',
-            content: Column(
-              children: [
-                Row(
-                  children: [
-                    const SizedBox(
-                      width: 25,
-                    ),
-                    const Text(
-                      '血压',
-                      style: TextStyle(fontSize: 25),
-                    ),
-                    const Expanded(child: SizedBox()),
-                    InkWell(
-                      child: _SideBar(
-                        value: _buildValue(),
-                        unit: 'mmHg',
-                      ),
-                    ),
-                  ],
-                ),
-                Row(
-                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
-                  children: [
-                    const SizedBox(
-                      width: 25,
-                    ),
-                    const Text(
-                      '脉率',
-                      style: TextStyle(fontSize: 25),
-                    ),
-                    const Expanded(child: SizedBox()),
-                    Text(
-                      controller.diagnosisDataValue['NIBP']?['Pulse_Beat']
-                              .toString() ??
-                          '',
-                      style: const TextStyle(
-                        fontSize: 45,
-                        color: Colors.black,
-                      ),
-                    ),
-                    const Text(
-                      '       bpm',
-                      style: TextStyle(fontSize: 25),
+          title: '',
+          content: Column(
+            children: [
+              Row(
+                children: [
+                  const SizedBox(
+                    width: 25,
+                  ),
+                  const Text(
+                    '血压',
+                    style: TextStyle(fontSize: 25),
+                  ),
+                  const Expanded(child: SizedBox()),
+                  InkWell(
+                    child: _SideBar(
+                      value: _buildValue(),
+                      unit: 'mmHg',
                     ),
-                    const SizedBox(
-                      width: 30,
+                  ),
+                ],
+              ),
+              Row(
+                mainAxisAlignment: MainAxisAlignment.spaceBetween,
+                children: [
+                  const SizedBox(
+                    width: 25,
+                  ),
+                  const Text(
+                    '脉率',
+                    style: TextStyle(fontSize: 25),
+                  ),
+                  const Expanded(child: SizedBox()),
+                  Text(
+                    controller.diagnosisDataValue['NIBP']?['Pulse_Beat']
+                            .toString() ??
+                        '',
+                    style: const TextStyle(
+                      fontSize: 45,
+                      color: Colors.black,
                     ),
-                  ],
-                ),
-              ],
-            )),
-        if (!isConnectFail)
-          DeviceStatusPosition(
-            deviceStatus: DeviceStatus(connectStatus: _connectStatus),
-          )
-        else
+                  ),
+                  const Text(
+                    '       bpm',
+                    style: TextStyle(fontSize: 25),
+                  ),
+                  const SizedBox(
+                    width: 30,
+                  ),
+                ],
+              ),
+            ],
+          ),
+        ),
+        if (isConnectFail) ...[
           _buildErrorButton(),
+        ] else ...[
+          Positioned(
+            right: 10,
+            top: 10,
+            child: DeviceStatus(connectStatus: _connectStatus),
+          ),
+        ],
       ],
     );
   }

+ 5 - 3
lib/pages/medical/widgets/blood_sugar.dart

@@ -1,5 +1,6 @@
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
+import 'package:vitalapp/managers/device_controller_manager.dart';
 import 'package:vitalapp/pages/medical/widgets/device_status_position.dart';
 import 'package:vnote_device_plugin/consts/types.dart';
 import 'package:vnote_device_plugin/devices/sugar.dart';
@@ -27,7 +28,7 @@ class BloodSugar extends StatefulWidget {
 
 class _ExamBloodSugarState extends State<BloodSugar> {
   var controller = Get.find<MedicalController>();
-  late SugarDeviceController sugar;
+  late DeviceControllerManager sugar;
   SugarDeviceWorker? worker;
   bool isConnectFail = false;
   WorkerStatus _connectStatus = WorkerStatus.connecting;
@@ -61,8 +62,9 @@ class _ExamBloodSugarState extends State<BloodSugar> {
       setState(() {});
       return;
     }
-    sugar = SugarDeviceController(device.model, device.mac);
-    worker = sugar.worker;
+    sugar =
+        DeviceControllerManager(DeviceTypes.SUGAR, device.model, device.mac);
+    worker = sugar.worker as SugarDeviceWorker?;
     _connectStatus = sugar.connectStatus;
 
     loadListeners();

+ 5 - 3
lib/pages/medical/widgets/body_bmi.dart

@@ -1,5 +1,6 @@
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
+import 'package:vitalapp/managers/device_controller_manager.dart';
 import 'package:vitalapp/pages/medical/widgets/device_status_position.dart';
 import 'package:vnote_device_plugin/consts/types.dart';
 import 'package:vnote_device_plugin/devices/weight.dart';
@@ -25,7 +26,7 @@ class BodyWeight extends StatefulWidget {
 
 class _ExamBodyWeightState extends State<BodyWeight> {
   var controller = Get.find<MedicalController>();
-  late BmiDeviceController bmi;
+  late DeviceControllerManager bmi;
   WeightDeviceWorker? worker;
   bool isConnectFail = false;
   int errorCount = 0;
@@ -63,6 +64,7 @@ class _ExamBodyWeightState extends State<BodyWeight> {
 
   @override
   void dispose() {
+    bmi.dispose();
     disconnect();
     worker?.dispose();
     super.dispose();
@@ -84,8 +86,8 @@ class _ExamBodyWeightState extends State<BodyWeight> {
       setState(() {});
       return;
     }
-    bmi = BmiDeviceController(device.model, device.mac);
-    worker = bmi.worker;
+    bmi = DeviceControllerManager(DeviceTypes.WEIGHT, device.model, device.mac);
+    worker = bmi.worker as WeightDeviceWorker;
     _connectStatus = bmi.connectStatus;
 
     loadListeners();

+ 6 - 3
lib/pages/medical/widgets/body_temperature.dart

@@ -1,5 +1,6 @@
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
+import 'package:vitalapp/managers/device_controller_manager.dart';
 import 'package:vitalapp/pages/medical/widgets/device_status_position.dart';
 import 'package:vnote_device_plugin/consts/types.dart';
 import 'package:vnote_device_plugin/devices/temp.dart';
@@ -23,7 +24,7 @@ class BodyTemperature extends StatefulWidget {
 
 class _ExamBodyTemperatureState extends State<BodyTemperature> {
   var controller = Get.find<MedicalController>();
-  late TempDeviceController temp;
+  late DeviceControllerManager temp;
 
   TempDeviceWorker? worker;
 
@@ -55,8 +56,8 @@ class _ExamBodyTemperatureState extends State<BodyTemperature> {
       worker = null;
       return;
     }
-    temp = TempDeviceController(device.model, device.mac);
-    worker = temp.worker;
+    temp = DeviceControllerManager(DeviceTypes.TEMP, device.model, device.mac);
+    worker = temp.worker as TempDeviceWorker;
     connectStatus = temp.connectStatus;
 
     loadListeners();
@@ -147,10 +148,12 @@ class _ExamBodyTemperatureState extends State<BodyTemperature> {
     print('设备连接中断');
     logger.i("设备连接中断:${worker!.mac}");
     if (errorCount < 3) {
+      logger.i("设备连接中断:${worker!.mac},$errorCount");
       errorCount++;
       disconnect();
       loadListeners();
     } else {
+      logger.i("设备连接中断:${worker!.mac},$errorCount");
       isConnectFail = true;
     }
     connectStatus = WorkerStatus.disconnected;

+ 4 - 3
lib/pages/medical/widgets/bool_oxygen.dart

@@ -1,6 +1,7 @@
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
 import 'package:vitalapp/components/dialog_number.dart';
+import 'package:vitalapp/managers/device_controller_manager.dart';
 import 'package:vitalapp/pages/medical/widgets/device_status_position.dart';
 import 'package:vnote_device_plugin/consts/types.dart';
 import 'package:vnote_device_plugin/devices/sp_o2.dart';
@@ -22,7 +23,7 @@ class BloodOxygen extends StatefulWidget {
 
 class _ExamBloodOxygenState extends State<BloodOxygen> {
   final controller = Get.find<MedicalController>();
-  late SpO2DeviceController spo2;
+  late DeviceControllerManager spo2;
   SpO2DeviceWorker? worker;
   String pulse = '';
   String spO2 = '';
@@ -58,8 +59,8 @@ class _ExamBloodOxygenState extends State<BloodOxygen> {
       worker = null;
       return;
     }
-    spo2 = SpO2DeviceController(device.model, device.mac);
-    worker = spo2.worker;
+    spo2 = DeviceControllerManager(DeviceTypes.SPO2, device.model, device.mac);
+    worker = spo2.worker as SpO2DeviceWorker;
     _connectStatus = spo2.connectStatus;
     loadListeners();
   }

+ 27 - 2
lib/pages/medical/widgets/device_status.dart

@@ -6,20 +6,45 @@ import 'package:vitalapp/pages/check/widgets/exam_device_connect_status/connect_
 import 'package:vitalapp/pages/check/widgets/exam_device_connect_status/connect_unbound_device.dart';
 import 'package:vitalapp/pages/medical/models/worker.dart';
 
-class DeviceStatus extends StatelessWidget {
+class DeviceStatus extends StatefulWidget {
   const DeviceStatus({
     super.key,
     required this.connectStatus,
   });
   final WorkerStatus connectStatus;
 
+  @override
+  State<StatefulWidget> createState() {
+    return _DeviceStatusState();
+  }
+}
+
+class _DeviceStatusState extends State<DeviceStatus> {
+  WorkerStatus? _connectStatus;
+
   @override
   Widget build(BuildContext context) {
     return _buildContent();
   }
 
+  @override
+  void initState() {
+    _connectStatus = widget.connectStatus;
+    super.initState();
+  }
+
+  @override
+  void didUpdateWidget(covariant DeviceStatus oldWidget) {
+    if (_connectStatus != widget.connectStatus) {
+      setState(() {
+        _connectStatus = widget.connectStatus;
+      });
+    }
+    super.didUpdateWidget(oldWidget);
+  }
+
   Widget _buildContent() {
-    switch (connectStatus) {
+    switch (_connectStatus) {
       case WorkerStatus.connectionFailed:
         return const DeviceConnectFail();
       case WorkerStatus.connected:

+ 5 - 3
lib/pages/medical/widgets/heart_rate.dart

@@ -3,6 +3,7 @@ import 'dart:convert';
 
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
+import 'package:vitalapp/managers/device_controller_manager.dart';
 import 'package:vitalapp/managers/interfaces/data_convert.dart';
 import 'package:vitalapp/managers/interfaces/models/device.dart';
 import 'package:vitalapp/pages/medical/controllers/heart.dart';
@@ -32,7 +33,7 @@ class HeartRate extends StatefulWidget {
 
 class _HeartRateState extends State<HeartRate> {
   var controller = Get.find<MedicalController>();
-  late HeartDeviceController heart;
+  late DeviceControllerManager heart;
   late HeartDeviceWorker worker;
   final dataConvertManager = Get.find<IDataConvertManager>();
   WorkerStatus _connectStatus = WorkerStatus.connecting;
@@ -103,8 +104,9 @@ class _HeartRateState extends State<HeartRate> {
       setState(() {});
       return;
     }
-    heart = HeartDeviceController(device.model, device.mac);
-    worker = heart.worker;
+    heart =
+        DeviceControllerManager(DeviceTypes.HEART, device.model, device.mac);
+    worker = heart.worker as HeartDeviceWorker;
     _connectStatus = heart.connectStatus;
 
     loadListeners();

+ 5 - 3
lib/pages/medical/widgets/urinalysis.dart

@@ -1,6 +1,7 @@
 import 'package:flutter/material.dart';
 import 'package:get/get.dart';
 import 'package:vitalapp/components/dialog_input.dart';
+import 'package:vitalapp/managers/device_controller_manager.dart';
 import 'package:vitalapp/pages/mappers/urine.dart';
 import 'package:vitalapp/pages/medical/controllers/urinalysis.dart';
 import 'package:vitalapp/pages/medical/widgets/device_status_position.dart';
@@ -26,7 +27,7 @@ class Urinalysis extends StatefulWidget {
 
 class _ExamUrinalysisState extends State<Urinalysis> {
   var controller = Get.find<MedicalController>();
-  late UrinalysisController urinaly;
+  late DeviceControllerManager urinaly;
   late UrineDeviceWorker worker;
   UrineExamData? urineExamData;
   bool isConnectFail = false;
@@ -67,8 +68,9 @@ class _ExamUrinalysisState extends State<Urinalysis> {
       connectStatus = WorkerStatus.unboundDevice;
       return;
     }
-    urinaly = UrinalysisController(device.model, device.mac);
-    worker = urinaly.worker;
+    urinaly =
+        DeviceControllerManager(DeviceTypes.URINE, device.model, device.mac);
+    worker = urinaly.worker as UrineDeviceWorker;
     connectStatus = urinaly.connectStatus;
 
     loadListeners();

+ 4 - 3
lib/pages/patient/bluetooth_card_reader/controller.dart

@@ -1,5 +1,6 @@
 import 'package:fis_jsonrpc/rpc.dart';
 import 'package:get/get.dart';
+import 'package:vitalapp/managers/device_controller_manager.dart';
 import 'package:vitalapp/managers/interfaces/device.dart';
 import 'package:vitalapp/managers/interfaces/models/device.dart';
 import 'package:vitalapp/pages/medical/controllers/ic_read.dart';
@@ -13,7 +14,7 @@ import 'package:fis_common/logger/logger.dart';
 class BluetoothCardReaderController extends GetxController {
   BluetoothCardReaderController();
   ICReaderDeviceWorker? worker;
-  IcReaderDeviceController? icReader;
+  DeviceControllerManager? icReader;
   WorkerStatus connectStatus = WorkerStatus.connecting;
 
   /// 是否连接中
@@ -61,10 +62,10 @@ class BluetoothCardReaderController extends GetxController {
       releaseListeners();
       await Future.delayed(const Duration(milliseconds: 500)); // 等待上一个reader释放
     }
-    icReader = IcReaderDeviceController(device.model, device.mac);
+    icReader = DeviceControllerManager(device.model, device.mac);
     logger.i(
         'BluetoothCardReaderController icReader: ${device.model}, ${device.mac} .');
-    worker = icReader?.worker;
+    worker = icReader?.worker as ICReaderDeviceWorker;
     logger.i('BluetoothCardReaderController get worker');
     connectStatus = icReader!.connectStatus;
     logger.i('BluetoothCardReaderController connectStatus:$connectStatus');