Compare commits
	
		
			4 Commits
		
	
	
		
			79c8cba21f
			...
			291e75c150
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 291e75c150 | |||
| 50b63e471d | |||
| f9beb54a28 | |||
| f420a9512f | 
| @ -3,7 +3,7 @@ import { getSyncData } from '../service/initable'; | ||||
| import hilog from '@ohos.hilog'; | ||||
| import FileUtil from '../../common/utils/File' | ||||
| import { GlobalConfig } from '../../config/index' | ||||
| 
 | ||||
| const TAG = 'socketTag[TcpDemo.TcpClient]' | ||||
| export async function getTCP(flag=false) { | ||||
|   globalThis.getCloseTcp=true | ||||
|   const fileUtil = new FileUtil(globalThis.context) | ||||
| @ -35,10 +35,16 @@ export async function getTCP(flag=false) { | ||||
|           console.log('ttttttt00') | ||||
| 
 | ||||
|           clearInterval(globalThis.intervalSendmsg) | ||||
|           globalThis.intervalSendmsg=setInterval(()=>{ | ||||
|           globalThis.intervalSendmsg=setInterval(async()=>{ | ||||
|             console.log('getCloseTcp',globalThis.carInfo.carNo) | ||||
|             if(!globalThis.getCloseTcp){ | ||||
|               globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
 | ||||
|               await globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
 | ||||
|               globalThis.tcpStep+=1 | ||||
|               if(globalThis.tcpStep>30){ | ||||
|                 console.log(TAG,'tcp重连开始') | ||||
|                 globalThis.tcpStep=0 | ||||
|                 getTCP() | ||||
|               } | ||||
|             } | ||||
|           },1000/3) | ||||
|           globalThis.TcpClient.onError((val) => { | ||||
| @ -68,10 +74,16 @@ export async function getTCP(flag=false) { | ||||
|       console.log('ttttttt12') | ||||
| 
 | ||||
|       clearInterval(globalThis.intervalSendmsg) | ||||
|       globalThis.intervalSendmsg=setInterval(()=>{ | ||||
|       globalThis.intervalSendmsg=setInterval(async()=>{ | ||||
|         // console.log('getCloseTcp',globalThis.getCloseTcp)
 | ||||
|         if(!globalThis.getCloseTcp){ | ||||
|           globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
 | ||||
|           await globalThis.TcpClient.sendMsg(globalThis.carInfo.carNo) //1002
 | ||||
|           globalThis.tcpStep+=1 | ||||
|           if(globalThis.tcpStep>30){ | ||||
|             console.log(TAG,'tcp重连开始') | ||||
|             globalThis.tcpStep=0 | ||||
|             getTCP() | ||||
|           } | ||||
|         } | ||||
|       },1000/3) | ||||
|       globalThis.TcpClient.onError((val) => { | ||||
|  | ||||
| @ -9,7 +9,6 @@ import appRecovery from '@ohos.app.ability.appRecovery'; | ||||
| import power from '@ohos.power'; | ||||
| import preferences from '@ohos.data.preferences'; | ||||
| 
 | ||||
| 
 | ||||
| export const gpsConfig = [ | ||||
|   { label: "差分状态", prop: "cfzt" }, | ||||
|   { label: "经纬度收星数", prop: "sxs" }, | ||||
| @ -71,6 +70,18 @@ enum EventCode { | ||||
|   Reply | ||||
| } | ||||
| 
 | ||||
| enum ButtonEventType { | ||||
|   Single, | ||||
|   Double, | ||||
|   LongPress | ||||
| } | ||||
| 
 | ||||
| interface ToolEvent<T = any> { | ||||
|   code: EventCode, | ||||
|   data: T | ||||
|   id?: string | ||||
| } | ||||
| 
 | ||||
| interface FileInfo { | ||||
|   fileName: string | ||||
|   lastUpdateTime: string | ||||
| @ -85,6 +96,13 @@ interface PlatformEvent<T = any> { | ||||
|   data: T | ||||
| } | ||||
| 
 | ||||
| interface ButtonParams { | ||||
|   type: ButtonEventType | ||||
|   button: number | ||||
|   page: number | ||||
| } | ||||
| 
 | ||||
| export  type CommandCallback = (button: number, reply: (result: number) => void) => void | ||||
| 
 | ||||
| const Tag = "[websocket]" | ||||
| const SystemLogDir = "/data/log/hilog" | ||||
| @ -208,6 +226,10 @@ export class RemoteToolWebsocket { | ||||
|     page: number, | ||||
|     cb: () => void | ||||
|   }> = [] | ||||
|   private onButtonCallback: Array<{ | ||||
|     page: number, | ||||
|     cb: CommandCallback | ||||
|   }> = [] | ||||
|   public isStart: boolean = false | ||||
|   private isRegister: boolean = false | ||||
|   private context: common.UIAbilityContext | ||||
| @ -374,6 +396,34 @@ export class RemoteToolWebsocket { | ||||
|           this.sendReply(this.serialNumber, data.eventType) | ||||
|           break | ||||
|         case PlatFormEventType.ToolCommand: | ||||
|           let command = JSON.parse(data.data) as ToolEvent | ||||
|           switch (command.code) { | ||||
|             case EventCode.Data: | ||||
|               break | ||||
|             case EventCode.Button: | ||||
|               let button = JSON.parse(command.data) as ButtonParams | ||||
|               this.onButtonCallback.forEach(item => { | ||||
|                 const reply = (result: number) => { | ||||
|                   this.sendReply(this.serialNumber, PlatFormEventType.SyncData, JSON.stringify({ | ||||
|                     code: EventCode.Reply, | ||||
|                     data: JSON.stringify(result), | ||||
|                     id: command.id | ||||
|                   } as ToolEvent)) | ||||
|                 } | ||||
|                 if (item.page === button.page) { | ||||
|                   item.cb(button.button, reply) | ||||
|                 } | ||||
|               }) | ||||
|               break | ||||
|             case EventCode.Router: | ||||
|               break | ||||
|             case EventCode.Function: | ||||
|               break | ||||
|             case EventCode.Reply: | ||||
|               break | ||||
|             default: | ||||
|               return | ||||
|           } | ||||
|           break | ||||
|         default: | ||||
|           console.warn("Unknown event type:", data.eventType); | ||||
| @ -640,6 +690,17 @@ export class RemoteToolWebsocket { | ||||
|   } | ||||
| 
 | ||||
|   offStart(page: number) { | ||||
|     this.onStartCallback = this.onStartCallback.filter(item => item.page != page) | ||||
|     this.onStartCallback = this.onStartCallback.filter(item => item.page !== page) | ||||
|   } | ||||
| 
 | ||||
|   onButton(cb: CommandCallback, page: number) { | ||||
|     this.onButtonCallback.push({ | ||||
|       page, | ||||
|       cb | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
|   offButton(page: number) { | ||||
|     this.onButtonCallback = this.onButtonCallback.filter(item => item.page !== page) | ||||
|   } | ||||
| } | ||||
| @ -148,13 +148,12 @@ export default class TcpClient { | ||||
|           this.tcpSendNum=0 | ||||
|           return | ||||
|         } | ||||
|         globalThis.getCloseTcp=true | ||||
|         console.log(`${TAG} TCPsend error ${JSON.stringify(err)}`) | ||||
|         // this.writeLog({
 | ||||
|         //   time:dateFormat(new Date()),
 | ||||
|         //   message: `${TAG} TCPsend error ${JSON.stringify(err)}`,
 | ||||
|         // })
 | ||||
|         reslove(false) | ||||
|         reject(false) | ||||
|       }); | ||||
|     }) | ||||
|   } | ||||
| @ -165,6 +164,7 @@ export default class TcpClient { | ||||
|       //   time:dateFormat(new Date()),
 | ||||
|       //   PLC:`${TAG} Tcponmessage`,
 | ||||
|       // })
 | ||||
|       globalThis.tcpStep=0 | ||||
|       globalThis.tcpUdpError = false | ||||
|       if (value) { | ||||
|         callback && callback(value.message) | ||||
|  | ||||
| @ -38,6 +38,7 @@ export default class EntryAbility extends UIAbility { | ||||
| 
 | ||||
|   async onWindowStageCreate(windowStage: window.WindowStage) { | ||||
|     hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); | ||||
|     globalThis.tcpStep=0 | ||||
| 
 | ||||
|     globalThis.carInfo = {} | ||||
|     globalThis.examinerInfo = {} | ||||
| @ -63,11 +64,15 @@ export default class EntryAbility extends UIAbility { | ||||
|     globalThis.pathDir = this.context.filesDir; | ||||
|     globalThis.context = this.context; | ||||
|     globalThis.isJudgeInitBool = false | ||||
|     console.info('jiangsong globalThis.pathDir = ' + globalThis.pathDir); | ||||
|     // this.requestPermission(this.context) | ||||
|     // this.featureAbilityAuth() | ||||
| 
 | ||||
|     const windowClass = await windowStage.getMainWindow(); | ||||
|     globalThis.windowClass = windowClass | ||||
|     await windowClass.setWindowLayoutFullScreen(true) | ||||
|     await windowClass.setWindowSystemBarEnable([]) | ||||
|     // await windowClass.setWindowLayoutFullScreen(true) | ||||
|     // await windowClass.setWindowSystemBarEnable([]) //全屏 | ||||
|     await windowClass.setWindowSystemBarEnable(['navigation']) | ||||
| 
 | ||||
|     windowStage.loadContent('pages/Index', (err, data) => { | ||||
|       if (err.code) { | ||||
|  | ||||
| @ -19,7 +19,7 @@ import { delPic } from '../common/service/videoService'; | ||||
| import imageBtn from './compontents/imageBtn'; | ||||
| import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements'; | ||||
| import { updateModelAndCar } from '../common/autoUpdate/index' | ||||
| import { RemoteToolWebsocket } from '../common/utils/RemotetoolWebsocket'; | ||||
| import { CommandCallback, RemoteToolWebsocket } from '../common/utils/RemotetoolWebsocket'; | ||||
| import { UsbUtils } from '../common/utils/UsbUtils'; | ||||
| 
 | ||||
| 
 | ||||
| @ -30,7 +30,7 @@ struct Index { | ||||
|   @State version: string = '' | ||||
|   @State url: string = '' | ||||
|   @State hasAuth: boolean = false; | ||||
|   @State dialogVisiable: boolean = false; | ||||
|   @State dialogVisible: boolean = false; | ||||
|   @State isSingle: boolean = false; | ||||
|   @State deviceId: string = ''; | ||||
|   @State angle: number = 0 | ||||
| @ -63,6 +63,15 @@ struct Index { | ||||
|   private context = getContext(this) as common.UIAbilityContext; | ||||
|   private remoteToolWebsocket: RemoteToolWebsocket = new RemoteToolWebsocket() | ||||
|   private usbUtils: UsbUtils = new UsbUtils(this.context) | ||||
|   private onButtonCallback: CommandCallback = (button, reply) => { | ||||
|     switch (button) { | ||||
|       case 1: | ||||
|         this.onNetWork(reply) | ||||
|         break | ||||
|       default: | ||||
|         return | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   @Styles | ||||
|   commStyle(){ | ||||
| @ -91,7 +100,7 @@ struct Index { | ||||
|             Image($r('app.media.btn_back')).width('14.4%').height('12.2%') | ||||
|               .onClick(() => { | ||||
| 
 | ||||
|                 this.dialogVisiable = true | ||||
|                 this.dialogVisible = true | ||||
|               }) | ||||
|           } | ||||
|         } | ||||
| @ -104,40 +113,8 @@ struct Index { | ||||
|           if (!this.isSingle) { | ||||
|             imageBtn({ btnWidth: '28%', btnHeight: '71%', imgSrc: $r('app.media.index_lw') }) | ||||
|               .margin({ left: 80 * globalThis.ratio }) | ||||
|               .onClick(async () => { | ||||
| 
 | ||||
|                 if (this.loading) { | ||||
| 
 | ||||
|                   return | ||||
|                 } | ||||
|                 setTimeout(() => { | ||||
|                   this.angle = 360 | ||||
|                 }, 1000) | ||||
|                 this.angle = 0 | ||||
|                 if (!globalThis.timeInfo) { | ||||
|                   globalThis.type = '1' | ||||
|                   globalThis.title = '时间同步接口连接失败' | ||||
|                   this.errorDialog.open() | ||||
|                   promptAction.showToast({ | ||||
|                     message: `时间同步接口连接失败`, | ||||
|                     duration: 3000 | ||||
|                   }); | ||||
|                   this.loading = false | ||||
|                   return | ||||
|                 } | ||||
|                 if (!globalThis.carInfo) { | ||||
|                   promptAction.showToast({ | ||||
|                     message: `车辆信息接口获取失败`, | ||||
|                     duration: 3000 | ||||
|                   }); | ||||
|                   globalThis.type = '1' | ||||
|                   globalThis.title = '车辆信息接口获取失败' | ||||
|                   this.errorDialog.open() | ||||
|                   this.loading = false | ||||
|                   return | ||||
|                 } | ||||
|                 this.testXMLToJSONInWorker() | ||||
| 
 | ||||
|               .onClick(() => { | ||||
|                 this.onNetWork() | ||||
|               }) | ||||
|           } | ||||
|           if (this.isSingle) { | ||||
| @ -247,8 +224,7 @@ struct Index { | ||||
|         .margin({ bottom: 10 }) | ||||
|       } | ||||
| 
 | ||||
|       // | ||||
|       if (this.dialogVisiable) { | ||||
|       if (this.dialogVisible) { | ||||
|         Flex({ justifyContent: FlexAlign.Center }) { | ||||
|           Text('确认是否退出应用') | ||||
|             .fontSize(28 * this.ratio * this.dialogRatio) | ||||
| @ -262,7 +238,7 @@ struct Index { | ||||
|             } | ||||
|             .commStyle() | ||||
|             .onClick(() => { | ||||
|               this.dialogVisiable = false | ||||
|               this.dialogVisible = false | ||||
| 
 | ||||
|             }).margin({ right: 10 * this.ratio }) | ||||
| 
 | ||||
| @ -312,7 +288,6 @@ struct Index { | ||||
|         .backgroundColor('#E6E3DF') | ||||
|         .borderRadius(19 * globalThis.ratio) | ||||
|       } | ||||
| 
 | ||||
|       if (this.loading) { | ||||
|         Column() { | ||||
|           Image($r('app.media.open_loading')) | ||||
| @ -353,13 +328,11 @@ struct Index { | ||||
|   } | ||||
| 
 | ||||
|   async aboutToAppear() { | ||||
| 
 | ||||
|     console.log('diyidiy') | ||||
| 
 | ||||
|     this.remoteToolWebsocket.onButton(this.onButtonCallback, 1) | ||||
|     this.avPlayer = new VoiceAnnounce(); | ||||
|     this.initParamFlag = false | ||||
|     this.delLoading = false | ||||
|     this.dialogVisiable = false | ||||
|     this.dialogVisible = false | ||||
|     this.angle = 0 | ||||
|     this.loading = false | ||||
|     globalThis.lsh = '1111111111111' | ||||
| @ -386,15 +359,46 @@ struct Index { | ||||
|   } | ||||
| 
 | ||||
|   aboutToDisappear() { | ||||
|     // this.vocObj && this.vocObj.releasePlayer() | ||||
|     this.remoteToolWebsocket.offButton(1) | ||||
|   } | ||||
| 
 | ||||
|   async testXMLToJSONInWorker() { | ||||
|   onNetWork(cb?: Function) { | ||||
|     if (this.loading) { | ||||
|       return | ||||
|     } | ||||
|     setTimeout(() => { | ||||
|       this.angle = 360 | ||||
|     }, 1000) | ||||
|     this.angle = 0 | ||||
|     if (!globalThis.timeInfo) { | ||||
|       globalThis.type = '1' | ||||
|       globalThis.title = '时间同步接口连接失败' | ||||
|       this.errorDialog.open() | ||||
|       promptAction.showToast({ | ||||
|         message: `时间同步接口连接失败`, | ||||
|         duration: 3000 | ||||
|       }); | ||||
|       this.loading = false | ||||
|       return | ||||
|     } | ||||
|     if (!globalThis.carInfo) { | ||||
|       promptAction.showToast({ | ||||
|         message: `车辆信息接口获取失败`, | ||||
|         duration: 3000 | ||||
|       }); | ||||
|       globalThis.type = '1' | ||||
|       globalThis.title = '车辆信息接口获取失败' | ||||
|       this.errorDialog.open() | ||||
|       this.loading = false | ||||
|       return | ||||
|     } | ||||
|     this.testXMLToJSONInWorker(cb) | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
|   async testXMLToJSONInWorker(cb?: Function) { | ||||
|     if (this.loading) { | ||||
|       return | ||||
|     } | ||||
|     const param = { | ||||
|       carId: globalThis.carInfo?.carId, | ||||
|       examinationRoomId: globalThis.carInfo?.examinationRoomId, | ||||
| @ -448,12 +452,14 @@ struct Index { | ||||
|             } | ||||
|             if (sys.v_no === '824' && decodeURIComponent(sys.v_value) == '0') { | ||||
|               // this.Param612Str= decodeURIComponent(sys.v_value) | ||||
|               cb(1) | ||||
|               router.pushUrl({ | ||||
|                 url: 'pages/CarCheck', | ||||
|                 params: { | ||||
|                   'fromIndex': true | ||||
|                 } | ||||
|               }, router.RouterMode.Single) | ||||
| 
 | ||||
|             } else { | ||||
|               router.pushUrl({ | ||||
|                 url: 'pages/ExaminerLogin', | ||||
| @ -463,6 +469,8 @@ struct Index { | ||||
|         }); | ||||
| 
 | ||||
|       } | ||||
|     }).catch(() => { | ||||
|       cb(0) | ||||
|     }) | ||||
|   } | ||||
| 
 | ||||
| @ -482,7 +490,7 @@ struct Index { | ||||
|       carNo: globalThis.carInfo.carNo, | ||||
|       placeId: globalThis.carInfo.examinationRoomId | ||||
|     } | ||||
|     // globalThis.udpClient2.initHeartSendMsg(param,this.context) | ||||
|      | ||||
|     if (globalThis.udpClient2.getStatus()) { | ||||
|       globalThis.udpClient2.sendMsgExt(param, this.context) | ||||
|     } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user