dev #2

Merged
wangzhongjie merged 77 commits from dev into main 2025-10-28 17:49:09 +08:00
6 changed files with 203 additions and 106 deletions
Showing only changes of commit cbb64fdf42 - Show all commits

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

@ -7,4 +7,5 @@ export * from "./Judge"
export * from "./SignDisplay"
export * from "./CarCheck"
export * from "./Test"
export * from "./Test"
export * from "./TerminallInfo"

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,
@ -245,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: "请勿频繁点击",
@ -256,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)
}
});
})
}
@ -323,74 +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 manufacturerList: CommonListType[] = [
{
label: '诚迈',
value: '1'
},
{
label: '润和',
value: '2'
}
]
@State carTypeList: CommonListType[] = CarTypeListData
@State manufacturerList: CommonListType[] = ManufacturerListData
aboutToAppear(): void {
}

View File

@ -221,7 +221,35 @@ 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 写入的数据
*/
@ -236,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 文件具体路径
@ -254,6 +307,22 @@ export function CreateFile(path: string): Promise<number> {
})
}
/**
* 删除文件
*/
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 文件具体路径

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({