济南修改 #25
@ -1,424 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// import camera from '@ohos.multimedia.camera';
|
||||
import deviceInfo from '@ohos.deviceInfo';
|
||||
import fileIo from '@ohos.file.fs';
|
||||
import image from '@ohos.multimedia.image';
|
||||
import media from '@ohos.multimedia.media';
|
||||
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
|
||||
import Logger from '../utils/Logger';
|
||||
import MediaModel from './MediaModel';
|
||||
|
||||
|
||||
const FOUR = 4; // format
|
||||
const EIGHT = 8; // capacity
|
||||
const FOUR_THOUSAND_AND_SIXTY_NINE = 4096; // buffer大小
|
||||
|
||||
const cameraMode = {
|
||||
modePhoto: 0, // 拍照模式
|
||||
modeVideo: 1, // 录像模式
|
||||
};
|
||||
|
||||
const cameraWH = {
|
||||
width: 480,
|
||||
height: 360,
|
||||
};
|
||||
|
||||
/**
|
||||
* 分辨率
|
||||
*/
|
||||
export enum VideoFrame {
|
||||
VIDEOFRAME_1920_1080,
|
||||
VIDEOFRAME_1280_720,
|
||||
VIDEOFRAME_800_600,
|
||||
};
|
||||
|
||||
type VideoFrameWH = {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
|
||||
const TAG = '[CameraModel]';
|
||||
|
||||
export default class CameraService {
|
||||
private mediaModel: MediaModel = undefined;
|
||||
private fileAsset: mediaLibrary.FileAsset = undefined;
|
||||
private cameraMgr: camera.CameraManager = undefined;
|
||||
private camerasArray: Array<camera.CameraDevice> = undefined;
|
||||
private cameraInput: camera.CameraInput = undefined;
|
||||
private previewOutput: camera.PreviewOutput = undefined;
|
||||
private photoOutPut: camera.PhotoOutput = undefined;
|
||||
private capSession: camera.CaptureSession = undefined;
|
||||
private videoOutput: camera.VideoOutput = undefined;
|
||||
private capability: camera.CameraOutputCapability = undefined;
|
||||
|
||||
private avRecorder: media.AVRecorder = undefined;
|
||||
private receiver: image.ImageReceiver = undefined;
|
||||
private photoPath: string = '';
|
||||
private fd: number = -1;
|
||||
private takePictureHandle: (photoUri: string) => void = undefined;
|
||||
private currentMode:number = cameraMode.modePhoto;
|
||||
|
||||
private videoFrameWH: VideoFrameWH = {
|
||||
width: 480,
|
||||
height: 360,
|
||||
}; // 视频分辨率
|
||||
private imageRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0; // 图片旋转角度
|
||||
|
||||
private videoProfile: media.VideoRecorderProfile = {
|
||||
audioChannels: 2,
|
||||
audioCodec: media.CodecMimeType.AUDIO_AAC,
|
||||
audioBitrate: 48000,
|
||||
audioSampleRate: 48000,
|
||||
fileFormat: media.ContainerFormatType.CFT_MPEG_4,
|
||||
videoBitrate: 48000,
|
||||
videoCodec: media.CodecMimeType.VIDEO_MPEG4,
|
||||
videoFrameWidth: 480,
|
||||
videoFrameHeight: 360,
|
||||
videoFrameRate: 30,
|
||||
};
|
||||
private videoSourceType: number = 0;
|
||||
|
||||
constructor() {
|
||||
this.mediaModel = MediaModel.getMediaInstance();
|
||||
this.receiver = image.createImageReceiver(
|
||||
cameraWH.width,
|
||||
cameraWH.height,
|
||||
FOUR,
|
||||
EIGHT
|
||||
);
|
||||
Logger.info(TAG, 'createImageReceiver');
|
||||
this.receiver.on('imageArrival', () => {
|
||||
Logger.info(TAG, 'imageArrival');
|
||||
this.receiver.readNextImage((err, image) => {
|
||||
Logger.info(TAG, 'readNextImage');
|
||||
if (err || image === undefined) {
|
||||
Logger.error(TAG, 'failed to get valid image');
|
||||
return;
|
||||
}
|
||||
image.getComponent(FOUR, (errMsg, img) => {
|
||||
Logger.info(TAG, 'getComponent');
|
||||
if (errMsg || img === undefined) {
|
||||
Logger.info(TAG, 'failed to get valid buffer');
|
||||
return;
|
||||
}
|
||||
let buffer = new ArrayBuffer(FOUR_THOUSAND_AND_SIXTY_NINE);
|
||||
if (img.byteBuffer) {
|
||||
buffer = img.byteBuffer;
|
||||
} else {
|
||||
Logger.error(TAG, 'img.byteBuffer is undefined');
|
||||
}
|
||||
this.saveImage(buffer, image);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置分辨率
|
||||
* @param videoFrame
|
||||
*/
|
||||
setVideoFrameWH(videoFrame: VideoFrame): void {
|
||||
switch (videoFrame) {
|
||||
case VideoFrame.VIDEOFRAME_800_600:
|
||||
this.videoFrameWH = {
|
||||
width: 800,
|
||||
height: 600,
|
||||
};
|
||||
Logger.info(
|
||||
TAG,
|
||||
`setVideoFrameWH videoFrameWH:${JSON.stringify(this.videoFrameWH)}`
|
||||
);
|
||||
break;
|
||||
case VideoFrame.VIDEOFRAME_1280_720:
|
||||
this.videoFrameWH = {
|
||||
width: 1280,
|
||||
height: 720,
|
||||
};
|
||||
Logger.info(
|
||||
TAG,
|
||||
`setVideoFrameWH videoFrameWH:${JSON.stringify(this.videoFrameWH)}`
|
||||
);
|
||||
break;
|
||||
case VideoFrame.VIDEOFRAME_1920_1080:
|
||||
this.videoFrameWH = {
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
};
|
||||
Logger.info(
|
||||
TAG,
|
||||
`setVideoFrameWH videoFrameWH:${JSON.stringify(this.videoFrameWH)}`
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 设置图片旋转角度
|
||||
* @param imageRotation
|
||||
*/
|
||||
setImageRotation(imageRotation: camera.ImageRotation): void {
|
||||
this.imageRotation = imageRotation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存图片
|
||||
* @param buffer
|
||||
* @param img
|
||||
*/
|
||||
async saveImage(buffer: ArrayBuffer, img: image.Image): Promise<void> {
|
||||
Logger.info(TAG, 'savePicture');
|
||||
this.fileAsset = await this.mediaModel.createAndGetUri(mediaLibrary.MediaType.IMAGE);
|
||||
this.photoPath = this.fileAsset.uri;
|
||||
Logger.info(TAG, `this.photoUri = ${this.photoPath}`);
|
||||
this.fd = await this.mediaModel.getFdPath(this.fileAsset);
|
||||
Logger.info(TAG, `this.fd = ${this.fd}`);
|
||||
await fileIo.write(this.fd, buffer);
|
||||
await this.fileAsset.close(this.fd);
|
||||
await img.release();
|
||||
Logger.info(TAG, 'save image done');
|
||||
if (this.takePictureHandle) {
|
||||
this.takePictureHandle(this.photoPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化相机
|
||||
* @param surfaceId
|
||||
*/
|
||||
async initCamera(surfaceId: string): Promise<void> {
|
||||
Logger.info(TAG, `initCamera surfaceId:${surfaceId}`);
|
||||
await this.cameraRelease();
|
||||
Logger.info(TAG, `deviceInfo.deviceType = ${deviceInfo.deviceType}`);
|
||||
if (deviceInfo.deviceType === 'default') {
|
||||
Logger.info(TAG, `deviceInfo.deviceType default 1 = ${deviceInfo.deviceType}`);
|
||||
this.videoSourceType = 1;
|
||||
Logger.info(TAG, `deviceInfo.deviceType default 2 = ${deviceInfo.deviceType}`);
|
||||
} else {
|
||||
Logger.info(TAG, `deviceInfo.deviceType other 1 = ${deviceInfo.deviceType}`);
|
||||
this.videoSourceType = 0;
|
||||
Logger.info(TAG, `deviceInfo.deviceType other 2 = ${deviceInfo.deviceType}`);
|
||||
}
|
||||
Logger.info(TAG, 'getCameraManager begin');
|
||||
try {
|
||||
Logger.info(TAG, 'getCameraManager try begin');
|
||||
this.cameraMgr = camera.getCameraManager(globalThis.cameraContext);
|
||||
Logger.info(TAG, 'getCameraManager try end');
|
||||
} catch (e) {
|
||||
Logger.info(TAG, `getCameraManager catch e:${JSON.stringify(e)}`);
|
||||
Logger.info(TAG, `getCameraManager catch code:${JSON.stringify(e.code)}`);
|
||||
Logger.info(TAG, `getCameraManager catch message:${JSON.stringify(e.message)}`);
|
||||
}
|
||||
Logger.info(TAG, 'getCameraManager end');
|
||||
Logger.info(TAG, `getCameraManager ${JSON.stringify(this.cameraMgr)}`);
|
||||
this.camerasArray = this.cameraMgr.getSupportedCameras();
|
||||
Logger.info(TAG, `get cameras ${this.camerasArray.length}`);
|
||||
if (this.camerasArray.length === 0) {
|
||||
Logger.info(TAG, 'cannot get cameras');
|
||||
return;
|
||||
}
|
||||
|
||||
let mCamera = this.camerasArray[0];
|
||||
this.cameraInput = this.cameraMgr.createCameraInput(mCamera);
|
||||
this.cameraInput.open();
|
||||
Logger.info(TAG, 'createCameraInput');
|
||||
this.capability = this.cameraMgr.getSupportedOutputCapability(mCamera);
|
||||
let previewProfile = this.capability.previewProfiles[0];
|
||||
this.previewOutput = this.cameraMgr.createPreviewOutput(
|
||||
previewProfile,
|
||||
surfaceId
|
||||
);
|
||||
Logger.info(TAG, 'createPreviewOutput');
|
||||
let rSurfaceId = await this.receiver.getReceivingSurfaceId();
|
||||
let photoProfile = this.capability.photoProfiles[0];
|
||||
this.photoOutPut = this.cameraMgr.createPhotoOutput(
|
||||
photoProfile,
|
||||
rSurfaceId
|
||||
);
|
||||
this.capSession = this.cameraMgr.createCaptureSession();
|
||||
Logger.info(TAG, 'createCaptureSession');
|
||||
this.capSession.beginConfig();
|
||||
Logger.info(TAG, 'beginConfig');
|
||||
this.capSession.addInput(this.cameraInput);
|
||||
this.capSession.addOutput(this.previewOutput);
|
||||
this.capSession.addOutput(this.photoOutPut);
|
||||
await this.capSession.commitConfig();
|
||||
await this.capSession.start();
|
||||
Logger.info(TAG, 'captureSession start');
|
||||
}
|
||||
|
||||
setTakePictureHandleCallback(callback): void {
|
||||
this.takePictureHandle = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拍照
|
||||
*/
|
||||
async takePicture(): Promise<void> {
|
||||
Logger.info(TAG, 'takePicture');
|
||||
if (this.currentMode === cameraMode.modeVideo) {
|
||||
this.currentMode = cameraMode.modePhoto;
|
||||
}
|
||||
Logger.info(TAG, `takePicture imageRotation:${this.imageRotation}`);
|
||||
let photoSettings = {
|
||||
rotation: this.imageRotation,
|
||||
quality: camera.QualityLevel.QUALITY_LEVEL_MEDIUM,
|
||||
location: {
|
||||
// 位置信息,经纬度
|
||||
latitude: 12.9698,
|
||||
longitude: 77.75,
|
||||
altitude: 1000,
|
||||
},
|
||||
mirror: false,
|
||||
};
|
||||
await this.photoOutPut.capture(photoSettings);
|
||||
Logger.info(TAG, 'takePicture done');
|
||||
AppStorage.Set('isRefresh', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始录像
|
||||
*/
|
||||
async startVideo(): Promise<void> {
|
||||
Logger.info(TAG, 'startVideo begin');
|
||||
Logger.info(TAG, 'startVideo 1');
|
||||
await this.capSession.stop();
|
||||
Logger.info(TAG, 'startVideo 2');
|
||||
this.capSession.beginConfig();
|
||||
Logger.info(TAG, 'startVideo 3');
|
||||
if (this.currentMode === cameraMode.modePhoto) {
|
||||
this.currentMode = cameraMode.modeVideo;
|
||||
if (this.photoOutPut) {
|
||||
this.capSession.removeOutput(this.photoOutPut);
|
||||
this.photoOutPut.release();
|
||||
}
|
||||
} else {
|
||||
if (this.videoOutput) {
|
||||
try {
|
||||
Logger.info(TAG, 'startVideo 4');
|
||||
this.capSession.removeOutput(this.videoOutput);
|
||||
Logger.info(TAG, 'startVideo 5');
|
||||
} catch (e) {
|
||||
Logger.info(TAG, `startVideo catch e:${JSON.stringify(e)}`);
|
||||
Logger.info(TAG, `startVideo catch code:${JSON.stringify(e.code)}`);
|
||||
Logger.info(TAG, `startVideo catch message:${JSON.stringify(e.message)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.videoOutput) {
|
||||
try {
|
||||
Logger.info(TAG, 'startVideo 6');
|
||||
this.capSession.removeOutput(this.videoOutput);
|
||||
Logger.info(TAG, 'startVideo 7');
|
||||
} catch (e) {
|
||||
Logger.info(TAG, `startVideo catch e:${JSON.stringify(e)}`);
|
||||
Logger.info(TAG, `startVideo catch code:${JSON.stringify(e.code)}`);
|
||||
Logger.info(TAG, `startVideo catch message:${JSON.stringify(e.message)}`);
|
||||
}
|
||||
try {
|
||||
Logger.info(TAG, 'startVideo release 1');
|
||||
await this.videoOutput.release();
|
||||
Logger.info(TAG, 'startVideo release 2');
|
||||
} catch (e) {
|
||||
Logger.info(TAG, `startVideo catch e:${JSON.stringify(e)}`);
|
||||
Logger.info(TAG, `startVideo catch code:${JSON.stringify(e.code)}`);
|
||||
Logger.info(TAG, `startVideo catch message:${JSON.stringify(e.message)}`);
|
||||
}
|
||||
}
|
||||
Logger.info(TAG, 'startVideo 8');
|
||||
this.fileAsset = await this.mediaModel.createAndGetUri(mediaLibrary.MediaType.VIDEO);
|
||||
Logger.info(TAG, `startVideo fileAsset:${this.fileAsset}`);
|
||||
this.fd = await this.mediaModel.getFdPath(this.fileAsset);
|
||||
Logger.info(TAG, `startVideo fd:${this.fd}`);
|
||||
media.createAVRecorder(async (error, recorder) => {
|
||||
Logger.info(TAG, `startVideo into createAVRecorder:${recorder}`);
|
||||
if (recorder != null) {
|
||||
Logger.info(TAG, `startVideo into recorder:${recorder}`);
|
||||
this.avRecorder = recorder;
|
||||
Logger.info(TAG, `startVideo createAVRecorder success:${this.avRecorder}`);
|
||||
// 当前录像配置
|
||||
let currConfig = {
|
||||
audioSourceType: 1,
|
||||
videoSourceType: this.videoSourceType,
|
||||
profile: this.videoProfile,
|
||||
url: `fd://${this.fd}`,
|
||||
rotation: 0
|
||||
};
|
||||
Logger.info(TAG, `startVideo into recorder:${recorder}`);
|
||||
await this.avRecorder.prepare(currConfig);
|
||||
Logger.info(TAG, `startVideo videoConfig:${JSON.stringify(currConfig)}`);
|
||||
let videoId = await this.avRecorder.getInputSurface();
|
||||
let videoProfile = this.capability.videoProfiles[0];
|
||||
Logger.info(TAG, `startVideo capability.videoProfiles[]=: ${JSON.stringify(this.capability.videoProfiles)}`);
|
||||
Logger.info(TAG, `startVideo videoProfile:${JSON.stringify(videoProfile)}`);
|
||||
this.videoOutput = this.cameraMgr.createVideoOutput(videoProfile, videoId);
|
||||
Logger.info(TAG, `startVideo videoOutput:${this.videoOutput}`);
|
||||
this.capSession.addOutput(this.videoOutput);
|
||||
Logger.info(TAG, 'startVideo addOutput');
|
||||
await this.capSession.commitConfig();
|
||||
Logger.info(TAG, 'startVideo commitConfig');
|
||||
await this.capSession.start();
|
||||
Logger.info(TAG, 'startVideo commitConfig capSession');
|
||||
await this.videoOutput.start();
|
||||
Logger.info(TAG, 'startVideo commitConfig videoOutput');
|
||||
try {
|
||||
Logger.info(TAG, 'startVideo avRecorder.start 1');
|
||||
await this.avRecorder.start();
|
||||
Logger.info(TAG, 'startVideo avRecorder.start 2');
|
||||
} catch (e) {
|
||||
Logger.info(TAG, `startVideo catch e:${JSON.stringify(e)}`);
|
||||
}
|
||||
|
||||
Logger.info(TAG, 'startVideo end');
|
||||
|
||||
} else {
|
||||
Logger.info(TAG, `startVideo createAVRecorder fail, error:${error}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止录像
|
||||
*/
|
||||
async stopVideo(): Promise<void> {
|
||||
Logger.info(TAG, 'stopVideo called');
|
||||
await this.avRecorder.stop();
|
||||
await this.avRecorder.release();
|
||||
await this.videoOutput.stop();
|
||||
await this.fileAsset.close(this.fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* 资源释放
|
||||
*/
|
||||
async cameraRelease(): Promise<void> {
|
||||
Logger.info(TAG, 'releaseCamera');
|
||||
if (this.cameraInput) {
|
||||
await this.cameraInput.close();
|
||||
}
|
||||
if (this.previewOutput) {
|
||||
await this.previewOutput.release();
|
||||
}
|
||||
if (this.photoOutPut) {
|
||||
await this.photoOutPut.release();
|
||||
}
|
||||
if (this.videoOutput) {
|
||||
await this.videoOutput.release();
|
||||
}
|
||||
if (this.capSession) {
|
||||
await this.capSession.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,424 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import camera from '@ohos.multimedia.camera';
|
||||
import deviceInfo from '@ohos.deviceInfo';
|
||||
import fileIo from '@ohos.file.fs';
|
||||
import image from '@ohos.multimedia.image';
|
||||
import media from '@ohos.multimedia.media';
|
||||
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
|
||||
import Logger from '../utils/Logger';
|
||||
import MediaModel from './MediaModel';
|
||||
|
||||
|
||||
const FOUR = 4; // format
|
||||
const EIGHT = 8; // capacity
|
||||
const FOUR_THOUSAND_AND_SIXTY_NINE = 4096; // buffer大小
|
||||
|
||||
const cameraMode = {
|
||||
modePhoto: 0, // 拍照模式
|
||||
modeVideo: 1, // 录像模式
|
||||
};
|
||||
|
||||
const cameraWH = {
|
||||
width: 480,
|
||||
height: 360,
|
||||
};
|
||||
|
||||
/**
|
||||
* 分辨率
|
||||
*/
|
||||
export enum VideoFrame {
|
||||
VIDEOFRAME_1920_1080,
|
||||
VIDEOFRAME_1280_720,
|
||||
VIDEOFRAME_800_600,
|
||||
};
|
||||
|
||||
type VideoFrameWH = {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
|
||||
const TAG = '[CameraModel]';
|
||||
|
||||
export default class CameraService {
|
||||
private mediaModel: MediaModel = undefined;
|
||||
private fileAsset: mediaLibrary.FileAsset = undefined;
|
||||
private cameraMgr: camera.CameraManager
|
||||
private camerasArray: Array<camera.CameraDevice> = undefined;
|
||||
private cameraInput: camera.CameraInput = undefined;
|
||||
private previewOutput: camera.PreviewOutput = undefined;
|
||||
private photoOutPut: camera.PhotoOutput = undefined;
|
||||
private capSession: camera.CaptureSession = undefined;
|
||||
private videoOutput: camera.VideoOutput = undefined;
|
||||
private capability: camera.CameraOutputCapability = undefined;
|
||||
|
||||
private avRecorder: media.AVRecorder = undefined;
|
||||
private receiver: image.ImageReceiver = undefined;
|
||||
private photoPath: string = '';
|
||||
private fd: number = -1;
|
||||
private takePictureHandle: (photoUri: string) => void = undefined;
|
||||
private currentMode:number = cameraMode.modePhoto;
|
||||
|
||||
private videoFrameWH: VideoFrameWH = {
|
||||
width: 480,
|
||||
height: 360,
|
||||
}; // 视频分辨率
|
||||
private imageRotation: camera.ImageRotation = camera.ImageRotation.ROTATION_0; // 图片旋转角度
|
||||
|
||||
private videoProfile: media.VideoRecorderProfile = {
|
||||
audioChannels: 2,
|
||||
audioCodec: media.CodecMimeType.AUDIO_AAC,
|
||||
audioBitrate: 48000,
|
||||
audioSampleRate: 48000,
|
||||
fileFormat: media.ContainerFormatType.CFT_MPEG_4,
|
||||
videoBitrate: 48000,
|
||||
videoCodec: media.CodecMimeType.VIDEO_MPEG4,
|
||||
videoFrameWidth: 480,
|
||||
videoFrameHeight: 360,
|
||||
videoFrameRate: 30,
|
||||
};
|
||||
private videoSourceType: number = 0;
|
||||
|
||||
constructor() {
|
||||
this.mediaModel = MediaModel.getMediaInstance();
|
||||
this.receiver = image.createImageReceiver(
|
||||
cameraWH.width,
|
||||
cameraWH.height,
|
||||
FOUR,
|
||||
EIGHT
|
||||
);
|
||||
Logger.info(TAG, 'createImageReceiver');
|
||||
this.receiver.on('imageArrival', () => {
|
||||
Logger.info(TAG, 'imageArrival');
|
||||
this.receiver.readNextImage((err, image) => {
|
||||
Logger.info(TAG, 'readNextImage');
|
||||
if (err || image === undefined) {
|
||||
Logger.error(TAG, 'failed to get valid image');
|
||||
return;
|
||||
}
|
||||
image.getComponent(FOUR, (errMsg, img) => {
|
||||
Logger.info(TAG, 'getComponent');
|
||||
if (errMsg || img === undefined) {
|
||||
Logger.info(TAG, 'failed to get valid buffer');
|
||||
return;
|
||||
}
|
||||
let buffer = new ArrayBuffer(FOUR_THOUSAND_AND_SIXTY_NINE);
|
||||
if (img.byteBuffer) {
|
||||
buffer = img.byteBuffer;
|
||||
} else {
|
||||
Logger.error(TAG, 'img.byteBuffer is undefined');
|
||||
}
|
||||
this.saveImage(buffer, image);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置分辨率
|
||||
* @param videoFrame
|
||||
*/
|
||||
setVideoFrameWH(videoFrame: VideoFrame): void {
|
||||
switch (videoFrame) {
|
||||
case VideoFrame.VIDEOFRAME_800_600:
|
||||
this.videoFrameWH = {
|
||||
width: 800,
|
||||
height: 600,
|
||||
};
|
||||
Logger.info(
|
||||
TAG,
|
||||
`setVideoFrameWH videoFrameWH:${JSON.stringify(this.videoFrameWH)}`
|
||||
);
|
||||
break;
|
||||
case VideoFrame.VIDEOFRAME_1280_720:
|
||||
this.videoFrameWH = {
|
||||
width: 1280,
|
||||
height: 720,
|
||||
};
|
||||
Logger.info(
|
||||
TAG,
|
||||
`setVideoFrameWH videoFrameWH:${JSON.stringify(this.videoFrameWH)}`
|
||||
);
|
||||
break;
|
||||
case VideoFrame.VIDEOFRAME_1920_1080:
|
||||
this.videoFrameWH = {
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
};
|
||||
Logger.info(
|
||||
TAG,
|
||||
`setVideoFrameWH videoFrameWH:${JSON.stringify(this.videoFrameWH)}`
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 设置图片旋转角度
|
||||
* @param imageRotation
|
||||
*/
|
||||
setImageRotation(imageRotation: camera.ImageRotation): void {
|
||||
this.imageRotation = imageRotation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存图片
|
||||
* @param buffer
|
||||
* @param img
|
||||
*/
|
||||
async saveImage(buffer: ArrayBuffer, img: image.Image): Promise<void> {
|
||||
Logger.info(TAG, 'savePicture');
|
||||
this.fileAsset = await this.mediaModel.createAndGetUri(mediaLibrary.MediaType.IMAGE);
|
||||
this.photoPath = this.fileAsset.uri;
|
||||
Logger.info(TAG, `this.photoUri = ${this.photoPath}`);
|
||||
this.fd = await this.mediaModel.getFdPath(this.fileAsset);
|
||||
Logger.info(TAG, `this.fd = ${this.fd}`);
|
||||
await fileIo.write(this.fd, buffer);
|
||||
await this.fileAsset.close(this.fd);
|
||||
await img.release();
|
||||
Logger.info(TAG, 'save image done');
|
||||
if (this.takePictureHandle) {
|
||||
this.takePictureHandle(this.photoPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化相机
|
||||
* @param surfaceId
|
||||
*/
|
||||
async initCamera(surfaceId: string): Promise<void> {
|
||||
Logger.info(TAG, `initCamera surfaceId:${surfaceId}`);
|
||||
await this.cameraRelease();
|
||||
Logger.info(TAG, `deviceInfo.deviceType = ${deviceInfo.deviceType}`);
|
||||
if (deviceInfo.deviceType === 'default') {
|
||||
Logger.info(TAG, `deviceInfo.deviceType default 1 = ${deviceInfo.deviceType}`);
|
||||
this.videoSourceType = 1;
|
||||
Logger.info(TAG, `deviceInfo.deviceType default 2 = ${deviceInfo.deviceType}`);
|
||||
} else {
|
||||
Logger.info(TAG, `deviceInfo.deviceType other 1 = ${deviceInfo.deviceType}`);
|
||||
this.videoSourceType = 0;
|
||||
Logger.info(TAG, `deviceInfo.deviceType other 2 = ${deviceInfo.deviceType}`);
|
||||
}
|
||||
Logger.info(TAG, 'getCameraManager begin');
|
||||
try {
|
||||
Logger.info(TAG, 'getCameraManager try begin');
|
||||
this.cameraMgr = camera.getCameraManager(globalThis.cameraContext);
|
||||
Logger.info(TAG, 'getCameraManager try end');
|
||||
} catch (e) {
|
||||
Logger.info(TAG, `getCameraManager catch e:${JSON.stringify(e)}`);
|
||||
Logger.info(TAG, `getCameraManager catch code:${JSON.stringify(e.code)}`);
|
||||
Logger.info(TAG, `getCameraManager catch message:${JSON.stringify(e.message)}`);
|
||||
}
|
||||
Logger.info(TAG, 'getCameraManager end');
|
||||
Logger.info(TAG, `getCameraManager ${JSON.stringify(this.cameraMgr)}`);
|
||||
this.camerasArray = this.cameraMgr.getSupportedCameras();
|
||||
Logger.info(TAG, `get cameras ${this.camerasArray.length}`);
|
||||
if (this.camerasArray.length === 0) {
|
||||
Logger.info(TAG, 'cannot get cameras');
|
||||
return;
|
||||
}
|
||||
|
||||
let mCamera = this.camerasArray[0];
|
||||
this.cameraInput = this.cameraMgr.createCameraInput(mCamera);
|
||||
this.cameraInput.open();
|
||||
Logger.info(TAG, 'createCameraInput');
|
||||
this.capability = this.cameraMgr.getSupportedOutputCapability(mCamera);
|
||||
let previewProfile = this.capability.previewProfiles[0];
|
||||
this.previewOutput = this.cameraMgr.createPreviewOutput(
|
||||
previewProfile,
|
||||
surfaceId
|
||||
);
|
||||
Logger.info(TAG, 'createPreviewOutput');
|
||||
let rSurfaceId = await this.receiver.getReceivingSurfaceId();
|
||||
let photoProfile = this.capability.photoProfiles[0];
|
||||
this.photoOutPut = this.cameraMgr.createPhotoOutput(
|
||||
photoProfile,
|
||||
rSurfaceId
|
||||
);
|
||||
this.capSession = this.cameraMgr.createCaptureSession();
|
||||
Logger.info(TAG, 'createCaptureSession');
|
||||
this.capSession.beginConfig();
|
||||
Logger.info(TAG, 'beginConfig');
|
||||
this.capSession.addInput(this.cameraInput);
|
||||
this.capSession.addOutput(this.previewOutput);
|
||||
this.capSession.addOutput(this.photoOutPut);
|
||||
await this.capSession.commitConfig();
|
||||
await this.capSession.start();
|
||||
Logger.info(TAG, 'captureSession start');
|
||||
}
|
||||
|
||||
setTakePictureHandleCallback(callback): void {
|
||||
this.takePictureHandle = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拍照
|
||||
*/
|
||||
async takePicture(): Promise<void> {
|
||||
Logger.info(TAG, 'takePicture');
|
||||
if (this.currentMode === cameraMode.modeVideo) {
|
||||
this.currentMode = cameraMode.modePhoto;
|
||||
}
|
||||
Logger.info(TAG, `takePicture imageRotation:${this.imageRotation}`);
|
||||
let photoSettings = {
|
||||
rotation: this.imageRotation,
|
||||
quality: camera.QualityLevel.QUALITY_LEVEL_MEDIUM,
|
||||
location: {
|
||||
// 位置信息,经纬度
|
||||
latitude: 12.9698,
|
||||
longitude: 77.75,
|
||||
altitude: 1000,
|
||||
},
|
||||
mirror: false,
|
||||
};
|
||||
await this.photoOutPut.capture(photoSettings);
|
||||
Logger.info(TAG, 'takePicture done');
|
||||
AppStorage.Set('isRefresh', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始录像
|
||||
*/
|
||||
async startVideo(): Promise<void> {
|
||||
Logger.info(TAG, 'startVideo begin');
|
||||
Logger.info(TAG, 'startVideo 1');
|
||||
await this.capSession.stop();
|
||||
Logger.info(TAG, 'startVideo 2');
|
||||
this.capSession.beginConfig();
|
||||
Logger.info(TAG, 'startVideo 3');
|
||||
if (this.currentMode === cameraMode.modePhoto) {
|
||||
this.currentMode = cameraMode.modeVideo;
|
||||
if (this.photoOutPut) {
|
||||
this.capSession.removeOutput(this.photoOutPut);
|
||||
this.photoOutPut.release();
|
||||
}
|
||||
} else {
|
||||
if (this.videoOutput) {
|
||||
try {
|
||||
Logger.info(TAG, 'startVideo 4');
|
||||
this.capSession.removeOutput(this.videoOutput);
|
||||
Logger.info(TAG, 'startVideo 5');
|
||||
} catch (e) {
|
||||
Logger.info(TAG, `startVideo catch e:${JSON.stringify(e)}`);
|
||||
Logger.info(TAG, `startVideo catch code:${JSON.stringify(e.code)}`);
|
||||
Logger.info(TAG, `startVideo catch message:${JSON.stringify(e.message)}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.videoOutput) {
|
||||
try {
|
||||
Logger.info(TAG, 'startVideo 6');
|
||||
this.capSession.removeOutput(this.videoOutput);
|
||||
Logger.info(TAG, 'startVideo 7');
|
||||
} catch (e) {
|
||||
Logger.info(TAG, `startVideo catch e:${JSON.stringify(e)}`);
|
||||
Logger.info(TAG, `startVideo catch code:${JSON.stringify(e.code)}`);
|
||||
Logger.info(TAG, `startVideo catch message:${JSON.stringify(e.message)}`);
|
||||
}
|
||||
try {
|
||||
Logger.info(TAG, 'startVideo release 1');
|
||||
await this.videoOutput.release();
|
||||
Logger.info(TAG, 'startVideo release 2');
|
||||
} catch (e) {
|
||||
Logger.info(TAG, `startVideo catch e:${JSON.stringify(e)}`);
|
||||
Logger.info(TAG, `startVideo catch code:${JSON.stringify(e.code)}`);
|
||||
Logger.info(TAG, `startVideo catch message:${JSON.stringify(e.message)}`);
|
||||
}
|
||||
}
|
||||
Logger.info(TAG, 'startVideo 8');
|
||||
this.fileAsset = await this.mediaModel.createAndGetUri(mediaLibrary.MediaType.VIDEO);
|
||||
Logger.info(TAG, `startVideo fileAsset:${this.fileAsset}`);
|
||||
this.fd = await this.mediaModel.getFdPath(this.fileAsset);
|
||||
Logger.info(TAG, `startVideo fd:${this.fd}`);
|
||||
media.createAVRecorder(async (error, recorder) => {
|
||||
Logger.info(TAG, `startVideo into createAVRecorder:${recorder}`);
|
||||
if (recorder != null) {
|
||||
Logger.info(TAG, `startVideo into recorder:${recorder}`);
|
||||
this.avRecorder = recorder;
|
||||
Logger.info(TAG, `startVideo createAVRecorder success:${this.avRecorder}`);
|
||||
// 当前录像配置
|
||||
let currConfig = {
|
||||
audioSourceType: 1,
|
||||
videoSourceType: this.videoSourceType,
|
||||
profile: this.videoProfile,
|
||||
url: `fd://${this.fd}`,
|
||||
rotation: 0
|
||||
};
|
||||
Logger.info(TAG, `startVideo into recorder:${recorder}`);
|
||||
await this.avRecorder.prepare(currConfig);
|
||||
Logger.info(TAG, `startVideo videoConfig:${JSON.stringify(currConfig)}`);
|
||||
let videoId = await this.avRecorder.getInputSurface();
|
||||
let videoProfile = this.capability.videoProfiles[0];
|
||||
Logger.info(TAG, `startVideo capability.videoProfiles[]=: ${JSON.stringify(this.capability.videoProfiles)}`);
|
||||
Logger.info(TAG, `startVideo videoProfile:${JSON.stringify(videoProfile)}`);
|
||||
this.videoOutput = this.cameraMgr.createVideoOutput(videoProfile, videoId);
|
||||
Logger.info(TAG, `startVideo videoOutput:${this.videoOutput}`);
|
||||
this.capSession.addOutput(this.videoOutput);
|
||||
Logger.info(TAG, 'startVideo addOutput');
|
||||
await this.capSession.commitConfig();
|
||||
Logger.info(TAG, 'startVideo commitConfig');
|
||||
await this.capSession.start();
|
||||
Logger.info(TAG, 'startVideo commitConfig capSession');
|
||||
await this.videoOutput.start();
|
||||
Logger.info(TAG, 'startVideo commitConfig videoOutput');
|
||||
try {
|
||||
Logger.info(TAG, 'startVideo avRecorder.start 1');
|
||||
await this.avRecorder.start();
|
||||
Logger.info(TAG, 'startVideo avRecorder.start 2');
|
||||
} catch (e) {
|
||||
Logger.info(TAG, `startVideo catch e:${JSON.stringify(e)}`);
|
||||
}
|
||||
|
||||
Logger.info(TAG, 'startVideo end');
|
||||
|
||||
} else {
|
||||
Logger.info(TAG, `startVideo createAVRecorder fail, error:${error}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止录像
|
||||
*/
|
||||
async stopVideo(): Promise<void> {
|
||||
Logger.info(TAG, 'stopVideo called');
|
||||
await this.avRecorder.stop();
|
||||
await this.avRecorder.release();
|
||||
await this.videoOutput.stop();
|
||||
await this.fileAsset.close(this.fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* 资源释放
|
||||
*/
|
||||
async cameraRelease(): Promise<void> {
|
||||
Logger.info(TAG, 'releaseCamera');
|
||||
if (this.cameraInput) {
|
||||
await this.cameraInput.close();
|
||||
}
|
||||
if (this.previewOutput) {
|
||||
await this.previewOutput.release();
|
||||
}
|
||||
if (this.photoOutPut) {
|
||||
await this.photoOutPut.release();
|
||||
}
|
||||
if (this.videoOutput) {
|
||||
await this.videoOutput.release();
|
||||
}
|
||||
if (this.capSession) {
|
||||
await this.capSession.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,173 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import mediaLibrary from '@ohos.multimedia.mediaLibrary';
|
||||
import DateTimeUtil from '../utils/DateTimeUtil';
|
||||
import Logger from '../utils/Logger';
|
||||
|
||||
const TAG = '[MediaModel]';
|
||||
|
||||
type FileInfo = {
|
||||
prefix: string;
|
||||
suffix: string;
|
||||
directory: number;
|
||||
};
|
||||
|
||||
export default class MediaModel {
|
||||
private mediaLibraryTest: mediaLibrary.MediaLibrary = undefined;
|
||||
private static mediaInstance: MediaModel = undefined;
|
||||
|
||||
constructor() {
|
||||
this.mediaLibraryTest = mediaLibrary.getMediaLibrary(globalThis.cameraContext);
|
||||
}
|
||||
|
||||
public static getMediaInstance(): MediaModel {
|
||||
if (this.mediaInstance === undefined) {
|
||||
this.mediaInstance = new MediaModel();
|
||||
}
|
||||
return this.mediaInstance;
|
||||
}
|
||||
|
||||
async createAndGetUri(mediaType: mediaLibrary.MediaType): Promise<mediaLibrary.FileAsset> {
|
||||
let dateTimeUtil: DateTimeUtil = new DateTimeUtil();
|
||||
let info: FileInfo = this.getInfoFromMediaType(mediaType);
|
||||
let name: string = `${dateTimeUtil.getDate()}_${dateTimeUtil.getTime()}`;
|
||||
let displayName: string = `${info.prefix}${name}${info.suffix}`;
|
||||
Logger.info(TAG, `displayName = ${displayName},mediaType = ${mediaType}`);
|
||||
let publicPath: string = await this.mediaLibraryTest.getPublicDirectory(
|
||||
info.directory
|
||||
);
|
||||
Logger.info(TAG, `publicPath = ${publicPath}`);
|
||||
let fileAsset: mediaLibrary.FileAsset = await this.mediaLibraryTest.createAsset(
|
||||
mediaType,
|
||||
displayName,
|
||||
publicPath
|
||||
);
|
||||
return fileAsset;
|
||||
}
|
||||
|
||||
async getFile(dataUri: mediaLibrary.FileAsset): Promise<mediaLibrary.FileAsset> {
|
||||
let fileKeyObj = mediaLibrary.FileKey;
|
||||
if (dataUri !== undefined) {
|
||||
let args = dataUri.id.toString();
|
||||
let fetchOp = {
|
||||
selections: `${fileKeyObj.ID}=?`,
|
||||
selectionArgs: [args],
|
||||
};
|
||||
const fetchFileResult: mediaLibrary.FetchFileResult = await this.mediaLibraryTest.getFileAssets(
|
||||
fetchOp
|
||||
);
|
||||
Logger.info(
|
||||
TAG,
|
||||
`fetchFileResult.getCount() = ${fetchFileResult.getCount()}`
|
||||
);
|
||||
const fileAssets = await fetchFileResult.getAllObject();
|
||||
let fileAsset: mediaLibrary.FileAsset = fileAssets[0];
|
||||
return fileAsset;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async getFdPath(fileAsset: mediaLibrary.FileAsset): Promise<number> {
|
||||
let fd: number = await fileAsset.open('Rw');
|
||||
Logger.info(TAG, `fd = ${fd}`);
|
||||
return fd;
|
||||
}
|
||||
|
||||
async getFileAssetsFromMediaType(mediaType: number): Promise<Array<mediaLibrary.FileAsset>> {
|
||||
Logger.info(TAG, `getFileAssetsFromType,mediaType = ${mediaType}`);
|
||||
let fileKeyObj = mediaLibrary.FileKey;
|
||||
let fileAssets: Array<mediaLibrary.FileAsset> = [];
|
||||
|
||||
try {
|
||||
let fetchOp = {
|
||||
selections: `${fileKeyObj.MEDIA_TYPE}=?`,
|
||||
selectionArgs: [`${mediaType}`],
|
||||
};
|
||||
const fetchFileResult: mediaLibrary.FetchFileResult = await this.mediaLibraryTest.getFileAssets(
|
||||
fetchOp
|
||||
);
|
||||
Logger.info(TAG, `getFileAssetsFromType,fetchFileResult.count = ${fetchFileResult.getCount()}`);
|
||||
if (fetchFileResult.getCount() > 0) {
|
||||
fileAssets = await fetchFileResult.getAllObject();
|
||||
}
|
||||
} catch (err) {
|
||||
console.info(`LSQ: err ${JSON.stringify(err)}`);
|
||||
}
|
||||
return fileAssets;
|
||||
}
|
||||
|
||||
onDateChange(callback: () => void): void {
|
||||
this.mediaLibraryTest.on('albumChange', () => {
|
||||
Logger.info(TAG, 'albumChange called');
|
||||
callback();
|
||||
});
|
||||
this.mediaLibraryTest.on('imageChange', () => {
|
||||
Logger.info(TAG, 'imageChange called');
|
||||
callback();
|
||||
});
|
||||
this.mediaLibraryTest.on('audioChange', () => {
|
||||
Logger.info(TAG, 'audioChange called');
|
||||
callback();
|
||||
});
|
||||
this.mediaLibraryTest.on('videoChange', () => {
|
||||
Logger.info(TAG, 'videoChange called');
|
||||
callback();
|
||||
});
|
||||
this.mediaLibraryTest.on('fileChange', () => {
|
||||
Logger.info(TAG, 'fileChange called');
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
offDateChange(): void {
|
||||
this.mediaLibraryTest.off('albumChange');
|
||||
this.mediaLibraryTest.off('imageChange');
|
||||
this.mediaLibraryTest.off('audioChange');
|
||||
this.mediaLibraryTest.off('videoChange');
|
||||
this.mediaLibraryTest.off('fileChange');
|
||||
}
|
||||
|
||||
getInfoFromMediaType(mediaType: mediaLibrary.MediaType): FileInfo {
|
||||
let fileInfo: FileInfo = {
|
||||
prefix: '',
|
||||
suffix: '',
|
||||
directory: 0
|
||||
};
|
||||
switch (mediaType) {
|
||||
case mediaLibrary.MediaType.FILE:
|
||||
fileInfo.prefix = 'FILE_';
|
||||
fileInfo.suffix = '.txt';
|
||||
fileInfo.directory = mediaLibrary.DirectoryType.DIR_DOCUMENTS;
|
||||
break;
|
||||
case mediaLibrary.MediaType.IMAGE:
|
||||
fileInfo.prefix = 'IMG_';
|
||||
fileInfo.suffix = '.jpg';
|
||||
fileInfo.directory = mediaLibrary.DirectoryType.DIR_IMAGE;
|
||||
break;
|
||||
case mediaLibrary.MediaType.VIDEO:
|
||||
fileInfo.prefix = 'VID_';
|
||||
fileInfo.suffix = '.mp4';
|
||||
fileInfo.directory = mediaLibrary.DirectoryType.DIR_VIDEO;
|
||||
break;
|
||||
case mediaLibrary.MediaType.AUDIO:
|
||||
fileInfo.prefix = 'AUD_';
|
||||
fileInfo.suffix = '.wav';
|
||||
fileInfo.directory = mediaLibrary.DirectoryType.DIR_AUDIO;
|
||||
break;
|
||||
}
|
||||
return fileInfo;
|
||||
}
|
||||
}
|
||||
@ -1,254 +0,0 @@
|
||||
//@ts-ignore
|
||||
import camera from '@ohos.multimedia.camera';
|
||||
import image from '@ohos.multimedia.image'
|
||||
import buffer from '@ohos.buffer';
|
||||
import call from '@ohos.telephony.call';
|
||||
|
||||
|
||||
export class cameraService {
|
||||
constructor(surfaceId) {
|
||||
this.surfaceId = surfaceId
|
||||
}
|
||||
private surfaceId: any = null;
|
||||
private cameraObj: any = null;
|
||||
private cameraManager: any = null;
|
||||
// 相机会话
|
||||
private captureSession: any = null;
|
||||
// 相机输入流
|
||||
private cameraInput: any = null;
|
||||
// 预览输出流
|
||||
private previewOutput: any = null;
|
||||
// 拍照输出流
|
||||
private photoOutput: any = null;
|
||||
// 照片接收对象
|
||||
private imageRecever: any = null;
|
||||
private imageSrc: String;
|
||||
async releaseSource() {
|
||||
// 停止当前会话
|
||||
await this.captureSession.stop()
|
||||
// 释放相机输入流
|
||||
await this.cameraInput.close()
|
||||
// 释放预览输出流
|
||||
await this.previewOutput.release()
|
||||
// 释放拍照输出流
|
||||
await this.photoOutput.release()
|
||||
// 释放会话
|
||||
await this.captureSession.release()
|
||||
// 会话置空
|
||||
this.captureSession = null
|
||||
}
|
||||
|
||||
async initCamera(callBack){
|
||||
let cameraManager = await camera.getCameraManager(globalThis.context)
|
||||
if (!cameraManager) {
|
||||
console.error("jiangsong camera.getCameraManager error")
|
||||
return;
|
||||
}
|
||||
// 监听相机状态变化
|
||||
cameraManager.on('cameraStatus', (err, cameraStatusInfo) => {
|
||||
// console.info(`jiangsong camera : ${cameraStatusInfo.camera.cameraId}`);
|
||||
// console.info(`jiangsong status: ${cameraStatusInfo.status}`);
|
||||
})
|
||||
|
||||
// 获取相机列表
|
||||
let cameraArray = await cameraManager.getSupportedCameras();
|
||||
if (cameraArray.length <= 0) {
|
||||
console.error("jiangsong cameraManager.getSupportedCameras error")
|
||||
return;
|
||||
}
|
||||
|
||||
for (let index = 0; index < cameraArray.length; index++) {
|
||||
console.info('cameraId : ' + cameraArray[index].cameraId); // 获取相机ID
|
||||
console.info('cameraPosition : ' + cameraArray[index].cameraPosition); // 获取相机位置
|
||||
console.info('cameraType : ' + cameraArray[index].cameraType); // 获取相机类型
|
||||
console.info('connectionType : ' + cameraArray[index].connectionType); // 获取相机连接类型
|
||||
}
|
||||
|
||||
// 创建相机输入流
|
||||
try {
|
||||
this.cameraInput = cameraManager.createCameraInput(cameraArray[0]);
|
||||
} catch (error) {
|
||||
console.error('jiangsong Failed to createCameraInput errorCode = ' + error.code);
|
||||
}
|
||||
|
||||
// 监听cameraInput错误信息
|
||||
let cameraDevice = cameraArray[0];
|
||||
this.cameraInput.on('error', cameraDevice, (error) => {
|
||||
console.info(`jiangsong Camera input error code: ${error.code}`);
|
||||
})
|
||||
|
||||
// 打开相机
|
||||
await this.cameraInput.open((err) => {
|
||||
if (err) {
|
||||
console.error(`jiangsong Failed to open the camera. ${err.code}`);
|
||||
return;
|
||||
}
|
||||
console.log('jiangsong Callback returned with camera opened.');
|
||||
});
|
||||
// 获取相机设备支持的输出流能力
|
||||
let cameraOutputCap = await cameraManager.getSupportedOutputCapability(cameraArray[0]);
|
||||
if (!cameraOutputCap) {
|
||||
console.error("jiangsong cameraManager.getSupportedOutputCapability error")
|
||||
return;
|
||||
}
|
||||
console.info("outputCapability: " + JSON.stringify(cameraOutputCap));
|
||||
|
||||
let previewProfilesArray = cameraOutputCap.previewProfiles;
|
||||
if (!previewProfilesArray) {
|
||||
console.error("jiangsong createOutput previewProfilesArray == null || undefined")
|
||||
}
|
||||
|
||||
let photoProfilesArray = cameraOutputCap.photoProfiles;
|
||||
if (!photoProfilesArray) {
|
||||
console.error("jiangsong createOutput photoProfilesArray == null || undefined")
|
||||
}
|
||||
|
||||
|
||||
// 创建预览输出流,其中参数 surfaceId 参考上文 XComponent 组件,预览流为XComponent组件提供的surface
|
||||
try {
|
||||
this.previewOutput = cameraManager.createPreviewOutput(previewProfilesArray[0], this.surfaceId)
|
||||
} catch (error) {
|
||||
console.error("jiangsong Failed to create the PreviewOutput instance.")
|
||||
}
|
||||
|
||||
// 监听预览输出错误信息
|
||||
this.previewOutput.on('error', (error) => {
|
||||
console.info(`jiangosng Preview output error code: ${error.code}`);
|
||||
})
|
||||
|
||||
// 创建ImageReceiver对象,并设置照片参数:分辨率大小是根据前面 photoProfilesArray 获取的当前设备所支持的拍照分辨率大小去设置
|
||||
this.imageRecever = await image.createImageReceiver(1920, 1080, 4, 8);
|
||||
|
||||
this.imageRecever.on('imageArrival',async () => {
|
||||
|
||||
console.info(`jiangsong imageArrival `);
|
||||
let img = await this.imageRecever.readLatestImage()
|
||||
let component = await img.getComponent(4)
|
||||
let buf = buffer.from(component.byteBuffer);
|
||||
let str = buf.toString('base64')
|
||||
|
||||
console.log('jiangsong getComponent buf str. ')
|
||||
if(callBack) {
|
||||
callBack(str)
|
||||
}
|
||||
})
|
||||
// 获取照片显示SurfaceId
|
||||
let photoSurfaceId = await this.imageRecever.getReceivingSurfaceId()
|
||||
// 创建拍照输出流
|
||||
try {
|
||||
this.photoOutput = cameraManager.createPhotoOutput(photoProfilesArray[0], photoSurfaceId)
|
||||
} catch (error) {
|
||||
console.error('jiangsong Failed to createPhotoOutput errorCode = ' + error.code);
|
||||
}
|
||||
//创建会话
|
||||
try {
|
||||
this.captureSession = cameraManager.createCaptureSession()
|
||||
} catch (error) {
|
||||
console.error('jiangsong Failed to create the CaptureSession instance. errorCode = ' + error.code);
|
||||
}
|
||||
|
||||
// 监听session错误信息
|
||||
this.captureSession.on('error', (error) => {
|
||||
console.info(`jiangsong Capture session error code: ${error.code}`);
|
||||
})
|
||||
|
||||
// 开始配置会话
|
||||
try {
|
||||
this.captureSession.beginConfig()
|
||||
} catch (error) {
|
||||
console.error('jiangsong Failed to beginConfig. errorCode = ' + error.code);
|
||||
}
|
||||
|
||||
// 向会话中添加相机输入流
|
||||
try {
|
||||
this.captureSession.addInput(this.cameraInput)
|
||||
} catch (error) {
|
||||
console.error('jiangsong Failed to addInput. errorCode = ' + error.code);
|
||||
}
|
||||
|
||||
// 向会话中添加预览输出流
|
||||
try {
|
||||
this.captureSession.addOutput(this.previewOutput)
|
||||
} catch (error) {
|
||||
console.error('jiangsong Failed to addOutput(previewOutput). errorCode = ' + error.code);
|
||||
}
|
||||
|
||||
// 向会话中添加拍照输出流
|
||||
try {
|
||||
this.captureSession.addOutput(this.photoOutput)
|
||||
} catch (error) {
|
||||
console.error('jiangsong Failed to addOutput(photoOutput). errorCode = ' + error.code);
|
||||
}
|
||||
|
||||
// 提交会话配置
|
||||
await this.captureSession.commitConfig()
|
||||
|
||||
// 启动会话
|
||||
await this.captureSession.start().then(() => {
|
||||
console.info('jiangsong Promise returned to indicate the session start success.');
|
||||
})
|
||||
// 判断设备是否支持闪光灯
|
||||
let flashStatus
|
||||
try {
|
||||
flashStatus = this.captureSession.hasFlash()
|
||||
} catch (error) {
|
||||
console.error('jiangsong Failed to hasFlash. errorCode = ' + error.code);
|
||||
}
|
||||
console.info('jiangsong Promise returned with the flash light support status:' + flashStatus);
|
||||
|
||||
if (flashStatus) {
|
||||
// 判断是否支持自动闪光灯模式
|
||||
let flashModeStatus
|
||||
try {
|
||||
let status = this.captureSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO)
|
||||
flashModeStatus = status
|
||||
} catch (error) {
|
||||
console.error('jiangsong Failed to check whether the flash mode is supported. errorCode = ' + error.code);
|
||||
}
|
||||
if(flashModeStatus) {
|
||||
// 设置自动闪光灯模式
|
||||
try {
|
||||
this.captureSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO)
|
||||
} catch (error) {
|
||||
console.error('jiangsong Failed to set the flash mode. errorCode = ' + error.code);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
takePhoto() {
|
||||
let settings = {
|
||||
quality: camera.QualityLevel.QUALITY_LEVEL_HIGH, // 设置图片质量高
|
||||
rotation: camera.ImageRotation.ROTATION_0 // 设置图片旋转角度0
|
||||
}
|
||||
|
||||
// 使用当前拍照设置进行拍照
|
||||
this.photoOutput.capture(settings, async (err) => {
|
||||
if (err) {
|
||||
console.error(`jiangsong Failed to capture the photo ${err.message}` + JSON.stringify(err));
|
||||
return;
|
||||
}
|
||||
|
||||
console.info('jiangsong Callback invoked to indicate the photo capture request success.' + JSON.stringify(this.imageRecever))
|
||||
// console.info('jiangsong Callback invoked to indicate the photo capture request success.');
|
||||
});
|
||||
}
|
||||
|
||||
async getPhoto() {
|
||||
// try {
|
||||
// let img = await this.imageRecever.readLatestImage()
|
||||
// // console.log('jiangsong readLatestImage success.' + JSON.stringify(img.clipRect));
|
||||
// let component = await img.getComponent(4)
|
||||
// let buf = buffer.from(component.byteBuffer);
|
||||
// let str = buf.toString('base64')
|
||||
// console.log('jiangsong getComponent buf str. ' + str.length + '--' + str.slice(0, 100))
|
||||
// this.imageSrc = str;
|
||||
// return str;
|
||||
// } catch (e) {
|
||||
// this.sleep(1000);
|
||||
// return await this.getPhoto()
|
||||
// }
|
||||
}
|
||||
sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay))
|
||||
|
||||
}
|
||||
@ -157,6 +157,7 @@ export async function getSingleCenterTable(param) {
|
||||
// .catch(err => {
|
||||
// reslove(false)
|
||||
// })
|
||||
console.log('联网更新失败,请检查网络后重新更新')
|
||||
promptAction.showToast({
|
||||
message: `联网更新失败,请检查网络后重新更新`,
|
||||
duration: 3000
|
||||
|
||||
@ -28,7 +28,7 @@ import DeviceInfoTable from '../constants/DeviceInfoTable'
|
||||
import USER from '../constants/USER'
|
||||
import util from '@ohos.util';
|
||||
import zlib from '@ohos.zlib';
|
||||
import FileModel from '../../pages/judgeSDK/utils/fileModel';
|
||||
import FileModel from '../../pages/judgeSDK/utils/file-model';
|
||||
// @ts-nocheck
|
||||
//读表
|
||||
//参数平台
|
||||
@ -361,7 +361,7 @@ export async function upDataZhongxinginitialization(param){
|
||||
}
|
||||
console.log('daihai2')
|
||||
|
||||
initialization(str).then((res)=>{
|
||||
initialization(str).then(async (res)=>{
|
||||
console.log('daihai3',JSON.stringify(res))
|
||||
if(!res){
|
||||
resolve(false)
|
||||
@ -374,21 +374,14 @@ export async function upDataZhongxinginitialization(param){
|
||||
if(!centerToMap[key]){
|
||||
continue
|
||||
}
|
||||
setSyncCenterSqlData(key,res,param).then((flag) => {
|
||||
if(!flag){
|
||||
const data= await setSyncCenterSqlData(key,res,param)
|
||||
if(!data){
|
||||
resolve(false)
|
||||
return
|
||||
}{
|
||||
}
|
||||
}
|
||||
resolve(true)
|
||||
}
|
||||
}).catch ((error) => {
|
||||
resolve(false)
|
||||
console.log(error)
|
||||
})
|
||||
}
|
||||
console.log('daihai4')
|
||||
|
||||
resolve(true)
|
||||
|
||||
console.log('resposestart')
|
||||
|
||||
}).catch((Error)=>{
|
||||
|
||||
@ -46,22 +46,22 @@ export default class FileUtil{
|
||||
*
|
||||
*/
|
||||
public addFile = async (filePath:string,content:string,type?:string)=>{
|
||||
const { READ_WRITE,CREATE,APPEND,TRUNC }= fs.OpenMode
|
||||
try {
|
||||
console.log('content',content)
|
||||
let file = fs.openSync(filePath, TRUNC|READ_WRITE |CREATE|APPEND);
|
||||
const option={
|
||||
offset:0,
|
||||
length:content.length,
|
||||
encoding:'utf-8'
|
||||
const { READ_WRITE,CREATE,APPEND }= fs.OpenMode
|
||||
const isExit = fs.accessSync(filePath);
|
||||
//文件存在先删除
|
||||
if(isExit){
|
||||
fs.unlinkSync(filePath);
|
||||
}
|
||||
fs.writeSync(file.fd,content,option)
|
||||
try {
|
||||
let file = fs.openSync(filePath, READ_WRITE | CREATE);
|
||||
//追加写入文件
|
||||
fs.writeSync(file.fd,content)
|
||||
fs.closeSync(file)
|
||||
console.error(LOGTAG,'写入文件成功')
|
||||
return true
|
||||
|
||||
}catch (e){
|
||||
console.error(LOGTAG,JSON.stringify(e))
|
||||
console.error(LOGTAG,'写入失败',JSON.stringify(e))
|
||||
}
|
||||
}
|
||||
/*
|
||||
@ -72,6 +72,15 @@ export default class FileUtil{
|
||||
const { READ_WRITE,CREATE,APPEND }= fs.OpenMode
|
||||
try {
|
||||
let file = fs.openSync(filePath, READ_WRITE | APPEND |CREATE);
|
||||
let index
|
||||
// if(type=='overWrite'){
|
||||
// //文件覆蓋
|
||||
// index=0
|
||||
// }else{
|
||||
// //文件追加
|
||||
// const str = fs.readTextSync(filePath);
|
||||
// index= str.length
|
||||
// }
|
||||
const newStr = content + '\n'
|
||||
//追加写入文件
|
||||
fs.writeSync(file.fd,newStr)
|
||||
|
||||
@ -18,9 +18,9 @@ export async function getTCP() {
|
||||
await globalThis.TcpClient.onMessage((val)=>{
|
||||
setTimeout(()=>{
|
||||
globalThis.TcpClient.sendMsg('1002')//1002
|
||||
if(val&&!globalThis.closeUDPSocket){
|
||||
if(val){
|
||||
// const msg=val.substring(5,val.length-1)
|
||||
console.log('socketTag[PLC.UdpClient]closeUDPSocket',globalThis.closeUDPSocket)
|
||||
console.log('socketTag[PLC.UdpClient] status:',globalThis.udpClient.getStatus())
|
||||
globalThis.udpClient?.sendMsg(val)
|
||||
}
|
||||
},1000)
|
||||
@ -40,11 +40,10 @@ export async function getTCP() {
|
||||
hilog.info(0x0000, 'testTag', "valvalval2" + JSON.stringify(val));
|
||||
setTimeout(()=>{
|
||||
globalThis.TcpClient.sendMsg('1002')//1002
|
||||
if(globalThis.udpClient && val&&!globalThis.closeUDPSocket){
|
||||
if(val&& globalThis.udpClient?.sendMsg){
|
||||
// const msg=val.substring(5,val.length-1)
|
||||
console.log('socketTag[PLC.UdpClient]closeUDPSocket',globalThis.closeUDPSocket)
|
||||
|
||||
globalThis.udpClient.sendMsg&&globalThis.udpClient?.sendMsg(val)
|
||||
globalThis.udpClient?.sendMsg(val)
|
||||
}
|
||||
},1000)
|
||||
|
||||
|
||||
@ -1,96 +1,114 @@
|
||||
import UdpClient from './UdpClient';
|
||||
//import UdpClient from './UdpClient';
|
||||
import UdpClientByCenter from './UdpClientByCenter';
|
||||
import { getSyncData} from '../service/initable'
|
||||
import { dateFormat } from '../../common/utils/tools'
|
||||
import prompt from '@ohos.prompt'
|
||||
import TcpClient from './TcpClient';
|
||||
import {string2Bytes} from '../../common/utils/tools'
|
||||
export async function sendMsg(val){
|
||||
import { getSyncData } from '../service/initable'
|
||||
import { getChuankouFn } from '../../common/service/indexService'
|
||||
|
||||
export async function sendMsg(val) {
|
||||
// globalThis.udpClient1&&globalThis.udpClient1.sendMsg(val)
|
||||
}
|
||||
export async function getUDP() {
|
||||
getSyncData('IpConfigTable').then((result:Array<any>)=>{
|
||||
if(result.length){
|
||||
if(globalThis.udpClient&&!globalThis.closeUDPSocket){
|
||||
globalThis.udpClient.closeUdp(()=>{
|
||||
setTimeout(()=>{
|
||||
globalThis.udpClient.rebindUdp(result[0].udplocalIp, result[0].udplocalIpPort,result[0].udpOppositeIp,result[0].udpOppositeIpPort)
|
||||
globalThis.udpClient.sendMsg('111')
|
||||
globalThis.host=`http://${result[0].centerIp}:${result[0].centerPort}`
|
||||
globalThis.udpClient.onError(globalThis.udpClient.onMessage?globalThis.udpClient.onMessage:()=>{})
|
||||
|
||||
},1000)
|
||||
export async function getUDP() {
|
||||
console.log(` getUDP enter`);
|
||||
getSyncData('IpConfigTable').then((result: Array<any>) => {
|
||||
if (result.length) {
|
||||
console.log(` getUDP has IPConfigTable `);
|
||||
if (globalThis.udpClient && globalThis.udpClient.closeUdp) {
|
||||
console.log(` getUDP has udclent close and rebind `);
|
||||
globalThis.udpClient.closeUdp(() => {
|
||||
setTimeout(() => {
|
||||
globalThis.udpClient.rebindUdp(result[0].udplocalIp, result[0].udplocalIpPort, result[0].udpOppositeIp, result[0].udpOppositeIpPort)
|
||||
globalThis.udpClient.sendMsg('111', null)
|
||||
globalThis.host = `http://${result[0].centerIp}:${result[0].centerPort}`
|
||||
globalThis.udpClient.onError_resend(globalThis.udpClient.onMessage_1?globalThis.udpClient.onMessage_1:()=>{})
|
||||
}, 1000)
|
||||
})
|
||||
}else{
|
||||
const udpClient: UdpClient =new UdpClient(result[0].udplocalIp, result[0].udplocalIpPort,result[0].udpOppositeIp,result[0].udpOppositeIpPort)
|
||||
}
|
||||
else {
|
||||
// 未绑定
|
||||
console.log(` getUDP has no udclent and bind `);
|
||||
const udpClient: UdpClientByCenter = new UdpClientByCenter(result[0].udplocalIp, result[0].udplocalIpPort, result[0].udpOppositeIp, result[0].udpOppositeIpPort)
|
||||
udpClient.bindUdp()
|
||||
udpClient.sendMsg('111')
|
||||
globalThis.host = `http://${result[0].centerIp}:${result[0].centerPort}`
|
||||
// udpClient.onError_resend(globalThis.udpClient.onMessage_1?globalThis.udpClient.onMessage_1:()=>{})
|
||||
globalThis.udpClient = udpClient
|
||||
globalThis.host=`http://${result[0].centerIp}:${result[0].centerPort}`
|
||||
globalThis.udpClient.onError(globalThis.udpClient.onMessage?globalThis.udpClient.onMessage:()=>{})
|
||||
|
||||
getChuankouFn()
|
||||
}
|
||||
|
||||
}else{
|
||||
globalThis.udpClient={}
|
||||
globalThis.udpClient.onMessage=()=>{}
|
||||
globalThis.host=''
|
||||
} else {
|
||||
console.log(` getUDP has no IPConfigTable `);
|
||||
// if(globalThis.udpClient)
|
||||
// {
|
||||
// console.log(` getUDP2 has IPConfigTable ,has udpClient ,close it`);
|
||||
// globalThis.udpClient.closeUdp(async ()=>{ })
|
||||
// }
|
||||
globalThis.udpClient = {}
|
||||
globalThis.udpClient.onMessage_1 = () => {}
|
||||
globalThis.host = ''
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export async function getUDP2() {
|
||||
getSyncData('IpConfigTable').then(async (result:Array<any>)=>{
|
||||
if(result.length){
|
||||
if(globalThis.udpClient2&&!globalThis.closeHeartSocket){
|
||||
|
||||
globalThis.udpClient2.closeUdp(async ()=>{
|
||||
setTimeout(()=>{
|
||||
globalThis.udpClient2.rebindUdp(result[0].udplocalIp, '8800',globalThis.carInfo?.udpAddress,globalThis.carInfo?.messagePort)
|
||||
globalThis.udpClient2.onMessage((val)=>{
|
||||
console.log(` getUDP2 enter`);
|
||||
getSyncData('IpConfigTable').then(async (result: Array<any>) => {
|
||||
if (result.length) {
|
||||
console.log(` getUDP2 has IPConfigTable `);
|
||||
if (globalThis.udpClient2 && globalThis.udpClient2.closeUdp) {
|
||||
console.log(` getUDP2 has udclent ,close and rebind `);
|
||||
globalThis.udpClient2.closeUdp(async () => {
|
||||
setTimeout(() => {
|
||||
globalThis.udpClient2.rebindUdp(result[0].udplocalIp, '8800', globalThis.carInfo?.udpAddress, globalThis.carInfo?.messagePort)
|
||||
}, 1000)
|
||||
})
|
||||
globalThis.udpClient2.onError()
|
||||
globalThis.udpClient2.setMsgCallBack=()=>{}
|
||||
},1000)
|
||||
}
|
||||
else {
|
||||
// 未绑定
|
||||
console.log(` getUDP2 has no udclent and bind `);
|
||||
const udpClient2: UdpClientByCenter = new UdpClientByCenter(result[0].udplocalIp, '8800', globalThis.carInfo?.udpAddress, globalThis.carInfo?.messagePort)
|
||||
|
||||
})
|
||||
}else{
|
||||
const udpClient: UdpClientByCenter =new UdpClientByCenter(result[0].udplocalIp, '8800',globalThis.carInfo?.udpAddress,globalThis.carInfo?.messagePort)
|
||||
globalThis.udpClient2 = udpClient
|
||||
globalThis.udpClient2.bindUdp()
|
||||
globalThis.udpClient2.onError()
|
||||
globalThis.udpClient2.onMessage((val)=>{
|
||||
if(val.id=='32'){
|
||||
globalThis.signNum=val.body[1]
|
||||
udpClient2.bindUdp()
|
||||
udpClient2.onError_Callback()
|
||||
udpClient2.onMessage_1((val) => {
|
||||
if (val.id == '32') {
|
||||
globalThis.signNum = val.body[1]
|
||||
|
||||
}else if(val.id=='46'){
|
||||
} else if (val.id == '46') {
|
||||
let tmpList = []
|
||||
const str = globalThis.lsh
|
||||
for (let i = 0;i < str.length; i++) {
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
tmpList.push(this.string2Bytes(str.charCodeAt(i), 1 * 8)[0])
|
||||
}
|
||||
const param = { id: 47, list: tmpList, carNo: globalThis.carInfo.carNo, placeId: globalThis.carInfo.examinationRoomId }
|
||||
const param = {
|
||||
id: 47,
|
||||
list: tmpList,
|
||||
carNo: globalThis.carInfo.carNo,
|
||||
placeId: globalThis.carInfo.examinationRoomId
|
||||
}
|
||||
globalThis.udpClient2.send(param)
|
||||
}
|
||||
})
|
||||
globalThis.udpClient2 = udpClient2
|
||||
}
|
||||
} else {
|
||||
globalThis.udpClient2 = {}
|
||||
globalThis.udpClient2.onMessage_2 = () => {
|
||||
}
|
||||
globalThis.udpClient2.setMsgCallBack = () => {
|
||||
}
|
||||
}else{
|
||||
globalThis.udpClient2={}
|
||||
globalThis.udpClient2.onMessage=()=>{}
|
||||
globalThis.udpClient2.setMsgCallBack=()=>{}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export async function setTopLineUdp(){
|
||||
export async function setTopLineUdp() {
|
||||
const config = await getSyncData('IpConfigTable');
|
||||
if(config && config[0] && config[0].udplocalIp){
|
||||
if (config && config[0] && config[0].udplocalIp) {
|
||||
const {udplocalIp,udpOppositeIp,udpOppositeIpPort} = config[0];
|
||||
const udpClient: UdpClientByCenter = new UdpClientByCenter(udplocalIp, '55509',udpOppositeIp,udpOppositeIpPort)
|
||||
const udpClient: UdpClientByCenter = new UdpClientByCenter(udplocalIp, '55509', udpOppositeIp, udpOppositeIpPort)
|
||||
udpClient.bindUdp()
|
||||
|
||||
return {
|
||||
send(bytes){
|
||||
send(bytes) {
|
||||
udpClient.sendHeadMsg(bytes)
|
||||
}
|
||||
}
|
||||
@ -98,29 +116,32 @@ export async function setTopLineUdp(){
|
||||
}
|
||||
|
||||
//
|
||||
export async function setJudgeUdp(){
|
||||
export async function setJudgeUdp() {
|
||||
const config = await getSyncData('IpConfigTable');
|
||||
|
||||
let udpIndex = 0;
|
||||
let currentUdpIndex = 0;
|
||||
let judgeUdpTimer
|
||||
clearInterval(judgeUdpTimer)
|
||||
judgeUdpTimer = setInterval(()=>{
|
||||
judgeUdpTimer = setInterval(() => {
|
||||
udpIndex += 1;
|
||||
},1000);
|
||||
}, 1000);
|
||||
|
||||
if(config && config[0] && config[0].udplocalIp){
|
||||
if (config && config[0] && config[0].udplocalIp) {
|
||||
const {udplocalIp} = config[0];
|
||||
const udpClient: UdpClientByCenter = new UdpClientByCenter(udplocalIp, '8080',globalThis.carInfo?.gpsAddress,globalThis.carInfo?.hintPort)
|
||||
udpClient.bindUdp()
|
||||
udpClient.onMessage((val)=>{
|
||||
console.log('valval',val)
|
||||
const udpClientbyCenter: UdpClientByCenter = new UdpClientByCenter(udplocalIp, '8080', globalThis.carInfo?.gpsAddress, globalThis.carInfo?.hintPort)
|
||||
udpClientbyCenter.bindUdp()
|
||||
udpClientbyCenter.onMessage_1((val) => {
|
||||
console.log('valval', val)
|
||||
})
|
||||
globalThis.judgeUdpClient = udpClient;
|
||||
// globalThis.judgeUdpClient = udpClientbyCenter;
|
||||
return {
|
||||
send(bytes){
|
||||
if(udpIndex > currentUdpIndex){
|
||||
udpClient.sendMsg({id:45,list:bytes,carNo:globalThis.carInfo.carNo,placeId:globalThis.carInfo.examinationRoomId})
|
||||
send(bytes) {
|
||||
if (udpIndex > currentUdpIndex) {
|
||||
udpClientbyCenter.sendMsgExt({ id: 45,
|
||||
list: bytes,
|
||||
carNo: globalThis.carInfo.carNo,
|
||||
placeId: globalThis.carInfo.examinationRoomId })
|
||||
currentUdpIndex = udpIndex
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ export default class TcpClient {
|
||||
this.localIpPort = localIpPort
|
||||
this.oppositeIpPort = oppositeIpPort
|
||||
console.log(TAG,'tcpreBind', this.localIp,this.localIpPort)
|
||||
let promise=this.tcp.bind({ address: this.localIp, port:parseInt(this.localIpPort)}, err => {
|
||||
let promise=this.tcp.bind({ address: this.localIp, port:parseInt(this.localIpPort), family: 1 }, err => {
|
||||
if (err) {
|
||||
globalThis.getCloseTcp=true
|
||||
hilog.info(0x0000, 'testTag', "tcpreBinderror:" + JSON.stringify(err));
|
||||
@ -60,7 +60,7 @@ export default class TcpClient {
|
||||
bindTcp() {
|
||||
console.log(TAG,'tcpbind',this.localIp,'localIp',this.localIpPort)
|
||||
return new Promise((resolve,reject)=>{
|
||||
let promise=this.tcp.bind({ address: this.localIp, port:parseInt(this.localIpPort) }, err => {
|
||||
let promise=this.tcp.bind({ address: this.localIp, port:parseInt(this.localIpPort), family: 1 }, err => {
|
||||
if (err) {
|
||||
console.log('testTag tcp bind faile');
|
||||
globalThis.getCloseTcp=true
|
||||
@ -86,7 +86,7 @@ export default class TcpClient {
|
||||
connectTcp(){
|
||||
console.log(TAG,'tcpConnect',this.oppositeIp,'localIp',this.oppositeIpPort)
|
||||
return new Promise((resolve,reject)=>{
|
||||
let promise = this.tcp.connect({ address: {address: this.oppositeIp, port: parseInt(this.oppositeIpPort)} , timeout: 6000});
|
||||
let promise = this.tcp.connect({ address: {address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1} , timeout: 6000});
|
||||
promise.then(() => {
|
||||
|
||||
this.tcp.setExtraOptions({
|
||||
|
||||
@ -50,7 +50,7 @@ export default class UdpClient {
|
||||
this.localIpPort = localIpPort
|
||||
this.oppositeIpPort = oppositeIpPort
|
||||
let promise = this.udp.bind({
|
||||
address: this.localIp, port: parseInt(this.localIpPort)
|
||||
address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
});
|
||||
promise.then(() => {
|
||||
globalThis.closeUDPSocket=false
|
||||
@ -67,7 +67,7 @@ export default class UdpClient {
|
||||
let promise = this.udp.bind({
|
||||
// address: '192.168.7.170', port: 20122, family: 1
|
||||
// address: '192.168.7.170', port: 31013, family: 1
|
||||
address: this.localIp, port: parseInt(this.localIpPort)
|
||||
address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
});
|
||||
promise.then(() => {
|
||||
globalThis.closeUDPSocket=false
|
||||
@ -97,6 +97,7 @@ export default class UdpClient {
|
||||
// port: 20022,
|
||||
address: this.oppositeIp,
|
||||
port: parseInt(this.oppositeIpPort),
|
||||
family: 1
|
||||
}
|
||||
});
|
||||
promise.then(() => {
|
||||
@ -125,7 +126,7 @@ export default class UdpClient {
|
||||
|
||||
onMessage(callback?) {
|
||||
this.udp.on('message', value => {
|
||||
// console.log(TAG,'udponmessage')
|
||||
console.log(TAG,'udponmessage')
|
||||
// 收到的是ArrayBuffer 需要进行转换解析
|
||||
globalThis.plcUdpError = false
|
||||
if (value) {
|
||||
@ -178,12 +179,12 @@ export default class UdpClient {
|
||||
if (globalThis.plcUdpError) {
|
||||
num++
|
||||
console.log(TAG,'plc udp信号丢失')
|
||||
// if(num==3){
|
||||
// await this.bindUdp()
|
||||
// await this.sendMsg('111')
|
||||
// await this.onMessage(callback)
|
||||
// num=0
|
||||
// }
|
||||
if(num==3){
|
||||
await this.bindUdp()
|
||||
await this.sendMsg('111')
|
||||
await this.onMessage(callback)
|
||||
num=0
|
||||
}
|
||||
prompt.showToast({
|
||||
message: 'plc udp信号丢失',
|
||||
duration: 2000
|
||||
@ -203,8 +204,6 @@ export default class UdpClient {
|
||||
globalThis.closeUDPSocket=false
|
||||
|
||||
} else {
|
||||
hilog.info(0x0000,TAG, 'udpCLient', 'closeonSuccess');
|
||||
|
||||
globalThis.closeUDPSocket=true
|
||||
|
||||
this.udp.getState((err, data) => {
|
||||
|
||||
@ -13,17 +13,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import socket from '@ohos.net.socket';
|
||||
import fs from '@ohos.file.fs'
|
||||
import mediaLibrary from '@ohos.multimedia.mediaLibrary'
|
||||
// @ts-ignore
|
||||
import socket, { UDPSocket } from '@ohos.net.socket';
|
||||
import { Array2Byte } from '../utils/tools'
|
||||
import FileUtil from '../../common/utils/File'
|
||||
import {fillZero,string2Bytes} from '../utils/tools'
|
||||
import { GlobalConfig } from '../../config/index'
|
||||
import { fillZero, string2Bytes } from '../utils/tools'
|
||||
|
||||
const TAG = '[UdpDemo.UdpClient]'
|
||||
// import common from '@ohos.app.ability.common';
|
||||
import hilog from '@ohos.hilog';
|
||||
import prompt from '@ohos.prompt'
|
||||
import call from '@ohos.telephony.call';
|
||||
|
||||
|
||||
export default class UdpClientByCenter {
|
||||
@ -31,25 +29,35 @@ export default class UdpClientByCenter {
|
||||
private localIpPort: string = ''
|
||||
private oppositeIp: string = ''
|
||||
private oppositeIpPort: string = ''
|
||||
private udpMsg: any=''
|
||||
private num:number = 0
|
||||
private udpMsg: any = ''
|
||||
private num: number = 0
|
||||
private fileUtil: FileUtil
|
||||
private udp: any = null
|
||||
private udp: UDPSocket = null
|
||||
private sendId: any = 0
|
||||
private lsh: string = null
|
||||
private context
|
||||
private stashFn:StashFunction
|
||||
private headLenth:number=9 //消息头长度
|
||||
private stashFn: StashFunction
|
||||
private headLenth: number = 9
|
||||
//消息头长度
|
||||
private isWorking: Boolean = false
|
||||
private plcUdpError = false;
|
||||
private initParam
|
||||
constructor(udplocalIp: string, udplocalIpPort:string,udpOppositeIp: string,udpOppositeIpPort:string) {
|
||||
|
||||
constructor(udplocalIp: string, udplocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) {
|
||||
this.localIp = udplocalIp
|
||||
this.oppositeIp = udpOppositeIp
|
||||
this.localIpPort = udplocalIpPort
|
||||
this.oppositeIpPort = udpOppositeIpPort
|
||||
this.stashFn=()=>{}
|
||||
this.stashFn = () => {
|
||||
}
|
||||
this.udp = socket.constructUDPSocketInstance();
|
||||
}
|
||||
rebindUdp(localIp: string, localIpPort:string,oppositeIp: string,oppositeIpPort:string){
|
||||
|
||||
getStatus() {
|
||||
return this.isWorking
|
||||
}
|
||||
|
||||
rebindUdp(localIp: string, localIpPort: string, oppositeIp: string, oppositeIpPort: string) {
|
||||
this.localIp = localIp
|
||||
this.oppositeIp = oppositeIp
|
||||
this.localIpPort = localIpPort
|
||||
@ -61,197 +69,280 @@ export default class UdpClientByCenter {
|
||||
});
|
||||
|
||||
promise.then(() => {
|
||||
globalThis.closeHeartSocket=false
|
||||
// globalThis.closeHeartSocket=false
|
||||
this.isWorking = true
|
||||
console.log(`${TAG} udp bind success`);
|
||||
}).catch(err => {
|
||||
globalThis.closeHeartSocket=true
|
||||
//globalThis.closeHeartSocket=true
|
||||
this.isWorking = false
|
||||
console.log(`${TAG} udp bind failed:${JSON.stringify(err)}`);
|
||||
});
|
||||
}
|
||||
initHeartSendMsg(param,context){
|
||||
console.log('1111param',JSON.stringify(param))
|
||||
this.initParam=param
|
||||
this.context=context
|
||||
}
|
||||
|
||||
bindUdp() {
|
||||
let promise = this.udp.bind({
|
||||
address: this.localIp, port: parseInt(this.localIpPort), family: 1
|
||||
});
|
||||
promise.then(() => {
|
||||
globalThis.closeHeartSocket=false
|
||||
this.isWorking = true
|
||||
console.log(`${TAG} udp bind success`);
|
||||
}).catch(err => {
|
||||
globalThis.closeHeartSocket=true
|
||||
this.isWorking = false
|
||||
console.log(`${TAG} udp bind failed:${JSON.stringify(err)}`);
|
||||
});
|
||||
}
|
||||
|
||||
//异或运算
|
||||
setMessageExclusive(tmpList){
|
||||
setMessageExclusive(tmpList) {
|
||||
let result = tmpList[0];
|
||||
for (let i = 1; i < tmpList.length; i++) {
|
||||
result = result ^ tmpList[i]
|
||||
}
|
||||
return [result];
|
||||
}
|
||||
|
||||
Array2Byte(array) {
|
||||
var buf = new ArrayBuffer(array.length);
|
||||
var view = new Uint8Array(buf);
|
||||
for (var i = 0; i != array.length; ++i)
|
||||
{
|
||||
for (var i = 0; i != array.length; ++i) {
|
||||
view[i] = array[i] & 0xFF;
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
//length消息体bufferlength id消息类型id bodyStr消息体string
|
||||
// setMsyBody(id,bodyByte){
|
||||
|
||||
// {id: 31,list:[0,1,'0000000000000'],carNo:489,placeId:62}
|
||||
setWholeMsg(params){
|
||||
setWholeMsg(params) {
|
||||
let head = this.setMsgHead(params);
|
||||
let headJudge = this.setMessageExclusive(head);
|
||||
let body = this.setMsgBody(params);
|
||||
let bodyJudge = this.setMessageExclusive(body);
|
||||
let end = [13,10];
|
||||
const arr=[...head, ...headJudge,...body, ...bodyJudge,...end]
|
||||
console.log('BitArray',arr)
|
||||
let end = [13, 10];
|
||||
const arr = [...head, ...headJudge, ...body, ...bodyJudge, ...end]
|
||||
console.log('BitArray', arr)
|
||||
return this.Array2Byte(arr).buffer
|
||||
|
||||
}
|
||||
setMsgHead({id, list, placeId=62, carNo=489}){
|
||||
console.log('globalThis.lshNo',globalThis.lshNo)
|
||||
let a = string2Bytes(`${id}${fillZero(placeId,3)}`, 2*8);
|
||||
console.log('aaa',a)
|
||||
let b = string2Bytes(`${fillZero(carNo,4)}${globalThis.lshNo}`, 4*8);
|
||||
console.log('bbb',b)
|
||||
let c = string2Bytes(list.length, 2*8);
|
||||
return [...a,...b,...c];
|
||||
|
||||
setMsgHead({id, list, placeId=62, carNo=489}) {
|
||||
console.log('globalThis.lshNo', globalThis.lshNo)
|
||||
let a = string2Bytes(`${id}${fillZero(placeId, 3)}`, 2 * 8);
|
||||
console.log('aaa', a)
|
||||
let b = string2Bytes(`${fillZero(carNo, 4)}${globalThis.lshNo}`, 4 * 8);
|
||||
console.log('bbb', b)
|
||||
let c = string2Bytes(list.length, 2 * 8);
|
||||
return [...a, ...b, ...c];
|
||||
}
|
||||
|
||||
setMsgBody({id,list}) {
|
||||
let tmpList = []
|
||||
tmpList = list
|
||||
|
||||
return tmpList ;
|
||||
return tmpList;
|
||||
|
||||
}
|
||||
|
||||
sendHeadMsg(msgData){
|
||||
console.log('sendsnd1')
|
||||
//udpOppositeIp
|
||||
let promise = this.udp.send({
|
||||
data: msgData,
|
||||
address: {
|
||||
address: this.oppositeIp,
|
||||
port: parseInt(this.oppositeIpPort),
|
||||
sendHeadMsg(msgData) {
|
||||
console.log('sendHeadMsg enter')
|
||||
this.sendMsg(msgData, null)
|
||||
console.log('sendHeadMsg exit')
|
||||
}
|
||||
});
|
||||
promise.then(() => {
|
||||
console.log(`${TAG} udpLine send success:`);
|
||||
}).catch(err => {
|
||||
console.log(`${TAG} udpLine send fail:${JSON.stringify(err)}`);
|
||||
});
|
||||
|
||||
sendMsg(msg, sendCallback?) {
|
||||
if (!this.isWorking && sendCallback) {
|
||||
sendCallback()
|
||||
}
|
||||
onError(callback?){
|
||||
this.udp.on('error',async err => {
|
||||
globalThis.closeHeartSocket=true
|
||||
callback&&callback()
|
||||
// callback&&callback()
|
||||
// this.closeUdp(()=>{
|
||||
// this.bindUdp()
|
||||
// })
|
||||
});
|
||||
}
|
||||
setMsgCallBack(callback){
|
||||
this.stashFn=callback?callback:()=>{}
|
||||
}
|
||||
sendMsg(param,context?) {
|
||||
this.udp.getState((err, data) => {
|
||||
if (err) {
|
||||
globalThis.closeHeartSocket=true
|
||||
this.isWorking = false
|
||||
return;
|
||||
}else{
|
||||
console.log('paramparam',JSON.stringify(param))
|
||||
if(context){
|
||||
this.context=context
|
||||
}
|
||||
this.sendId=param.id
|
||||
console.log('sendMsg',JSON.stringify(param))
|
||||
const msgData=this.setWholeMsg(param)
|
||||
// const msgData=this.setMsyBody('31','010000000000000')
|
||||
} else {
|
||||
let promise = this.udp.send({
|
||||
data: msgData,
|
||||
data: msg,
|
||||
address: {
|
||||
address: this.oppositeIp,
|
||||
port: parseInt(this.oppositeIpPort),
|
||||
}
|
||||
});
|
||||
promise.then(() => {
|
||||
if(param.sendCallback){
|
||||
param.sendCallback()
|
||||
if (sendCallback) {
|
||||
sendCallback()
|
||||
}
|
||||
// if(this.sendId=='46'&¶m.callback){
|
||||
// param.callback()
|
||||
// }
|
||||
console.log(`${TAG} udp send success:`);
|
||||
console.log(`${TAG}udpCLient udp send success:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`);
|
||||
}).catch(err => {
|
||||
console.log(`${TAG} udp send fail:${JSON.stringify(err)}`);
|
||||
console.log(`${TAG}udpCLient udp send fail:oppositeIp${this.oppositeIp},oppositeIpPort:${this.oppositeIpPort},localIp:${this.localIp},localIpPort,${this.localIpPort}`);
|
||||
});
|
||||
}
|
||||
console.log('getState success:' + JSON.stringify(data));
|
||||
})
|
||||
}
|
||||
|
||||
sendMsgExt(param, context?) {
|
||||
console.log('sendMsgExt enter');
|
||||
if (context) {
|
||||
this.context = context
|
||||
}
|
||||
onMessage(callback,type?) {
|
||||
this.udp.on('message', value => {
|
||||
let arr=[]
|
||||
this.sendId = param.id
|
||||
const msgData = this.setWholeMsg(param)
|
||||
this.sendMsg(msgData, param.sendCallback)
|
||||
}
|
||||
|
||||
onError_Callback(callback?) {
|
||||
this.udp.on('error', async err => {
|
||||
this.isWorking = false;
|
||||
console.log('UdpClientByCenter onError err:' + JSON.stringify(err));
|
||||
callback && callback()
|
||||
});
|
||||
}
|
||||
|
||||
onError_resend(callback?) {
|
||||
this.udp.on('error', async err => {
|
||||
this.isWorking = false;
|
||||
console.log(TAG, 'udpError', JSON.stringify(err))
|
||||
await this.bindUdp()
|
||||
await this.sendMsg('111', null)
|
||||
await this.onMessage_1(callback)
|
||||
callback && callback()
|
||||
});
|
||||
}
|
||||
|
||||
setMsgCallBack(callback) {
|
||||
this.stashFn = callback ? callback : () => {
|
||||
}
|
||||
}
|
||||
//中心udp回执
|
||||
onMessage_2(callback, type?) {
|
||||
this.udp.on('message', (value, remoteInfo) => {
|
||||
console.log('UdpClientByCenter onMessage msg:' + JSON.stringify(value));
|
||||
let arr = []
|
||||
let dataView = new DataView(value.message)
|
||||
for (let i = 0;i < dataView?.byteLength; ++i) {
|
||||
arr[i]=dataView?.getUint8(i)
|
||||
for (let i = 0; i < dataView?.byteLength; ++i) {
|
||||
arr[i] = dataView?.getUint8(i)
|
||||
}
|
||||
let idNum = '0x' + fillZero(arr[1].toString(16),2) + fillZero(arr[0].toString(16),2) ;
|
||||
let id = Math.floor(+idNum/1000)
|
||||
let idNum = '0x' + fillZero(arr[1].toString(16), 2) + fillZero(arr[0].toString(16), 2);
|
||||
let id = Math.floor(+idNum / 1000)
|
||||
hilog.info(0x0000, 'bitbit', JSON.stringify(arr));
|
||||
|
||||
let lengthNum = '0x' + fillZero(arr[7].toString(16),2) + fillZero(arr[6].toString(16),2) ;
|
||||
let length= +lengthNum;
|
||||
let list=[]
|
||||
for(let i=this.headLenth;i<=this.headLenth+length-1;i++){
|
||||
let lengthNum = '0x' + fillZero(arr[7].toString(16), 2) + fillZero(arr[6].toString(16), 2);
|
||||
let length = +lengthNum;
|
||||
let list = []
|
||||
for (let i = this.headLenth; i <= this.headLenth + length - 1; i++) {
|
||||
list.push(arr[i])
|
||||
}
|
||||
this.stashFn({id,length,body:list,sendId:this.sendId})
|
||||
callback({id,length,body:list,sendId:this.sendId})
|
||||
this.stashFn({
|
||||
id, length, body: list, sendId: this.sendId
|
||||
})
|
||||
callback({
|
||||
id, length, body: list, sendId: this.sendId
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
closeUdp(callback) {
|
||||
this.udp.close(err=>{
|
||||
if(err){
|
||||
|
||||
}else{
|
||||
this.udp.getState((err, data) => {
|
||||
if (err) {
|
||||
return;
|
||||
}else{
|
||||
globalThis.closeHeartSocket=true
|
||||
if(!data.isisClose){
|
||||
setTimeout(()=>{
|
||||
closeUdp(callback?) {
|
||||
console.log('UdpClientByCenter enter closeUdp ip:' + this.localIp + ' port:' + this.localIpPort);
|
||||
this.udp.on('close', () => {
|
||||
console.log('UdpClientByCenter onClose ip:' + this.localIp + ' port:' + this.localIpPort);
|
||||
this.isWorking = false
|
||||
if (callback != null) {
|
||||
callback()
|
||||
},1000)
|
||||
}
|
||||
}
|
||||
)
|
||||
this.udp.close(err => {
|
||||
if (err) {
|
||||
console.log('UdpClientByCenter closeUdp failed ip:' + this.localIp + ' port:' + this.localIpPort + ' err:' + JSON.stringify(err));
|
||||
} else {
|
||||
console.log('UdpClientByCenter closeUdp succeed ip:' + this.localIp + ' port:' + this.localIpPort);
|
||||
}
|
||||
})
|
||||
// let promise = this.udp.getState({});
|
||||
// promise.then(data => {
|
||||
//
|
||||
// console.log('getState success:' + JSON.stringify(data));
|
||||
// }).catch(err => {
|
||||
// callback()
|
||||
// console.log('getState fail');
|
||||
// });
|
||||
}
|
||||
});
|
||||
|
||||
//plc
|
||||
onMessage_1(callback?) {
|
||||
this.udp.on('message', value => {
|
||||
console.log(TAG, 'udponmessage')
|
||||
// 收到的是ArrayBuffer 需要进行转换解析
|
||||
this.plcUdpError = false
|
||||
if (value) {
|
||||
let dataView = new DataView(value.message)
|
||||
let str = ""
|
||||
for (let i = 0; i < dataView?.byteLength; ++i) {
|
||||
let c = String.fromCharCode(dataView?.getUint8(i))
|
||||
if (c !== "\n") {
|
||||
str += c
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`${TAG} udp on message array buffer:${str}`);
|
||||
let strachArr = str.split(',')
|
||||
if (strachArr[0] != '#DN_GD') {
|
||||
return
|
||||
}
|
||||
console.log(`${TAG} udp222 on message array buffer:${str}`);
|
||||
|
||||
strachArr[28] = globalThis.chuankoMsg || '0'
|
||||
// this.stashFn(str)
|
||||
const newArr = JSON.parse(JSON.stringify(strachArr))
|
||||
// this.stashFn=()=>{}
|
||||
callback && callback(newArr.toString())
|
||||
|
||||
} else {
|
||||
callback && callback('')
|
||||
}
|
||||
console.log('messageTimeEnd')
|
||||
this.testIfUdpConnetced(callback)
|
||||
});
|
||||
}
|
||||
|
||||
testIfUdpConnetced(callback) {
|
||||
const arrRed = [0x55, 0xaa, 0x01, 0x01, 0x02, 0x00, 0x03, 0x00];
|
||||
const arrBlue = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00];
|
||||
const arrGreen = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x01];
|
||||
const arrBlueBuffer = Array2Byte(arrBlue).buffer
|
||||
const arrRedBuffer = Array2Byte(arrRed).buffer
|
||||
const arrGreenBugger = Array2Byte(arrGreen).buffer
|
||||
let num = 0
|
||||
//监听udp是否断开
|
||||
clearInterval(globalThis.messageTimer)
|
||||
globalThis.messageTimer = setInterval(() => {
|
||||
const lightLineUdp = globalThis.lightLineUdp
|
||||
const isJudge = globalThis.isJudge
|
||||
setTimeout(async () => {
|
||||
//程序断开
|
||||
lightLineUdp?.send(this.plcUdpError ? arrRedBuffer : (isJudge ? arrGreenBugger : arrBlueBuffer));
|
||||
if (this.plcUdpError) {
|
||||
num++
|
||||
console.log(TAG, 'plc udp信号丢失')
|
||||
if (num == 3) {
|
||||
await this.bindUdp()
|
||||
await this.sendMsg('111', null)
|
||||
await this.onMessage_1(callback)
|
||||
num = 0
|
||||
}
|
||||
prompt.showToast({
|
||||
message: 'plc udp信号丢失',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
this.plcUdpError = true;
|
||||
}, 2000)
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
// initHeartSendMsg(param,context){
|
||||
// console.log('1111param',JSON.stringify(param))
|
||||
// this.initParam=param
|
||||
// this.context=context
|
||||
// }
|
||||
}
|
||||
|
||||
interface StashFunction {
|
||||
(params: { id: number; length: number; body: any[]; sendId: string }): void;
|
||||
(params: {
|
||||
id: number;
|
||||
length: number;
|
||||
body: any[];
|
||||
sendId: string
|
||||
}): void;
|
||||
}
|
||||
@ -21,7 +21,7 @@ export const initJudgeUdp = async () => {
|
||||
globalThis.lightLineUdp = lightLineUdp
|
||||
/*******************************************/
|
||||
|
||||
globalThis.udpClient.onMessage(async (msg) => {
|
||||
globalThis.udpClient.onMessage_1(async (msg) => {
|
||||
const stachArr = msg.split(',')
|
||||
if (stachArr[0] != '#DN_GD') {
|
||||
return
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import http from '@ohos.net.http';
|
||||
import convertxml from '@ohos.convertxml';
|
||||
import prompt from '@ohos.prompt'
|
||||
import { sendGreen } from '../../pages/judgeSDK/utils/judgeCommon';
|
||||
import { sendGreen } from '../../pages/judgeSDK/utils/judge-common';
|
||||
import {GlobalConfig} from '../../config/index'
|
||||
const config = {
|
||||
host:GlobalConfig.host,
|
||||
@ -41,7 +41,7 @@ export default async function request(req: any) {
|
||||
console.info('surenjun',baseUrl)
|
||||
const {result,responseCode} = await httpRequest.request(`${baseUrl}${url}${paramsStr}`, options);
|
||||
console.log('daihai5')
|
||||
let res:any = xml ? xmlToJson(result) : result;
|
||||
let res:any = xml ? xmlToJson(result,url) : result;
|
||||
console.log('daihai55')
|
||||
|
||||
console.log('响应头地址' + JSON.stringify(res))
|
||||
@ -108,8 +108,8 @@ export default async function request(req: any) {
|
||||
}
|
||||
|
||||
//xml格式转JSON
|
||||
function xmlToJson(result) {
|
||||
console.log("xmlToJson begin");
|
||||
function xmlToJson(result,url) {
|
||||
console.log("xmlToJson begin",url);
|
||||
let xmlOptions = {trim : false, declarationKey:"_declaration",
|
||||
instructionKey : "_instruction", attributesKey : "_attributes",
|
||||
textKey : "_text", cdataKey:"_cdata", doctypeKey : "_doctype",
|
||||
@ -125,7 +125,7 @@ function xmlToJson(result) {
|
||||
let {_elements:xmlArr} = conv.convertToJSObject(strXml, xmlOptions);
|
||||
console.log("xmlToJson deeml begin");
|
||||
let res = deeml(xmlArr);
|
||||
console.log("xmlToJson end");
|
||||
console.log("xmlToJson end",url);
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
@ -31,8 +31,6 @@ export default class EntryAbility extends UIAbility {
|
||||
globalThis.version = '2024.11.22.14'
|
||||
globalThis.judgeVersion = '2024.11.22.14'
|
||||
globalThis.videoVersion= '1.0'
|
||||
globalThis.closeUDPSocket=true
|
||||
globalThis.closeHeartSocket=true
|
||||
// globalThis.version = '2023.12.13.01'
|
||||
// globalThis.judgeVersion = '2023.09.30.1'
|
||||
// globalThis.videoVersion= '1.0'
|
||||
|
||||
@ -166,7 +166,7 @@ export default struct Index {
|
||||
|
||||
getPLCInfo() {
|
||||
const that = this
|
||||
globalThis.udpClient && globalThis.udpClient.onMessage((msg) => {
|
||||
globalThis.udpClient && globalThis.udpClient.onMessage_1((msg) => {
|
||||
if (!this.breakFlag) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -216,9 +216,7 @@ struct Index {
|
||||
}
|
||||
|
||||
async testXMLToJSONInWorker() {
|
||||
let workerInstance = new worker.ThreadWorker('entry/ets/workers/worker.ts', {
|
||||
name: 'FriendsMoments Worker'
|
||||
});
|
||||
let workerInstance = new worker.ThreadWorker('entry/ets/workers/worker.ts');
|
||||
const param = {
|
||||
carId: globalThis.carInfo?.carId,
|
||||
examinationRoomId: globalThis.carInfo?.examinationRoomId,
|
||||
@ -231,12 +229,15 @@ struct Index {
|
||||
workerInstance.postMessage(param);
|
||||
workerInstance.onmessage = (e: MessageEvents): void => {
|
||||
console.log("baoyihu after postMessage :", JSON.stringify(e.data));
|
||||
if (e.data.isComplete) {
|
||||
let workData: WorkData = e.data;
|
||||
if (workData.isComplete) {
|
||||
router.pushUrl({
|
||||
url: 'pages/ExaminerLogin',
|
||||
}, router.RouterMode.Single)
|
||||
}
|
||||
this.loading = false
|
||||
workerInstance.terminate();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -258,8 +259,8 @@ struct Index {
|
||||
placeId: globalThis.carInfo.examinationRoomId
|
||||
}
|
||||
// globalThis.udpClient2.initHeartSendMsg(param,this.context)
|
||||
if (!globalThis.closeHeartSocket) {
|
||||
globalThis.udpClient2.sendMsg(param, this.context)
|
||||
if (globalThis.udpClient2.getStatus()) {
|
||||
globalThis.udpClient2.sendMsgExt(param, this.context)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ import LoadingPopup from './compontents/judge/LoadingPopup';
|
||||
import DeductedPopup from './compontents/judge/DeductionPopup';
|
||||
import AmplifyPopup from './compontents/judge/AmplifyPopup';
|
||||
import Judge from './judgeSDK/judge';
|
||||
import { defaultJudgeConfigObj } from './judgeSDK/utils//judgeCommon';
|
||||
import { defaultJudgeConfigObj } from './judgeSDK/utils//judge-common';
|
||||
import {
|
||||
CARINFO,
|
||||
CDSBInfo,
|
||||
@ -21,13 +21,86 @@ import {
|
||||
import { chunkArr, formatTime, getCurrentHourTime, getCurrentTime } from '../common/utils/tools';
|
||||
import { examJudgeEndExam } from './judgeSDK/api/index';
|
||||
import { getSyncData } from '../common/service/initable';
|
||||
import { judgeConfig } from './judgeSDK/utils/judgeConfig';
|
||||
import { judgeConfig } from './judgeSDK/utils/judge-config';
|
||||
import FileUtil from '../common/utils/File';
|
||||
import SignDisplayCom from './compontents/signDisplayCom';
|
||||
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
scroller: Scroller = new Scroller()
|
||||
//页面通用字体大小
|
||||
@State FONTSIZE: number = 28
|
||||
@State BIGFONTSIZE: number = 28
|
||||
//结束考试弹窗
|
||||
@State endPopupVisible: boolean = false
|
||||
//等待弹窗(考试及格,考试不及格使用)
|
||||
@State loadingPopupVisible: boolean = false
|
||||
//实时轨迹弹窗
|
||||
@State signDisplayComVisible: boolean = false
|
||||
@State isDdxk: boolean = false;
|
||||
@State time: string = ''
|
||||
//考试用时
|
||||
@State examTime: number = 0
|
||||
//开始时间
|
||||
@State startTime: string = '00:00:00'
|
||||
@State startFullTime: string = ''
|
||||
@State startHourTime: string = ''
|
||||
//科目类型
|
||||
@State examSubject: 2 | 3 = 3;
|
||||
@State ddxkTime: number = 0;
|
||||
@State ddxkKsxmArr: string[] = ['']
|
||||
@State ddxkKfArr: string[] = ['']
|
||||
@State xmmcStr: string = ''
|
||||
@State carztStr: string = ''
|
||||
@State kfArr: {
|
||||
xmmcStr?: string,
|
||||
score: string,
|
||||
desc: string
|
||||
}[] = []
|
||||
@State name: string = ''
|
||||
@State idCard: string = ''
|
||||
@State totalScore: number = 100
|
||||
//模拟考试项目
|
||||
@State projects: Project[] = []
|
||||
@State projectsObj: ProjectObj = {}
|
||||
@State projectsCenterObj: ProjectObj = {}
|
||||
@State markRuleListObj: MarkRule = {}
|
||||
@State cdsbInfoObj: CDSBInfo = {}
|
||||
@State timer: number = 0
|
||||
@State judgeConfig: { [k: string]: string }[] = []
|
||||
@State judgeConfigObj: { [k: string]: any } = defaultJudgeConfigObj
|
||||
//流水号
|
||||
@State lsh: string = ''
|
||||
@State kszp: string = ''
|
||||
@State ksdd: string = ''
|
||||
@State kssycs: string = ''
|
||||
@State kslx: string = ''
|
||||
//监管接口序列号
|
||||
@State serialNumber: number = 0
|
||||
@State carType: string = ''
|
||||
@State carName: string = ''
|
||||
@State isDeductedPopShow: boolean = false
|
||||
@State isAmplifyPopShow: boolean = false
|
||||
@State amplifiedImgIndex: number = 0
|
||||
@State judge: any = {}
|
||||
//行驶距离
|
||||
@State jl: number = 0
|
||||
//应考里程
|
||||
@State examMileage: string = '0'
|
||||
@State artSubject3Projects: string[] = ['直线', '会车', '变道', '超车', '掉头', '停车']
|
||||
@State artSubject3ProjectsCodesArr: string[] = ['3', '9', '4', '10', '12', '11']
|
||||
@State manualMarkRules: MarkRule[] = []
|
||||
//科目三评判初始化数据
|
||||
@State systemparmArr: SYSTEMPARMARR[] = []
|
||||
@State mapPointItemArr: MAPITEMPOINTITEM[] = []
|
||||
@State carinfoArrr: CARINFO[] = []
|
||||
@State mapPointArr: MAPPOINT[] = []
|
||||
private context = getContext(this) as common.UIAbilityContext;
|
||||
private img: ImageBitmap = new ImageBitmap("/resources/base/media/1.png")
|
||||
//已考的考试项目
|
||||
private wantInfos = []
|
||||
|
||||
async aboutToAppear() {
|
||||
globalThis.windowClass.setWindowSystemBarEnable([''])
|
||||
@ -127,9 +200,10 @@ struct Index {
|
||||
NoCancelId: mark.nocancelid * 1,
|
||||
GPS_SID: mark.gps_sid == 0 ? false : true
|
||||
}
|
||||
const markserial = mark.markserial * 1;
|
||||
|
||||
//筛选出人工评判的扣分
|
||||
if (Number(tempObj.markserial) > 100 && Number(tempObj.markserial) < 200) {
|
||||
if (markserial > 100 && markserial < 200) {
|
||||
this.manualMarkRules.push(tempObj)
|
||||
}
|
||||
this.markRuleListObj[`${mark.itemno}_${mark.markserial}`] = {
|
||||
@ -170,33 +244,6 @@ struct Index {
|
||||
this.examMileage = sys.v_value + '';
|
||||
}
|
||||
|
||||
//364 绕车一周评判时机(1-开始考试后判 2-开始考试前判)
|
||||
if(sys.v_no == '364' && sys.v_value == 2 ){
|
||||
let currentParams: any = router.getParams();
|
||||
const {sczb,kfdm} = currentParams;
|
||||
kfdm.forEach(kf => {
|
||||
const {xmdm, kfdm} = kf
|
||||
const currentKf = this.markRuleListObj[`${xmdm}_${kfdm}`];
|
||||
const currentProject = this.projectsObj[xmdm]
|
||||
this.kfArr.push({
|
||||
//扣分项目名称
|
||||
xmmcStr: currentProject.name,
|
||||
//@ts-ignore
|
||||
xmdm,
|
||||
desc: currentKf.markshow,
|
||||
score: currentKf.markreal,
|
||||
markcatalog: currentKf.markcatalog,
|
||||
markserial: currentKf.markserial,
|
||||
kfxh: currentKf.kfxh
|
||||
})
|
||||
this.totalScore += currentKf.markreal * 1;
|
||||
})
|
||||
this.projectsObj['1'].type = kfdm.length ? '4':'3';
|
||||
this.projectsObj = {
|
||||
...this.projectsObj
|
||||
}
|
||||
}
|
||||
|
||||
this.judgeConfigObj[sys.v_no] = value
|
||||
});
|
||||
this.judgeConfig = syssetJudgeConfigArr;
|
||||
@ -253,8 +300,7 @@ struct Index {
|
||||
//初始化systemParam表
|
||||
async initSystemKm3Param(sysParam?: SYSTEMPARMARR[]) {
|
||||
const systemParms: any = sysParam || await getSyncData('MA_SYSTEMPARM')
|
||||
let currentParams: any = router.getParams();
|
||||
this.wayno = currentParams.wayno
|
||||
|
||||
const {isTrajectoryOpen} = judgeConfig
|
||||
|
||||
systemParms.forEach((systemParm) => {
|
||||
@ -492,7 +538,7 @@ struct Index {
|
||||
if (this.examSubject == 3) {
|
||||
Row() {
|
||||
Text('考试路线:').fontColor('#E5CCA1').fontSize(this.FONTSIZE)
|
||||
Text(`线路${this.wayno}`).fontColor('#FFAD33').fontSize(this.FONTSIZE)
|
||||
Text(`线路${globalThis.carInfo.wayno}`).fontColor('#FFAD33').fontSize(this.FONTSIZE)
|
||||
}
|
||||
}
|
||||
|
||||
@ -532,6 +578,7 @@ struct Index {
|
||||
|
||||
Row() {
|
||||
Flex({ direction: FlexDirection.Column }) {
|
||||
|
||||
if (this.kfArr.length) {
|
||||
List({}) {
|
||||
ForEach(this.kfArr, (item) => {
|
||||
@ -858,7 +905,6 @@ struct Index {
|
||||
if (this.isDeductedPopShow) {
|
||||
DeductedPopup({
|
||||
currentItems: Reflect.ownKeys(this.projectsObj).map(projectKey => {
|
||||
//@ts-ignore
|
||||
const project = this.projectsObj[projectKey]
|
||||
return project.type == '2' ? project.projectCode : ''
|
||||
}).filter(project => project !== ''),
|
||||
@ -915,13 +961,11 @@ struct Index {
|
||||
// 获取是否能人工进项目
|
||||
getIsExitManualProject = (index: number) => {
|
||||
const {judgeConfigObj,artSubject3ProjectsCodesArr,projectsObj} = this;
|
||||
//不允许人工触发的项目列表,以","分隔
|
||||
|
||||
const unExitManualProjects = judgeConfigObj['332'].split(',') || [];
|
||||
//直线行驶中不进其他考试项目(0-否 1-是)
|
||||
const param348 = judgeConfigObj['348'] || '0';
|
||||
//里程不够允许手工点靠边停车(0-否 1-是)
|
||||
const param387 = judgeConfigObj['387'] || '0';
|
||||
//车上是否能进行人工操作(0-能1-不能人工评判2-不能人工进项目3-都不能)
|
||||
|
||||
if (judgeConfigObj['342'] === '3' || judgeConfigObj['342'] === '2') {
|
||||
return false
|
||||
}
|
||||
@ -930,7 +974,6 @@ struct Index {
|
||||
return false
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
if (param348 == '0' && projectsObj['9']?.type == 2) {
|
||||
return index === 0 ? true : false
|
||||
}
|
||||
@ -942,76 +985,4 @@ struct Index {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
scroller: Scroller = new Scroller()
|
||||
//页面通用字体大小
|
||||
@State wayno:number = 0
|
||||
@State FONTSIZE: number = 28
|
||||
@State BIGFONTSIZE: number = 28
|
||||
//结束考试弹窗
|
||||
@State endPopupVisible: boolean = false
|
||||
//等待弹窗(考试及格,考试不及格使用)
|
||||
@State loadingPopupVisible: boolean = false
|
||||
//实时轨迹弹窗
|
||||
@State signDisplayComVisible: boolean = false
|
||||
@State isDdxk: boolean = false;
|
||||
@State time: string = ''
|
||||
//考试用时
|
||||
@State examTime: number = 0
|
||||
//开始时间
|
||||
@State startTime: string = '00:00:00'
|
||||
@State startFullTime: string = ''
|
||||
@State startHourTime: string = ''
|
||||
//科目类型
|
||||
@State examSubject: 2 | 3 = 3;
|
||||
@State ddxkTime: number = 0;
|
||||
@State ddxkKsxmArr: string[] = ['']
|
||||
@State ddxkKfArr: string[] = ['']
|
||||
@State xmmcStr: string = ''
|
||||
@State carztStr: string = ''
|
||||
@State kfArr: {
|
||||
xmmcStr?: string,
|
||||
score: string,
|
||||
desc: string
|
||||
}[] = []
|
||||
@State name: string = ''
|
||||
@State idCard: string = ''
|
||||
@State totalScore: number = 100
|
||||
//模拟考试项目
|
||||
@State projects: Project[] = []
|
||||
@State projectsObj: ProjectObj = {}
|
||||
@State projectsCenterObj: ProjectObj = {}
|
||||
@State markRuleListObj: MarkRule = {}
|
||||
@State cdsbInfoObj: CDSBInfo = {}
|
||||
@State timer: number = 0
|
||||
@State judgeConfig: { [k: string]: string }[] = []
|
||||
@State judgeConfigObj: { [k: string]: any } = defaultJudgeConfigObj
|
||||
//流水号
|
||||
@State lsh: string = ''
|
||||
@State kszp: string = ''
|
||||
@State ksdd: string = ''
|
||||
@State kssycs: string = ''
|
||||
@State kslx: string = ''
|
||||
//监管接口序列号
|
||||
@State serialNumber: number = 0
|
||||
@State carType: string = ''
|
||||
@State carName: string = ''
|
||||
@State isDeductedPopShow: boolean = false
|
||||
@State isAmplifyPopShow: boolean = false
|
||||
@State amplifiedImgIndex: number = 0
|
||||
@State judge: any = {}
|
||||
//行驶距离
|
||||
@State jl: number = 0
|
||||
//应考里程
|
||||
@State examMileage: string = '0'
|
||||
@State artSubject3Projects: string[] = ['直线', '会车', '变道', '超车', '掉头', '停车']
|
||||
@State artSubject3ProjectsCodesArr: string[] = ['3', '9', '4', '10', '12', '11']
|
||||
@State manualMarkRules: MarkRule[] = []
|
||||
//科目三评判初始化数据
|
||||
@State systemparmArr: SYSTEMPARMARR[] = []
|
||||
@State mapPointItemArr: MAPITEMPOINTITEM[] = []
|
||||
@State carinfoArrr: CARINFO[] = []
|
||||
@State mapPointArr: MAPPOINT[] = []
|
||||
private context = getContext(this) as common.UIAbilityContext;
|
||||
//已考的考试项目
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ export default struct Index {
|
||||
const {no1,no2,no3,txt1,txt2} = systemParm;
|
||||
if (no1 == 4) {
|
||||
const temp = { no2, no3, txt1: decodeURI(txt1), txt2 }
|
||||
console.info('surenjun', JSON.stringify(temp))
|
||||
this.roadObj[no2] = no2
|
||||
}
|
||||
})
|
||||
@ -56,8 +57,10 @@ export default struct Index {
|
||||
const roadArr = Reflect.ownKeys(this.roadObj).map((roadKey) => {
|
||||
return this.roadObj[roadKey]
|
||||
});
|
||||
const wayno = roadArr[Math.floor(Math.random()*roadArr.length)];
|
||||
this.goJudge(wayno)
|
||||
globalThis.carInfo.wayno = roadArr[Math.floor(Math.random()*roadArr.length)];
|
||||
router.pushUrl({
|
||||
url: 'pages/Judge',
|
||||
}, router.RouterMode.Single);
|
||||
})
|
||||
ForEach(Reflect.ownKeys(this.roadObj), (roadIndex) => {
|
||||
ListItem() {
|
||||
@ -78,7 +81,10 @@ export default struct Index {
|
||||
.height(220)
|
||||
.margin({ left: 5, bottom: 10 })
|
||||
.onClick(async () => {
|
||||
this.goJudge(this.roadObj[roadIndex])
|
||||
globalThis.carInfo.wayno = this.roadObj[roadIndex];
|
||||
router.pushUrl({
|
||||
url: 'pages/Judge',
|
||||
}, router.RouterMode.Single);
|
||||
})
|
||||
})
|
||||
}.lanes(8).margin({ top: 50, left: 15 })
|
||||
@ -89,18 +95,6 @@ export default struct Index {
|
||||
|
||||
}
|
||||
|
||||
goJudge(wayno) {
|
||||
let currentParams: any = router.getParams() || {};
|
||||
const {sczb,kfdm} = currentParams;
|
||||
router.replaceUrl({
|
||||
url: 'pages/Judge',
|
||||
params:{
|
||||
sczb,
|
||||
kfdm,
|
||||
wayno
|
||||
outClick() {
|
||||
}
|
||||
}, router.RouterMode.Single);
|
||||
|
||||
}
|
||||
outClick(){}
|
||||
}
|
||||
@ -4,8 +4,8 @@ import ethernet from '@ohos.net.ethernet';
|
||||
import prompt from '@ohos.prompt'
|
||||
import { upDateTableByArray} from '../common/service/initable'
|
||||
import { getSyncData} from '../common/service/initable'
|
||||
// import { getUDP, getUDP2 } from '../common/utils/GlobleUdp';
|
||||
// import { getTCP } from '../common/utils/GlobleTcp';
|
||||
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
|
||||
@ -14,9 +14,8 @@ import common from '@ohos.app.ability.common';
|
||||
import { User } from './interfaces';
|
||||
import WebRTCVoice from './webRTC/';
|
||||
import promptAction from '@ohos.promptAction';
|
||||
import { getSyncData } from '../common/service/initable';
|
||||
import { CandidateData, EmptyCandidateObject } from '../mock/CandidateData';
|
||||
import BoardPrePareSetPopup from './compontents/judge/BoardPrePareSetPopup'
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct UserInfo {
|
||||
@ -35,10 +34,6 @@ struct UserInfo {
|
||||
@State url: string = ''
|
||||
@State lsh: string = ''
|
||||
@State qkFlag: boolean = false
|
||||
@State isBoardPrePareSetPopupOpen: boolean = false
|
||||
@State isFirstBoardPrePareSetPopupBtnShow: boolean = false
|
||||
@State isBoardPrePareSetPopupShow: boolean = false
|
||||
@State sczbkf:{xmdm:number,kfdm:string}[] = []
|
||||
@State currentUser: User = EmptyCandidateObject
|
||||
@State dataList: Array<User> = []
|
||||
@State list: Array<User> = []
|
||||
@ -199,9 +194,7 @@ struct UserInfo {
|
||||
this.qkFn()
|
||||
}
|
||||
|
||||
async initData() {
|
||||
this.sczbkf = []
|
||||
this.isFirstBoardPrePareSetPopupBtnShow = false;
|
||||
initData() {
|
||||
this.stepFlag = false
|
||||
this.faceCompareSucess = 0
|
||||
this.showFaceCompare = false
|
||||
@ -223,15 +216,6 @@ struct UserInfo {
|
||||
} else {
|
||||
// this.getExaminationStudentInfoFn()
|
||||
}
|
||||
const syssetParams = await getSyncData('MA_SYSSET');
|
||||
//@ts-ignore
|
||||
syssetParams.forEach(sys => {
|
||||
//364 绕车一周评判时机(1-开始考试后判 2-开始考试前判)
|
||||
if(sys.v_no === '364'){
|
||||
this.isBoardPrePareSetPopupOpen = true;
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async heartMsg() {
|
||||
@ -262,7 +246,7 @@ struct UserInfo {
|
||||
placeId: globalThis.carInfo.examinationRoomId
|
||||
}
|
||||
|
||||
globalThis.udpClient2.sendMsg(param, this.context)
|
||||
globalThis.udpClient2.sendMsgExt(param, this.context)
|
||||
}
|
||||
|
||||
async initSysset() {
|
||||
@ -413,7 +397,7 @@ struct UserInfo {
|
||||
placeId: globalThis.carInfo.examinationRoomId
|
||||
}
|
||||
|
||||
globalThis.udpClient2.sendMsg(param, this.context)
|
||||
globalThis.udpClient2.sendMsgExt(param, this.context)
|
||||
if (res.examinationStuAbsentRsp.head.resultCode == '0') {
|
||||
this.pageIndex = 0
|
||||
this.qkFlag = false
|
||||
@ -547,7 +531,6 @@ struct UserInfo {
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
|
||||
TopLogo({ outFlag: $outFlag }).margin({ bottom: 10 })
|
||||
Row() {
|
||||
Row() {
|
||||
@ -644,14 +627,6 @@ struct UserInfo {
|
||||
.onClick(() => {
|
||||
this.qkFlag = true
|
||||
})
|
||||
|
||||
if( this.isBoardPrePareSetPopupOpen && !this.isFirstBoardPrePareSetPopupBtnShow){
|
||||
//上车准备
|
||||
Image($r('app.media.sczb_btn')).commStyle().onClick(()=>{
|
||||
this.isBoardPrePareSetPopupShow = true;
|
||||
this.isFirstBoardPrePareSetPopupBtnShow = true;
|
||||
})
|
||||
}else{
|
||||
Image($r('app.media.ksks_btn'))
|
||||
.commStyle()
|
||||
.onClick(() => {
|
||||
@ -677,10 +652,6 @@ struct UserInfo {
|
||||
this.AccountTable.query('0', (result) => {
|
||||
router.pushUrl({
|
||||
url: examSubject == 3 ? 'pages/Roads':'pages/Judge',
|
||||
params:{
|
||||
sczb:Number(this.isBoardPrePareSetPopupOpen),
|
||||
kfdm:this.sczbkf
|
||||
}
|
||||
}, router.RouterMode.Single);
|
||||
this.stopDeviceById()
|
||||
})
|
||||
@ -690,10 +661,6 @@ struct UserInfo {
|
||||
this.AccountTable.query('0', (result) => {
|
||||
router.pushUrl({
|
||||
url: examSubject == 3?'pages/Roads':'pages/Judge',
|
||||
params:{
|
||||
sczb:Number(this.isBoardPrePareSetPopupOpen),
|
||||
kfdm:this.sczbkf
|
||||
}
|
||||
}, router.RouterMode.Single);
|
||||
this.stopDeviceById()
|
||||
})
|
||||
@ -709,8 +676,6 @@ struct UserInfo {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (this.showFaceCompare) {
|
||||
@ -754,19 +719,6 @@ struct UserInfo {
|
||||
.backgroundColor('#E6E3DF')
|
||||
.borderRadius(19 * this.ratio)
|
||||
}
|
||||
|
||||
// 上车准备
|
||||
if(this.isBoardPrePareSetPopupShow){
|
||||
BoardPrePareSetPopup({
|
||||
closePopup:()=>{
|
||||
this.isBoardPrePareSetPopupShow = false
|
||||
},
|
||||
confirmMark:(kfdm)=>{
|
||||
this.sczbkf= kfdm
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
.height('100%')
|
||||
.width('100%')
|
||||
|
||||
@ -172,7 +172,7 @@ export default struct FaceCompare {
|
||||
carNo: globalThis.carInfo.carNo,
|
||||
placeId: globalThis.carInfo.examinationRoomId
|
||||
}
|
||||
globalThis.udpClient2.sendMsg(param, this.context)
|
||||
globalThis.udpClient2.sendMsgExt(param, this.context)
|
||||
}
|
||||
|
||||
async faceComparFn() {
|
||||
@ -229,7 +229,7 @@ export default struct FaceCompare {
|
||||
this.callBackFlag = true
|
||||
}
|
||||
}
|
||||
globalThis.udpClient2 && globalThis.udpClient2.sendMsg(param, this.context)
|
||||
globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param, this.context)
|
||||
clearInterval(this.interval)
|
||||
this.interval = setInterval(() => {
|
||||
if (this.callBackFlag) {
|
||||
@ -239,7 +239,7 @@ export default struct FaceCompare {
|
||||
carNo: globalThis.carInfo.carNo,
|
||||
placeId: globalThis.carInfo.examinationRoomId,
|
||||
}
|
||||
globalThis.udpClient2 && globalThis.udpClient2.sendMsg(param2, this.context)
|
||||
globalThis.udpClient2 && globalThis.udpClient2.sendMsgExt(param2, this.context)
|
||||
}
|
||||
}, 1000)
|
||||
globalThis.udpClient2.setMsgCallBack((val) => {
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import router from '@ohos.router';
|
||||
import UdpClient from '../../common/utils/UdpClient';
|
||||
import FileLog from '../judgeSDK/utils/fileLog';
|
||||
import FileLog from '../judgeSDK/utils/file-log';
|
||||
import RealTime from '../compontents/judge/RealTime';
|
||||
import { GPSData, SignalData } from '../../mock';
|
||||
import { SignalDataType } from '../../model';
|
||||
@ -21,7 +20,6 @@ export default struct SignDisplayCom {
|
||||
@State @Watch('outClick') outFlag: boolean = false;
|
||||
@State url: string = ''
|
||||
private timer = null
|
||||
private udpClient: UdpClient = null
|
||||
private FileLog: FileLog
|
||||
private vocObj = null;
|
||||
|
||||
@ -308,13 +306,15 @@ export default struct SignDisplayCom {
|
||||
|
||||
|
||||
if (showBack) {
|
||||
globalThis.udpClient.onMessage((msg) => {
|
||||
this.ratio=1.2
|
||||
globalThis.udpClient&&globalThis.udpClient.onMessage_1((msg) => {
|
||||
console.log('msgmsg', msg)
|
||||
if (msg) {
|
||||
getSignal(msg)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.ratio=1
|
||||
clearInterval(globalThis.signalTimer)
|
||||
globalThis.signalTimer = setInterval(() => {
|
||||
const msgStr = globalThis.msgStr
|
||||
@ -333,7 +333,7 @@ export default struct SignDisplayCom {
|
||||
const that = this
|
||||
const showBack = this.showBack;
|
||||
if (showBack) {
|
||||
globalThis.udpClient.onMessage((msg) => {
|
||||
globalThis.udpClient.onMessage_1((msg) => {
|
||||
getSignal(msg)
|
||||
})
|
||||
} else {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import apiJudgeSdk from 'libJudgeSdk.so';
|
||||
import Judge from '../../judgeSDK/utils/judgeReal';
|
||||
import Judge from '../../judgeSDK/utils/judge-real';
|
||||
import { MarkRule, Project, ProjectObj } from '../../judgeSDK/api/judgeSDK.d';
|
||||
import common from '@ohos.app.ability.common';
|
||||
|
||||
|
||||
@ -131,7 +131,6 @@ export function handleLog(level,infoStr, len){
|
||||
*
|
||||
*/
|
||||
export async function examJudgeEndExam(){
|
||||
console.info('surenjun','考试结束调用')
|
||||
const temp = libJudgeSdk.examJudgeEndExam();
|
||||
return await handle(temp,'examJudgeEndExam')
|
||||
}
|
||||
@ -171,26 +170,6 @@ export async function examJudgeSetPerformCallback(fn){
|
||||
const temp = libJudgeSdk.examJudgeSetPerformCallback(fn);
|
||||
return await handle(temp,'examJudgeSetPerformCallback')
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @desc 语音播报结束
|
||||
* /
|
||||
*/
|
||||
|
||||
export async function examJudgeSoundEnd(param:{
|
||||
//项目代码
|
||||
itemno:number,
|
||||
//语音码
|
||||
code:string,
|
||||
//语音类型
|
||||
type:number,
|
||||
}){
|
||||
const {itemno,code,type} = param;
|
||||
const temp = libJudgeSdk.examJudgeSoundEnd(itemno,code,type);
|
||||
return await handle(temp,'examJudgeSoundEnd')
|
||||
}
|
||||
|
||||
/*
|
||||
* @desc通用处理函数
|
||||
*
|
||||
|
||||
@ -16,8 +16,7 @@ export interface MarkRule{
|
||||
itemno?:number
|
||||
markcatalog?:string
|
||||
markshow?:string
|
||||
markserial?:string
|
||||
markstandard?:number,
|
||||
markserial?:number
|
||||
markreal?:number
|
||||
kfxh?:string
|
||||
onlyoneid?:number
|
||||
@ -119,8 +118,7 @@ export interface EXAMDATA{
|
||||
sound:{
|
||||
xmdm:number,
|
||||
//语音播放文件代码
|
||||
code:string,
|
||||
type:number
|
||||
code:string
|
||||
},
|
||||
//模拟灯光
|
||||
mndg:string
|
||||
@ -140,9 +138,7 @@ export interface SOUND {
|
||||
//项目代码
|
||||
xmdm:number
|
||||
//语音播放提示代码
|
||||
code:string,
|
||||
//0:普通,1:模拟灯光
|
||||
type:number
|
||||
code:string
|
||||
}
|
||||
export interface SYSSET {
|
||||
v_no:string,
|
||||
@ -151,7 +147,7 @@ export interface SYSSET {
|
||||
}
|
||||
|
||||
export interface ProjectObj {
|
||||
[k:string]:Project
|
||||
[k:any]:Project
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -2,16 +2,19 @@ import systemTime from '@ohos.systemDateTime';
|
||||
import router from '@ohos.router';
|
||||
import util from '@ohos.util';
|
||||
import buffer from '@ohos.buffer';
|
||||
|
||||
import { testKmItems, testMarkRules } from './dataTest/index';
|
||||
import { EXAMDATA, SOUND } from './api/judgeSDK';
|
||||
import VoiceAnnounce from './utils/voiceAnnouncements';
|
||||
import FileModel from './utils/fileModel';
|
||||
import FilePhoto from './utils/filePhoto';
|
||||
import FileUtil from '../../common/utils/File';
|
||||
import FileLog from './utils/fileLog';
|
||||
|
||||
import JudgeTask from './utils/judgeTask';
|
||||
import { judgeConfig } from './utils/judgeConfig';
|
||||
import VoiceAnnounce from './utils/voice-announcements';
|
||||
import FileModel from './utils/file-model';
|
||||
import FilePhoto from './utils/file-photo';
|
||||
import FileUtil from '../../common/utils/File';
|
||||
import FileLog from '../judgeSDK/utils/file-log';
|
||||
|
||||
import JudgeTask from './utils/judge-task';
|
||||
import SimulateLights from './utils/simulate-lights';
|
||||
import { judgeConfig } from './utils/judge-config';
|
||||
|
||||
import { uploadExamProgressData, writeObjectOut } from '../../api/judge';
|
||||
import {
|
||||
@ -33,33 +36,35 @@ import {
|
||||
plcStrToWXJson,
|
||||
promptWxCode,
|
||||
senorToWXDataStr
|
||||
} from './utils/judgeCommon';
|
||||
} from './utils/judge-common';
|
||||
import {
|
||||
examJudgeArtificialItem,
|
||||
examJudgeArtificialMark,
|
||||
examJudgeBeginExam,
|
||||
examJudgeEndExam,
|
||||
examJudgeInit,
|
||||
examJudgeSoundEnd,
|
||||
examJudgeMapSetParam,
|
||||
examJudgeMapSetScaling,
|
||||
examJudgeRealExam,
|
||||
examJudgeSetLogCallback,
|
||||
examJudgeSetPerformCallback,
|
||||
examJudgeSetRealExamCallback
|
||||
} from './api/index';
|
||||
import UsbService from '../../common/service/usbService';
|
||||
|
||||
import Prompt from '@system.prompt';
|
||||
|
||||
const judgeTag = 'SURENJUN_JUDGE'
|
||||
|
||||
export default class Judge {
|
||||
|
||||
|
||||
constructor(judgeUI) {
|
||||
this.serialIndex = 1;
|
||||
this.judgeUI = judgeUI
|
||||
|
||||
//语音播放工具
|
||||
this.avPlayer = new VoiceAnnounce();
|
||||
new SimulateLights(this.avPlayer)
|
||||
//模型工具
|
||||
this.fileModel = new FileModel(judgeUI.context);
|
||||
//文件工具
|
||||
@ -128,7 +133,7 @@ export default class Judge {
|
||||
console.info(judgeTag, '2.注册日志回调完成')
|
||||
|
||||
let initInfo = isTrajectoryOpen ? JSON.parse(strArr[0]) : await this.getJudgeInitData();
|
||||
|
||||
console.log('SURENJUN_JUDGE',isJudgeInitBool,isTrajectoryOpen,JSON.stringify(initInfo))
|
||||
//相关评判初始化只做一次
|
||||
if (!isJudgeInitBool) {
|
||||
await fileLog.setExamJudgeData(initInfo)
|
||||
@ -136,7 +141,6 @@ export default class Judge {
|
||||
globalThis.isJudgeInitBool = true
|
||||
console.info(judgeTag, '4.评判初始化完成')
|
||||
} else {
|
||||
await fileLog.setExamJudgeData(initInfo)
|
||||
}
|
||||
|
||||
globalThis.isJudge = true
|
||||
@ -153,19 +157,24 @@ export default class Judge {
|
||||
this.performInfo = performInfo
|
||||
this.judgeUI.jl = Math.ceil((performInfo.qjjl + performInfo.dcjl) / 100)
|
||||
})
|
||||
|
||||
// 3.开始考试
|
||||
let beginExamInfo = isTrajectoryOpen ? {
|
||||
...JSON.parse(strArr[1]),
|
||||
replay: 1
|
||||
} : await getJudgeBeginData()
|
||||
|
||||
console.log(judgeTag,'22222',JSON.stringify(beginExamInfo),strArr[1])
|
||||
await fileLog.setExamJudgeData(beginExamInfo)
|
||||
console.log(judgeTag,'333333')
|
||||
await examJudgeBeginExam(beginExamInfo);
|
||||
console.log(judgeTag,'4444444')
|
||||
|
||||
console.info(judgeTag, '6.开始考试注册完成')
|
||||
|
||||
avPlayer.playAudio(['voice/ksks.WAV'])
|
||||
|
||||
await examJudgeMapSetParam(640, 480); //设置参数宽、高
|
||||
await examJudgeMapSetScaling(120); //设置缩放比例,一般默认填100(就是100%的意思) ,数字越大视野越大,数字越小视野越小,不能为0
|
||||
|
||||
this.judgeUI.draw = true
|
||||
|
||||
// 处理轨迹plc信息
|
||||
@ -176,117 +185,13 @@ export default class Judge {
|
||||
|
||||
|
||||
// 处理实时udp里的plc信号
|
||||
globalThis.udpClient.onMessage(async (msg) => {
|
||||
globalThis.udpClient.onMessage_1(async (msg) => {
|
||||
handleUdp(msg)
|
||||
})
|
||||
|
||||
}
|
||||
// 获取评判初始化数据
|
||||
getJudgeInitData = async () => {
|
||||
const {getModelData,getKm3JudgeInitConfig} = this
|
||||
const carInfo = globalThis.carInfo;
|
||||
const { examSubject,plateNo,carId } = carInfo;
|
||||
const {fileLog} = this
|
||||
const judgeUI = this.judgeUI
|
||||
const {projectsObj,cdsbInfoObj,markRuleListObj,carType,carName} = judgeUI
|
||||
|
||||
const examType = examSubject == 2 ? 'km2' : 'km3'
|
||||
}
|
||||
|
||||
let allitems = [];
|
||||
|
||||
if (examSubject == 2) {
|
||||
allitems = Reflect.ownKeys(cdsbInfoObj).map(cdsbKey => {
|
||||
const cdsb = cdsbInfoObj[cdsbKey];
|
||||
const {xmdm,xmxh,modelKey} = cdsb
|
||||
return {
|
||||
xmdm, xmxh, model: getModelData(`${examType}/${modelKey}.txt`)
|
||||
}
|
||||
})
|
||||
}
|
||||
const initInfo = {
|
||||
kskm: examSubject * 1,
|
||||
kchp: plateNo,
|
||||
kchm: carId * 1,
|
||||
kscx: carType,
|
||||
cxcode: '1',
|
||||
name: carName,
|
||||
carmodel: getModelData(`${examType}/${carType}.txt`),
|
||||
allitems,
|
||||
mark: Reflect.ownKeys(markRuleListObj).map(ruleKey => (markRuleListObj[ruleKey])) || testMarkRules,
|
||||
sysset: judgeUI.judgeConfig,
|
||||
};
|
||||
|
||||
let km3Config = {}
|
||||
|
||||
if (examSubject) {
|
||||
km3Config = await getKm3JudgeInitConfig();
|
||||
}
|
||||
// 获取科目三的评判配置
|
||||
console.info(judgeTag, '3.获取评判初始化数据完成')
|
||||
return {
|
||||
...initInfo,
|
||||
...km3Config,
|
||||
}
|
||||
}
|
||||
// 获取开始考试数据
|
||||
getJudgeBeginData = async () => {
|
||||
const {code,name:examinerName} = globalThis.examinerInfo;
|
||||
let currentParams: any = router.getParams();
|
||||
const {sczb,kfdm} = currentParams;
|
||||
const {isExam} = this;
|
||||
const judgeUI = this.judgeUI
|
||||
const {projects,carType,isDdxk,ddxkTime,projectsCenterObj,ddxkKsxmArr,ddxkKfArr} = judgeUI;
|
||||
const beginInfo = {
|
||||
kgid: '012',
|
||||
kgxm: decodeURI(examinerName || ''),
|
||||
exam: isExam ? 1 : 0,
|
||||
//是否回放
|
||||
replay: 0,
|
||||
//生成的轨迹文件
|
||||
track: '',
|
||||
xm: judgeUI.name,
|
||||
sex: 0,
|
||||
kslsh: judgeUI.lsh,
|
||||
sfzmhm: judgeUI.idCard,
|
||||
ksyy: '',
|
||||
kscx: carType,
|
||||
kkcs: 1,
|
||||
sfyk: 0,
|
||||
ykkkcs: 1,
|
||||
wayno: judgeUI.wayno * 1,
|
||||
czlx: 0,
|
||||
kskssj: await systemTime.getCurrentTime(),
|
||||
ksxm: projects.map(project => {
|
||||
return {
|
||||
xmdm: project.projectCode * 1,
|
||||
xmxh: '',
|
||||
}
|
||||
}),
|
||||
//断点续考
|
||||
ddxk: isDdxk ? 1 : 0,
|
||||
ddkssj: ddxkTime,
|
||||
ykxm: isDdxk ? (ddxkKsxmArr?.map(projectCenterCode => (projectsCenterObj[projectCenterCode]?.projectCode) * 1)) : [],
|
||||
kfxm: isDdxk ? (ddxkKfArr?.map(kf => {
|
||||
const [xmdm, kfdm] = kf.split(',')
|
||||
return {
|
||||
xmdm: xmdm * 1,
|
||||
kfdm
|
||||
}
|
||||
})) : [],
|
||||
yklc: 0,
|
||||
special: [],
|
||||
//TODO 科目三参数临时写死
|
||||
sczb: (sczb === undefined || sczb == 0)?0:1,
|
||||
sczbkf:kfdm,
|
||||
dmndg: false,
|
||||
nitem1: false,
|
||||
nitem41: false,
|
||||
mfxx: false,
|
||||
mfxxn: false
|
||||
}
|
||||
console.info(judgeTag, '5.获取开始考试数据完成')
|
||||
return beginInfo
|
||||
}
|
||||
// 项目开始接口同步
|
||||
beginProject = async (ksxm) => {
|
||||
const carInfo = globalThis.carInfo;
|
||||
@ -427,28 +332,28 @@ export default class Judge {
|
||||
fileLog.setExamJudgeWuxiData(data)
|
||||
console.info(judgeTag, '上传照片 end')
|
||||
}
|
||||
|
||||
// 评判语音提示
|
||||
goJudgeVoice = async (sound: SOUND) => {
|
||||
const {avPlayer,fileLog} = this;
|
||||
const {xmdm,code,type} = sound;
|
||||
const {avPlayer} = this;
|
||||
const {xmdm,code} = sound;
|
||||
//判断是不是模拟灯光语音
|
||||
console.info(judgeTag,JSON.stringify(sound))
|
||||
if(type == 1){
|
||||
const isLight = code.slice(0, 3) === '417';
|
||||
if (isLight) {
|
||||
console.info(judgeTag, '模拟灯光开始播放:' + code)
|
||||
}
|
||||
avPlayer.playAudio([`voice/${code}.mp3`], true, () => {
|
||||
if (type == 1) {
|
||||
if (isLight) {
|
||||
console.info(judgeTag, '播放结束:' + code)
|
||||
examJudgeSoundEnd({itemno:xmdm,code,type})
|
||||
fileLog.setExamJudgeData({
|
||||
method: 'examJudgeSoundEnd',
|
||||
itemno: xmdm,
|
||||
code,
|
||||
type,
|
||||
setTimeout(() => {
|
||||
this.wav = 1;
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 处理考试结束
|
||||
public handEndExam = async (isManual?: Boolean) => {
|
||||
const {isExam,judgeUI,endExam,handleSEP,avPlayer} = this;
|
||||
@ -481,6 +386,26 @@ export default class Judge {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 当前项目转换
|
||||
getDqxmStr = (type) => {
|
||||
const projectsObj = this.judgeUI.projectsObj
|
||||
return projectsObj[type]?.abbreviation || '通用评判'
|
||||
}
|
||||
|
||||
// 扣分项目转换
|
||||
getKfStr = (code) => {
|
||||
const markRuleListObj = this.judgeUI.markRuleListObj;
|
||||
const thisMark = markRuleListObj[code]
|
||||
return {
|
||||
desc: thisMark.markshow,
|
||||
score: thisMark.markreal,
|
||||
markcatalog: thisMark.markcatalog,
|
||||
markserial: thisMark.markserial,
|
||||
kfxh: thisMark.kfxh
|
||||
}
|
||||
}
|
||||
|
||||
// 考试结束
|
||||
public endExam = async (isManual?: Boolean) => {
|
||||
const carInfo = globalThis.carInfo;
|
||||
@ -530,23 +455,55 @@ export default class Judge {
|
||||
}, 3000)
|
||||
|
||||
}
|
||||
// 当前项目转换
|
||||
getDqxmStr = (type) => {
|
||||
const projectsObj = this.judgeUI.projectsObj
|
||||
return projectsObj[type]?.abbreviation || '通用评判'
|
||||
}
|
||||
// 扣分项目转换
|
||||
getKfStr = (code) => {
|
||||
const markRuleListObj = this.judgeUI.markRuleListObj;
|
||||
const thisMark = markRuleListObj[code]
|
||||
|
||||
// 获取评判初始化数据
|
||||
getJudgeInitData = async () => {
|
||||
const {getModelData,getKm3JudgeInitConfig} = this
|
||||
const carInfo = globalThis.carInfo;
|
||||
const { examSubject,plateNo,carId } = carInfo;
|
||||
const {fileLog} = this
|
||||
const judgeUI = this.judgeUI
|
||||
const {projectsObj,cdsbInfoObj,markRuleListObj,carType,carName} = judgeUI
|
||||
|
||||
const examType = examSubject == 2 ? 'km2' : 'km3'
|
||||
|
||||
let allitems = [];
|
||||
|
||||
if (examSubject == 2) {
|
||||
allitems = Reflect.ownKeys(cdsbInfoObj).map(cdsbKey => {
|
||||
const cdsb = cdsbInfoObj[cdsbKey];
|
||||
const {xmdm,xmxh,modelKey} = cdsb
|
||||
return {
|
||||
desc: thisMark.markshow,
|
||||
score: thisMark.markreal,
|
||||
markcatalog: thisMark.markcatalog,
|
||||
markserial: thisMark.markserial,
|
||||
kfxh: thisMark.kfxh
|
||||
xmdm, xmxh, model: getModelData(`${examType}/${modelKey}.txt`)
|
||||
}
|
||||
})
|
||||
}
|
||||
const initInfo = {
|
||||
kskm: examSubject * 1,
|
||||
kchp: plateNo,
|
||||
kchm: carId * 1,
|
||||
kscx: carType,
|
||||
cxcode: '1',
|
||||
name: carName,
|
||||
carmodel: getModelData(`${examType}/${carType}.txt`),
|
||||
allitems,
|
||||
mark: Reflect.ownKeys(markRuleListObj).map(ruleKey => (markRuleListObj[ruleKey])) || testMarkRules,
|
||||
sysset: judgeUI.judgeConfig,
|
||||
};
|
||||
|
||||
let km3Config = {}
|
||||
|
||||
if (examSubject) {
|
||||
km3Config = await getKm3JudgeInitConfig();
|
||||
}
|
||||
// 获取科目三的评判配置
|
||||
console.info(judgeTag, '3.获取评判初始化数据完成')
|
||||
return {
|
||||
...initInfo,
|
||||
...km3Config,
|
||||
}
|
||||
}
|
||||
|
||||
// 消息心跳发送
|
||||
getMessageHeartbeat = async (isEnd?: Boolean) => {
|
||||
const carInfo = globalThis.carInfo;
|
||||
@ -646,6 +603,66 @@ export default class Judge {
|
||||
this.serialIndex += 1;
|
||||
return Array2Byte(tempArr)
|
||||
}
|
||||
|
||||
// 获取开始考试数据
|
||||
getJudgeBeginData = async () => {
|
||||
console.log('globalThis.carInfo.wayno',globalThis.carInfo.wayno)
|
||||
const {code,name:examinerName} = globalThis.examinerInfo;
|
||||
const {isExam,isTrajectoryOpen} = this;
|
||||
const judgeUI = this.judgeUI
|
||||
const {projects,carType,isDdxk,ddxkTime,projectsCenterObj,ddxkKsxmArr,ddxkKfArr} = judgeUI;
|
||||
const beginInfo = {
|
||||
kgid: '012',
|
||||
kgxm: decodeURI(examinerName || ''),
|
||||
exam: isExam ? 1 : 0,
|
||||
//是否回放
|
||||
replay: 0,
|
||||
//生成的轨迹文件
|
||||
track: '',
|
||||
xm: judgeUI.name,
|
||||
sex: 0,
|
||||
kslsh: judgeUI.lsh,
|
||||
sfzmhm: judgeUI.idCard,
|
||||
ksyy: '',
|
||||
kscx: carType,
|
||||
kkcs: 1,
|
||||
sfyk: 0,
|
||||
ykkkcs: 1,
|
||||
wayno: Number(globalThis.carInfo.wayno)|| 0,
|
||||
czlx: 0,
|
||||
kskssj: await systemTime.getCurrentTime(),
|
||||
ksxm: projects.map(project => {
|
||||
return {
|
||||
xmdm: project.projectCode * 1,
|
||||
xmxh: '',
|
||||
}
|
||||
}),
|
||||
//断点续考
|
||||
ddxk: isDdxk ? 1 : 0,
|
||||
ddkssj: ddxkTime,
|
||||
ykxm: isDdxk ? (ddxkKsxmArr?.map(projectCenterCode => (projectsCenterObj[projectCenterCode]?.projectCode) * 1)) : [],
|
||||
kfxm: isDdxk ? (ddxkKfArr?.map(kf => {
|
||||
const [xmdm, kfdm] = kf.split(',')
|
||||
return {
|
||||
xmdm: xmdm * 1,
|
||||
kfdm
|
||||
}
|
||||
})) : [],
|
||||
yklc: 0,
|
||||
special: [],
|
||||
//TODO 科目三参数临时写死
|
||||
sczb: 0,
|
||||
sczbkf: [],
|
||||
dmndg: false,
|
||||
nitem1: false,
|
||||
nitem41: false,
|
||||
mfxx: false,
|
||||
mfxxn: false
|
||||
}
|
||||
console.info(judgeTag, '5.获取开始考试数据完成')
|
||||
return beginInfo
|
||||
}
|
||||
|
||||
//获取场地序号
|
||||
getSbxh = (ksxm, xmxh) => {
|
||||
const {judgeUI} = this;
|
||||
@ -660,6 +677,7 @@ export default class Judge {
|
||||
const sbxh = currentCdsb.sbbh || '00000000'
|
||||
return sbxh
|
||||
}
|
||||
|
||||
getSbbm = (ksxm, xmxh) => {
|
||||
const {judgeUI} = this;
|
||||
const {cdsbInfoObj,projectsObj} = judgeUI;
|
||||
@ -672,6 +690,7 @@ export default class Judge {
|
||||
const sbxh = currentCdsb.sbbm || '00000000'
|
||||
return sbxh
|
||||
}
|
||||
|
||||
// 中心所有项目转换
|
||||
getTranslateProject = () => {
|
||||
// const {testKmItems} = this;
|
||||
@ -694,11 +713,13 @@ export default class Judge {
|
||||
}
|
||||
return arr.map(numStr => parseInt(numStr, 2));
|
||||
}
|
||||
|
||||
// 获取考试项目详情
|
||||
getProjectInfo = (projectCode) => {
|
||||
const judgeUI = this.judgeUI;
|
||||
return judgeUI.projectsObj[projectCode]
|
||||
}
|
||||
|
||||
// 获取模型数据
|
||||
getModelData = (modelName) => {
|
||||
const modelPath = this.modelPath
|
||||
@ -729,6 +750,7 @@ export default class Judge {
|
||||
itemno: itemno * 1,
|
||||
type: 1
|
||||
})
|
||||
|
||||
console.info(judgeTag, `人工评判进入项目-${itemno}`)
|
||||
|
||||
}
|
||||
@ -848,6 +870,8 @@ export default class Judge {
|
||||
|
||||
}
|
||||
}
|
||||
public plcStr: string
|
||||
private judgeUI
|
||||
// 更改考试状态
|
||||
goVoiceAnnounce = async (event, xmdm, kf, xmjs) => {
|
||||
const {projectsObj,judgeConfigObj} = this.judgeUI;
|
||||
@ -913,14 +937,17 @@ export default class Judge {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// 获取plc数据
|
||||
getPlcData = async (plc: string) => {
|
||||
const {fileLog,mndgStr,rmndg} = this;
|
||||
const {fileLog,mndgStr,rmndg,wav} = this;
|
||||
await fileLog.setPlcProgressData(plc)
|
||||
//plc字符串转化成评判初始化数据
|
||||
const tempData = await plcStrToJson(plc);
|
||||
//模拟灯光回放时刻
|
||||
tempData.sensor.rmndg = rmndg;
|
||||
//模拟灯光单个灯光结束时刻
|
||||
tempData.sensor.wav = wav;
|
||||
//模拟灯灯光灯光项目
|
||||
tempData.sensor.mndg = mndgStr;
|
||||
//plc字符串转化成无锡所过程数据
|
||||
@ -931,6 +958,7 @@ export default class Judge {
|
||||
this.plcStr = plc;
|
||||
this.mndgStr = '';
|
||||
this.rmndg = 0;
|
||||
this.wav = 0;
|
||||
globalThis.msgStr = plc
|
||||
|
||||
return tempData
|
||||
@ -938,6 +966,7 @@ export default class Judge {
|
||||
// 处理轨迹plc信号
|
||||
handleTrajectoryUdp = async (strArr) => {
|
||||
const {fileLog} = this;
|
||||
console.log('kkkkk')
|
||||
let num = 2;
|
||||
const {usbService} = this;
|
||||
const judgeTimer = setInterval(async () => {
|
||||
@ -1065,8 +1094,7 @@ export default class Judge {
|
||||
judgeUI.projectsObj = deepClone(copyProjectsObj)
|
||||
}
|
||||
}
|
||||
public plcStr: string
|
||||
private judgeUI
|
||||
|
||||
private fileLog
|
||||
private totalScore: number
|
||||
private folderPath: string
|
||||
@ -1074,6 +1102,7 @@ export default class Judge {
|
||||
private avPlayer
|
||||
private carztStr: string
|
||||
private rmndg: 0 | 1
|
||||
private wav: 0 | 1
|
||||
private mndgStr: string | undefined
|
||||
// 模拟灯光
|
||||
setMndg = async (mndgStr: string) => {
|
||||
|
||||
@ -1,117 +0,0 @@
|
||||
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'
|
||||
import promptAction from '@ohos.promptAction'
|
||||
import fileAccess from '@ohos.file.fileAccess'
|
||||
import common from '@ohos.app.ability.common'
|
||||
import Want from '@ohos.app.ability.Want'
|
||||
import fs from '@ohos.file.fs'
|
||||
import FileUtil from '../../../common/utils/File'
|
||||
import {getCurrentTime} from '../../../common/utils/tools'
|
||||
|
||||
interface StuInfo{
|
||||
name:string
|
||||
lsh:string
|
||||
idCard:string
|
||||
}
|
||||
|
||||
const LOGTAG = 'LOGTAG'
|
||||
export default class FileLog {
|
||||
|
||||
//后续文件路径待替换
|
||||
private fileUtil: FileUtil
|
||||
private stuInfo: StuInfo
|
||||
public folderPath: string
|
||||
|
||||
constructor(context) {
|
||||
const fileUtil = new FileUtil(context)
|
||||
this.fileUtil = fileUtil
|
||||
}
|
||||
|
||||
// 设置文件夹
|
||||
public initFileLogo = async (stuInfo:StuInfo) => {
|
||||
const {fileUtil,setExamLineData} = this
|
||||
const {name,lsh,idCard} = stuInfo;
|
||||
this.stuInfo = stuInfo;
|
||||
const time = await getCurrentTime()
|
||||
const date = time.split(' ')[0].split('-').join('_')
|
||||
const hourTime = time.split(' ')[1].split(':').join('_')
|
||||
const folderPath = await fileUtil.initFolder(`/logs/${date}/${lsh}_${idCard}_${name}_${date}_${hourTime}`);
|
||||
this.folderPath = folderPath;
|
||||
}
|
||||
|
||||
// 过程文件数据
|
||||
public setExamProgressData = async (str:Object) => {
|
||||
const {fileUtil,folderPath} = this;
|
||||
await fileUtil.editFile(`${folderPath}/exam_progress_data.txt`,JSON.stringify(str));
|
||||
}
|
||||
|
||||
// 无锡所接口数据
|
||||
public setExamJudgeWuxiData = async (str) => {
|
||||
const {fileUtil,folderPath} = this;
|
||||
await fileUtil.editFile(`${folderPath}/wuxi_exam_data.txt`,str);
|
||||
}
|
||||
|
||||
// 无锡所过程数据
|
||||
public setExamJudgeWuxiProgressData = async (str)=>{
|
||||
const {fileUtil,folderPath} = this;
|
||||
await fileUtil.editFile(`${folderPath}/wuxi_progress_data.txt`,str);
|
||||
}
|
||||
|
||||
// plc文件数据
|
||||
public setPlcProgressData = async (str:Object) => {
|
||||
const {fileUtil,folderPath} = this;
|
||||
await fileUtil.editFile(`${folderPath}/plc_data.txt`,JSON.stringify(str));
|
||||
}
|
||||
|
||||
// 过程评判json数据
|
||||
public setExamJudgeData = async (str:Object) => {
|
||||
const {fileUtil,folderPath} = this;
|
||||
await fileUtil.editFile(`${folderPath}/judge_exam_data.txt`,JSON.stringify(str));
|
||||
}
|
||||
|
||||
// 过程评判回调数据
|
||||
public setExamJudgeCallbackData = async (str:string) => {
|
||||
const {fileUtil,folderPath} = this;
|
||||
await fileUtil.editFile(`${folderPath}/judge_progress_callback_data.txt`,str);
|
||||
}
|
||||
|
||||
// 过程评判日志调数据
|
||||
public setExamJudgeLogData = async (str:string) => {
|
||||
const {fileUtil,folderPath} = this;
|
||||
await fileUtil.editFile(`${folderPath}/judge_log_data.txt`,str);
|
||||
}
|
||||
|
||||
// 无锡所轨迹数据
|
||||
public setExamLineData = async (plcStr) => {
|
||||
const {fileUtil,folderPath} = this;
|
||||
const plcData = plcStr.split(',');
|
||||
const time = await getCurrentTime();
|
||||
|
||||
const lineData = [
|
||||
/*帧头*/ time,
|
||||
/*卫星时间*/time,
|
||||
/*经度*/ plcData[95],
|
||||
/*纬度*/ plcData[95],
|
||||
/*高度*/ plcData[86],
|
||||
/*方位角*/ 0,
|
||||
/*俯仰角*/ plcData[91],
|
||||
/*速度角*/'',
|
||||
/*速度*/ plcData[97],
|
||||
/*横滚*/'',
|
||||
/*卫星定位状态*/'',
|
||||
/*卫星定向状态*/'',
|
||||
/*前天线可用星数*/'',
|
||||
/*后天线可用星数*/'',
|
||||
/*东向位置坐标*/'',
|
||||
/*北向位置坐标*/'',
|
||||
/*天向位置坐标*/'',
|
||||
/*东向速度*/'',
|
||||
/*北向速度*/'',
|
||||
/*评判信号1*/[plcData[14],plcData[19],plcData[5],'',plcData[2],plcData[3],plcData[7],plcData[8],plcData[13],plcData[12],plcData[17],'',plcData[4],plcData[11],plcData[20],plcData[9],0].join(','),
|
||||
/*评判信号2*/['',plcData[28],'','',plcData[10],'','','','','','','','','','','','',''].join(','),
|
||||
/*发动机转速*/ plcData[25],
|
||||
/*结束符*/ time,
|
||||
];
|
||||
|
||||
await fileUtil.editFile(`${folderPath}/exam_wuxi_data.txt`,JSON.stringify(lineData));
|
||||
};
|
||||
}
|
||||
@ -1,54 +0,0 @@
|
||||
import FileUtil from '../../../common/utils/File'
|
||||
import zlib from '@ohos.zlib';
|
||||
export default class FileModel{
|
||||
|
||||
//后续文件路径待替换
|
||||
private fileUtil: FileUtil
|
||||
public folderPath: string
|
||||
|
||||
constructor(context){
|
||||
(async ()=>{
|
||||
const fileUtil = new FileUtil(context)
|
||||
this.fileUtil = fileUtil
|
||||
})()
|
||||
|
||||
}
|
||||
|
||||
// 设置文件夹
|
||||
public initFolder = async () => {
|
||||
const {fileUtil} = this
|
||||
await fileUtil.initFolder(`/models/model_enc`);
|
||||
const folderPath = await fileUtil.initFolder(`/models`);
|
||||
this.folderPath = folderPath;
|
||||
}
|
||||
|
||||
// 存储zip文件并解压
|
||||
public storingFiles = async (str) => {
|
||||
const {fileUtil,folderPath} = this;
|
||||
await fileUtil.editFile(`${folderPath}/model.zip`,str,'overWrite')
|
||||
|
||||
let options = {
|
||||
level: zlib.CompressLevel.COMPRESS_LEVEL_DEFAULT_COMPRESSION,
|
||||
memLevel: zlib.MemLevel.MEM_LEVEL_DEFAULT,
|
||||
strategy: zlib.CompressStrategy.COMPRESS_STRATEGY_DEFAULT_STRATEGY
|
||||
};
|
||||
|
||||
zlib.unzipFile(
|
||||
`${folderPath}/model.zip`,
|
||||
`${folderPath}`,
|
||||
options).then((data) => {
|
||||
console.log("unzipFile result:" + data);
|
||||
}).catch((err)=>{
|
||||
console.log("catch((err)=>" + err);
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
//获取文件内容
|
||||
public getModelContent = (folderPath,fileName) => {
|
||||
const {fileUtil} = this;
|
||||
const content = fileUtil.getFileContent(`${folderPath}/${fileName}`)
|
||||
return content;
|
||||
}
|
||||
|
||||
}
|
||||
@ -3,7 +3,6 @@ import onvifclient from '@ohos.onvifclient';
|
||||
import fs from '@ohos.file.fs'
|
||||
import util from '@ohos.util';
|
||||
import FileUtil from '../../../common/utils/File'
|
||||
import { takePhoto } from '../../../common/service/videoService';
|
||||
|
||||
interface Params{
|
||||
userName:string
|
||||
@ -33,10 +32,5 @@ export default class FilePhoto{
|
||||
}
|
||||
|
||||
public async getPhoto(){
|
||||
const {params,context,fileUtil} = this;
|
||||
return new Promise(async (reslove)=>{
|
||||
const data=await takePhoto(params,context,'jt/',1)
|
||||
reslove(data.base64)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1,397 +0,0 @@
|
||||
import {string2Bytes,Array2Byte,getCurrentTime} from '../../../common/utils/tools'
|
||||
import {testMarkRules,testRealExam,testKmItems} from '../dataTest/index'
|
||||
|
||||
import promptAction from '@ohos.promptAction'
|
||||
import systemTime from '@ohos.systemDateTime';
|
||||
|
||||
//获取本地扣分项
|
||||
export const getTestMarkRules = () =>{
|
||||
testMarkRules.map((mark:any) => {
|
||||
return {
|
||||
itemno:mark.itemno*1,
|
||||
markcatalog:mark.markcatalog,
|
||||
markshow:mark.markshow,
|
||||
markreal:mark.markreal*1,
|
||||
markserial:mark.markserial,
|
||||
kfxh:mark.kfxh
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 中心信号转换
|
||||
export const getTranslateSignals = (tempItems) => {
|
||||
const len = Math.floor(tempItems.length / 8);
|
||||
const arr = [];
|
||||
for(let i = 0;i < len;i++){
|
||||
const temp = tempItems.slice( i*8 , (i+1)*8 );
|
||||
arr.push(temp.join(''));
|
||||
}
|
||||
const temp = arr.map(numStr => parseInt(numStr,2))
|
||||
return temp.map(item => string2Bytes(item , 8)[0])
|
||||
}
|
||||
|
||||
// c++评判考车行驶状态转换
|
||||
export function getCarStatus(status: -1 | 0 | 1):string {
|
||||
switch (status){
|
||||
case -1:return '后退'
|
||||
case 0:return '停车'
|
||||
case 1:return '前进'
|
||||
default :return ''
|
||||
}
|
||||
}
|
||||
|
||||
// 当前考车中心状态转换
|
||||
export function getCarStatusType(carzt){
|
||||
switch (carzt){
|
||||
case -1:return [1,0]
|
||||
case 0: return [0,0]
|
||||
case 1: return [0,1]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 中心实时项目状态转换
|
||||
export function getCenterProjectStatus(status){
|
||||
switch (status){
|
||||
//不考
|
||||
case 0:return '00'
|
||||
//未考
|
||||
case 1:return '01'
|
||||
//已考
|
||||
case 2:return '10'
|
||||
}
|
||||
}
|
||||
|
||||
//获取科目三开始项目、结束项目语音
|
||||
|
||||
export function getKmProjectVoice(
|
||||
projectCode,
|
||||
// 1:项目开始 2:项目结束
|
||||
type: 1 | 2
|
||||
) {
|
||||
const carInfo = globalThis.carInfo;
|
||||
const { examSubject } = carInfo;
|
||||
|
||||
if(examSubject == 2){
|
||||
return projectCode
|
||||
}
|
||||
|
||||
switch (projectCode*1){
|
||||
//直线行驶
|
||||
case 40300: return type === 1 ? 403001 : 403002
|
||||
//变更车道
|
||||
case 40500: return type === 1 ? 405001 : 405002
|
||||
//超车
|
||||
case 41400 : return type === 1 ? 414001 : undefined
|
||||
//直线行驶
|
||||
case 40700 : return type === 1 ? 407001 : undefined
|
||||
//左转
|
||||
case 40800 : return type === 1 ? 408001 : undefined
|
||||
//右转
|
||||
case 40900 : return type === 1 ? 409001 : undefined
|
||||
//通过人行横道
|
||||
case 41000 : return type === 1? 410001:undefined
|
||||
//通过学校
|
||||
case 41100 : return type === 1 ? 411001:undefined
|
||||
//通过车站
|
||||
case 41200 : return type === 1 ? 412001 : undefined
|
||||
//会车
|
||||
case 41300 : return type === 1 ? 413001: 413002
|
||||
//靠边停车
|
||||
case 40600 : return type === 1 ? 406001 : undefined
|
||||
//掉头
|
||||
case 41500 : return type === 1 ? 415001:undefined
|
||||
//超车
|
||||
case 40400 : return type === 1 ? 404001:undefined
|
||||
|
||||
default :return undefined
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 上传监管数据code转换
|
||||
export function promptWxCode(
|
||||
jkid:'17C52' | '17C54' |'17C55' | '17C53' | '17C56',
|
||||
code:number
|
||||
){
|
||||
let toast = '';
|
||||
const singlePlay = globalThis.singlePlay
|
||||
if(singlePlay){
|
||||
return
|
||||
}
|
||||
switch (jkid){
|
||||
//项目开始
|
||||
case '17C52':
|
||||
switch (code){
|
||||
case 0:toast = '存在作弊嫌疑,已被取消或暂停考试';break;
|
||||
case -1:toast = '无考生身份比对信息';break;
|
||||
case -2:toast = '考试项目与考试安排信息不符';break;
|
||||
case -3:toast = '考试设备未备案';break;
|
||||
case -4:toast = '考试设备与考试项目不符';break;
|
||||
case -5:toast = '考试设备使用状态异常';break;
|
||||
case -6:toast = '考生考试车型与考试设备使用准驾车型范围不符';break;
|
||||
case -7:toast = '该考生存在作弊嫌疑,已被暂停/取消考试';break;
|
||||
case -8:toast = '项目开始时间不能小于科目开始时间';break;
|
||||
case -9:toast = '存在未结束的考试项目、不能开始新的项目考试!';break;
|
||||
case -10:toast = '科目三考车号牌不能为空';break;
|
||||
case -11:toast = '同一考车存在未结束考试,不能开始应用于新的考试';break;
|
||||
case -12:toast = '未找到考场记录';break;
|
||||
case -13:toast = '未找到考车信息';break;
|
||||
case -14:toast = '随机抽取考生的考车与当前考车不一致';break;
|
||||
default:toast = '';break;
|
||||
}
|
||||
break;
|
||||
//过程照片
|
||||
case '17C54':
|
||||
switch (code){
|
||||
case -1:toast = '无当前科目考试信息';break;
|
||||
case -2:toast = '考生身份证明号码与考生预约信息不符';break;
|
||||
case -3:toast = '考试项目不正确';break;
|
||||
case -4:toast = '考试过程中拍摄照片数量少于3张!';break;
|
||||
case -5:toast = '考试项目不符合要求';break;
|
||||
case -6:toast = '存在未结束的考试项目!';break;
|
||||
}
|
||||
break;
|
||||
//项目结束
|
||||
case '17C55':
|
||||
switch (code){
|
||||
case -1:toast = '无当前考试项目开始信息';break;
|
||||
case -2:toast = '考生身份证明号码与考生预约信息不符';break;
|
||||
case -3:toast = '考试项目不正确';break;
|
||||
case -4:toast = '考试设备序号不正确!';break;
|
||||
case -5:toast = '考试项目结束时间写入错误';break;
|
||||
case -6:toast = '考生未进行身份认证';break;
|
||||
case -7:toast = '项目考试过程信息记录被非法篡改';break;
|
||||
case -8:toast = '每个考试项目中必须至少抓拍一张照片';break;
|
||||
case -12:toast = '未找到考场记录';break;
|
||||
case -13:toast = '未找到考车信息';break;
|
||||
case -15:toast = '考试过程信息必须由考车上传';break;
|
||||
case -90:toast = '考试项目已经结束、无需重传';break;
|
||||
case -91:toast = '实际道路考试,在完成科目考试时统一结束';break;
|
||||
default:break;
|
||||
}
|
||||
break;
|
||||
//扣分
|
||||
case '17C53':
|
||||
switch (code){
|
||||
case 0:toast = '已存在同一时间的同一扣分记录';break
|
||||
case -1:toast = '无当前考试项目开始信息';break;
|
||||
case -2:toast = '扣分时间大于项目开始时间!';break;
|
||||
case -3:toast = '考试项目与扣分项不符';break;
|
||||
case -4:toast = '项目考试过程中,请传入当前考试项目代码';break;
|
||||
case -5:toast = '考生未进行身份认证';break;
|
||||
case -6:toast = '扣分时间写入错误';break;
|
||||
case -7:toast = '项目考试过程信息记录被非法篡改';break;
|
||||
case -12:toast = '未找到考场记录';break;
|
||||
case -13:toast = '未找到考车信息';break;
|
||||
case -15:toast = '考试过程信息必须由考车上传';break;
|
||||
default:toast = '';break
|
||||
}
|
||||
break;
|
||||
//考试结束
|
||||
case '17C56':
|
||||
switch (code){
|
||||
case -1:toast = '无当前科目考试信息';break;
|
||||
case -2:toast = '考生身份证明号码与考生预约信息不符';break;
|
||||
case -3:toast = '考试结束时间不正确';break;
|
||||
case -4:toast = '考试过程中拍摄照片数量少于3张!';break;
|
||||
case -5:toast = '考试项目不符合要求';break;
|
||||
case -6:toast = '存在未结束的考试项目!';break;
|
||||
case -7:toast = '传输的考试成绩非空';break;
|
||||
case -91:toast = '考试成绩计算不一致';break;
|
||||
case -91:toast = '日间考试已结束等待进行夜间考试';break;
|
||||
default: toast = '';break
|
||||
}
|
||||
break;
|
||||
default :break;
|
||||
}
|
||||
promptAction.showToast({
|
||||
message: decodeURIComponent(toast),
|
||||
duration: 4000
|
||||
});
|
||||
}
|
||||
|
||||
// 获取plc数据
|
||||
export const plcStrToJson = async (plc:string) =>{
|
||||
|
||||
const p = plc.split(',').map((val,key)=>{
|
||||
if(key !== 27 && key !== 92){
|
||||
//@ts-ignore
|
||||
return val*1
|
||||
}else{
|
||||
return val
|
||||
}
|
||||
});
|
||||
let data:any = testRealExam;
|
||||
const time = await systemTime.getCurrentTime()
|
||||
const tempData = {
|
||||
sensor:{
|
||||
//安全带 车门门开关 手刹 脚刹 副刹 离合器 喇叭 示宽灯 近光灯 远光灯
|
||||
aqd:p[19], mkg:p[14], ssc:p[13], jsc:p[12], fsc:p[18], lhq:p[17], lb:p[4], skd:p[9], jgd:p[7], ygd:p[8],
|
||||
//左方向灯 右方向灯 双跳灯 雾灯 雨刮器 点火1 点火2 发动机转速 档位 车速
|
||||
zfxd:p[2], yfxd:p[3], shtd:p[20],wd:p[10], ygq:p[11], dh1:p[5], dh2:p[6], fdjzs:p[25], dw:p[28], cs:p[23],
|
||||
//@ts-ignore 方向盘
|
||||
fxp:p[27].split('_')[0]*1,
|
||||
//累计脉冲 溜车脉冲 超声波左后 超声波右后 超声波右前 超声波左前 座椅 仪表盘 后视镜 倒车镜 光照 雨量
|
||||
ljmc:p[24], lcmc:0, csbzh:p[32], csbyh:p[30], csbyq:p[31], csbzq:p[29], zy:0, tbp:0, hsj:0, dcj:0, gx:0, yl:0,
|
||||
//TODO 数据待替换 油压 闪灯 信号灯
|
||||
yy:0, sde:0, xhd:'',rmndg:0, wav:0 , mndg:''
|
||||
},
|
||||
gps:{
|
||||
//办卡类型 定位差分状态
|
||||
bklx:p[56], dwzt:p[83],
|
||||
//@ts-ignore 角度差分状态
|
||||
jdzt:p[92].split('-')[0]*1,
|
||||
//gps数据
|
||||
//gps时间 经度 纬度 航向角 俯仰角 海拔高 高度差 速度
|
||||
sj:time, jd:p[96], wd:p[95], hxj:p[90], fyj:p[91], hbg:p[85], gdc:p[86], sd:p[97],
|
||||
//龄期 经度因子 纬度因子 定位搜星数
|
||||
age:p[87], jdyz:p[89], wdyz:p[88], dwsxs:p[84],
|
||||
//@ts-ignore 角度搜星数
|
||||
jdsxs:p[92].split('-')[1]*1
|
||||
},
|
||||
gps2:data.gps,
|
||||
vision:data.vision,
|
||||
radar:data.radar,
|
||||
extend:{}
|
||||
}
|
||||
return tempData
|
||||
}
|
||||
|
||||
export const plcStrToWXJson = async (plc:string) =>{
|
||||
const p = plc.split(',').map((val,key)=>{
|
||||
if(key !== 27 && key !== 92){
|
||||
//@ts-ignore
|
||||
return val*1
|
||||
}else{
|
||||
return val
|
||||
}
|
||||
});
|
||||
const timeStr = p[93] + '' + p[94];
|
||||
const gps = {
|
||||
//办卡类型 定位差分状态
|
||||
bklx:p[56], dwzt:p[83],
|
||||
// 经度 纬度 航向角 俯仰角 海拔高 高度差 速度
|
||||
jd:p[96], wd:p[95], hxj:p[90], fyj:p[91], hbg:p[85], gdc:p[86], sd:p[97],
|
||||
//龄期 经度因子 纬度因子 定位搜星数
|
||||
age:p[87], jdyz:p[89], wdyz:p[88], dwsxs:p[84],
|
||||
}
|
||||
const judgeSignal = [
|
||||
// 车门 安全带 熄火 发动机启动 左转向 右转向 前照灯近灯 前照灯远灯
|
||||
p[14], p[19], p[5], p[6], p[2], p[3], p[7], p[8],
|
||||
// 注车制动 行车制动 离合器 副制动 喇叭 雨刷 危险报警灯 示廓灯 系统未涉及的传感器信号
|
||||
p[13], p[12], p[17], p[18], p[4], p[11], p[20], p[9], 0
|
||||
]
|
||||
const judgeAnotherSignal = [
|
||||
// 低三挡位 左侧单边桥1 左侧单边桥2 右侧单边桥1 右侧单边桥2 雾灯
|
||||
'000', '0', '0', '0', '0', p[10],
|
||||
// 桩杆全无信号 左后绕车 右后绕车 右前绕车 左前绕车
|
||||
'000', '0', '0', '0', '0'
|
||||
]
|
||||
const wuXiData = [
|
||||
// 卫星时间 精度 纬度 高度 方位角 俯仰角 速度角 速度 横滚 卫星定位状态
|
||||
'$KSXT', timeStr, gps.jd, gps.wd, gps.hbg, gps.hxj, gps.fyj, '' , gps.sd, '', gps.dwzt, gps.dwzt,
|
||||
//前天线可用星数 后天线可用星数 东向坐标位置 北向位置坐标 天向位置坐标 东向速度 北向速度 天向速度
|
||||
'', '', '', '', '', '', '', '',
|
||||
//@ts-ignore 评判信号1 评判信号2 发动机转速
|
||||
(judgeSignal.join('')*1).toString(16), (judgeAnotherSignal.join('')*1).toString(16) , p[25],
|
||||
'0xFFFFFFF'
|
||||
]
|
||||
const wuXiDataStr = wuXiData.join(',')
|
||||
return wuXiDataStr
|
||||
}
|
||||
|
||||
export const senorToWXDataStr= async (tempData) => {
|
||||
const {sensor,gps} = tempData;
|
||||
const timeStr = await getTimeStr()
|
||||
|
||||
const {mkg,aqd,dh1,dh2, zfxd, yfxd, jgd, ygd,ssc , jsc, lhq, fsc, lb, ygq,wd} = sensor
|
||||
const judgeSignal = [
|
||||
//车门 安全带 熄火 发动机启动 左转向 右转向 前照灯近灯 前照灯远灯
|
||||
mkg, aqd, dh1, dh2, zfxd, yfxd, jgd, ygd,
|
||||
// 注车制动 行车制动 离合器 副制动 喇叭 雨刷 危险报警灯 示廓灯 系统未涉及的传感器信号
|
||||
ssc , jsc, lhq, fsc, lb, ygq, 0, 0, 0
|
||||
]
|
||||
|
||||
const judgeAnotherSignal = [
|
||||
// 低三挡位 左侧单边桥1 左侧单边桥2 右侧单边桥1 右侧单边桥2 雾灯
|
||||
'000', '0', '0', '0', '0', '0',,'0',
|
||||
// 桩杆全无信号 左后绕车 右后绕车 右前绕车 左前绕车
|
||||
'000', '0', '0', '0', '0', '0','0'
|
||||
]
|
||||
//@ts-ignore
|
||||
const str1 = (judgeSignal.join('')*1).toString(16);
|
||||
//@ts-ignore
|
||||
const str2 = (judgeAnotherSignal.join('')*1).toString(16);
|
||||
|
||||
const wuXiData = [
|
||||
// 卫星时间 精度 纬度 高度 方位角 俯仰角 速度角 速度 横滚 卫星定位状态
|
||||
'$KSXT', timeStr, gps.jd, gps.wd, gps.hbg, gps.hxj, gps.fyj, '0' , gps.sd, '0', gps.dwzt,
|
||||
//前天线可用星数 后天线可用星数 东向坐标位置 北向位置坐标 天向位置坐标 东向速度 北向速度 天向速度
|
||||
'0', '0', '0', '0', '0', '0', '0', '0','0',
|
||||
//@ts-ignore 评判信号1 评判信号2 发动机转速
|
||||
// (judgeSignal.join('')*1).toString(16), (judgeAnotherSignal.join('')*1).toString(16) , sensor.fdjzs,
|
||||
'0006', '0001' , sensor.fdjzs,
|
||||
'0xFFFFFFF'
|
||||
]
|
||||
return wuXiData.map(d => (d + '')).join(',');
|
||||
// console.log('wuXiData',wuXiData.join(','));
|
||||
}
|
||||
|
||||
export const getTimeStr = async () =>{
|
||||
const date = await systemTime.getDate()
|
||||
const timeStr = '';
|
||||
const Y = date.getFullYear();
|
||||
const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) ;
|
||||
const D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
|
||||
const h = (date.getHours() < 10 ? '0' + (date.getHours()) : date.getHours());
|
||||
const m = (date.getMinutes() < 10 ? '0' + (date.getMinutes()) : date.getMinutes());
|
||||
const s = (date.getSeconds() < 10 ? '0' + (date.getSeconds()) : date.getSeconds());
|
||||
const ss = (date.getMilliseconds() +'').slice(0,2);
|
||||
return timeStr + Y + M +D +h +m +s +'.' + ss
|
||||
}
|
||||
|
||||
//蓝灯
|
||||
export function sendBlue(){
|
||||
const arrBlue = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00];
|
||||
const arrBlueBuffer= Array2Byte(arrBlue).buffer
|
||||
globalThis.lightLineUdp.send(arrBlueBuffer);
|
||||
}
|
||||
|
||||
//绿灯
|
||||
export function sendGreen(){
|
||||
const arrGreen = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x01];
|
||||
const arrGreenBuffer= Array2Byte(arrGreen).buffer
|
||||
globalThis.lightLineUdp.send(arrGreenBuffer);
|
||||
}
|
||||
|
||||
//红灯
|
||||
export function sendRed(){
|
||||
const arrRed= [0x55, 0xaa, 0x01, 0x01, 0x02, 0x00, 0x03, 0x00];
|
||||
const arrRedBuffer= Array2Byte(arrRed).buffer
|
||||
globalThis.lightLineUdp.send(arrRedBuffer);
|
||||
}
|
||||
|
||||
export const defaultJudgeConfigObj = {
|
||||
//结束考试方式 0-不合格继续 1-考试不合格报靠边停车 2-不合格不报靠边 3-训练不合格报靠边 4-自动退出 5-不合格自动退出
|
||||
302:'5',
|
||||
332:'',
|
||||
//是否能进行人工操作 0-不能人工评判 1-不能人工进项目 3-都不能
|
||||
342:'',
|
||||
//有项目未结束时可以靠边停车 0-否 1-是
|
||||
343:'1',
|
||||
//考试未结束且有扣分,是否可以退出
|
||||
344:'0',
|
||||
//直线行驶中是否可以进其它项目 0-否 1-是
|
||||
348:'0',
|
||||
//车上是否能点结束考试 0:否 1:是
|
||||
353:'0',
|
||||
//是否启动断电续考 0:否 1:是
|
||||
369:'1',
|
||||
//是否显示应考里程
|
||||
375:'0',
|
||||
//里程不够允许手工点靠边停车
|
||||
387:'0',
|
||||
//监管模式有扣分续考(0-否++1-是+把上次未考完的扣分带下来重新考试)
|
||||
432:'1'
|
||||
}
|
||||
@ -1,22 +0,0 @@
|
||||
|
||||
|
||||
//考试回放开关
|
||||
export const judgeConfig = {
|
||||
//本地目录开关
|
||||
isTrajectoryOpen: false,
|
||||
//是否开启Udp
|
||||
udpOpen:false,
|
||||
// 本地模型地址
|
||||
modelPath: 'models/model_enc',
|
||||
// 轨迹回放地址
|
||||
trajectoryPath: 'logs/2024_06_18/0000000000001_342323199501470011_测试学员1_2024_06_26_10_04_23/judge_exam_data.txt'
|
||||
}
|
||||
//0000000000001_342323199501470011_测试学员1_2024_04_28_10_59_44
|
||||
// 模拟灯光轨迹
|
||||
// test_sub3_car_test_jinan-32038219990808021X-20240417092356.txt
|
||||
|
||||
// 济南轨迹回放
|
||||
// test_sub3_car_test_jinan-32038219990808021X-20240322173643.txt
|
||||
// test_sub3_car_test_jinan-32038219990808021X-20240322173643.track
|
||||
// 2024_01_24_11_30_06_2210707689316_620502199005070478_马鸣五
|
||||
// 2024_01_24_10_25_41_2231212226990_330184200208281821_金晓婷
|
||||
@ -1,44 +0,0 @@
|
||||
import {
|
||||
examJudgeMapSetParam,
|
||||
examJudgeMapSetScaling
|
||||
} from '../api/index'
|
||||
import systemTime from '@ohos.systemDateTime';
|
||||
|
||||
import FileUtil from '../../../common/utils/File'
|
||||
import FileModel from './../utils/file-model'
|
||||
import {testRealExam} from '../dataTest/index'
|
||||
|
||||
const judgeTag = 'SURENJUN_JUDGE'
|
||||
|
||||
export default class JudgeImg {
|
||||
|
||||
private judgeUI
|
||||
private modelPath:string
|
||||
private fileModel:FileModel
|
||||
private fileUtil:FileUtil
|
||||
private plcData:any
|
||||
|
||||
constructor(judgeUI) {
|
||||
this.modelPath = 'models/model_enc'
|
||||
this.judgeUI = judgeUI
|
||||
this.fileUtil = new FileUtil(judgeUI.context)
|
||||
this.fileModel = new FileModel(judgeUI.context)
|
||||
this.init()
|
||||
}
|
||||
|
||||
async init(){
|
||||
const isJudgeInitBool = globalThis.isJudgeInitBool;
|
||||
const {judgeUI} = this;
|
||||
console.info(judgeTag,'1.进入评判入口')
|
||||
|
||||
await examJudgeMapSetParam(640, 480); //设置参数宽、高
|
||||
await examJudgeMapSetScaling(120); //设置缩放比例,一般默认填100(就是100%的意思) ,数字越大视野越大,数字越小视野越小,不能为0
|
||||
judgeUI.draw = true
|
||||
|
||||
}
|
||||
|
||||
//获取评判初始化数据
|
||||
getInitInfo = () =>{
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,42 +0,0 @@
|
||||
import Prompt from '@system.prompt'
|
||||
|
||||
const TAG = 'SURENJUN_JUDGE'
|
||||
|
||||
export default class JudgeTask{
|
||||
private queue = []
|
||||
private status:string
|
||||
constructor() {
|
||||
this.queue = []
|
||||
this.status = 'end'
|
||||
}
|
||||
|
||||
executeQueue = async ()=>{
|
||||
const {queue,executeQueue} = this
|
||||
if(queue.length){
|
||||
for (const currentTask of queue) {
|
||||
const {status} = this
|
||||
try {
|
||||
await currentTask();
|
||||
}catch (e){
|
||||
// console.info(TAG,'过程数据接口解析错误')
|
||||
Prompt.showToast({
|
||||
message: '过程数据接口解析错误',
|
||||
duration: 3000
|
||||
});
|
||||
}
|
||||
this.queue.shift()
|
||||
await executeQueue()
|
||||
}
|
||||
}else{
|
||||
this.status = 'end'
|
||||
}
|
||||
}
|
||||
|
||||
addTask = async (fn) =>{
|
||||
this.queue.push(fn);
|
||||
if(this.status == 'end' && this.queue.length === 1){
|
||||
await this.executeQueue();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,150 +0,0 @@
|
||||
import media from '@ohos.multimedia.media';
|
||||
import Prompt from '@system.prompt';
|
||||
|
||||
const TAG = 'VoiceAnnounce'
|
||||
|
||||
export default class VoiceAnnounce{
|
||||
|
||||
//队列时候立马终止
|
||||
private isStopped:Boolean
|
||||
private queue:String[]
|
||||
private newQueue:String[]
|
||||
private pendingQueue:String[]
|
||||
private callback:Function;
|
||||
constructor() {
|
||||
this.isStopped = false;
|
||||
this.queue = []
|
||||
}
|
||||
|
||||
async playAudio(urls:string[],shit,callback:Function){
|
||||
const {isStopped,queue} = this;
|
||||
this.callback = callback
|
||||
if(shit){
|
||||
//队列清空,重新初始化
|
||||
this.isStopped = true;
|
||||
this.newQueue = urls
|
||||
}
|
||||
if(queue.length){
|
||||
//队列续上
|
||||
this.queue = this.queue.concat(urls);
|
||||
|
||||
}else{
|
||||
this.queue = urls
|
||||
await this.executeQueue()
|
||||
}
|
||||
}
|
||||
|
||||
async executeQueue(){
|
||||
const avPlayer = new AVPlayer();
|
||||
const go = async () => {
|
||||
const {queue,callback,isStopped,newQueue} = this;
|
||||
if(isStopped){
|
||||
//清空原来队列
|
||||
this.queue = newQueue
|
||||
this.isStopped = false;
|
||||
await go()
|
||||
return
|
||||
}
|
||||
|
||||
await avPlayer.play(queue[0],callback);
|
||||
this.queue.shift();
|
||||
console.info(TAG,JSON.stringify(this.queue),'堆栈弹出');
|
||||
if(this.queue.length){
|
||||
await go()
|
||||
}
|
||||
}
|
||||
await go()
|
||||
avPlayer.avPlayerStop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class AVPlayer {
|
||||
|
||||
public avPlayer:any = null;
|
||||
|
||||
private voiceUrl: string[];
|
||||
private voiceStatus: 'completed' | 'playing'
|
||||
private endCallback:Function
|
||||
constructor() {}
|
||||
|
||||
// 以下为使用资源管理接口获取打包在HAP内的媒体资源文件并通过fdSrc属性进行播放示例
|
||||
async play(name,callback) {
|
||||
this.endCallback = callback
|
||||
const avPlayer = await media.createAVPlayer();
|
||||
this.avPlayer = avPlayer;
|
||||
return new Promise(async (resolve,reject) => {
|
||||
let url = ''
|
||||
await this.setAVPlayerCallback(()=>{
|
||||
//@ts-ignore
|
||||
resolve()
|
||||
});
|
||||
try {
|
||||
url = await globalThis.context.resourceManager.getRawFd(name);
|
||||
this.avPlayer.fdSrc = url;
|
||||
} catch (e) {
|
||||
Prompt.showToast({
|
||||
message: `${name}语音文件不存在`,
|
||||
duration: 4000
|
||||
});
|
||||
resolve(1)
|
||||
}
|
||||
})
|
||||
}
|
||||
//音频播放队列
|
||||
public releasePlayer() {
|
||||
this.avPlayer.release();
|
||||
}
|
||||
|
||||
avPlayerStop() {
|
||||
this.avPlayer && this.avPlayer.stop()
|
||||
this.avPlayer && this.avPlayer.reset()
|
||||
this.avPlayer && this.avPlayer.release()
|
||||
}
|
||||
// 注册avplayer回调函数
|
||||
setAVPlayerCallback(callBack) {
|
||||
|
||||
this.avPlayer.on('error', (err) => {
|
||||
this.avPlayer && this.avPlayer.stop()
|
||||
this.avPlayer && this.avPlayer.reset()
|
||||
this.avPlayer && this.avPlayer.release()
|
||||
})
|
||||
|
||||
let num = 0;
|
||||
// 状态机变化回调函数
|
||||
this.avPlayer.on('stateChange', async (state, reason) => {
|
||||
const {endCallback} = this;
|
||||
switch (state) {
|
||||
case 'idle': // 成功调用reset接口后触发该状态机上报
|
||||
break;
|
||||
case 'initialized': // avplayer 设置播放源后触发该状态上报
|
||||
this.avPlayer.prepare()
|
||||
break;
|
||||
case 'prepared': // prepare调用成功后上报该状态机
|
||||
this.avPlayer.play();
|
||||
this.voiceStatus = 'playing'
|
||||
break;
|
||||
case 'playing': // play成功调用后触发该状态机上报
|
||||
break;
|
||||
case 'paused': // pause成功调用后触发该状态机上报
|
||||
break;
|
||||
case 'completed': // 播放结束后触发该状态机上报
|
||||
this.voiceStatus = 'completed'
|
||||
this.avPlayer.stop(); //调用播放结束接口
|
||||
if(endCallback){
|
||||
endCallback()
|
||||
}
|
||||
break;
|
||||
case 'stopped': // stop接口成功调用后触发该状态机上报
|
||||
this.avPlayer.reset(); // 调用reset接口初始化avplayer状态
|
||||
callBack()
|
||||
break;
|
||||
case 'released':
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -35,6 +35,7 @@ workerPort.onmessage = (e: MessageEvents): void => {
|
||||
workerPort.postMessage({ isComplete: true });
|
||||
}else{
|
||||
workerPort.postMessage({ isComplete: false });
|
||||
|
||||
}
|
||||
})
|
||||
}else if(param.mode=='3'){
|
||||
@ -42,6 +43,10 @@ workerPort.onmessage = (e: MessageEvents): void => {
|
||||
getDoubleCeneterTable(param).then((ret)=>{
|
||||
if (ret) {
|
||||
workerPort.postMessage({ isComplete: true });
|
||||
|
||||
}else{
|
||||
workerPort.postMessage({ isComplete: false });
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user