Merge branch 'dev' of http://88.22.24.105:3000/harmony_car/subject-two into dev
This commit is contained in:
		
						commit
						6e0c61ca0d
					
				| @ -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 | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | |||||||
| @ -24,7 +24,7 @@ export default class GetDistance { | |||||||
|     const {fileUtil} = this |     const {fileUtil} = this | ||||||
|     const time = await getCurrentTime() |     const time = await getCurrentTime() | ||||||
|     const folderPath = await fileUtil.initFolder(`/车辆行驶距离统计`); |     const folderPath = await fileUtil.initFolder(`/车辆行驶距离统计`); | ||||||
|     console.info('surenjun folderPath=>' ,folderPath); |     // console.info('surenjun folderPath=>' ,folderPath);
 | ||||||
|     const date = time.split(' ')[0].split('-').join('_') |     const date = time.split(' ')[0].split('-').join('_') | ||||||
|     const timeStr = time.split(' ')[1] |     const timeStr = time.split(' ')[1] | ||||||
|     this.timeStr = timeStr |     this.timeStr = timeStr | ||||||
| @ -41,15 +41,15 @@ export default class GetDistance { | |||||||
|   // 过程文件数据
 |   // 过程文件数据
 | ||||||
|   public setTimeData = async (str:number) => { |   public setTimeData = async (str:number) => { | ||||||
|     const {fileUtil,folderPath,timeStr,date,totalDistance} = this; |     const {fileUtil,folderPath,timeStr,date,totalDistance} = this; | ||||||
|     console.log('folderPath',folderPath) |     // console.log('folderPath',folderPath)
 | ||||||
|     const content = await fileUtil.readFile(`${folderPath}/${date}.txt`) || ''; |     const content = await fileUtil.readFile(`${folderPath}/${date}.txt`) || ''; | ||||||
|     const contentArr = content.split('\n').filter(item => item) |     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.totalDistance += (str * 1 > 200 ? 200 : str*1) | ||||||
|     this.totalTime += 1; |     this.totalTime += 1; | ||||||
|     contentArr[contentArr.length - 1] = `程序启动时间:${timeStr} 累计行驶距离:${(this.totalDistance).toFixed(2)}m 累计运行时常:${Math.ceil(this.totalTime/60)}min`+ '\n' |     contentArr[contentArr.length - 1] = `程序启动时间:${timeStr} 累计行驶距离:${(this.totalDistance).toFixed(2)}m 累计运行时常:${Math.ceil(this.totalTime/60)}min`+ '\n' | ||||||
|     console.info('surenjun',contentArr.join('\n')) |     console.info('surenjun',contentArr.join('\n')) | ||||||
|     console.log('folderPath',folderPath,date) |     // console.log('folderPath',folderPath,date)
 | ||||||
|     this.uploadData() |     this.uploadData() | ||||||
| 
 | 
 | ||||||
|     // await fileUtil.addFile(
 |     // await fileUtil.addFile(
 | ||||||
|  | |||||||
| @ -3,10 +3,14 @@ import { getSyncData } from '../service/initable'; | |||||||
| import hilog from '@ohos.hilog'; | import hilog from '@ohos.hilog'; | ||||||
| import FileUtil from '../../common/utils/File' | import FileUtil from '../../common/utils/File' | ||||||
| import { GlobalConfig } from '../../config/index' | import { GlobalConfig } from '../../config/index' | ||||||
|  | import GpsTcpClient from './GpsTcpClient' | ||||||
|  | 
 | ||||||
| export async function getTCP(flag=false) { | export async function getTCP(flag=false) { | ||||||
|   globalThis.getCloseTcp=true |   globalThis.getCloseTcp=true | ||||||
|   const fileUtil = new FileUtil(globalThis.context) |   const fileUtil = new FileUtil(globalThis.context) | ||||||
|   const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt'); |   const data = await fileUtil.readFile(GlobalConfig.comoonfileWriteAddress + '/config/ipConfig.txt'); | ||||||
|  | 
 | ||||||
|  |   const gpsTcpClient = new GpsTcpClient() | ||||||
|   if (data === '' || data === undefined) { |   if (data === '' || data === undefined) { | ||||||
|     globalThis.TcpClient = {} |     globalThis.TcpClient = {} | ||||||
|     globalThis.TcpClient.onMessage = () => { |     globalThis.TcpClient.onMessage = () => { | ||||||
| @ -44,7 +48,7 @@ export async function getTCP(flag=false) { | |||||||
|               if (val) { |               if (val) { | ||||||
|                 // const msg=val.substring(5,val.length-1)
 |                 // const msg=val.substring(5,val.length-1)
 | ||||||
|                 console.log('socketTag[PLC.UdpClient] status:', globalThis.udpClient.getStatus()) |                 console.log('socketTag[PLC.UdpClient] status:', globalThis.udpClient.getStatus()) | ||||||
|                 globalThis.udpClient?.sendMsg(val) |                 gpsTcpClient.sendGpsMsg(val) | ||||||
|               } |               } | ||||||
|             }, 1000) |             }, 1000) | ||||||
| 
 | 
 | ||||||
| @ -77,7 +81,7 @@ export async function getTCP(flag=false) { | |||||||
|       await globalThis.TcpClient.onMessage((val) => { |       await globalThis.TcpClient.onMessage((val) => { | ||||||
|         setTimeout(() => { |         setTimeout(() => { | ||||||
|           if (val && globalThis.udpClient?.sendMsg) { |           if (val && globalThis.udpClient?.sendMsg) { | ||||||
|             globalThis.udpClient?.sendMsg(val) |             gpsTcpClient.sendGpsMsg(val) | ||||||
|           } |           } | ||||||
|         }, 1000) |         }, 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) { |     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(() => { | ||||||
|  | |||||||
| @ -1,246 +1,278 @@ | |||||||
| import socket from '@ohos.net.socket'; | 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 { | export default class UdpByOne { | ||||||
|   //   PLC udp
 |   //   PLC udp
 | ||||||
|   private PLCUDP: any; |   private PLCUDP: any; | ||||||
|   // PLC localIp
 |   // PLC localIp
 | ||||||
|   private PLCLocalIp: string='192.168.7.170'; |   private LocalIp: string = '192.168.7.170'; | ||||||
|   // PLC localIpPort
 |   // PLC localIpPort
 | ||||||
|   private PLCLocalIpPort: string='31012'; |   private PLCLocalIpPort: string = '31012'; | ||||||
|  |   private OppositeIp: string = '192.168.7.124' | ||||||
|   // 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
 | ||||||
|   private GPSLocalIp: string='192.168.7.124'; |  | ||||||
|   // GPS localIpPort
 |   // GPS localIpPort
 | ||||||
|   private GPSLocalIpPort: string='30013'; |   private GPSLocalIpPort: string = '31013'; | ||||||
|   // GPS oppositeIpPort
 |   // GPS oppositeIpPort
 | ||||||
|   private GPSOppositeIpPort: string; |   private GPSOppositeIpPort: string = '30013'; | ||||||
|   // GPS消息
 |   // GPS消息
 | ||||||
|   private GPSMsg: string; |   private GPSMsg: any; | ||||||
| 
 | 
 | ||||||
|   constructor() { |   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
 |     //   初始化UDP
 | ||||||
|     this.PLCUDP = socket.constructUDPSocketInstance(); |     this.PLCUDP = socket.constructUDPSocketInstance(); | ||||||
|     // this.PLCUDP.bind(this.PLCLocalIp, this.PLCLocalIpPort);
 |     // this.PLCUDP.bind(this.PLCLocalIp, this.PLCLocalIpPort);
 | ||||||
|     this.PLCUDP.bind({ |     this.PLCUDP.bind({ | ||||||
|       // address: '192.168.7.170', port: 20122, family: 1
 |       address: this.LocalIp, port: parseInt(this.PLCLocalIpPort), family: 1 | ||||||
|       address: this.PLCLocalIp, port: parseInt(this.PLCLocalIpPort), family: 1 |  | ||||||
|     }); |     }); | ||||||
|     // this.GPSUDP = socket.constructUDPSocketInstance();
 |     this.GPSUDP = socket.constructUDPSocketInstance(); | ||||||
|     // this.GPSUDP.bind(this.GPSLocalIp, this.GPSLocalIpPort);
 |     // this.GPSUDP.bind(this.GPSLocalIp, this.GPSLocalIpPort);
 | ||||||
|  |     this.GPSUDP.bind({ | ||||||
|  |       address: this.LocalIp, port: parseInt(this.GPSLocalIpPort), family: 1 | ||||||
|  |     }); | ||||||
|   } |   } | ||||||
| 
 |  | ||||||
|   //   重新绑定
 |   //   重新绑定
 | ||||||
|   public rebind() { |   public rebind() { | ||||||
|     this.PLCUDP.bind(this.PLCLocalIp, this.PLCLocalIpPort); |     this.PLCUDP.bind(this.LocalIp, this.PLCLocalIpPort); | ||||||
|     this.GPSUDP.bind(this.GPSLocalIp, this.GPSLocalIpPort); |     this.GPSUDP.bind(this.LocalIp, this.GPSLocalIpPort); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //   PLC发送消息
 |   //   PLC发送消息
 | ||||||
|   public sendPLCMsg(msg: string) { |   public sendPLCMsg(msg: string) { | ||||||
|     this.PLCUDP.send({ |     // this.PLCUDP.send({
 | ||||||
|       data: '111111', |     //   data: '111111',
 | ||||||
|       address: { |     //   address: {
 | ||||||
|         address: '192.168.7.124', |     //     address: this.OppositeIp,
 | ||||||
|         port: parseInt(this.PLCOppositeIpPort), |     //     port: parseInt(this.PLCOppositeIpPort),
 | ||||||
|       } |     //   }
 | ||||||
|     }) |     // })
 | ||||||
|     // this.PLCUDP.sendTo(msg, this.PLCOppositeIpPort);
 |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   //   GPS发送消息
 |   //   GPS发送消息
 | ||||||
|   public sendGPSMsg(msg: string) { |   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) { |   public receiveMsg(callback) { | ||||||
|     console.log('heartMsg','getCallback') |     console.log('heartMsg', 'getCallback') | ||||||
|     this.sendPLCMsg('1111') |     this.sendPLCMsg('1111') | ||||||
|     this.PLCUDP.on("message", (message2, remoteInfo) => { |     this.sendGPSMsg('1111') | ||||||
|       console.log('heartMsg','getPlc') |     this.PLCUDP.on("message", (res, remoteInfo) => { | ||||||
| 
 |       console.log('heartMsg', 'getPlc') | ||||||
|       this.PLCMsg = message2; |       console.log('heartMsg', 'getGps') | ||||||
|  |       this.PLCMsg = res.message; | ||||||
|       //   组合数据
 |       //   组合数据
 | ||||||
|       let newMessage = this.handleMsg() |       let newMessage = this.handleMsg() | ||||||
|       callback(newMessage) |       callback(newMessage) | ||||||
|     }) |     }) | ||||||
|     return |     this.GPSUDP.on("message", (res1, remoteInfo) => { | ||||||
|     this.GPSUDP.on("message", (message1, remoteInfo) => { |       console.log('heartMsg', 'getGps') | ||||||
|       console.log('heartMsg','GPSUDP') |       let dataView = new DataView(res1.message) | ||||||
|       this.GPSMsg = message1; |       let str = "" | ||||||
|       this.PLCUDP.on("message", (message2, remoteInfo) => { |       for (let i = 0; i < dataView?.byteLength; ++i) { | ||||||
|         this.PLCMsg = message2; |         let c = String.fromCharCode(dataView?.getUint8(i)) | ||||||
|         //   组合数据
 |         if (c !== "\n") { | ||||||
|         let newMessage = this.handleMsg() |           str += c | ||||||
|         callback(newMessage) |         } | ||||||
|       }) |       } | ||||||
|  |       this.GPSMsg = str; | ||||||
|  |       if(str.length < 10){ | ||||||
|  |         return | ||||||
|  |       } | ||||||
|  |       let newMessage = this.handleMsg() | ||||||
|  |       callback(newMessage) | ||||||
|     }) |     }) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // 处理消息
 |   // 处理消息
 | ||||||
|   public handleMsg() { |   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; |     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]; |  | ||||||
|     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 PLCByteArr = this.PLCMsg.map((num) => num.toString(2).padStart(8, "0")); |       //   组合GPS数据
 | ||||||
|     console.log(PLCByteArr[1][2]); |       // 状态83
 | ||||||
|     // 左方向灯 2
 |       newMessage[83] = GPGGAMsgArr[6]; | ||||||
|     newMessage[2] = PLCByteArr[6][2]; |       // 收星数84
 | ||||||
|     // 右方向灯 3
 |       newMessage[84] = GPGGAMsgArr[7]; | ||||||
|     newMessage[3] = PLCByteArr[6][3]; |       // 海拔高85
 | ||||||
|     // 喇叭 4
 |       newMessage[80] = GPGGAMsgArr[9]; | ||||||
|     newMessage[4] = PLCByteArr[8][2]; |       // 高度差86
 | ||||||
|     // 点火1 5
 |       // 龄期87
 | ||||||
|     newMessage[5] = PLCByteArr[8][0]; |       newMessage[87] = GPGGAMsgArr[13]; | ||||||
|     // 点火2 6
 |       // 维度因子88
 | ||||||
|     newMessage[6] = PLCByteArr[8][1]; |       // 经度因子89
 | ||||||
|     // 近光灯 7
 |       // 航向角90
 | ||||||
|     newMessage[7] = PLCByteArr[6][0]; |       newMessage[90] = PTNLMsgArr[3]; | ||||||
|     // 远光灯 8
 |       // 俯仰角91
 | ||||||
|     newMessage[8] = PLCByteArr[6][1]; |       newMessage[91] = PTNLMsgArr[5]; | ||||||
|     // 示廓灯 9
 |       // 航向角状态-收星数92
 | ||||||
|     newMessage[9] = PLCByteArr[6][5]; |       newMessage[92] = PTNLMsgArr[10] + '-' + PTNLMsgArr[12].split('*')[0]; | ||||||
|     // 雾灯 10
 |       //  年月日93 RMCMsgArr[9]为ddmmyy 日月年 转换为年月日
 | ||||||
|     // 雨刮器 11
 |       newMessage[93] = | ||||||
|     newMessage[11] = PLCByteArr[8][2]; |         GPRMCMsgArr[9].slice(0, 2) + GPRMCMsgArr[9].slice(2, 4) + GPRMCMsgArr[9].slice(4, 6); | ||||||
|     // 脚刹 12
 |       // 时分秒94 GPGGAMsgArr[1]为021126.00去掉小数点后的时间
 | ||||||
|     newMessage[12] = PLCByteArr[7][2]; |       newMessage[94] = GPGGAMsgArr[1].replace(".", ""); | ||||||
|     // 手刹 13
 |       // 经度95
 | ||||||
|     newMessage[13] = PLCByteArr[7][3]; |       newMessage[95] = GPGGAMsgArr[4]; | ||||||
|     // 主驾驶门 14
 |       // 纬度96
 | ||||||
|     newMessage[14] = PLCByteArr[7][0]; |       newMessage[96] = GPGGAMsgArr[2]; | ||||||
|     // NC 15
 |       // 速度97
 | ||||||
|     // TODO
 |       newMessage[97] = GPRMCMsgArr[7]; | ||||||
|     // SA15 16
 |     } | ||||||
|     // TODO
 |     if (this.PLCMsg) { | ||||||
|     // 离合 17
 |       let dataView = new DataView(this.PLCMsg) | ||||||
|     newMessage[17] = PLCByteArr[7][1]; |       let PLCByteArr = [] | ||||||
|     // 副刹车 18
 |       for (let i = 0; i < dataView?.byteLength; ++i) { | ||||||
|     newMessage[18] = PLCByteArr[7][4]; |         let c = dataView?.getUint8(i).toString(2).padStart(8, "0") | ||||||
|     // 安全带 19
 |         PLCByteArr.push(c.toString()) | ||||||
|     newMessage[19] = PLCByteArr[7][7]; |       } | ||||||
|     // 双跳灯 20
 |       if (PLCByteArr.length < 55) { | ||||||
|     newMessage[20] = PLCByteArr[6][4]; |         return newMessage.join(",") | ||||||
|     // 其他门 21
 |       } | ||||||
|     // TODO
 |       console.log("heartMsgheartMsg1", PLCByteArr.toString()); | ||||||
|     // 转速过高 22
 |       // 左方向灯 2
 | ||||||
|     newMessage[22] = PLCByteArr[9][7]; |       newMessage[2] = PLCByteArr[6][5]; | ||||||
|     // 车速 23
 |       // 右方向灯 3 .
 | ||||||
|     newMessage[23] = PLCByteArr[11]; |       newMessage[3] = PLCByteArr[6][4]; | ||||||
|     // 累计脉冲 24
 |       // 喇叭 4
 | ||||||
|     let Data25 = parseInt(PLCByteArr[25], 2); |       newMessage[4] = PLCByteArr[8][4]; | ||||||
|     let Data26 = parseInt(PLCByteArr[26], 2); |       // 点火1 5
 | ||||||
|     let Data27 = parseInt(PLCByteArr[27], 2); |       newMessage[5] = PLCByteArr[8][7]; | ||||||
|     let Data28 = parseInt(PLCByteArr[28], 2); |       // 点火2 6
 | ||||||
|     newMessage[24] = ((Data25 << 24) + (Data26 << 16) + (Data27 << 8) + Data28).toString(); |       newMessage[6] = PLCByteArr[8][6]; | ||||||
|     // 发动机转速 25
 |       // 近光灯 7
 | ||||||
|     let Data29 = parseInt(PLCByteArr[29], 2); |       newMessage[7] = PLCByteArr[6][7]; | ||||||
|     let Data30 = parseInt(PLCByteArr[30], 2); |       // 远光灯 8
 | ||||||
|     let Data31 = parseInt(PLCByteArr[31], 2); |       newMessage[8] = PLCByteArr[6][6]; | ||||||
|     let Data32 = parseInt(PLCByteArr[32], 2); |       // 示廓灯 9
 | ||||||
|     newMessage[25] = ((Data29 << 24) + (Data30 << 16) + (Data31 << 8) + Data32).toString(); |       newMessage[9] = PLCByteArr[6][2]; | ||||||
|     // 熄火次数 26
 |       // 雾灯 10
 | ||||||
|     newMessage[26] = PLCByteArr[33]; |       // 雨刮器 11
 | ||||||
|     // 方向盘角度 27
 |       newMessage[11] = PLCByteArr[8][5]; | ||||||
|     // 档位 28
 |       // 脚刹 12
 | ||||||
|     newMessage[27] = PLCByteArr[15]; |       newMessage[12] = PLCByteArr[7][5]; | ||||||
|     // 超声波1 29
 |       // 手刹 13
 | ||||||
|     let Data52 = parseInt(PLCByteArr[52], 2); |       newMessage[13] = PLCByteArr[7][4]; | ||||||
|     let Data53 = parseInt(PLCByteArr[53], 2); |       // 主驾驶门 14
 | ||||||
|     newMessage[29] = ((Data52 << 8) + Data53).toString(); |       newMessage[14] = PLCByteArr[7][7]; | ||||||
|     // 超声波2 30
 |       // NC 15
 | ||||||
|     let Data54 = parseInt(PLCByteArr[54], 2); |       // TODO
 | ||||||
|     let Data55 = parseInt(PLCByteArr[55], 2); |       // SA15 16
 | ||||||
|     newMessage[30] = ((Data54 << 8) + Data55).toString(); |       // TODO
 | ||||||
|     // 超声波3 31
 |       // 离合 17
 | ||||||
|     // 超声波4 32
 |       newMessage[17] = PLCByteArr[7][6]; | ||||||
|     // 触摸1 33
 |       // 副刹车 18
 | ||||||
|     // 触摸2 34
 |       newMessage[18] = PLCByteArr[7][3]; | ||||||
|     // 触摸3 35
 |       // 安全带 19
 | ||||||
|     // SCIO 36
 |       newMessage[19] = PLCByteArr[7][0]; | ||||||
|     // SC1A_C 37
 |       // 双跳灯 20
 | ||||||
|     // SC1B_C 38
 |       newMessage[20] = PLCByteArr[6][3]; | ||||||
|     // SC2A_C 39
 |       // 其他门 21
 | ||||||
|     // SC2B_C 40
 |       // TODO
 | ||||||
|     // SC3A_C 41
 |       // 转速过高 22
 | ||||||
|     // SC3B_C 42
 |       newMessage[22] = PLCByteArr[9][0]; | ||||||
|     // SC4A_C 43
 |       // 车速 23
 | ||||||
|     // SC4B_C 44
 |       newMessage[23] = parseInt(PLCByteArr[11], 2)+''; | ||||||
|     // SC5A_C 45
 |       // 累计脉冲 24
 | ||||||
|     // SC5B_C 46
 |       let Data25 = parseInt(PLCByteArr[25], 2); | ||||||
|     // SC6A_C 47
 |       let Data26 = parseInt(PLCByteArr[26], 2); | ||||||
|     // SC6B_C 48
 |       let Data27 = parseInt(PLCByteArr[27], 2); | ||||||
|     // 发送次数 49
 |       let Data28 = parseInt(PLCByteArr[28], 2); | ||||||
|     // 方向盘类型 50
 |       newMessage[24] = ((Data25 << 24) + (Data26 << 16) + (Data27 << 8) + Data28).toString(); | ||||||
|     // 汽车类型 51
 |       // 发动机转速 25
 | ||||||
|     // 接口心跳 52
 |       let Data29 = parseInt(PLCByteArr[29], 2); | ||||||
|     // 本机IP 53
 |       let Data30 = parseInt(PLCByteArr[30], 2); | ||||||
|     // 固件版本 54
 |       let Data31 = parseInt(PLCByteArr[31], 2); | ||||||
|     // 按键数值 55
 |       let Data32 = parseInt(PLCByteArr[32], 2); | ||||||
|     // GPS板卡类型 56
 |       newMessage[25] = ((Data29 << 24) + (Data30 << 16) + (Data31 << 8) + Data32).toString(); | ||||||
|     // GPS板卡软件版本 57
 |       // 熄火次数 26
 | ||||||
|     // 改正数次数/改正数大小 58
 |       newMessage[26] = parseInt(PLCByteArr[33], 2) + ''; | ||||||
|     // GPS数据次数/数据长度 59
 |       // 方向盘角度 27
 | ||||||
|     // GPS错误次数 60
 |       // TODO 档位 磁档位为外接信号
 | ||||||
|     // 已工作时长/设定的工作时长 61
 |       newMessage[28] = parseInt(PLCByteArr[13], 2) + ''; | ||||||
|     // 改正数数据长度*数据长度-基准站RTCM改正数类型 62
 |       // newMessage[27] = globalThis.chuankoMsg
 | ||||||
|     console.log('heartMsgend',newMessage.join(",")) |       // 超声波1 29
 | ||||||
|  |       let Data52 = parseInt(PLCByteArr[52], 2); | ||||||
|  |       let Data53 = parseInt(PLCByteArr[53], 2); | ||||||
|  | 
 | ||||||
|  |       newMessage[29] = (PLCByteArr[4][1] >0 ? 800 : 0) +'' | ||||||
|  |       // 超声波2 30
 | ||||||
|  |       newMessage[30] =  (PLCByteArr[4][0] >0 ? 800:0 )+'' | ||||||
|  |       // 超声波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(",") |     return newMessage.join(",") | ||||||
|   } |   } | ||||||
|  | |||||||
| @ -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);
 | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -60,8 +60,8 @@ export const getMessageHeartbeat = async (msg) => { | |||||||
|   const {fourInOneScreen:{gpsDigit}} = judgeConfig |   const {fourInOneScreen:{gpsDigit}} = judgeConfig | ||||||
|   const asclshArr = stringToASC(fillZero( |   const asclshArr = stringToASC(fillZero( | ||||||
|     globalThis.singlePlay |     globalThis.singlePlay | ||||||
|       ? '1111111111111' |       ? (examSubject == 2 ? '0000000000000' : '0000000000000') | ||||||
|       : globalThis.lsh, |       : '11111111111', | ||||||
|     13)); |     13)); | ||||||
|   const ascksyhArr = stringToASC(fillZero(examSubject == 2 ? '0000000000000':'1111111111111', 13)) |   const ascksyhArr = stringToASC(fillZero(examSubject == 2 ? '0000000000000':'1111111111111', 13)) | ||||||
|   const ascsbxhArr = stringToASC('00000000') |   const ascsbxhArr = stringToASC('00000000') | ||||||
|  | |||||||
| @ -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 | ||||||
|  | |||||||
| @ -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() { | ||||||
| 
 | 
 | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @ -714,10 +714,15 @@ export default class Judge { | |||||||
|       allitems = Reflect.ownKeys(itemInfoObj).map(cdsbKey => { |       allitems = Reflect.ownKeys(itemInfoObj).map(cdsbKey => { | ||||||
|         const cdsb = itemInfoObj[cdsbKey]; |         const cdsb = itemInfoObj[cdsbKey]; | ||||||
|         const {xmdm,xmxh,modelKey} = cdsb |         const {xmdm,xmxh,modelKey} = cdsb | ||||||
|         return { |         const modelVal= getModelData(`${examType}/${modelKey}.txt`) | ||||||
|           xmdm, xmxh, model: getModelData(`${examType}/${modelKey}.txt`) |         if(modelVal){ | ||||||
|  |           return { | ||||||
|  |             xmdm, xmxh, model: modelVal | ||||||
|  |           } | ||||||
|  |         }else{ | ||||||
|  |           return undefined | ||||||
|         } |         } | ||||||
|       }) |       }).filter(item => item !== undefined) | ||||||
|     } |     } | ||||||
|     //获取版本号
 |     //获取版本号
 | ||||||
|     const sdkver = await examJudgeVersion(); |     const sdkver = await examJudgeVersion(); | ||||||
| @ -1487,7 +1492,9 @@ export default class Judge { | |||||||
|     const sbxh = getSbxh(xmdm, xmxh) |     const sbxh = getSbxh(xmdm, xmxh) | ||||||
|     const {carzt,dcjl,qjjl,dxjl,bxjl} = performInfo || {}; |     const {carzt,dcjl,qjjl,dxjl,bxjl} = performInfo || {}; | ||||||
|     const asclshArr = stringToASC( |     const asclshArr = stringToASC( | ||||||
|       fillZero((singlePlay ? (examSubject == 2 ? '0000000000000' : '1111111111111') : lsh) || 0, 13) |       fillZero(( | ||||||
|  |         singlePlay ? | ||||||
|  |           (examSubject == 2 ? '0000000000000' : '0000000000000') : lsh) || 0, 13) | ||||||
|     ); |     ); | ||||||
|     //13不足要补0
 |     //13不足要补0
 | ||||||
|     const ascksyhArr = stringToASC(fillZero(ksyh || 0, 13)) |     const ascksyhArr = stringToASC(fillZero(ksyh || 0, 13)) | ||||||
|  | |||||||
| @ -54,11 +54,12 @@ export default class FileModel{ | |||||||
|       const content = fileUtil.getFileContent(`${folderPath}/${fileName}`) |       const content = fileUtil.getFileContent(`${folderPath}/${fileName}`) | ||||||
|       return content; |       return content; | ||||||
|     }catch (e){ |     }catch (e){ | ||||||
|       console.info('surenjun',JSON.stringify(e)) |       // console.info('surenjun',JSON.stringify(e))
 | ||||||
|       promptAction.showToast({ |       // promptAction.showToast({
 | ||||||
|         message:`请检查模型路径${folderPath}/${fileName}是否正确!`, |       //   message:`请检查模型路径${folderPath}/${fileName}是否正确!`,
 | ||||||
|         duration:4000 |       //   duration:4000
 | ||||||
|       }) |       // })
 | ||||||
|  |       return '' | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user