2025-01-21 16:52:58 +08:00

240 lines
5.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// import libJudgeSdk from 'libJudgeSdk.so'
//@ts-ignore
import libJudgeSdk from '@ohos.judgesdk'
/**
* 苏仁君
* @date 2023/04/10
* @desc 调用c++评判库
**/
/**
*
* @desc 获取版本信息
**/
export async function examJudgeVersion(){
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<string>{
const temp = libJudgeSdk.examJudgeSetLogCallback(level,handleLog);
return await handle(temp,'examJudgeSetLogCallback')
}
/*
*
* @desc评判初始化
*/
export async function examJudgeInit(data){
const str = JSON.stringify(data);
const temp = libJudgeSdk.examJudgeInit(str,str.length);
return await handle(temp,'examJudgeInit')
}
/*
*
* @desc 执行实时考试过程 实时传递传感信息
*/
export async function examJudgeRealExam(data){
const str = JSON.stringify(data);
const temp = libJudgeSdk.examJudgeRealExam(str,str.length);
return await handle(temp,'examJudgeRealExam')
}
/*
*
* @desc 设置评判输出的考试过程数据回调函数
*/
//js_examJudgeSetRealExamCallback
export async function examJudgeSetRealExamCallback(fn){
const temp = libJudgeSdk.examJudgeSetRealExamCallback(fn);
return await handle(temp,'examJudgeSetRealExamCallback')
}
/*
*
* @desc 设置轨迹图像回调函数
*/
export async function examJudgeMapImageSetCallback(fn){
console.log('examJudgeMapexamJudgeMapImageSetCallbackStart')
const temp = libJudgeSdk.examJudgeMapImageSetCallback(fn);
console.log('examJudgeMapexamJudgeMapImageSetCallbackEnd')
return await handle(temp,'examJudgeMapImageSetCallback')
}
/*
*
* @desc 人工扣分操作
*/
export async function examJudgeArtificialMark(
//项目代码
itemno:number,
//扣分代码
serial:string,
//扣分类型number
type:number
){
const temp = libJudgeSdk.examJudgeArtificialMark(itemno,serial,type);
return await handle(temp,'examJudgeArtificialMark')
}
/*
*
* @desc 人工进入项目
*/
export async function examJudgeArtificialItem(
//项目代码
itemno:number,
//操作类型
type:number = 0
){
const temp = libJudgeSdk.examJudgeArtificialItem(itemno,type);
return await handle(temp,'examJudgeArtificialMark')
}
/*
*
* @desc 设置地图轨迹图像绘制的开关
*/
export async function examJudgeMapSetDrawing(fn){
console.log('examJudgeMapexamJudgeMapSetDrawingStart')
const temp = libJudgeSdk.examJudgeMapSetDrawing(fn);
console.log('examJudgeMapexamJudgeMapSetDrawingEnd')
return await handle(temp,'examJudgeMapSetDrawing')
}
/*
*
* @desc开始考试
*/
export async function examJudgeBeginExam(data){
const str = JSON.stringify(data);
const temp = 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 = libJudgeSdk.examJudgeEndExam();
return await handle(temp,'examJudgeEndExam')
}
/*
*@desc examJudgeDestroy
*
*/
export async function examJudgeDestroy(){
const temp = libJudgeSdk.examJudgeDestroy();
return await handle(temp,'examJudgeDestroy')
}
/*
*@desc设置地图轨迹图像参数
*
*/
export async function examJudgeMapSetParam(width:number,height:number){
console.log('examJudgeMapSetstart')
const temp = libJudgeSdk.examJudgeMapSetParam(width,height );
console.log('examJudgeMapSetEnd')
return await handle(temp,'examJudgeMapSetParam')
}
/*
*@desc设置地图图像缩放系数
*
*/
export async function examJudgeMapSetScaling(scaling?:number){
console.log('examJudgeMapscanl')
const temp = libJudgeSdk.examJudgeMapSetScaling(scaling || 1);
console.log('examJudgeMapscanlend')
return await handle(temp,'examJudgeMapSetScaling')
}
/*
*@desc设置考试过程数据回调
*
*/
export async function examJudgeSetPerformCallback(fn){
const temp = libJudgeSdk.examJudgeSetPerformCallback(fn);
return await handle(temp,'examJudgeSetPerformCallback')
}
/**
*
* @desc 语音播报结束
* /
*/
export async function examJudgeSoundEnd(param:{
//项目代码
itemno:number,
//语音码
code:string,
//语音类型
type:number,
}){
const {itemno,code,type} = param;
const temp = libJudgeSdk.examJudgeSoundEnd(itemno,code,type);
return await handle(temp,'examJudgeSoundEnd')
}
/**
*
* @desc 实时距离计算
*
* */
export async function examCalcGpsDistance(param:{
jd1:number,
wd1:number,
jd2:number,
wd2:number,
h:number
}){
const {jd1,wd1,jd2,wd2,h} = param
const temp = libJudgeSdk.examCalcGpsDistance(jd1,wd1,jd2,wd2,h);
return await temp;
}
/*
* @desc通用处理函数
*
*/
async function handle(temp,fnName):Promise<string>{
return new Promise((resolve,reject)=>{
if(temp == 0){
resolve(temp);
}else{
console.log('surenjun error:' + `调用c++函数 ${fnName} 异常:`+ libJudgeSdk.examJudgeErrorInfo(temp*1))
reject(temp)
}
})
}