|
@@ -1,25 +1,16 @@
|
|
|
import TimeUtil from '../common/util/TimeUtil'
|
|
|
-import BusinessConstant, { DeviceType } from '../common//constants/BusinessConstant'
|
|
|
-import {
|
|
|
- MqttAsync,
|
|
|
- MqttConnectOptions,
|
|
|
- MqttSubscribeOptions,
|
|
|
- MqttPublishOptions,
|
|
|
- MqttResponse,
|
|
|
- MqttMessage,
|
|
|
- MqttClient,
|
|
|
-} from '@ohos/mqtt';
|
|
|
+import CommonConstants from '../common//constants/CommonConstants'
|
|
|
import Lighting from '../viewmodel/device/Lighting';
|
|
|
import router from '@ohos.router';
|
|
|
import AntiWristStrap from '../viewmodel/device/AntiWristStrap';
|
|
|
import ThreeColourLight from '../viewmodel/device/ThreeColourLight';
|
|
|
import ElectricSolderingIron from '../viewmodel/device/ElectricSolderingIron';
|
|
|
import WeldFumeExtractor from '../viewmodel/device/WeldFumeExtractor';
|
|
|
-import MqttUploadData from '../viewmodel/mqtt/MqttUploadData';
|
|
|
import MqttDataItem from '../viewmodel/mqtt/MqttDataItem';
|
|
|
import MqttCmdData from '../viewmodel/mqtt/MqttCmdData';
|
|
|
import CardReader from '../viewmodel/device/CardReader';
|
|
|
import ElectricScrewdriver from '../viewmodel/device/ElectricScrewdriver';
|
|
|
+import MqttManager from '../common/util/mqtt';
|
|
|
|
|
|
@Component
|
|
|
export struct DeviceView {
|
|
@@ -29,47 +20,24 @@ export struct DeviceView {
|
|
|
@State arr: string[] = [];
|
|
|
scroller: Scroller = new Scroller();
|
|
|
|
|
|
- private mqttAsyncClient: MqttClient | null = null;
|
|
|
- // Set Client Configuration
|
|
|
- @State subscribeTopic: string = BusinessConstant.mqttSubscribeTopic;
|
|
|
- @State publishTopic: string = BusinessConstant.mqttPublishTopic;
|
|
|
- @State payload: string = '';
|
|
|
- @State url: string = BusinessConstant.mqttUrl;
|
|
|
- @State clientId: string = BusinessConstant.mqttClientId;
|
|
|
- @State userName: string = BusinessConstant.mqttUserName;
|
|
|
- @State password: string = BusinessConstant.mqttPassword;
|
|
|
- @State connectedCount: number = 0;
|
|
|
- // @State isConnect: boolean = false;
|
|
|
- @State isPromise: boolean = false;
|
|
|
-
|
|
|
+ //照明
|
|
|
+ @StorageProp('Lighting') lighting: Lighting = {}
|
|
|
//三色灯
|
|
|
- @State threeColourLight: ThreeColourLight = { LedRed: 0, LedOrange: 0, LedGreen: 0, Buzzer: 0 }
|
|
|
+ @StorageProp('ThreeColourLight') threeColourLight: ThreeColourLight = {}
|
|
|
//焊烟排烟机/空气净化器
|
|
|
- @State weldFumeExtractor: WeldFumeExtractor = { ExhaustFan: 0}
|
|
|
+ @StorageProp('WeldFumeExtractor') weldFumeExtractor: WeldFumeExtractor = { ExhaustFan: 0}
|
|
|
// 电烙铁
|
|
|
- @State solderingIron: ElectricSolderingIron = { SolderingCurrTemp: 0}
|
|
|
+ @StorageProp('ElectricSolderingIron') solderingIron: ElectricSolderingIron = { SolderingCurrTemp: 0}
|
|
|
// 电动螺丝刀
|
|
|
- @State screwdriver: ElectricScrewdriver = { OnlineStatus: 0}
|
|
|
+ @StorageProp('ElectricScrewdriver') screwdriver: ElectricScrewdriver = { TorqueHoldTime:0 }
|
|
|
// 防静电手环
|
|
|
- @State wristStrap: AntiWristStrap = { RingWearNormal: 0, RingWearStandby: 0, RingWearFault: 0,OnlineStatus: 0 }
|
|
|
+ @StorageProp('AntiWristStrap') wristStrap: AntiWristStrap = { RingWearNormal: 0, RingWearStandby: 0, RingWearFault: 0, OnlineStatus: 0}
|
|
|
// 读卡器
|
|
|
- @State cardReader: CardReader = { RfidCardNum1: '', RfidCardNum2: '', OnlineStatus: 0}
|
|
|
- // 照明
|
|
|
- @State lighting: Lighting = { lighting: 0, OnlineStatus: 0 }
|
|
|
+ @StorageProp('CardReader') cardReader: CardReader = {}
|
|
|
|
|
|
|
|
|
private swiperController: SwiperController = new SwiperController()
|
|
|
|
|
|
- async aboutToAppear() {
|
|
|
- await this.createClient();
|
|
|
- await this.connect();
|
|
|
- await this.subscribe();
|
|
|
- }
|
|
|
-
|
|
|
- // async aboutToDisappear() {
|
|
|
- // await this.disconnect();
|
|
|
- // await this.destroy()
|
|
|
- // }
|
|
|
|
|
|
build() {
|
|
|
Column() {
|
|
@@ -249,7 +217,7 @@ export struct DeviceView {
|
|
|
.width('100%')
|
|
|
.justifyContent(FlexAlign.Center)
|
|
|
Row() {
|
|
|
- Text(BusinessConstant.stationName)
|
|
|
+ Text(CommonConstants.stationName)
|
|
|
.fontSize($r('app.float.fontSize_6_4'))
|
|
|
.fontColor(this.weldFumeExtractor?.ExhaustFan! === 1 ? $r("app.color.99000000") : $r("app.color.60FFFFFF"))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
@@ -288,14 +256,14 @@ export struct DeviceView {
|
|
|
let mqttData: MqttCmdData = {
|
|
|
w: [item]
|
|
|
}
|
|
|
- this.payload = JSON.stringify(mqttData)
|
|
|
- this.publish()
|
|
|
- if (this.weldFumeExtractor?.OnlineStatus! === 1) {
|
|
|
- this.weldFumeExtractor = {
|
|
|
- ExhaustFan: item.value,
|
|
|
- OnlineStatus: 1
|
|
|
- }
|
|
|
- }
|
|
|
+ // 发送控制命令
|
|
|
+ MqttManager.publish(CommonConstants.mqttSubscribePublish, JSON.stringify(mqttData))
|
|
|
+ // if (this.weldFumeExtractor?.OnlineStatus! === 1) {
|
|
|
+ // this.weldFumeExtractor = {
|
|
|
+ // ExhaustFan: item.value,
|
|
|
+ // OnlineStatus: 1
|
|
|
+ // }
|
|
|
+ // }
|
|
|
})
|
|
|
|
|
|
// 照明
|
|
@@ -314,7 +282,7 @@ export struct DeviceView {
|
|
|
.width('100%')
|
|
|
.justifyContent(FlexAlign.Center)
|
|
|
Row() {
|
|
|
- Text(BusinessConstant.stationName)
|
|
|
+ Text(CommonConstants.stationName)
|
|
|
.fontSize($r('app.float.fontSize_6_4'))
|
|
|
.fontColor(this.lighting?.lighting! === 1 ? $r("app.color.99000000") : $r("app.color.60FFFFFF"))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
@@ -353,14 +321,14 @@ export struct DeviceView {
|
|
|
let mqttData: MqttCmdData = {
|
|
|
w: [item]
|
|
|
}
|
|
|
- this.payload = JSON.stringify(mqttData)
|
|
|
- this.publish()
|
|
|
- if (this.lighting?.OnlineStatus! === 1) {
|
|
|
- this.lighting = {
|
|
|
- lighting: item.value,
|
|
|
- OnlineStatus: 1
|
|
|
- }
|
|
|
- }
|
|
|
+ // 发送控制命令
|
|
|
+ MqttManager.publish(CommonConstants.mqttSubscribePublish, JSON.stringify(mqttData))
|
|
|
+ // if (this.lighting?.OnlineStatus! === 1) {
|
|
|
+ // this.lighting = {
|
|
|
+ // lighting: item.value,
|
|
|
+ // OnlineStatus: 1
|
|
|
+ // }
|
|
|
+ // }
|
|
|
})
|
|
|
|
|
|
// 读卡器
|
|
@@ -384,7 +352,7 @@ export struct DeviceView {
|
|
|
.width('100%')
|
|
|
.justifyContent(FlexAlign.Center)
|
|
|
Row() {
|
|
|
- Text(BusinessConstant.stationName)
|
|
|
+ Text(CommonConstants.stationName)
|
|
|
.fontSize($r('app.float.fontSize_6_4'))
|
|
|
.fontColor($r("app.color.60FFFFFF"))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
@@ -448,7 +416,7 @@ export struct DeviceView {
|
|
|
.width('100%')
|
|
|
.justifyContent(FlexAlign.Center)
|
|
|
Row() {
|
|
|
- Text(BusinessConstant.stationName)
|
|
|
+ Text(CommonConstants.stationName)
|
|
|
.fontSize($r('app.float.fontSize_6_4'))
|
|
|
.fontColor($r("app.color.60FFFFFF"))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
@@ -508,7 +476,7 @@ export struct DeviceView {
|
|
|
.width('100%')
|
|
|
.justifyContent(FlexAlign.Center)
|
|
|
Row() {
|
|
|
- Text(BusinessConstant.stationName)
|
|
|
+ Text(CommonConstants.stationName)
|
|
|
.fontSize($r('app.float.fontSize_6_4'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
@@ -566,7 +534,7 @@ export struct DeviceView {
|
|
|
.width('100%')
|
|
|
.justifyContent(FlexAlign.Center)
|
|
|
Row() {
|
|
|
- Text(BusinessConstant.stationName)
|
|
|
+ Text(CommonConstants.stationName)
|
|
|
.fontSize($r('app.float.fontSize_6_4'))
|
|
|
.fontColor($r("app.color.60FFFFFF"))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
@@ -621,7 +589,7 @@ export struct DeviceView {
|
|
|
.width('100%')
|
|
|
.justifyContent(FlexAlign.Center)
|
|
|
Row() {
|
|
|
- Text(BusinessConstant.stationName)
|
|
|
+ Text(CommonConstants.stationName)
|
|
|
.fontSize($r('app.float.fontSize_6_4'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
@@ -678,7 +646,7 @@ export struct DeviceView {
|
|
|
.width('100%')
|
|
|
.justifyContent(FlexAlign.Center)
|
|
|
Row() {
|
|
|
- Text(BusinessConstant.stationName)
|
|
|
+ Text(CommonConstants.stationName)
|
|
|
.fontSize($r('app.float.fontSize_6_4'))
|
|
|
.fontColor($r("app.color.60FFFFFF"))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
@@ -759,7 +727,7 @@ export struct DeviceView {
|
|
|
.width('100%')
|
|
|
.justifyContent(FlexAlign.Center)
|
|
|
Row() {
|
|
|
- Text(BusinessConstant.stationName)
|
|
|
+ Text(CommonConstants.stationName)
|
|
|
.fontSize($r('app.float.fontSize_6_4'))
|
|
|
.fontColor($r("app.color.60FFFFFF"))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
@@ -807,7 +775,7 @@ export struct DeviceView {
|
|
|
.width('100%')
|
|
|
.justifyContent(FlexAlign.Center)
|
|
|
Row() {
|
|
|
- Text(BusinessConstant.stationName)
|
|
|
+ Text(CommonConstants.stationName)
|
|
|
.fontSize($r('app.float.fontSize_6_4'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Lighter)
|
|
@@ -848,430 +816,5 @@ export struct DeviceView {
|
|
|
.width('100%')
|
|
|
.height('100%')
|
|
|
}
|
|
|
-
|
|
|
- createClient(): undefined | void {
|
|
|
- console.log("hhtest", '请求连接');
|
|
|
- if (this.mqttAsyncClient) {
|
|
|
- return;
|
|
|
- }
|
|
|
- this.mqttAsyncClient = MqttAsync.createMqtt({
|
|
|
- url: this.url,
|
|
|
- clientId: this.clientId,
|
|
|
- persistenceType: 1,
|
|
|
- });
|
|
|
- let num = 0
|
|
|
- while (num < 5) {
|
|
|
- if (!this.mqttAsyncClient) {
|
|
|
- this.mqttAsyncClient = MqttAsync.createMqtt({
|
|
|
- url: this.url,
|
|
|
- clientId: this.clientId,
|
|
|
- persistenceType: 1,
|
|
|
- });
|
|
|
- }
|
|
|
- num++
|
|
|
- }
|
|
|
- if (!this.mqttAsyncClient) {
|
|
|
- console.log("hhtest", '创建失败');
|
|
|
- return;
|
|
|
- }
|
|
|
- this.messageArrived()
|
|
|
- this.connectLost()
|
|
|
- this.mqttAsyncClient.setMqttTrace(6);
|
|
|
- // // this.showLog("create client success");
|
|
|
- }
|
|
|
-
|
|
|
- async connect(): Promise<undefined | void> {
|
|
|
- console.info('hhtest', "connect");
|
|
|
- // // this.showLog("connect");
|
|
|
- let options: MqttConnectOptions = {
|
|
|
- userName: this.userName,
|
|
|
- password: this.password,
|
|
|
- cleanSession:false,
|
|
|
- connectTimeout: 300
|
|
|
- };
|
|
|
- if (this.mqttAsyncClient == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!(await this.isConnected())) {
|
|
|
- if (this.isPromise) {
|
|
|
- this.mqttAsyncClient.connect(options).then((data: MqttResponse) => {
|
|
|
- console.info('hhtest', "connect result:" + JSON.stringify(data));
|
|
|
- this.connectedCount++;
|
|
|
- }).catch((data: MqttResponse) => {
|
|
|
- console.info('hhtest', "connect fail result:" + JSON.stringify(data));
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.mqttAsyncClient.connect(options, (err: Error, data: MqttResponse) => {
|
|
|
- if (!err) {
|
|
|
- console.info('hhtest', "connect result:" + JSON.stringify(data));
|
|
|
- if (data.message == "Connect Success") {
|
|
|
- console.info('hhtest', "connect result connectedCount:");
|
|
|
- this.connectedCount++;
|
|
|
- }
|
|
|
- } else {
|
|
|
- console.info('hhtest', "connect error:" + JSON.stringify(err));
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- async publish(): Promise<undefined | void> {
|
|
|
- console.info('hhtest', "publish");
|
|
|
- let publishOption: MqttPublishOptions = {
|
|
|
- topic: this.publishTopic,
|
|
|
- qos: 1,
|
|
|
- payload: this.payload
|
|
|
- }
|
|
|
- console.log('hhtest', 'publish msg:----------' + JSON.stringify(publishOption))
|
|
|
- if (this.mqttAsyncClient == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (await this.isConnected()) {
|
|
|
- if (this.isPromise) {
|
|
|
- this.mqttAsyncClient.publish(publishOption).then((data: MqttResponse) => {
|
|
|
- console.info('hhtest', "publish success result:" + JSON.stringify(data));
|
|
|
- }).catch((err: MqttResponse) => {
|
|
|
- console.info('hhtest', "publish fail result:" + JSON.stringify(err));
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.mqttAsyncClient.publish(publishOption, (err: Error, data: MqttResponse) => {
|
|
|
- console.info('hhtest', "publish response:");
|
|
|
- if (!err) {
|
|
|
- console.info('hhtest', "publish result:" + JSON.stringify(data));
|
|
|
- } else {
|
|
|
- console.info('hhtest', "publish error:" + JSON.stringify(err));
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- async subscribe(): Promise<undefined | void> {
|
|
|
- console.info('hhtest', "subscribe");
|
|
|
- let subscribeOption: MqttSubscribeOptions = {
|
|
|
- topic: this.subscribeTopic,
|
|
|
- qos: 2
|
|
|
- }
|
|
|
- if (this.mqttAsyncClient == null) {
|
|
|
- console.info('hhtest', "client not created");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (await this.isConnected()) {
|
|
|
- if (this.isPromise) {
|
|
|
- this.mqttAsyncClient.subscribe(subscribeOption).then((data: MqttResponse) => {
|
|
|
- console.info('hhtest', "subscribe success result:" + JSON.stringify(data));
|
|
|
- }).catch((err: MqttResponse) => {
|
|
|
- console.info('hhtest', "subscribe fail result:" + JSON.stringify(err));
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.mqttAsyncClient.subscribe(subscribeOption, (err: Error, data: MqttResponse) => {
|
|
|
- if (!err) {
|
|
|
- console.info('hhtest', "subscribe result:" + JSON.stringify(data));
|
|
|
- } else {
|
|
|
- console.info('hhtest', "subscribe error:" + JSON.stringify(err));
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- messageArrived(): undefined | void {
|
|
|
- console.info('hhtest', "messageArrived");
|
|
|
- if (this.mqttAsyncClient == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- this.mqttAsyncClient.messageArrived((err: Error, data: MqttMessage) => {
|
|
|
- if (!err) {
|
|
|
- // this.showLog(msg);
|
|
|
- let dataStr = JSON.stringify(data);
|
|
|
- console.info('hhtest', "messageArrived message:" + dataStr);
|
|
|
- if (dataStr.indexOf(this.subscribeTopic) === -1) {
|
|
|
- return
|
|
|
- }
|
|
|
- let updateData: MqttUploadData = JSON.parse(data.payload) as MqttUploadData;
|
|
|
- if (!updateData || !updateData.d || updateData.d.length <= 0) {
|
|
|
- console.info('hhtest', "updateData没有解析成功" + JSON.stringify(updateData));
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- let device0: ThreeColourLight = { LedRed: 0, LedOrange: 0, LedGreen: 0, Buzzer: 0, OpenStatus: 0 }
|
|
|
- let device1: WeldFumeExtractor = { ExhaustFan: 0, OnlineStatus: 0}
|
|
|
- let device2: ElectricSolderingIron = { SolderingCurrTemp: 0, OnlineStatus: 0}
|
|
|
- let device3: ElectricScrewdriver = { TighteRotationDirection: 0, TorqueHoldTime: 0, TightenTorqueTarget: 0,
|
|
|
- TorqueUpperLimit: 0, TorqueLowerLimit: 0, EnableFloatSlipDetection: 0, FloatDetectionTurns: 0, OnlineStatus: 0}
|
|
|
- let device4: AntiWristStrap = { RingWearNormal: 0, RingWearStandby: 0, RingWearFault: 0,OnlineStatus: 0 }
|
|
|
- let device5: CardReader = { RfidCardNum1: '', RfidCardNum2: '', OnlineStatus: 0}
|
|
|
- let device6: Lighting = { lighting: 0, OnlineStatus: 0 }
|
|
|
- let collectFlag: Array<boolean> = [false, false, false, false, false, false, false, false]
|
|
|
- for (const element of updateData.d) {
|
|
|
- if (BusinessConstant.attrMap.has(element.tag)) {
|
|
|
- let deviceType: string = BusinessConstant.attrMap.get(element.tag) ?? '';
|
|
|
- switch (deviceType) {
|
|
|
- case DeviceType.ThreeColourLight:
|
|
|
- collectFlag[0] = true
|
|
|
- if (element.tag! === 'LedRed') {
|
|
|
- device0.LedRed = element.value
|
|
|
- } else if (element.tag! === 'LedOrange') {
|
|
|
- device0.LedOrange = element.value
|
|
|
- } else if (element.tag! === 'LedGreen') {
|
|
|
- device0.LedGreen = element.value
|
|
|
- } else if (element.tag! === 'Buzzer') {
|
|
|
- device0.Buzzer = element.value
|
|
|
- }
|
|
|
- if (device0.LedRed! === 1 || device0.LedOrange! === 1
|
|
|
- || device0.LedGreen! === 1 || device0.Buzzer! === 1) {
|
|
|
- device0.OpenStatus = 1
|
|
|
- }
|
|
|
- device0.OnlineStatus = 1
|
|
|
- break;
|
|
|
- case DeviceType.WeldFumeExtractor:
|
|
|
- collectFlag[1] = true
|
|
|
- if (element.tag! === 'ExhaustFan') {
|
|
|
- device1.ExhaustFan = element.value
|
|
|
- }
|
|
|
- device1.OnlineStatus = 1
|
|
|
- break;
|
|
|
- case DeviceType.ElectricSolderingIron:
|
|
|
- collectFlag[2] = true
|
|
|
- if (element.tag! === 'SolderingCurrTemp') {
|
|
|
- device2.SolderingCurrTemp = element.value
|
|
|
- }
|
|
|
- device2.OnlineStatus = 1
|
|
|
- break;
|
|
|
- case DeviceType.ElectricScrewdriver:
|
|
|
- collectFlag[3] = true
|
|
|
- if (element.tag! === 'TightenTorqueTarget') {
|
|
|
- device3.TightenTorqueTarget = element.value
|
|
|
- } else if (element.tag! === 'TorqueHoldTime') {
|
|
|
- device3.TorqueHoldTime = element.value
|
|
|
- }
|
|
|
- device3.OnlineStatus = 1
|
|
|
- break;
|
|
|
- case DeviceType.AntiWristStrap:
|
|
|
- collectFlag[4] = true
|
|
|
- if (element.tag! === 'RingWearNormal') {
|
|
|
- device4.RingWearNormal = element.value
|
|
|
- } else if (element.tag! === 'RingWearStandby') {
|
|
|
- device4.RingWearStandby = element.value
|
|
|
- } else if (element.tag! === 'RingWearFault') {
|
|
|
- device4.RingWearFault = element.value
|
|
|
- }
|
|
|
- device4.OnlineStatus = 1
|
|
|
- break;
|
|
|
- case DeviceType.CardReader:
|
|
|
- collectFlag[5] = true
|
|
|
- if (element.tag! === 'RfidCardNum1') {
|
|
|
- let value = element.value?.toString(16)
|
|
|
- device5.RfidCardNum1 = value === '0' ? '' : value
|
|
|
- } else if (element.tag! === 'RfidCardNum2') {
|
|
|
- let value = element.value?.toString(16)
|
|
|
- device5.RfidCardNum2 = value === '0' ? '' : value
|
|
|
- }
|
|
|
- device5.OnlineStatus = 1
|
|
|
- break;
|
|
|
- case DeviceType.Lighting:
|
|
|
- collectFlag[6] = true
|
|
|
- if (element.tag! === 'lighting') {
|
|
|
- device6.lighting = element.value
|
|
|
- }
|
|
|
- device6.OnlineStatus = 1
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if (collectFlag[0]) {
|
|
|
- this.threeColourLight = device0;
|
|
|
- } else {
|
|
|
- this.threeColourLight = {
|
|
|
- LedRed: this.threeColourLight.LedRed,
|
|
|
- LedGreen: this.threeColourLight.LedGreen,
|
|
|
- LedOrange: this.threeColourLight.LedOrange,
|
|
|
- Buzzer: this.threeColourLight.Buzzer,
|
|
|
- OpenStatus: 0
|
|
|
- }
|
|
|
- }
|
|
|
- if (collectFlag[1]) {
|
|
|
- this.weldFumeExtractor = device1;
|
|
|
- } else {
|
|
|
- this.weldFumeExtractor.OnlineStatus = 0
|
|
|
- this.weldFumeExtractor = {
|
|
|
- ExhaustFan: this.weldFumeExtractor.ExhaustFan,
|
|
|
- OnlineStatus: 0
|
|
|
- }
|
|
|
- }
|
|
|
- if (collectFlag[2]) {
|
|
|
- this.solderingIron = device2;
|
|
|
- } else {
|
|
|
- this.solderingIron.OnlineStatus = 0
|
|
|
- this.solderingIron = {
|
|
|
- SolderingCurrTemp: this.solderingIron.SolderingCurrTemp,
|
|
|
- OnlineStatus: 0
|
|
|
- }
|
|
|
- }
|
|
|
- if (collectFlag[3]) {
|
|
|
- this.screwdriver = JSON.parse(JSON.stringify(device3)) as ElectricScrewdriver;
|
|
|
- } else {
|
|
|
- this.screwdriver = {
|
|
|
- TightenTorqueTarget: this.screwdriver.TightenTorqueTarget,
|
|
|
- TorqueHoldTime: this.screwdriver.TorqueHoldTime,
|
|
|
- OnlineStatus: 0
|
|
|
- }
|
|
|
- }
|
|
|
- if (collectFlag[4]) {
|
|
|
- this.wristStrap = JSON.parse(JSON.stringify(device4)) as AntiWristStrap;
|
|
|
- } else {
|
|
|
- this.wristStrap = {
|
|
|
- RingWearNormal: this.wristStrap.RingWearNormal,
|
|
|
- RingWearStandby: this.wristStrap.RingWearStandby,
|
|
|
- RingWearFault: this.wristStrap.RingWearFault,
|
|
|
- OnlineStatus: 0
|
|
|
- }
|
|
|
- }
|
|
|
- if (collectFlag[5]) {
|
|
|
- this.cardReader = JSON.parse(JSON.stringify(device5)) as CardReader;
|
|
|
- } else {
|
|
|
- this.cardReader = {
|
|
|
- RfidCardNum1: this.cardReader.RfidCardNum1,
|
|
|
- RfidCardNum2: this.cardReader.RfidCardNum2,
|
|
|
- OnlineStatus: 0
|
|
|
- }
|
|
|
- }
|
|
|
- if (collectFlag[6]) {
|
|
|
- this.lighting = JSON.parse(JSON.stringify(device6)) as Lighting;
|
|
|
- } else {
|
|
|
- this.lighting = {
|
|
|
- lighting: this.lighting.lighting,
|
|
|
- OnlineStatus: 0
|
|
|
- }
|
|
|
- }
|
|
|
- console.info('hhtest', "this.threeColourLight" + JSON.stringify(this.threeColourLight));
|
|
|
- console.info('hhtest', "this.weldFumeExtractor" + JSON.stringify(this.weldFumeExtractor));
|
|
|
- console.info('hhtest', "this.solderingIron" + JSON.stringify(this.solderingIron));
|
|
|
- console.info('hhtest', "this.wristStrap" + JSON.stringify(this.wristStrap));
|
|
|
- console.info('hhtest', "this.cardReader" + JSON.stringify(this.cardReader));
|
|
|
- console.info('hhtest', "this.lighting" + JSON.stringify(this.lighting));
|
|
|
- } else {
|
|
|
- console.info('hhtest', "messageArrived error:" + JSON.stringify(err));
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- async unsubscribe(): Promise<undefined | void> {
|
|
|
- console.info('hhtest', "unsubscribe");
|
|
|
- let subscribeOption: MqttSubscribeOptions = {
|
|
|
- topic: this.subscribeTopic,
|
|
|
- qos: 2
|
|
|
- }
|
|
|
- if (this.mqttAsyncClient == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (await this.isConnected()) {
|
|
|
- if (this.isPromise) {
|
|
|
- this.mqttAsyncClient.unsubscribe(subscribeOption).then((data: MqttResponse) => {
|
|
|
- console.info('hhtest', "unsubscribe success result:" + JSON.stringify(data));
|
|
|
- }).catch((err: MqttResponse) => {
|
|
|
- console.info('hhtest', "unsubscribe fail result:" + JSON.stringify(err));
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.mqttAsyncClient.unsubscribe(subscribeOption, (err: Error, data: MqttResponse) => {
|
|
|
- if (!err) {
|
|
|
- console.info('hhtest', "unsubscribe result:" + JSON.stringify(data));
|
|
|
- } else {
|
|
|
- console.info('hhtest', "unsubscribe error:" + JSON.stringify(err));
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- async disconnect(): Promise<undefined | void> {
|
|
|
- console.info('hhtest', "disconnect");
|
|
|
- if (this.mqttAsyncClient == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (await this.isConnected()) {
|
|
|
- if (this.isPromise) {
|
|
|
- this.mqttAsyncClient.disconnect().then((data: MqttResponse) => {
|
|
|
- console.info('hhtest', "disconnect success result:" + JSON.stringify(data));
|
|
|
- }).catch((err: MqttResponse) => {
|
|
|
- console.info('hhtest', "disconnect fail result:" + JSON.stringify(err));
|
|
|
- })
|
|
|
- } else {
|
|
|
- this.mqttAsyncClient.disconnect((err: Error, data: MqttResponse) => {
|
|
|
- if (!err) {
|
|
|
- console.info('hhtest', "disconnect result:" + JSON.stringify(data));
|
|
|
- } else {
|
|
|
- console.info('hhtest', "disconnect error:" + JSON.stringify(err));
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- async isConnected(): Promise<undefined | boolean> {
|
|
|
- console.info('hhtest', "isConnected");
|
|
|
- if (this.mqttAsyncClient == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- return this.mqttAsyncClient.isConnected().then((data: boolean) => {
|
|
|
- console.info('hhtest', "isConnected result:" + data);
|
|
|
- if (!data) {
|
|
|
- }
|
|
|
- return data;
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- async reconnect(): Promise<undefined | void> {
|
|
|
- console.info('hhtest', "reconnect");
|
|
|
- if (this.mqttAsyncClient == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!(await this.isConnected())) {
|
|
|
- if (this.connectedCount == 0) {
|
|
|
- console.info('hhtest', "reconnect: client previously not connected");
|
|
|
- return;
|
|
|
- }
|
|
|
- this.mqttAsyncClient.reconnect().then((data: boolean) => {
|
|
|
- console.info('hhtest', "reConnected result:" + data);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- connectLost(): undefined | void {
|
|
|
- console.info('hhtest', "connectLost");
|
|
|
- if (this.mqttAsyncClient == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- this.mqttAsyncClient.connectLost((err: Error, data: MqttResponse) => {
|
|
|
- if (!err) {
|
|
|
- this.reconnect();
|
|
|
- console.info('hhtest', "connect lost cause:" + JSON.stringify(data));
|
|
|
- } else {
|
|
|
- console.info('hhtest', "connect lost error:" + JSON.stringify(err));
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- async destroy(): Promise<undefined | void> {
|
|
|
- console.info('hhtest', "destroy");
|
|
|
- if (this.mqttAsyncClient == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- this.mqttAsyncClient.destroy().then((data: boolean) => {
|
|
|
- console.info('hhtest', "destroy result:" + data);
|
|
|
- this.mqttAsyncClient = null;
|
|
|
- this.connectedCount = 0;
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- clear(): void {
|
|
|
- this.arr = [];
|
|
|
- }
|
|
|
-
|
|
|
- setIsPromise(isPromise: boolean): void {
|
|
|
- this.isPromise = !isPromise
|
|
|
- console.info('hhtest', "setIsPromise result:" + this.isPromise);
|
|
|
- }
|
|
|
}
|
|
|
|