fix: TCP UDP中心通
This commit is contained in:
parent
9e9b34c0b4
commit
0f95021737
@ -78,13 +78,10 @@ struct Index {
|
||||
async onPageShow(): Promise<void> {
|
||||
console.log("首页 onPageShow")
|
||||
await UseAuth(this.context)
|
||||
// DifferentialAndSignal.init()
|
||||
DifferentialAndSignal.onMsg(() => {
|
||||
console.log("外层接受")
|
||||
})
|
||||
this.avPlayer.playAudio(['welcome.wav'])
|
||||
this.baseInfo = AppStorage.get<BaseInfoType>('baseInfo')!
|
||||
this.initParams()
|
||||
|
||||
AppStorage.setOrCreate('singlePlay', false)
|
||||
this.num = 0
|
||||
AppStorage.setOrCreate('lsh', '1111111111111')
|
||||
@ -181,12 +178,6 @@ struct Index {
|
||||
console.log("test1111")
|
||||
await GetDeviceInfo(this.context)
|
||||
this.carInfo = await GetCarInfo()
|
||||
// TODO
|
||||
// CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => {
|
||||
// if (data.id == 32) {
|
||||
// AppStorage.setOrCreate('signNum', data.body[1])
|
||||
// }
|
||||
// },)
|
||||
this.carInfo = AppStorage.get<CarInfoType>('carInfo')!
|
||||
this.deviceId = this.carInfo.carNo || ""
|
||||
await SetCurrentTime()
|
||||
@ -199,6 +190,11 @@ struct Index {
|
||||
// TODO
|
||||
// CenterUDPBusinessInstance.startHeartBeat()
|
||||
CreateAlbum(this.fileHelper)
|
||||
// 启动worker通道
|
||||
DifferentialAndSignal.init()
|
||||
DifferentialAndSignal.onMsg(() => {
|
||||
console.log("外层接受")
|
||||
})
|
||||
}
|
||||
|
||||
build() {
|
||||
|
||||
@ -53,6 +53,7 @@ export async function GetCarInfo(): Promise<CarInfoType> {
|
||||
if (res.obtainCarExamInfoRsp && res.obtainCarExamInfoRsp.body) {
|
||||
const carInfo: ObtainCarExamInfoRspBody = res?.obtainCarExamInfoRsp?.body!
|
||||
carInfo.plateNo = decodeURIComponent(carInfo.plateNo)
|
||||
console.log("Worker received message car", JSON.stringify(carInfo))
|
||||
AppStorage.setOrCreate('carInfo', carInfo)
|
||||
return carInfo
|
||||
}
|
||||
|
||||
25
entry/src/main/ets/utils/SerialNumber.ets
Normal file
25
entry/src/main/ets/utils/SerialNumber.ets
Normal file
@ -0,0 +1,25 @@
|
||||
// 流水号生成获取
|
||||
class SerialNumber {
|
||||
private serialNumber: string = "000000";
|
||||
|
||||
// 生成流水号(外部手动调用)
|
||||
generate() {
|
||||
let num = Number(this.serialNumber) + 1;
|
||||
if (num > 999999) {
|
||||
num = 0; // 超过 999999 时重置为 000000
|
||||
}
|
||||
this.serialNumber = num.toString().padStart(6, "0");
|
||||
}
|
||||
|
||||
// 获取当前流水号
|
||||
get() {
|
||||
return this.serialNumber;
|
||||
}
|
||||
|
||||
// 重置流水号(可选)
|
||||
reset() {
|
||||
this.serialNumber = "000000";
|
||||
}
|
||||
}
|
||||
|
||||
export const SerialNumberInstance = new SerialNumber();
|
||||
@ -139,6 +139,7 @@ export default class UdpClient {
|
||||
private bindEvent() {
|
||||
this.udp?.on("message", value => {
|
||||
let result = this.dealMethod?.(value.message)
|
||||
console.log(UDPTag, "中心返回消息", result)
|
||||
this.messageEvents.forEach(cb => {
|
||||
cb(result)
|
||||
})
|
||||
|
||||
@ -38,12 +38,10 @@ class CenterUDPBusiness {
|
||||
}
|
||||
|
||||
startHeartBeat() {
|
||||
console.log("心跳")
|
||||
// 组装消息,一秒发送一次
|
||||
this.timer = setInterval(() => {
|
||||
SetSerialNumber()
|
||||
// const signNum = AppStorage.get<number>('signNum')
|
||||
// const statue = AppStorage.get<string>('statue')
|
||||
// const lsh = AppStorage.get<string>('lsh')
|
||||
const arr = [this.signNum || 0, this.statue || 1]
|
||||
let tmpList: number[] = [];
|
||||
tmpList.push(NumberToByteArray(Number(arr[0]), 1 * 8)[0])
|
||||
@ -52,7 +50,6 @@ class CenterUDPBusiness {
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
tmpList.push(NumberToByteArray(str.charCodeAt(i), 1 * 8)[0])
|
||||
}
|
||||
// const carInfo = AppStorage.get<CarInfoType>('carInfo')!
|
||||
const data: UDPParamType = {
|
||||
id: 31,
|
||||
list: tmpList,
|
||||
@ -60,6 +57,7 @@ class CenterUDPBusiness {
|
||||
placeId: this.carInfo.examinationRoomId!
|
||||
}
|
||||
const param = this.setWholeMsg(data)
|
||||
console.log("查看")
|
||||
this.udp.sendMsg(param);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// 处理worker线程的消息tcp拿差分改正数,udp给后置机
|
||||
import worker, { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope } from '@ohos.worker';
|
||||
import { WorkerTag } from '../config';
|
||||
import { CenterCallBackMsgType, WorkerBackMessage, WorkerMessage } from '../model';
|
||||
import { WorkerMessage } from '../model';
|
||||
import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness';
|
||||
import { DifferentialSignal } from '../utils/business/DifferentialSignal';
|
||||
import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness';
|
||||
@ -21,15 +21,15 @@ workerPort.onmessage = (e: MessageEvents) => {
|
||||
DifferentialSignal.init(result.config);
|
||||
DifferentialSignal.sendData()
|
||||
// 初始化后置机UDP
|
||||
ObtainUdpBusinessInstance.init(result.config)
|
||||
// ObtainUdpBusinessInstance.init(result.config)
|
||||
// 初始化中心UDP
|
||||
CenterUDPBusinessInstance.init(result.config, result.carInfo, result.otherMessage)
|
||||
// 中心心跳
|
||||
CenterUDPBusinessInstance.startHeartBeat()
|
||||
// 如果外部有这个消息进来就开始给中心发送
|
||||
if (result.udpParam) {
|
||||
CenterUDPBusinessInstance.sendData(result.udpParam);
|
||||
}
|
||||
// if (result.udpParam) {
|
||||
// CenterUDPBusinessInstance.sendData(result.udpParam);
|
||||
// }
|
||||
// 获取TCP差分改正数信号
|
||||
DifferentialSignal.getData((data: ArrayBuffer) => {
|
||||
console.log(WorkerTag, "Received differential signal data:", data.byteLength, "bytes")
|
||||
@ -37,29 +37,29 @@ workerPort.onmessage = (e: MessageEvents) => {
|
||||
ObtainUdpBusinessInstance.sendData(data)
|
||||
})
|
||||
// 监听PLC和GPS信号
|
||||
ObtainUdpBusinessInstance.onMsg((data: string) => {
|
||||
// TODO
|
||||
// 需要观察
|
||||
console.log(WorkerTag, "后置机消息", data)
|
||||
// 收到后置机消息传出去提供给业务,data应该是个string
|
||||
workerPort.postMessage(
|
||||
JSON.stringify({
|
||||
type: 'obtainUdpData',
|
||||
data: data
|
||||
} as WorkerBackMessage))
|
||||
})
|
||||
CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => {
|
||||
// TODO
|
||||
// 需要观察
|
||||
console.log(WorkerTag, "中心消息", data)
|
||||
// 收到中心指令发送出去
|
||||
workerPort.postMessage(
|
||||
JSON.stringify({
|
||||
type: 'centerUdpData',
|
||||
data: data
|
||||
} as WorkerBackMessage)
|
||||
)
|
||||
})
|
||||
// ObtainUdpBusinessInstance.onMsg((data: string) => {
|
||||
// // TODO
|
||||
// // 需要观察
|
||||
// console.log(WorkerTag, "后置机消息", data)
|
||||
// // 收到后置机消息传出去提供给业务,data应该是个string
|
||||
// workerPort.postMessage(
|
||||
// JSON.stringify({
|
||||
// type: 'obtainUdpData',
|
||||
// data: data
|
||||
// } as WorkerBackMessage))
|
||||
// })
|
||||
// CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => {
|
||||
// // TODO
|
||||
// // 需要观察
|
||||
// console.log(WorkerTag, "中心消息", data)
|
||||
// // 收到中心指令发送出去
|
||||
// workerPort.postMessage(
|
||||
// JSON.stringify({
|
||||
// type: 'centerUdpData',
|
||||
// data: data
|
||||
// } as WorkerBackMessage)
|
||||
// )
|
||||
// })
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user