Compare commits

..

No commits in common. "0fa4bb81cc33573dbd27125a88e083d7d11f052d" and "c1363263b26688ca0b402f7829887d892a069ba6" have entirely different histories.

2 changed files with 35 additions and 47 deletions

View File

@ -74,7 +74,10 @@ 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);
@ -87,22 +90,18 @@ export default class FileUtil{
fs.closeSync(file)
console.error(LOGTAG,'写入文件成功')
}
/*
* @desc
*
*/
public editFile = async (filePath:string,content:string,fd?:number)=>{
public editFile = async (filePath:string,content:string,type?:string)=>{
const { READ_WRITE,CREATE,APPEND }= fs.OpenMode
try {
const newStr = content + '\n'
if(fd !== undefined){
fs.writeSync(fd,newStr)
return fd
}else{
let file = fs.openSync(filePath, READ_WRITE | APPEND |CREATE);
const newStr = content + '\n'
//追加写入文件
fs.writeSync(file.fd,newStr)
return file.fd
}
fs.closeSync(file)
console.error(LOGTAG,'写入文件成功')
return true
}catch (e){
console.error(LOGTAG,JSON.stringify(e))

View File

@ -21,22 +21,9 @@ 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
}
// 设置文件夹
@ -54,62 +41,63 @@ export default class FileLog {
// 过程文件数据
public setExamProgressData = async (str:Object) => {
const {fileUtil,folderPath,progressDataFd} = this;
this.progressDataFd = await fileUtil.editFile(`${folderPath}/exam_progress_data.txt`,JSON.stringify(str),progressDataFd);
const {fileUtil,folderPath} = this;
await fileUtil.editFile(`${folderPath}/exam_progress_data.txt`,JSON.stringify(str));
}
// 无锡所接口数据
public setExamJudgeWuxiData = async (str) => {
const {fileUtil,folderPath,examJudgeWuxiDataFd} = this;
this.examJudgeWuxiDataFd = await fileUtil.editFile(`${folderPath}/wuxi_exam_data.txt`,str,examJudgeWuxiDataFd);
const {fileUtil,folderPath} = this;
await fileUtil.editFile(`${folderPath}/wuxi_exam_data.txt`,str);
}
// 无锡所过程数据
public setExamJudgeWuxiProgressData = async (str)=>{
const {fileUtil,folderPath,examJudgeWuxiProgressDataFd} = this;
this.examJudgeWuxiProgressDataFd = await fileUtil.editFile(`${folderPath}/wuxi_progress_data.txt`,str,examJudgeWuxiProgressDataFd);
const {fileUtil,folderPath} = this;
await fileUtil.editFile(`${folderPath}/wuxi_progress_data.txt`,str);
}
// plc文件数据
public setPlcProgressData = async (str:Object) => {
const {fileUtil,folderPath,plcDataFd} = this;
this.plcDataFd = await fileUtil.editFile(`${folderPath}/plc_data.txt`,JSON.stringify(str),plcDataFd);
const {fileUtil,folderPath} = this;
await fileUtil.editFile(`${folderPath}/plc_data.txt`,JSON.stringify(str));
}
// 过程评判json数据
public setExamJudgeData = async (str:Object) => {
const {fileUtil,folderPath,examJudgeDataFd} = this;
this.examJudgeDataFd = await fileUtil.editFile(`${folderPath}/judge_exam_data.txt`,JSON.stringify(str),examJudgeDataFd);
const {fileUtil,folderPath} = this;
await fileUtil.editFile(`${folderPath}/judge_exam_data.txt`,JSON.stringify(str));
}
// 过程评判回调数据
public setExamJudgeCallbackData = async (str:string) => {
const {fileUtil,folderPath,examJudgeCallbackDataFd} = this;
this.examJudgeCallbackDataFd = await fileUtil.editFile(`${folderPath}/judge_progress_callback_data.txt`,str,examJudgeCallbackDataFd);
const {fileUtil,folderPath} = this;
await fileUtil.editFile(`${folderPath}/judge_progress_callback_data.txt`,str);
}
// 过程评判日志调数据
public setExamJudgeLogData = async (str:string) => {
const {fileUtil,folderPath,examJudgeLogDataFd} = this;
this.examJudgeLogDataFd = await fileUtil.editFile(`${folderPath}/judge_log_data.txt`,str,examJudgeLogDataFd);
const {fileUtil,folderPath} = this;
await fileUtil.editFile(`${folderPath}/judge_log_data.txt`,str);
}
// 设置四合一画面数据
public setFourAndOneLogData = async (str:string) => {
const {fileUtil,folderPath,fourAndOneLogDataFd} = this;
this.fourAndOneLogDataFd = await fileUtil.editFile(`${folderPath}/four_one_log_data.txt`,str,fourAndOneLogDataFd);
const {fileUtil,folderPath} = this;
await fileUtil.editFile(`${folderPath}/four_one_log_data.txt`,str);
}
public setFourAndOneLogDataBytes = async (str:string) => {
const {fileUtil,folderPath,fourAndOneLogDataBytesFd} = this;
this.fourAndOneLogDataBytesFd = await fileUtil.editFile(`${folderPath}/four_one_log_byte_data.txt`,str,fourAndOneLogDataBytesFd);
const {fileUtil,folderPath} = this;
await fileUtil.editFile(`${folderPath}/four_one_log_byte_data.txt`,str);
}
// 无锡所轨迹数据
public setExamLineData = async (plcStr) => {
const {fileUtil,folderPath,examLineDataFd} = this;
const {fileUtil,folderPath} = this;
const plcData = plcStr.split(',');
const time = await getCurrentTime();
const lineData = [
/*帧头*/ time,
/*卫星时间*/time,
@ -135,6 +123,7 @@ export default class FileLog {
/*发动机转速*/ plcData[25],
/*结束符*/ time,
];
this.examLineDataFd = await fileUtil.editFile(`${folderPath}/exam_wuxi_data.txt`,JSON.stringify(lineData),examLineDataFd);
await fileUtil.editFile(`${folderPath}/exam_wuxi_data.txt`,JSON.stringify(lineData));
};
}