From 7cabbbd29a977269695562170a93b189ffe33908 Mon Sep 17 00:00:00 2001 From: lixiao <932184220@qq.com> Date: Wed, 4 Sep 2024 15:28:59 +0800 Subject: [PATCH] cpp --- entry/src/main/cpp/sdk/api/include/JudgeSdk.h | 2 +- entry/src/main/cpp/sdk/api/js/JSApiBridge.cpp | 6 +- entry/src/main/cpp/sdk/api/js/JSApiBridge.h | 2 +- .../main/cpp/sdk/api/platform/JudgeSdk.cpp | 8 +- .../cpp/sdk/assistdrive/AutomaticService.cpp | 2 +- .../cpp/sdk/assistdrive/AutomaticService.h | 2 +- .../cpp/sdk/assistdrive/IAutomaticInterface.h | 2 +- .../cpp/sdk/assistdrive/IAutomaticService.h | 2 +- entry/src/main/ets/pages/Index.ets | 143 +++++---- entry/src/main/ets/utils/LogHelper.ts | 6 +- entry/src/main/ets/utils/Store.ets | 4 +- entry/src/main/ets/utils/native/NativeSDK.ets | 230 +++++++++++++-- .../src/main/ets/utils/native/NativeUtils.ets | 15 +- .../main/ets/utils/simulator/UdpClient.ets | 14 +- entry/src/main/ets/utils/udp/UdpClient.ets | 12 +- .../ets/utils/wireControl/WireControl.ets | 2 - .../rawfile/config/duolun/aiconfig.json | 277 ++++++++++++++++++ .../rawfile/config/simulator/aiconfig.json | 277 ++++++++++++++++++ 18 files changed, 891 insertions(+), 115 deletions(-) create mode 100644 entry/src/main/resources/rawfile/config/duolun/aiconfig.json create mode 100644 entry/src/main/resources/rawfile/config/simulator/aiconfig.json diff --git a/entry/src/main/cpp/sdk/api/include/JudgeSdk.h b/entry/src/main/cpp/sdk/api/include/JudgeSdk.h index 82beb21..ff2437e 100644 --- a/entry/src/main/cpp/sdk/api/include/JudgeSdk.h +++ b/entry/src/main/cpp/sdk/api/include/JudgeSdk.h @@ -273,7 +273,7 @@ JUDGE_SDK_API int JUDGE_SDK_METHOD autoServiceSetBasePoint(const char* data, int * 参数: data: 场地模型信息, json字符串; length: 字符串长度 * 返回值: 调用执行结果错误码, 0: 成功, 其他: 失败 */ -JUDGE_SDK_API int JUDGE_SDK_METHOD autoServiceSetFeildModel(const char* data, int length); +JUDGE_SDK_API int JUDGE_SDK_METHOD autoServiceSetFieldModel(const char* data, int length); /** * 说明: 设置教学点信息 diff --git a/entry/src/main/cpp/sdk/api/js/JSApiBridge.cpp b/entry/src/main/cpp/sdk/api/js/JSApiBridge.cpp index 1253e48..d38dcf2 100644 --- a/entry/src/main/cpp/sdk/api/js/JSApiBridge.cpp +++ b/entry/src/main/cpp/sdk/api/js/JSApiBridge.cpp @@ -482,9 +482,9 @@ JS_JUDGE_FUN_IMPL(autoServiceSetBasePoint) return createErrorCode(env, code); } -JS_JUDGE_FUN_IMPL(autoServiceSetFeildModel) +JS_JUDGE_FUN_IMPL(autoServiceSetFieldModel) { - logdebug("call js_autoServiceSetFeildModel"); + logdebug("call js_autoServiceSetFieldModel"); size_t argc = 2; napi_value args[2] = {nullptr}; @@ -500,7 +500,7 @@ JS_JUDGE_FUN_IMPL(autoServiceSetFeildModel) return createErrorCode(env, errorNapiArgType); } - int code = AutomaticService::autoServiceSetFeildModel(data.c_str(), data.length()); + int code = AutomaticService::autoServiceSetFieldModel(data.c_str(), data.length()); return createErrorCode(env, code); } diff --git a/entry/src/main/cpp/sdk/api/js/JSApiBridge.h b/entry/src/main/cpp/sdk/api/js/JSApiBridge.h index 72457c6..f68d58b 100644 --- a/entry/src/main/cpp/sdk/api/js/JSApiBridge.h +++ b/entry/src/main/cpp/sdk/api/js/JSApiBridge.h @@ -42,7 +42,7 @@ public: JS_JUDGE_FUN_DECL(autoServiceInit); JS_JUDGE_FUN_DECL(autoServiceSetBasePoint); - JS_JUDGE_FUN_DECL(autoServiceSetFeildModel); + JS_JUDGE_FUN_DECL(autoServiceSetFieldModel); JS_JUDGE_FUN_DECL(autoServiceSetTeachPointInfo); JS_JUDGE_FUN_DECL(autoServiceSetTeachPointParam); JS_JUDGE_FUN_DECL(autoServiceSetCarModel); diff --git a/entry/src/main/cpp/sdk/api/platform/JudgeSdk.cpp b/entry/src/main/cpp/sdk/api/platform/JudgeSdk.cpp index 3fadc50..91361b8 100644 --- a/entry/src/main/cpp/sdk/api/platform/JudgeSdk.cpp +++ b/entry/src/main/cpp/sdk/api/platform/JudgeSdk.cpp @@ -29,7 +29,7 @@ JS_JUDGE_API_JOIN(examJudgeMapImage); JS_JUDGE_API_JOIN(examJudgeMapImageSetCallback); JS_JUDGE_API_JOIN(autoServiceInit); JS_JUDGE_API_JOIN(autoServiceSetBasePoint); -JS_JUDGE_API_JOIN(autoServiceSetFeildModel); +JS_JUDGE_API_JOIN(autoServiceSetFieldModel); JS_JUDGE_API_JOIN(autoServiceSetTeachPointInfo); JS_JUDGE_API_JOIN(autoServiceSetTeachPointParam); JS_JUDGE_API_JOIN(autoServiceSetCarModel); @@ -72,7 +72,7 @@ static napi_value JS_JUDGE_MODULE_EXPORT(napi_env env, napi_value exports) JS_JUDGE_CAT_DESC(examJudgeMapImageSetCallback), JS_JUDGE_CAT_DESC(autoServiceInit), JS_JUDGE_CAT_DESC(autoServiceSetBasePoint), - JS_JUDGE_CAT_DESC(autoServiceSetFeildModel), + JS_JUDGE_CAT_DESC(autoServiceSetFieldModel), JS_JUDGE_CAT_DESC(autoServiceSetTeachPointInfo), JS_JUDGE_CAT_DESC(autoServiceSetTeachPointParam), JS_JUDGE_CAT_DESC(autoServiceSetCarModel), @@ -378,9 +378,9 @@ JUDGE_SDK_API int autoServiceSetBasePoint(const char* data, int length) return FactoryAutomaticApi->autoServiceSetBasePoint(data, length); } -JUDGE_SDK_API int autoServiceSetFeildModel(const char* data, int length) +JUDGE_SDK_API int autoServiceSetFieldModel(const char* data, int length) { - return FactoryAutomaticApi->autoServiceSetFeildModel(data, length); + return FactoryAutomaticApi->autoServiceSetFieldModel(data, length); } JUDGE_SDK_API int autoServiceSetTeachPointInfo(const char* data, int length) diff --git a/entry/src/main/cpp/sdk/assistdrive/AutomaticService.cpp b/entry/src/main/cpp/sdk/assistdrive/AutomaticService.cpp index e41237b..7b8560c 100644 --- a/entry/src/main/cpp/sdk/assistdrive/AutomaticService.cpp +++ b/entry/src/main/cpp/sdk/assistdrive/AutomaticService.cpp @@ -54,7 +54,7 @@ int AutomaticService::autoServiceSetBasePoint(const char *data, int length) return 0; } -int AutomaticService::autoServiceSetFeildModel(const char *data, int length) +int AutomaticService::autoServiceSetFieldModel(const char *data, int length) { try { diff --git a/entry/src/main/cpp/sdk/assistdrive/AutomaticService.h b/entry/src/main/cpp/sdk/assistdrive/AutomaticService.h index bb6face..662adc6 100644 --- a/entry/src/main/cpp/sdk/assistdrive/AutomaticService.h +++ b/entry/src/main/cpp/sdk/assistdrive/AutomaticService.h @@ -29,7 +29,7 @@ public: virtual int autoServiceInit() override; virtual int autoServiceSetBasePoint(const char *data, int length) override; - virtual int autoServiceSetFeildModel(const char *data, int length) override; + virtual int autoServiceSetFieldModel(const char *data, int length) override; virtual int autoServiceSetTeachPointInfo(const char *data, int length) override; virtual int autoServiceSetTeachPointParam(const char *data, int length) override; virtual int autoServiceSetCarModel(const char *data, int length) override; diff --git a/entry/src/main/cpp/sdk/assistdrive/IAutomaticInterface.h b/entry/src/main/cpp/sdk/assistdrive/IAutomaticInterface.h index dad5124..57e940e 100644 --- a/entry/src/main/cpp/sdk/assistdrive/IAutomaticInterface.h +++ b/entry/src/main/cpp/sdk/assistdrive/IAutomaticInterface.h @@ -11,7 +11,7 @@ public: virtual int autoServiceInit() = 0; virtual int autoServiceSetBasePoint(const char *data, int length) = 0; - virtual int autoServiceSetFeildModel(const char *data, int length) = 0; + virtual int autoServiceSetFieldModel(const char *data, int length) = 0; virtual int autoServiceSetTeachPointInfo(const char *data, int length) = 0; virtual int autoServiceSetTeachPointParam(const char *data, int length) = 0; virtual int autoServiceSetCarModel(const char *data, int length) = 0; diff --git a/entry/src/main/cpp/sdk/assistdrive/IAutomaticService.h b/entry/src/main/cpp/sdk/assistdrive/IAutomaticService.h index ff7b567..8f9ca7c 100644 --- a/entry/src/main/cpp/sdk/assistdrive/IAutomaticService.h +++ b/entry/src/main/cpp/sdk/assistdrive/IAutomaticService.h @@ -11,7 +11,7 @@ public: virtual int autoServiceInit() = 0; virtual int autoServiceSetBasePoint(const char *data, int length) = 0; - virtual int autoServiceSetFeildModel(const char *data, int length) = 0; + virtual int autoServiceSetFieldModel(const char *data, int length) = 0; virtual int autoServiceSetTeachPointInfo(const char *data, int length) = 0; virtual int autoServiceSetTeachPointParam(const char *data, int length) = 0; virtual int autoServiceSetCarModel(const char *data, int length) = 0; diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index d5b713f..4e8b0fd 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -2,12 +2,15 @@ import common from '@ohos.app.ability.common'; import RealTime from '../components/RealTime'; import { MediaPlayer } from '../utils/MediaPlayer'; import { CommandType, MessageCallBackParams, SimulatorUdpClient } from '../utils/simulator/UdpClient'; -import { UdpClient } from '../utils/udp/UdpClient'; -import { ConfigItemProps, Status } from '../model/index'; +import { BackMachineUdpClient } from '../utils/udp/UdpClient'; +import { ConfigItemProps, ConfigProps, Status } from '../model/index'; import { getConfigFile } from '../utils/native/NativeUtils'; import promptAction from '@ohos.promptAction'; import { OutWireControl } from '../utils/wireControl/OutWireControl'; +import { nativeLogCallback, nativeSDKInit, setBasePoint, setConfigFile, setImageSize } from '../utils/native/NativeSDK'; +import { LogHelper } from '../utils/LogHelper'; +import util from '@ohos.util'; // 直角转弯 (0, 0) (0, 1) ... @@ -23,10 +26,6 @@ const audios = new Array(33).map((_, i) => { return "audio/output_" + i + ".mp3" }) -function TestLog(...message: string[]) { - console.log("Assisted Driving: ", ...message) -} - const projectAudio = [ [4, 5], [0, 1, 2, 3], @@ -64,30 +63,47 @@ struct Index { @State currentPath: number = 0 @State currentLibrary: number = 0 @State process: number = 1 + private line: string + private lib: string private carModel: string private fieldModel: string private teachPoint: string + private teachPointParams: string private basePoint: string private player: MediaPlayer = new MediaPlayer(getContext(this) as common.UIAbilityContext) - private simulatorUdpClient: SimulatorUdpClient - private backupUdpClient: UdpClient - private outWireControl: OutWireControl + private simulatorUdpClient?: SimulatorUdpClient + private backupUdpClient?: BackMachineUdpClient + private outWireControl?: OutWireControl async aboutToAppear() { - getConfigFile().then(([fieldModel, carModel, lib, path, teachPoint, basePoint]) => { - this.fieldModel = fieldModel - this.carModel = carModel - this.libraries = lib - this.paths = path - this.teachPoint = teachPoint - this.basePoint = basePoint - }).catch(err => { - TestLog(err) - }) - this.outWireControl = new OutWireControl() - await this.outWireControl.init("192.168.7.181", 30021) - await this.initPlatformUDP() - await this.initAudioPlayer() + try { + await getConfigFile().then(([fieldModel, carModel, line, lib, teachPoint, teachPointParams, basePoint]) => { + this.fieldModel = fieldModel + this.carModel = carModel + this.teachPoint = teachPoint + this.basePoint = basePoint + this.teachPointParams = teachPointParams + this.line = line + this.lib = lib + this.libraries = (JSON.parse(lib) as ConfigProps>).features + this.paths = (JSON.parse(line) as ConfigProps>>).features + }) + await nativeSDKInit() + // await nativeLogCallback((message: string, len: number) => { + // LogHelper.I("NativeSDK", message) + // }) + 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() + } catch (err) { + promptAction.showToast({ + message: JSON.stringify(err), + duration: 3000 + }) + LogHelper.E("View ", JSON.stringify(err)) + } } async playAudio(project: number, point: number) { @@ -108,56 +124,63 @@ struct Index { // 初始化终端UDP async initPlatformUDP() { this.simulatorUdpClient = new SimulatorUdpClient("0.0.0.0", 8990, "88.22.10.118", 9001) - await this.simulatorUdpClient.bindUdp() - // this.simulatorUdpClient.heart() - setInterval(() => { - this.simulatorUdpClient.uploadPosition() - }, 1000) - this.simulatorUdpClient.onMessage(({type, data = [] }: MessageCallBackParams) => { - if (type === CommandType.Start) { - let path = this.paths.findIndex(item => { - return item.properties.id === data[0] - }) - let lib = this.libraries.findIndex(item => { - return item.properties.id === data[1] - }) - if (path === -1 || lib === -1) { - promptAction.showToast({ - message: "错误的路线或库位" + try { + await this.simulatorUdpClient.bindUdp() + this.simulatorUdpClient.heart() + setInterval(() => { + this.simulatorUdpClient.uploadPosition() + }, 1000) + this.simulatorUdpClient.onMessage(({type, data = [] }: MessageCallBackParams) => { + if (type === CommandType.Start) { + let path = this.paths.findIndex(item => { + return item.properties.id === data[0] }) - this.simulatorUdpClient.sendPID26(CommandType.Failed) - return + let lib = this.libraries.findIndex(item => { + return item.properties.id === data[1] + }) + if (path === -1 || lib === -1) { + promptAction.showToast({ + message: "错误的路线或库位" + }) + this.simulatorUdpClient.sendPID26(CommandType.Failed) + return + } + this.currentPath = path + this.currentLibrary = lib + this.status = Status.Running + this.simulatorUdpClient.sendPID26(CommandType.Success) } - this.currentPath = path - this.currentLibrary = lib - this.status = Status.Running - this.simulatorUdpClient.sendPID26(CommandType.Success) - } - else if (type === CommandType.Stop) { - this.status = Status.Idle - this.simulatorUdpClient.sendPID26(CommandType.Success) - } - }) + else if (type === CommandType.Stop) { + this.status = Status.Idle + this.simulatorUdpClient.sendPID26(CommandType.Success) + } + }) + } catch (err) { + throw new Error(JSON.stringify(err)) + } } // 初始化后置机UDP async initBackMachineUDP() { - this.backupUdpClient = new UdpClient("", 0, "", 0) - await this.backupUdpClient.bindUdp() - this.backupUdpClient.onMessage(() => { - - }) + this.backupUdpClient = new BackMachineUdpClient("", 0, "", 0) + try { + await this.backupUdpClient.bindUdp() + this.backupUdpClient.onMessage(() => { + }) + } catch (err) { + throw new Error(JSON.stringify(err)) + } } // 上方按钮点击 onConfirm() { if (this.status === Status.Idle) { - this.simulatorUdpClient.setPathId(this.paths[this.currentPath].properties.id) - this.simulatorUdpClient.setLibId(this.libraries[this.currentLibrary].properties.id) - this.simulatorUdpClient.sendPID26(CommandType.Start) + this.simulatorUdpClient?.setPathId(this.paths[this.currentPath].properties.id) + this.simulatorUdpClient?.setLibId(this.libraries[this.currentLibrary].properties.id) + this.simulatorUdpClient?.sendPID26(CommandType.Start) this.status = Status.Running } else { - this.simulatorUdpClient.sendPID26(CommandType.Stop) + this.simulatorUdpClient?.sendPID26(CommandType.Stop) this.status = Status.Idle } } diff --git a/entry/src/main/ets/utils/LogHelper.ts b/entry/src/main/ets/utils/LogHelper.ts index 4f69695..2e6b7ce 100644 --- a/entry/src/main/ets/utils/LogHelper.ts +++ b/entry/src/main/ets/utils/LogHelper.ts @@ -18,7 +18,11 @@ export class LogHelper { public static DOOR_SWITCH = "door_switch"; public static I(tag: string, ...msg: any[]) { - console.log(tag + "__", ...msg); + console.log(`[Assisted Drive Module ${tag} Message]: `, ...msg); + } + + public static E(tag: string, ...msg: any[]) { + console.error(`[Assisted Drive Module ${tag} Message]: `, ...msg); } public static getDetailLog(tag: string, value: number) { diff --git a/entry/src/main/ets/utils/Store.ets b/entry/src/main/ets/utils/Store.ets index c09b809..388e062 100644 --- a/entry/src/main/ets/utils/Store.ets +++ b/entry/src/main/ets/utils/Store.ets @@ -1,6 +1,6 @@ import common from '@ohos.app.ability.common' import { SimulatorUdpClient } from './simulator/UdpClient' -import { UdpClient } from './udp/UdpClient' +import { BackMachineUdpClient } from './udp/UdpClient' class Store { private static instance: Store @@ -8,7 +8,7 @@ class Store { public closeUDPSocket: boolean public plcUdpError: boolean public serialPortMsg: string - public backMachineUDPClient: UdpClient + public backMachineUDPClient: BackMachineUdpClient public simulatorUdpClient: SimulatorUdpClient public isJudge: boolean public messageTimer: number diff --git a/entry/src/main/ets/utils/native/NativeSDK.ets b/entry/src/main/ets/utils/native/NativeSDK.ets index c842536..bb8830a 100644 --- a/entry/src/main/ets/utils/native/NativeSDK.ets +++ b/entry/src/main/ets/utils/native/NativeSDK.ets @@ -1,18 +1,212 @@ -// import libJudgeSdk from 'libJudgeSdk.so' -// -// function useNativeAPI(cb: Function, ...args: Object[]) { -// return new Promise((resolve, reject) => { -// let params = args.map(item => JSON.stringify(item)) -// let result = cb(...params) -// if (result === 0) { -// resolve() -// } else { -// reject() -// } -// }) -// } -// -// export function init(data: Object) { -// return useNativeAPI(libJudgeSdk.examJudgeInit, data) -// } -// +import libJudgeSdk from 'libJudgeSdk.so' +import { LogHelper } from '../LogHelper' + +const Tag = "NativeSDK" + +function useNativeAPI(cb: Function, ...args: Object[]) { + return new Promise((resolve, reject) => { + let params = args.map(item => JSON.stringify(item)) + let result = cb(...params) + LogHelper.I(Tag, cb.name, "receive sdk result ", result) + if (result === 0) { + LogHelper.I(Tag, "use native function ", cb.name, " success") + resolve() + } else { + reject("use native function " + cb.name + " failed") + } + }) +} + +// sdk初始化 +export function nativeSDKInit(data?: Object) { + return useNativeAPI(libJudgeSdk.autoServiceInit, data) +} + +// 日志回调 +export async function nativeLogCallback(callback: Function) { + return new Promise((resolve, reject) => { + const result = libJudgeSdk.registerAutoServiceLogCallback(callback) + if (result === 0) { + LogHelper.I(Tag, "use native function ", "registerAutoServiceLogCallback", " success") + resolve() + } else { + reject("use native function " + "registerAutoServiceLogCallback" + " failed, error code " + result) + } + }) +} + +// 设置基准点 +export function setBasePoint(basePoint: string) { + return new Promise((resolve, reject) => { + const result = libJudgeSdk.autoServiceSetBasePoint(basePoint, basePoint.length) + if (result === 0) { + LogHelper.I(Tag, "use native function ", "autoServiceSetBasePoint", " success") + resolve() + } else { + reject("use native function " + "autoServiceSetBasePoint" + " failed, error code " + result) + } + }) +} + +// 设置场地模型 +export function setFieldModel(fieldModel: string) { + return new Promise((resolve, reject) => { + const result = libJudgeSdk.autoServiceSetFieldModel(fieldModel, fieldModel.length) + if (result === 0) { + LogHelper.I(Tag, "use native function ", "autoServiceSetFieldModel", " success") + resolve() + } else { + reject("use native function " + "autoServiceSetFieldModel" + " failed, error code " + result) + } + }) +} + +// 设置教学点 +export function setTeachPoint(teachPoint: string) { + return new Promise((resolve, reject) => { + const result = libJudgeSdk.autoServiceSetTeachPointInfo(teachPoint, teachPoint.length) + if (result === 0) { + LogHelper.I(Tag, "use native function ", "autoServiceSetTeachPointInfo", " success") + resolve() + } else { + reject("use native function " + "autoServiceSetTeachPointInfo" + " failed, error code " + result) + } + }) +} + +// 设置教学点参数 +export function setTeachPointParam(teachPointParam: string) { + return new Promise((resolve, reject) => { + const result = libJudgeSdk.autoServiceSetTeachPointParam(teachPointParam, teachPointParam.length) + if (result === 0) { + LogHelper.I(Tag, "use native function ", "autoServiceSetTeachPointParam", " success") + resolve() + } else { + reject("use native function " + "autoServiceSetTeachPointParam" + " failed, error code " + result) + } + }) +} + +// 设置车模 +export function setCarModel(carModel: string) { + return new Promise((resolve, reject) => { + const result = libJudgeSdk.autoServiceSetCarModel(carModel, carModel.length) + if (result === 0) { + LogHelper.I(Tag, "use native function ", "autoServiceSetCarModel", " success") + resolve() + } else { + reject("use native function " + "autoServiceSetCarModel" + " failed, error code " + result) + } + }) +} + +// 设置路径信息 +export function setLineInfo(line: string) { + return new Promise((resolve, reject) => { + const result = libJudgeSdk.autoServiceSetLineInfo(line, line.length) + if (result === 0) { + LogHelper.I(Tag, "use native function ", "autoServiceSetLineInfo", " success") + resolve() + } else { + reject("use native function " + "autoServiceSetLineInfo" + " failed, error code " + result) + } + }) +} + +// 设置库位信息 +export function setLibInfo(lib: string) { + return new Promise((resolve, reject) => { + const result = libJudgeSdk.autoServiceSetLibInfo(lib, lib.length) + if (result === 0) { + LogHelper.I(Tag, "use native function ", "autoServiceSetLibInfo", " success") + resolve() + } else { + reject("use native function " + "autoServiceSetLibInfo" + " failed, error code " + result) + } + }) +} + +// 选择路径和库位 +export function selectLineAndLib(line: number, lib: number) { + return new Promise((resolve, reject) => { + const result = libJudgeSdk.autoServiceSelectLineAndLib(line, lib) + if (result === 0) { + LogHelper.I(Tag, "use native function ", "autoServiceSelectLineAndLib", " success") + resolve() + } else { + reject("use native function " + "autoServiceSelectLineAndLib" + " failed, error code " + result) + } + }) +} + +// 轨迹跟踪 +export function onTrack(lng: number, lat: number, yaw: number, v: number) { + return new Promise((resolve, reject) => { + const result = libJudgeSdk.autoServiceTrack(lng, lat, yaw, v) + if (result === 0) { + LogHelper.I(Tag, "use native function ", "autoServiceTrack", " success") + resolve() + } else { + reject("use native function " + "autoServiceTrack" + " failed, error code " + result) + } + }) +} + +// 设置线画图大小 +export function setImageSize(width: number, height: number) { + return new Promise((resolve, reject) => { + const result = libJudgeSdk.autoServiceSetImageSize(width, height) + if (result === 0) { + LogHelper.I(Tag, "use native function ", "autoServiceSetImageSize", " success") + resolve() + } else { + reject("use native function " + "autoServiceSetImageSize" + " failed, error code " + result) + } + }) +} + +// 注册车辆控制回调 +export function registerControlCallback(callback: Function) { + return new Promise((resolve, reject) => { + const result = libJudgeSdk.registerAutoServiceCallback(callback) + if (result === 0) { + LogHelper.I(Tag, "use native function ", "registerAutoServiceCallback", " success") + resolve() + } else { + reject("use native function " + "registerAutoServiceCallback" + " failed, error code " + result) + } + }) +} + +// 注册教学语音回调 +export function registerSoundCallback(callback: Function) { + return new Promise((resolve, reject) => { + const result = libJudgeSdk.registerAutoServiceSoundCallback(callback) + if (result === 0) { + LogHelper.I(Tag, "use native function ", "registerAutoServiceSoundCallback", " success") + resolve() + } else { + reject("use native function " + "registerAutoServiceSoundCallback" + " failed, error code " + result) + } + }) +} + +// 设置配置文件 +export function setConfigFile( + basePoint: string, + fieldModel: string, + teachPoint: string, + teachPointParams: string, + carModel: string, + line: string, + lib: string) { + return Promise.all([ + setBasePoint(basePoint), + setFieldModel(fieldModel), + setTeachPoint(teachPoint), + setTeachPointParam(teachPointParams), + setCarModel(carModel), + setLineInfo(line), + setLibInfo(lib)]) +} + diff --git a/entry/src/main/ets/utils/native/NativeUtils.ets b/entry/src/main/ets/utils/native/NativeUtils.ets index 677038c..f8c41d7 100644 --- a/entry/src/main/ets/utils/native/NativeUtils.ets +++ b/entry/src/main/ets/utils/native/NativeUtils.ets @@ -26,20 +26,21 @@ function getCarModel() { // 获取库位 function getLibrary() { - return getRawFile(`config/${dir}/destLib.json`).then(res => { - return (JSON.parse(res) as ConfigProps>).features - }) + return getRawFile(`config/${dir}/destLib.json`) } // 获取路线 function getTrack() { - return getRawFile(`config/${dir}/naviPath.json`).then(res => { - return (JSON.parse(res) as ConfigProps>>).features - }) + return getRawFile(`config/${dir}/naviPath.json`) } // 获取教学点位 function getTeachPoint() { + return getRawFile(`config/${dir}/aiconfig.json`) +} + +// 获取教学点位参数 +function getTeachPointParams() { return getRawFile(`config/${dir}/collectParams.json`).then(res => { const origin = (JSON.parse(res) as Array) const native: NativeTeachPoint = { item: [] } @@ -77,6 +78,6 @@ function translateTeachPoint() { // 获取SDK所需的配置文件 export function getConfigFile() { - return Promise.all([getFieldModel(), getCarModel(), getLibrary(), getTrack(), getTeachPoint(), getBasePoint()]) + return Promise.all([getFieldModel(), getCarModel(), getTrack(), getLibrary(), getTeachPoint(), getTeachPointParams(), getBasePoint()]) } diff --git a/entry/src/main/ets/utils/simulator/UdpClient.ets b/entry/src/main/ets/utils/simulator/UdpClient.ets index 420406b..014453e 100644 --- a/entry/src/main/ets/utils/simulator/UdpClient.ets +++ b/entry/src/main/ets/utils/simulator/UdpClient.ets @@ -1,7 +1,8 @@ import socket from '@ohos.net.socket'; +import { LogHelper } from '../LogHelper'; import { byte2string, DataToByte } from '../Utils'; -const TAG = 'socketTag[Simulator.UdpClient] ' +const TAG = 'SimulatorUDP' function generateCheckCode(arr: Uint8Array | Uint16Array | Uint32Array) { let end: number @@ -55,6 +56,7 @@ export class SimulatorUdpClient { private pathId: number private lidId: number private callback?: MessageCallBack + public static Tag = "SimulatorUDP" constructor(localIp: string, localIpPort: number, oppositeIp: string, oppositeIpPort: number) { this.localIp = localIp @@ -119,12 +121,12 @@ export class SimulatorUdpClient { type: CommandType.Start, data: [path, lib] }) - console.log(TAG, `receive pid18: command start, path: ${path}, lib: ${lib}`) + LogHelper.I(TAG, `receive pid18: command start, path: ${path}, lib: ${lib}`) } else if (type === 16) { this.callback?.({ type: CommandType.Stop }) - console.log(TAG, `receive pid18: command stop`) + LogHelper.I(TAG, `receive pid18: command stop`) } } @@ -184,16 +186,16 @@ export class SimulatorUdpClient { } }) .then(() => { - console.log(TAG, `[${this.oppositeIp}:${this.oppositeIpPort}]: send success`) + LogHelper.I(TAG, `[${this.oppositeIp}:${this.oppositeIpPort}]: send success`) }) .catch(err => { - console.error(JSON.stringify(err)) + LogHelper.E(TAG, JSON.stringify(err)) }) } onError(callback?) { this.udp.on('error', async err => { - console.log(TAG, 'udpError', JSON.stringify(err)) + LogHelper.E(TAG, JSON.stringify(err)) this.bindUdp() this.sendMsg('111') this.onMessage(callback) diff --git a/entry/src/main/ets/utils/udp/UdpClient.ets b/entry/src/main/ets/utils/udp/UdpClient.ets index c69b445..15f800c 100644 --- a/entry/src/main/ets/utils/udp/UdpClient.ets +++ b/entry/src/main/ets/utils/udp/UdpClient.ets @@ -1,12 +1,13 @@ import socket from '@ohos.net.socket'; import promptAction from '@ohos.promptAction'; +import { LogHelper } from '../LogHelper'; import { getSerialPort } from '../native/HiserialUtils'; import Store from '../Store'; -const TAG = 'socketTag[PLC.UdpClient] ' +const TAG = 'BackMachineUDP' -export class UdpClient { +export class BackMachineUdpClient { private localIp: string = '' private localIpPort: number = 0 private oppositeIp: string = '' @@ -14,6 +15,7 @@ export class UdpClient { private udp: socket.UDPSocket = null private num: number = 0 private plcUdpError: boolean = false + public static TAG: string = 'BackMachineUDP' constructor(localIp: string, localIpPort: number, oppositeIp: string, oppositeIpPort: number) { this.localIp = localIp @@ -41,7 +43,6 @@ export class UdpClient { sendMsg(msg) { return this.udp.getState() .then(data => { - console.log('getState success:' + JSON.stringify(data)); return this.udp.send({ data: msg, address: { @@ -52,11 +53,10 @@ export class UdpClient { }) }) .then(() => { - console.log(`${TAG}udpCLient udp send success:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`); + LogHelper.I(TAG, `[${this.oppositeIp}:${this.oppositeIpPort}]: send success`) }) .catch(err => { - console.log(`${TAG}udpCLient udp send fail:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`); - console.log(`${TAG}udpCLient udp send fail error: ${JSON.stringify(err)}`); + LogHelper.E(TAG, JSON.stringify(err)) }) } diff --git a/entry/src/main/ets/utils/wireControl/WireControl.ets b/entry/src/main/ets/utils/wireControl/WireControl.ets index 87ae037..ace70b6 100644 --- a/entry/src/main/ets/utils/wireControl/WireControl.ets +++ b/entry/src/main/ets/utils/wireControl/WireControl.ets @@ -147,8 +147,6 @@ export class WireControl { this.socket.setExtraOptions({ reuseAddress: true }); return this.socket.bind({ address: "192.168.7.170", port: 31021 }).then(() => { this.isInit = true; - }).catch((err) => { - LogHelper.I(LogHelper.TAG, "init failed: ", JSON.stringify(err)) }) } diff --git a/entry/src/main/resources/rawfile/config/duolun/aiconfig.json b/entry/src/main/resources/rawfile/config/duolun/aiconfig.json new file mode 100644 index 0000000..26bde86 --- /dev/null +++ b/entry/src/main/resources/rawfile/config/duolun/aiconfig.json @@ -0,0 +1,277 @@ +{ + "item":[ + { + "item_code":"20100", + "teach_point":[ + { + "point_index":1, + "teachName":"进项目-江西蓝天", + "velocity_max": 5.7, + "velocity_std": 3, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":2, + "teachName":"停车-江西蓝天", + "velocity_max": 7.4, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":3, + "teachName":"右入库第一把右打满-江西蓝天", + "velocity_max": 4.1, + "velocity_std": 0.8, + "steering_std": 540, + "lamp_std": 0 + }, + { + "point_index":4, + "teachName":"右入库第二把回正-江西蓝天", + "velocity_max": 3.1, + "velocity_std": 0.8, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":5, + "teachName":"右入库第三把右打满-江西蓝天", + "velocity_max": 2.3, + "velocity_std": 0.8, + "steering_std": 540, + "lamp_std": 0 + }, + { + "point_index":6, + "teachName":"右入库调整库边距-江西蓝天", + "velocity_max": 2.6, + "velocity_std": 0.8, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":7, + "teachName":"右入库停车-江西蓝天", + "velocity_max": 3.8, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":8, + "teachName":"左出库-江西蓝天", + "velocity_max": 4.5, + "velocity_std": 0.7, + "steering_std": 540, + "lamp_std": 0 + }, + { + "point_index":9, + "teachName":"回正方向-江西蓝天", + "velocity_max": 4.3, + "velocity_std": 1.5, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":10, + "teachName":"左出库停车-江西蓝天", + "velocity_max": 4.9, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":11, + "teachName":"左入库第一把左打满-江西蓝天", + "velocity_max": 3.5, + "velocity_std": 0.8, + "steering_std": 540, + "lamp_std": 0 + }, + { + "point_index":12, + "teachName":"左入库第二把回正-江西蓝天", + "velocity_max": 3.1, + "velocity_std": 0.8, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":13, + "teachName":"左入库第三把左打满-江西蓝天", + "velocity_max": 4.1, + "velocity_std": 0.8, + "steering_std": 540, + "lamp_std": 0 + }, + { + "point_index":14, + "teachName":"左入库调整库边距-江西蓝天", + "velocity_max": 3.3, + "velocity_std": 0.9, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":15, + "teachName":"左入库停车-江西蓝天", + "velocity_max": 3.5, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":16, + "teachName":"右出库-江西蓝天", + "velocity_max": 4, + "velocity_std": 1.3, + "steering_std": 540, + "lamp_std": 0 + } + ] + }, + { + "item_code":"20700", + "teach_point":[ + { + "point_index":1, + "teachName":"进项目-江西蓝天-新", + "velocity_max": 7.9, + "velocity_std": 2.2, + "steering_std": 0, + "lamp_std": 1 + }, + { + "point_index":2, + "teachName":"左转-江西蓝天", + "velocity_max": 7.1, + "velocity_std": 1.7, + "steering_std": 540, + "lamp_std": 1 + } + ] + }, + { + "item_code":"20400", + "teach_point":[ + { + "point_index":1, + "teachName":"进项目-江西蓝天", + "velocity_max": 8.2, + "velocity_std": 3.3, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":2, + "teachName":"停车-江西蓝天", + "velocity_max": 7.6, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":3, + "teachName":"入库第一把右打一圈-江西蓝天", + "velocity_max": 5.3, + "velocity_std": 1.2, + "steering_std": 360, + "lamp_std": 0 + }, + { + "point_index":4, + "teachName":"入库第二把回正方向-江西蓝天", + "velocity_max": 3.4, + "velocity_std": 1.1, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":5, + "teachName":"入库第三把左打满-江西蓝天", + "velocity_max": 4.8, + "velocity_std": 1.2, + "steering_std": 540, + "lamp_std": 0 + }, + { + "point_index":6, + "teachName":"入库停车-江西蓝天", + "velocity_max": 3.7, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":8, + "teachName":"出库第二把右打满-江西蓝天", + "velocity_max": 5.7, + "velocity_std": 1.6, + "steering_std": 540, + "lamp_std": -1 + } + ] + }, + { + "item_code":"20300", + "teach_point":[ + { + "point_index":1, + "teachName":"进项目-江西蓝天", + "velocity_max": 8.0, + "velocity_std": 4.0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":2, + "teachName":"定点停车-江西蓝天", + "velocity_max": 6, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + } + ] + }, + { + "item_code":"20600", + "teach_point":[ + { + "point_index":1, + "teachName":"进项目-蓝天", + "velocity_max": 3.8, + "velocity_std": 1.8, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":2, + "teachName":"左打一圈-江西蓝天", + "velocity_max": 7.1, + "velocity_std": 2.5, + "steering_std": 360, + "lamp_std": 0 + }, + { + "point_index":3, + "teachName":"回正方向-江西蓝天", + "velocity_max": 6.3, + "velocity_std": 2.0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":4, + "teachName":"右打一圈-江西蓝天", + "velocity_max": 7.4, + "velocity_std": 2.4, + "steering_std": 360, + "lamp_std": 0 + } + ] + } + ] +} \ No newline at end of file diff --git a/entry/src/main/resources/rawfile/config/simulator/aiconfig.json b/entry/src/main/resources/rawfile/config/simulator/aiconfig.json new file mode 100644 index 0000000..26bde86 --- /dev/null +++ b/entry/src/main/resources/rawfile/config/simulator/aiconfig.json @@ -0,0 +1,277 @@ +{ + "item":[ + { + "item_code":"20100", + "teach_point":[ + { + "point_index":1, + "teachName":"进项目-江西蓝天", + "velocity_max": 5.7, + "velocity_std": 3, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":2, + "teachName":"停车-江西蓝天", + "velocity_max": 7.4, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":3, + "teachName":"右入库第一把右打满-江西蓝天", + "velocity_max": 4.1, + "velocity_std": 0.8, + "steering_std": 540, + "lamp_std": 0 + }, + { + "point_index":4, + "teachName":"右入库第二把回正-江西蓝天", + "velocity_max": 3.1, + "velocity_std": 0.8, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":5, + "teachName":"右入库第三把右打满-江西蓝天", + "velocity_max": 2.3, + "velocity_std": 0.8, + "steering_std": 540, + "lamp_std": 0 + }, + { + "point_index":6, + "teachName":"右入库调整库边距-江西蓝天", + "velocity_max": 2.6, + "velocity_std": 0.8, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":7, + "teachName":"右入库停车-江西蓝天", + "velocity_max": 3.8, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":8, + "teachName":"左出库-江西蓝天", + "velocity_max": 4.5, + "velocity_std": 0.7, + "steering_std": 540, + "lamp_std": 0 + }, + { + "point_index":9, + "teachName":"回正方向-江西蓝天", + "velocity_max": 4.3, + "velocity_std": 1.5, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":10, + "teachName":"左出库停车-江西蓝天", + "velocity_max": 4.9, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":11, + "teachName":"左入库第一把左打满-江西蓝天", + "velocity_max": 3.5, + "velocity_std": 0.8, + "steering_std": 540, + "lamp_std": 0 + }, + { + "point_index":12, + "teachName":"左入库第二把回正-江西蓝天", + "velocity_max": 3.1, + "velocity_std": 0.8, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":13, + "teachName":"左入库第三把左打满-江西蓝天", + "velocity_max": 4.1, + "velocity_std": 0.8, + "steering_std": 540, + "lamp_std": 0 + }, + { + "point_index":14, + "teachName":"左入库调整库边距-江西蓝天", + "velocity_max": 3.3, + "velocity_std": 0.9, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":15, + "teachName":"左入库停车-江西蓝天", + "velocity_max": 3.5, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":16, + "teachName":"右出库-江西蓝天", + "velocity_max": 4, + "velocity_std": 1.3, + "steering_std": 540, + "lamp_std": 0 + } + ] + }, + { + "item_code":"20700", + "teach_point":[ + { + "point_index":1, + "teachName":"进项目-江西蓝天-新", + "velocity_max": 7.9, + "velocity_std": 2.2, + "steering_std": 0, + "lamp_std": 1 + }, + { + "point_index":2, + "teachName":"左转-江西蓝天", + "velocity_max": 7.1, + "velocity_std": 1.7, + "steering_std": 540, + "lamp_std": 1 + } + ] + }, + { + "item_code":"20400", + "teach_point":[ + { + "point_index":1, + "teachName":"进项目-江西蓝天", + "velocity_max": 8.2, + "velocity_std": 3.3, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":2, + "teachName":"停车-江西蓝天", + "velocity_max": 7.6, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":3, + "teachName":"入库第一把右打一圈-江西蓝天", + "velocity_max": 5.3, + "velocity_std": 1.2, + "steering_std": 360, + "lamp_std": 0 + }, + { + "point_index":4, + "teachName":"入库第二把回正方向-江西蓝天", + "velocity_max": 3.4, + "velocity_std": 1.1, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":5, + "teachName":"入库第三把左打满-江西蓝天", + "velocity_max": 4.8, + "velocity_std": 1.2, + "steering_std": 540, + "lamp_std": 0 + }, + { + "point_index":6, + "teachName":"入库停车-江西蓝天", + "velocity_max": 3.7, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":8, + "teachName":"出库第二把右打满-江西蓝天", + "velocity_max": 5.7, + "velocity_std": 1.6, + "steering_std": 540, + "lamp_std": -1 + } + ] + }, + { + "item_code":"20300", + "teach_point":[ + { + "point_index":1, + "teachName":"进项目-江西蓝天", + "velocity_max": 8.0, + "velocity_std": 4.0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":2, + "teachName":"定点停车-江西蓝天", + "velocity_max": 6, + "velocity_std": 0, + "steering_std": 0, + "lamp_std": 0 + } + ] + }, + { + "item_code":"20600", + "teach_point":[ + { + "point_index":1, + "teachName":"进项目-蓝天", + "velocity_max": 3.8, + "velocity_std": 1.8, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":2, + "teachName":"左打一圈-江西蓝天", + "velocity_max": 7.1, + "velocity_std": 2.5, + "steering_std": 360, + "lamp_std": 0 + }, + { + "point_index":3, + "teachName":"回正方向-江西蓝天", + "velocity_max": 6.3, + "velocity_std": 2.0, + "steering_std": 0, + "lamp_std": 0 + }, + { + "point_index":4, + "teachName":"右打一圈-江西蓝天", + "velocity_max": 7.4, + "velocity_std": 2.4, + "steering_std": 360, + "lamp_std": 0 + } + ] + } + ] +} \ No newline at end of file