Compare commits

...

11 Commits

Author SHA1 Message Date
wangzhongjie
cbb64fdf42 fix: 文件读取优化,以及设置存储优化 2025-10-17 11:49:44 +08:00
wangzhongjie
a3d51c8a79 fix: 增加一个指令 2025-10-17 11:06:02 +08:00
wangzhongjie
aa67ead81a fix: 串口代码优化 2025-10-17 10:18:59 +08:00
wangzhongjie
fa80b4ca7b fix: 串口代码优化 2025-10-17 10:12:13 +08:00
wangzhongjie
b9ed251380 fix: 合并代码 2025-10-17 10:03:02 +08:00
wangzhongjie
1fb5fa23b9 fix: 润和兼容性更改 2025-10-17 10:02:17 +08:00
wangzhongjie
6d3a5d2360 Merge branch 'dev' of http://47.122.70.237:3000/harmony_car/harmony_vehicle_terminal into dev 2025-10-15 17:19:48 +08:00
wangzhongjie
09096d8d6c fix: 合并log 2025-10-15 17:18:51 +08:00
wangzhongjie
801932c42e fix: 修复考试结束两次返回 2025-10-15 17:17:52 +08:00
wangzhongjie
d35c015f7f Merge branch 'dev' of http://47.122.70.237:3000/harmony_car/harmony_vehicle_terminal into dev 2025-10-15 16:29:15 +08:00
wangzhongjie
a94575c6f1 fix: 查看问题 2025-10-15 16:29:13 +08:00
19 changed files with 319 additions and 179 deletions

View File

@ -1,8 +1,8 @@
gitLog:
git log --since="2025-08-08 14:00" --until="2025-08-19 15:00" --pretty=format:"<details>%n <summary>%s</summary>%n <span style=\"color: #888;\">[提交人]:</span><span style=\"color: #333;\">%an</span><br>%n <span style=\"color: #888;\">[提交时间]:</span><span style=\"color: #333;\">%ad</span><br>%n <span style=\"color: #888;\">[提交版本]:</span><span style=\"color: #333;\">%h</span>%n</details>%n" --date=format:"%Y-%m-%d %H:%M" > release_note.md
re:
hdc shell mount -o remount,rw /
pushJudge:
hdc file send /Users/wangzhongjie/Desktop/duolun/openHarmony/car_next/ohos/so/libjudgesdk.z.so /system/lib/module/
uninstall:
hdc uninstall com.oh.dts

View File

@ -5,9 +5,9 @@
"name": "default",
"material": {
"certpath": "/Users/wangzhongjie/.ohos/config/openharmony/default_car_next_xIuD6UMCLxZgyeiH-w2XdDck6DewIfdHAvOk_FUbNZo=.cer",
"storePassword": "0000001BD807731D6FB9F044E3DF0E0429F4BB4214FE1608E25B4197041FBF36DDA3C6760585312F2864B6",
"storePassword": "0000001B42BCAC6B534ABB3B488F5C45764278201EE92A007F988939EC561EEB8ED64F737B8A11A7A72A1E",
"keyAlias": "debugKey",
"keyPassword": "0000001BFA38BF5235541496B5FF9ED9FFA764AB53FABC873D21DC230060209C2FF24ACE5DA09413B0C138",
"keyPassword": "0000001B2A149F63C38A6F5B972EC903EB0ADAB7978BA6C33B8E460C7353BD0BC2248776AB2FD2AE009A98",
"profile": "/Users/wangzhongjie/.ohos/config/openharmony/default_car_next_xIuD6UMCLxZgyeiH-w2XdDck6DewIfdHAvOk_FUbNZo=.p7b",
"signAlg": "SHA256withECDSA",
"storeFile": "/Users/wangzhongjie/.ohos/config/openharmony/default_car_next_xIuD6UMCLxZgyeiH-w2XdDck6DewIfdHAvOk_FUbNZo=.p12"

View File

@ -8,10 +8,9 @@ import { BaseInfoType, CarInfoType, EnvironmentConfigurationType, ExaminerInfoTy
import DB from '../utils/DbSql';
import { DrivingDataStorage } from '../utils/business/DrivingDataStorage';
import { InitTable } from '../utils/table/Operation';
import FileUtils from '../utils/FileUtils';
import { EntryTag } from '../config';
import { dConsole } from '../utils/LogWorker';
import { UseAuth } from '../utils/Common';
import { ReadFileContent, UseAuth } from '../utils/Common';
import { DifferentialAndSignal } from '../utils/business/DifferentialAndSignalWorker';
export default class EntryAbility extends UIAbility {
@ -19,9 +18,8 @@ export default class EntryAbility extends UIAbility {
console.log(EntryTag, "多伦鸿蒙车载程序启动")
await DB.init(this.context)
try {
let fileUtil = new FileUtils(this.context)
// 读取系统设置参数
const data = await fileUtil.readFile(GlobalConfig.commonFileWriteAddress + '/config/ipConfig.txt');
const data = await ReadFileContent(GlobalConfig.commonFileWriteAddress + '/config/ipConfig.txt')
if (data !== '' && data !== undefined) {
const result: EnvironmentConfigurationType = JSON.parse(data)
AppStorage.setOrCreate<EnvironmentConfigurationType>("EnvironmentConfiguration", result)
@ -33,7 +31,7 @@ export default class EntryAbility extends UIAbility {
AppStorage.setOrCreate<string>("host", host)
}
// 读取视频配置
const videoData = await fileUtil.readFile(GlobalConfig.commonFileWriteAddress + '/config/config3.txt');
const videoData = await ReadFileContent(GlobalConfig.commonFileWriteAddress + '/config/config3.txt')
if (videoData !== '' && videoData !== undefined) {
const videoConfig: VideoConfig = JSON.parse(videoData)
AppStorage.setOrCreate<VideoConfig>("VideoConfig", videoConfig)
@ -79,8 +77,7 @@ export default class EntryAbility extends UIAbility {
})
AppStorage.setOrCreate('isJudgeInitBool', false)
let fileUtil = new FileUtils(this.context)
const data = await fileUtil.readFile(GlobalConfig.commonFileWriteAddress + '/config/ipConfig.txt');
const data = await ReadFileContent(GlobalConfig.commonFileWriteAddress + '/config/ipConfig.txt')
if (data !== '' && data !== undefined) {
const config: EnvironmentConfigurationType = JSON.parse(data)
await windowClass.setWindowLayoutFullScreen(true)

View File

@ -0,0 +1,71 @@
import { CommonListType } from '../model'
export const RearMachineModelListData: CommonListType[] = [
{
label: '一型机',
value: '1'
},
{
label: '二型机',
value: '2'
},
{
label: '三型机',
value: '3'
},
{
label: '一体机',
value: '4'
}
]
export const BoardListData: CommonListType[] = [
{
label: '北云',
value: '1'
},
{
label: '天宝MB2',
value: '2'
}
]
export const LogListData: CommonListType[] = [
{
label: '开启',
value: '1'
},
{
label: '关闭',
value: '0'
}
]
export const CarTypeListData: CommonListType[] = [
{
label: '小车C1',
value: '1'
},
{
label: '小车C2',
value: '2'
},
{
label: '大车',
value: '3'
},
{
label: '牵引车A2',
value: '4'
}
]
export const ManufacturerListData: CommonListType[] = [
{
label: '诚迈',
value: '1'
},
{
label: '润和',
value: '2'
}
]

View File

@ -8,3 +8,4 @@ export * from "./SignDisplay"
export * from "./CarCheck"
export * from "./Test"
export * from "./TerminallInfo"

View File

@ -173,6 +173,8 @@ export interface EnvironmentConfigurationType {
judgeVersion?: string
// 是否使用网络摄像头
isUseNetworkCamera?: string
// 厂商 诚迈 1 润和 2
manufacturer?: string
}
//全局配置

View File

@ -427,7 +427,8 @@ export struct JudgePage {
const carlistArr = info.carlist === '' ? [] : (decodeURI(info.carlist || "").split(',') || []);
const newKey = key.split('~').join('_')
const xmdm = Number(key.split('~')[0])
const currentProject: ProjectInfo = Reflect.get(this.projectsObj, xmdm)
const data: ProjectInfos = JSON.parse(JSON.stringify(this.projectsObj))
const currentProject: ProjectInfo = Reflect.get(data, xmdm)
if (currentProject && (carlistArr.length == 0 || carlistArr.includes(this.carlist))) {
Reflect.set(this.itemInfoObj!, newKey, {
modelKey: newKey,
@ -461,7 +462,7 @@ export struct JudgePage {
const examItems: string | undefined = currentParams?.examItems;
// 2024-01-03 16:29:26;0;20300,;2,4^2,4;null;
if (examItems !== '' && examItems !== undefined) {
dConsole.info(JudgeTag, 'surenjun examItems=>', JSON.stringify(examItems))
dConsole.info(JudgeTag, 'surenjun examItems=>', examItems)
const examItemsArrs = examItems.split(';');
const startTime = examItemsArrs[0]
const ddxkKsxmArr = examItemsArrs[2]?.split(',').filter(item => item) || []

View File

@ -408,9 +408,9 @@ export class BaseJudge {
const singlePlay = judgeUI.singlePlay
//TODO 断网考试结束补传
// await uploadDisConnectData();
let backTimeOut = setTimeout(() => {
router.back()
}, 90 * 1000)
// let backTimeOut = setTimeout(() => {
// router.back()
// }, 90 * 1000)
console.info(JudgeTag, '考试结束 end')
const param302 = judgeUI.judgeConfigObj.param_302;
@ -427,11 +427,9 @@ export class BaseJudge {
case 'voice/unqualified_one.wav':
currentKssycs = 0;
break;
case 'voice/unqualified_two.wav':
currentKssycs = 1;
break;
case 'voice/qualified.mp3':
currentKssycs = 0;
break;
@ -474,7 +472,7 @@ export class BaseJudge {
if (!singlePlay) {
// await uploadProgressData();
}
clearTimeout(backTimeOut)
// clearTimeout(backTimeOut)
//语音播放扣分项
let score = 0;
//结束考试时候是否播报一遍所有扣分
@ -747,7 +745,7 @@ export class BaseJudge {
}
// 考试结束
case 5: {
dConsole.info(JudgeTag, "考试结束")
dConsole.info(JudgeTag, "考试结束距离1", ksjs)
that.ksjs = ksjs;
dConsole.writeProcessData(ProcessDataEnumType.JudgeExamData, JSON.stringify({
method: 'examJudgeEndExam'

View File

@ -1,7 +1,7 @@
/**
* 过程数据处理
*/
import { ExamProcessDataTag, ProcessDataTag, QueueTag } from '../../config';
import { ExamProcessDataTag, JudgeTag, ProcessDataTag, QueueTag } from '../../config';
import {
CarInfoType,
CDSBInfo,
@ -184,6 +184,7 @@ export const TheExamIsOver = async (judgeUI: JudgePage, that: JudgeBusiness, cal
const carInfo: CarInfoType = AppStorage.get("carInfo")!
const photoBase64 = await GetPhotoBase64(judgeUI.context);
const ksjs = that.ksjs!
dConsole.log(JudgeTag, "考试结束距离", that.ksjs)
const data: RegulatoryInterfaceParams = {
JGHOST: AppStorage.get<string>("JGHOST") || "",
xtlb: '17',
@ -197,7 +198,8 @@ export const TheExamIsOver = async (judgeUI: JudgePage, that: JudgeBusiness, cal
zp: photoBase64,
jssj: dayTs().format("YYYY-MM-DD HH:mm:ss"),
kscj: (judgeUI.totalScore * 1) > 0 ? judgeUI.totalScore : 0,
kslc: Math.ceil(((ksjs?.qjjl! + ksjs?.dcjl!) || 0) / 100),
// kslc: Math.ceil(((ksjs?.qjjl + ksjs?.dcjl) || 0) / 100),
kslc: Math.ceil(((ksjs?.qjjl + ksjs?.dcjl) || 0) / 100),
dwlc: [ksjs.d1, ksjs.d2, ksjs.d3, ksjs.d4, ksjs!.d5].map((d, index) => `${index + 1},${Math.floor(d / 100)}`)
.join(';'),
}

View File

@ -99,11 +99,12 @@ export class SmallJudge extends BaseJudge implements BaseJudgeImpl {
public async GetJudgeInitData(context: common.UIAbilityContext, markRuleListObj: object, carType: string, carName: string, systemparmArr: SYSTEM_PARAM[], carinfoArr: CAR_INFO[], examSubject: string, itemInfoObj: ItemInfos, judgeConfig: SyssetConfig[], carlist: string, mapPointArr: MAPPOINT[], mapPointItemArr: MAPITEMPOINTITEM[]) {
const carInfo = AppStorage.get<CarInfoType>('carInfo');
const examType = carInfo?.examSubject == '2' ? 'km2' : 'km3'
dConsole.log(JudgeTag, "itemInfoObj", itemInfoObj)
let allitems: ItemInfo[] = [];
if (examSubject == '2' && itemInfoObj) {
allitems = Reflect.ownKeys(itemInfoObj).map(cdsbKey => {
const cdsb: CDSBInfo = Reflect.get(itemInfoObj, cdsbKey);
// const cdsb: CDSBInfo = Reflect.get(itemInfoObj, cdsbKey);
const cdsb: CDSBInfo = Object.entries(itemInfoObj).find((arr: Array<string>) => arr[0] === cdsbKey)![1]
const model = GetModelData(`${examType}/${cdsb.modelKey}.txt`, context)
const temp: ItemInfo = {
xmdm: cdsb?.xmdm || 0,
@ -298,7 +299,6 @@ export class SmallJudge extends BaseJudge implements BaseJudgeImpl {
}
public async JudgeStart(callBack: Function, judgeUI: JudgePage, that: JudgeBusiness) {
const isTrajectoryOpen = JudgeConfig.isTrajectoryOpen;
const trajectoryPath = JudgeConfig.trajectoryPath;
let strArr: string[] = [];

View File

@ -1,25 +1,25 @@
import HeaderComponent from './compontents/Header';
import { CommonListType, EnvironmentConfigurationType } from '../model';
import common from '@ohos.app.ability.common';
import FileUtils from '../utils/FileUtils';
import { GlobalConfig, TerminalInfoTag } from '../config';
import ethernet from '@ohos.net.ethernet';
import { BusinessError } from '@ohos.base';
import Prompt from '@system.prompt';
import { dConsole } from '../utils/LogWorker';
import window from '@ohos.window';
import { BoardListData, CarTypeListData, LogListData, ManufacturerListData, RearMachineModelListData } from '../mock';
import { OverWriteFile, ReadFileContent } from '../utils/Common';
@Entry
@Component
struct TerminalInfoPage {
@State config: EnvironmentConfigurationType = {}
@State isProcessing: boolean = false;
private fileUtil!: FileUtils
@State IpConfigFilePath: string = GlobalConfig.commonFileWriteAddress + '/config/ipConfig.txt'
private context = getContext(this) as common.UIAbilityContext;
async aboutToAppear() {
this.fileUtil = new FileUtils(this.context)
const data = await this.fileUtil.readFile(GlobalConfig.commonFileWriteAddress + '/config/ipConfig.txt');
const data = await ReadFileContent(this.IpConfigFilePath)
dConsole.log(TerminalInfoTag, "data", data)
if (data) {
this.config = JSON.parse(data)
@ -28,6 +28,10 @@ struct TerminalInfoPage {
}
async aboutToDisappear() {
dConsole.log(TerminalInfoTag, "TerminalInfoPage aboutToDisappear")
}
build() {
Flex({
justifyContent: FlexAlign.Center,
@ -225,6 +229,14 @@ struct TerminalInfoPage {
}
}
})
blockComponent({
label: "前置机厂商",
type: 8,
value: this.config.manufacturer,
change: (value: string) => {
this.config.manufacturer = value;
}
})
}.margin(20)
}
.height(650)
@ -237,7 +249,7 @@ struct TerminalInfoPage {
})
Row() {
Image($r('app.media.bc')).height(80).objectFit(ImageFit.Contain).onClick(() => {
Image($r('app.media.bc')).height(80).objectFit(ImageFit.Contain).onClick(async () => {
if (this.isProcessing) {
Prompt.showToast({
message: "请勿频繁点击",
@ -248,33 +260,43 @@ struct TerminalInfoPage {
this.isProcessing = true
dConsole.log(TerminalInfoTag, "保存配置", JSON.stringify(this.config))
AppStorage.setOrCreate<EnvironmentConfigurationType>("EnvironmentConfiguration", this.config)
this.fileUtil.addFile(GlobalConfig.commonFileWriteAddress + '/config/ipConfig.txt', JSON.stringify(this.config))
// this.fileUtil.addFile(GlobalConfig.commonFileWriteAddress + '/config/ipConfig.txt', JSON.stringify(this.config))
// 先删除文件
const result = await OverWriteFile(this.IpConfigFilePath, JSON.stringify(this.config))
if (result) {
Prompt.showToast({
message: "保存配置文件成功",
duration: 3000
})
ethernet.setIfaceConfig("eth0", {
mode: ethernet.IPSetMode.STATIC,
ipAddr: this.config.udplocalIp,
route: "0.0.0.0",
gateway: this.config.gateway, //value.gateway网关
netMask: this.config.netMask, //value.netMask网络掩码
dnsServers: this.config.dnsServers,
domain: ""
}, (error: BusinessError) => {
if (error) {
Prompt.showToast({
message: '设置失败' + JSON.stringify(error),
duration: 3000
});
} else {
Prompt.showToast({
message: '设置网络成功',
duration: 3000
});
// 延迟几秒
setTimeout(() => {
this.isProcessing = false
}, 3000)
}
});
}
dConsole.init(this.config.isOpenLog)
ethernet.setIfaceConfig("eth0", {
mode: ethernet.IPSetMode.STATIC,
ipAddr: this.config.udplocalIp,
route: "0.0.0.0",
gateway: this.config.gateway, //value.gateway网关
netMask: this.config.netMask, //value.netMask网络掩码
dnsServers: this.config.dnsServers,
domain: ""
}, (error: BusinessError) => {
if (error) {
Prompt.showToast({
message: '设置失败' + JSON.stringify(error),
duration: 3000
});
} else {
Prompt.showToast({
message: '设置成功',
duration: 3000
});
// 延迟几秒
setTimeout(() => {
this.isProcessing = false
}, 3000)
}
});
})
}
@ -315,64 +337,13 @@ struct blockComponent {
// 0 -输入框,1 -后置机类型,2 -日志开关,3 -板卡类型
@State type: number = 0
// '一型机', '二型机', '三型机', '一体机'
@State rearMachineModelList: CommonListType[] = [
{
label: '一型机',
value: '1'
},
{
label: '二型机',
value: '2'
},
{
label: '三型机',
value: '3'
},
{
label: '一体机',
value: '4'
}
]
@State rearMachineModelList: CommonListType[] = RearMachineModelListData
// '北云', '天宝MB2'
@State boardList: CommonListType[] = [
{
label: '北云',
value: '1'
},
{
label: '天宝MB2',
value: '2'
}
]
@State logList: CommonListType[] = [
{
label: '开启',
value: '1'
},
{
label: '关闭',
value: '0'
}
]
@State boardList: CommonListType[] = BoardListData
@State logList: CommonListType[] = LogListData
// 车型 "小车C1", "小车C2", "大车", "牵引车A2"
@State carTypeList: CommonListType[] = [
{
label: '小车C1',
value: '1'
},
{
label: '小车C2',
value: '2'
},
{
label: '大车',
value: '3'
},
{
label: '牵引车A2',
value: '4'
}
]
@State carTypeList: CommonListType[] = CarTypeListData
@State manufacturerList: CommonListType[] = ManufacturerListData
aboutToAppear(): void {
}
@ -410,7 +381,7 @@ struct blockComponent {
} else {
ForEach(this.type === 1 ? this.rearMachineModelList :
this.type === 2 || this.type === 5 || this.type === 6 || this.type === 7 ? this.logList :
this.type === 3 ? this.boardList : this.carTypeList, (item: CommonListType, index) => {
this.type === 3 ? this.boardList : this.type === 8 ? this.manufacturerList : this.carTypeList, (item: CommonListType, index) => {
Radio({ value: item.label, group: 'terRadioGroup' + this.type })
.borderColor('#E5CBA1')
.checked(item.value === this.value ? true : false)

View File

@ -156,14 +156,6 @@ struct UserInfoPage {
@State singlePlay: boolean = false
private context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext;
private avPlayer!: VoiceAnnounce
private labelBlocks: LabelBlockType[] = [
{ label: '考生姓名', key: 'xm' },
{ label: '身份证号', key: 'sfzmhm' },
{ label: ' 流 水 号 ', key: 'lsh' },
{ label: '考试路线', key: 'ksxl' },
{ label: '待考次数', key: 'kssycs' },
{ label: '考试员名', key: 'ksy2' },
]
//开始考试准备
prePareExam = async () => {
dConsole.log(StartExamTag, 'prePareExam')
@ -180,9 +172,12 @@ struct UserInfoPage {
if (this.singlePlay) {
this.currentUser.id = '0'
dConsole.log(StartExamTag, '开始考试3', this.currentUser)
SqlInsertTable('USER', [this.currentUser]).catch((e: BusinessError) => {
dConsole.log(StartExamTag, "error", JSON.stringify(e))
})
try {
// let data: Array<User> = JSON.parse(JSON.stringify([this.currentUser]))
await SqlInsertTable('USER', [this.currentUser])
} catch (e) {
dConsole.error(StartExamTag, '开始考试插入用户表失败', JSON.stringify(e))
}
// 初始化开始考试过程数据文件夹
InitializeExamProcessData(this.currentUser)
dConsole.log(StartExamTag, '开始考试4')
@ -213,6 +208,14 @@ struct UserInfoPage {
}
}
private labelBlocks: LabelBlockType[] = [
{ label: '考生姓名', key: 'xm' },
{ label: '身份证号', key: 'sfzmhm' },
{ label: ' 流 水 号 ', key: 'lsh' },
{ label: '考试路线', key: 'ksxl' },
{ label: '待考次数', key: 'kssycs' },
{ label: '考试员名', key: 'ksy2' },
]
async aboutToAppear() {
this.avPlayer = new VoiceAnnounce(this.context);

View File

@ -109,11 +109,11 @@ export function NumberToByteArray(number: number | string, len: number): number[
return arrBytes;
}
/*
* 将字符串填充为指定长度的字符串前面补0
* @param str 要填充的字符串或数字
* @param len 目标长度
* @return 返回填充后的字符串
/**
* 将字符串填充为指定长度的字符串前面补0
* @param str 要填充的字符串或数字
* @param len 目标长度
* @return 返回填充后的字符串
*/
export function FillZero(str: string | number, len: number): string {
str = str.toString();
@ -176,10 +176,10 @@ export function DeepClone<T extends Object>(target: T): T {
return target;
}
/*
* 检查文件或目录是否存在
* @param path 文件或目录的路径
* @return 返回一个 Promise解析为 true 如果存在,否则为 false
/**
* 检查文件或目录是否存在
* @param path 文件或目录的路径
* @return 返回一个 Promise解析为 true 如果存在,否则为 false
*/
export function IsExit(path: string): Promise<boolean> {
return new Promise((resolve, reject) => {
@ -221,7 +221,37 @@ export function CreateDir(path: string): Promise<boolean> {
}
/**
* 写文件
* 打开文件
*/
export function OpenFile(path: string): Promise<number> {
return new Promise((resolve, reject) => {
try {
const file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.APPEND | fs.OpenMode.CREATE)
resolve(file.fd)
} catch (e) {
reject(-1)
}
})
}
/**
* 关闭文件
*/
export function CloseFile(fd: number): Promise<boolean> {
return new Promise((resolve, reject) => {
try {
fs.closeSync(fd)
resolve(true)
} catch (e) {
reject(false)
}
})
}
/**
* 追加写文件
* @params fd 文件描述符
* @params data 写入的数据
*/
export function EditFile(fd: number, data: string): Promise<boolean> {
return new Promise((resolve, reject) => {
@ -234,6 +264,31 @@ export function EditFile(fd: number, data: string): Promise<boolean> {
})
}
/**
* 覆盖写文件
*/
export function OverWriteFile(path: string, data: string): Promise<boolean> {
return new Promise(async (resolve, reject) => {
try {
// 先删除文件
const res = await DeleteFile(path);
if (res) {
// 创建文件
const fd = await CreateFile(path);
if (fd !== -1) {
// 写入数据
await EditFile(fd, data);
// 关闭文件
await CloseFile(fd);
}
}
resolve(true)
} catch (e) {
reject(false)
}
})
}
/**
* 创建文件
* @params path 文件具体路径
@ -252,10 +307,41 @@ export function CreateFile(path: string): Promise<number> {
})
}
/*
* 将秒数转换为灵活的时间格式HH:MM:SS
* @param seconds 要转换的秒数
* @return 返回格式化后的时间字符串
/**
* 删除文件
*/
export function DeleteFile(path: string): Promise<boolean> {
return new Promise((resolve, reject) => {
try {
fs.unlinkSync(path)
console.log(CommonFileTag, "删除文件成功", path)
resolve(true)
} catch (e) {
console.log(CommonFileTag, "删除文件失败", path)
reject(false)
}
})
}
/**
* 读取文件内容
* @params path 文件具体路径
*/
export function ReadFileContent(path: string): Promise<string> {
return new Promise((resolve, reject) => {
try {
const data = fs.readTextSync(path)
resolve(data)
} catch (e) {
reject(e)
}
})
}
/**
* 将秒数转换为灵活的时间格式HH:MM:SS
* @param seconds 要转换的秒数
* @return 返回格式化后的时间字符串
*/
export function FormatTimeFlexible(seconds: number): string {
if (seconds < 0) {
@ -291,10 +377,10 @@ export function ApplyForAuthorization(context: Context, permissionList: Array<Pe
})
}
/*
* 使用权限
* @param context 上下文
* @return 返回一个 Promise解析为 true 如果授权成功,否则为 false
/**
* 使用权限
* @param context 上下文
* @return 返回一个 Promise解析为 true 如果授权成功,否则为 false
*/
export async function UseAuth(context: common.UIAbilityContext): Promise<boolean> {
const permissions: Array<Permissions> = [
@ -352,3 +438,4 @@ export const GetPhotoBase64 = async (context: common.UIAbilityContext): Promise<
}
}
}

View File

@ -1,14 +1,14 @@
import testNapi from '@ohos.hiserialsdk';
import HiSerialSDK from '@ohos.hiserialsdk';
import { SerialPortTag } from '../config';
// 打开串口工具
/*
* @param serialPort 串口名称
/**
* 打开串口工具
* @param serialPort 串口名称
*/
export const OpenSerialPort = (serialPort: string) => {
return new Promise<number>((resolve, reject) => {
testNapi.SerialOpenAsync(serialPort, (value: number) => {
HiSerialSDK.SerialOpenAsync(serialPort, (value: number) => {
if (value === -1) {
console.error(SerialPortTag, "打开串口失败!")
reject(-1)
@ -19,16 +19,17 @@ export const OpenSerialPort = (serialPort: string) => {
})
}
//初始化串口数据
/*
* @param fd 串口文件描述符
* @param speed 波特率
* @returns Promise<boolean> 成功返回true失败返回false
/**
* 初始化串口数据
* @param fd 串口文件描述符
* @param speed 波特率
* @returns Promise<boolean> 成功返回true失败返回false
*/
export const InitSerialPortData =
async (fd: number, speed: number) => {
return new Promise<boolean>((resolve, reject) => {
testNapi.SerialSetAsync(fd, speed, 0, 8, 1, 0x4e, (value: number) => {
HiSerialSDK.SerialSetAsync(fd, speed, 0, 8, 1, 0x4e, (value: number) => {
// 0 成功 -1失败
if (value === 0) {
console.log(SerialPortTag, "初始化成功!")
@ -42,16 +43,17 @@ export const InitSerialPortData =
})
}
//发送数据
/*
* @param fd 串口文件描述符
* @param data 要发送的数据数组
* @returns Promise<number> 成功返回发送的字节数,失败返回-1
/**
* 发送数据
* @param fd 串口文件描述符
* @param data 要发送的数据数组
* @returns Promise<number> 成功返回发送的字节数,失败返回-1
*/
export const SendSerialPortData = (fd: number, data: number[]) => {
// console.log(SerialPortTag, "wzj-----发送数据")
console.log(SerialPortTag, "wzj-----发送数据")
return new Promise<number>((resolve, reject) => {
testNapi.SerialSendAsync(fd, data, (value: number) => {
HiSerialSDK.SerialSendAsync(fd, data, (value: number) => {
console.log(SerialPortTag, "发送数据完成!")
if (value === -1) {
console.error(SerialPortTag, "发送失败!")
reject(-1)
@ -61,16 +63,16 @@ export const SendSerialPortData = (fd: number, data: number[]) => {
})
}
// 接受数据
/*
* @param fd 串口文件描述符
* @param timeout 超时时间,单位毫秒
* @returns Promise<HiSerialSDK.receiveInfo> 成功返回接收到的数据,失败返回-1
/**
* 接受数据
* @param fd 串口文件描述符
* @param timeout 超时时间,单位毫秒
* @returns Promise<HiSerialSDK.receiveInfo> 成功返回接收到的数据,失败返回-1
*/
export const ReceiveSerialPortData = (fd: number, timeout: number,) => {
// console.log(SerialPortTag, "wzj-----接受数据")
console.log(SerialPortTag, "wzj-----接受数据")
return new Promise<HiSerialSDK.receiveInfo>((resolve) => {
testNapi.SerialRecvAsync(fd, timeout, (value: HiSerialSDK.receiveInfo) => {
HiSerialSDK.SerialRecvAsync(fd, timeout, (value: HiSerialSDK.receiveInfo) => {
resolve(value)
})
})
@ -78,13 +80,13 @@ export const ReceiveSerialPortData = (fd: number, timeout: number,) => {
// 主动接受数据
export const ReceiveSerialPortDataBySelf = (fd: number, callback: Function) => {
testNapi.SerialListenCallbackSet(fd, callback)
HiSerialSDK.SerialListenCallbackSet(fd, callback)
}
// 取消主动接受
export const CancelReceiveSerialPortData = async (fd: number) => {
return new Promise<boolean>((resolve, reject) => {
let result: number = testNapi.SerialListenCallbackCancel(fd)
let result: number = HiSerialSDK.SerialListenCallbackCancel(fd)
if (result === 0) {
resolve(true)
} else {

View File

@ -83,7 +83,7 @@ export default class UdpClient {
address: this.oppositeIp, port: parseInt(this.oppositeIpPort), family: 1
}
}).then(res => {
console.log(UDPTag, "udp发送成功", JSON.stringify(res))
// console.log(UDPTag, "udp发送成功", JSON.stringify(res))
}).catch((e: BusinessError) => {
console.error(UDPTag, "udp发送失败", JSON.stringify(e))
})

View File

@ -43,7 +43,7 @@ class CenterUDPBusiness {
console.log(CenterUdpTag, "心跳", JSON.stringify(this.carInfo))
// 组装消息,一秒发送一次
this.timer = setInterval(() => {
console.log(CenterUdpTag, "发送心跳")
// console.log(CenterUdpTag, "发送心跳")
// 生成流水号
SerialNumberInstance.generate()
// console.log(CenterUdpTag, "流水号生成")

View File

@ -20,8 +20,6 @@ import { GetDwStatusType, GetTranslateSignals } from '../../pages/Judge/utils';
import { testKm2Items, testKm3Items } from '../../mock';
import { dConsole } from '../LogWorker';
// import { examCalcGpsDistance } from '../../pages/Judge/JudgeUtils';
class JudgeUdpBusiness {
private static instance: JudgeUdpBusiness

View File

@ -9,6 +9,7 @@ import {
} from '../SerialPort';
import Prompt from '@system.prompt';
import { SerialPortTag } from '../../config';
import { EnvironmentConfigurationType } from '../../model';
class serialPortService {
private fd: number = -1
@ -20,6 +21,11 @@ class serialPortService {
private tryCount: number = 0
async init() {
let config: EnvironmentConfigurationType = AppStorage.get<EnvironmentConfigurationType>("EnvironmentConfiguration")!
if (config.manufacturer === "2") {
console.log(SerialPortTag, "更改润和串口端口")
this.serialPort = "/dev/ttyS7"
}
const res = await OpenSerialPort(this.serialPort)
if (res === -1) {
Prompt.showToast({

View File

@ -34,7 +34,10 @@ export function SqlInsertTable(tableName: string, data: Array<RecordType>, delFl
const columns: string = columnsData?.filter((column) => column !== "id").join(",") || "";
const values = data.map(item => {
const value = columnsData?.filter(column => column !== "id")
.map((column) => `'${Reflect.get(item, column) || ""}'`)
.map((column) => {
// return `'${Reflect.get(item, column) || ""}'`
return `'${Object.entries(item).find((keyArr: Array<string>) => keyArr[0] === column)?.[1] || ""}'`
})
.join(",")
return `(${value})`
}).join(",")
@ -52,8 +55,6 @@ export function SqlInsertTable(tableName: string, data: Array<RecordType>, delFl
})
}
// 参数平台
// TODO 后续废弃这个方法,直接调用SqlInsertTable
// 依据数组和表名更新sql表
export function UpdateTableByArray(tableName: string, arr: Array<RecordType>): Promise<boolean> {