feat:dev_proxy

This commit is contained in:
surenjun 2025-06-16 15:31:19 +08:00
parent ce3a1e86a6
commit 29f85dca0a
28 changed files with 718 additions and 2064 deletions

View File

@ -0,0 +1,10 @@
export default interface IIdlServiceExt {
processData(data: string, callback: processDataCallback): void;
insertDataToMap(key: string, val: number, callback: insertDataToMapCallback): void;
}
export type processDataCallback = (errCode: number, returnValue: string) => void;
export type insertDataToMapCallback = (errCode: number) => void;

View File

@ -0,0 +1,51 @@
import IdlServiceExtStub from './idl_service_ext_stub';
import hilog from '@ohos.hilog';
import type { insertDataToMapCallback } from './i_idl_service_ext';
import type { processDataCallback } from './i_idl_service_ext';
import request from '../common/utils/request';
import pasteboard from '@ohos.pasteboard';
const ERR_OK = 0;
const TAG: string = "[IdlServiceExtImpl]";
const DOMAIN_NUMBER: number = 0xFF00;
// 开发者需要在这个类型里对接口进行实现
export default class ServiceExtImpl extends IdlServiceExtStub {
processData(data: string, callback: processDataCallback): void {
// 开发者自行实现业务逻辑
hilog.info(DOMAIN_NUMBER, TAG, `js-test ServiceExtensionAbility--processData: ${data}`);
console.log("lixiao receive", data)
pasteboard.getSystemPasteboard().getData().then((res) => {
let pasteData = res.getPrimaryText()
console.log("lixiao receive paste", pasteData)
request(JSON.parse(pasteData)).then(response => {
console.log("lixiao success", JSON.stringify(response))
callback(0, JSON.stringify({
code: 0,
data: response
}));
// callback(0, JSON.stringify(response));
}).catch(async (err) => {
callback(0, JSON.stringify({
code: 1,
data: err
}));
console.log("lixiao error", JSON.stringify(err))
})
}).catch(err => {
callback(0, JSON.stringify({
code: 1,
data: {
code: 2300007
}
}));
console.log("lixiao paste error", JSON.stringify(err))
})
}
insertDataToMap(key: string, val: number, callback: insertDataToMapCallback): void {
// 开发者自行实现业务逻辑
hilog.info(DOMAIN_NUMBER, TAG, `js-test ServiceExtensionAbility--insertDataToMap, key: ${key} val: ${val}`);
callback(ERR_OK);
}
}

View File

@ -0,0 +1,57 @@
import {processDataCallback} from "./i_idl_service_ext";
import {insertDataToMapCallback} from "./i_idl_service_ext";
import IIdlServiceExt from "./i_idl_service_ext";
import rpc from "@ohos.rpc";
export default class IdlServiceExtProxy implements IIdlServiceExt {
constructor(proxy) {
this.proxy = proxy;
}
processData(data: string, callback: processDataCallback): void
{
let _option = new rpc.MessageOption();
let _data = new rpc.MessageParcel();
let _reply = new rpc.MessageParcel();
// _data.writeString(data);
_data.writeString(data)
this.proxy.sendRequest(IdlServiceExtProxy.COMMAND_PROCESS_DATA, _data, _reply, _option).then(function(result) {
if (result.errCode === 0) {
let _errCode = result.reply.readInt();
if (_errCode != 0) {
let _returnValue = undefined;
callback(_errCode, _returnValue);
return;
}
let _returnValue = result.reply.readString();
callback(_errCode, _returnValue);
} else {
console.log("sendRequest failed, errCode: " + result.errCode);
}
})
}
insertDataToMap(key: string, val: number, callback: insertDataToMapCallback): void
{
let _option = new rpc.MessageOption();
let _data = new rpc.MessageParcel();
let _reply = new rpc.MessageParcel();
_data.writeString(key);
_data.writeInt(val);
this.proxy.sendRequest(IdlServiceExtProxy.COMMAND_INSERT_DATA_TO_MAP, _data, _reply, _option).then(function(result) {
if (result.errCode === 0) {
let _errCode = result.reply.readInt();
callback(_errCode);
} else {
console.log("sendRequest failed, errCode: " + result.errCode);
}
})
}
static readonly COMMAND_PROCESS_DATA = 1;
static readonly COMMAND_INSERT_DATA_TO_MAP = 2;
private proxy
}

View File

@ -0,0 +1,86 @@
import { processDataCallback } from "./i_idl_service_ext";
import { insertDataToMapCallback } from "./i_idl_service_ext";
import IIdlServiceExt from "./i_idl_service_ext";
import rpc from "@ohos.rpc";
import common from '@ohos.app.ability.common';
export default class IdlServiceExtStub extends rpc.RemoteObject implements IIdlServiceExt {
protected context: common.ServiceExtensionContext
constructor(des: string, context: common.ServiceExtensionContext) {
super(des);
this.context = context;
}
onRemoteMessageRequest(code: number, data: rpc.MessageSequence, reply: rpc.MessageSequence, option): Promise<boolean> {
console.log("lixiao onRemoteRequest called, code = " + code);
return new Promise<boolean>((resolve, reject) => {
switch (code) {
case IdlServiceExtStub.COMMAND_PROCESS_DATA: {
// let _data = data.readString();
let _data = data.readString()
this.processData(_data, (errCode, returnValue) => {
console.log("lixiao callback", returnValue);
console.log("lixiao errCode", errCode);
reply.writeInt(errCode);
reply.writeString(returnValue);
resolve(true)
});
break
}
case IdlServiceExtStub.COMMAND_INSERT_DATA_TO_MAP: {
let _key = data.readString();
let _val = data.readInt();
this.insertDataToMap(_key, _val, (errCode) => {
reply.writeInt(errCode);
resolve(true)
});
break
}
default: {
console.log("invalid request code" + code);
reject(true)
}
}
})
}
// onRemoteRequest(code: number, data, reply, option): boolean {
// console.log("lixiao onRemoteRequest called, code = " + code);
// switch (code) {
// case IdlServiceExtStub.COMMAND_PROCESS_DATA: {
// let _data = data.readString();
// this.processData(_data, (errCode, returnValue) => {
// reply.writeInt(errCode);
// if (errCode == 0) {
// reply.writeString(returnValue);
// }
// });
// return true;
// }
// case IdlServiceExtStub.COMMAND_INSERT_DATA_TO_MAP: {
// let _key = data.readString();
// let _val = data.readInt();
// this.insertDataToMap(_key, _val, (errCode) => {
// reply.writeInt(errCode);
// });
// return true;
// }
// default: {
// console.log("invalid request code" + code);
// break;
// }
// }
// return false;
// }
processData(data: string, callback: processDataCallback): void {
}
insertDataToMap(key: string, val: number, callback: insertDataToMapCallback): void {
}
static readonly COMMAND_PROCESS_DATA = 1;
static readonly COMMAND_INSERT_DATA_TO_MAP = 2;
}

View File

@ -0,0 +1,38 @@
import ServiceExtension from '@ohos.app.ability.ServiceExtensionAbility'
// import { ServiceExtensionAbility, Want } from '@kit.AbilityKit';
// import { rpc } from '@kit.IPCKit';
import hilog from '@ohos.hilog';
import { tcpUtil } from '../common/utils/TcpRequest';
import ServiceExtImpl from '../IdlServiceExt/idl_service_ext_impl';
const TAG: string = '[ServiceExtAbility]';
const DOMAIN_NUMBER: number = 0xFF00;
export default class ServiceExtAbility extends ServiceExtension {
serviceExtImpl: ServiceExtImpl = new ServiceExtImpl('ExtImpl', this.context);
async onCreate(want): Promise<void> {
// tcp创建连接
await tcpUtil.init()
hilog.info(DOMAIN_NUMBER, TAG, `js-test ServiceExtensionAbility-- onCreate, want: ${want.abilityName}`);
};
onRequest(want, startId: number): void {
hilog.info(DOMAIN_NUMBER, TAG, `js-test ServiceExtensionAbility--onRequest, want: ${want.abilityName}`);
};
onConnect(want) {
hilog.info(DOMAIN_NUMBER, TAG, `js-test ServiceExtensionAbility--onConnect, want: ${want.abilityName}`);
// 返回ServiceExtImpl对象客户端获取后便可以与ServiceExtensionAbility进行通信
return this.serviceExtImpl;
};
onDisconnect(want): void {
hilog.info(DOMAIN_NUMBER, TAG, `js-test ServiceExtensionAbility--onDisconnect, want: ${want.abilityName}`);
};
onDestroy(): void {
hilog.info(DOMAIN_NUMBER, TAG, 'js-test ServiceExtensionAbility--onDestroy');
};
};

View File

@ -0,0 +1,26 @@
import common from '@ohos.app.ability.common';
import hilog from '@ohos.hilog';
import Want from '@ohos.app.ability.Want';
const DOMAIN_NUMBER: number = 0xFF00;
// import { BusinessError } from '@ohos.base';
import promptAction from '@ohos.promptAction';
const TAG: string = '[ServiceInteractive]';
let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; // UIAbilityContext
let want: Want = {
deviceId: '',
bundleName: 'com.oh.dts',
abilityName: 'ServiceExtAbility'
};
context.startServiceExtensionAbility(want).then(() => {
hilog.info(DOMAIN_NUMBER, TAG, `js-test ServiceInteractive-- Succeeded in starting ServiceExtensionAbility, want: ${want.abilityName}`);
// // 成功启动后台服务
// promptAction.showToast({
// message: $r('app.string.SuccessfullyStartBackendService')
// });
}).catch((err) => {
hilog.error(DOMAIN_NUMBER, TAG, `Failed to start ServiceExtensionAbility. Code is ${err.code}, message is ${err.message}`);
});

View File

@ -4,7 +4,8 @@ import { getSyncData } from '../common/service/initable';
import writeObjectOutNew from './judgeNew';
import FileUtil from '../common/utils/File';
import tempRequest from '../common/utils/tempRequest';
import pasteboard from '@ohos.pasteboard';
import emitter from '@ohos.events.emitter';
let baseHost = globalThis.host;
@ -54,7 +55,6 @@ export async function writeObjectOut(params, filePath?: string): Promise<WR> {
//新监管调用
if (globalThis.isJGNew) {
return await writeObjectOutNew(params, filePath)
}
drvexam.zp = drvexam.zp === undefined ? undefined : encodeURIComponent(drvexam.zp)
@ -64,20 +64,20 @@ export async function writeObjectOut(params, filePath?: string): Promise<WR> {
.map((key: string) => (
`<${key}>${drvexam[key]}</${key}>`));
console.log('surenjun filePath=>', filePath);
if (filePath) {
const fileUtil = new FileUtil(globalThis.context);
await fileUtil.initFolder(filePath);
fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify({
xtlb, jkxlh, jkid, drvexam: { ...drvexam, zp: '' },
}) + `\n`);
}));
}
//对象转换成xml
const temp = await request({
host: globalThis.JGHOST,
url: '/dems_ws/services/TmriOutAccess?wsdl',
data: `<?xml version="1.0"?>
let temp
try {
let data = JSON.stringify({
host: globalThis.JGHOST,
url: '/dems_ws/services/TmriOutAccess?wsdl',
data: `<?xml version="1.0"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
@ -101,20 +101,60 @@ export async function writeObjectOut(params, filePath?: string): Promise<WR> {
</writeObjectOut>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`,
method: 'post',
xml: true
},)
method: 'post',
xml: true
})
try {
let systemPasteboard = pasteboard.getSystemPasteboard()
console.log('surenjun','1')
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, data)
await systemPasteboard.clear()
await systemPasteboard.setData(pasteData)
console.log('surenjun','2')
} catch (e) {
console.log("wzj pasteboard error", e, "项目代码:", params?.data.param?.ksxm)
}
let fn = () => {
return new Promise((resolve, reject) => {
let tick = setTimeout(() => {
emitter.emit({
eventId: 1
})
tick = null
reject({
code: 2300028,
message: "children process not response"
})
}, 20 * 1000)
console.log("wzj process start,项目代码:", params.data?.param?.ksxm)
globalThis.serviceExtProxy.processData("1", (errorCode: number, retVal: string) => {
console.log("lixiao process accept,项目代码:", params.data?.param?.ksxm, " 错误码:", errorCode, JSON.stringify(retVal))
if (tick != null) {
clearTimeout(tick)
let result = JSON.parse(retVal)
if (result.code === 0) {
resolve(result.data)
} else {
emitter.emit({
eventId: 1
})
reject(result.data)
}
}
});
})
}
temp = await fn()
} catch (e) {
console.log("旧监管错误")
temp = e
}
console.log("temp message: ", JSON.stringify(temp))
if (filePath) {
const fileUtil = new FileUtil(globalThis.context);
await fileUtil.initFolder(filePath);
fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(temp) + `\n`);
await fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(temp) + `\n`);
}
// const {code} = temp;
// if(code == '2300007' || code == '2300028'){
// return await writeObjectOut(params,filePath)
// }else{
// return temp
// }
return temp
}

View File

@ -1,8 +1,8 @@
import { getSyncData } from '../common/service/initable';
import request from "../common/utils/request"
let baseHost = globalThis.host;
import FileUtil from '../common/utils/File';
import FileLog from '../pages/judgeSDK/utils/fileLog';
import pasteboard from '@ohos.pasteboard';
import emitter from '@ohos.events.emitter';
//监管接口序列号映射
const gjxlhObj = {
@ -14,31 +14,37 @@ const gjxlhObj = {
'17C56': '02-21-000014',
}
interface WR{
message?:string
code:number
interface WR {
message?: string
code: number
}
export default async function writeObjectOutNew(data,filePath): Promise<WR> {
export default async function writeObjectOutNew(data, filePath): Promise<WR> {
const fileUtil = new FileUtil(globalThis.context);
const {jkid , drvexam} = data;
const { jkid, drvexam } = data;
const basic = await getBasicConfig(jkid);
const params = await getParams(jkid, drvexam);
const {wglb,jkxlh,glbm,jgbh,sjbs} = basic;
const { wglb, jkxlh, glbm, jgbh, sjbs } = basic;
if(filePath){
await fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`,JSON.stringify({
wglb,jkxlh,glbm,jgbh,sjbs,
data:params.data,
file:{...params.file,param:[]},
if (filePath) {
await fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify({
wglb,
jkxlh,
glbm,
jgbh,
sjbs,
data: params.data,
file: {
...params.file, param: []
},
}));
}
// let connectTimeout = sjbs === '02-21-000014' ?60000:1
console.info('surenjun','调用新监管')
console.info('surenjun', '调用新监管,项目代码:', params.data.param.ksxm)
let temp
try {
temp = await request({
let data = JSON.stringify({
host: globalThis.JGHOST,
method: 'post',
//是否是新中心
@ -64,13 +70,52 @@ export default async function writeObjectOutNew(data,filePath): Promise<WR> {
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>`,
})
try {
let systemPasteboard = pasteboard.getSystemPasteboard()
let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, data)
await systemPasteboard.clear()
await systemPasteboard.setData(pasteData)
} catch (e) {
console.log("wzj pasteboard error", e, "项目代码:", params.data.param.ksxm)
}
let fn = () => {
return new Promise((resolve, reject) => {
let tick = setTimeout(() => {
emitter.emit({
eventId: 1
})
tick = null
reject({
code: 2300028,
message: "children process not response"
})
}, 20 * 1000)
console.log("wzj process start,项目代码:", params.data.param.ksxm)
globalThis.serviceExtProxy.processData("1", (errorCode: number, retVal: string) => {
console.log("lixiao process accept,项目代码:", params.data.param.ksxm, " 错误码:", errorCode, JSON.stringify(retVal))
if (tick != null) {
clearTimeout(tick)
let result = JSON.parse(retVal)
if (result.code === 0) {
resolve(result.data)
} else {
emitter.emit({
eventId: 1
})
reject(result.data)
}
}
});
})
}
temp = await fn()
} catch (e) {
console.log("新监管错误")
temp = e
}
console.log("temp message: ", JSON.stringify(temp))
if(filePath){
await fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`,JSON.stringify(temp) +`\n`);
if (filePath) {
await fileUtil.editFile(`${filePath}/wuxi_exam_data.txt`, JSON.stringify(temp) + `\n`);
}
return temp
@ -189,7 +234,10 @@ export async function getParams(jkid, drvexam) {
sfzmhm: drvexam.sfzmhm
},
},
file: { sjbs: gjxlhObj[jkid], param: [{ field: '', data: drvexam.zp }] }
file: {
sjbs: gjxlhObj[jkid],
param: [{ field: '', data: drvexam.zp }]
}
}
default:

View File

@ -65,7 +65,6 @@ export default class AIO {
this.gpsFd = await OpenSerialPort(GlobalConfig.serialPortConfig.gps.path);
//初始化串口
await InitSerialPortData(this.gpsFd, 115200);
console.log('surenjun gpsFd=>',this.gpsFd)
ReceiveSerialPortDataBySelf(this.gpsFd, async (res1, res2, res3, res4) => {
// console.log(res1.toString(), res2.toString(), res3.toString(), "接受数据");
let buffer = this.arrayToBuffer(res3)

View File

@ -11,70 +11,100 @@ export default class UdpByOne {
// PLC localIp
private LocalIp: string = '192.168.7.170';
// PLC localIpPort
private PLCLocalIpPort: string = '31012';
private PLCLocalIpPort: number = 31012;
private OppositeIp: string = '192.168.7.124'
// PLC oppositeIpPort
private PLCOppositeIpPort: string = '30012';
private PLCOppositeIpPort: number = 30012;
// PLC消息
private PLCMsg: ArrayBuffer;
// GPS udp
private GPSUDP: any;
private GPSTCP: any;
// GPS localIp
// GPS localIpPort
private GPSLocalIpPort: string = '31013';
private GPSLocalIpPort: number = 31013;
// GPS oppositeIpPort
private GPSOppositeIpPort: string = '30013';
private GPSOppositeIpPort: number = 30013;
// GPS消息
private GPSMsg: any;
private timer: number;
public type: 1| 2
constructor(type) {
//一型机 二型机
public terType: 1 | 2
//板卡类型
public cardType: 0| 1 | 2
constructor(terType,cardType) {
this.terType = terType;
this.cardType = cardType;
this.init()
console.info('surenjun type=>',type +'')
this.type = type;
}
async init(){
const fileUtil = new FileUtil(globalThis.context)
const {terType,cardType} = this
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
const result = JSON.parse(data)
this.LocalIp = result.udplocalIp;
this.OppositeIp = result.udpOppositeIp;
this.OppositeIp = result.udpOppositeIp;
// 初始化UDP
this.PLCUDP = socket.constructUDPSocketInstance();
// this.PLCUDP.bind(this.PLCLocalIp, this.PLCLocalIpPort);
this.PLCUDP.bind({
address: this.LocalIp, port: parseInt(this.PLCLocalIpPort), family: 1
address: this.LocalIp, port: this.PLCLocalIpPort, family: 1
});
this.GPSUDP = socket.constructUDPSocketInstance();
// this.GPSUDP.bind(this.GPSLocalIp, this.GPSLocalIpPort);
this.GPSUDP.bind({
address: this.LocalIp, port: parseInt(this.GPSLocalIpPort), family: 1
});
this.PLCUDP.on("message", (res, remoteInfo) => {
this.PLCMsg = res.message;
})
this.GPSUDP.on("message", (res1, remoteInfo) => {
let dataView = new DataView(res1.message)
let str = ""
for (let i = 0; i < dataView?.byteLength; ++i) {
let c = String.fromCharCode(dataView?.getUint8(i))
if (c !== "\n") {
str += c
}
if(terType == 1 && cardType == 1){
this.GPSTCP = socket.constructTCPSocketInstance();
await this.GPSTCP.bind({address:this.LocalIp,port:this.GPSLocalIpPort,family: 1});
try {
await this.GPSTCP.connect({address:{
address:this.OppositeIp,port:this.GPSOppositeIpPort
}});
}catch (e) {
console.info('surenjun e=>',JSON.stringify(e))
}
this.GPSMsg = str;
})
console.info('surenjun=>','3')
this.GPSTCP.on("message", (res1, remoteInfo) => {
let dataView = new DataView(res1.message)
let str = ""
for (let i = 0; i < dataView?.byteLength; ++i) {
let c = String.fromCharCode(dataView?.getUint8(i))
if (c !== "\n") {str += c}
}
this.GPSMsg = str;
})
}else{
this.GPSUDP = socket.constructUDPSocketInstance();
// this.GPSUDP.bind(this.GPSLocalIp, this.GPSLocalIpPort);
await this.GPSUDP.bind({
address: this.LocalIp, port: this.GPSLocalIpPort, family: 1
});
this.GPSUDP.on("message", (res1, remoteInfo) => {
let dataView = new DataView(res1.message)
let str = ""
for (let i = 0; i < dataView?.byteLength; ++i) {
let c = String.fromCharCode(dataView?.getUint8(i))
if (c !== "\n") {
str += c
}
}
this.GPSMsg = str;
})
}
}
// 重新绑定
public rebind() {
this.PLCUDP.bind(this.LocalIp, this.PLCLocalIpPort);
this.GPSUDP.bind(this.LocalIp, this.GPSLocalIpPort);
this.PLCUDP.rebind(this.LocalIp, this.PLCLocalIpPort);
this.GPSUDP?.rebind(this.LocalIp, this.GPSLocalIpPort);
this.GPSTCP?.rebind(this.LocalIp, this.GPSLocalIpPort);
}
// PLC发送消息
@ -83,7 +113,7 @@ export default class UdpByOne {
data: '111111',
address: {
address: this.OppositeIp,
port: parseInt(this.PLCOppositeIpPort),
port: this.PLCOppositeIpPort,
}
})
}
@ -96,6 +126,7 @@ export default class UdpByOne {
// 处理消息
public handleMsg() {
let newMessage = PLCGPSData;
const cardType = this.cardType;
if (this.GPSMsg) {
let GPGGAMatch = this.GPSMsg.match(/\$GPGGA[^$]*/);
@ -106,10 +137,14 @@ export default class UdpByOne {
// 使用正则表达式提取$GPGST消息
let GPGSTMatch = this.GPSMsg.match(/\$GPGST[^$]*/);
let GPGSTMsgArr = GPGSTMatch ? GPGSTMatch[0]?.split(",").slice(0, 9) : [];
// 使用正则表达式提取$GPGST消息
let GNGSTMatch = this.GPSMsg.match(/\$GNGST[^$]*/);
let GNGSTMsgArr = GNGSTMatch ? GNGSTMatch[0]?.split(",").slice(0, 9) : [];
// 使用正则提取$PTNL消息
let PTNLMatch = this.GPSMsg.match(/\$PTNL[^$]*/);
let PTNLMsgArr = PTNLMatch ? PTNLMatch[0].split(",")?.slice(0, 14) : [];
// 组合GPS数据
// 状态83
newMessage[83] = GPGGAMsgArr[6];
@ -122,18 +157,20 @@ export default class UdpByOne {
// 龄期87
newMessage[87] = GPGGAMsgArr[13];
// 维度因子88
newMessage[88] = GPGSTMsgArr[6];
newMessage[88] = GPGSTMsgArr[6] || GNGSTMsgArr[6];
// 经度因子89
newMessage[89] = GPGSTMsgArr[7]
newMessage[89] = GPGSTMsgArr[7] || GNGSTMsgArr[7];
// 航向角90
newMessage[90] = PTNLMsgArr[3];
const hxj = Number(PTNLMsgArr[3])
newMessage[90] = (cardType == 0 ? hxj : ((hxj + 180 > 360) ?(hxj + 180 - 360): hxj + 180)).toFixed(4)
// newMessage[90] = PTNLMsgArr[3];
// 俯仰角91
newMessage[91] = PTNLMsgArr[5];
// 航向角状态-收星数92
newMessage[92] = PTNLMsgArr[10] + '-' + (PTNLMsgArr[12] && PTNLMsgArr[12].split('*')[0]);
// 年月日93 RMCMsgArr[9]为ddmmyy 日月年 转换为年月日
newMessage[93] =
GPRMCMsgArr[9] && (GPRMCMsgArr[9].slice(0, 2) + GPRMCMsgArr[9].slice(2, 4) + GPRMCMsgArr[9].slice(4, 6));
GPRMCMsgArr[9] && (GPRMCMsgArr[9].slice(0, 2) + GPRMCMsgArr[9].slice(2, 4) + GPRMCMsgArr[9].slice(4, 6));
// 时分秒94 GPGGAMsgArr[1]为021126.00去掉小数点后的时间
newMessage[94] = GPGGAMsgArr[1] && GPGGAMsgArr[1].replace(".", "");
// 经度95
@ -210,18 +247,19 @@ export default class UdpByOne {
newMessage[25] = ((Data29 << 24) + (Data30 << 16) + (Data31 << 8) + Data32).toString();
// 熄火次数 26
newMessage[26] = parseInt(PLCByteArr[33], 2) + '';
// 方向盘角度 27
// TODO 档位 磁档位为外接信号
newMessage[28] = (globalThis.chuankoMsg == '0' || globalThis.chuankoMsg == '' ||globalThis.chuankoMsg == undefined)?(parseInt(PLCByteArr[13], 2) + ''): globalThis.chuankoMsg;
if(this.type == 1){
if(this.terType == 1){
// 超声波1
newMessage[29] = (PLCByteArr[4][1] > 0 ? '300' : '1200')
// 超声波2
newMessage[30] = (PLCByteArr[4][0] > 0 ? '300': '1200' )
}
if(this.type == 2){
if(this.terType == 2){
newMessage[29] = (parseInt(PLCByteArr[52], 2) > 10) ? '1200' : '300'
newMessage[30] = (parseInt(PLCByteArr[54], 2) > 10) ? '1200': '300'
}

View File

@ -8,6 +8,8 @@ import GpsTcpClient from '../utils/GpsTcpClient'
export default class RearEndUnitsTool {
//一型机 二型机 三型机 一体机
public terType: 0 | 1 | 2 | 3 = 2;
//C1板卡 B4板卡
public cardType: 0 | 1;
public timer: number = 0
public diffTimer: number = 0
private UdpByOneClass: UdpByOne
@ -21,15 +23,18 @@ export default class RearEndUnitsTool {
public receiveMsg = (callBack)=> {
const terType = this.terType;
const cardType = this.cardType;
//TODO 临时处理关闭消息接收
this.cancelMsg()
switch (terType) {
//一型机
//一型机
case 0: {
const udpClass = this.getFUdp({
type: 1
})
terType: 1,
cardType,
});
this.timer = setInterval(() => {
const message = udpClass.handleMsg()
callBack && callBack(message)
@ -37,10 +42,11 @@ export default class RearEndUnitsTool {
}
break;
//二型机
//二型机
case 1: {
const udpClass = this.getFUdp({
type: 2
terType: 2,
cardType
})
this.timer = setInterval(() => {
const message = udpClass.handleMsg()
@ -50,14 +56,14 @@ export default class RearEndUnitsTool {
}
break;
//三型机
//三型机
case 2:
// this.timer = setInterval(() => {
// callBack && callBack(message)
// }, 200)
// break;
// this.timer = setInterval(() => {
// callBack && callBack(message)
// }, 200)
// break;
//一体机
//一体机
case 3:
const aioClass = this.getAio()
this.timer = setInterval(() => {
@ -88,13 +94,14 @@ export default class RearEndUnitsTool {
const result = JSON.parse(config || '{}')
//默认设置为三代机
this.terType = result.terType
this.cardType = result.cardType
return this.terType
}
//获取一型机&二型机单例
private getFUdp({type}) {
private getFUdp({terType,cardType}) {
if (!this.UdpByOneClass) {
this.UdpByOneClass = new UdpByOne(type);
this.UdpByOneClass = new UdpByOne(terType,cardType);
}
return this.UdpByOneClass;
}
@ -118,23 +125,29 @@ export default class RearEndUnitsTool {
// 转发差分改正数
public sendDiffCorrections = (message) => {
const type = this.terType
const cardType = this.cardType
//差分改正数截取前5位
let dataView = new DataView(message)
const Arraybuffer = message.slice(5, dataView?.byteLength);
switch (type){
//一型机
//一型机
case 0:
const GpsTcpClientClass = this.getGpsTcp()
GpsTcpClientClass.sendGpsMsg(Arraybuffer);break
//天宝类型板卡
if(cardType === 1){
globalThis.udpClient?.sendMsg(Arraybuffer);break
}else{
const GpsTcpClientClass = this.getGpsTcp()
GpsTcpClientClass.sendGpsMsg(Arraybuffer);break
}
//二型机
//二型机
case 1: globalThis.udpClient?.sendMsg(Arraybuffer);break
//三型机
//三型机
case 2: globalThis.udpClient?.sendMsg(Arraybuffer);break
//一体机的差分不需要截取
//一体机的差分不需要截取
case 3: this.diffData = message;break
}

View File

@ -7,6 +7,7 @@ import { takePhoto, deleteAllFileByPiC } from '../../common/service/videoService
// import { VideoConfigData } from '../../mock';
import request from '@ohos.request'
import Prompt from '@system.prompt';
import util from '@ohos.util';
import {
delSyncTable,
@ -453,7 +454,8 @@ function getChuankouFnMsg() {
testNapi.SerialRecvAsync(globalThis.fd, timeout, (revTestInfo) => {
const message = revTestInfo?.recevedBuf?.toString()
if (message == '') {
let msgBuf = util.TextDecoder.create().decodeWithStream(new Uint8Array(revTestInfo?.recevedBuf))
if (message == '' || msgBuf == '') {
globalThis.num = 1
// clearInterval(chuankou)
testNapi.SerialClose(globalThis.fd);
@ -464,16 +466,8 @@ function getChuankouFnMsg() {
return
}
const msg = message?.split(',')
if (!msg?.length) {
} else if (msg[0] != '98' || msg[1] != '85' || msg.length < 9) {
} else if (msg.length < 12) {
} else {
globalThis.chuankoMsg = msg[9]
}
let dang = Number(msgBuf?.split(",")?.[1]?.split('\r')[0] || 0)
globalThis.chuankoMsg =( msg[9] === '' || msg[9] >10 ) ? dang: msg[9]
setTimeout(() => {
getChuankouFnMsg()
}, 500)

View File

@ -458,7 +458,7 @@ export async function upDataZhongxinginitialization(param) {
resolve(true)
}).catch((Error) => {
console.log("init table5", JSON.stringify(Error))
resolve(Error.initializationRsp.head)
resolve(Error?.initializationRsp?.head || false)
})
} catch (error) {
console.log("init table6", JSON.stringify(error))

View File

@ -224,7 +224,10 @@ export async function getUDP2(context, errorFlag?) {
}else if(val.id == '39'){
//确定远程终止
const lsh = val.body.map(byte => String.fromCharCode(byte)).join('')
console.log( 'surenjun 远程终止考试lsh=>', lsh )
console.log( 'surenjun globalThis.lsh', globalThis.lsh )
if( lsh == globalThis.lsh ){
console.log( 'surenjun 开始执行远程终止考试', lsh )
globalThis.udpEvent.sendStopExam()
globalThis.judgeUdp.confirmStopExam(globalThis.signNum)
}

View File

@ -380,7 +380,6 @@ export default class UdpClientByCenter {
}
// console.info('surenjun2','set message_1Fn=>' + newArr.toString())
callback && callback(newArr.toString())
console.info('surenjun 左方向灯=>', newArr.toString())
this.currentValue = newArr.toString();
} else {
callback && callback('')

View File

@ -83,7 +83,7 @@ export default class JudgeEmitter {
}
public onStopExam = async (callBack?: Function) => {
console.info('surenjun', '注册远程扣分考试事件')
console.info('surenjun', '注册远程终止考试事件')
this.stopExam = callBack
}
@ -111,6 +111,7 @@ export default class JudgeEmitter {
//结束考试
public sendStopExam = async () => {
console.info('surenjun emit', 'EVENTID.stopExamEventId')
emitter.emit({
eventId: EVENTID.stopExamEventId
}, {

View File

@ -289,15 +289,15 @@ const getDwStatusType = (dw)=> {
case 3: return [0,0,1,1]
case 4: return [0,1,0,0]
case 5: return [0,1,0,1]
//R档
//R档
case 9: return [1,0,0,1]
//P档位
//P档位
case 10: return [1,0,1,0]
//D档
//D档
case 11: return [1,0,1,1]
//S档
//S档
case 12: return [1,1,0,0]
//M档
//M档
case 13: return [1,1,0,1]
default :return [0,0,0,0]
}

View File

@ -99,14 +99,14 @@ export default async function tempRequest<T>(req: any): Promise<T> {
reject(res)
}
}).catch(Error => {
console.info('test-error0' + url + ' error:resp: ' + JSON.stringify(Error.message))
httpRequest.destroy();
Prompt.showToast({
message: Error?.message,
duration: 5000
});
reject(Error)
})
console.info('test-error0' + url + ' error:resp: ' + JSON.stringify(Error.message))
httpRequest.destroy();
Prompt.showToast({
message: Error?.message,
duration: 5000
});
reject(Error)
})
} catch (e) {
console.info('test-error' + url + ' error:resp: ' + JSON.stringify(e))

View File

@ -10,7 +10,7 @@ import { GlobalConfig } from '../config/global'
import { tcpUtil } from '../common/utils/TcpRequest';
import DB from '../common/database/DbSql';
import { initTable } from '../common/service/initable';
import Want from '@ohos.app.ability.Want';
export default class EntryAbility extends UIAbility {
async onCreate(want, launchParam) {
try {
@ -26,10 +26,16 @@ export default class EntryAbility extends UIAbility {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
}
onDestroy() {
async onDestroy() {
const arrClose = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00]
const arrCloseBuffer = Array2Byte(arrClose).buffer
globalThis?.lightLineUdp?.send(arrCloseBuffer);
let want: Want = {
deviceId: '',
bundleName: 'com.oh.dts',
abilityName: 'ServiceExtAbility'
};
await this.context.stopServiceExtensionAbility(want)
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}
@ -51,6 +57,7 @@ export default class EntryAbility extends UIAbility {
globalThis.judgeVersion = GlobalConfig.version.wx.km2[1];
globalThis.tcpSendNum = 0
globalThis.videoVersion = '1.0'
globalThis.tcpStep=0
//视频遮挡
globalThis.spzd = {
@ -72,9 +79,8 @@ export default class EntryAbility extends UIAbility {
const windowClass = await windowStage.getMainWindow();
globalThis.windowClass = windowClass
// await windowClass.setWindowLayoutFullScreen(true)
// await windowClass.setWindowSystemBarEnable([]) //全屏
await windowClass.setWindowSystemBarEnable(['navigation'])
await windowClass.setWindowLayoutFullScreen(true)
await windowClass.setWindowSystemBarEnable([]) //全屏
windowStage.loadContent('pages/Index', (err, data) => {
if (err.code) {

View File

@ -20,6 +20,10 @@ import { delPic } from '../common/service/videoService';
import imageBtn from './compontents/imageBtn';
import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements';
import {updateModelAndCar} from '../common/autoUpdate/index'
import IdlServiceExtProxy from '../IdlServiceExt/idl_service_ext_proxy';
import Want from '@ohos.app.ability.Want';
import emitter from '@ohos.events.emitter';
// import {uploadLogFile} from '../common/service/indexService'
import { getModalValueCdAndCar } from '../api';
@ -29,7 +33,6 @@ import { getModalValueCdAndCar } from '../api';
@Component
struct Index {
@State carNum: string = ''
@State version: string = ''
@State url: string = ''
@State hasAuth: boolean = false;
@State dialogVisiable: boolean = false;
@ -46,6 +49,9 @@ struct Index {
@State num: number = 0;
//模型是否下载
@State isModelInit: boolean = false;
@State judgeVersion: string = ""
private version: string = judgeConfig.version
fileHelper = null;
errorDialog: CustomDialogController = new CustomDialogController({
builder: errorMsgDialog({
@ -66,6 +72,7 @@ struct Index {
private avPlayer
private workerInstance = null;
private context = getContext(this) as common.UIAbilityContext;
private serviceExtProxy: IdlServiceExtProxy
@Styles
commStyle(){
@ -364,20 +371,24 @@ struct Index {
}
async aboutToAppear() {
// setInterval(() => {
// let date = new Date();
// console.info('jiangsong1:timeSynchronization begin ');
// uploadProgressData()
// let params = {
// time: dateFormat(date),
// deviceNo: globalThis.deviceNo,
// version: globalThis.version,
// judgeVersion: globalThis.judgeVersion
// }
// timeSynchronizationHTTP(params)
// }, 1000)
console.log('diyidiy')
emitter.on({
eventId: 1
}, async () => {
let want: Want = {
deviceId: '',
bundleName: 'com.oh.dts',
abilityName: 'ServiceExtAbility'
};
try {
console.log("lixiao, 开始重启服务")
await this.context.stopServiceExtensionAbility(want)
await this.startServiceAbility()
console.log("lixiao, 重启服务成功")
} catch (e) {
console.log("lixiao, 重启服务失败", JSON.stringify(e))
}
})
await this.startServiceAbility()
this.avPlayer = new VoiceAnnounce();
this.initParamFlag = false
@ -410,6 +421,55 @@ struct Index {
}
async startServiceAbility() {
let want: Want = {
deviceId: '',
bundleName: 'com.oh.dts',
abilityName: 'ServiceExtAbility'
};
await this.context.startServiceExtensionAbility(want).then(() => {
// 成功启动后台服务
console.log('js-test index.ets Succeeded in starting ServiceExtensionAbility.');
let self = this;
let options: common.ConnectOptions = {
onConnect(elementName, remote): void {
console.log('js-test index.ets onConnect callback');
if (remote === null) {
console.log(`js-test index.ets onConnect remote is null`);
return;
}
self.serviceExtProxy = new IdlServiceExtProxy(remote);
globalThis.serviceExtProxy = self.serviceExtProxy
console.log(`js-test index.ets processData, this.serviceExtProxy == `, self.serviceExtProxy);
// 通过接口调用的方式进行通信屏蔽了RPC通信的细节简洁明了
// self.serviceExtProxy.processData(1, (errorCode: number, retVal: object) => {
// console.log(`js-test index.ets processData, errorCode: ${errorCode}, retVal: ${retVal}`);
// });
},
onDisconnect(elementName): void {
console.log('js-test index.ets onDisconnect callback');
},
onFailed(code): void {
console.log('js-test index.ets onFailed callback', JSON.stringify(code));
}
}
// 建立连接后返回的Id需要保存下来在解绑服务时需要作为参数传入
// let connectionId = context.connectServiceExtensionAbility(want, options);
try {
this.context.connectServiceExtensionAbility(want, options);
} catch (e) {
console.log('js-test index.ets connectServiceExtensionAbility err == ', JSON.stringify(e));
}
// 成功连接后台服务
console.log('js-test index.ets connectServiceExtensionAbility success');
}).catch((err) => {
console.log(`js-test index.ets Failed to start ServiceExtensionAbility. Code is ${err.code}, message is ${err.message}`);
});
}
aboutToDisappear() {
// this.vocObj && this.vocObj.releasePlayer()
}
@ -502,6 +562,9 @@ struct Index {
})
});
}else{
this.loading = false
this.loadingText = ''
}
})
// workerInstance.postMessage(param);

View File

@ -331,8 +331,6 @@ struct Index {
//真实监管下发考试项目
if (isInExam && !(kStringArr.includes(txt2) || kStringArr.includes(no2 + ''))) {
console.info('surenjun =>', txt2)
console.info('surenjun => no2', no2)
this.projectsObj[no2*1].type = '3'
this.projectsObj[no2*1].isUpload = true
this.projectsObj[no2*1].isEnd = true

View File

@ -21,8 +21,10 @@ struct Index {
// @State inputTextList1: string[] = ['172.37.55.191','18782','192.168.7.1','8082','255.255.255.0','192.168.7.170','114.114.114.114','192.168.7.124','20022','172.37.55.59','20122']
@State inputTextList1: string[] = ['172.37.55.191', '18782', '172.37.55.191', '8082', '255.255.255.0', '192.168.7.1', '114.114.114.114', '192.168.7.124', '20022', '192.168.7.170', '20122']
@State terTextList: string[] = ['一型机', '二型机', '三型机', '一体机']
@State cardTextList: string[] = ['北云', '天宝MB2']
@State netTextList: string[] = ['否', '是']
@State selectedTerType: number = 0
@State selectedCardType: number = 0
//是否启用网络差分
@State netOpen: number = 0
// @State inputTextList2: string[] = []
@ -94,6 +96,7 @@ struct Index {
})
}.width('50%').height('14%')
Row() {
Text('是否启用网络差分')
.width('40%')
@ -113,7 +116,30 @@ struct Index {
})
Text(netText).fontSize(20).fontColor('#FFF')
})
}.width('52%').height('14%')
}.width('51%').height('14%')
Row(){
Text('板卡类型')
.width('40%')
.height('100%')
.fontColor('#E5CBA1')
.padding({ 'left': '35px' })
.fontSize(this.inputFontSize * this.ratio)
ForEach(this.cardTextList, (cardText, index) => {
Radio({ value: cardText, group: 'cardRadioGroup' })
.borderColor('#E5CBA1')
.checked(index === this.selectedCardType)
.onChange((value: boolean) => {
if(value){
this.selectedCardType = index
}
})
Text(cardText).fontSize(20).fontColor('#FFF')
})
}.width('49%').height('14%')
}
}
.width('95%')
@ -145,6 +171,7 @@ struct Index {
centerIp: this.inputTextList1[2],
centerPort: this.inputTextList1[3],
terType: this.selectedTerType,
cardType: this.selectedCardType,
netOpen: this.netOpen
}
fileUtil.addFile(`${folderPath}/ipConfig.txt`, JSON.stringify(param), '')
@ -218,6 +245,7 @@ struct Index {
this.inputTextList1[2] = result.centerIp
this.inputTextList1[3] = result.centerPort
this.selectedTerType = result.terType
this.selectedCardType = result.cardType
this.netOpen= result.netOpen
console.log('surenjun', this.selectedTerType + '');
}

View File

@ -755,12 +755,12 @@ struct UserInfo {
// globalThis.ksyh = this.currentUser.ksy1sfzmhm
// }, 200)
// } else {
setTimeout(() => {
this.currentUser = this.dataList[0]
this.currentUser.ksy2 = globalThis.kgxm
globalThis.ksyh = this.currentUser.ksy1sfzmhm
globalThis.lsh = this.currentUser.lsh
}, 200)
setTimeout(() => {
this.currentUser = this.dataList[0]
this.currentUser.ksy2 = globalThis.kgxm
globalThis.ksyh = this.currentUser.ksy1sfzmhm
globalThis.lsh = this.currentUser.lsh
}, 200)
// }
} else {
this.currentUser = EmptyCandidateObject

View File

@ -3,8 +3,9 @@ import Judge from '../../judgeSDK/utils/judgeReal';
import { MarkRule, Project, ProjectObj } from '../../judgeSDK/api/judgeSDK.d';
import common from '@ohos.app.ability.common';
import {
examJudgeMapSetScaling
examJudgeMapSetScaling, examJudgeVersion
} from '../../judgeSDK/api'
import { judgeConfig } from '../../judgeSDK/utils/judgeConfig';
interface RoadDataType {
name: string,
@ -30,6 +31,8 @@ export default struct RealTime {
@State ratio: number = 1
@State lane: Object = {}
@State timer:number = 0
@State version: string = ""
constructor() {
super()
@ -67,22 +70,28 @@ export default struct RealTime {
Column() {
if (this.draw) {
XComponent({
id: 'duolun_plugin_id_draw', //显示轨迹窗口id名称注意这个ID要和C++侧一致,不能变
type: 'surface',
libraryname: 'JudgeSdk'
// libraryname: 'judgesdk'
})
.width(this.widthNumber)
.height(this.heightNumber)
.onLoad(() => {
apiJudgeSdk.examJudgeMapSetDrawing(true); //停止绘制地图轨迹false:表示结束绘制
})
.onDestroy(() => {
apiJudgeSdk.examJudgeMapSetDrawing(false); //停止绘制地图轨迹false:表示结束绘制
this.draw = false;
clearInterval(globalThis.realTimer)
Stack({ alignContent: Alignment.TopEnd }) {
XComponent({
id: 'duolun_plugin_id_draw', //显示轨迹窗口id名称注意这个ID要和C++侧一致,不能变
type: 'surface',
libraryname: 'JudgeSdk'
})
.width(this.widthNumber)
.height(this.heightNumber)
.onLoad(() => {
apiJudgeSdk.examJudgeMapSetDrawing(true); //停止绘制地图轨迹false:表示结束绘制
})
.onDestroy(() => {
apiJudgeSdk.examJudgeMapSetDrawing(false); //停止绘制地图轨迹false:表示结束绘制
this.draw = false;
clearInterval(globalThis.realTimer)
})
}.width(this.widthNumber)
.height(this.heightNumber)
Row() {
Text(this.version).margin({ right: 10 }).fontSize(14).fontColor(0x333333)
}
} else {
Column() {
}
@ -108,7 +117,10 @@ export default struct RealTime {
async aboutToDisappear() {
clearInterval(this.timer)
}
async aboutToAppear() {
this.version = (await examJudgeVersion()) + "/" + judgeConfig.version
const judge = new Judge(this)
let timer = setInterval(()=>{
this.lane = globalThis.laneData;

File diff suppressed because it is too large Load Diff

View File

@ -60,15 +60,15 @@ export function getDwStatusType(dw){
case 3: return [0,0,1,1]
case 4: return [0,1,0,0]
case 5: return [0,1,0,1]
//R档
//R档
case 9: return [1,0,0,1]
//P档位
//P档位
case 10: return [1,0,1,0]
//D档
//D档
case 11: return [1,0,1,1]
//S档
//S档
case 12: return [1,1,0,0]
//M档
//M档
case 13: return [1,1,0,1]
default :return [0,0,0,0]
}

View File

@ -1,5 +1,6 @@
//考试回放开关
export const judgeConfig = {
version:'2024.08.21.01',
//本地目录开关
isTrajectoryOpen: false,
//是否开启拍照

View File

@ -34,7 +34,7 @@ export default class JudgeTask {
message: '过程任务执行失败=>' + JSON.stringify(e),
duration: 3000
});
res(false)
res(e)
}
}, isDelay ? delayTime : 0);
})