dev #65

Merged
wangzhongjie merged 71 commits from dev into main 2025-06-17 17:32:26 +08:00
6 changed files with 383 additions and 382 deletions
Showing only changes of commit 912f5636db - Show all commits

View File

@ -1,190 +1,137 @@
import Want from '@ohos.app.ability.Want' import Want from '@ohos.app.ability.Want'
import promptAction from '@ohos.promptAction' import promptAction from '@ohos.promptAction'
import fileAccess from '@ohos.file.fileAccess'
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl' import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'
import common from '@ohos.app.ability.common' import common from '@ohos.app.ability.common'
import fs from '@ohos.file.fs' import fs from '@ohos.file.fs'
const LOGTAG = 'LOGTAG' const LOGTAG = 'LOGTAG'
export default class FileUtil{
private context: common.UIAbilityContext
private wantInfos: Want[]
private fileAccessHelper: fileAccess.FileAccessHelper
//后续文件路径待替换
private absolutePath = '/mnt/hmdfs/100/account/device_view/local/files/duolun'
public destFile:string
public filePathFdObj:Object = {}
constructor(wantInfos) {
const {requestPermission} = this;
this.wantInfos = wantInfos;
requestPermission();
fs.mkdir(this.absolutePath)
}
/*
* @desc
*
*/
public initFolder = async (folderPath:string) => {
const {absolutePath} = this;
const folderList = folderPath.split('/').filter(folderName => folderName !== '');
let path = absolutePath
folderList.forEach((folderName=>{
path += `/${folderName}`;
try {
const isExit = fs.accessSync(path);
if(!isExit){
fs.mkdirSync(path)
}
} catch (e) {
console.info('初始化文件夹失败',path)
promptAction.showToast({
message:`初始化文件夹失败`+ folderPath + JSON.stringify(e),
duration:4000,
})
}
}));
return path;
}
export default class FileUtil {
public destFile: string
public filePathFdObj: Object = {}
/* /*
* @desc * @desc
* *
*/ */
public addFile = async (filePath:string,content:string,type?:string)=>{ public addFile = async (filePath: string, content: string, type?: string) => {
const { READ_WRITE,CREATE,APPEND }= fs.OpenMode const { READ_WRITE,CREATE,APPEND } = fs.OpenMode
const isExit = fs.accessSync(filePath); const isExit = fs.accessSync(filePath);
//文件存在先删除 //文件存在先删除
if(isExit){ if (isExit) {
fs.unlinkSync(filePath); fs.unlinkSync(filePath);
} }
try { try {
let file = fs.openSync(filePath, READ_WRITE | CREATE); let file = fs.openSync(filePath, READ_WRITE | CREATE);
//追加写入文件 //追加写入文件
fs.writeSync(file.fd,content) fs.writeSync(file.fd, content)
fs.closeSync(file) fs.closeSync(file)
console.error(LOGTAG,'写入文件成功') console.error(LOGTAG, '写入文件成功')
return true return true
}catch (e){ } catch (e) {
promptAction.showToast({ promptAction.showToast({
message:`addFile文件失败`+ filePath +JSON.stringify(e), message: `addFile文件失败` + filePath + JSON.stringify(e),
duration:4000, duration: 4000,
}) })
console.error(LOGTAG,'写入失败',JSON.stringify(e)) console.error(LOGTAG, '写入失败', JSON.stringify(e))
} }
} }
/* /*
* @desc * @desc
* *
*/ */
public editFile = async (filePath:string,content:string,fd?:number)=>{ public editFile = async (filePath: string, content: string, fd?: number) => {
const {filePathFdObj} = this; const {filePathFdObj} = this;
const { READ_WRITE,CREATE,APPEND }= fs.OpenMode const { READ_WRITE,CREATE,APPEND } = fs.OpenMode
const newStr = content + '\n' const newStr = content + '\n'
const thisFile = filePathFdObj[filePath]; const thisFile = filePathFdObj[filePath];
try { try {
if(thisFile){ if (thisFile) {
fs.writeSync(thisFile.fd,newStr) fs.writeSync(thisFile.fd, newStr)
return fd; return fd;
}else{ } else {
let file = fs.openSync(filePath, READ_WRITE | APPEND |CREATE); let file = fs.openSync(filePath, READ_WRITE | APPEND | CREATE);
fs.writeSync(file.fd,newStr) fs.writeSync(file.fd, newStr)
this.filePathFdObj[filePath] = file this.filePathFdObj[filePath] = file
return file.fd return file.fd
} }
} catch (e) { } catch (e) {
promptAction.showToast({ promptAction.showToast({
message:`editFile文件失败`+ filePath +JSON.stringify(e), message: `editFile文件失败` + filePath + JSON.stringify(e),
duration:4000, duration: 4000,
}) })
console.error(LOGTAG,JSON.stringify(e)) console.error(LOGTAG, JSON.stringify(e))
} }
} }
/* /*
* @desc * @desc
* *
*/ */
public closeFile = async (filePath:string)=>{ public closeFile = async (filePath: string) => {
const {filePathFdObj} = this; const {filePathFdObj} = this;
const thisFile = filePathFdObj[filePath]; const thisFile = filePathFdObj[filePath];
if(thisFile){ if (thisFile) {
fs.closeSync(thisFile); fs.closeSync(thisFile);
console.info(LOGTAG,filePath + '文件关闭成功') console.info(LOGTAG, filePath + '文件关闭成功')
} }
} }
/* /*
* @desc * @desc
* *
**/ **/
public readFile = async (filePath:string) => { public readFile = async (filePath: string) => {
try{ try {
console.log('strrr',filePath) console.log('strrr', filePath)
const str = await fs.readText(filePath); const str = await fs.readText(filePath);
return str return str
}catch (e){ } catch (e) {
promptAction.showToast({ promptAction.showToast({
message:`读取文件失败`+ filePath +JSON.stringify(e), message: `读取文件失败` + filePath + JSON.stringify(e),
duration:4000, duration: 4000,
}) })
console.log('readFile文件失败'+ filePath +JSON.stringify(e)) console.log('readFile文件失败' + filePath + JSON.stringify(e))
return '' return ''
} }
} }
/* /*
* @desc获取系统目录里的文件列表 * @desc获取系统目录里的文件列表
*/ */
public getDeviceList = async (folderPath?:string)=>{ public getDeviceList = async (folderPath?: string) => {
const {absolutePath,getFilePathList} = this; const {absolutePath,getFilePathList} = this;
return getFilePathList(`${absolutePath}/${folderPath}`,false) return getFilePathList(`${absolutePath}/${folderPath}`, false)
}; };
private context: common.UIAbilityContext
private wantInfos: Want[]
private fileAccessHelper: any
//后续文件路径待替换
private absolutePath = '/mnt/hmdfs/100/account/device_view/local/files/duolun'
private getFilePathList = async (filePath: string, isSdcard: boolean) => {
let fileName = [], sdCardFileName = [];
// 删除文件夹或者文件 try {
/* const filenames = await fs.listFile(filePath);
* @desc for (let i = 0; i < filenames.length; i++) {
* @param{{type}} 1:文件夹 2 3 console.error(LOGTAG, `目录:${filePath}的子文件:${filenames[i]}`);
**/ if (isSdcard) {
sdCardFileName.push(filenames[i])
public deleteF = async (path:string,type: 1 | 2 | 3) => { } else {
const {getFilePathList,absolutePath} = this fileName.push(filenames[i])
if(type === 1){ }
const fileList = await getFilePathList(`${absolutePath}/${path}`,false); }
fileList.forEach(filePath =>{ return isSdcard ? sdCardFileName : fileName
fs.unlinkSync(`${absolutePath}/${path}/${filePath}`); } catch (e) {
}) console.error(LOGTAG, JSON.stringify(e));
fs.rmdirSync(`${absolutePath}/${path}`);
return true
} }
if(type === 2){
fs.unlinkSync(`${absolutePath}/${path}`);
return true
}
if(type === 3){
fs.unlinkSync(`${path}`);
return true
}
} }
// 获取系统文件绝对路径
public getAbsolutePath = () =>{
const {absolutePath} = this;
return absolutePath
}
// 检索文件列表 // 检索文件列表
public getSdCardPathList = async () => { public getSdCardPathList = async () => {
//@ts-ignore
this.wantInfos = await fileAccess.getFileAccessAbilityInfo(); this.wantInfos = await fileAccess.getFileAccessAbilityInfo();
const {wantInfos,context} = this; const {wantInfos,context} = this;
const fileAccessHelper = fileAccess.createFileAccessHelper(this.context,this.wantInfos); //@ts-ignore
const fileAccessHelper = fileAccess.createFileAccessHelper(this.context, this.wantInfos);
this.fileAccessHelper = fileAccessHelper; this.fileAccessHelper = fileAccessHelper;
let isDone = false; let isDone = false;
@ -200,52 +147,29 @@ export default class FileUtil{
if (!isDone) { if (!isDone) {
let deviceType = rootInfo.value.deviceType; let deviceType = rootInfo.value.deviceType;
let displayName = rootInfo.value.displayName; let displayName = rootInfo.value.displayName;
let uri:string = rootInfo.value.uri; let uri: string = rootInfo.value.uri;
let deviceFlags = rootInfo.value.deviceFlags; let deviceFlags = rootInfo.value.deviceFlags;
console.error(LOGTAG,`设备类型:${deviceType},设备名称:${displayName}设备根目录Uri${uri},设备支持的能力:${deviceFlags}`); console.error(LOGTAG, `设备类型:${deviceType},设备名称:${displayName}设备根目录Uri${uri},设备支持的能力:${deviceFlags}`);
if(uri.indexOf('/mnt/external/')>0){ if (uri.indexOf('/mnt/external/') > 0) {
// if('vol-8-1' ==displayName){ // if('vol-8-1' ==displayName){
this.destFile = uri.split('ExternalFileManager')[1]+'/' this.destFile = uri.split('ExternalFileManager')[1] + '/'
console.error(LOGTAG,`外置存储路径:`+this.destFile); console.error(LOGTAG, `外置存储路径:` + this.destFile);
this.getFilePathList(this.destFile,true) this.getFilePathList(this.destFile, true)
} }
} }
} }
} catch (error) { } catch (error) {
console.error(LOGTAG,"getRoots failed, errCode:" + error.code + ", errMessage:" + error.message); console.error(LOGTAG, "getRoots failed, errCode:" + error.code + ", errMessage:" + error.message);
} }
} }
public getFileContent = (filePath:string) => { // 删除文件夹或者文件
const {absolutePath} = this; /*
const { READ_WRITE }= fs.OpenMode * @desc
const path = `${absolutePath}/${filePath}` * @param{{type}} 1:文件夹 2 3
const str = fs.readTextSync(path); **/
return str
}
private getFilePathList = async (filePath:string,isSdcard:boolean) => {
let fileName = [],sdCardFileName = [];
try {
const filenames = await fs.listFile(filePath);
for (let i = 0; i < filenames.length; i++) {
console.error(LOGTAG,`目录:${filePath}的子文件:${filenames[i]}`);
if(isSdcard){
sdCardFileName.push(filenames[i])
}else{
fileName.push(filenames[i])
}
}
return isSdcard ? sdCardFileName : fileName
}catch (e){
console.error(LOGTAG,JSON.stringify(e));
}
}
// 文件系统初始化 // 文件系统初始化
private requestPermission = async () => { private requestPermission = async () => {
const {context,absolutePath} = this; const {context,absolutePath} = this;
@ -253,19 +177,87 @@ export default class FileUtil{
'ohos.permission.READ_MEDIA', 'ohos.permission.READ_MEDIA',
'ohos.permission.WRITE_MEDIA' 'ohos.permission.WRITE_MEDIA'
]; ];
// @ts-ignore
this.wantInfos = await fileAccess.getFileAccessAbilityInfo(); this.wantInfos = await fileAccess.getFileAccessAbilityInfo();
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager() let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager()
atManager.requestPermissionsFromUser(context, permissions , async (code, result) => { atManager.requestPermissionsFromUser(context, permissions, async (code, result) => {
const permissionRequest = result.authResults[0] const permissionRequest = result.authResults[0]
if(permissionRequest == -1){ if (permissionRequest == -1) {
promptAction.showToast({ promptAction.showToast({
message: "请先授权", message: "请先授权",
duration:3000, duration: 3000,
}) })
return return
} }
}) })
} }
constructor(wantInfos) {
const {requestPermission} = this;
this.wantInfos = wantInfos;
requestPermission();
fs.mkdir(this.absolutePath)
}
/*
* @desc
*
*/
public initFolder = async (folderPath: string) => {
const {absolutePath} = this;
const folderList = folderPath.split('/').filter(folderName => folderName !== '');
let path = absolutePath
folderList.forEach((folderName => {
path += `/${folderName}`;
try {
const isExit = fs.accessSync(path);
if (!isExit) {
fs.mkdirSync(path)
}
} catch (e) {
console.info('初始化文件夹失败', path)
promptAction.showToast({
message: `初始化文件夹失败` + folderPath + JSON.stringify(e),
duration: 4000,
})
}
}));
return path;
}
public deleteF = async (path: string, type: 1 | 2 | 3) => {
const {getFilePathList,absolutePath} = this
if (type === 1) {
const fileList = await getFilePathList(`${absolutePath}/${path}`, false);
fileList.forEach(filePath => {
fs.unlinkSync(`${absolutePath}/${path}/${filePath}`);
})
fs.rmdirSync(`${absolutePath}/${path}`);
return true
}
if (type === 2) {
fs.unlinkSync(`${absolutePath}/${path}`);
return true
}
if (type === 3) {
fs.unlinkSync(`${path}`);
return true
}
}
// 获取系统文件绝对路径
public getAbsolutePath = () => {
const {absolutePath} = this;
return absolutePath
}
public getFileContent = (filePath: string) => {
const {absolutePath} = this;
const { READ_WRITE } = fs.OpenMode
const path = `${absolutePath}/${filePath}`
const str = fs.readTextSync(path);
return str
}
} }

View File

@ -164,7 +164,6 @@ class TcpUtils {
if (log) { if (log) {
console.log(tag, 'send', message) console.log(tag, 'send', message)
} }
this.fileUtil.addFile(this.path + 'temp.txt', `^#${message}#$`)
this.socket.send({ this.socket.send({
data: `^#${message}#$` data: `^#${message}#$`
}).then(() => { }).then(() => {

View File

@ -1,5 +1,7 @@
import socket from '@ohos.net.socket'; import socket from '@ohos.net.socket';
import { PLCGPSData } from '../../mock'; import { PLCGPSData } from '../../mock/PLCGPSData';
// import { PLCGPSData } from '../../mock';
export default class UdpByOne { export default class UdpByOne {
// PLC udp // PLC udp
@ -12,7 +14,7 @@ export default class UdpByOne {
// PLC oppositeIpPort // PLC oppositeIpPort
private PLCOppositeIpPort: string = '30012'; private PLCOppositeIpPort: string = '30012';
// PLC消息 // PLC消息
private PLCMsg: number[]; private PLCMsg: ArrayBuffer;
// GPS udp // GPS udp
private GPSUDP: any; private GPSUDP: any;
// GPS localIp // GPS localIp
@ -21,7 +23,7 @@ export default class UdpByOne {
// GPS oppositeIpPort // GPS oppositeIpPort
private GPSOppositeIpPort: string = '30013'; private GPSOppositeIpPort: string = '30013';
// GPS消息 // GPS消息
private GPSMsg: string; private GPSMsg: any;
constructor() { constructor() {
// 初始化UDP // 初始化UDP
@ -72,16 +74,13 @@ export default class UdpByOne {
this.sendGPSMsg('1111') this.sendGPSMsg('1111')
this.PLCUDP.on("message", (res, remoteInfo) => { this.PLCUDP.on("message", (res, remoteInfo) => {
console.log('heartMsg', 'getPlc') console.log('heartMsg', 'getPlc')
this.PLCMsg = res.message; this.PLCMsg = res.message;
// 组合数据 // 组合数据
let newMessage = this.handleMsg(res.message) let newMessage = this.handleMsg()
callback(newMessage) callback(newMessage)
}) })
return
this.GPSUDP.on("message", (res1, remoteInfo) => { this.GPSUDP.on("message", (res1, remoteInfo) => {
console.log('heartMsg', 'GPSUDP') console.log('heartMsg', 'GPSUDP')
let dataView = new DataView(res1.message) let dataView = new DataView(res1.message)
let str = "" let str = ""
for (let i = 0; i < dataView?.byteLength; ++i) { for (let i = 0; i < dataView?.byteLength; ++i) {
@ -91,176 +90,173 @@ export default class UdpByOne {
} }
} }
this.GPSMsg = str; this.GPSMsg = str;
console.log('heartMsgGPSstr', str) let newMessage = this.handleMsg()
return this.PLCUDP.on("message", (res2, remoteInfo) => { callback(newMessage)
this.PLCMsg = res2.message;
// 组合数据
// let newMessage = this.handleMsg()
// callback(newMessage)
})
}) })
} }
// 处理消息 // 处理消息
public handleMsg(plcMessage) { public handleMsg() {
let newMessage = PLCGPSData; let newMessage = PLCGPSData;
console.log('heartMsg000', PLCGPSData) console.log('heartMsg000', PLCGPSData)
// 海拔高度 if (this.GPSMsg) {
// 原始GPS消息字符串 // 使用正则表达式提取$GPGGA消息
// this.GPSMsg = `$GPGGA,021126.00,2955.5885178,N,11953.8931034,E,5,12,0.8,13.191,M,6.838,M,2.000,0000*49$GPRMC,021126.00,A,2955.5885178,N,11953.8931034,E,4.881,318.3,170623,0.0,E,F*37$GPGST,021126.00,3.30,1.77,3.30,0.0000,1.77,1.25,3.30*67$PTNL,AVR,021126.00,+47.3119,Yaw,+0.4832,Tilt,,,0.817,3,1.7,25*09`; let GPGGAMsg = this.GPSMsg.match(/\$GPGGA[^$]*/)[0];
// 使用正则表达式提取$GPGGA消息 let GPGGAMsgArr = GPGGAMsg ? GPGGAMsg.split(",").slice(0, 15) : [];
let GPGGAMsg = this.GPSMsg.match(/\$GPGGA[^$]*/)[0]; // 使用正则提取$GPRMC消息
let GPGGAMsgArr = GPGGAMsg.split(",").slice(0, 15); let GPRMCMsg = this.GPSMsg.match(/\$GPRMC[^$]*/)[0];
// 使用正则提取$GPRMC消息 let GPRMCMsgArr = GPRMCMsg ? GPRMCMsg.split(",").slice(0, 14) : [];
let GPRMCMsg = this.GPSMsg.match(/\$GPRMC[^$]*/)[0]; // 使用正则表达式提取$GPGST消息
let GPRMCMsgArr = GPRMCMsg.split(",").slice(0, 14); let GPGSTMatch = this.GPSMsg.match(/\$GPGST[^$]*/);
// 使用正则表达式提取$GPGST消息] let GPGSTMsgArr = GPGSTMatch ? GPGSTMatch[0].split(",").slice(0, 9) : [];
let GPGSTMsg = this.GPSMsg.match(/\$GPGST[^$]*/)[0]; // 使用正则提取$PTNL消息
let GPGSTMsgArr = GPGSTMsg.split(",").slice(0, 9); let PTNLMsg = this.GPSMsg.match(/\$PTNL[^$]*/)[0];
// 使用正则提取$PTNL消息 let PTNLMsgArr = PTNLMsg.split(",").slice(0, 14);
let PTNLMsg = this.GPSMsg.match(/\$PTNL[^$]*/)[0]; // 组合GPS数据
let PTNLMsgArr = PTNLMsg.split(",").slice(0, 14); // 状态83
// 组合GPS数据 newMessage[83] = GPRMCMsgArr[6];
// 状态83 // 收星数84
newMessage[83] = GPRMCMsgArr[6]; newMessage[84] = PTNLMsgArr[10];
// 收星数84 // 海拔高85
newMessage[84] = PTNLMsgArr[10]; newMessage[80] = GPGGAMsgArr[9];
// 海拔高85 // 高度差86
newMessage[80] = GPGGAMsgArr[9]; // 龄期87
// 高度差86 newMessage[87] = GPGSTMsgArr[11];
// 龄期87 // 维度因子88
newMessage[87] = GPGSTMsgArr[11]; // 经度因子89
// 维度因子88 // 航向角90
// 经度因子89 newMessage[90] = PTNLMsgArr[3];
// 航向角90 // 俯仰角91
newMessage[90] = PTNLMsgArr[3]; newMessage[91] = PTNLMsgArr[5];
// 俯仰角91 // 航向角状态-收星数92
newMessage[91] = PTNLMsgArr[5]; newMessage[92] = PTNLMsgArr[8];
// 航向角状态-收星数92 // 年月日93 RMCMsgArr[9]为ddmmyy 日月年 转换为年月日
newMessage[92] = PTNLMsgArr[8]; newMessage[93] =
// 年月日93 RMCMsgArr[9]为ddmmyy 日月年 转换为年月日 GPRMCMsgArr[9].slice(4, 6) +
newMessage[93] = GPRMCMsgArr[9].slice(2, 4) +
GPRMCMsgArr[9].slice(4, 6) + GPRMCMsgArr[9].slice(0, 2);
GPRMCMsgArr[9].slice(2, 4) + // 时分秒94 GPGGAMsgArr[1]为021126.00去掉小数点后的时间
GPRMCMsgArr[9].slice(0, 2); newMessage[94] = GPGGAMsgArr[1].replace(".", "");
// 时分秒94 GPGGAMsgArr[1]为021126.00去掉小数点后的时间 // 经度95
newMessage[94] = GPGGAMsgArr[1].replace(".", ""); newMessage[95] = GPGGAMsgArr[4];
// 经度95 // 纬度96
newMessage[95] = GPGGAMsgArr[4]; newMessage[96] = GPGGAMsgArr[2];
// 纬度96 // 速度97
newMessage[96] = GPGGAMsgArr[2]; newMessage[97] = GPRMCMsgArr[7];
// 速度97
newMessage[97] = GPRMCMsgArr[7];
let dataView = new DataView(plcMessage)
let PLCByteArr = []
for (let i = 0; i < dataView?.byteLength; ++i) {
let c = dataView?.getUint8(i).toString(2).padStart(8, "0")
console.log('heartMsgheartMsg', c)
PLCByteArr.push(c.toString())
} }
// return if (this.PLCMsg) {
// let PLCByteArr = this.PLCMsg.map((num) => num.toString(2).padStart(8, "0")); let dataView = new DataView(this.PLCMsg)
console.log("heartMsgheartMsg1", PLCByteArr.toString()); let PLCByteArr = []
// 左方向灯 2 for (let i = 0; i < dataView?.byteLength; ++i) {
newMessage[2] = PLCByteArr[6][2]; let c = dataView?.getUint8(i).toString(2).padStart(8, "0")
// 右方向灯 3 PLCByteArr.push(c.toString())
newMessage[3] = PLCByteArr[6][3]; }
// 喇叭 4 if (PLCByteArr.length < 55) {
newMessage[4] = PLCByteArr[8][2]; return newMessage.join(",")
// 点火1 5 }
newMessage[5] = PLCByteArr[8][0]; console.log("heartMsgheartMsg1", PLCByteArr.toString());
// 点火2 6 // 左方向灯 2
newMessage[6] = PLCByteArr[8][1]; newMessage[2] = PLCByteArr[6][5];
// 近光灯 7 // 右方向灯 3 .
newMessage[7] = PLCByteArr[6][0]; newMessage[3] = PLCByteArr[6][4];
// 远光灯 8 // 喇叭 4
newMessage[8] = PLCByteArr[6][1]; newMessage[4] = PLCByteArr[8][4];
// 示廓灯 9 // 点火1 5
newMessage[9] = PLCByteArr[6][5]; newMessage[5] = PLCByteArr[8][7];
// 雾灯 10 // 点火2 6
// 雨刮器 11 newMessage[6] = PLCByteArr[8][6];
newMessage[11] = PLCByteArr[8][2]; // 近光灯 7
// 脚刹 12 newMessage[7] = PLCByteArr[6][7];
newMessage[12] = PLCByteArr[7][2]; // 远光灯 8
// 手刹 13 newMessage[8] = PLCByteArr[6][6];
newMessage[13] = PLCByteArr[7][3]; // 示廓灯 9
// 主驾驶门 14 newMessage[9] = PLCByteArr[6][2];
newMessage[14] = PLCByteArr[7][0]; // 雾灯 10
// NC 15 // 雨刮器 11
// TODO newMessage[11] = PLCByteArr[8][5];
// SA15 16 // 脚刹 12
// TODO newMessage[12] = PLCByteArr[7][5];
// 离合 17 // 手刹 13
newMessage[17] = PLCByteArr[7][1]; newMessage[13] = PLCByteArr[7][4];
// 副刹车 18 // 主驾驶门 14
newMessage[18] = PLCByteArr[7][4]; newMessage[14] = PLCByteArr[7][7];
// 安全带 19 // NC 15
newMessage[19] = PLCByteArr[7][7]; // TODO
// 双跳灯 20 // SA15 16
newMessage[20] = PLCByteArr[6][4]; // TODO
// 其他门 21 // 离合 17
// TODO newMessage[17] = PLCByteArr[7][6];
// 转速过高 22 // 副刹车 18
newMessage[22] = PLCByteArr[9][7]; newMessage[18] = PLCByteArr[7][3];
// 车速 23 // 安全带 19
newMessage[23] = PLCByteArr[11]; newMessage[19] = PLCByteArr[7][0];
// 累计脉冲 24 // 双跳灯 20
let Data25 = parseInt(PLCByteArr[25], 2); newMessage[20] = PLCByteArr[6][3];
let Data26 = parseInt(PLCByteArr[26], 2); // 其他门 21
let Data27 = parseInt(PLCByteArr[27], 2); // TODO
let Data28 = parseInt(PLCByteArr[28], 2); // 转速过高 22
newMessage[24] = ((Data25 << 24) + (Data26 << 16) + (Data27 << 8) + Data28).toString(); newMessage[22] = PLCByteArr[9][0];
// 发动机转速 25 // 车速 23
let Data29 = parseInt(PLCByteArr[29], 2); newMessage[23] = PLCByteArr[11];
let Data30 = parseInt(PLCByteArr[30], 2); // 累计脉冲 24
let Data31 = parseInt(PLCByteArr[31], 2); let Data25 = parseInt(PLCByteArr[25], 2);
let Data32 = parseInt(PLCByteArr[32], 2); let Data26 = parseInt(PLCByteArr[26], 2);
newMessage[25] = ((Data29 << 24) + (Data30 << 16) + (Data31 << 8) + Data32).toString(); let Data27 = parseInt(PLCByteArr[27], 2);
// 熄火次数 26 let Data28 = parseInt(PLCByteArr[28], 2);
newMessage[26] = PLCByteArr[33]; newMessage[24] = ((Data25 << 24) + (Data26 << 16) + (Data27 << 8) + Data28).toString();
// 方向盘角度 27 // 发动机转速 25
// 档位 28 let Data29 = parseInt(PLCByteArr[29], 2);
newMessage[27] = PLCByteArr[15]; let Data30 = parseInt(PLCByteArr[30], 2);
// 超声波1 29 let Data31 = parseInt(PLCByteArr[31], 2);
let Data52 = parseInt(PLCByteArr[52], 2); let Data32 = parseInt(PLCByteArr[32], 2);
let Data53 = parseInt(PLCByteArr[53], 2); newMessage[25] = ((Data29 << 24) + (Data30 << 16) + (Data31 << 8) + Data32).toString();
newMessage[29] = ((Data52 << 8) + Data53).toString(); // 熄火次数 26
// 超声波2 30 newMessage[26] = PLCByteArr[33];
let Data54 = parseInt(PLCByteArr[54], 2); // 方向盘角度 27
let Data55 = parseInt(PLCByteArr[55], 2); // 档位 28
newMessage[30] = ((Data54 << 8) + Data55).toString(); newMessage[27] = PLCByteArr[15];
// 超声波3 31 // 超声波1 29
// 超声波4 32 let Data52 = parseInt(PLCByteArr[52], 2);
// 触摸1 33 let Data53 = parseInt(PLCByteArr[53], 2);
// 触摸2 34 newMessage[29] = ((Data52 << 8) + Data53).toString();
// 触摸3 35 // 超声波2 30
// SCIO 36 let Data54 = parseInt(PLCByteArr[54], 2);
// SC1A_C 37 let Data55 = parseInt(PLCByteArr[55], 2);
// SC1B_C 38 newMessage[30] = ((Data54 << 8) + Data55).toString();
// SC2A_C 39 // 超声波3 31
// SC2B_C 40 // 超声波4 32
// SC3A_C 41 // 触摸1 33
// SC3B_C 42 // 触摸2 34
// SC4A_C 43 // 触摸3 35
// SC4B_C 44 // SCIO 36
// SC5A_C 45 // SC1A_C 37
// SC5B_C 46 // SC1B_C 38
// SC6A_C 47 // SC2A_C 39
// SC6B_C 48 // SC2B_C 40
// 发送次数 49 // SC3A_C 41
// 方向盘类型 50 // SC3B_C 42
// 汽车类型 51 // SC4A_C 43
// 接口心跳 52 // SC4B_C 44
// 本机IP 53 // SC5A_C 45
// 固件版本 54 // SC5B_C 46
// 按键数值 55 // SC6A_C 47
// GPS板卡类型 56 // SC6B_C 48
// GPS板卡软件版本 57 // 发送次数 49
// 改正数次数/改正数大小 58 // 方向盘类型 50
// GPS数据次数/数据长度 59 // 汽车类型 51
// GPS错误次数 60 // 接口心跳 52
// 已工作时长/设定的工作时长 61 // 本机IP 53
// 改正数数据长度*数据长度-基准站RTCM改正数类型 62 // 固件版本 54
// 按键数值 55
// GPS板卡类型 56
// GPS板卡软件版本 57
// 改正数次数/改正数大小 58
// GPS数据次数/数据长度 59
// GPS错误次数 60
// 已工作时长/设定的工作时长 61
// 改正数数据长度*数据长度-基准站RTCM改正数类型 62
}
console.log('heartMsgend', newMessage.join(",")) console.log('heartMsgend', newMessage.join(","))
return newMessage.join(",") return newMessage.join(",")

View File

@ -303,7 +303,7 @@ export default class UdpClientByCenter {
onMessage_1(callback?) { onMessage_1(callback?) {
this.onMessage_1Callback = callback; this.onMessage_1Callback = callback;
this.UPDOne.receiveMsg(callback); this.UPDOne.receiveMsg(callback);
this.udp && this.udp.on('message', this.message_1Fn); // this.udp && this.udp.on('message', this.message_1Fn);
} }

View File

@ -1,11 +1,9 @@
import TopLogo from './compontents/TopLogo' import TopLogo from './compontents/TopLogo'
import { registrationDeviceNo } from '../api/checkCar' import { registrationDeviceNo } from '../api/checkCar'
import { dateFormat } from '../common/utils/tools' import { dateFormat } from '../common/utils/tools'
import deviceManager from '@ohos.distributedHardware.deviceManager'
import { upDateTableByArray } from '../common/service/initable'
import promptAction from '@ohos.promptAction' import promptAction from '@ohos.promptAction'
import FileUtil from '../common/utils/File' import FileUtil from '../common/utils/File'
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common'
@Entry @Entry
@Component @Component
@ -24,7 +22,8 @@ export default struct Index {
onPageShow() { onPageShow() {
// this.plateNo=globalThis.carInfo.plateNo // this.plateNo=globalThis.carInfo.plateNo
console.log('createDeviceManagerstart') console.log('createDeviceManagerstart')
try{ try {
// @ts-ignore
deviceManager.createDeviceManager('com.oh.dts', (error, value) => { deviceManager.createDeviceManager('com.oh.dts', (error, value) => {
if (error) { if (error) {
console.error('createDeviceManager failed.'); console.error('createDeviceManager failed.');
@ -37,8 +36,8 @@ export default struct Index {
globalThis.deviceNo = 'MAC-' + this.deviceNo globalThis.deviceNo = 'MAC-' + this.deviceNo
}); });
}catch (error){ } catch (error) {
console.log('createDeviceManagererror',error) console.log('createDeviceManagererror', error)
} }
} }
@ -125,7 +124,7 @@ export default struct Index {
const folderPath = await fileUtil.initFolder(`/config`); const folderPath = await fileUtil.initFolder(`/config`);
fileUtil.addFile(`${folderPath}/deviceNo.txt`, JSON.stringify(param)) fileUtil.addFile(`${folderPath}/deviceNo.txt`, JSON.stringify(param))
globalThis.deviceNo = this.ip globalThis.deviceNo = this.ip
console.log('globalThis.deviceNo',globalThis.deviceNo) console.log('globalThis.deviceNo', globalThis.deviceNo)
// upDateTableByArray('DeviceInfoTable', [{ deviceId: this.ip }]) // upDateTableByArray('DeviceInfoTable', [{ deviceId: this.ip }])
registrationDeviceNo(param).then(res => { registrationDeviceNo(param).then(res => {
// @ts-ignore // @ts-ignore

View File

@ -1,9 +1,5 @@
import TopLogo from './compontents/TopLogo';
import TopLogo from './compontents/TopLogo' import prompt from '@ohos.prompt';
import ethernet from '@ohos.net.ethernet';
import prompt from '@ohos.prompt'
import { upDateTableByArray} from '../common/service/initable'
import { getSyncData} from '../common/service/initable'
import FileUtil from '../common/utils/File'; import FileUtil from '../common/utils/File';
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
import { GlobalConfig } from '../config'; import { GlobalConfig } from '../config';
@ -12,59 +8,60 @@ import { GlobalConfig } from '../config';
@Entry @Entry
@Component @Component
struct Index { struct Index {
@State textList1: string[] = ['差分服务器Ip', '响应端口', '中心服务器IP', '响应端口', '子网掩码', '默认网关', 'dns', '后置机IP ', '响应端口', '前置机IP', '本地端口']
@State textList1: string[] = ['差分服务器Ip','响应端口','中心服务器IP','响应端口', '子网掩码','默认网关','dns','后置机IP ', '响应端口','前置机IP','本地端口']
// @State textList2: string[] = [] // @State textList2: string[] = []
@State ratio: number = 1700 / 960 @State ratio: number = 1700 / 960
@State inputFontSize:number=12 //12 @State inputFontSize: number = 12 //12
// //
// @State inputTextList1: string[] = ['192.168.7.170','8084','192.168.7.170','20122','255.255.255.0','192.168.7.1','','','114.114.114.114','112.80.35.83','11055' + // @State inputTextList1: string[] = ['192.168.7.170','8084','192.168.7.170','20122','255.255.255.0','192.168.7.1','','','114.114.114.114','112.80.35.83','11055' +
// '',] // '',]
// @State inputTextList2: string[] = ['192.168.7.124','20022'] // @State inputTextList2: string[] = ['192.168.7.124','20022']
// @State inputTextList1: string[] = ['172.37.55.191','18782','192.168.7.1','8082','255.255.255.0','192.168.7.170','114.114.114.114','192.168.7.124','20022','172.37.55.59','20122'] // @State inputTextList1: string[] = ['172.37.55.191','18782','192.168.7.1','8082','255.255.255.0','192.168.7.170','114.114.114.114','192.168.7.124','20022','172.37.55.59','20122']
@State inputTextList1: string[] = ['172.37.55.191','18782','172.37.55.191','8082','255.255.255.0','192.168.7.1','114.114.114.114','192.168.7.124','20022','192.168.7.170','20122'] @State inputTextList1: string[] = ['172.37.55.191', '18782', '172.37.55.191', '8082', '255.255.255.0', '192.168.7.1', '114.114.114.114', '192.168.7.124', '20022', '192.168.7.170', '20122']
// @State inputTextList2: string[] = [] // @State inputTextList2: string[] = []
// 112.80.35.83 11052 // 112.80.35.83 11052
// @State inputTextList1: string[] = ['192.168.36.2','8084','192.168.36.200','20122','255.255.255.0','192.168.36.1','','','114.114.114.114','192.168.36.139','8000'] // @State inputTextList1: string[] = ['192.168.36.2','8084','192.168.36.200','20122','255.255.255.0','192.168.36.1','','','114.114.114.114','192.168.36.139','8000']
@State @Watch('outClick') outFlag: boolean = false;
scroller: Scroller = new Scroller()
// @State inputTextList2: string[] = ['192.168.36.139','20022'] // @State inputTextList2: string[] = ['192.168.36.139','20022']
private fileUtil: FileUtil private fileUtil: FileUtil
private context = getContext(this) as common.UIAbilityContext; private context = getContext(this) as common.UIAbilityContext;
private vocObj = null;
@State @Watch('outClick') outFlag: boolean = false; private vocObj = null;
scroller: Scroller = new Scroller()
build() { build() {
Column() { Column() {
TopLogo({outFlag:$outFlag}) TopLogo({ outFlag: $outFlag })
Column() { Column() {
Column() { Column() {
Scroll(this.scroller){ Scroll(this.scroller) {
Flex({'wrap':FlexWrap.Wrap}) { Flex({ 'wrap': FlexWrap.Wrap }) {
ForEach(this.textList1, (item:string, index:number) => { ForEach(this.textList1, (item: string, index: number) => {
Row() { Row() {
Text(item) Text(item)
.width('40%') .width('40%')
.height('100%') .height('100%')
.fontColor('#E5CBA1') .fontColor('#E5CBA1')
.padding({'left': '35px'}) .padding({ 'left': '35px' })
.fontSize(this.inputFontSize*this.ratio) .fontSize(this.inputFontSize * this.ratio)
TextInput({'text':this.inputTextList1[index]?this.inputTextList1[index]: ''}) TextInput({ 'text': this.inputTextList1[index] ? this.inputTextList1[index] : '' })
.width('50%') .width('50%')
.height('60%') .height('60%')
.fontColor('#fff') .fontColor('#fff')
.borderColor('#E6E0D8') .borderColor('#E6E0D8')
.borderRadius('10px') .borderRadius('10px')
.borderWidth('2px') .borderWidth('2px')
.fontSize(this.inputFontSize*this.ratio) .fontSize(this.inputFontSize * this.ratio)
.padding({top:0,bottom:0}) .padding({ top: 0, bottom: 0 })
.linearGradient({ .linearGradient({
angle: 0, angle: 0,
colors: [[0x403C36, 0.0], [0x4D473D, 0.34], [0x3D3A34, 1.0]] colors: [[0x403C36, 0.0], [0x4D473D, 0.34], [0x3D3A34, 1.0]]
}).onChange((value: string) => { })
this.inputTextList1[index]=value .onChange((value: string) => {
this.inputTextList1[index] = value
}) })
} }
.width('50%') .width('50%')
.height('16.7%') .height('16.7%')
@ -74,33 +71,49 @@ struct Index {
} }
.width('95%') .width('95%')
.height('90%') .height('90%')
.margin({'top': '2%'}) .margin({ 'top': '2%' })
.backgroundColor('#282828') .backgroundColor('#282828')
.borderRadius('15px') .borderRadius('15px')
} }
.width('100%') .width('100%')
.height('80%') .height('80%')
.borderRadius('25px') .borderRadius('25px')
Column() { Column() {
Image($r('app.media.terminal_save')).width('20.5%').height('74%').onClick(async ()=>{ Image($r('app.media.terminal_save')).width('20.5%').height('74%').onClick(async () => {
const fileUtil = new FileUtil(this.context) const fileUtil = new FileUtil(this.context)
const folderPath = await fileUtil.initFolder(`/config`); const folderPath = await fileUtil.initFolder(`/config`);
const param={udplocalIp:this.inputTextList1[9],udplocalIpPort:this.inputTextList1[10],udpOppositeIp:this.inputTextList1[7],udpOppositeIpPort:this.inputTextList1[8],tcplocalIp:this.inputTextList1[9],tcplocalIpPort:'8088',tcpOppositeIp:this.inputTextList1[0],tcpOppositePort:this.inputTextList1[1],netMask:this.inputTextList1[4],gateway:this.inputTextList1[5],dnsServers:this.inputTextList1[6],centerIp:this.inputTextList1[2],centerPort:this.inputTextList1[3]} const param = {
fileUtil.addFile(`${folderPath}/ipConfig.txt`, JSON.stringify(param),'') udplocalIp: this.inputTextList1[9],
udplocalIpPort: this.inputTextList1[10],
udpOppositeIp: this.inputTextList1[7],
udpOppositeIpPort: this.inputTextList1[8],
tcplocalIp: this.inputTextList1[9],
tcplocalIpPort: '8088',
tcpOppositeIp: this.inputTextList1[0],
tcpOppositePort: this.inputTextList1[1],
netMask: this.inputTextList1[4],
gateway: this.inputTextList1[5],
dnsServers: this.inputTextList1[6],
centerIp: this.inputTextList1[2],
centerPort: this.inputTextList1[3]
}
fileUtil.addFile(`${folderPath}/ipConfig.txt`, JSON.stringify(param), '')
// upDateTableByArray('IpConfigTable',[]) // upDateTableByArray('IpConfigTable',[])
// @ts-ignore
ethernet.setIfaceConfig("eth0", { ethernet.setIfaceConfig("eth0", {
mode: 0, mode: 0,
ipAddr:this.inputTextList1[9], ipAddr: this.inputTextList1[9],
route: "0.0.0.0", route: "0.0.0.0",
gateway: this.inputTextList1[5],//value.gateway网关 gateway: this.inputTextList1[5], //value.gateway网关
netMask: this.inputTextList1[4],//value.netMask网络掩码 netMask: this.inputTextList1[4], //value.netMask网络掩码
dnsServers: this.inputTextList1[6], dnsServers: this.inputTextList1[6],
// @ts-ignore // @ts-ignore
domain: "" domain: ""
}, (error) => { }, (error) => {
if (error) { if (error) {
prompt.showToast({ prompt.showToast({
message: '设置失败'+JSON.stringify(error), message: '设置失败' + JSON.stringify(error),
duration: 3000 duration: 3000
}); });
} else { } else {
@ -116,20 +129,20 @@ struct Index {
.backgroundColor('#CCC4B8') .backgroundColor('#CCC4B8')
.width('100%') .width('100%')
.height('20%') .height('20%')
.borderRadius({'bottomLeft':'25px','bottomRight':'25px'}) .borderRadius({ 'bottomLeft': '25px', 'bottomRight': '25px' })
.justifyContent(FlexAlign.SpaceAround) .justifyContent(FlexAlign.SpaceAround)
} }
.width('75%') .width('75%')
.height('69.4%') .height('69.4%')
.backgroundColor('#E6E3DF') .backgroundColor('#E6E3DF')
.borderRadius('25px') .borderRadius('25px')
.margin({'top':'7%'}) .margin({ 'top': '7%' })
.justifyContent(FlexAlign.SpaceAround) .justifyContent(FlexAlign.SpaceAround)
} }
.width('100%') .width('100%')
.height('100%') .height('100%')
.backgroundImagePosition({x: 0, y: 0}) .backgroundImagePosition({ x: 0, y: 0 })
.backgroundImage($r('app.media.index_bg')) .backgroundImage($r('app.media.index_bg'))
.backgroundImageSize({ width: '100%', height: '100%' }) .backgroundImageSize({ width: '100%', height: '100%' })
} }
@ -138,26 +151,26 @@ struct Index {
const fileUtil = new FileUtil(this.context) const fileUtil = new FileUtil(this.context)
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt'); const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
if (data === '' || data === undefined) { if (data === '' || data === undefined) {
}else{ } else {
const result=JSON.parse(data) const result = JSON.parse(data)
console.log('tagtag',JSON.stringify(result)) console.log('tagtag', JSON.stringify(result))
this.inputTextList1[9]=result.udplocalIp this.inputTextList1[9] = result.udplocalIp
this.inputTextList1[10]=result.udplocalIpPort this.inputTextList1[10] = result.udplocalIpPort
this.inputTextList1[7]=result.udpOppositeIp this.inputTextList1[7] = result.udpOppositeIp
this.inputTextList1[8]=result.udpOppositeIpPort this.inputTextList1[8] = result.udpOppositeIpPort
// this.inputTextList1[0]=result[0].tcplocalIp // this.inputTextList1[0]=result[0].tcplocalIp
// this.inputTextList1[13]=result[0].tcplocalIpPort // this.inputTextList1[13]=result[0].tcplocalIpPort
this.inputTextList1[0]=result.tcpOppositeIp this.inputTextList1[0] = result.tcpOppositeIp
this.inputTextList1[1]=result.tcpOppositePort this.inputTextList1[1] = result.tcpOppositePort
this.inputTextList1[5]=result.gateway this.inputTextList1[5] = result.gateway
this.inputTextList1[4]=result.netMask this.inputTextList1[4] = result.netMask
this.inputTextList1[6]=result.dnsServers this.inputTextList1[6] = result.dnsServers
this.inputTextList1[2]=result.centerIp this.inputTextList1[2] = result.centerIp
this.inputTextList1[3]=result.centerPort this.inputTextList1[3] = result.centerPort
} }
//@ts-ignore
ethernet.getIfaceConfig("eth0", (error, value) => { ethernet.getIfaceConfig("eth0", (error, value) => {
if (error) { if (error) {
// that.errorMsg='error' // that.errorMsg='error'
@ -173,10 +186,12 @@ struct Index {
}) })
} }
onPageShow() { onPageShow() {
console.info('Index onPageShow'); console.info('Index onPageShow');
} }
outClick(){
outClick() {
} }
} }