|
@@ -1,6 +1,74 @@
|
|
|
|
+import MqttManager from '../common/util/mqtt';
|
|
|
|
+import emitter from '@ohos.events.emitter';
|
|
|
|
+import {EventId,MQTTPublishData,MQTTReceiveData} from '../common/util/mqtt';
|
|
@Component
|
|
@Component
|
|
export struct InBoundView {
|
|
export struct InBoundView {
|
|
@Prop messages: string[] = []
|
|
@Prop messages: string[] = []
|
|
|
|
+ @State drawerPositionStatus: number = 1
|
|
|
|
+ @State materialBoxID: string = ''
|
|
|
|
+ //料箱重量
|
|
|
|
+ @State materialBoxWeight: number = 0
|
|
|
|
+
|
|
|
|
+ refreshTag=()=>{
|
|
|
|
+ emitter.on({
|
|
|
|
+ eventId: EventId.MQTT_MESSAGE
|
|
|
|
+ }, (eventData: emitter.EventData) => {
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ const payload = eventData.data?.['payload'] as string;
|
|
|
|
+ const valueJson: MQTTReceiveData = JSON.parse(payload);
|
|
|
|
+ const stationItem = valueJson?.d?.find(item => item.tag === 'Station2Set');
|
|
|
|
+ const stationWeight = valueJson?.d?.find(item => item.tag === 'Station2Weight');
|
|
|
|
+ const rfidString = decodeRfidString(
|
|
|
|
+ valueJson?.d?.find(item => item.tag === 'RFID3Data1')?.value as number,
|
|
|
|
+ valueJson?.d?.find(item => item.tag === 'RFID3Data2')?.value as number,
|
|
|
|
+ valueJson?.d?.find(item => item.tag === 'RFID3Data3')?.value as number,
|
|
|
|
+ valueJson?.d?.find(item => item.tag === 'RFID3Data4')?.value as number
|
|
|
|
+ );
|
|
|
|
+ this.materialBoxID = rfidString;
|
|
|
|
+
|
|
|
|
+ //this.materialBoxID = "XF-00002";
|
|
|
|
+ if (stationItem?.value !== undefined) {
|
|
|
|
+ this.drawerPositionStatus = Number(stationItem.value);
|
|
|
|
+ console.log(`更新抽屉状态: ${this.drawerPositionStatus} (${typeof this.drawerPositionStatus})`);
|
|
|
|
+ }
|
|
|
|
+ if (stationWeight?.value !== undefined) {
|
|
|
|
+ this.materialBoxWeight =decodeWeight(stationWeight.value)
|
|
|
|
+ console.log(`更新重量状态: ${this.materialBoxWeight} (${typeof this.materialBoxWeight})`);
|
|
|
|
+ }
|
|
|
|
+ } catch (e) {
|
|
|
|
+ console.error("MQTT消息处理异常:", e);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ //抽屉推出
|
|
|
|
+ pushOut =()=>{
|
|
|
|
+ const drawerCommand: MQTTPublishData = {
|
|
|
|
+ w: [
|
|
|
|
+ {
|
|
|
|
+ tag: "Station2Set",
|
|
|
|
+ value: 0
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
|
|
+ MqttManager.publish('station100/cmd/devices', drawerCommand, 1, true);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //抽屉伸入
|
|
|
|
+ pushIn =()=>{
|
|
|
|
+ const drawerCommand: MQTTPublishData = {
|
|
|
|
+ w: [
|
|
|
|
+ {
|
|
|
|
+ tag: "Station2Set",
|
|
|
|
+ value: 1
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
|
|
+ MqttManager.publish('station100/cmd/devices', drawerCommand, 1, true);
|
|
|
|
+ }
|
|
|
|
+ aboutToAppear(): void {
|
|
|
|
+ this.refreshTag()
|
|
|
|
+ }
|
|
build() {
|
|
build() {
|
|
Column() {
|
|
Column() {
|
|
Text('出入库料口操作')
|
|
Text('出入库料口操作')
|
|
@@ -9,7 +77,11 @@ export struct InBoundView {
|
|
.margin({ top: '3%' })
|
|
.margin({ top: '3%' })
|
|
Column() {
|
|
Column() {
|
|
Stack() {
|
|
Stack() {
|
|
- Image($r('app.media.drawer_in_box'))// 替换为您的电梯图片资源
|
|
|
|
|
|
+ Image(
|
|
|
|
+ this.drawerPositionStatus === 1
|
|
|
|
+ ? (this.materialBoxWeight >0 ? $r('app.media.drawer_in_box') : $r('app.media.drawer_in_no_box'))
|
|
|
|
+ : (this.materialBoxWeight >0 ? $r('app.media.drawer_out_box') : $r('app.media.drawer_out_no_box'))
|
|
|
|
+ )// 替换为您的电梯图片资源
|
|
.width('100%')
|
|
.width('100%')
|
|
.height('100%')
|
|
.height('100%')
|
|
.borderRadius($r('app.float.virtualSize_6_4'))
|
|
.borderRadius($r('app.float.virtualSize_6_4'))
|
|
@@ -21,7 +93,7 @@ export struct InBoundView {
|
|
.width('5%')
|
|
.width('5%')
|
|
.height('30%')
|
|
.height('30%')
|
|
.fillColor($r('app.color.30D158'))
|
|
.fillColor($r('app.color.30D158'))
|
|
- Text("15Kg")
|
|
|
|
|
|
+ Text(String(this.materialBoxWeight)+"kg")
|
|
.margin({ left: 10 })
|
|
.margin({ left: 10 })
|
|
.fontSize($r('app.float.fontSize_15_2'))
|
|
.fontSize($r('app.float.fontSize_15_2'))
|
|
.fontColor($r('app.color.30D158')) // 绿色文字
|
|
.fontColor($r('app.color.30D158')) // 绿色文字
|
|
@@ -33,7 +105,7 @@ export struct InBoundView {
|
|
.height('30%')
|
|
.height('30%')
|
|
.fillColor($r('app.color.30D158'))
|
|
.fillColor($r('app.color.30D158'))
|
|
|
|
|
|
- Text("LX-00010")
|
|
|
|
|
|
+ Text(this.materialBoxID)
|
|
.margin({ left: 10 })
|
|
.margin({ left: 10 })
|
|
.fontSize($r('app.float.fontSize_15_2'))
|
|
.fontSize($r('app.float.fontSize_15_2'))
|
|
.fontColor($r('app.color.30D158')) // 绿色文字
|
|
.fontColor($r('app.color.30D158')) // 绿色文字
|
|
@@ -87,7 +159,7 @@ export struct InBoundView {
|
|
.backgroundColor($r('app.color.20FFFFFF'))
|
|
.backgroundColor($r('app.color.20FFFFFF'))
|
|
.borderRadius($r('app.float.virtualSize_6_4'))
|
|
.borderRadius($r('app.float.virtualSize_6_4'))
|
|
.onClick(() => {
|
|
.onClick(() => {
|
|
- // 按钮点击事件处理
|
|
|
|
|
|
+ this.pushOut()
|
|
})
|
|
})
|
|
|
|
|
|
Button({ type: ButtonType.Normal }) {
|
|
Button({ type: ButtonType.Normal }) {
|
|
@@ -100,7 +172,7 @@ export struct InBoundView {
|
|
.backgroundColor($r('app.color.20FFFFFF'))
|
|
.backgroundColor($r('app.color.20FFFFFF'))
|
|
.borderRadius($r('app.float.virtualSize_6_4'))
|
|
.borderRadius($r('app.float.virtualSize_6_4'))
|
|
.onClick(() => {
|
|
.onClick(() => {
|
|
- // 按钮点击事件处理
|
|
|
|
|
|
+ this.pushIn()
|
|
})
|
|
})
|
|
}
|
|
}
|
|
.width('95%')
|
|
.width('95%')
|
|
@@ -128,3 +200,47 @@ export struct InBoundView {
|
|
.justifyContent(FlexAlign.Start)
|
|
.justifyContent(FlexAlign.Start)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+function decodeRegister(regValue: number | undefined): string {
|
|
|
|
+ if (regValue === undefined) return ''; // 处理undefined
|
|
|
|
+
|
|
|
|
+ // 确保是16位无符号整数
|
|
|
|
+ const value = regValue & 0xFFFF;
|
|
|
|
+
|
|
|
|
+ // 提取高8位和低8位
|
|
|
|
+ const highByte = (value >> 8) & 0xFF;
|
|
|
|
+ const lowByte = value & 0xFF;
|
|
|
|
+
|
|
|
|
+ // 转换为ASCII字符
|
|
|
|
+ return String.fromCharCode(highByte) + String.fromCharCode(lowByte);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 完整RFID解码函数
|
|
|
|
+function decodeRfidString(
|
|
|
|
+ rfidData1?: number,
|
|
|
|
+ rfidData2?: number,
|
|
|
|
+ rfidData3?: number,
|
|
|
|
+ rfidData4?: number
|
|
|
|
+): string {
|
|
|
|
+ return [
|
|
|
|
+ decodeRegister(rfidData1),
|
|
|
|
+ decodeRegister(rfidData2),
|
|
|
|
+ decodeRegister(rfidData3),
|
|
|
|
+ decodeRegister(rfidData4)
|
|
|
|
+ ].join('');
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function decodeWeight(regValue: number | undefined): number {
|
|
|
|
+ if (regValue === undefined) return 0; // 处理undefined
|
|
|
|
+
|
|
|
|
+ // 确保是16位无符号整数
|
|
|
|
+ const value = regValue & 0xFFFF;
|
|
|
|
+
|
|
|
|
+ // 提取高8位和低8位
|
|
|
|
+ const highByte = (value >> 8) & 0xFF;
|
|
|
|
+ const lowByte = value & 0xFF;
|
|
|
|
+
|
|
|
|
+ // 转换为ASCII字符
|
|
|
|
+ return highByte+lowByte/100
|
|
|
|
+}
|