Compare commits
No commits in common. "f140274c922671fe7ba74729f40324e43f2d2e9a" and "5efb9cd735f7547382fdf449d4363ea652e4c000" have entirely different histories.
f140274c92
...
5efb9cd735
@ -1,11 +1,6 @@
|
||||
{
|
||||
"apiType": "stageMode",
|
||||
"buildOption": {
|
||||
sourceOption: {
|
||||
"workers": [
|
||||
'./src/main/ets/workers/DifferentialCorrection.ets'
|
||||
]
|
||||
}
|
||||
},
|
||||
"buildOptionSet": [
|
||||
{
|
||||
|
||||
@ -28,7 +28,4 @@ export const FileHelpTag = '[FileHelp]';
|
||||
export const RequestTag = '[Request]';
|
||||
|
||||
//entry tag
|
||||
export const EntryTag = '[Entry]';
|
||||
|
||||
//worker tag
|
||||
export const WorkerTag = '[Worker]';
|
||||
export const EntryTag = '[Entry]';
|
||||
@ -12,7 +12,7 @@ export const GlobalConfig: GlobalConfigType = {
|
||||
commonFileWriteAddress: '/mnt/hmdfs/100/account/device_view/local/files/duolun',
|
||||
picSavePath: '/storage/cloud/100/files/Photo/',
|
||||
videoSavePath: '/storage/cloud/100/files/Videos/',
|
||||
host: 'http://192.168.32.105:8089',
|
||||
host: 'http://172.37.55.192:8082',
|
||||
modelNo: "3",
|
||||
version: {
|
||||
//杭州
|
||||
|
||||
@ -10,9 +10,9 @@ import { JudgeConfigType } from '../model'
|
||||
|
||||
|
||||
//考试回放开关
|
||||
export const JudgeConfig: JudgeConfigType = {
|
||||
export const JudgeConfig:JudgeConfigType = {
|
||||
//本地目录开关
|
||||
isTrajectoryOpen: false,
|
||||
isTrajectoryOpen: true,
|
||||
//是否开启拍照
|
||||
isPhotoOpen: true,
|
||||
//扣分语音是否强制开启
|
||||
|
||||
@ -170,7 +170,7 @@ interface VersionInfo {
|
||||
}
|
||||
|
||||
|
||||
export interface CenterCallBackMsgType {
|
||||
export interface centerCallBackMsgType {
|
||||
id: number;
|
||||
length: number;
|
||||
body: number[];
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
export interface TakePhotoCallbackData {
|
||||
fileSize: number
|
||||
fileSize: number;
|
||||
errorCode: number
|
||||
}
|
||||
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
import { CarInfoType, CenterCallBackMsgType, EnvironmentConfigurationType, UDPParamType } from '.';
|
||||
|
||||
export interface WorkerMessage {
|
||||
config: EnvironmentConfigurationType;
|
||||
carInfo: CarInfoType;
|
||||
udpParam?: UDPParamType;
|
||||
otherMessage: OtherMessageType;
|
||||
}
|
||||
|
||||
export interface OtherMessageType {
|
||||
signNum: number;
|
||||
statue: string;
|
||||
lsh: string;
|
||||
}
|
||||
|
||||
export interface WorkerBackMessage {
|
||||
type: string;
|
||||
data: string | CenterCallBackMsgType
|
||||
}
|
||||
@ -19,5 +19,3 @@ export * from "./api"
|
||||
export * from "./TableColumn"
|
||||
|
||||
export * from "./Other"
|
||||
|
||||
export * from "./Worker"
|
||||
@ -3,13 +3,15 @@ import router from '@ohos.router';
|
||||
|
||||
import { JudgeConfig } from '../config';
|
||||
import VoiceAnnounce from './judgeSDK/utils/voiceAnnouncements';
|
||||
import { BaseInfoType } from '../model/Common';
|
||||
import { BaseInfoType, centerCallBackMsgType } from '../model/Common';
|
||||
import { CarInfoType, InitializeTheCentralTableType, MASYSSETTableType, TimeSynchronizationRspBody } from '../model';
|
||||
import { CreateAlbum, GetCarInfo, GetDeviceInfo, SetCurrentTime, UseAuth } from './Index/utils';
|
||||
import { GetSyncData, InitializeTheCentralTable } from '../utils/table/Operation';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import { delPic } from '../utils/Video';
|
||||
import { FileHelper } from '../utils/FileHelp';
|
||||
import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness';
|
||||
import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness';
|
||||
import { DrivingDataStorage } from '../utils/business/DrivingDataStorage';
|
||||
import { JudgeUdpBusinessInstance } from '../utils/business/JudgeUdpBusiness';
|
||||
import { JudgeEmitterInstance } from '../utils/business/UdpEvent';
|
||||
@ -18,7 +20,6 @@ import CardComponent from './Index/Card';
|
||||
import BottomMessageComponent from './Index/BottomMessage';
|
||||
import LoadingComponent from './Index/Loading';
|
||||
import Prompt from '@system.prompt';
|
||||
import { DifferentialAndSignal } from '../utils/business/DifferentialAndSignal';
|
||||
|
||||
|
||||
@Entry
|
||||
@ -59,7 +60,6 @@ struct Index {
|
||||
}
|
||||
|
||||
async aboutToAppear() {
|
||||
console.log("首页 aboutToAppear")
|
||||
await UseAuth(this.context)
|
||||
this.ratio = AppStorage.get<BaseInfoType>('baseInfo')?.ratio || 1.4
|
||||
this.angle = 0
|
||||
@ -76,12 +76,7 @@ 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()
|
||||
@ -179,14 +174,15 @@ struct Index {
|
||||
|
||||
async initParams() {
|
||||
console.log("test1111")
|
||||
ObtainUdpBusinessInstance.init();
|
||||
await GetDeviceInfo(this.context)
|
||||
this.carInfo = await GetCarInfo()
|
||||
// TODO
|
||||
// CenterUDPBusinessInstance.onMsg((data: CenterCallBackMsgType) => {
|
||||
// if (data.id == 32) {
|
||||
// AppStorage.setOrCreate('signNum', data.body[1])
|
||||
// }
|
||||
// },)
|
||||
CenterUDPBusinessInstance.init();
|
||||
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()
|
||||
@ -209,7 +205,6 @@ struct Index {
|
||||
HeaderComponent({
|
||||
shortLogo: false
|
||||
})
|
||||
|
||||
CardComponent({
|
||||
isSingle: this.singlePlay,
|
||||
singleClick: () => {
|
||||
|
||||
@ -164,5 +164,3 @@ export function CreateAlbum(fileHelper: FileHelper) {
|
||||
fileHelper.createAlbum('pz');
|
||||
fileHelper.createAlbum(date);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { GPSData, SignalData } from '../mock';
|
||||
import { SignalDataType } from '../model';
|
||||
import SignalDisplayComponent from './compontents/SignalDisplay';
|
||||
import signDisplayCom from './compontents/SignDisplayCom';
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
@ -14,12 +14,12 @@ struct Index {
|
||||
@State @Watch('outClick') outFlag: boolean = false;
|
||||
@State url: string = ''
|
||||
|
||||
// @State gpsList: Array<any> = []
|
||||
build() {
|
||||
Column() {
|
||||
// signDisplayCom({
|
||||
// showBack: true
|
||||
// })
|
||||
SignalDisplayComponent()
|
||||
signDisplayCom({
|
||||
showBack: true
|
||||
})
|
||||
}
|
||||
.width('100%')
|
||||
.height('100%')
|
||||
|
||||
@ -96,7 +96,7 @@ struct Index {
|
||||
this.fileUtil.addFile(`${folderPath}/ipConfig.txt`, JSON.stringify(param))
|
||||
AppStorage.setOrCreate<EnvironmentConfigurationType>("EnvironmentConfiguration", param)
|
||||
const host = `http://${param.centerIp}:${param.centerPort}`
|
||||
console.log("中心host", host)
|
||||
console.log("中心host",host)
|
||||
AppStorage.setOrCreate<string>("host", host)
|
||||
ethernet.setIfaceConfig("eth0", {
|
||||
mode: ethernet.IPSetMode.STATIC,
|
||||
|
||||
@ -21,7 +21,7 @@ import { CryptoJS } from '@ohos/crypto-js';
|
||||
import {
|
||||
BeginExamRequest,
|
||||
CarInfoType,
|
||||
CenterCallBackMsgType,
|
||||
centerCallBackMsgType,
|
||||
DrvexamType,
|
||||
ExaminationStuAbsentParams,
|
||||
ExaminerLoginInfo,
|
||||
@ -1312,7 +1312,7 @@ struct UserInfo {
|
||||
.backgroundImageSize({ width: '100%', height: '100%' })
|
||||
}
|
||||
|
||||
private onCenterMsg = (val: CenterCallBackMsgType) => {
|
||||
private onCenterMsg = (val: centerCallBackMsgType) => {
|
||||
if (val.id == 32) {
|
||||
AppStorage.setOrCreate('signNum', val.body[1])
|
||||
if (val.body[0] == 7) {
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
import router from '@ohos.router';
|
||||
import RealTime from '../compontents/judge/RealTime';
|
||||
import { GPSData, SignalData } from '../../mock';
|
||||
import { SignalDataType, WorkerBackMessage } from '../../model';
|
||||
import { SignalDataType } from '../../model';
|
||||
import { ObtainUdpBusinessInstance } from '../../utils/business/ObtainUdpBusiness';
|
||||
import { DifferentialAndSignal } from '../../utils/business/DifferentialAndSignal';
|
||||
|
||||
@Component
|
||||
export default struct SignDisplayCom {
|
||||
@ -332,14 +331,12 @@ export default struct SignDisplayCom {
|
||||
|
||||
if (this.showBack) {
|
||||
this.ratio = 1.4
|
||||
DifferentialAndSignal.onMsg((data: string) => {
|
||||
const result: WorkerBackMessage = JSON.parse(data)
|
||||
if (result.type === "centerUdpData") {
|
||||
this.getSignal(result.data as string)
|
||||
ObtainUdpBusinessInstance.onMsg((msg) => {
|
||||
if (msg) {
|
||||
this.getSignal(msg)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
} else {
|
||||
clearInterval(this.signalTimer)
|
||||
this.signalTimer = setInterval(() => {
|
||||
@ -365,7 +362,7 @@ export default struct SignDisplayCom {
|
||||
clearInterval(this.signalTimer)
|
||||
this.signalTimer = setInterval(() => {
|
||||
//TODO 临时方案
|
||||
const msgStr = AppStorage.get<string>('msgStr') || ""
|
||||
const msgStr = AppStorage.get<string>('msgStr')||""
|
||||
getSignal(msgStr)
|
||||
}, 200)
|
||||
}
|
||||
|
||||
@ -1,271 +0,0 @@
|
||||
import router from '@ohos.router'
|
||||
import { GPSData, SignalData } from '../../mock'
|
||||
import { EnvironmentConfigurationType, SignalDataType, WorkerBackMessage } from '../../model'
|
||||
import { DifferentialAndSignal } from '../../utils/business/DifferentialAndSignal'
|
||||
|
||||
@Component
|
||||
export default struct SignalDisplayComponent {
|
||||
@State sjxhColum: Array<SignalDataType> = SignalData
|
||||
@State signArr: Array<string> = []
|
||||
@State GPSColum: Array<SignalDataType> = GPSData
|
||||
|
||||
aboutToAppear(): void {
|
||||
|
||||
DifferentialAndSignal.onMsg((data: string) => {
|
||||
const result: WorkerBackMessage = JSON.parse(data)
|
||||
if (result.type === "centerUdpData") {
|
||||
this.getSignal(result.data as string)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
getSignal = (msg: string) => {
|
||||
const strachArr = msg.split(',')
|
||||
if (strachArr[0] != '#DN_GD') {
|
||||
return
|
||||
}
|
||||
this.signArr = strachArr
|
||||
|
||||
for (let i = 0; i <= 12; i++) {
|
||||
this.sjxhColum[i].value = this.signArr[i+2]
|
||||
}
|
||||
|
||||
this.sjxhColum[13].value = this.signArr[17]
|
||||
this.sjxhColum[14].value = this.signArr[18]
|
||||
this.sjxhColum[15].value = this.signArr[19]
|
||||
this.sjxhColum[16].value = this.signArr[20]
|
||||
this.sjxhColum[17].value = this.signArr[23] //车速
|
||||
this.sjxhColum[18].value = this.signArr[28]
|
||||
this.sjxhColum[19].value = this.signArr[29]
|
||||
this.sjxhColum[20].value = this.signArr[30]
|
||||
this.sjxhColum[21].value = this.signArr[15] //NC
|
||||
this.sjxhColum[22].value = this.signArr[16] //SA15
|
||||
this.sjxhColum[23].value = this.signArr[21]
|
||||
this.sjxhColum[24].value = this.signArr[22]
|
||||
this.sjxhColum[25].value = this.signArr[24]
|
||||
this.sjxhColum[26].value = this.signArr[26]
|
||||
this.sjxhColum[27].value = this.signArr[25]
|
||||
this.sjxhColum[28].value = this.signArr[27]
|
||||
this.sjxhColum[29].value = this.signArr[31]
|
||||
this.sjxhColum[30].value = this.signArr[32]
|
||||
this.sjxhColum[31].value = this.signArr[33]
|
||||
this.sjxhColum[32].value = this.signArr[34]
|
||||
this.sjxhColum[33].value = this.signArr[35]
|
||||
for (let i = 34; i <= 46; i++) {
|
||||
this.sjxhColum[i].value = this.signArr[i+2]
|
||||
}
|
||||
let t = 0
|
||||
for (let i = 83; i <= 97; i++) {
|
||||
this.GPSColum[t].value = this.signArr[i]
|
||||
t++
|
||||
}
|
||||
this.GPSColum[14].value = ((Number((this.signArr[97] || 0)) * 1.852).toFixed(2)).toString()
|
||||
const str0 = this.signArr[93].substr(0, 2)
|
||||
const str1 = this.signArr[93].substr(2, 2)
|
||||
const str2 = this.signArr[93].substr(4.2)
|
||||
this.signArr[93] = str2 + str1 + str0
|
||||
this.GPSColum[10].value = this.signArr[93]
|
||||
|
||||
// this.signArr[53]=192.168.7.170'
|
||||
this.sjxhColum = JSON.parse(JSON.stringify((this.sjxhColum)))
|
||||
this.signArr = JSON.parse(JSON.stringify((this.signArr)))
|
||||
this.GPSColum = JSON.parse(JSON.stringify((this.GPSColum)))
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
// 头部
|
||||
Flex({
|
||||
alignItems: ItemAlign.Center,
|
||||
justifyContent: FlexAlign.SpaceBetween
|
||||
}) {
|
||||
Row() {
|
||||
// 短logo
|
||||
Image($r('app.media.shortLogo')).height(100).width(150).objectFit(ImageFit.Contain).margin({
|
||||
left: 10
|
||||
})
|
||||
}
|
||||
|
||||
Row() {
|
||||
// 返回按钮
|
||||
Image($r('app.media.topB_back')).height(100).onClick(() => {
|
||||
router.back()
|
||||
})
|
||||
}
|
||||
}.width("100%").height(100)
|
||||
|
||||
Column() {
|
||||
// GPS信号展示
|
||||
GPSComponent({
|
||||
data: this.signArr
|
||||
})
|
||||
// 车载信号以及车载坐标
|
||||
Column() {
|
||||
CarComponent({
|
||||
data: this.sjxhColum
|
||||
})
|
||||
CoordinateComponent({
|
||||
data: this.GPSColum
|
||||
})
|
||||
}.margin({
|
||||
top: 5
|
||||
}).backgroundColor("#282828")
|
||||
|
||||
}
|
||||
.width("100%")
|
||||
.height("100%")
|
||||
.backgroundColor("#fff")
|
||||
.borderRadius(20)
|
||||
.padding(20)
|
||||
.margin(20)
|
||||
}.width("100%").height("100%").backgroundColor("#222222")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Component
|
||||
struct GPSComponent {
|
||||
@State data: Array<string> = []
|
||||
@State ip: string = ""
|
||||
|
||||
aboutToAppear(): void {
|
||||
// 获取config
|
||||
let config: EnvironmentConfigurationType =
|
||||
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration") || {
|
||||
tcplocalIp: "",
|
||||
tcplocalIpPort: "",
|
||||
tcpOppositeIp: "",
|
||||
tcpOppositePort: ""
|
||||
}
|
||||
this.ip = config.tcplocalIp
|
||||
}
|
||||
|
||||
build() {
|
||||
Flex({
|
||||
wrap: FlexWrap.Wrap
|
||||
}) {
|
||||
blockComponent({
|
||||
label: "发送次数",
|
||||
value: this.data[49] || "-"
|
||||
})
|
||||
blockComponent({
|
||||
label: "固件版本",
|
||||
value: this.data[54] || "-"
|
||||
})
|
||||
|
||||
blockComponent({
|
||||
label: "方向盘类型",
|
||||
value: this.data[50] || "-"
|
||||
})
|
||||
blockComponent({
|
||||
label: "按键数值",
|
||||
value: this.data[55] || "-"
|
||||
})
|
||||
blockComponent({
|
||||
label: "GPS错误次数",
|
||||
value: this.data[60] || "-"
|
||||
})
|
||||
blockComponent({
|
||||
label: "汽车类型",
|
||||
value: this.data[51] || "-"
|
||||
})
|
||||
blockComponent({
|
||||
label: "GPS板卡类型",
|
||||
value: this.data[56] || "-"
|
||||
})
|
||||
blockComponent({
|
||||
label: "本机IP",
|
||||
value: this.ip
|
||||
})
|
||||
|
||||
blockComponent({
|
||||
label: "接口心跳",
|
||||
value: this.data[52] || "-"
|
||||
})
|
||||
blockComponent({
|
||||
label: "GPS板卡软件版本",
|
||||
value: this.data[57] || "-"
|
||||
})
|
||||
blockComponent({
|
||||
label: "改正数次数/改正数大小",
|
||||
value: this.data[58] || "-"
|
||||
})
|
||||
blockComponent({
|
||||
label: "已工作时长/设定工作时长",
|
||||
value: this.data[61] || "-"
|
||||
})
|
||||
blockComponent({
|
||||
label: "GPS数据次数/数据长度",
|
||||
value: this.data[59] || "-"
|
||||
})
|
||||
blockComponent({
|
||||
label: "改正数据长度*数据长度-基准站RTCM改正数类型",
|
||||
value: this.data[62] || "-"
|
||||
})
|
||||
}.backgroundColor("#282828").width("100%")
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
struct CarComponent {
|
||||
@State data: Array<SignalDataType> = SignalData
|
||||
|
||||
build() {
|
||||
Flex({
|
||||
wrap: FlexWrap.Wrap
|
||||
}) {
|
||||
ForEach(this.data, (item: SignalDataType) => {
|
||||
blockComponent({
|
||||
label: item.key,
|
||||
value: item.value
|
||||
})
|
||||
})
|
||||
}.width("100%")
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
struct CoordinateComponent {
|
||||
@State data: Array<SignalDataType> = GPSData
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
Text("GPS坐标").fontColor("#FFB433").fontSize(20).margin({
|
||||
top: 20
|
||||
})
|
||||
Flex({
|
||||
wrap: FlexWrap.Wrap
|
||||
}) {
|
||||
ForEach(this.data, (item: SignalDataType) => {
|
||||
blockComponent({
|
||||
color: "#FFB433",
|
||||
label: item.key,
|
||||
value: item.value
|
||||
})
|
||||
})
|
||||
}
|
||||
}.width("100%").backgroundColor("#1A1A1A").justifyContent(FlexAlign.Center)
|
||||
}
|
||||
}
|
||||
|
||||
@Component
|
||||
struct blockComponent {
|
||||
@State label: string = "发送次数"
|
||||
@State value: string = "1"
|
||||
@State widthNum: number = 130
|
||||
@State color: string = "#FDF5E7"
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
Row() {
|
||||
Text(this.label + ":").fontColor(this.color)
|
||||
}.width(this.widthNum).justifyContent(FlexAlign.End)
|
||||
|
||||
Row() {
|
||||
Text(this.value).fontColor(this.color)
|
||||
}.width(80).justifyContent(FlexAlign.Start).margin({
|
||||
left: 20
|
||||
})
|
||||
}.height(65).justifyContent(FlexAlign.Center).alignItems(VerticalAlign.Center)
|
||||
}
|
||||
}
|
||||
@ -10,7 +10,7 @@ export default class TcpClient {
|
||||
private oppositeIp: string = ''
|
||||
private oppositeIpPort: string = ''
|
||||
private tcpSendNum: number = 0
|
||||
private tcp: socket.TCPSocket = socket.constructTCPSocketInstance()
|
||||
private tcp: socket.TCPSocket = null
|
||||
private events: Array<Function> = []
|
||||
|
||||
constructor() {
|
||||
@ -20,102 +20,59 @@ export default class TcpClient {
|
||||
return TcpClient.instance
|
||||
}
|
||||
|
||||
// 初始化tcp连接
|
||||
async init(tcpLocalIp: string, tcpLocalIpPort: string, tcpOppositeIp: string, tcpOppositePort: string) {
|
||||
init(tcpLocalIp: string, tcpLocalIpPort: string, tcpOppositeIp: string, tcpOppositePort: string) {
|
||||
this.localIp = tcpLocalIp
|
||||
this.oppositeIp = tcpOppositeIp
|
||||
this.localIpPort = tcpLocalIpPort
|
||||
this.oppositeIpPort = tcpOppositePort
|
||||
console.log(TCPTag, 'new Tcp', this.localIp, this.localIpPort, this.oppositeIp, this.oppositeIpPort)
|
||||
this.tcp = socket.constructTCPSocketInstance();
|
||||
await this.bindTcp()
|
||||
await this.connectTcp()
|
||||
this.bindTcp()
|
||||
}
|
||||
|
||||
// 绑定tcp
|
||||
bindTcp(): Promise<Boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.tcp.bind({
|
||||
address: this.localIp,
|
||||
port: Number(this.localIpPort),
|
||||
family: 1
|
||||
}).then(() => {
|
||||
console.log(TCPTag, 'bindTcp success:', this.localIp, this.localIpPort, this.oppositeIp, this.oppositeIpPort)
|
||||
resolve(true)
|
||||
}).catch((err: BusinessError) => {
|
||||
console.log(TCPTag, 'bindTcp error:', JSON.stringify(err), this.localIp, this.localIpPort, this.oppositeIp, this.oppositeIpPort)
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 连接tcp
|
||||
connectTcp(): Promise<Boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.tcp.connect({
|
||||
bindTcp(): Promise<void> {
|
||||
return this.tcp.bind({
|
||||
address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
}).then(() => {
|
||||
return this.tcp.connect({
|
||||
address: {
|
||||
address: this.oppositeIp, port: Number(this.oppositeIpPort), family: 1
|
||||
}, timeout: 1000 * 15
|
||||
address: this.oppositeIp, port: parseInt(this.oppositeIpPort)
|
||||
},
|
||||
timeout: 6000
|
||||
})
|
||||
.then(() => {
|
||||
this.getMessage()
|
||||
console.log(TCPTag, "tcp connect success")
|
||||
return this.tcp.setExtraOptions({
|
||||
keepAlive: true
|
||||
}).then(() => {
|
||||
try {
|
||||
this.tcp.on("message", value => {
|
||||
let data = new DataView(value.message)
|
||||
this.events.forEach(cb => {
|
||||
cb(value.message.slice(5, data.byteLength))
|
||||
})
|
||||
})
|
||||
.then(() => {
|
||||
resolve(true)
|
||||
})
|
||||
.catch((err: BusinessError) => {
|
||||
console.log(TCPTag, "tcp connect or keepAlive error: ", JSON.stringify(err))
|
||||
console.log(TCPTag, "tcp 重启服务")
|
||||
reject(err)
|
||||
})
|
||||
return Promise.resolve()
|
||||
} catch (e) {
|
||||
return Promise.reject(e)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
getMessage() {
|
||||
this.tcp.on("message", value => {
|
||||
let data = new DataView(value.message)
|
||||
this.events.forEach(cb => {
|
||||
cb(value.message.slice(5, data.byteLength))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 重新绑定tcp
|
||||
async reBind() {
|
||||
await this.close()
|
||||
this.tcp = socket.constructTCPSocketInstance();
|
||||
await this.bindTcp()
|
||||
await this.connectTcp()
|
||||
}
|
||||
|
||||
// 监听tcp错误
|
||||
onError(callback: Function) {
|
||||
this.tcp.on('error', err => {
|
||||
console.log(TCPTag, 'tcp on error: ', JSON.stringify(err))
|
||||
callback?.()
|
||||
});
|
||||
}
|
||||
|
||||
// 关闭tcp连接
|
||||
close(): Promise<void> {
|
||||
return this.tcp?.close()
|
||||
}
|
||||
|
||||
// 监听tcp消息
|
||||
onMsg(callback: Function) {
|
||||
this.events.push(callback)
|
||||
}
|
||||
|
||||
// 接收tcp消息
|
||||
sendMsg(data: string): Promise<void> {
|
||||
return this.tcp?.send({
|
||||
data
|
||||
}).catch(async (err: BusinessError) => {
|
||||
console.log(TCPTag, 'sendMsg error:', JSON.stringify(err))
|
||||
this.tcpSendNum++
|
||||
if (this.tcpSendNum > 10) {
|
||||
this.tcpSendNum = 0
|
||||
@ -125,7 +82,6 @@ export default class TcpClient {
|
||||
})
|
||||
}
|
||||
|
||||
// 取消监听tcp消息
|
||||
offMsg(callback: Function) {
|
||||
this.events = this.events.filter(cb => cb !== callback)
|
||||
}
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
import socket from '@ohos.net.socket'
|
||||
import promptAction from '@ohos.promptAction'
|
||||
import { CarInfoType, EnvironmentConfigurationType } from '../model'
|
||||
import { UDPTag } from '../config'
|
||||
import { FillZero, StringToASCII } from './Common'
|
||||
import { BusinessError } from '@ohos.base'
|
||||
import { FillZero, StringToBytes, StringToASCII } from './Common'
|
||||
import { CenterUDPBusinessInstance } from './business/CenterUdpBusiness'
|
||||
|
||||
interface MsgExt {
|
||||
id: number,
|
||||
@ -29,18 +33,33 @@ type DealMethod<T extends Object> = (value: ArrayBuffer) => T
|
||||
|
||||
|
||||
export default class UdpClient {
|
||||
protected udp: socket.UDPSocket | null = null
|
||||
private localIp: string = ''
|
||||
private localIpPort: string = ''
|
||||
private oppositeIp: string = ''
|
||||
private oppositeIpPort: string = ''
|
||||
protected udp: socket.UDPSocket | null = null
|
||||
private messageEvents: Array<Function> = []
|
||||
private errorEvents: Array<Function> = []
|
||||
private dealMethod?: DealMethod<object>
|
||||
|
||||
// 绑定udp连接
|
||||
private bindEvent() {
|
||||
this.udp?.on("message", value => {
|
||||
let result = this.dealMethod?.(value.message)
|
||||
this.messageEvents.forEach(cb => {
|
||||
cb(result)
|
||||
})
|
||||
})
|
||||
this.udp?.on("error", (err) => {
|
||||
console.log(UDPTag, 'udp error', JSON.stringify(err))
|
||||
this.errorEvents.forEach(cb => {
|
||||
cb(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
bindUdp(): Promise<void> | undefined {
|
||||
console.log(UDPTag, "绑定udp", this.localIp, this.localIpPort)
|
||||
console.log(UDPTag, "绑定udp",this.localIp,this.localIpPort)
|
||||
return this.udp?.bind({
|
||||
address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
}).then(res => {
|
||||
@ -48,7 +67,6 @@ export default class UdpClient {
|
||||
})
|
||||
}
|
||||
|
||||
// 重新绑定udp连接
|
||||
async reBind() {
|
||||
await this.close()
|
||||
this.udp = socket.constructUDPSocketInstance();
|
||||
@ -56,7 +74,6 @@ export default class UdpClient {
|
||||
await this.bindUdp()
|
||||
}
|
||||
|
||||
// 关闭udp连接
|
||||
close(): Promise<void> | undefined {
|
||||
this.messageEvents = []
|
||||
this.errorEvents = []
|
||||
@ -66,12 +83,10 @@ export default class UdpClient {
|
||||
return this.udp?.close()
|
||||
}
|
||||
|
||||
// 设置处理消息的函数
|
||||
setDealMethod<T extends Object>(fun: DealMethod<T>) {
|
||||
this.dealMethod = fun
|
||||
}
|
||||
|
||||
// 发送消息
|
||||
sendMsg(data: ArrayBuffer | string): Promise<void> | undefined {
|
||||
return this.udp?.send({
|
||||
data,
|
||||
@ -83,7 +98,6 @@ export default class UdpClient {
|
||||
})
|
||||
}
|
||||
|
||||
// 组装消息
|
||||
setWholeMsg(params: MsgExt): ArrayBuffer {
|
||||
let head = generateHead(params);
|
||||
let headJudge = exclusive(head);
|
||||
@ -94,13 +108,11 @@ export default class UdpClient {
|
||||
return new Uint8Array(arr).buffer
|
||||
}
|
||||
|
||||
// 发送消息
|
||||
sendMsgExt(param: MsgExt) {
|
||||
const msgData = this.setWholeMsg(param)
|
||||
this.sendMsg(msgData)
|
||||
}
|
||||
|
||||
// 创建udp实例
|
||||
async create(udpLocalIp: string, udpLocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) {
|
||||
console.log(UDPTag, "udp 初始化参数", udpLocalIp, udpLocalIpPort, udpOppositeIp, udpOppositeIpPort)
|
||||
await this.close()
|
||||
@ -117,38 +129,19 @@ export default class UdpClient {
|
||||
}
|
||||
}
|
||||
|
||||
// 绑定消息事件
|
||||
onMsg(callback: Function) {
|
||||
if (this.messageEvents.findIndex(cb => cb === callback) !== -1) {
|
||||
if (this.messageEvents.findIndex(cb => cb === callback)) {
|
||||
return
|
||||
}
|
||||
this.messageEvents.push(callback)
|
||||
}
|
||||
|
||||
// 绑定错误事件
|
||||
onError(callback: Function) {
|
||||
this.errorEvents.push(callback)
|
||||
}
|
||||
|
||||
// 取消绑定事件
|
||||
offMsg(callback: Function) {
|
||||
this.messageEvents = this.messageEvents.filter(cb => cb !== callback)
|
||||
}
|
||||
|
||||
// 绑定事件
|
||||
private bindEvent() {
|
||||
this.udp?.on("message", value => {
|
||||
let result = this.dealMethod?.(value.message)
|
||||
this.messageEvents.forEach(cb => {
|
||||
cb(result)
|
||||
})
|
||||
})
|
||||
this.udp?.on("error", (err) => {
|
||||
console.log(UDPTag, 'udp error', JSON.stringify(err))
|
||||
this.errorEvents.forEach(cb => {
|
||||
cb(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1,11 +1,5 @@
|
||||
// 中心心跳/发送消息
|
||||
import {
|
||||
CarInfoType,
|
||||
CenterCallBackMsgType,
|
||||
EnvironmentConfigurationType,
|
||||
OtherMessageType,
|
||||
UDPParamType
|
||||
} from '../../model';
|
||||
import { CarInfoType, centerCallBackMsgType, EnvironmentConfigurationType, UDPParamType } from '../../model';
|
||||
import { fillZero, string2Bytes } from '../../pages/judgeSDK/utils/Common';
|
||||
import { NumberToByteArray } from '../Common';
|
||||
import UdpClient from '../UdpUtils';
|
||||
@ -19,10 +13,6 @@ class CenterUDPBusiness {
|
||||
private timer: number = -1
|
||||
private headLength: number = 9
|
||||
private sendId: number = 0
|
||||
private carInfo: CarInfoType = {}
|
||||
private signNum: number = -1
|
||||
private statue: string = ""
|
||||
private lsh: string = ""
|
||||
|
||||
constructor() {
|
||||
if (CenterUDPBusiness.instance) {
|
||||
@ -31,71 +21,7 @@ class CenterUDPBusiness {
|
||||
return CenterUDPBusiness.instance
|
||||
}
|
||||
|
||||
sendData(data: UDPParamType) {
|
||||
this.sendId = data.id
|
||||
const param = this.setWholeMsg(data)
|
||||
this.udp.sendMsg(param);
|
||||
}
|
||||
|
||||
startHeartBeat() {
|
||||
// 组装消息,一秒发送一次
|
||||
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])
|
||||
tmpList.push(NumberToByteArray(Number(arr[1]), 1 * 8)[0])
|
||||
const str = this.lsh || '0000000000000'
|
||||
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,
|
||||
carNo: this.carInfo.carNo!,
|
||||
placeId: this.carInfo.examinationRoomId!
|
||||
}
|
||||
const param = this.setWholeMsg(data)
|
||||
this.udp.sendMsg(param);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
onMsg(cb: (param: CenterCallBackMsgType) => void) {
|
||||
this.udp.onMsg(cb)
|
||||
}
|
||||
|
||||
offMsg(cb: (param: CenterCallBackMsgType) => void) {
|
||||
this.udp.offMsg(cb)
|
||||
}
|
||||
|
||||
// 初始化
|
||||
async init(config: EnvironmentConfigurationType, carInfo: CarInfoType, otherMessage: OtherMessageType) {
|
||||
try {
|
||||
// let result: EnvironmentConfigurationType =
|
||||
// AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")!
|
||||
// const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
|
||||
this.signNum = otherMessage.signNum || 0
|
||||
this.statue = otherMessage.statue || '1'
|
||||
this.lsh = otherMessage.lsh || '0000000000000'
|
||||
this.carInfo = carInfo
|
||||
this.udp.create(config.udplocalIp!, '8800', carInfo.udpAddress!, carInfo.messagePort!)
|
||||
this.udp.setDealMethod(this.dealMsg)
|
||||
} catch (e) {
|
||||
console.error(UDPTag, "初始化中心 udp失败")
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭所有动作
|
||||
async close() {
|
||||
clearInterval(this.timer)
|
||||
return this.udp.close()
|
||||
}
|
||||
|
||||
private dealMsg(msg: ArrayBuffer): CenterCallBackMsgType {
|
||||
private dealMsg(msg: ArrayBuffer): centerCallBackMsgType {
|
||||
let arr: number[] = []
|
||||
let dataView = new DataView(msg)
|
||||
for (let i = 0; i < dataView?.byteLength; ++i) {
|
||||
@ -156,6 +82,65 @@ class CenterUDPBusiness {
|
||||
}
|
||||
return [result];
|
||||
}
|
||||
|
||||
sendData(data: UDPParamType) {
|
||||
this.sendId = data.id
|
||||
const param = this.setWholeMsg(data)
|
||||
this.udp.sendMsg(param);
|
||||
}
|
||||
|
||||
startHeartBeat() {
|
||||
// 组装消息,一秒发送一次
|
||||
this.timer = setInterval(() => {
|
||||
SetSerialNumber()
|
||||
const signNum = AppStorage.get<number>('signNum')
|
||||
const statue = AppStorage.get<string>('statue')
|
||||
const lsh = AppStorage.get<string>('lsh')
|
||||
const arr = [signNum || 0, statue || 1]
|
||||
let tmpList: number[] = [];
|
||||
tmpList.push(NumberToByteArray(Number(arr[0]), 1 * 8)[0])
|
||||
tmpList.push(NumberToByteArray(Number(arr[1]), 1 * 8)[0])
|
||||
const str = lsh || '0000000000000'
|
||||
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,
|
||||
carNo: carInfo.carNo!,
|
||||
placeId: carInfo.examinationRoomId!
|
||||
}
|
||||
const param = this.setWholeMsg(data)
|
||||
this.udp.sendMsg(param);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
onMsg(cb: (param: centerCallBackMsgType) => void) {
|
||||
this.udp.onMsg(cb)
|
||||
}
|
||||
|
||||
offMsg(cb: (param: centerCallBackMsgType) => void) {
|
||||
this.udp.offMsg(cb)
|
||||
}
|
||||
|
||||
async init() {
|
||||
try {
|
||||
let result: EnvironmentConfigurationType =
|
||||
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")!
|
||||
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
|
||||
this.udp.create(result.udplocalIp!, '8800', carInfo.udpAddress!, carInfo.messagePort!)
|
||||
this.udp.setDealMethod(this.dealMsg)
|
||||
} catch (e) {
|
||||
console.error(UDPTag, "初始化中心 udp失败")
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭所有动作
|
||||
async close() {
|
||||
clearInterval(this.timer)
|
||||
return this.udp.close()
|
||||
}
|
||||
}
|
||||
|
||||
export const CenterUDPBusinessInstance = new CenterUDPBusiness();
|
||||
@ -1,66 +0,0 @@
|
||||
// 拉起Worker处理tcp信息以及接受后置机UDP信息
|
||||
import worker, { MessageEvents } from '@ohos.worker';
|
||||
import { WorkerTag } from '../../config';
|
||||
import { CarInfoType, EnvironmentConfigurationType, WorkerMessage } from '../../model';
|
||||
|
||||
class differentialAndSignal {
|
||||
private workerInstance = new worker.ThreadWorker("entry/ets/workers/DifferentialCorrection.ets")
|
||||
private events: Array<Function> = []
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
// 初始化Worker
|
||||
init() {
|
||||
this.workerInstance = new worker.ThreadWorker("entry/ets/workers/DifferentialCorrection.ets");
|
||||
let config: EnvironmentConfigurationType =
|
||||
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration") || {
|
||||
tcplocalIp: "",
|
||||
tcplocalIpPort: "",
|
||||
tcpOppositeIp: "",
|
||||
tcpOppositePort: ""
|
||||
}
|
||||
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
|
||||
const signNum = AppStorage.get<number>('signNum')
|
||||
const statue = AppStorage.get<string>('statue')
|
||||
const lsh = AppStorage.get<string>('lsh')
|
||||
const data: WorkerMessage = {
|
||||
config: config,
|
||||
carInfo: carInfo,
|
||||
otherMessage: {
|
||||
signNum: signNum || 0,
|
||||
statue: statue || "",
|
||||
lsh: lsh || ""
|
||||
}
|
||||
}
|
||||
this.workerInstance.postMessage(JSON.stringify(data))
|
||||
this.getMessage()
|
||||
}
|
||||
|
||||
// 添加监听
|
||||
onMsg(callback: Function) {
|
||||
if (this.events.findIndex(cb => cb === callback) !== -1) return; // 防止重复添加监听器
|
||||
this.events.push(callback);
|
||||
}
|
||||
|
||||
// 取消监听
|
||||
offMsg(callback: Function) {
|
||||
this.events = this.events.filter((cb) => cb !== callback);
|
||||
}
|
||||
|
||||
// 获取Worker消息
|
||||
getMessage() {
|
||||
this.workerInstance.onmessage = (e: MessageEvents): void => {
|
||||
if (e.data) {
|
||||
console.log(WorkerTag, "Worker 收到消息: " + e.data);
|
||||
this.events.forEach((callback) => {
|
||||
callback(e.data);
|
||||
});
|
||||
} else {
|
||||
console.error(WorkerTag, "Worker 收到空消息");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const DifferentialAndSignal = new differentialAndSignal();
|
||||
@ -1,31 +1,20 @@
|
||||
//差分信号
|
||||
import { TCPTag } from '../../config';
|
||||
import { EnvironmentConfigurationType } from '../../model';
|
||||
import TcpClient from '../TcpUtils';
|
||||
|
||||
class differentialSignal {
|
||||
private differentialSignalTcp: TcpClient = new TcpClient()
|
||||
private differentialSignalTcp: TcpClient;
|
||||
private timer: number = -1
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
init(config: EnvironmentConfigurationType) {
|
||||
init() {
|
||||
this.differentialSignalTcp = new TcpClient();
|
||||
// let config: EnvironmentConfigurationType =
|
||||
// AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration") || {
|
||||
// tcplocalIp: "",
|
||||
// tcplocalIpPort: "",
|
||||
// tcpOppositeIp: "",
|
||||
// tcpOppositePort: ""
|
||||
// }
|
||||
console.log(TCPTag, "初始化", JSON.stringify(config))
|
||||
if (config.tcplocalIp || config.tcplocalIpPort || config.tcpOppositeIp || config.tcpOppositePort) {
|
||||
this.differentialSignalTcp.init(config.tcplocalIp || "", config.tcplocalIpPort || "", config.tcpOppositeIp || "",
|
||||
config.tcpOppositePort || "");
|
||||
} else {
|
||||
console.log(TCPTag, "未配置差分信号TCP信息,请在环境配置中设置")
|
||||
}
|
||||
let config: EnvironmentConfigurationType =
|
||||
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
|
||||
this.differentialSignalTcp.init(config.tcplocalIp, config.tcplocalIpPort, config.tcpOppositeIp,
|
||||
config.tcpOppositePort);
|
||||
}
|
||||
|
||||
// 发送消息
|
||||
@ -41,7 +30,6 @@ class differentialSignal {
|
||||
// 获取消息
|
||||
getData(callback: (data: ArrayBuffer) => void) {
|
||||
this.differentialSignalTcp.onMsg((data: ArrayBuffer) => {
|
||||
console.log(TCPTag, "获取", data);
|
||||
callback(data);
|
||||
});
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ class ObtainUdpBusiness {
|
||||
this.modelNo = GlobalConfig.modelNo || ""
|
||||
}
|
||||
|
||||
init(config: EnvironmentConfigurationType) {
|
||||
init() {
|
||||
switch (this.modelNo) {
|
||||
case "0":
|
||||
this.initSecondaryBoard()
|
||||
@ -25,7 +25,7 @@ class ObtainUdpBusiness {
|
||||
this.initSecondGeneration()
|
||||
break
|
||||
case "3":
|
||||
this.initThirdGeneration(config)
|
||||
this.initThirdGeneration()
|
||||
break
|
||||
default:
|
||||
this.initFirstGeneration()
|
||||
@ -68,8 +68,7 @@ class ObtainUdpBusiness {
|
||||
}
|
||||
}
|
||||
|
||||
// 发送数据
|
||||
sendData(data: string | ArrayBuffer) {
|
||||
sendData(data: string) {
|
||||
switch (this.modelNo) {
|
||||
case "0":
|
||||
this.sendSecondaryBoardMsg(data)
|
||||
@ -99,12 +98,11 @@ class ObtainUdpBusiness {
|
||||
private initSecondGeneration() {
|
||||
|
||||
}
|
||||
|
||||
// 三代机udp初始化
|
||||
private initThirdGeneration(config: EnvironmentConfigurationType) {
|
||||
private initThirdGeneration() {
|
||||
try {
|
||||
// let config: EnvironmentConfigurationType =
|
||||
// AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")!
|
||||
let config: EnvironmentConfigurationType =
|
||||
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")!
|
||||
console.log("获取udp设置", JSON.stringify(config))
|
||||
this.thirdGenerationMachineUdp = new UdpClient()
|
||||
this.thirdGenerationMachineUdp.create(config.udplocalIp!, config.udplocalIpPort!, config.udpOppositeIp!,
|
||||
@ -155,19 +153,19 @@ class ObtainUdpBusiness {
|
||||
this.thirdGenerationMachineUdp!.onMsg(cb)
|
||||
}
|
||||
|
||||
private sendSecondaryBoardMsg(data: string | ArrayBuffer) {
|
||||
private sendSecondaryBoardMsg(data: string) {
|
||||
|
||||
}
|
||||
|
||||
private sendFirstGenerationMsg(data: string | ArrayBuffer) {
|
||||
private sendFirstGenerationMsg(data: string) {
|
||||
|
||||
}
|
||||
|
||||
private sendSecondGenerationMsg(data: string | ArrayBuffer) {
|
||||
private sendSecondGenerationMsg(data: string) {
|
||||
|
||||
}
|
||||
|
||||
private sendThirdGenerationMsg(data: string | ArrayBuffer) {
|
||||
private sendThirdGenerationMsg(data: string) {
|
||||
this.thirdGenerationMachineUdp!.sendMsg(data)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,83 +0,0 @@
|
||||
// 处理worker线程的消息tcp拿差分改正数,udp给后置机
|
||||
import worker, { ErrorEvent, MessageEvents, ThreadWorkerGlobalScope } from '@ohos.worker';
|
||||
import { WorkerTag } from '../config';
|
||||
import { CenterCallBackMsgType, WorkerBackMessage, WorkerMessage } from '../model';
|
||||
import { CenterUDPBusinessInstance } from '../utils/business/CenterUdpBusiness';
|
||||
import { DifferentialSignal } from '../utils/business/DifferentialSignal';
|
||||
import { ObtainUdpBusinessInstance } from '../utils/business/ObtainUdpBusiness';
|
||||
|
||||
const workerPort: ThreadWorkerGlobalScope = worker.workerPort;
|
||||
|
||||
/**
|
||||
* Defines the event handler to be called when the worker thread receives a message sent by the host thread.
|
||||
* The event handler is executed in the worker thread.
|
||||
*
|
||||
* @param e message data
|
||||
*/
|
||||
workerPort.onmessage = (e: MessageEvents) => {
|
||||
console.log(WorkerTag, `Worker received message: ${e.data}`);
|
||||
const result: WorkerMessage = JSON.parse(e.data);
|
||||
// 初始化TCP
|
||||
DifferentialSignal.init(result.config);
|
||||
DifferentialSignal.sendData()
|
||||
// 初始化后置机UDP
|
||||
ObtainUdpBusinessInstance.init(result.config)
|
||||
// 初始化中心UDP
|
||||
CenterUDPBusinessInstance.init(result.config, result.carInfo, result.otherMessage)
|
||||
// 中心心跳
|
||||
CenterUDPBusinessInstance.startHeartBeat()
|
||||
// 如果外部有这个消息进来就开始给中心发送
|
||||
if (result.udpParam) {
|
||||
CenterUDPBusinessInstance.sendData(result.udpParam);
|
||||
}
|
||||
// 获取TCP差分改正数信号
|
||||
DifferentialSignal.getData((data: ArrayBuffer) => {
|
||||
console.log(WorkerTag, "Received differential signal data:", data.byteLength, "bytes")
|
||||
// TCP拿到差分改正数发给后置机
|
||||
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)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the event handler to be called when the worker receives a message that cannot be deserialized.
|
||||
* The event handler is executed in the worker thread.
|
||||
*
|
||||
* @param e message data
|
||||
*/
|
||||
workerPort.onmessageerror = (e: MessageEvents) => {
|
||||
console.log(WorkerTag, `Worker received message error: ${e.data}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the event handler to be called when an exception occurs during worker execution.
|
||||
* The event handler is executed in the worker thread.
|
||||
*
|
||||
* @param e error message
|
||||
*/
|
||||
workerPort.onerror = (e: ErrorEvent) => {
|
||||
console.log(WorkerTag, `Worker error: ${e.message}, filename: ${e.filename}, lineno: ${e.lineno}, colno: ${e.colno}`)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user