fix: 一代机

This commit is contained in:
wangzhongjie 2025-02-21 15:22:23 +08:00
parent 95a53a04e0
commit 912f5636db
6 changed files with 383 additions and 382 deletions

View File

@ -1,190 +1,137 @@
import Want from '@ohos.app.ability.Want'
import promptAction from '@ohos.promptAction'
import fileAccess from '@ohos.file.fileAccess'
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl'
import common from '@ohos.app.ability.common'
import fs from '@ohos.file.fs'
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
*
*/
public addFile = async (filePath:string,content:string,type?:string)=>{
const { READ_WRITE,CREATE,APPEND }= fs.OpenMode
public addFile = async (filePath: string, content: string, type?: string) => {
const { READ_WRITE,CREATE,APPEND } = fs.OpenMode
const isExit = fs.accessSync(filePath);
//文件存在先删除
if(isExit){
if (isExit) {
fs.unlinkSync(filePath);
}
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)
console.error(LOGTAG,'写入文件成功')
console.error(LOGTAG, '写入文件成功')
return true
}catch (e){
} catch (e) {
promptAction.showToast({
message:`addFile文件失败`+ filePath +JSON.stringify(e),
duration:4000,
message: `addFile文件失败` + filePath + JSON.stringify(e),
duration: 4000,
})
console.error(LOGTAG,'写入失败',JSON.stringify(e))
console.error(LOGTAG, '写入失败', JSON.stringify(e))
}
}
/*
* @desc
*
*/
public editFile = async (filePath:string,content:string,fd?:number)=>{
public editFile = async (filePath: string, content: string, fd?: number) => {
const {filePathFdObj} = this;
const { READ_WRITE,CREATE,APPEND }= fs.OpenMode
const newStr = content + '\n'
const { READ_WRITE,CREATE,APPEND } = fs.OpenMode
const newStr = content + '\n'
const thisFile = filePathFdObj[filePath];
try {
if(thisFile){
fs.writeSync(thisFile.fd,newStr)
if (thisFile) {
fs.writeSync(thisFile.fd, newStr)
return fd;
}else{
let file = fs.openSync(filePath, READ_WRITE | APPEND |CREATE);
fs.writeSync(file.fd,newStr)
} else {
let file = fs.openSync(filePath, READ_WRITE | APPEND | CREATE);
fs.writeSync(file.fd, newStr)
this.filePathFdObj[filePath] = file
return file.fd
}
} catch (e) {
promptAction.showToast({
message:`editFile文件失败`+ filePath +JSON.stringify(e),
duration:4000,
message: `editFile文件失败` + filePath + JSON.stringify(e),
duration: 4000,
})
console.error(LOGTAG,JSON.stringify(e))
console.error(LOGTAG, JSON.stringify(e))
}
}
/*
* @desc
*
*/
public closeFile = async (filePath:string)=>{
public closeFile = async (filePath: string) => {
const {filePathFdObj} = this;
const thisFile = filePathFdObj[filePath];
if(thisFile){
if (thisFile) {
fs.closeSync(thisFile);
console.info(LOGTAG,filePath + '文件关闭成功')
console.info(LOGTAG, filePath + '文件关闭成功')
}
}
/*
* @desc
*
**/
public readFile = async (filePath:string) => {
try{
console.log('strrr',filePath)
public readFile = async (filePath: string) => {
try {
console.log('strrr', filePath)
const str = await fs.readText(filePath);
return str
}catch (e){
} catch (e) {
promptAction.showToast({
message:`读取文件失败`+ filePath +JSON.stringify(e),
duration:4000,
message: `读取文件失败` + filePath + JSON.stringify(e),
duration: 4000,
})
console.log('readFile文件失败'+ filePath +JSON.stringify(e))
console.log('readFile文件失败' + filePath + JSON.stringify(e))
return ''
}
}
/*
* @desc获取系统目录里的文件列表
*/
public getDeviceList = async (folderPath?:string)=>{
public getDeviceList = async (folderPath?: string) => {
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 = [];
// 删除文件夹或者文件
/*
* @desc
* @param{{type}} 1:文件夹 2 3
**/
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
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));
}
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 () => {
//@ts-ignore
this.wantInfos = await fileAccess.getFileAccessAbilityInfo();
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;
let isDone = false;
@ -200,52 +147,29 @@ export default class FileUtil{
if (!isDone) {
let deviceType = rootInfo.value.deviceType;
let displayName = rootInfo.value.displayName;
let uri:string = rootInfo.value.uri;
let uri: string = rootInfo.value.uri;
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){
this.destFile = uri.split('ExternalFileManager')[1]+'/'
console.error(LOGTAG,`外置存储路径:`+this.destFile);
this.getFilePathList(this.destFile,true)
this.destFile = uri.split('ExternalFileManager')[1] + '/'
console.error(LOGTAG, `外置存储路径:` + this.destFile);
this.getFilePathList(this.destFile, true)
}
}
}
} 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
const path = `${absolutePath}/${filePath}`
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));
}
}
// 删除文件夹或者文件
/*
* @desc
* @param{{type}} 1:文件夹 2 3
**/
// 文件系统初始化
private requestPermission = async () => {
const {context,absolutePath} = this;
@ -253,19 +177,87 @@ export default class FileUtil{
'ohos.permission.READ_MEDIA',
'ohos.permission.WRITE_MEDIA'
];
// @ts-ignore
this.wantInfos = await fileAccess.getFileAccessAbilityInfo();
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]
if(permissionRequest == -1){
if (permissionRequest == -1) {
promptAction.showToast({
message: "请先授权",
duration:3000,
duration: 3000,
})
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) {
console.log(tag, 'send', message)
}
this.fileUtil.addFile(this.path + 'temp.txt', `^#${message}#$`)
this.socket.send({
data: `^#${message}#$`
}).then(() => {

View File

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

View File

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

View File

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