This commit is contained in:
lixiao 2024-09-05 17:19:12 +08:00
parent e5eb8eb7b7
commit 7e69ada2d2

View File

@ -87,6 +87,10 @@ struct Index {
async aboutToAppear() { async aboutToAppear() {
try { try {
await this.initWireControlUDP()
await this.initPlatformUDP()
await this.initAudioPlayer()
await this.initBackMachineUDP()
await getConfigFile().then(([fieldModel, carModel, line, lib, teachPoint, teachPointParams, basePoint]) => { await getConfigFile().then(([fieldModel, carModel, line, lib, teachPoint, teachPointParams, basePoint]) => {
this.fieldModel = fieldModel this.fieldModel = fieldModel
this.carModel = carModel this.carModel = carModel
@ -102,7 +106,27 @@ struct Index {
await nativeLogCallback((message: string, _: number) => { await nativeLogCallback((message: string, _: number) => {
LogHelper.I("NativeSDK", "[Log Callback]: ", message) LogHelper.I("NativeSDK", "[Log Callback]: ", message)
}) })
await registerControlCallback(() => { await registerControlCallback((fxp: number, move: number) => {
if (fxp > 0) {
this.outWireControl.rightWheel(fxp)
} else {
this.outWireControl.leftWheel(fxp)
}
switch (move) {
case -1000:
break;
case -1:
this.outWireControl.moveDown()
break;
case 0:
this.outWireControl.moveStop()
break;
case 1:
this.outWireControl.moveUp()
break;
default:
break;
}
LogHelper.I("NativeSDK", "[Control Callback]: ") LogHelper.I("NativeSDK", "[Control Callback]: ")
}) })
await registerSoundCallback(() => { await registerSoundCallback(() => {
@ -110,11 +134,6 @@ struct Index {
}) })
await setImageSize(500, 300) await setImageSize(500, 300)
await setConfigFile(this.basePoint, this.fieldModel, this.teachPoint, this.teachPointParams, this.carModel, this.line, this.lib) await setConfigFile(this.basePoint, this.fieldModel, this.teachPoint, this.teachPointParams, this.carModel, this.line, this.lib)
this.outWireControl = new OutWireControl()
await this.outWireControl.init("192.168.7.181", 30021)
await this.initPlatformUDP()
await this.initAudioPlayer()
await this.initBackMachineUDP()
} catch (err) { } catch (err) {
promptAction.showToast({ promptAction.showToast({
message: JSON.stringify(err?.message || err), message: JSON.stringify(err?.message || err),
@ -145,9 +164,9 @@ struct Index {
try { try {
await this.simulatorUdpClient.bindUdp() await this.simulatorUdpClient.bindUdp()
// this.simulatorUdpClient.heart() // this.simulatorUdpClient.heart()
setInterval(() => { // setInterval(() => {
this.simulatorUdpClient.uploadPosition(new GpsInfo(), new CarInfo()) // this.simulatorUdpClient.uploadPosition(new GpsInfo(), new CarInfo())
}, 1000) // }, 1000)
this.simulatorUdpClient.onMessage(({type, data = [] }: MessageCallBackParams) => { this.simulatorUdpClient.onMessage(({type, data = [] }: MessageCallBackParams) => {
if (type === CommandType.Start) { if (type === CommandType.Start) {
let path = this.paths.findIndex(item => { let path = this.paths.findIndex(item => {
@ -194,6 +213,12 @@ struct Index {
} }
} }
// 初始化车机控制UDP
async initWireControlUDP() {
this.outWireControl = new OutWireControl()
await this.outWireControl.init("192.168.7.181", 30021)
}
// 上方按钮点击 // 上方按钮点击
onConfirm() { onConfirm() {
if (this.status === Status.Idle) { if (this.status === Status.Idle) {
@ -202,9 +227,12 @@ struct Index {
this.simulatorUdpClient?.sendPID26(CommandType.Start) this.simulatorUdpClient?.sendPID26(CommandType.Start)
selectLineAndLib(this.paths[this.currentPath].properties.id, this.libraries[this.currentLibrary].properties.id) selectLineAndLib(this.paths[this.currentPath].properties.id, this.libraries[this.currentLibrary].properties.id)
this.status = Status.Running this.status = Status.Running
this.outWireControl.apaStart()
} else { } else {
this.simulatorUdpClient?.sendPID26(CommandType.Stop) this.simulatorUdpClient?.sendPID26(CommandType.Stop)
this.status = Status.Idle this.status = Status.Idle
this.outWireControl.moveStop()
this.outWireControl.apaStop()
} }
} }