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