This commit is contained in:
lixiao 2024-09-10 17:04:06 +08:00
parent 7a3582481b
commit f459b8fdb7
5 changed files with 99 additions and 21 deletions

View File

@ -1,6 +1,6 @@
{
"app": {
"bundleName": "com.duolun.myapplication",
"bundleName": "com.duolun.ai.drive",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",

View File

@ -4,13 +4,13 @@
{
"name": "default",
"material": {
"certpath": "C:\\Users\\lixiao\\.ohos\\config\\openharmony\\auto_ohos_default_assistedDrive_com.duolun.myapplication.cer",
"storePassword": "0000001A78AD688CBC1DBFD79BF9FC921E8E1D6E1090159805708C96F8E01D4030A64244CF8703DF8818",
"certpath": "C:\\Users\\lixiao\\.ohos\\config\\openharmony\\auto_ohos_default_assistedDrive_com.duolun.ai.drive.cer",
"storePassword": "0000001BBDEED229409F7E26F917CD66E7524AD76F6AC0B0BAC7603950676F71FB0F364B3946BEE85B9B3C",
"keyAlias": "debugKey",
"keyPassword": "0000001A8E470AB8DD0263B1F5F7A0703880A31C127A26A78D5526164C5AD31D6E416B2A700555E56DCC",
"profile": "C:\\Users\\lixiao\\.ohos\\config\\openharmony\\auto_ohos_default_assistedDrive_com.duolun.myapplication.p7b",
"keyPassword": "0000001B5FF518BBD3340B667612C1F4365D481D19C923236F4780B008C5518DBCF913C5D67B3EBAAE49CE",
"profile": "C:\\Users\\lixiao\\.ohos\\config\\openharmony\\auto_ohos_default_assistedDrive_com.duolun.ai.drive.p7b",
"signAlg": "SHA256withECDSA",
"storeFile": "C:\\Users\\lixiao\\.ohos\\config\\openharmony\\auto_ohos_default_assistedDrive_com.duolun.myapplication.p12"
"storeFile": "C:\\Users\\lixiao\\.ohos\\config\\openharmony\\auto_ohos_default_assistedDrive_com.duolun.ai.drive.p12"
}
}
],

View File

@ -22,6 +22,7 @@ import { LogHelper } from '../utils/LogHelper';
import util from '@ohos.util';
import { CarInfo, GpsInfo, parseCar, parseGps } from '../utils/udp/Gps';
import ActiveUdp from '../utils/udp/AvtiveUdp';
import ethernet from '@ohos.net.ethernet';
// 直角转弯 (0, 0) (0, 1) ...
@ -88,14 +89,15 @@ struct Index {
private carStatus: number = 0
async aboutToAppear() {
this.init()
}
async init() {
try {
await this.initWireControlUDP()
await this.initPlatformUDP()
await this.initAudioPlayer()
// 激活
await ActiveUdp.active()
await this.initBackMachineUDP()
// await this.initWireControlUDP()
// await this.initPlatformUDP()
// await this.initAudioPlayer()
// await this.initBackMachineUDP()
await getConfigFile().then(([fieldModel, carModel, line, lib, teachPoint, teachPointParams, basePoint]) => {
this.fieldModel = fieldModel
this.carModel = carModel
@ -148,10 +150,32 @@ struct Index {
message: JSON.stringify(err?.message || err),
duration: 3000
})
LogHelper.E("View", JSON.stringify(err?.message || err))
LogHelper.E("View", err?.message || JSON.stringify(err))
}
}
// 设置本地网络
async setLocalNetWork() {
ethernet.setIfaceConfig("eth0", {
ipAddr: "192.168.7.170",
mode: ethernet.IPSetMode.STATIC,
route: '0.0.0.0',
gateway: '192.168.7.1',
netMask: '255.255.255.0',
dnsServers: '8.8.8.8'
}).then(() => {
promptAction.showToast({
message: "设置本地网络成功",
duration: 3000
})
}).catch((err) => {
promptAction.showToast({
message: "设置本地网络失败\n" + err?.message || JSON.stringify(err),
duration: 3000
})
})
}
// 播放语音
async playAudio(project: number, idx: number) {
try {
@ -166,7 +190,6 @@ struct Index {
})
LogHelper.E("View", JSON.stringify(err?.message || err))
}
}
// 初始化语音播放器
@ -182,10 +205,6 @@ struct Index {
this.simulatorUdpClient = new SimulatorUdpClient("0.0.0.0", 8990, "88.22.10.118", 9001)
try {
await this.simulatorUdpClient.bindUdp()
// this.simulatorUdpClient.heart()
// setInterval(() => {
// this.simulatorUdpClient.uploadPosition(new GpsInfo(), new CarInfo())
// }, 1000)
this.simulatorUdpClient.onMessage(({type, data = [] }: MessageCallBackParams) => {
if (type === CommandType.Start) {
let path = this.paths.findIndex(item => {
@ -355,6 +374,54 @@ struct Index {
})
}.backgroundColor('rgba(228, 229, 233, 0.7)').borderRadius(10)
}.width("100%").height("100%").padding(24).alignItems(VerticalAlign.Top)
Column() {
Button("设置本地网络", { type: ButtonType.Normal })
.backgroundColor(0xffffff)
.fontColor(0x557685)
.borderRadius(8)
.shadow({
offsetX: 3,
offsetY: 3,
color: 0xf1f1f1,
radius: 10
})
.margin({ bottom: 10 })
.onClick(() => {
this.setLocalNetWork()
})
Button("激活后置机", { type: ButtonType.Normal })
.backgroundColor(0xffffff)
.fontColor(0x557685)
.borderRadius(8)
.shadow({
offsetX: 3,
offsetY: 3,
color: 0xf1f1f1,
radius: 10
})
.margin({ bottom: 10 })
.onClick(() => {
ActiveUdp.active()
})
Button("重新初始化程序", { type: ButtonType.Normal })
.backgroundColor(0xffffff)
.fontColor(0x557685)
.borderRadius(8)
.shadow({
offsetX: 3,
offsetY: 3,
color: 0xf1f1f1,
radius: 10
})
.margin({ bottom: 10 })
.onClick(() => {
this.init()
})
}.position({
x: 0,
y: "80%"
}).padding(10).alignItems(HorizontalAlign.Start)
}.height('100%')
.width("100%")
}

View File

@ -3,7 +3,7 @@ import util from '@ohos.util'
import http from '@ohos.net.http'
import { LogHelper } from '../LogHelper'
import promptAction from '@ohos.promptAction'
import deviceManager from '@ohos.distributedHardware.deviceManager';
import ethernet from '@ohos.net.ethernet';
function int2byte(integer: number) {
@ -86,6 +86,10 @@ export default class ActiveUdp {
this.callback = (message) => {
resolve(message)
}
promptAction.showToast({
message: "正在向后置机请求设备编号",
duration: 2000
})
this.udp.send({
address: {
address: "192.168.7.124",
@ -111,7 +115,7 @@ export default class ActiveUdp {
xmlData += "<branchSchoolId>1</branchSchoolId>"
xmlData += "</head>"
xmlData += "<body>"
xmlData += `<deviceNo>${""}</deviceNo>`
xmlData += `<deviceNo>123456789000000</deviceNo>`
xmlData += "<trainType>2</trainType>"
xmlData += "<minute>12800</minute>"
xmlData += `<key>${res}</key>`
@ -131,6 +135,10 @@ export default class ActiveUdp {
this.callback = (message) => {
resolve(message)
}
promptAction.showToast({
message: "正在激活后置机",
duration: 2000
})
this.udp.send({
address: {
address: "192.168.7.124",
@ -147,6 +155,7 @@ export default class ActiveUdp {
message: "激活成功",
duration: 2000
})
this.udp.close()
})
.catch(err => {
promptAction.showToast({

View File

@ -34,7 +34,9 @@
}
],
"requestPermissions": [
{ "name": "ohos.permission.INTERNET" }
{ "name": "ohos.permission.INTERNET" },
{ "name": "ohos.permission.CONNECTIVITY_INTERNAL" },
{ "name": "ohos.permission.ACCESS_SERVICE_DM" }
]
}
}