Compare commits

..

No commits in common. "284de0a0e34ae183c14784ac0f29eff674dda65e" and "b1264c19e825c68f6793ad5f0aa681149c192fed" have entirely different histories.

11 changed files with 242 additions and 88 deletions

View File

@ -136,7 +136,7 @@ export async function uploadExamProgressData(params: UploadExamProgressDataParam
if (singlePlay) {
return
}
return request<object>({
return request({
url: '/der2/services/exam/uploadExamDataFile.ws',
data: `<?xml version="1.0" encoding="UTF-8"?>
<uploadExamDataFileReq>

View File

@ -108,7 +108,7 @@ interface GetPhotosForOtherParams {
//参数下发读表接口
export async function getPhotosForOther(params: GetPhotosForOtherParams) {
return request<object>({
return request({
url: '/der2/services/third/getPhotosForOther.ws',
data: `<?xml version="1.0" encoding="utf-8"?><getBmzpReq><head><time>${params.time}</time></head><body><sfzmhm>${params.sfzmhm}</sfzmhm><kskm>2</kskm><zptype>${params.zptype}</zptype><ksrq>${params.ksrq}</ksrq></body></getBmzpReq>`,
method: http.RequestMethod.POST,
@ -118,7 +118,7 @@ export async function getPhotosForOther(params: GetPhotosForOtherParams) {
}
export async function setVideoText() {
return request<object>({
return request({
url: 'http://admin:12345qwe@192.168.36.94/PSIA/Custom/SelfExt/OSD/channels/2/textOverlay',
data: `<?xml version="1.0" encoding="UTF-8" ?>
<TextOverlayList><TextOverlay><id>1</id><enabled>true</enabled><positionX>0</positionX><positionY>0</positionY><displayText>1222</displayText></TextOverlay><TextOverlay><id>2</id><enabled>true</enabled><positionX>0</positionX><positionY>0</positionY><displayText>2222</displayText></TextOverlay><TextOverlay><id>3</id><enabled>false</enabled><positionX>0</positionX><positionY>0</positionY><displayText></displayText></TextOverlay><TextOverlay><id>4</id><enabled>false</enabled><positionX>0</positionX><positionY>0</positionY><displayText></displayText></TextOverlay><TextOverlay><id>5</id><enabled>false</enabled><positionX>0</positionX><positionY>0</positionY><displayText></displayText></TextOverlay><TextOverlay><id>6</id><enabled>false</enabled><positionX>0</positionX><positionY>0</positionY><displayText></displayText></TextOverlay><TextOverlay><id>7</id><enabled>false</enabled><positionX>0</positionX><positionY>0</positionY><displayText></displayText></TextOverlay><TextOverlay><id>8</id><enabled>false</enabled><positionX>0</positionX><positionY>0</positionY><displayText></displayText></TextOverlay></TextOverlayList>`,

View File

@ -9,6 +9,7 @@ import DB from '../utils/DbSql';
import { DrivingDataStorage } from '../utils/business/DrivingDataStorage';
import { InitTable } from '../utils/table/Operation';
import FileUtils from '../utils/FileUtils';
import { lightUDPClient } from '../utils/UdpUtils';
export default class EntryAbility extends UIAbility {
async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) {
@ -32,7 +33,7 @@ export default class EntryAbility extends UIAbility {
onDestroy() {
const arrClose = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00]
// TODO UDP缺失
// lightUDPClient.sendMsg(new Uint8Array(arrClose).buffer)
lightUDPClient.sendMsg(new Uint8Array(arrClose).buffer)
DrivingDataStorage.close()
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
}

View File

@ -34,10 +34,10 @@ export interface AmplifyItem {
/** UDP 通信参数 */
export interface UDPParamType {
id: number;
list: number[];
carNo: string;
placeId: string;
id?: number;
list?: number[];
carNo?: string;
placeId?: string;
sendCallback?: () => void;
}

View File

@ -74,11 +74,11 @@ export function ArrayToByteArray(array: number[]): Uint8Array {
* @param len 字节数
* @returns 返回字节数组
*/
export function NumberToByteArray(number: number, len: number): number[] {
export function NumberToByteArray(number: number, len: number): number[] | undefined {
let str = Math.floor(number).toString(2);
if (str.length > len) {
console.log('数据长度不对~~');
return [];
return;
}
const byteString = FillZero(str, len);

View File

@ -35,10 +35,6 @@ function xmlToJSON(target: string): object {
return transfer(result['_elements'])
}
function setObj(target: Record<string, object>, key: string, value: object) {
target[key] = value
}
function transfer(target: Array<object>, name?: string): object {
const result: object = new Object()
@ -48,7 +44,7 @@ function transfer(target: Array<object>, name?: string): object {
if (_elements === undefined) {
return
}
const jsonObj: Record<string, object> = result[el['_name']] as Record<string, object>
const jsonObj: object = result[el['_name']]
const handleCommonArray = (obj: object) => {
if (Array.isArray(jsonObj)) {
result[el['_name']].push(obj)
@ -61,18 +57,16 @@ function transfer(target: Array<object>, name?: string): object {
if (jsonObj) {
handleCommonArray(_elements[0]['_text'])
} else {
setObj(jsonObj, el['_name'], _elements[0]["_text"])
// jsonObj[el['_name'] as string] = _elements[0]["_text"] as object
jsonObj[el['_name']] = _elements[0]["_text"]
}
} else {
if (jsonObj) {
handleCommonArray(transfer(el['_elements'], el['_name']))
} else {
setObj(jsonObj, el['_name'], transfer(el['_elements'], el['_name']))
// jsonObj[el['_name'] as string] = transfer(el['_elements'], el['_name'])
jsonObj[el['_name']] = transfer(el['_elements'], el['_name'])
}
}
} else if (el['_attributes'] && name) {
} else if (el['_attributes']) {
result[name] = {
value: el['_text'],
attributes: el['__attributes']
@ -88,7 +82,7 @@ interface CenterCodeResult {
keystr?: string
}
function dealCenterCode(message: string, isNewCenter: boolean = false): CenterCodeResult | undefined {
function dealCenterCode(message: string, isNewCenter: boolean): CenterCodeResult {
if (isNewCenter) {
const msg: object = JSON.parse(message);
const result: object = msg?.['data'][0]?.result;
@ -113,12 +107,9 @@ function dealCenterCode(message: string, isNewCenter: boolean = false): CenterCo
}
}
}
return undefined
}
type RequestResult = Object | object | string | CenterCodeResult
export default function Request<T extends RequestResult>(options: RequestOption): Promise<T> {
export default function Request<T = object>(options: RequestOption): Promise<T> {
return new Promise((resolve, reject) => {
const instance = http.createHttp()
const baseURL = options.host || base
@ -132,11 +123,11 @@ export default function Request<T extends RequestResult>(options: RequestOption)
readTimeout: options.timeout || 30 * 1000
}).then(async data => {
let result = options.xml ? xmlToJSON(data.result as string) : data.result
let resObj: object = new Object()
let resObj: object
if (typeof result === 'string') {
result = JSON.parse(result)
}
if (result['Envelope'] !== undefined) {
if (result['Envelope']) {
const msgXml: string = result['Envelope']['Body']['writeObjectOutResponse']['return'];
resolve(dealCenterCode(msgXml, options.isNewCenter) as T)
return

View File

@ -4,7 +4,6 @@ import { CarInfoType, EnvironmentConfigurationType } from '../model'
import { UDPTag } from '../config'
import { BusinessError } from '@ohos.base'
import { FillZero, StringToBytes, StringToASCII } from './Common'
import { CenterUDPClientInstance } from './business/CenterUdpBusiness'
interface MsgExt {
id: number,
@ -37,19 +36,19 @@ export default class UdpClient {
private localIpPort: string = ''
private oppositeIp: string = ''
private oppositeIpPort: string = ''
protected udp: socket.UDPSocket | null = null
protected udp: socket.UDPSocket = null
private messageEvents: Array<Function> = []
private errorEvents: Array<Function> = []
private dealMethod?: DealMethod<object>
private dealMethod: DealMethod<object>
private bindEvent() {
this.udp?.on("message", value => {
let result = this.dealMethod?.(value.message)
let result = this.dealMethod(value.message)
this.messageEvents.forEach(cb => {
cb(result)
})
})
this.udp?.on("error", (err) => {
this.udp.on("error", (err) => {
console.log(UDPTag, 'udp error', JSON.stringify(err))
this.errorEvents.forEach(cb => {
cb(err)
@ -58,8 +57,8 @@ export default class UdpClient {
}
bindUdp(): Promise<void> | undefined {
return this.udp?.bind({
bindUdp(): Promise<void> {
return this.udp.bind({
address: this.localIp, port: parseInt(this.localIpPort), family: 1
})
}
@ -71,10 +70,10 @@ export default class UdpClient {
await this.bindUdp()
}
close(): Promise<void> | undefined {
close(): Promise<void> {
this.messageEvents = []
this.errorEvents = []
this.dealMethod = undefined
this.dealMethod = null
this.udp?.off("message")
this.udp?.off("error")
return this.udp?.close()
@ -84,8 +83,8 @@ export default class UdpClient {
this.dealMethod = fun
}
sendMsg(data: ArrayBuffer | string): Promise<void> | undefined {
return this.udp?.send({
sendMsg(data: ArrayBuffer | string): Promise<void> {
return this.udp.send({
data,
address: {
address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1
@ -135,3 +134,179 @@ export default class UdpClient {
}
}
// 获取后置机信号
class ObjUdpClient extends UdpClient {
private static instance: ObjUdpClient
constructor() {
super()
if (!ObjUdpClient.instance) {
ObjUdpClient.instance = this
}
return ObjUdpClient.instance
}
async init(): Promise<void> {
return new Promise((resolve, reject) => {
try {
let result: EnvironmentConfigurationType =
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
if (result) {
this.create(result.udplocalIp, result.udplocalIpPort, result.udpOppositeIp, result.udpOppositeIpPort)
.then(resolve)
.catch(reject)
}
} catch (e) {
promptAction.showToast({
message: "初始化obj udp失败"
})
}
})
}
}
// 中心
class CenterUDPClient extends UdpClient {
private static instance: CenterUDPClient
constructor() {
super()
if (!CenterUDPClient.instance) {
CenterUDPClient.instance = this
}
return CenterUDPClient.instance
}
async init(): Promise<void> {
return new Promise((resolve, reject) => {
try {
let result: EnvironmentConfigurationType =
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
if (result) {
this.create(result.udplocalIp, '8800', carInfo?.udpAddress, carInfo?.messagePort).then(resolve).catch(reject)
}
} catch (e) {
reject(e)
promptAction.showToast({
message: "初始化中心 udp失败"
})
}
})
}
}
// 顶灯
class LightUDPClient extends UdpClient {
private static instance: LightUDPClient
constructor() {
super()
if (!LightUDPClient.instance) {
LightUDPClient.instance = this
}
return LightUDPClient.instance
}
async init(): Promise<void> {
return new Promise((resolve, reject) => {
try {
let result: EnvironmentConfigurationType =
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
if (result) {
this.create(result.udplocalIp, '55509', result.udpOppositeIp, result.udpOppositeIpPort)
.then(resolve)
.catch(reject)
}
} catch (e) {
reject(e)
promptAction.showToast({
message: "初始化灯光 udp失败"
})
}
})
}
}
// 评判udp
class JudgeUdpClient extends UdpClient {
private udpIndex = 0;
private currentUdpIndex = 0;
private static instance: JudgeUdpClient
constructor() {
super()
if (!JudgeUdpClient.instance) {
JudgeUdpClient.instance = this
}
return JudgeUdpClient.instance
}
async init(): Promise<void> {
return new Promise((resolve, reject) => {
try {
let result: EnvironmentConfigurationType =
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
if (result) {
this.create(result.udplocalIp, '8080', carInfo.udpAddress, carInfo.hintPort).then(resolve).catch(reject)
setInterval(() => {
this.udpIndex += 1
}, 1000)
}
} catch (e) {
reject(e)
}
})
}
send(bytes: number[]) {
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
if (this.udpIndex > this.currentUdpIndex) {
this.sendMsgExt({
id: 45,
list: bytes,
carNo: carInfo.carNo,
placeId: carInfo.examinationRoomId
})
this.currentUdpIndex = this.udpIndex
}
}
//申请远程扣分查询
askKf(directives: number) {
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
centerUDPClient.sendMsgExt({
id: 35,
list: [directives],
carNo: carInfo.carNo,
placeId: carInfo.examinationRoomId,
})
console.info('surenjun', `考车查询扣分项目内容,请求指令为:${directives}`)
}
//确定远程扣分
confirmKf(directives: number, code: number) {
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
centerUDPClient.sendMsgExt({
id: 37,
list: [directives, code],
carNo: carInfo.carNo,
placeId: carInfo.examinationRoomId
})
console.info('surenjun', `考车发送确定扣分指令,指令为:${directives}`)
}
}
// obj
export const objUDPClient = new ObjUdpClient()
// 中心
export const centerUDPClient = new CenterUDPClient()
// 灯光
export const lightUDPClient = new LightUDPClient()
// 评判
export const judgeUDPClient = new JudgeUdpClient()

View File

@ -8,13 +8,13 @@ import { UDPTag } from '../../config';
// 中心UDP业务逻辑
class CenterUDPBusiness {
private static instance: CenterUDPBusiness
private udp: UdpClient = new UdpClient()
private udp: UdpClient
private timer: number = -1
private headLength: number = 9
private sendId: number = 0
constructor() {
if (CenterUDPBusiness.instance) {
if (!CenterUDPBusiness.instance) {
CenterUDPBusiness.instance = this
}
return CenterUDPBusiness.instance
@ -45,19 +45,14 @@ class CenterUDPBusiness {
let headJudge = this.setMessageExclusive(head);
let bodyJudge = this.setMessageExclusive(params.list);
let end = [13, 10];
const arr: number[] = []
head.forEach(item => arr.push(item))
headJudge.forEach(item => arr.push(item))
params.list?.forEach(item => arr.push(item))
bodyJudge.forEach(item => arr.push(item))
end.forEach(item => arr.push(item))
const arr: Array<number> = [...head, ...headJudge, ...params.list, ...bodyJudge, ...end]
return this.array2Byte(arr).buffer
}
private array2Byte(array: Array<number>) {
const buf = new ArrayBuffer(array.length);
const view = new Uint8Array(buf);
for (let i = 0; i = array.length; ++i) {
for (let i = 0; i != array.length; ++i) {
view[i] = array[i] & 0xFF;
}
return view;
@ -67,11 +62,7 @@ class CenterUDPBusiness {
let a = string2Bytes(Number(`${params.id}${fillZero(params.placeId, 3)}`), 2 * 8);
let b = string2Bytes(Number(`${fillZero(params.carNo, 4)}${AppStorage.get('lshNo')}`), 4 * 8);
let c = string2Bytes(params.list.length, 2 * 8);
let result: number[] = []
a?.forEach(item => result.push(item))
b?.forEach(item => result.push(item))
c?.forEach(item => result.push(item))
return result;
return [...a, ...b, ...c];
}
private setMessageExclusive(tmpList: Array<number>) {
@ -102,12 +93,12 @@ class CenterUDPBusiness {
for (let i = 0; i < str.length; i++) {
tmpList.push(NumberToByteArray(str.charCodeAt(i), 1 * 8)[0])
}
const carInfo = AppStorage.get<CarInfoType>('carInfo')!
const carInfo = AppStorage.get<CarInfoType>('carInfo')
const data: UDPParamType = {
id: 31,
list: tmpList,
carNo: carInfo.carNo!,
placeId: carInfo.examinationRoomId!
carNo: carInfo.carNo,
placeId: carInfo.examinationRoomId
}
const param = this.setWholeMsg(data)
this.udp.sendMsg(param);
@ -126,9 +117,9 @@ class CenterUDPBusiness {
return new Promise((resolve, reject) => {
try {
let result: EnvironmentConfigurationType =
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")!
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
this.udp.create(result.udplocalIp!, '8800', carInfo.udpAddress!, carInfo.messagePort!)
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
this.udp.create(result.udplocalIp, '8800', carInfo?.udpAddress, carInfo?.messagePort)
.then(resolve)
.catch(reject)
this.udp.setDealMethod(this.dealMsg)

View File

@ -24,7 +24,7 @@ class drivingDataStorage {
this.totalTime = 0;
this.fd = await this.fileUtil!.editFile(
`${folderPath}/${this.date}.txt`,
`程序启动时间:${this.time} 累计行驶距离:${this.totalDistance}m 累计运行时常:${this.totalTime}min`)!
`程序启动时间:${this.time} 累计行驶距离:${this.totalDistance}m 累计运行时常:${this.totalTime}min`)
return folderPath
}

View File

@ -28,7 +28,7 @@ function string2Bytes(num: number | string, len: number) {
let str = (Math.floor(Number(num))).toString(2);
if (str.length > len) {
console.log('数据长度不对~~');
return []
return
}
let byteString = FillZero(str, len);
@ -48,7 +48,7 @@ function string2Bytes(num: number | string, len: number) {
class JudgeUdpBusiness {
private static instance: JudgeUdpBusiness
private udp: UdpClient = new UdpClient()
private udp: UdpClient
private currentUdpIndex = 0;
public udpIndex = 0;
@ -81,11 +81,7 @@ class JudgeUdpBusiness {
let a = string2Bytes(Number(`${params.id}${fillZero(params.placeId, 3)}`), 2 * 8);
let b = string2Bytes(Number(`${fillZero(params.carNo, 4)}${AppStorage.get('lshNo')}`), 4 * 8);
let c = string2Bytes(params.list.length, 2 * 8);
let result: number[] = []
a?.forEach(item => result.push(item))
b?.forEach(item => result.push(item))
c?.forEach(item => result.push(item))
return result;
return [...a, ...b, ...c];
}
private setMessageExclusive(tmpList: Array<number>) {
@ -235,7 +231,7 @@ class JudgeUdpBusiness {
}
async getMessageHeartbeat(msg: string): Promise<number[]> {
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
let gpsDigit = JudgeConfig.fourInOneScreen.gpsDigit
const asclshArr = StringToASCII(FillZero(
AppStorage.get<boolean>("singlePlay")
@ -244,7 +240,7 @@ class JudgeUdpBusiness {
13));
const ascksyhArr = StringToASCII(carInfo.examSubject === '2' ? '0000000000000' : '1111111111111')
const ascsbxhArr = StringToASCII('00000000')
const serialIndex = AppStorage.get<number>("serialIndex")!
const serialIndex = AppStorage.get<number>("serialIndex")
const plcData = await this.getPlcData(msg);
let param: number[] = Object.entries(plcData.sensor)
.filter((item: [string, number]) => {
@ -332,13 +328,13 @@ class JudgeUdpBusiness {
}
sendData(bytes: number[]) {
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
if (this.udpIndex > this.currentUdpIndex) {
this.udp.sendMsgExt({
id: 45,
list: bytes,
carNo: carInfo.carNo!,
placeId: carInfo.examinationRoomId!
carNo: carInfo.carNo,
placeId: carInfo.examinationRoomId
})
this.currentUdpIndex = this.udpIndex
}
@ -346,24 +342,24 @@ class JudgeUdpBusiness {
//申请远程扣分查询
askKf(directives: number) {
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
CenterUDPClientInstance.sendData({
id: 35,
list: [directives],
carNo: carInfo.carNo!,
placeId: carInfo.examinationRoomId!,
carNo: carInfo.carNo,
placeId: carInfo.examinationRoomId,
})
console.info('surenjun', `考车查询扣分项目内容,请求指令为:${directives}`)
}
//确定远程扣分
confirmKf(directives: number, code: number) {
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
CenterUDPClientInstance.sendData({
id: 37,
list: [directives, code],
carNo: carInfo.carNo!,
placeId: carInfo.examinationRoomId!
carNo: carInfo.carNo,
placeId: carInfo.examinationRoomId
})
console.info('surenjun', `考车发送确定扣分指令,指令为:${directives}`)
}
@ -372,9 +368,9 @@ class JudgeUdpBusiness {
return new Promise((resolve, reject) => {
try {
let result: EnvironmentConfigurationType =
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")!
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')!
this.udp.create(result.udplocalIp!, '8080', carInfo.udpAddress!, carInfo.hintPort!).then(resolve).catch(reject)
AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")
const carInfo: CarInfoType = AppStorage.get<CarInfoType>('carInfo')
this.udp.create(result.udplocalIp, '8080', carInfo.udpAddress, carInfo.hintPort).then(resolve).catch(reject)
ObtainUdpBusinessInstance.onMsg(async (msg: string) => {
let prevJd = 0, preWd = 0
@ -382,8 +378,8 @@ class JudgeUdpBusiness {
if (stashArr[0] != '#DN_GD') {
return
}
const udpIndex = AppStorage.get<number>("udpIndex")!;
const isJudge = AppStorage.get<boolean>("isJudge")!;
const udpIndex = AppStorage.get<number>("udpIndex");
const isJudge = AppStorage.get<boolean>("isJudge");
if (udpIndex % 5 === 0 && !isJudge) {
const bytes = await this.getMessageHeartbeat(msg);
const msgArr: string[] = msg.split(',');

View File

@ -1,5 +1,5 @@
import emitter from '@ohos.events.emitter';
import { JudgeUdpBusinessInstance } from './JudgeUdpBusiness';
import { judgeUDPClient } from '../UdpUtils';
enum EventId {
//远程扣分处理
@ -21,22 +21,22 @@ class JudgeEmitter {
}
private kfContent: Function = () => {
}
private directives: string = ''
private directives: string
//监听开始考试
public onBeginExam(callBack: Function) {
public onBeginExam(callBack?: Function) {
console.info('surenjun', '注册远程开始考试事件')
this.beginExamCallBack = callBack
}
//监听结束考试
public onEndExam(callBack: Function) {
public onEndExam(callBack?: Function) {
console.info('surenjun', '注册远程结束考试事件')
this.endExamCallBack = callBack
}
//监听扣分处理
public onKfExam(callBack: Function) {
public onKfExam(callBack?: Function) {
console.info('surenjun', '注册远程扣分考试事件')
this.kfContent = callBack
}
@ -80,7 +80,7 @@ class JudgeEmitter {
//监听扣分指令
public sendOnKf(directives: string) {
this.directives = directives
JudgeUdpBusinessInstance.askKf(Number(directives))
judgeUDPClient.askKf(Number(directives))
}
// 获取扣分项目编号