Compare commits
	
		
			2 Commits
		
	
	
		
			c1363263b2
			...
			0fa4bb81cc
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 0fa4bb81cc | |||
| fbc1d49af1 | 
| @ -74,10 +74,7 @@ export default class FileUtil{ | ||||
|       console.error(LOGTAG,'写入失败',JSON.stringify(e)) | ||||
|     } | ||||
|   } | ||||
|   /* | ||||
|   * @desc 创建或者编辑文件 | ||||
|   * | ||||
|   */ | ||||
| 
 | ||||
|   public openFileSync=async(filePath)=>{ | ||||
|     const { READ_WRITE,CREATE,APPEND }= fs.OpenMode | ||||
|     let file = fs.openSync(filePath, READ_WRITE | APPEND |CREATE); | ||||
| @ -90,18 +87,22 @@ export default class FileUtil{ | ||||
|     fs.closeSync(file) | ||||
|     console.error(LOGTAG,'写入文件成功') | ||||
|   } | ||||
| 
 | ||||
| 
 | ||||
|   public editFile = async (filePath:string,content:string,type?:string)=>{ | ||||
|   /* | ||||
|   * @desc 创建或者编辑文件 | ||||
|   * | ||||
|   */ | ||||
|   public editFile = async (filePath:string,content:string,fd?:number)=>{ | ||||
|     const { READ_WRITE,CREATE,APPEND }= fs.OpenMode | ||||
|     try { | ||||
|       let file = fs.openSync(filePath, READ_WRITE | APPEND |CREATE); | ||||
|       const newStr =  content + '\n' | ||||
|       //追加写入文件
 | ||||
|       fs.writeSync(file.fd,newStr) | ||||
|       fs.closeSync(file) | ||||
|       console.error(LOGTAG,'写入文件成功') | ||||
|       return true | ||||
|       if(fd !== undefined){ | ||||
|         fs.writeSync(fd,newStr) | ||||
|         return fd | ||||
|       }else{ | ||||
|         let file = fs.openSync(filePath, READ_WRITE | APPEND |CREATE); | ||||
|         fs.writeSync(file.fd,newStr) | ||||
|         return file.fd | ||||
|       } | ||||
| 
 | ||||
|     }catch (e){ | ||||
|       console.error(LOGTAG,JSON.stringify(e)) | ||||
|  | ||||
| @ -21,9 +21,22 @@ export default class FileLog { | ||||
|   private stuInfo: StuInfo | ||||
|   public folderPath: string | ||||
| 
 | ||||
|   public progressDataFd: number = undefined | ||||
|   public examJudgeWuxiDataFd: number = undefined | ||||
|   public examJudgeWuxiProgressDataFd: number = undefined | ||||
|   public plcDataFd: number = undefined | ||||
|   public examJudgeDataFd: number = undefined | ||||
|   public examJudgeCallbackDataFd: number = undefined | ||||
|   public examJudgeLogDataFd: number = undefined | ||||
|   public fourAndOneLogDataFd: number = undefined | ||||
|   public fourAndOneLogDataBytesFd: number = undefined | ||||
|   public examLineDataFd: number = undefined | ||||
| 
 | ||||
| 
 | ||||
|   constructor(context) { | ||||
|     const fileUtil = new FileUtil(context) | ||||
|     this.fileUtil = fileUtil | ||||
| 
 | ||||
|   } | ||||
| 
 | ||||
|   // 设置文件夹
 | ||||
| @ -41,63 +54,62 @@ export default class FileLog { | ||||
| 
 | ||||
|   // 过程文件数据
 | ||||
|   public setExamProgressData = async (str:Object) => { | ||||
|     const {fileUtil,folderPath} = this; | ||||
|     await fileUtil.editFile(`${folderPath}/exam_progress_data.txt`,JSON.stringify(str)); | ||||
|     const {fileUtil,folderPath,progressDataFd} = this; | ||||
|     this.progressDataFd = await fileUtil.editFile(`${folderPath}/exam_progress_data.txt`,JSON.stringify(str),progressDataFd); | ||||
|   } | ||||
| 
 | ||||
|   // 无锡所接口数据
 | ||||
|   public setExamJudgeWuxiData = async (str) => { | ||||
|     const {fileUtil,folderPath} = this; | ||||
|     await fileUtil.editFile(`${folderPath}/wuxi_exam_data.txt`,str); | ||||
|     const {fileUtil,folderPath,examJudgeWuxiDataFd} = this; | ||||
|     this.examJudgeWuxiDataFd = await fileUtil.editFile(`${folderPath}/wuxi_exam_data.txt`,str,examJudgeWuxiDataFd); | ||||
|   } | ||||
| 
 | ||||
|   // 无锡所过程数据
 | ||||
|   public setExamJudgeWuxiProgressData = async (str)=>{ | ||||
|     const {fileUtil,folderPath} = this; | ||||
|     await fileUtil.editFile(`${folderPath}/wuxi_progress_data.txt`,str); | ||||
|     const {fileUtil,folderPath,examJudgeWuxiProgressDataFd} = this; | ||||
|     this.examJudgeWuxiProgressDataFd = await fileUtil.editFile(`${folderPath}/wuxi_progress_data.txt`,str,examJudgeWuxiProgressDataFd); | ||||
|   } | ||||
| 
 | ||||
|   // plc文件数据
 | ||||
|   public setPlcProgressData = async (str:Object) => { | ||||
|     const {fileUtil,folderPath} = this; | ||||
|     await fileUtil.editFile(`${folderPath}/plc_data.txt`,JSON.stringify(str)); | ||||
|     const {fileUtil,folderPath,plcDataFd} = this; | ||||
|     this.plcDataFd  = await fileUtil.editFile(`${folderPath}/plc_data.txt`,JSON.stringify(str),plcDataFd); | ||||
|   } | ||||
| 
 | ||||
|   // 过程评判json数据
 | ||||
|   public setExamJudgeData = async (str:Object) => { | ||||
|     const {fileUtil,folderPath} = this; | ||||
|     await fileUtil.editFile(`${folderPath}/judge_exam_data.txt`,JSON.stringify(str)); | ||||
|     const {fileUtil,folderPath,examJudgeDataFd} = this; | ||||
|     this.examJudgeDataFd = await fileUtil.editFile(`${folderPath}/judge_exam_data.txt`,JSON.stringify(str),examJudgeDataFd); | ||||
|   } | ||||
| 
 | ||||
|   // 过程评判回调数据
 | ||||
|   public setExamJudgeCallbackData = async (str:string) => { | ||||
|     const {fileUtil,folderPath} = this; | ||||
|     await fileUtil.editFile(`${folderPath}/judge_progress_callback_data.txt`,str); | ||||
|     const {fileUtil,folderPath,examJudgeCallbackDataFd} = this; | ||||
|     this.examJudgeCallbackDataFd = await fileUtil.editFile(`${folderPath}/judge_progress_callback_data.txt`,str,examJudgeCallbackDataFd); | ||||
|   } | ||||
| 
 | ||||
|   // 过程评判日志调数据
 | ||||
|   public setExamJudgeLogData = async (str:string) => { | ||||
|     const {fileUtil,folderPath} = this; | ||||
|     await fileUtil.editFile(`${folderPath}/judge_log_data.txt`,str); | ||||
|     const {fileUtil,folderPath,examJudgeLogDataFd} = this; | ||||
|     this.examJudgeLogDataFd = await fileUtil.editFile(`${folderPath}/judge_log_data.txt`,str,examJudgeLogDataFd); | ||||
|   } | ||||
| 
 | ||||
|   // 设置四合一画面数据
 | ||||
|   public setFourAndOneLogData = async (str:string) => { | ||||
|     const {fileUtil,folderPath} = this; | ||||
|     await fileUtil.editFile(`${folderPath}/four_one_log_data.txt`,str); | ||||
|     const {fileUtil,folderPath,fourAndOneLogDataFd} = this; | ||||
|     this.fourAndOneLogDataFd = await fileUtil.editFile(`${folderPath}/four_one_log_data.txt`,str,fourAndOneLogDataFd); | ||||
|   } | ||||
| 
 | ||||
|   public setFourAndOneLogDataBytes = async (str:string) => { | ||||
|     const {fileUtil,folderPath} = this; | ||||
|     await fileUtil.editFile(`${folderPath}/four_one_log_byte_data.txt`,str); | ||||
|     const {fileUtil,folderPath,fourAndOneLogDataBytesFd} = this; | ||||
|     this.fourAndOneLogDataBytesFd = await fileUtil.editFile(`${folderPath}/four_one_log_byte_data.txt`,str,fourAndOneLogDataBytesFd); | ||||
|   } | ||||
| 
 | ||||
|   // 无锡所轨迹数据
 | ||||
|   public setExamLineData = async (plcStr) => { | ||||
|     const {fileUtil,folderPath} = this; | ||||
|     const {fileUtil,folderPath,examLineDataFd} = this; | ||||
|     const plcData = plcStr.split(','); | ||||
|     const time = await getCurrentTime(); | ||||
| 
 | ||||
|     const lineData = [ | ||||
|     /*帧头*/ time, | ||||
|       /*卫星时间*/time, | ||||
| @ -123,7 +135,6 @@ export default class FileLog { | ||||
|       /*发动机转速*/ plcData[25], | ||||
|       /*结束符*/ time, | ||||
|     ]; | ||||
| 
 | ||||
|     await fileUtil.editFile(`${folderPath}/exam_wuxi_data.txt`,JSON.stringify(lineData)); | ||||
|     this.examLineDataFd = await fileUtil.editFile(`${folderPath}/exam_wuxi_data.txt`,JSON.stringify(lineData),examLineDataFd); | ||||
|   }; | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user