forked from harmony_car/subject-two
		
	
		
			
				
	
	
		
			155 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			155 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import libJudgeSdk from 'libJudgeSdk.so'
 | ||
| // 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){
 | ||
|   const temp = libJudgeSdk.examJudgeMapImageSetCallback(fn);
 | ||
|   return await handle(temp,'examJudgeMapImageSetCallback')
 | ||
| }
 | ||
| 
 | ||
| /*
 | ||
|  *
 | ||
|  * @desc 设置地图轨迹图像绘制的开关
 | ||
|  */
 | ||
| export async function examJudgeMapSetDrawing(fn){
 | ||
|   const temp = libJudgeSdk.examJudgeMapSetDrawing(fn);
 | ||
|   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){
 | ||
|   const temp = libJudgeSdk.examJudgeMapSetParam(width,height );
 | ||
|   return await handle(temp,'examJudgeMapSetParam')
 | ||
| }
 | ||
| 
 | ||
| /*
 | ||
|  *@desc设置地图图像缩放系数
 | ||
|  *
 | ||
|  */
 | ||
| export async function examJudgeMapSetScaling(scaling?:number){
 | ||
|   const temp = libJudgeSdk.examJudgeMapSetScaling(scaling || 1);
 | ||
|   return await handle(temp,'examJudgeMapSetScaling')
 | ||
| }
 | ||
| 
 | ||
| /*
 | ||
|  *@desc设置考试过程数据回调
 | ||
|  *
 | ||
|  */
 | ||
| export async function examJudgeSetPerformCallback(fn){
 | ||
|   const temp = libJudgeSdk.examJudgeSetPerformCallback(fn);
 | ||
|   return await handle(temp,'examJudgeSetPerformCallback')
 | ||
| }
 | ||
| /*
 | ||
|  * @desc通用处理函数
 | ||
|  *
 | ||
|  */
 | ||
| async  function handle(temp,fnName):Promise<string>{
 | ||
|   return new Promise((resolve,reject)=>{
 | ||
|     if(temp == 0){
 | ||
|       resolve(temp);
 | ||
|     }else{
 | ||
|       console.log('error:' + `调用c++函数 ${fnName} 异常:`+ libJudgeSdk.examJudgeErrorInfo(temp*1))
 | ||
|       reject(temp)
 | ||
|     }
 | ||
|   })
 | ||
| } |