소스 검색

feat(mqttServiceForDevice): subscribe to two topics for compatibility with software and hardware exposure

sw 1 개월 전
부모
커밋
875e16a8af
1개의 변경된 파일14개의 추가작업 그리고 2개의 파일을 삭제
  1. 14 2
      src/domain/mqttServiceForDevice.ts

+ 14 - 2
src/domain/mqttServiceForDevice.ts

@@ -32,7 +32,7 @@ interface MqttMessage {
   PUBLISH: string;
 }
 
-// const MQTT_TOPIC = 'CCOS/DEVICE/Generator/Notify/GENERATORSYNCSTATE';
+const MQTT_TOPIC_2 = 'CCOS/DEVICE/Generator/Notify/GENERATORSYNCSTATE'; //发生器
 const MQTT_TOPIC = 'CCOS/DEVICE/Detector/Notify/XrayON';
 
 const options = {
@@ -46,7 +46,7 @@ let mqttClient;
 
 const handleMqttMessage = (message: MqttMessage) => {
   console.log(`[mqttServiceForDevice] 收到message.CONTEXT ${message.CONTEXT}`);
-  if (message.CONTEXT === '1') {
+  if (message.CONTEXT === '1' || message.CONTEXT === '3') {
     emitter.emit('ACQUISITION_STARTED');
   }
 };
@@ -63,6 +63,14 @@ const startListening = () => {
         );
       }
     });
+    mqttClient.subscribe(MQTT_TOPIC_2, (err) => {
+      if (err) {
+        console.error(
+          '[mqttServiceForDevice] Failed to subscribe to topic',
+          err
+        );
+      }
+    });
   });
 
   mqttClient.on('error', (error) => {
@@ -74,6 +82,10 @@ const startListening = () => {
       const parsedMessage: MqttMessage = JSON.parse(message.toString());
       handleMqttMessage(parsedMessage);
     }
+    if (topic === MQTT_TOPIC_2) {
+      const parsedMessage: MqttMessage = JSON.parse(message.toString());
+      handleMqttMessage(parsedMessage);
+    }
   });
 };