dev #65
@ -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);
|
||||
//追加写入文件
|
||||
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 { 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
|
||||
}
|
||||
|
||||
if(type === 2){
|
||||
fs.unlinkSync(`${absolutePath}/${path}`);
|
||||
return true
|
||||
}
|
||||
if(type === 3){
|
||||
fs.unlinkSync(`${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])
|
||||
}
|
||||
}
|
||||
|
||||
// 获取系统文件绝对路径
|
||||
public getAbsolutePath = () =>{
|
||||
const {absolutePath} = this;
|
||||
return absolutePath
|
||||
return isSdcard ? sdCardFileName : fileName
|
||||
} catch (e) {
|
||||
console.error(LOGTAG, JSON.stringify(e));
|
||||
}
|
||||
|
||||
}
|
||||
// 检索文件列表
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ export default class GetDistance {
|
||||
const {fileUtil} = this
|
||||
const time = await getCurrentTime()
|
||||
const folderPath = await fileUtil.initFolder(`/车辆行驶距离统计`);
|
||||
console.info('surenjun folderPath=>' ,folderPath);
|
||||
// console.info('surenjun folderPath=>' ,folderPath);
|
||||
const date = time.split(' ')[0].split('-').join('_')
|
||||
const timeStr = time.split(' ')[1]
|
||||
this.timeStr = timeStr
|
||||
@ -41,15 +41,15 @@ export default class GetDistance {
|
||||
// 过程文件数据
|
||||
public setTimeData = async (str:number) => {
|
||||
const {fileUtil,folderPath,timeStr,date,totalDistance} = this;
|
||||
console.log('folderPath',folderPath)
|
||||
// console.log('folderPath',folderPath)
|
||||
const content = await fileUtil.readFile(`${folderPath}/${date}.txt`) || '';
|
||||
const contentArr = content.split('\n').filter(item => item)
|
||||
console.info('surenjun contentArr',JSON.stringify(contentArr))
|
||||
// console.info('surenjun contentArr',JSON.stringify(contentArr))
|
||||
this.totalDistance += (str * 1 > 200 ? 200 : str*1)
|
||||
this.totalTime += 1;
|
||||
contentArr[contentArr.length - 1] = `程序启动时间:${timeStr} 累计行驶距离:${(this.totalDistance).toFixed(2)}m 累计运行时常:${Math.ceil(this.totalTime/60)}min`+ '\n'
|
||||
console.info('surenjun',contentArr.join('\n'))
|
||||
console.log('folderPath',folderPath,date)
|
||||
// console.log('folderPath',folderPath,date)
|
||||
this.uploadData()
|
||||
|
||||
// await fileUtil.addFile(
|
||||
|
||||
@ -3,10 +3,14 @@ import { getSyncData } from '../service/initable';
|
||||
import hilog from '@ohos.hilog';
|
||||
import FileUtil from '../../common/utils/File'
|
||||
import { GlobalConfig } from '../../config/index'
|
||||
import GpsTcpClient from './GpsTcpClient'
|
||||
|
||||
export async function getTCP(flag=false) {
|
||||
globalThis.getCloseTcp=true
|
||||
const fileUtil = new FileUtil(globalThis.context)
|
||||
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
|
||||
|
||||
const gpsTcpClient = new GpsTcpClient()
|
||||
if (data === '' || data === undefined) {
|
||||
globalThis.TcpClient = {}
|
||||
globalThis.TcpClient.onMessage = () => {
|
||||
@ -44,7 +48,7 @@ export async function getTCP(flag=false) {
|
||||
if (val) {
|
||||
// const msg=val.substring(5,val.length-1)
|
||||
console.log('socketTag[PLC.UdpClient] status:', globalThis.udpClient.getStatus())
|
||||
globalThis.udpClient?.sendMsg(val)
|
||||
gpsTcpClient.sendGpsMsg(val)
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
@ -77,7 +81,7 @@ export async function getTCP(flag=false) {
|
||||
await globalThis.TcpClient.onMessage((val) => {
|
||||
setTimeout(() => {
|
||||
if (val && globalThis.udpClient?.sendMsg) {
|
||||
globalThis.udpClient?.sendMsg(val)
|
||||
gpsTcpClient.sendGpsMsg(val)
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
|
||||
53
entry/src/main/ets/common/utils/GpsTcpClient.ts
Normal file
53
entry/src/main/ets/common/utils/GpsTcpClient.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import FileUtil from '../../common/utils/File';
|
||||
import { GlobalConfig } from '../../config/index';
|
||||
import socket from '@ohos.net.socket';
|
||||
|
||||
const TAG = '[GpsTcpClient]'
|
||||
export default class GpsTcpClient{
|
||||
|
||||
private LocalIp: string
|
||||
private tcp: socket.TCPSocket
|
||||
constructor() {
|
||||
this.init()
|
||||
|
||||
}
|
||||
|
||||
async init(){
|
||||
const fileUtil = new FileUtil(globalThis.context)
|
||||
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
|
||||
const result = JSON.parse(data)
|
||||
this.LocalIp = result.udplocalIp;
|
||||
this.tcp = socket.constructTCPSocketInstance();
|
||||
|
||||
await this.tcp.bind({
|
||||
address: this.LocalIp,
|
||||
port:31015,
|
||||
family: 1
|
||||
});
|
||||
|
||||
try {
|
||||
const res = await this.tcp.connect({
|
||||
address:{
|
||||
address: '192.168.7.100',
|
||||
port:30015
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(TAG +'connect error',JSON.stringify(e))
|
||||
}
|
||||
|
||||
this.tcp.on('error', (data) => {
|
||||
console.log(TAG + 'on error',JSON.stringify(data))
|
||||
this.init()
|
||||
})
|
||||
}
|
||||
|
||||
public async sendGpsMsg(data:ArrayBuffer){
|
||||
try {
|
||||
await this.tcp.send({data})
|
||||
} catch (e) {
|
||||
console.log(TAG + 'send error',JSON.stringify(e))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -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(() => {
|
||||
|
||||
@ -1,121 +1,144 @@
|
||||
import socket from '@ohos.net.socket';
|
||||
import { PLCGPSData } from '../../mock';
|
||||
import { PLCGPSData } from '../../mock/PLCGPSData';
|
||||
import FileUtil from '../../common/utils/File';
|
||||
import { GlobalConfig } from '../../config/index';
|
||||
|
||||
// import { PLCGPSData } from '../../mock';
|
||||
|
||||
export default class UdpByOne {
|
||||
// PLC udp
|
||||
private PLCUDP: any;
|
||||
// PLC localIp
|
||||
private PLCLocalIp: string='192.168.7.170';
|
||||
private LocalIp: string = '192.168.7.170';
|
||||
// PLC localIpPort
|
||||
private PLCLocalIpPort: string='31012';
|
||||
private PLCLocalIpPort: string = '31012';
|
||||
private OppositeIp: string = '192.168.7.124'
|
||||
// PLC oppositeIpPort
|
||||
private PLCOppositeIpPort: string='30012';
|
||||
private PLCOppositeIpPort: string = '30012';
|
||||
// PLC消息
|
||||
private PLCMsg: number[];
|
||||
private PLCMsg: ArrayBuffer;
|
||||
// GPS udp
|
||||
private GPSUDP: any;
|
||||
// GPS localIp
|
||||
private GPSLocalIp: string='192.168.7.124';
|
||||
// GPS localIpPort
|
||||
private GPSLocalIpPort: string='30013';
|
||||
private GPSLocalIpPort: string = '31013';
|
||||
// GPS oppositeIpPort
|
||||
private GPSOppositeIpPort: string;
|
||||
private GPSOppositeIpPort: string = '30013';
|
||||
// GPS消息
|
||||
private GPSMsg: string;
|
||||
private GPSMsg: any;
|
||||
|
||||
constructor() {
|
||||
this.init()
|
||||
}
|
||||
|
||||
async init(){
|
||||
const fileUtil = new FileUtil(globalThis.context)
|
||||
const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt');
|
||||
const result = JSON.parse(data)
|
||||
this.LocalIp = result.udplocalIp;
|
||||
this.OppositeIp = result.udpOppositeIp;
|
||||
|
||||
// 初始化UDP
|
||||
this.PLCUDP = socket.constructUDPSocketInstance();
|
||||
// this.PLCUDP.bind(this.PLCLocalIp, this.PLCLocalIpPort);
|
||||
this.PLCUDP.bind({
|
||||
// address: '192.168.7.170', port: 20122, family: 1
|
||||
address: this.PLCLocalIp, port: parseInt(this.PLCLocalIpPort), family: 1
|
||||
address: this.LocalIp, port: parseInt(this.PLCLocalIpPort), family: 1
|
||||
});
|
||||
// this.GPSUDP = socket.constructUDPSocketInstance();
|
||||
this.GPSUDP = socket.constructUDPSocketInstance();
|
||||
// this.GPSUDP.bind(this.GPSLocalIp, this.GPSLocalIpPort);
|
||||
this.GPSUDP.bind({
|
||||
address: this.LocalIp, port: parseInt(this.GPSLocalIpPort), family: 1
|
||||
});
|
||||
}
|
||||
|
||||
// 重新绑定
|
||||
public rebind() {
|
||||
this.PLCUDP.bind(this.PLCLocalIp, this.PLCLocalIpPort);
|
||||
this.GPSUDP.bind(this.GPSLocalIp, this.GPSLocalIpPort);
|
||||
this.PLCUDP.bind(this.LocalIp, this.PLCLocalIpPort);
|
||||
this.GPSUDP.bind(this.LocalIp, this.GPSLocalIpPort);
|
||||
}
|
||||
|
||||
// PLC发送消息
|
||||
public sendPLCMsg(msg: string) {
|
||||
this.PLCUDP.send({
|
||||
data: '111111',
|
||||
address: {
|
||||
address: '192.168.7.124',
|
||||
port: parseInt(this.PLCOppositeIpPort),
|
||||
}
|
||||
})
|
||||
// this.PLCUDP.sendTo(msg, this.PLCOppositeIpPort);
|
||||
// this.PLCUDP.send({
|
||||
// data: '111111',
|
||||
// address: {
|
||||
// address: this.OppositeIp,
|
||||
// port: parseInt(this.PLCOppositeIpPort),
|
||||
// }
|
||||
// })
|
||||
}
|
||||
|
||||
// GPS发送消息
|
||||
public sendGPSMsg(msg: string) {
|
||||
this.GPSUDP.sendTo(msg, this.GPSOppositeIpPort);
|
||||
// this.GPSUDP.send({
|
||||
// data: '111111',
|
||||
// address: {
|
||||
// address: this.OppositeIp,
|
||||
// port: parseInt(this.GPSOppositeIpPort),
|
||||
// }
|
||||
// })
|
||||
|
||||
}
|
||||
|
||||
// 接受消息
|
||||
public receiveMsg(callback) {
|
||||
console.log('heartMsg','getCallback')
|
||||
console.log('heartMsg', 'getCallback')
|
||||
this.sendPLCMsg('1111')
|
||||
this.PLCUDP.on("message", (message2, remoteInfo) => {
|
||||
console.log('heartMsg','getPlc')
|
||||
|
||||
this.PLCMsg = message2;
|
||||
this.sendGPSMsg('1111')
|
||||
this.PLCUDP.on("message", (res, remoteInfo) => {
|
||||
console.log('heartMsg', 'getPlc')
|
||||
console.log('heartMsg', 'getGps')
|
||||
this.PLCMsg = res.message;
|
||||
// 组合数据
|
||||
let newMessage = this.handleMsg()
|
||||
callback(newMessage)
|
||||
})
|
||||
this.GPSUDP.on("message", (res1, remoteInfo) => {
|
||||
console.log('heartMsg', 'getGps')
|
||||
let dataView = new DataView(res1.message)
|
||||
let str = ""
|
||||
for (let i = 0; i < dataView?.byteLength; ++i) {
|
||||
let c = String.fromCharCode(dataView?.getUint8(i))
|
||||
if (c !== "\n") {
|
||||
str += c
|
||||
}
|
||||
}
|
||||
this.GPSMsg = str;
|
||||
if(str.length < 10){
|
||||
return
|
||||
this.GPSUDP.on("message", (message1, remoteInfo) => {
|
||||
console.log('heartMsg','GPSUDP')
|
||||
this.GPSMsg = message1;
|
||||
this.PLCUDP.on("message", (message2, remoteInfo) => {
|
||||
this.PLCMsg = message2;
|
||||
// 组合数据
|
||||
}
|
||||
let newMessage = this.handleMsg()
|
||||
callback(newMessage)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 处理消息
|
||||
public handleMsg() {
|
||||
// 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 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`;
|
||||
console.log('heartMsg000', PLCGPSData)
|
||||
if (this.GPSMsg) {
|
||||
// 使用正则表达式提取$GPGGA消息
|
||||
let GPGGAMsg = this.GPSMsg.match(/\$GPGGA[^$]*/)[0];
|
||||
let GPGGAMsgArr = GPGGAMsg.split(",").slice(0, 15);
|
||||
let GPGGAMsgArr = GPGGAMsg ? 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);
|
||||
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);
|
||||
let PTNLMsgArr = PTNLMsg.split(",")?.slice(0, 14);
|
||||
|
||||
// 组合GPS数据
|
||||
// 状态83
|
||||
newMessage[83] = GPRMCMsgArr[6];
|
||||
newMessage[83] = GPGGAMsgArr[6];
|
||||
// 收星数84
|
||||
newMessage[84] = PTNLMsgArr[10];
|
||||
newMessage[84] = GPGGAMsgArr[7];
|
||||
// 海拔高85
|
||||
newMessage[80] = GPGGAMsgArr[9];
|
||||
// 高度差86
|
||||
// 龄期87
|
||||
newMessage[87] = GPGSTMsgArr[11];
|
||||
newMessage[87] = GPGGAMsgArr[13];
|
||||
// 维度因子88
|
||||
// 经度因子89
|
||||
// 航向角90
|
||||
@ -123,12 +146,10 @@ export default class UdpByOne {
|
||||
// 俯仰角91
|
||||
newMessage[91] = PTNLMsgArr[5];
|
||||
// 航向角状态-收星数92
|
||||
newMessage[92] = PTNLMsgArr[8];
|
||||
newMessage[92] = PTNLMsgArr[10] + '-' + PTNLMsgArr[12].split('*')[0];
|
||||
// 年月日93 RMCMsgArr[9]为ddmmyy 日月年 转换为年月日
|
||||
newMessage[93] =
|
||||
GPRMCMsgArr[9].slice(4, 6) +
|
||||
GPRMCMsgArr[9].slice(2, 4) +
|
||||
GPRMCMsgArr[9].slice(0, 2);
|
||||
GPRMCMsgArr[9].slice(0, 2) + GPRMCMsgArr[9].slice(2, 4) + GPRMCMsgArr[9].slice(4, 6);
|
||||
// 时分秒94 GPGGAMsgArr[1]为021126.00去掉小数点后的时间
|
||||
newMessage[94] = GPGGAMsgArr[1].replace(".", "");
|
||||
// 经度95
|
||||
@ -137,52 +158,61 @@ export default class UdpByOne {
|
||||
newMessage[96] = GPGGAMsgArr[2];
|
||||
// 速度97
|
||||
newMessage[97] = GPRMCMsgArr[7];
|
||||
|
||||
let PLCByteArr = this.PLCMsg.map((num) => num.toString(2).padStart(8, "0"));
|
||||
console.log(PLCByteArr[1][2]);
|
||||
}
|
||||
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][2];
|
||||
// 右方向灯 3
|
||||
newMessage[3] = PLCByteArr[6][3];
|
||||
newMessage[2] = PLCByteArr[6][5];
|
||||
// 右方向灯 3 .
|
||||
newMessage[3] = PLCByteArr[6][4];
|
||||
// 喇叭 4
|
||||
newMessage[4] = PLCByteArr[8][2];
|
||||
newMessage[4] = PLCByteArr[8][4];
|
||||
// 点火1 5
|
||||
newMessage[5] = PLCByteArr[8][0];
|
||||
newMessage[5] = PLCByteArr[8][7];
|
||||
// 点火2 6
|
||||
newMessage[6] = PLCByteArr[8][1];
|
||||
newMessage[6] = PLCByteArr[8][6];
|
||||
// 近光灯 7
|
||||
newMessage[7] = PLCByteArr[6][0];
|
||||
newMessage[7] = PLCByteArr[6][7];
|
||||
// 远光灯 8
|
||||
newMessage[8] = PLCByteArr[6][1];
|
||||
newMessage[8] = PLCByteArr[6][6];
|
||||
// 示廓灯 9
|
||||
newMessage[9] = PLCByteArr[6][5];
|
||||
newMessage[9] = PLCByteArr[6][2];
|
||||
// 雾灯 10
|
||||
// 雨刮器 11
|
||||
newMessage[11] = PLCByteArr[8][2];
|
||||
newMessage[11] = PLCByteArr[8][5];
|
||||
// 脚刹 12
|
||||
newMessage[12] = PLCByteArr[7][2];
|
||||
newMessage[12] = PLCByteArr[7][5];
|
||||
// 手刹 13
|
||||
newMessage[13] = PLCByteArr[7][3];
|
||||
newMessage[13] = PLCByteArr[7][4];
|
||||
// 主驾驶门 14
|
||||
newMessage[14] = PLCByteArr[7][0];
|
||||
newMessage[14] = PLCByteArr[7][7];
|
||||
// NC 15
|
||||
// TODO
|
||||
// SA15 16
|
||||
// TODO
|
||||
// 离合 17
|
||||
newMessage[17] = PLCByteArr[7][1];
|
||||
newMessage[17] = PLCByteArr[7][6];
|
||||
// 副刹车 18
|
||||
newMessage[18] = PLCByteArr[7][4];
|
||||
newMessage[18] = PLCByteArr[7][3];
|
||||
// 安全带 19
|
||||
newMessage[19] = PLCByteArr[7][7];
|
||||
newMessage[19] = PLCByteArr[7][0];
|
||||
// 双跳灯 20
|
||||
newMessage[20] = PLCByteArr[6][4];
|
||||
newMessage[20] = PLCByteArr[6][3];
|
||||
// 其他门 21
|
||||
// TODO
|
||||
// 转速过高 22
|
||||
newMessage[22] = PLCByteArr[9][7];
|
||||
newMessage[22] = PLCByteArr[9][0];
|
||||
// 车速 23
|
||||
newMessage[23] = PLCByteArr[11];
|
||||
newMessage[23] = parseInt(PLCByteArr[11], 2)+'';
|
||||
// 累计脉冲 24
|
||||
let Data25 = parseInt(PLCByteArr[25], 2);
|
||||
let Data26 = parseInt(PLCByteArr[26], 2);
|
||||
@ -196,18 +226,18 @@ export default class UdpByOne {
|
||||
let Data32 = parseInt(PLCByteArr[32], 2);
|
||||
newMessage[25] = ((Data29 << 24) + (Data30 << 16) + (Data31 << 8) + Data32).toString();
|
||||
// 熄火次数 26
|
||||
newMessage[26] = PLCByteArr[33];
|
||||
newMessage[26] = parseInt(PLCByteArr[33], 2) + '';
|
||||
// 方向盘角度 27
|
||||
// 档位 28
|
||||
newMessage[27] = PLCByteArr[15];
|
||||
// TODO 档位 磁档位为外接信号
|
||||
newMessage[28] = parseInt(PLCByteArr[13], 2) + '';
|
||||
// newMessage[27] = globalThis.chuankoMsg
|
||||
// 超声波1 29
|
||||
let Data52 = parseInt(PLCByteArr[52], 2);
|
||||
let Data53 = parseInt(PLCByteArr[53], 2);
|
||||
newMessage[29] = ((Data52 << 8) + Data53).toString();
|
||||
|
||||
newMessage[29] = (PLCByteArr[4][1] >0 ? 800 : 0) +''
|
||||
// 超声波2 30
|
||||
let Data54 = parseInt(PLCByteArr[54], 2);
|
||||
let Data55 = parseInt(PLCByteArr[55], 2);
|
||||
newMessage[30] = ((Data54 << 8) + Data55).toString();
|
||||
newMessage[30] = (PLCByteArr[4][0] >0 ? 800:0 )+''
|
||||
// 超声波3 31
|
||||
// 超声波4 32
|
||||
// 触摸1 33
|
||||
@ -240,7 +270,9 @@ export default class UdpByOne {
|
||||
// GPS错误次数 60
|
||||
// 已工作时长/设定的工作时长 61
|
||||
// 改正数数据长度*数据长度-基准站RTCM改正数类型 62
|
||||
console.log('heartMsgend',newMessage.join(","))
|
||||
}
|
||||
|
||||
console.log('heartMsgend', newMessage.join(","))
|
||||
|
||||
return newMessage.join(",")
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -60,8 +60,8 @@ export const getMessageHeartbeat = async (msg) => {
|
||||
const {fourInOneScreen:{gpsDigit}} = judgeConfig
|
||||
const asclshArr = stringToASC(fillZero(
|
||||
globalThis.singlePlay
|
||||
? '1111111111111'
|
||||
: globalThis.lsh,
|
||||
? (examSubject == 2 ? '0000000000000' : '0000000000000')
|
||||
: '11111111111',
|
||||
13));
|
||||
const ascksyhArr = stringToASC(fillZero(examSubject == 2 ? '0000000000000':'1111111111111', 13))
|
||||
const ascsbxhArr = stringToASC('00000000')
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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,57 +8,58 @@ 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
|
||||
|
||||
})
|
||||
}
|
||||
@ -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.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() {
|
||||
|
||||
}
|
||||
}
|
||||
@ -714,10 +714,15 @@ export default class Judge {
|
||||
allitems = Reflect.ownKeys(itemInfoObj).map(cdsbKey => {
|
||||
const cdsb = itemInfoObj[cdsbKey];
|
||||
const {xmdm,xmxh,modelKey} = cdsb
|
||||
const modelVal= getModelData(`${examType}/${modelKey}.txt`)
|
||||
if(modelVal){
|
||||
return {
|
||||
xmdm, xmxh, model: getModelData(`${examType}/${modelKey}.txt`)
|
||||
xmdm, xmxh, model: modelVal
|
||||
}
|
||||
})
|
||||
}else{
|
||||
return undefined
|
||||
}
|
||||
}).filter(item => item !== undefined)
|
||||
}
|
||||
//获取版本号
|
||||
const sdkver = await examJudgeVersion();
|
||||
@ -1487,7 +1492,9 @@ export default class Judge {
|
||||
const sbxh = getSbxh(xmdm, xmxh)
|
||||
const {carzt,dcjl,qjjl,dxjl,bxjl} = performInfo || {};
|
||||
const asclshArr = stringToASC(
|
||||
fillZero((singlePlay ? (examSubject == 2 ? '0000000000000' : '1111111111111') : lsh) || 0, 13)
|
||||
fillZero((
|
||||
singlePlay ?
|
||||
(examSubject == 2 ? '0000000000000' : '0000000000000') : lsh) || 0, 13)
|
||||
);
|
||||
//13不足要补0
|
||||
const ascksyhArr = stringToASC(fillZero(ksyh || 0, 13))
|
||||
|
||||
@ -54,11 +54,12 @@ export default class FileModel{
|
||||
const content = fileUtil.getFileContent(`${folderPath}/${fileName}`)
|
||||
return content;
|
||||
}catch (e){
|
||||
console.info('surenjun',JSON.stringify(e))
|
||||
promptAction.showToast({
|
||||
message:`请检查模型路径${folderPath}/${fileName}是否正确!`,
|
||||
duration:4000
|
||||
})
|
||||
// console.info('surenjun',JSON.stringify(e))
|
||||
// promptAction.showToast({
|
||||
// message:`请检查模型路径${folderPath}/${fileName}是否正确!`,
|
||||
// duration:4000
|
||||
// })
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user