Browse Source

feat(exam): monitor system ready state and display status at exposure indicator position after entering exam

sw 1 month ago
parent
commit
e5a6baf51d
3 changed files with 38 additions and 2 deletions
  1. 13 1
      src/domain/mqttService.ts
  2. 11 1
      src/pages/exam/DeviceArea.tsx
  3. 14 0
      src/states/exam/deviceAreaSlice.ts

+ 13 - 1
src/domain/mqttService.ts

@@ -12,6 +12,7 @@ export interface MqttMessage {
 
 //const MQTT_BROKER_URL = 'ws://your-mqtt-broker-url'; // Replace with your actual MQTT broker URL
 const MQTT_TOPIC = 'MODULE/TASK/IMGPROC/PROGRESS';
+const MQTT_GLOBAL_TOPIC = 'MODULE/TASK/STATUS/GLOBAL';
 console.log('[mqttService] MQTT_BROKER_URL', MQTT_BROKER_URL);
 const options = {
   clean: true, // true: 清除会话, false: 保留会话
@@ -55,6 +56,11 @@ const startListening = () => {
         console.error('Failed to subscribe to topic', err);
       }
     });
+    mqttClient.subscribe(MQTT_GLOBAL_TOPIC, (err) => {
+      if (err) {
+        console.error('Failed to subscribe to global topic', err);
+      }
+    });
   });
 
   mqttClient.on('error', (error) => {
@@ -65,6 +71,13 @@ const startListening = () => {
     if (topic === MQTT_TOPIC) {
       const parsedMessage: MqttMessage = JSON.parse(message.toString());
       handleMqttMessage(parsedMessage);
+    } else if (topic === MQTT_GLOBAL_TOPIC) {
+      const parsedMessage = JSON.parse(message.toString());
+      if (parsedMessage.AllReady) {
+        emitter.emit('AllReady_TRUE');
+      } else {
+        emitter.emit('AllReady_FALSE');
+      }
     }
   });
 };
@@ -73,5 +86,4 @@ const stopListening = () => {
   mqttClient.end();
   console.log('Stopped listening to MQTT broker');
 };
-
 export { mqttClient, handleMqttMessage, startListening, stopListening };

+ 11 - 1
src/pages/exam/DeviceArea.tsx

@@ -38,7 +38,17 @@ const DeviceArea = ({ className }: { className?: string }) => {
         title={`手闸状态指示器: ${generatorStatus}`}
       />
       <Button
-        icon={<CameraOutlined />}
+        icon={
+          <CameraOutlined
+            className={
+              exposureStatus === 'ready'
+                ? 'text-green-500'
+                : exposureStatus === 'not_ready'
+                  ? ''
+                  : ''
+            }
+          />
+        }
         title={`曝光指示器: ${exposureStatus}`}
       />
       <Button

+ 14 - 0
src/states/exam/deviceAreaSlice.ts

@@ -95,6 +95,20 @@ emitter.on('DETECTOR_ACQUISITION_ERROR', () => {
   );
 });
 
+emitter.on('AllReady_TRUE', () => {
+  deviceAreaSlice.caseReducers.setExposureStatus(
+    deviceAreaSlice.getInitialState(),
+    { type: 'setExposureStatus', payload: 'ready' }
+  );
+});
+
+emitter.on('AllReady_FALSE', () => {
+  deviceAreaSlice.caseReducers.setExposureStatus(
+    deviceAreaSlice.getInitialState(),
+    { type: 'setExposureStatus', payload: 'not_ready' }
+  );
+});
+
 export const { setGeneratorStatus, setExposureStatus, setTabletStatus } =
   deviceAreaSlice.actions;
 export { GeneratorStatus };