diff --git a/entry/src/main/ets/common/service/FileHelper.ts b/entry/src/main/ets/common/service/FileHelper.ts index a1b8e70e..3b4378d1 100644 --- a/entry/src/main/ets/common/service/FileHelper.ts +++ b/entry/src/main/ets/common/service/FileHelper.ts @@ -15,6 +15,7 @@ import photoAccessHelper from '@ohos.file.photoAccessHelper'; import dataSharePredicates from '@ohos.data.dataSharePredicates'; +import common from '@ohos.app.ability.common'; export class FileHelper { FILE_ASSET_FETCH_COLUMNS = [ @@ -38,7 +39,7 @@ export class FileHelper { private userFileMgr: photoAccessHelper.PhotoAccessHelper = undefined; constructor() { - const context=AppStorage.get('context') + const context: common.UIAbilityContext = AppStorage.get('context') this.userFileMgr = photoAccessHelper.getPhotoAccessHelper(context); } diff --git a/entry/src/main/ets/config/LogEnum.ets b/entry/src/main/ets/config/LogEnum.ets index 596fbb7b..679e1f61 100644 --- a/entry/src/main/ets/config/LogEnum.ets +++ b/entry/src/main/ets/config/LogEnum.ets @@ -1 +1,3 @@ -export const DbTag = '[DBTag]'; \ No newline at end of file +export const DbTag = '[DBTag]'; + +export const SerialPortTag = '[SerialPortTag]'; \ No newline at end of file diff --git a/entry/src/main/ets/entryability/EntryAbility.ets b/entry/src/main/ets/entryability/EntryAbility.ets index 98939574..632749c9 100644 --- a/entry/src/main/ets/entryability/EntryAbility.ets +++ b/entry/src/main/ets/entryability/EntryAbility.ets @@ -11,9 +11,12 @@ import { tcpUtil } from '../common/utils/TcpRequest'; import DB from '../common/database/DbSql'; import { initTable } from '../common/service/initable'; import { centerUDPClient, lightUDPClient, objUDPClient } from '../utils/UdpUtils'; +import Want from '@ohos.app.ability.Want'; +import AbilityConstant from '@ohos.app.ability.AbilityConstant'; +import { BaseInfoType, CarInfoType } from '../model'; export default class EntryAbility extends UIAbility { - async onCreate(want, launchParam) { + async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { try { console.log("sql first") await DB.init(this.context) @@ -30,7 +33,8 @@ export default class EntryAbility extends UIAbility { onDestroy() { const arrClose = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00] const arrCloseBuffer = Array2Byte(arrClose).buffer - globalThis?.lightLineUdp?.send(arrCloseBuffer); + // TODO UDP缺失 + // globalThis?.lightLineUdp?.send(arrCloseBuffer); hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy'); } @@ -44,13 +48,13 @@ export default class EntryAbility extends UIAbility { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); await tcpUtil.init() - AppStorage.SetOrCreate('carInfo', {}) - AppStorage.SetOrCreate('examinerInfo', {}) - AppStorage.SetOrCreate('lsh', '0000000000000') - AppStorage.SetOrCreate('statue', 1) //考试状态 - AppStorage.SetOrCreate('signNum', 0) //心跳指令编号 - AppStorage.SetOrCreate('deviceNo', 0) //设备号 - AppStorage.SetOrCreate('baseInfo', { + AppStorage.setOrCreate('carInfo', {}) + AppStorage.setOrCreate('examinerInfo', {}) + AppStorage.setOrCreate('lsh', '0000000000000') + AppStorage.setOrCreate('statue', 1) //考试状态 + AppStorage.setOrCreate('signNum', 0) //心跳指令编号 + AppStorage.setOrCreate('deviceNo', 0) //设备号 + AppStorage.setOrCreate('baseInfo', { hasAuth: false, version: GlobalConfig.version.jn.km3[0], judgeVersion: GlobalConfig.version.jn.km3[1], diff --git a/entry/src/main/ets/mock/CandidateData.ets b/entry/src/main/ets/mock/CandidateData.ets index fd2827e0..1329a316 100644 --- a/entry/src/main/ets/mock/CandidateData.ets +++ b/entry/src/main/ets/mock/CandidateData.ets @@ -268,27 +268,4 @@ export const EmptyCandidateObject: User = { yycs: '' } -export const VideoConfigData: VideoConfig = { - spls: '', - faceFlag: false, - pztd: '2', - ljlx: '', - ip: '192.168.7.112', - port: '554', - userName: 'admin', - pwd: '12345qwe', - td1: '1', - td2: '2', - td3: '3', - td4: '4', - videoRecord1: false, - videoRecord2: false, - videoRecord3: false, - videoRecord4: false, - rlls: '1', - spzd4: false, - spzd3: false, - spzd2: false, - spzd1: false, - zdyz: '500' -} + diff --git a/entry/src/main/ets/model/CarCheck.ets b/entry/src/main/ets/model/CarCheck.ets index b2aa23d2..4ae87b0c 100644 --- a/entry/src/main/ets/model/CarCheck.ets +++ b/entry/src/main/ets/model/CarCheck.ets @@ -18,15 +18,6 @@ export interface CarConfigurationParams { body: Record; } -// 车辆信息 -export interface CarInfoType { - carId?: string; - examinationRoomId?: string; - plateNo?: string; - carNo?: string; - examSubject?: string; - isNeedCheck?: string; -} diff --git a/entry/src/main/ets/model/Common.ets b/entry/src/main/ets/model/Common.ets index a999f3e7..13d47a20 100644 --- a/entry/src/main/ets/model/Common.ets +++ b/entry/src/main/ets/model/Common.ets @@ -76,6 +76,7 @@ export interface CommonType { key: string; } +// 基础信息 export interface BaseInfoType { hasAuth?: boolean, version?: string, @@ -94,4 +95,19 @@ export interface RouteParamsType { sczb?: string; kfdm?: string; type?: string; -} \ No newline at end of file +} + +// 车辆信息 +export interface CarInfoType { + carId?: string; + examinationRoomId?: string; + plateNo?: string; + carNo?: string; + examSubject?: string; + isNeedCheck?: string; + udpAddress?: string + messagePort?: string +} + +// TODO +export interface ExaminerInfoType {} \ No newline at end of file diff --git a/entry/src/main/ets/utils/SerialPort.ets b/entry/src/main/ets/utils/SerialPort.ets new file mode 100644 index 00000000..e3a2f7e5 --- /dev/null +++ b/entry/src/main/ets/utils/SerialPort.ets @@ -0,0 +1,95 @@ +import testNapi from '@ohos.hiserialsdk'; +import HiSerialSDK from '@ohos.hiserialsdk'; +import { SerialPortTag } from '../config'; + +// 打开串口工具 +export const OpenSerialPort = (serialPort: string) => { + return new Promise((resolve, reject) => { + testNapi.SerialOpenAsync(serialPort, (value: number) => { + if (value === -1) { + console.log(SerialPortTag, "打开串口失败!") + reject(-1) + } + console.log(SerialPortTag, "打开成功!!") + resolve(value) + }) + }) +} + +//初始化串口数据 +export const InitSerialPortData = + async (fd: number, speed: number) => { + return new Promise((resolve, reject) => { + testNapi.SerialSetAsync(fd, speed, 0, 8, 1, 0x4e, (value: number) => { + // 0 成功 -1失败 + if (value === 0) { + console.log(SerialPortTag, "初始化成功!") + resolve(true) + } + if (value === -1) { + console.log(SerialPortTag, "初始化失败!") + reject(false) + } + }) + }) + } + +//发送数据 +export const SendSerialPortData = (fd: number, data: number[]) => { + console.log(SerialPortTag, "wzj-----发送数据") + return new Promise((resolve, reject) => { + testNapi.SerialSendAsync(fd, data, (value: number) => { + if (value === -1) { + console.log(SerialPortTag, "发送失败!") + reject(-1) + } + resolve(value) + }) + }) +} + +// 接受数据 +export const ReceiveSerialPortData = (fd: number, timeout: number,) => { + console.log(SerialPortTag, "wzj-----接受数据") + return new Promise((resolve) => { + testNapi.SerialRecvAsync(fd, timeout, (value: HiSerialSDK.receiveInfo) => { + resolve(value) + }) + }) +} + +// 主动接受数据 +export const ReceiveSerialPortDataBySelf = (fd: number, callback: Function) => { + testNapi.SerialListenCallbackSet(fd, callback) +} + +// 取消主动接受 +export const CancelReceiveSerialPortData = async (fd: number) => { + return new Promise((resolve, reject) => { + let result: number = testNapi.SerialListenCallbackCancel(fd) + if (result === 0) { + resolve(true) + } else { + reject(false) + } + }) +} + +/** + * 将输入字符串转换为ASCII码数组 + * @param input 要转换的输入字符串 + * @returns 转换后的ASCII码数组 + */ +export const ConvertToASCII = (input: string): number[] => { + return input.split('').map(char => char.charCodeAt(0)); +} + +/** + * 将输入字符串转换为十六进制(hex)数组 + * @param input 要转换的输入字符串 + * @returns 转换后的十六进制数组 + */ +export const ConvertToHex = (input: string): number[] => { + return input.split('').map(char => parseInt(char.charCodeAt(0).toString(16), 16)); +} + diff --git a/entry/src/main/ets/utils/UdpUtils.ets b/entry/src/main/ets/utils/UdpUtils.ets index dfeb079f..3d6c7f4d 100644 --- a/entry/src/main/ets/utils/UdpUtils.ets +++ b/entry/src/main/ets/utils/UdpUtils.ets @@ -2,6 +2,7 @@ import socket from '@ohos.net.socket' import common from '@ohos.app.ability.common' import FileUtils from './fileUtils' import promptAction from '@ohos.promptAction' +import { CarInfoType } from '../model' type DealMethod = (value: ArrayBuffer) => string @@ -22,30 +23,6 @@ class UdpClient { private errorEvents: Array = [] private dealMethod: DealMethod - protected create(udpLocalIp: string, udpLocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) { - this.localIp = udpLocalIp - this.oppositeIp = udpOppositeIp - this.localIpPort = udpLocalIpPort - this.oppositeIpPort = udpOppositeIpPort - this.udp = socket.constructUDPSocketInstance(); - this.bindEvent() - this.bindUdp() - } - - private bindEvent() { - this.udp?.on("message", value => { - let result = this?.dealMethod(value.message) - this.messageEvents.forEach(cb => { - cb(result) - }) - }) - this.udp.on("error", (err) => { - this.errorEvents.forEach(cb => { - cb(err) - }) - }) - } - bindUdp(): Promise { return this.udp.bind({ address: this.localIp, port: parseInt(this.localIpPort), family: 1 }) } @@ -83,6 +60,30 @@ class UdpClient { }) }) } + + protected create(udpLocalIp: string, udpLocalIpPort: string, udpOppositeIp: string, udpOppositeIpPort: string) { + this.localIp = udpLocalIp + this.oppositeIp = udpOppositeIp + this.localIpPort = udpLocalIpPort + this.oppositeIpPort = udpOppositeIpPort + this.udp = socket.constructUDPSocketInstance(); + this.bindEvent() + this.bindUdp() + } + + private bindEvent() { + this.udp?.on("message", value => { + let result = this?.dealMethod(value.message) + this.messageEvents.forEach(cb => { + cb(result) + }) + }) + this.udp.on("error", (err) => { + this.errorEvents.forEach(cb => { + cb(err) + }) + }) + } } class ObjUdpClient extends UdpClient { @@ -107,10 +108,7 @@ class CenterUDPClient extends UdpClient { try { const fileUtil = new FileUtils(context) const data = await fileUtil.readFile("" + '/config/ipConfig.txt'); - const carInfo: { - udpAddress: string - messagePort: string - } = AppStorage.Get('carInfo') + const carInfo: CarInfoType = AppStorage.get('carInfo') if (data?.length > 0) { const result: IPConfig = JSON.parse(data) this.create(result.udplocalIp, '8800', carInfo?.udpAddress, carInfo?.messagePort)