From 4f34fc484c0556f66bfa41bd19a69b79f631f35a Mon Sep 17 00:00:00 2001 From: lvyuankang <1344032923@qq.com> Date: Wed, 12 Feb 2025 11:30:16 +0800 Subject: [PATCH] =?UTF-8?q?globalThis=20udp=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/common/utils/UdpClient.ts | 237 ---------- .../ets/common/utils/UdpClientByCenter.ts | 44 +- .../ets/pages/compontents/SignDisplayCom.ets | 5 - .../ets/pages/compontents/SignDisplayCom2.ets | 439 ------------------ 4 files changed, 7 insertions(+), 718 deletions(-) delete mode 100644 entry/src/main/ets/common/utils/UdpClient.ts delete mode 100644 entry/src/main/ets/pages/compontents/SignDisplayCom2.ets diff --git a/entry/src/main/ets/common/utils/UdpClient.ts b/entry/src/main/ets/common/utils/UdpClient.ts deleted file mode 100644 index 0fe7d78f..00000000 --- a/entry/src/main/ets/common/utils/UdpClient.ts +++ /dev/null @@ -1,237 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import socket from '@ohos.net.socket'; -import { Array2Byte } from '../utils/tools' -import {getChuankouFn} from '../../common/service/indexService' -import {getUDP} from './GlobalUdp' -const TAG = 'socketTag[PLC.UdpClient]' -import prompt from '@ohos.prompt' - -import hilog from '@ohos.hilog'; -let num=0 -export default class UdpClient { - private localIp: string = '' - private localIpPort: string = '' - private oppositeIp: string = '' - private oppositeIpPort: string = '' - - private udp: any = null - // private stashFn:StashFuncotionon - - constructor(udplocalIp: string, udplocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) { - this.localIp = udplocalIp - this.oppositeIp = udpOppositeIp - this.localIpPort = udplocalIpPort - this.oppositeIpPort = udpOppositeIpPort - getChuankouFn() - console.log(TAG,'newUdp') - // this.stashFn=()=>{} - this.udp = socket.constructUDPSocketInstance(); - } - - rebindUdp(localIp: string, localIpPort: string, oppositeIp: string, oppositeIpPort: string) { - console.log(TAG,'rebindUdp',this.localIp,this.localIpPort) - - this.localIp = localIp - this.oppositeIp = oppositeIp - this.localIpPort = localIpPort - this.oppositeIpPort = oppositeIpPort - let promise = this.udp.bind({ - address: this.localIp, port: parseInt(this.localIpPort), family: 1 - }); - promise.then(() => { - globalThis.closeUDPSocket=false - - console.log(`${TAG},udpCLient udp rebind success`); - }).catch(err => { - globalThis.closeUDPSocket=true - console.log(`${TAG},udpCLient udp rebind failed:${JSON.stringify(err)}`); - }); - } - - bindUdp() { - console.log(TAG,'udpbind',this.localIp,this.localIpPort) - let promise = this.udp.bind({ - // address: '192.168.7.170', port: 20122, family: 1 - // address: '192.168.7.170', port: 31013, family: 1 - address: this.localIp, port: parseInt(this.localIpPort), family: 1 - }); - promise.then(() => { - globalThis.closeUDPSocket=false - console.log(`${TAG}udpCLient udp bind success`); - }).catch(err => { - globalThis.closeUDPSocket=true - console.log(`${TAG}udpCLient udp bind failed:${JSON.stringify(err)}`); - }); - } - setMsgCallBack(callback){ - // this.stashFn=callback?callback:()=>{} - } - sendMsg(msg) { - console.log(TAG,'UdpSend1111',this.oppositeIp,this.oppositeIpPort) - this.udp.getState((err, data) => { - if (err) { - - console.log('getState fail'); - return; - } else { - let promise = this.udp.send({ - data: msg, - address: { - // address: '192.168.7.124', - // port: 30013, - // address: '192.168.7.124', - // port: 20022, - address: this.oppositeIp, - port: parseInt(this.oppositeIpPort), - family: 1 - } - }); - promise.then(() => { - console.log(`${TAG}udpCLient udp send success:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`); - }).catch(err => { - console.log(`${TAG}udpCLient udp send fail:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`); - }); - } - console.log('getState success:' + JSON.stringify(data)); - }) - - } - onError(callback?){ - this.udp.on('error',async err => { - globalThis.closeUDPSocket=true - console.log(TAG,'udpError',JSON.stringify(err)) - await this.bindUdp() - await this.sendMsg('111') - await this.onMessage(callback) - // callback&&callback() - // this.closeUdp(()=>{ - // this.bindUdp() - // }) - }); - } - - onMessage(callback?) { - console.info(TAG, '注册udp message监听事件') - this.udp.on('message', value => { - console.log(TAG,'udponmessage') - // 收到的是ArrayBuffer 需要进行转换解析 - globalThis.plcUdpError = false - if (value) { - - let dataView = new DataView(value.message) - // console.log(`${TAG} udp message length:${dataView?.byteLength}`); - let str = "" - for (let i = 0; i < dataView?.byteLength; ++i) { - let c = String.fromCharCode(dataView?.getUint8(i)) - if (c !== "\n") { - str += c - } - } - - console.log(`${TAG} udp on message array buffer:${str}`); - let strachArr = str.split(',') - if (strachArr[0] != '#DN_GD') { - return - } - console.log(`${TAG} udp222 on message array buffer:${str}`); - - strachArr[28]=globalThis.chuankoMsg||'0' - // this.stashFn(str) - const newArr=JSON.parse(JSON.stringify(strachArr)) - // this.stashFn=()=>{} - callback&&callback(newArr.toString()) - - } else { - callback&&callback('') - } - - }); - const arrRed = [0x55, 0xaa, 0x01, 0x01, 0x02, 0x00, 0x03, 0x00]; - const arrBlue = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00]; - const arrGreen = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x01]; - const arrBlueBuffer = Array2Byte(arrBlue).buffer - const arrRedBuffer = Array2Byte(arrRed).buffer - const arrGreenBugger = Array2Byte(arrGreen).buffer - //监听udp是否断开 - clearInterval(globalThis.messageTimer) - globalThis.messageTimer = setInterval(() => { - const lightLineUdp = globalThis.lightLineUdp - const isJudge = globalThis.isJudge - setTimeout(async () => { - //程序断开 - lightLineUdp?.send(globalThis.plcUdpError ? arrRedBuffer : (isJudge ? arrGreenBugger : arrBlueBuffer)); - if (globalThis.plcUdpError) { - // num++ - console.log(TAG,'plc udp信号丢失') - // if(num==3){ - getUDP(globalThis.context,true) - // await this.bindUdp() - // await this.sendMsg('111') - // await this.onMessage(callback) - // num=0 - // } - prompt.showToast({ - message: 'plc udp信号丢失', - duration: 2000 - }); - } - globalThis.plcUdpError = true; - }, 2000) - }, 3000) - } - - closeUdp(callback) { - this.udp.close(err => { - hilog.info(0x0000,TAG, 'udpCLient', 'close'); - - if (err) { - hilog.info(0x0000,TAG, 'udpCLient', 'closeonerror'); - globalThis.closeUDPSocket=false - - } else { - globalThis.closeUDPSocket=true - - this.udp.getState((err, data) => { - if (err) { - console.log('getState fail'); - return; - } else { - if (!data.isisClose) { - setTimeout(() => { - callback() - }, 1000) - } - } - console.log('getState success:' + JSON.stringify(data)); - }) - // let promise = this.udp.getState({}); - // promise.then(data => { - // - // console.log('getState success:' + JSON.stringify(data)); - // }).catch(err => { - // callback() - // console.log('getState fail'); - // }); - } - }); - } - - -} -interface StashFunction { - (str: string) -} \ No newline at end of file diff --git a/entry/src/main/ets/common/utils/UdpClientByCenter.ts b/entry/src/main/ets/common/utils/UdpClientByCenter.ts index d1891209..ac5ff6ee 100644 --- a/entry/src/main/ets/common/utils/UdpClientByCenter.ts +++ b/entry/src/main/ets/common/utils/UdpClientByCenter.ts @@ -26,6 +26,7 @@ import promptAction from '@ohos.promptAction'; import { getUDP } from './GlobalUdp'; import { dateFormat } from '../utils/tools' import { getSyncData } from '../service/initable'; +import App from '@system.app'; export default class UdpClientByCenter { @@ -40,7 +41,6 @@ export default class UdpClientByCenter { private udp: UDPSocket = null private sendId: any = 0 private lsh: string = null - private context private folderPath private stashFn: StashFunction private errorStep: number=0 @@ -81,14 +81,12 @@ export default class UdpClientByCenter { }); promise.then(() => { - // globalThis.closeHeartSocket=false this.isWorking = true // this.writeLog({ // time:dateFormat(new Date()), // PLC:`${TAG} getUDPudp rebind success`, // }) }).catch(err => { - //globalThis.closeHeartSocket=true this.isWorking = false // this.writeLog({ // time:dateFormat(new Date()), @@ -152,7 +150,7 @@ export default class UdpClientByCenter { setMsgHead({id, list, placeId=62, carNo=489}) { let a = string2Bytes(`${id}${fillZero(placeId, 3)}`, 2 * 8); - let b = string2Bytes(`${fillZero(carNo, 4)}${globalThis.lshNo}`, 4 * 8); + let b = string2Bytes(`${fillZero(carNo, 4)}${AppStorage.get('lshNo')}`, 4 * 8); let c = string2Bytes(list.length, 2 * 8); return [...a, ...b, ...c]; } @@ -328,7 +326,7 @@ export default class UdpClientByCenter { return } - strachArr[28] = globalThis.chuankoMsg || strachArr[28] + strachArr[28] = AppStorage.get('chuankoMsg') || strachArr[28] // this.stashFn(str) const newArr = JSON.parse(JSON.stringify(strachArr)) @@ -343,7 +341,6 @@ export default class UdpClientByCenter { PLC: `${TAG}差分状态异常,${strachArr[83]},${strachArr[92]}`, }) }else{ - globalThis.dialogOpen=false this.chafenFlag=0 } callback && callback(newArr.toString()) @@ -376,13 +373,12 @@ export default class UdpClientByCenter { const arrRedBuffer = Array2Byte(arrRed).buffer const arrGreenBugger = Array2Byte(arrGreen).buffer let num = 0 - globalThis.dialogOpen=false //监听udp是否断开 clearInterval(globalThis.messageTimer) globalThis.messageTimer = setInterval(() => { const lightLineUdp = globalThis.lightLineUdp - const isJudge = globalThis.isJudge + const isJudge = AppStorage.get('isJudge') setTimeout(async () => { //程序断开 lightLineUdp?.send(this.plcUdpError ? arrRedBuffer : (isJudge ? arrGreenBugger : arrBlueBuffer)); @@ -394,35 +390,9 @@ export default class UdpClientByCenter { }) console.log(TAG, 'plc udp信号丢失') if (num == 3) { - getUDP(globalThis.context,true) - globalThis.title='plc udp信号丢失' - globalThis.type='3' - if(!globalThis.dialogOpen){ - // AppStorage.SetOrCreate('errorCode', 1); - // if(this.errorStep!=1){ - // console.log('sys.v_valuesys.v_valuesys.v_value11221') - // - // this.errorStep=1 - // this.avPlayer.playAudio(['voice/差分状态异常.wav']) - // getSyncData('MA_SYSSET').then(syssetParams => { - // console.log('sys.v_valuesys.v_valuesys.v_value11221',JSON.stringify(syssetParams)) - // // @ts-ignore - // syssetParams.forEach(sys => { - // // 差分长时间是SINGLE状态报考车故障,停止考试(0-否 1-是) - // if (sys.v_no === '424'&&sys.v_value==1){ - // //plc差分丢失 - // AppStorage.SetOrCreate('errorCode', 0); - // AppStorage.SetOrCreate('errorCodeFlage', true); - // - // } - // }) - // // const errorParam = syssetParams.filter(sys => sys.v_no === '424') // - // // that.studentRefreshStatue = studentRefreshParam?.[0]?.v_value || '0' - // - // - // }); - // } - } + getUDP(AppStorage.get('context'),true) + AppStorage.setOrCreate('title','plc udp信号丢失') + AppStorage.setOrCreate('type',3) num = 0 } diff --git a/entry/src/main/ets/pages/compontents/SignDisplayCom.ets b/entry/src/main/ets/pages/compontents/SignDisplayCom.ets index 60dbe634..34864e98 100644 --- a/entry/src/main/ets/pages/compontents/SignDisplayCom.ets +++ b/entry/src/main/ets/pages/compontents/SignDisplayCom.ets @@ -1,5 +1,4 @@ import router from '@ohos.router'; -import UdpClient from '../../common/utils/UdpClient'; import FileLog from '../judgeSDK/utils/fileLog'; import RealTime from '../compontents/judge/RealTime'; import { GPSData, SignalData } from '../../mock'; @@ -23,10 +22,6 @@ export default struct SignDisplayCom { @State interval: number = 0 @State @Watch('outClick') outFlag: boolean = false; @State url: string = '' - private timer = null - private udpClient: UdpClient = null - private FileLog: FileLog - private vocObj = null; constructor() { super() diff --git a/entry/src/main/ets/pages/compontents/SignDisplayCom2.ets b/entry/src/main/ets/pages/compontents/SignDisplayCom2.ets deleted file mode 100644 index 4e766772..00000000 --- a/entry/src/main/ets/pages/compontents/SignDisplayCom2.ets +++ /dev/null @@ -1,439 +0,0 @@ -import router from '@ohos.router'; -import UdpClient from '../../common/utils/UdpClient'; -import FileLog from '../judgeSDK/utils/fileLog'; -import RealTime from '../compontents/judge/RealTime'; -import { GPSData, SignalData } from '../../mock'; -import { SignalDataType } from '../../model'; -import FileUtil from '../../common/utils/File' -import { GlobalConfig } from '../../config/index' -@Component -export default struct SignDisplayCom { - @State showBack: boolean = false - @State scaleNum: number = 1 - @State msg: string = '' - @State signArr: Array = [] - @State sjxhColum: Array = SignalData - @State GPSColum: Array = GPSData - @State ratio: number = 850 / 960 - @State gpsActive: number = 1 - @Prop active: number = 0 - @State msgStr: string = '' - @State udplocalIp: string = '' - @State interval: number = 0 - @State @Watch('outClick') outFlag: boolean = false; - @State url: string = '' - private timer = null - private udpClient: UdpClient = null - private FileLog: FileLog - private vocObj = null; - - constructor() { - super() - } - - build() { - Column() { - Column() { - Flex({ justifyContent: FlexAlign.SpaceBetween }) { - Row() { - Image($r('app.media.signal_logoS')).width(30 * this.ratio).height(24 * this.ratio) - Row() { - Text('PLC信号').fontColor(this.active == 0 ? '#FFAD33' : '#e7cba3').fontSize(20 * this.ratio) - } - .backgroundImage(this.active == 0 ? $r('app.media.signal_tabS') : $r('app.media.signal_tab')) - .width(144 * this.ratio) - .height(50 * this.ratio) - .backgroundImageSize({ width: '100%', height: '100%' }) - .justifyContent(FlexAlign.Center) - .onClick(() => { - this.active = 0 - - }) - - if (!this.showBack) { - Row() { - Text('实时轨迹').fontColor(this.active == 1 ? '#FFAD33' : '#e7cba3').fontSize(20 * this.ratio) - } - .backgroundImage(this.active == 1 ? $r('app.media.signal_tabS') : $r('app.media.signal_tab')) - .width(144 * this.ratio) - .height(50 * this.ratio) - .backgroundImageSize({ width: '100%', height: '100%' }) - .justifyContent(FlexAlign.Center) - .onClick(() => { - this.active = 1 - // this.vocObj.playAudio({ - // type: 1, - // name: 'media_button.wav' - // }) - }) - } - - Row() { - Text('原始数据').fontColor(this.active == 2 ? '#FFAD33' : '#e7cba3').fontSize(20 * this.ratio) - } - .backgroundImage(this.active == 2 ? $r('app.media.signal_tabS') : $r('app.media.signal_tab')) - .width(144 * this.ratio) - .height(50 * this.ratio) - .backgroundImageSize({ width: '100%', height: '100%' }) - .justifyContent(FlexAlign.Center) - .onClick(() => { - this.active = 2 - }) - } - - Row() { - if (this.showBack) { - Image($r('app.media.topB_back')).height('12.2%') - .onClick(() => { - router.back() - // this.url='back' - // this.vocObj.playAudio({ - // type: 1, - // name: 'media_button.wav' - // }) - this.outFlag = true - }) - } - } - }.width(936 * this.ratio) - - Column() { - Flex({ direction: FlexDirection.Column }) { - Row() { - Text("发送次数:" + this.signArr[49] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .width('25%') - .textAlign(TextAlign.Start) - Text("固件版本:" + this.signArr[54] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .width('30%') - .textAlign(TextAlign.Start) - Text("GPS数据次数/数据长度:" + this.signArr[59] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .textAlign(TextAlign.Start) - }.justifyContent(FlexAlign.Start).padding({ left: 10 * this.ratio }).margin({ top: 8 * this.ratio }) - - Row() { - Text("方向盘类型:" + this.signArr[50] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .width('25%') - .textAlign(TextAlign.Start) - Text("按键数值:" + this.signArr[55] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .width('30%') - .textAlign(TextAlign.Start) - Text("GPS错误次数:" + this.signArr[60] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .textAlign(TextAlign.Start) - }.justifyContent(FlexAlign.Start).padding({ left: 10 * this.ratio }).margin({ top: 8 * this.ratio }) - - Row() { - Text("汽车类型:" + this.signArr[51] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .width('25%') - .textAlign(TextAlign.Start) - Text("GPS板卡类型:" + this.signArr[56] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .width('30%') - .textAlign(TextAlign.Start) - Text("已工作时长/设定的工作时长:" + this.signArr[61] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .textAlign(TextAlign.Start) - }.justifyContent(FlexAlign.Start).padding({ left: 10 * this.ratio }).margin({ top: 8 * this.ratio }) - - Row() { - Text("接口心跳:" + this.signArr[52] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .width('25%') - .textAlign(TextAlign.Start) - Text("GPS板卡软件版本:" + this.signArr[57] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .width('30%') - .textAlign(TextAlign.Start) - Text("改正数次数/改正数大小:" + this.signArr[58] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .textAlign(TextAlign.Start) - }.justifyContent(FlexAlign.Start).padding({ left: 10 * this.ratio }).margin({ top: 8 * this.ratio }) - - Row() { - Text("本机IP:" + this.signArr[53] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .width('25%') - .textAlign(TextAlign.Start) - Text("改正数数据长度*数据长度-基准站RTCM改正数类型:" + this.signArr[62] || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .textAlign(TextAlign.Start) - }.justifyContent(FlexAlign.Start).padding({ left: 10 * this.ratio }).margin({ top: 8 * this.ratio }) - } - .backgroundColor('#282828') - .width(this.ratio * 890) - .height(136 * this.ratio) - .margin({ left: 0 * this.ratio, top: 15 * this.ratio }) - - Row() { - Flex({ direction: FlexDirection.Column, wrap: FlexWrap.Wrap }) { - ForEach(this.sjxhColum, (item) => { - Column() { - Text(`${item.key}:${item.value}`) - .fontSize(14 * this.ratio) - .lineHeight(25 * this.ratio) - .fontColor('#fff') - }.height(25 * this.ratio).justifyContent(FlexAlign.Start).width('16%') - }) - } - - Column() { - Text('GPS坐标:').fontColor('#FFFFFF').fontSize(14 * this.ratio).margin({ bottom: 10 * this.ratio }) - Text('状态:' + this.signArr[83]).fontColor('#FFB433').fontSize(14 * this.ratio).height(18 * this.ratio) - Text('收星数:' + this.signArr[84]).fontColor('#FFB433').fontSize(14 * this.ratio).height(18 * this.ratio) - Text('海拔高:' + this.signArr[85]).fontColor('#FFB433').fontSize(14 * this.ratio).height(18 * this.ratio) - Text('高度差:' + this.signArr[86]).fontColor('#FFB433').fontSize(14 * this.ratio).height(18 * this.ratio) - Text('龄期:' + this.signArr[87]).fontColor('#FFB433').fontSize(14 * this.ratio).height(18 * this.ratio) - Text('维度因子:' + this.signArr[88]) - .fontColor('#FFB433') - .fontSize(14 * this.ratio) - .height(18 * this.ratio) - Text('经度因子:' + this.signArr[89]) - .fontColor('#FFB433') - .fontSize(14 * this.ratio) - .height(18 * this.ratio) - Text('航向角:' + this.signArr[90]).fontColor('#FFB433').fontSize(14 * this.ratio).height(18 * this.ratio) - Text('俯仰角:' + this.signArr[91]).fontColor('#FFB433').fontSize(14 * this.ratio).height(18 * this.ratio) - Text('航向角状态-收星数:' + this.signArr[92]) - .fontColor('#FFB433') - .fontSize(14 * this.ratio) - .height(18 * this.ratio) - Text('年月日:' + this.signArr[93]).fontColor('#FFB433').fontSize(14 * this.ratio).height(18 * this.ratio) - Text('时分秒:' + this.signArr[94]).fontColor('#FFB433').fontSize(14 * this.ratio).height(18 * this.ratio) - Text('经度:' + this.signArr[95]).fontColor('#FFB433').fontSize(14 * this.ratio).height(18 * this.ratio) - Text('纬度:' + this.signArr[96]).fontColor('#FFB433').fontSize(14 * this.ratio).height(18 * this.ratio) - Text('速度:' + ((Number((this.signArr[97]||0))*1.852).toFixed(2)).toString()).fontColor('#FFB433').fontSize(14 * this.ratio).height(18 * this.ratio) - } - .backgroundColor('#1A1A1A') - .width(170 * this.ratio) - .height(300 * this.ratio) - .position({ y: 0 * this.ratio, x: 720 * this.ratio }) - }.backgroundColor('#282828').width(this.ratio * 890).height(308 * this.ratio).margin({ top: 3 * this.ratio }) - } - .width(936 * this.ratio) - .height(480 * this.ratio) - .margin({ left: 10 * this.ratio }) - .padding({ left: 10 * this.ratio, right: 10 * this.ratio }) - .backgroundImage($r('app.media.km_open')) - .backgroundImageSize({ width: '100%', height: '100%' }) - .visibility(this.active == 0 ? Visibility.Visible : Visibility.None) - Column() { - Column() { - Text( this.msg || '0') - .fontColor('#FFF5E5') - .fontSize(14 * this.ratio) - .width('100%') - .textAlign(TextAlign.Start) - - } - .backgroundColor('#282828') - .width(this.ratio * 890) - .height(436 * this.ratio) - .margin({ left: 0 * this.ratio, top: 15 * this.ratio }) - - } - .width(936 * this.ratio) - .height(480 * this.ratio) - .margin({ left: 10 * this.ratio }) - .padding({ left: 10 * this.ratio, right: 10 * this.ratio }) - .backgroundImage($r('app.media.km_open')) - .backgroundImageSize({ width: '100%', height: '100%' }) - .visibility(this.active == 2 ? Visibility.Visible : Visibility.None) - Row() { - Flex({ direction: FlexDirection.Column }) { - Row() { - Row() { - Text('GPS').fontColor(this.gpsActive == 0 ? '#2D3C5A' : '#fff') - } - .width(316 / 2 * this.ratio) - .height(24 * this.ratio) - .backgroundColor(this.gpsActive == 0 ? '#fff' : '#1A1A1A') - .margin({ left: 10 * this.ratio, right: 10 * this.ratio }) - .justifyContent(FlexAlign.Center) - .onClick(() => { - this.gpsActive = 0 - }) - - }.margin({ top: 10 * this.ratio }) - - Flex({ direction: FlexDirection.Column }) { - ForEach(this.GPSColum, (item) => { - Column() { - Text(`${item.key}:${item.value}`) - .fontSize(12 * this.ratio) - .lineHeight(20 * this.ratio) - .fontColor('#fff') - }.height(20 * this.ratio).justifyContent(FlexAlign.Start).width('100%') - }) - } - } - .width(168 * this.ratio) - .height(380 * this.ratio) - .backgroundColor('#282828') - .margin({ top: 6 * this.ratio, left: 10 * this.ratio }) - - Row() { - RealTime({ - widthNumber: Math.floor(550 * this.ratio), - heightNumber: Math.floor(380 * this.ratio), - }) - } - .width(550 * this.ratio) - .height(380 * this.ratio) - .backgroundColor('#1A1A1A') - .margin({ top: 6 * this.ratio,}) - - } - .width(936 * this.ratio) - .height(420 * this.ratio) - .margin({ left: 10 * this.ratio }) - .padding({ left: 10 * this.ratio, right: 10 * this.ratio }) - .backgroundImage($r('app.media.km_open')) - .backgroundImageSize({ width: '100%', height: '100%' }) - .visibility(this.active == 1 ? Visibility.Visible : Visibility.None) - } - .width('100%') - .height('100%') - } - - } - - aboutToDisappear() { - clearInterval(this.interval) - } - - async aboutToAppear() { - const fileUtil = new FileUtil(globalThis.context) - const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt') - this.udplocalIp=JSON.parse(data).udplocalIp - this.ratio = this.ratio * (this.scaleNum || 1); - const that = this - const {showBack,getSignal} = this - - - if (showBack) { - this.ratio = 1.4 - globalThis.udpClient.onMessage_1&&globalThis.udpClient.onMessage_1((msg) => { - console.log('getUDPonMessage_1bysignDisplay0', msg) - if (msg) { - getSignal(msg) - } - }) - } else { - clearInterval(globalThis.signalTimer) - globalThis.signalTimer = setInterval(() => { - const msgStr = globalThis.msgStr - if (msgStr) { - getSignal(msgStr) - - } - }, 200) - } - } - - onPageShow() { - console.info('SURENJUN', 123) - - const getSignal = this.getSignal; - const that = this - const showBack = this.showBack; - if (showBack) { - globalThis.udpClient.onMessage_1&&globalThis.udpClient.onMessage_1((msg) => { - console.log('getUDPonMessage_1bysignDisplay2', msg) - - getSignal(msg) - }) - } else { - clearInterval(globalThis.signalTimer) - globalThis.signalTimer = setInterval(() => { - //TODO 临时方案 - const msgStr = globalThis.msgStr - getSignal(msgStr) - }, 200) - } - - } - - getSignal = (msg) => { - console.log('msgmsgmsg', msg) - const that = this; - that.msg = msg - const strachArr = msg.split(',') - if (strachArr[0] != '#DN_GD') { - return - } - this.signArr = strachArr - - for (let i = 0; i <= 12; i++) { - this.sjxhColum[i].value = this.signArr[i+2] - } - - this.sjxhColum[13].value = this.signArr[17] - this.sjxhColum[14].value = this.signArr[18] - this.sjxhColum[15].value = this.signArr[19] - this.sjxhColum[16].value = this.signArr[20] - this.sjxhColum[17].value = this.signArr[23] //车速 - this.sjxhColum[18].value = this.signArr[28] - this.sjxhColum[19].value = this.signArr[29] - this.sjxhColum[20].value = this.signArr[30] - this.sjxhColum[21].value = this.signArr[15] //NC - this.sjxhColum[22].value = this.signArr[16] //SA15 - this.sjxhColum[23].value = this.signArr[21] - this.sjxhColum[24].value = this.signArr[22] - this.sjxhColum[25].value = this.signArr[24] - this.sjxhColum[26].value = this.signArr[26] - this.sjxhColum[27].value = this.signArr[25] - this.sjxhColum[28].value = this.signArr[27] - this.sjxhColum[29].value = this.signArr[31] - this.sjxhColum[30].value = this.signArr[32] - this.sjxhColum[31].value = this.signArr[33] - this.sjxhColum[32].value = this.signArr[34] - this.sjxhColum[33].value = this.signArr[35] - for (let i = 34; i <= 46; i++) { - this.sjxhColum[i].value = this.signArr[i+2] - } - let t = 0 - // for (let i = 83; i <= 97; i++) { - this.GPSColum[14].value = ((Number((this.signArr[97]||0))*1.852).toFixed(2)).toString() - // t++ - // } - // for (let i = 83; i <= 97; i++) { - // this.GPSColum[t].value = this.signArr[i] - // t++ - // } - const str0=this.signArr[93].substr(0,2) - const str1=this.signArr[93].substr(2,2) - const str2=this.signArr[93].substr(4.2) - this.signArr[93]=str2+str1+str0 - this.signArr[53]=this.udplocalIp - this.sjxhColum = JSON.parse(JSON.stringify((this.sjxhColum))) - that.signArr = JSON.parse(JSON.stringify((this.signArr))) - that.GPSColum = JSON.parse(JSON.stringify((this.GPSColum))) - } - - outClick() { - } - - saveLog() { - - } -}