230 lines
5.4 KiB
Plaintext
230 lines
5.4 KiB
Plaintext
import libJudgeSdk from 'libjudgesdk.so';
|
||
import { JudgeBeginObj, JudgeInitObj, Plc } from '../../../model';
|
||
|
||
// import libJudgeSdk from '@ohos.judgesdk'
|
||
/**
|
||
* 苏仁君
|
||
* @date 2023/04/10
|
||
* @desc 调用c++评判库
|
||
**/
|
||
|
||
|
||
/**
|
||
*
|
||
* @desc 获取版本信息
|
||
**/
|
||
export async function examJudgeVersion(): Promise<string> {
|
||
return await libJudgeSdk.examJudgeVersion();
|
||
}
|
||
|
||
/**
|
||
*
|
||
* @params level
|
||
* 关闭[0] 错误[1] 警告[2] 追踪[3] 信息[4] 调试[5] 全部[6]
|
||
注意:0 是关闭日志,6 是日志全部输出,数字越大日志输出越多调试和测试阶段可以开到 6,正式上线最多开到
|
||
* @params callBack 日志操作回调
|
||
* @desc 设置评判日志级别和日志回调函数
|
||
*/
|
||
export async function examJudgeSetLogCallback(level: number, handleLog: Function): Promise<number> {
|
||
const temp: number = libJudgeSdk.examJudgeSetLogCallback(level, handleLog);
|
||
return await handle(temp, 'examJudgeSetLogCallback')
|
||
}
|
||
|
||
/*
|
||
*
|
||
* @desc评判初始化
|
||
*/
|
||
export async function examJudgeInit(data: JudgeInitObj) {
|
||
const str = JSON.stringify(data);
|
||
const temp: number = libJudgeSdk.examJudgeInit(str, str.length);
|
||
return await handle(temp, 'examJudgeInit')
|
||
}
|
||
|
||
/*
|
||
*
|
||
* @desc 执行实时考试过程 实时传递传感信息
|
||
*/
|
||
export async function examJudgeRealExam(data: Plc) {
|
||
const str = JSON.stringify(data);
|
||
const temp: number = libJudgeSdk.examJudgeRealExam(str, str.length);
|
||
return await handle(temp, 'examJudgeRealExam')
|
||
}
|
||
|
||
/*
|
||
*
|
||
* @desc 设置评判输出的考试过程数据回调函数
|
||
*/
|
||
//js_examJudgeSetRealExamCallback
|
||
export async function examJudgeSetRealExamCallback(fn: Function) {
|
||
const temp: number = libJudgeSdk.examJudgeSetRealExamCallback(fn);
|
||
return await handle(temp, 'examJudgeSetRealExamCallback')
|
||
}
|
||
|
||
/*
|
||
*
|
||
* @desc 设置轨迹图像回调函数
|
||
*/
|
||
export async function examJudgeMapImageSetCallback(fn: Function) {
|
||
const temp: number = libJudgeSdk.examJudgeMapImageSetCallback(fn);
|
||
return await handle(temp, 'examJudgeMapImageSetCallback')
|
||
}
|
||
|
||
/*
|
||
*
|
||
* @desc 人工扣分操作
|
||
*/
|
||
|
||
export async function examJudgeArtificialMark(
|
||
//项目代码
|
||
itemno: number,
|
||
//扣分代码
|
||
serial: string,
|
||
//扣分类型:number
|
||
type: number
|
||
) {
|
||
const temp: number = libJudgeSdk.examJudgeArtificialMark(itemno, serial, type);
|
||
return await handle(temp, 'examJudgeArtificialMark')
|
||
}
|
||
|
||
/*
|
||
*
|
||
* @desc 人工进入项目
|
||
*/
|
||
export async function examJudgeArtificialItem(
|
||
//项目代码
|
||
itemno: number,
|
||
//操作类型
|
||
type: number = 0
|
||
) {
|
||
const temp: number = libJudgeSdk.examJudgeArtificialItem(itemno, type);
|
||
return await handle(temp, 'examJudgeArtificialMark')
|
||
}
|
||
|
||
|
||
/*
|
||
*
|
||
* @desc 设置地图轨迹图像绘制的开关
|
||
*/
|
||
export async function examJudgeMapSetDrawing(bool: boolean) {
|
||
const temp: number = libJudgeSdk.examJudgeMapSetDrawing(bool);
|
||
return await handle(temp, 'examJudgeMapSetDrawing')
|
||
}
|
||
|
||
|
||
/*
|
||
*
|
||
* @desc开始考试
|
||
*/
|
||
export async function examJudgeBeginExam(data: JudgeBeginObj) {
|
||
const str = JSON.stringify(data);
|
||
const temp: number = libJudgeSdk.examJudgeBeginExam(str, str.length);
|
||
return await handle(temp, 'examJudgeBeginExam')
|
||
}
|
||
|
||
|
||
/* @params level:日志等级,infoStr:日志信息,len:数据长度
|
||
* @desc处理日志文件
|
||
*/
|
||
// export function handleLog(level, infoStr, len) {
|
||
// //TODO
|
||
// }
|
||
|
||
/*
|
||
* @desc结束考试
|
||
*
|
||
*/
|
||
export async function examJudgeEndExam() {
|
||
const temp: number = libJudgeSdk.examJudgeEndExam();
|
||
return await handle(temp, 'examJudgeEndExam')
|
||
}
|
||
|
||
/*
|
||
*@desc examJudgeDestroy
|
||
*
|
||
*/
|
||
export async function examJudgeDestroy() {
|
||
const temp: number = libJudgeSdk.examJudgeDestroy();
|
||
return await handle(temp, 'examJudgeDestroy')
|
||
}
|
||
|
||
/*
|
||
*@desc设置地图轨迹图像参数
|
||
*
|
||
*/
|
||
export async function examJudgeMapSetParam(width: number, height: number) {
|
||
const temp: number = libJudgeSdk.examJudgeMapSetParam(width, height);
|
||
return await handle(temp, 'examJudgeMapSetParam')
|
||
}
|
||
|
||
/*
|
||
*@desc设置地图图像缩放系数
|
||
*
|
||
*/
|
||
export async function examJudgeMapSetScaling(scaling?: number) {
|
||
const temp: number = libJudgeSdk.examJudgeMapSetScaling(scaling || 1);
|
||
return await handle(temp, 'examJudgeMapSetScaling')
|
||
}
|
||
|
||
/*
|
||
*@desc设置考试过程数据回调
|
||
*
|
||
*/
|
||
export async function examJudgeSetPerformCallback(fn: Function) {
|
||
const temp: number = libJudgeSdk.examJudgeSetPerformCallback(fn);
|
||
return await handle(temp, 'examJudgeSetPerformCallback')
|
||
}
|
||
|
||
/**
|
||
*
|
||
* @desc 语音播报结束
|
||
* /
|
||
*/
|
||
interface SoundParam {
|
||
//项目代码
|
||
xmdm: number,
|
||
|
||
//语音码
|
||
code: string,
|
||
|
||
//语音类型
|
||
type: 0 | 1,
|
||
}
|
||
|
||
export async function examJudgeSoundEnd(param: SoundParam) {
|
||
const temp: number = libJudgeSdk.examJudgeSoundEnd(param.xmdm, param.code, param.type);
|
||
return await handle(temp, 'examJudgeSoundEnd')
|
||
}
|
||
|
||
/**
|
||
*
|
||
* @desc 实时距离计算
|
||
*
|
||
* */
|
||
interface DistanceParam {
|
||
jd1: number,
|
||
wd1: number,
|
||
jd2: number,
|
||
wd2: number,
|
||
h: number
|
||
}
|
||
|
||
export async function examCalcGpsDistance(param: DistanceParam): Promise<number> {
|
||
const temp: number = libJudgeSdk.examCalcGpsDistance(param.jd1, param.wd1, param.jd2, param.wd2, param.h);
|
||
return temp
|
||
}
|
||
|
||
|
||
/*
|
||
* @desc通用处理函数
|
||
*
|
||
*/
|
||
async function handle(temp: number, fnName: string): Promise<number> {
|
||
return new Promise((resolve, reject) => {
|
||
if (temp == 0) {
|
||
resolve(temp);
|
||
} else {
|
||
console.log('surenjun error:' + `调用c++函数 ${fnName} 异常:` + libJudgeSdk.examJudgeErrorInfo(temp * 1))
|
||
reject(temp)
|
||
}
|
||
})
|
||
} |