fix: 优化部分结构代码
This commit is contained in:
parent
f281fd369f
commit
0a5648967d
@ -1,5 +1,4 @@
|
||||
import { AmplifyItem, DefaultJudgeConfigObj, PerLane, PLCType } from '../model';
|
||||
import dayTs from '../utils/Date';
|
||||
import { AmplifyItem, DefaultJudgeConfigObj, KmItem, PerLane, PLCType } from '../model';
|
||||
|
||||
export const AmplifyArr: AmplifyItem[] = [
|
||||
{ name: '直线', projectCode: '3', projectCodeCenter: '40300' },
|
||||
@ -266,4 +265,54 @@ export const DefaultJudgeConfigData: DefaultJudgeConfigObj = {
|
||||
param_387: '0',
|
||||
//监管模式有扣分续考(0-否++1-是+把上次未考完的扣分带下来重新考试)
|
||||
param_432: '1'
|
||||
}
|
||||
}
|
||||
|
||||
//所有的科二 科目三项目
|
||||
export const testKm2Items: KmItem[] = [
|
||||
{ code: '20100', status: 0 },
|
||||
{ code: '20200', status: 0 },
|
||||
{ code: '20300', status: 0 },
|
||||
{ code: '20400', status: 0 },
|
||||
|
||||
{ code: '20500', status: 0 },
|
||||
{ code: '20600', status: 0 },
|
||||
{ code: '20700', status: 0 },
|
||||
{ code: '20800', status: 0 },
|
||||
|
||||
{ code: '20900', status: 0 },
|
||||
{ code: '21000', status: 0 },
|
||||
{ code: '21100', status: 0 },
|
||||
{ code: '21200', status: 0 },
|
||||
|
||||
{ code: '21300', status: 0 },
|
||||
{ code: '21400', status: 0 },
|
||||
{ code: '21500', status: 0 },
|
||||
{ code: '21600', status: 0 },
|
||||
|
||||
{ code: '21700', status: 0 },
|
||||
{ code: '21800', status: 0 },
|
||||
]
|
||||
|
||||
export const testKm3Items: KmItem[] = [
|
||||
{ code: '40100', status: 0 },
|
||||
{ code: '40200', status: 0 },
|
||||
{ code: '40300', status: 0 },
|
||||
{ code: '40400', status: 0 },
|
||||
|
||||
{ code: '40500', status: 0 },
|
||||
{ code: '40600', status: 0 },
|
||||
{ code: '40700', status: 0 },
|
||||
{ code: '40800', status: 0 },
|
||||
|
||||
{ code: '40900', status: 0 },
|
||||
{ code: '41000', status: 0 },
|
||||
{ code: '41100', status: 0 },
|
||||
{ code: '41200', status: 0 },
|
||||
|
||||
{ code: '41300', status: 0 },
|
||||
{ code: '41400', status: 0 },
|
||||
{ code: '41500', status: 0 },
|
||||
{ code: '41700', status: 0 },
|
||||
|
||||
{ code: '41600', status: 0 },
|
||||
]
|
||||
|
||||
@ -1,155 +0,0 @@
|
||||
package com.duolun.vehterminal.dl_frontend.port;
|
||||
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.duolun.vehterminal.dl_base.config.ExamParam;
|
||||
import com.duolun.vehterminal.dl_base.log.LogHelper;
|
||||
import com.duolun.vehterminal.dl_library.SensorCache;
|
||||
import com.duolun.vehterminal.dl_library.VehicleStatus;
|
||||
import com.duolun.vehterminal.dl_library.bean.GPSInfo;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class GpsPort extends Port{
|
||||
|
||||
private final String TAG = "GpsPort";
|
||||
|
||||
private StringBuffer gpsData = new StringBuffer();
|
||||
|
||||
private long start = System.currentTimeMillis();
|
||||
|
||||
public void start() {
|
||||
super.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleData() {
|
||||
try {
|
||||
//client.send("hello!".getBytes());
|
||||
byte[] msg = client.receive();
|
||||
if(msg == null) return;
|
||||
String revMsg = new String(msg, "US-ASCII").trim();
|
||||
String obdData = SensorCache.getInstance().getObdData();
|
||||
SensorCache.getInstance().setPlcData(obdData + revMsg);
|
||||
|
||||
if(TextUtils.isEmpty(revMsg)) return;
|
||||
long timeLen = System.currentTimeMillis() - start;
|
||||
// Log.e(TAG,"----------------revMsg--->"+revMsg);
|
||||
if(timeLen>100){
|
||||
if(!TextUtils.isEmpty(gpsData.toString())){
|
||||
GPSInfo info = getGPSInfo(gpsData.toString());
|
||||
if (info != null) {
|
||||
if (info.getMode() == 4) {
|
||||
VehicleStatus.status[VehicleStatus.GPS] = VehicleStatus.NORMAL;
|
||||
} else {
|
||||
VehicleStatus.status[VehicleStatus.GPS] = VehicleStatus.EXCEPTION;
|
||||
}
|
||||
SensorCache.getInstance().putGpsInfo(info);
|
||||
}
|
||||
}
|
||||
gpsData = new StringBuffer();
|
||||
gpsData.append(revMsg);
|
||||
}else{
|
||||
gpsData.append(revMsg);
|
||||
}
|
||||
start = System.currentTimeMillis();
|
||||
} catch (Exception e) {
|
||||
LogHelper.e(TAG,"",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private GPSInfo getGPSInfo(String data) {
|
||||
LogHelper.i(TAG, "getGPSInfo--->"+data);
|
||||
GPSInfo info = new GPSInfo();
|
||||
info.setGpsFrontNum(1);
|
||||
try {
|
||||
String[] lines = data.split("\r\n");
|
||||
for(String line:lines){
|
||||
if(line.startsWith("$KSXT")){
|
||||
getGPS(info,line);
|
||||
}else if(line.startsWith("$GPGST")){
|
||||
String[] _data = line.split(",");
|
||||
info.setLatErrorValue(Float.parseFloat(TextUtils.isEmpty(_data[6]) ? "0" : _data[6]));//维度精度因子
|
||||
info.setLongErrorValue(Float.parseFloat(TextUtils.isEmpty(_data[7]) ? "0" : _data[7]));//经度精度因子
|
||||
info.setHeightErrorValue(Float.parseFloat(_data[8].split("\\*")[0]));
|
||||
}else if(line.startsWith("#HEADINGA")){
|
||||
String[] strs = line.split(",");
|
||||
BigDecimal b = new BigDecimal(Float.parseFloat(strs[12]));
|
||||
float azimuthAngle = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
|
||||
azimuthAngle += 180;
|
||||
if (azimuthAngle > 360) {
|
||||
azimuthAngle = azimuthAngle - 360;
|
||||
}
|
||||
info.setAzimuthAngle(azimuthAngle);
|
||||
BigDecimal d = new BigDecimal(Float.parseFloat(strs[13]));
|
||||
info.setPitchAngle(d.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue());
|
||||
info.setAzimuthAngleErrorValue(Float.parseFloat(strs[15]));
|
||||
info.setPitchAngleErrorValue(Float.parseFloat(strs[16]));
|
||||
}else if(line.startsWith("$GPGGA")){
|
||||
String[] gps = line.split(",");
|
||||
int status = Integer.parseInt(TextUtils.isEmpty(gps[6]) ? "0" : gps[6]);//状态
|
||||
if (status > 0) info.setStatus(1);
|
||||
info.setMode(status);
|
||||
info.setLocationStatus(status + "");
|
||||
}
|
||||
}
|
||||
info.setGpsData(data);
|
||||
SensorCache.getInstance().putGpsInfo(info);
|
||||
} catch (Exception e) {
|
||||
LogHelper.e(TAG, "getGPSInfo->", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private void getGPS(GPSInfo gpsInfo,String signal) {
|
||||
try {
|
||||
String[] gps = signal.split(",");
|
||||
if (gps.length < 14) {
|
||||
gpsInfo.setRevTime(System.currentTimeMillis());
|
||||
SensorCache.getInstance().putGpsInfo(gpsInfo);
|
||||
LogHelper.i(TAG,signal);
|
||||
return;
|
||||
}
|
||||
gpsInfo.setMsg("#GPS," + signal);
|
||||
gpsInfo.setRevTime(System.currentTimeMillis());
|
||||
gpsInfo.setAzimuthStatus(gps[11]);
|
||||
gpsInfo.setAzimuthNum(gps[12]);
|
||||
gpsInfo.setGpsFrontNum(Integer.parseInt(TextUtils.isEmpty(gps[13]) ? "0" : gps[13]));//收星数
|
||||
gpsInfo.setHeight(Float.parseFloat(TextUtils.isEmpty(gps[4]) ? "0" : gps[4]));//海拔高度
|
||||
gpsInfo.setAge(Float.parseFloat(TextUtils.isEmpty(gps[20]) ? "0" : gps[20]));//龄期
|
||||
String pitchAngle = gps[6];//俯仰角
|
||||
gpsInfo.setPitchAngle(Float.parseFloat(TextUtils.isEmpty(pitchAngle) ? "0" : pitchAngle));
|
||||
gpsInfo.setGpsTime(gps[1]);
|
||||
gpsInfo.setLatitude(Double.parseDouble(TextUtils.isEmpty(gps[3]) ? "0" : gps[3]));//维度
|
||||
gpsInfo.setLongitude(Double.parseDouble(TextUtils.isEmpty(gps[2]) ? "0" : gps[2]));//精度
|
||||
float speed = 0;
|
||||
if (gps.length>14 && !TextUtils.isEmpty(gps[8])) {
|
||||
BigDecimal r = new BigDecimal(Float.parseFloat(gps[8]) * 1.852);
|
||||
speed = r.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
|
||||
gpsInfo.setVelocity(speed);
|
||||
}
|
||||
if ("0".equals(ExamParam.SPEED_TYPE) || TextUtils.isEmpty(ExamParam.SPEED_TYPE))
|
||||
ExamParam.SPEED = speed + "";
|
||||
} catch (Exception e) {
|
||||
LogHelper.i5(TAG, "异常数据:" + signal);
|
||||
LogHelper.i5(TAG, "异常信息:"+e.getMessage());
|
||||
gpsInfo.setRevTime(System.currentTimeMillis());
|
||||
SensorCache.getInstance().putGpsInfo(gpsInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 坐标预处理,将度分转为度
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private double translateLatLon(double a) {
|
||||
int temp1 = (int) Math.floor(a / 100);
|
||||
double temp2 = temp1 + (a - temp1 * 100) / 60;
|
||||
return temp2;
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
Find GPGST,Find GPRMC,Find GPGGA,Find PTNL,Find BESTPOSA,Find HEADINGA,Find KSXT,Find BYC,
|
||||
$GPGST,045215.20,0.03,0.01,0.03,0.0000,0.01,0.01,0.03*60
|
||||
$GPRMC,045215.20,A,3206.3460589,N,11842.1399062,E,0.022,0.0,081024,0.0,E,D*30
|
||||
$GPGGA,045215.20,3206.3460589,N,11842.1399062,E,4,42,0.5,1.935,M,0.592,M,3.200,0000*7A
|
||||
$PTNL,AVR,045215.20,+66.5809,Yaw,-1.1687,Tilt,,,1.288,3,1.2,38*01
|
||||
$KSXT,20241008045215.20,118.70233177,32.10576765,2.5270,66.58,-1.17,70.35,0.040,,3,3,38,42,-45.675,-21.352,-2.137,0.038,0.013,0.015,3.2,40,*8BA53C1A
|
||||
#BESTPOSA,COM1,0,87.5,FINESTEERING,2335,190353.200,00000000,0000,782;SOL_COMPUTED,NARROW_INT,32.10576764819,118.70233176936,1.9353,0.5917,WGS84,0.0132,0.0118,0.0253,"0",3.200,0.034,44,42,42,42,00,00,30,37*77b805ad
|
||||
#HEADINGA,COM1,0,87.5,FINESTEERING,2335,190353.200,00000000,0000,782;SOL_COMPUTED,NARROW_INT,1.287597299,66.580940247,-1.168731809,0.0,0.808748186,0.807274878,"0",44,38,44,26,0,00,30,37*3e44d092
|
||||
#BYCHECKA,COM1,0,87.5,FINESTEERING,2335,190353.200,00000000,0000,782;1268,2335,190353.200,1,1,1,0,1,1,1,1,1,1,1,1*c786fc2a
|
||||
File diff suppressed because it is too large
Load Diff
@ -1 +0,0 @@
|
||||
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
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,6 +0,0 @@
|
||||
{
|
||||
"jxm":20100,
|
||||
"qxxm":20200,
|
||||
"kf":{"xmdm":20100, "kfdm":"001"},
|
||||
"mndg":[20100,20101,20102]
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
{
|
||||
"ic": "xxx",
|
||||
"kgid": "1002",
|
||||
"kgxm": "考官姓名",
|
||||
"exam": 1,
|
||||
"track": 0,
|
||||
"xm": "张三",
|
||||
"sex": 0,
|
||||
"kslsh": "1234567890",
|
||||
"sfzmhm": "32038219990808012X",
|
||||
"ksyy": "A",
|
||||
"kscx": "C1",
|
||||
"kkcs": 2,
|
||||
"sfyk": 0,
|
||||
"ykkkcs": 1,
|
||||
"wayno": 5,
|
||||
"czlx": 0,
|
||||
"kskssj": 1680840026000,
|
||||
"ksxm": [{
|
||||
"xmdm": 5,
|
||||
"xmxh": "01"
|
||||
}, {
|
||||
"xmdm": 6,
|
||||
"xmxh": "02"
|
||||
}],
|
||||
"ddxk": 0,
|
||||
"ddkssj": 1680840026000,
|
||||
"ykxm": [5, 6],
|
||||
"kfxm": [{
|
||||
"xmdm": 5,
|
||||
"kfdm": "01"
|
||||
}, {
|
||||
"xmdm": 6,
|
||||
"kfdm": "02"
|
||||
}],
|
||||
"yklc": 500,
|
||||
"special": [1, 2,3]
|
||||
}
|
||||
@ -1,20 +0,0 @@
|
||||
{
|
||||
"kskm": 2,
|
||||
"kchp": "苏A88888",
|
||||
"kchm": 1,
|
||||
"kscx": "C1",
|
||||
"cxcode": "1",
|
||||
"name": "桑塔纳",
|
||||
"allitems": [{
|
||||
"xmdm": 5,
|
||||
"kfdm": "01"
|
||||
}, {
|
||||
"xmdm": 6,
|
||||
"kfdm": "01"
|
||||
},
|
||||
{
|
||||
"xmdm": 6,
|
||||
"kfdm": "02"
|
||||
}
|
||||
]
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
||||
ex
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,102 +0,0 @@
|
||||
{
|
||||
"sensor": {
|
||||
"aqd": 1,
|
||||
"mkg": 0,
|
||||
"ssc": 1,
|
||||
"jsc": 0,
|
||||
"fsc": 0,
|
||||
"lhq": 0,
|
||||
"lb": 0,
|
||||
"skd": 0,
|
||||
"jgd": 0,
|
||||
"ygd": 1,
|
||||
"zfxd": 1,
|
||||
"yfxd": 0,
|
||||
"shtd": 0,
|
||||
"wd": 0,
|
||||
"ygq": 0,
|
||||
"dh1": 1,
|
||||
"dh2": 0,
|
||||
"fdjzs": 2400,
|
||||
"dw": 0,
|
||||
"cs": 5.8,
|
||||
"fxp": -5,
|
||||
"ljmc": 23,
|
||||
"lcmc": 0,
|
||||
"csb1": 3000,
|
||||
"csb2": 0,
|
||||
"csb3": 0,
|
||||
"csb4": 0,
|
||||
"zy": 0,
|
||||
"tbp": 0,
|
||||
"hsj": 0,
|
||||
"dcj": 0,
|
||||
"gx": 123070,
|
||||
"yl": 0
|
||||
},
|
||||
"gps": {
|
||||
"bklx":2,
|
||||
"dwzt":4,
|
||||
"jdzt":4,
|
||||
"sj": 1680840026000,
|
||||
"jd": 113.12345678,
|
||||
"wd": 31.12345678,
|
||||
"hxj": 50.1234,
|
||||
"fyj": 1.1234,
|
||||
"hbg": 22.123,
|
||||
"gdc": 1.123,
|
||||
"sd": 10.9,
|
||||
"age": 1.2,
|
||||
"jdyz": 0.001,
|
||||
"wdyz": 0.001,
|
||||
"dwsxs": 17,
|
||||
"jdsxs": 14
|
||||
},
|
||||
"gps2": {
|
||||
"bklx":1,
|
||||
"dwzt":4,
|
||||
"jdzt":4,
|
||||
"sj": 1680840026000,
|
||||
"jd": 113.12345678,
|
||||
"wd": 31.12345678,
|
||||
"hxj": 50.1234,
|
||||
"fyj": 1.1234,
|
||||
"hbg": 22.123,
|
||||
"gdc": 1.123,
|
||||
"sd": 10.9,
|
||||
"age": 1.2,
|
||||
"jdyz": 0.001,
|
||||
"wdyz": 0.001,
|
||||
"dwsxs": 17,
|
||||
"jdsxs": 14
|
||||
},
|
||||
"vision": {
|
||||
"sj": 1680840026000,
|
||||
"score": 0.85,
|
||||
"zyjd": 60.23,
|
||||
"sxjd": 65.33,
|
||||
"ytjd": 68.45,
|
||||
"fxp": 2,
|
||||
"ch": 0,
|
||||
"hld": 1
|
||||
},
|
||||
"radar": {
|
||||
"sj": 1680840026000,
|
||||
"zxh": 999,
|
||||
"qfsj": [{"bh": 1,"lx": 1,"jl": 2.35,"sd": 3.68}, {"bh": 2,"lx": 2 ,"jl": 4.82,"sd": 5.24}],
|
||||
"hfsj": [{"bh": 1,"lx": 1,"jl": 2.35,"sd": 3.68}, {"bh": 2,"lx": 2 , "jl": 4.82,"sd": 5.24}],
|
||||
"zqsj": [{"bh": 1,"lx": 1,"jl": 2.35,"sd": 3.68}, {"bh": 2,"lx": 2 , "jl": 4.82,"sd": 5.24}],
|
||||
"zhsj": [{"bh": 1,"lx": 1,"jl": 2.35,"sd": 3.68}, {"bh": 2,"lx": 2 , "jl": 4.82,"sd": 5.24}],
|
||||
"zcsj": [{"bh": 1,"lx": 1,"jl": 2.35,"sd": 3.68}, {"bh":2,"lx": 2 , "jl": 4.82,"sd": 5.24}],
|
||||
"yqsj": [{"bh": 1,"lx": 1,"jl": 2.35,"sd": 3.68}, {"bh":2,"lx": 2 , "jl": 4.82,"sd": 5.24}],
|
||||
"yhsj": [{"bh": 1,"lx": 1,"jl": 2.35,"sd": 3.68}, {"bh":2,"lx": 2 , "jl": 4.82,"sd": 5.24}],
|
||||
"ycsj": [{"bh": 1,"lx": 1,"jl": 2.35,"sd": 3.68}, {"bh": 2,"lx": 2 , "jl": 4.82,"sd": 5.24}],
|
||||
"fqsj": [{"bh": 1,"lx": 1,"jl": 2.35,"sd": 3.68}, {"bh":2,"lx": 2 , "jl": 4.82,"sd": 5.24}],
|
||||
"qfwt": {"xrjl": 2.357,"zawjl": 3.608},
|
||||
"rcyz": 1,
|
||||
"show":[{"bh":1,"zb": [{"x": 0, "y": 1},{"x": 0, "y": 1},{"x": 0, "y": 1},{"x": 0, "y":1}]},
|
||||
{"bh":2,"zb": [{"x": 0, "y": 1},{"x": 0, "y": 1},{"x": 0, "y": 1},{"x": 0, "y": 1}]}]
|
||||
},
|
||||
"extend": {
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,6 @@ import systemTime from '@ohos.systemDateTime';
|
||||
import router from '@ohos.router';
|
||||
import util from '@ohos.util';
|
||||
import buffer from '@ohos.buffer';
|
||||
import { testKm2Items, testKm3Items } from './dataTest/index';
|
||||
|
||||
import VoiceAnnounce from './utils/voiceAnnouncements';
|
||||
import FileModel from './utils/fileModel';
|
||||
@ -79,6 +78,7 @@ import {
|
||||
} from '../Judge/utils';
|
||||
import { DifferentialAndSignal } from '../../utils/business/DifferentialAndSignalWorker';
|
||||
import { dConsole } from '../../utils/LogWorker';
|
||||
import { testKm2Items, testKm3Items } from '../../mock';
|
||||
|
||||
|
||||
type GetKm3JudgeInitConfig = () => Promise<Km3JudgeInitConfig>
|
||||
@ -184,47 +184,6 @@ export default class Judge {
|
||||
private isExamEnd: boolean
|
||||
// 是否发送udp
|
||||
private isUdpEnd: boolean = false
|
||||
// 处理udp plc信号
|
||||
handleUdp = async (msg: string) => {
|
||||
const stachArr = msg.split(',')
|
||||
if (stachArr[0] != '#DN_GD' || this.isUdpEnd) {
|
||||
return
|
||||
}
|
||||
const gpsPart = msg.split("#END$GPS,")[1];
|
||||
const gpsStatus = gpsPart.split(",")[0];
|
||||
if (gpsStatus === "4") {
|
||||
dConsole.log(JudgeTag, "差分状态正常", gpsStatus)
|
||||
this.judgeUI.isDwztRight = true
|
||||
} else {
|
||||
dConsole.log(JudgeTag, "差分状态异常", gpsStatus)
|
||||
this.judgeUI.isDwztRight = false
|
||||
}
|
||||
this.judgeUI.isDwztRight
|
||||
const plcData = await this.getPlcData(msg);
|
||||
// 4.过程数据
|
||||
await this.fileLog?.setExamJudgeData(JSON.stringify(plcData))
|
||||
//检测到有无锡所设备接入,需要发送特定的数据,供检测
|
||||
// if (this.usbService.isWXUSBDevice) {
|
||||
// const str = await senorToWXDataStr(msg);
|
||||
// this.usbService.sendUSB(str)
|
||||
// }
|
||||
const param350: number = Reflect.get(this.judgeUI.judgeConfigObj, '350')
|
||||
this.judgeUI.sd = ((param350 == 0 ? plcData.gps.sd : plcData.sensor.cs) as number * 1.852).toFixed(0) + ''
|
||||
this.judgeUI.dw = (Math.floor(plcData.sensor.dw as number) || 0) + ''
|
||||
//TODO 暂时关闭差分检测异常
|
||||
// await this.checkDwzt(plcData.gps.dwzt,plcData.gps.jdzt);
|
||||
if (!this.isExamEnd) {
|
||||
await examJudgeRealExam(plcData)
|
||||
}
|
||||
// let udpIndex = AppStorage.get<number>('udpIndex') || 0;
|
||||
// if (udpIndex % 5 === 0 && !this.isUdpEnd) {
|
||||
// TODO UPD缺失
|
||||
// const judgeUdp = globalThis.judgeUdp
|
||||
// const bytes = await this.getMessageHeartbeat(this.isExamEnd);
|
||||
// judgeUdp.send(bytes)
|
||||
// }
|
||||
// AppStorage.setOrCreate('udpIndex', udpIndex++)
|
||||
}
|
||||
//是否手动结束考试
|
||||
private isManual: boolean = false
|
||||
//UDP服务序列号
|
||||
@ -271,60 +230,6 @@ export default class Judge {
|
||||
dConsole.info(JudgeTag, '过程数据文件上传 end')
|
||||
}
|
||||
private judgeTask: JudgeTask
|
||||
// 检测扣分、结束项目时该项目是否开始
|
||||
checkProjectIsStart = async (xmdm: number, currentType: 1 | 2, kf?: MarkRule) => {
|
||||
if (xmdm == 20) {
|
||||
return true
|
||||
}
|
||||
const judgeUI = this.judgeUI;
|
||||
const judgeTask = this.judgeTask;
|
||||
const projectsObj: object = this.judgeUI.projectsObj
|
||||
const currentProject: ProjectInfo = Reflect.get(projectsObj, xmdm)
|
||||
const isUpload = currentProject.isUpload
|
||||
|
||||
//如果项目没有开始
|
||||
dConsole.info(JudgeTag, 'surenjun isUpload=>', isUpload)
|
||||
if (!isUpload) {
|
||||
dConsole.info(JudgeTag, '项目补传开始')
|
||||
//项目开始补传
|
||||
judgeTask.addTask(async () => {
|
||||
await this.beginProject(xmdm)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
judgeTask.addTask(async () => {
|
||||
await this.uploadProgressPhoto(xmdm)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
currentProject.isUpload = true;
|
||||
Reflect.set(this.judgeUI.projectsObj, xmdm, currentProject)
|
||||
//扣分补传
|
||||
if (currentType == 2) {
|
||||
judgeTask.addTask(async () => {
|
||||
await this.pointsDedute(xmdm, kf!)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
}
|
||||
//扣分补传判断是否合格 不合格补传项目结束
|
||||
if (currentType == 1 || (currentType == 2 && this.totalScore < judgeUI.passingScore)) {
|
||||
judgeTask.addTask(async () => {
|
||||
await this.endProject(xmdm)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
currentProject.isEnd = true;
|
||||
Reflect.set(this.judgeUI.projectsObj, xmdm, currentProject)
|
||||
}
|
||||
judgeTask.addTask(async () => {
|
||||
this.checkExamIsEnd()
|
||||
})
|
||||
return false;
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
private tempData?: PLCType
|
||||
//实时计算gps经纬度距离
|
||||
handDistance = async () => {
|
||||
@ -373,40 +278,46 @@ export default class Judge {
|
||||
AppStorage.setOrCreate('msgStr', plc)
|
||||
return tempData
|
||||
}
|
||||
// 处理轨迹plc信号
|
||||
handleTrajectoryUdp = async (strArr: string[]) => {
|
||||
let num = 2;
|
||||
const judgeTimer = setInterval(async () => {
|
||||
const msgStr = strArr[num];
|
||||
if (msgStr == '') {
|
||||
dConsole.info(JudgeTag, '模拟数据考试结束')
|
||||
clearInterval(judgeTimer)
|
||||
this.checkExamIsEnd(true)
|
||||
return
|
||||
}
|
||||
const msg: PLCType = JSON.parse(strArr[num]);
|
||||
num++
|
||||
// 4.过程数据
|
||||
this.tempData = msg
|
||||
// this.judgeUI.isDwztRight = (msg?.gps?.dwzt == 4 && msg?.gps?.jdzt == 3);
|
||||
this.judgeUI.sd = Math.floor(msg?.gps?.sd * 1.852) + '';
|
||||
this.judgeUI.dw = Math.floor(msg?.sensor?.dw) + ''
|
||||
this.plcData = msg
|
||||
// this.judgeUI.isDwztRight = msg.gps.dwzt == 4;
|
||||
AppStorage.setOrCreate('msgStr', '')
|
||||
if (msg.method === 'examJudgeArtificialItem') {
|
||||
this.setJudgeItem(msg.itemno, msg.type)
|
||||
}
|
||||
if (msg.method === 'examJudgeArtificialMark') {
|
||||
this.setJudgeItem(msg.itemno, msg.serial)
|
||||
}
|
||||
await examJudgeRealExam(msg)
|
||||
// const bytes = await this.getMessageHeartbeat();
|
||||
// bytes && globalThis.judgeUdp.send(bytes)
|
||||
|
||||
}, 200)
|
||||
// TODO 定时器缺失
|
||||
// globalThis.judgeTimer = judgeTimer;
|
||||
// 处理udp plc信号
|
||||
handleUdp = async (msg: string) => {
|
||||
const stachArr = msg.split(',')
|
||||
if (stachArr[0] != '#DN_GD' || this.isUdpEnd) {
|
||||
return
|
||||
}
|
||||
const gpsPart = msg.split("#END$GPS,")[1];
|
||||
const gpsStatus = gpsPart.split(",")[0];
|
||||
if (gpsStatus === "4") {
|
||||
dConsole.log(JudgeTag, "差分状态正常", gpsStatus)
|
||||
this.judgeUI.isDwztRight = true
|
||||
} else {
|
||||
dConsole.log(JudgeTag, "差分状态异常", gpsStatus)
|
||||
this.judgeUI.isDwztRight = false
|
||||
}
|
||||
this.judgeUI.isDwztRight
|
||||
const plcData = await this.getPlcData(msg);
|
||||
// 4.过程数据
|
||||
await this.fileLog?.setExamJudgeData(JSON.stringify(plcData))
|
||||
//检测到有无锡所设备接入,需要发送特定的数据,供检测
|
||||
// if (this.usbService.isWXUSBDevice) {
|
||||
// const str = await senorToWXDataStr(msg);
|
||||
// this.usbService.sendUSB(str)
|
||||
// }
|
||||
const param350: number = Reflect.get(this.judgeUI.judgeConfigObj, '350')
|
||||
this.judgeUI.sd = ((param350 == 0 ? plcData.gps.sd : plcData.sensor.cs) as number * 1.852).toFixed(0) + ''
|
||||
this.judgeUI.dw = (Math.floor(plcData.sensor.dw as number) || 0) + ''
|
||||
//TODO 暂时关闭差分检测异常
|
||||
// await this.checkDwzt(plcData.gps.dwzt,plcData.gps.jdzt);
|
||||
if (!this.isExamEnd) {
|
||||
await examJudgeRealExam(plcData)
|
||||
}
|
||||
// let udpIndex = AppStorage.get<number>('udpIndex') || 0;
|
||||
// if (udpIndex % 5 === 0 && !this.isUdpEnd) {
|
||||
// TODO UPD缺失
|
||||
// const judgeUdp = globalThis.judgeUdp
|
||||
// const bytes = await this.getMessageHeartbeat(this.isExamEnd);
|
||||
// judgeUdp.send(bytes)
|
||||
// }
|
||||
// AppStorage.setOrCreate('udpIndex', udpIndex++)
|
||||
}
|
||||
private isEndTip: boolean = false;
|
||||
//本地轨迹回放地址
|
||||
@ -427,6 +338,32 @@ export default class Judge {
|
||||
const code = await writeObjectOut(JSON.parse(examDataStr), "", this.context);
|
||||
}
|
||||
}
|
||||
private artSubject3ProjectsCodesArr: number[] = [3, 9, 4, 10, 12, 11]
|
||||
private lane: LANE = {
|
||||
road: '', num: 0, count: 0
|
||||
}
|
||||
private disConnectNum: number = 0;
|
||||
//调用监管接口
|
||||
sendWriteObjectOut: SendWriteObjectOut = async (data, filePath) => {
|
||||
const temp = await writeObjectOut(data, filePath, this.context);
|
||||
dConsole.log(JudgeTag, "wzj", JSON.stringify(temp))
|
||||
//断网&网络超时次数计算
|
||||
if (temp.code == 2300007 || temp.code == 2300028) {
|
||||
this.disConnectNum += 1;
|
||||
if (this.disConnectNum < 5) {
|
||||
return await this.sendWriteObjectOut(data, filePath)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.disConnectNum >= 5) {
|
||||
dConsole.info('surenjun', '123')
|
||||
this.judgeUI.errorMsg = '当前的考试过程信息网络传输异常,程序点击确认将重启!';
|
||||
this.judgeUI.disConnectErrorOpen = true
|
||||
}
|
||||
|
||||
this.disConnectNum = 0
|
||||
return temp
|
||||
}
|
||||
// 项目开始接口同步
|
||||
beginProject = async (ksxm: number) => {
|
||||
const carInfo = AppStorage.get<CarInfoType>('carInfo');
|
||||
@ -530,32 +467,6 @@ export default class Judge {
|
||||
UploadRegulatoryCodeConversion('17C54', temp.code || 0)
|
||||
dConsole.info(JudgeTag, '上传照片 end')
|
||||
}
|
||||
private artSubject3ProjectsCodesArr: number[] = [3, 9, 4, 10, 12, 11]
|
||||
private lane: LANE = {
|
||||
road: '', num: 0, count: 0
|
||||
}
|
||||
private disConnectNum: number = 0;
|
||||
//调用监管接口
|
||||
sendWriteObjectOut: SendWriteObjectOut = async (data, filePath) => {
|
||||
const temp = await writeObjectOut(data, filePath, this.context);
|
||||
dConsole.log(JudgeTag, "wzj", JSON.stringify(temp))
|
||||
//断网&网络超时次数计算
|
||||
if (temp.code == 2300007 || temp.code == 2300028) {
|
||||
this.disConnectNum += 1;
|
||||
if (this.disConnectNum < 5) {
|
||||
return await this.sendWriteObjectOut(data, filePath)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.disConnectNum >= 5) {
|
||||
dConsole.info('surenjun', '123')
|
||||
this.judgeUI.errorMsg = '当前的考试过程信息网络传输异常,程序点击确认将重启!';
|
||||
this.judgeUI.disConnectErrorOpen = true
|
||||
}
|
||||
|
||||
this.disConnectNum = 0
|
||||
return temp
|
||||
}
|
||||
private videoData?: RecordHandleType
|
||||
//当前科目二的考试项目
|
||||
private deductedPopShowTimer: number = 0;
|
||||
@ -674,6 +585,95 @@ export default class Judge {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 检测扣分、结束项目时该项目是否开始
|
||||
checkProjectIsStart = async (xmdm: number, currentType: 1 | 2, kf?: MarkRule) => {
|
||||
if (xmdm == 20) {
|
||||
return true
|
||||
}
|
||||
const judgeUI = this.judgeUI;
|
||||
const judgeTask = this.judgeTask;
|
||||
const projectsObj: object = this.judgeUI.projectsObj
|
||||
const currentProject: ProjectInfo = Reflect.get(projectsObj, xmdm)
|
||||
const isUpload = currentProject.isUpload
|
||||
|
||||
//如果项目没有开始
|
||||
dConsole.info(JudgeTag, 'surenjun isUpload=>', isUpload)
|
||||
if (!isUpload) {
|
||||
dConsole.info(JudgeTag, '项目补传开始')
|
||||
//项目开始补传
|
||||
judgeTask.addTask(async () => {
|
||||
await this.beginProject(xmdm)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
judgeTask.addTask(async () => {
|
||||
await this.uploadProgressPhoto(xmdm)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
currentProject.isUpload = true;
|
||||
Reflect.set(this.judgeUI.projectsObj, xmdm, currentProject)
|
||||
//扣分补传
|
||||
if (currentType == 2) {
|
||||
judgeTask.addTask(async () => {
|
||||
await this.pointsDedute(xmdm, kf!)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
}
|
||||
//扣分补传判断是否合格 不合格补传项目结束
|
||||
if (currentType == 1 || (currentType == 2 && this.totalScore < judgeUI.passingScore)) {
|
||||
judgeTask.addTask(async () => {
|
||||
await this.endProject(xmdm)
|
||||
}, {
|
||||
isDelay: true
|
||||
})
|
||||
currentProject.isEnd = true;
|
||||
Reflect.set(this.judgeUI.projectsObj, xmdm, currentProject)
|
||||
}
|
||||
judgeTask.addTask(async () => {
|
||||
this.checkExamIsEnd()
|
||||
})
|
||||
return false;
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
// 处理轨迹plc信号
|
||||
handleTrajectoryUdp = async (strArr: string[]) => {
|
||||
let num = 2;
|
||||
const judgeTimer = setInterval(async () => {
|
||||
const msgStr = strArr[num];
|
||||
if (msgStr == '') {
|
||||
dConsole.info(JudgeTag, '模拟数据考试结束')
|
||||
clearInterval(judgeTimer)
|
||||
this.checkExamIsEnd(true)
|
||||
return
|
||||
}
|
||||
const msg: PLCType = JSON.parse(strArr[num]);
|
||||
num++
|
||||
// 4.过程数据
|
||||
this.tempData = msg
|
||||
// this.judgeUI.isDwztRight = (msg?.gps?.dwzt == 4 && msg?.gps?.jdzt == 3);
|
||||
this.judgeUI.sd = Math.floor(msg?.gps?.sd * 1.852) + '';
|
||||
this.judgeUI.dw = Math.floor(msg?.sensor?.dw) + ''
|
||||
this.plcData = msg
|
||||
// this.judgeUI.isDwztRight = msg.gps.dwzt == 4;
|
||||
AppStorage.setOrCreate('msgStr', '')
|
||||
if (msg.method === 'examJudgeArtificialItem') {
|
||||
this.setJudgeItem(msg.itemno, msg.type)
|
||||
}
|
||||
if (msg.method === 'examJudgeArtificialMark') {
|
||||
this.setJudgeItem(msg.itemno, msg.serial)
|
||||
}
|
||||
await examJudgeRealExam(msg)
|
||||
// const bytes = await this.getMessageHeartbeat();
|
||||
// bytes && globalThis.judgeUdp.send(bytes)
|
||||
|
||||
}, 200)
|
||||
// TODO 定时器缺失
|
||||
// globalThis.judgeTimer = judgeTimer;
|
||||
}
|
||||
|
||||
constructor(judgeUI: JudgeUI) {
|
||||
this.serialIndex = 1;
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
import WebRtcModel, { WebRtcState } from './model/WebRtcModel';
|
||||
import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import prompt from '@ohos.prompt'
|
||||
import ethernet from '@ohos.net.ethernet';
|
||||
|
||||
const TAG: string = '[webRTCVoice]';
|
||||
|
||||
export default class WebRTCVoice{
|
||||
|
||||
private context:common.UIAbilityContext;
|
||||
private atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
|
||||
private webRtcModel: WebRtcModel = new WebRtcModel()
|
||||
|
||||
//TODO ourId待替换
|
||||
private ourId: string = 'surenjun'
|
||||
private peerId: string = ''
|
||||
private state: string = '暂未连接'
|
||||
|
||||
constructor(context) {
|
||||
this.context = context;
|
||||
this.init()
|
||||
}
|
||||
|
||||
handleStateChange = (state, message) => {
|
||||
console.log(TAG, "on state change, message:" + message);
|
||||
this.state = message;
|
||||
}
|
||||
|
||||
init = () => {
|
||||
const {webRtcModel,ourId,context,handleStateChange} = this;
|
||||
webRtcModel.setContext(context);
|
||||
webRtcModel.initWebSocket(ourId, handleStateChange);
|
||||
webRtcModel.initRtc();
|
||||
|
||||
try {
|
||||
this.atManager.requestPermissionsFromUser(context, ['ohos.permission.MICROPHONE'], (err, data) => {
|
||||
console.info('data:' + JSON.stringify(data));
|
||||
console.info('data permissions:' + data.permissions);
|
||||
console.info('data authResults:' + data.authResults);
|
||||
});
|
||||
// prompt.showToast({
|
||||
// message: '语音对讲初始化完成',
|
||||
// duration: 2000
|
||||
// });
|
||||
} catch (err) {
|
||||
console.log(`catch err->${JSON.stringify(err)}`);
|
||||
}
|
||||
}
|
||||
|
||||
aboutToDisappear = () => {
|
||||
const {webRtcModel} = this;
|
||||
webRtcModel.disappearWebSocket()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,333 +0,0 @@
|
||||
import media from '@ohos.multimedia.media';
|
||||
import webSocket from '@ohos.net.webSocket';
|
||||
import prompt from '@ohos.prompt';
|
||||
|
||||
const TAG_RTC: string = '[SURENJUN_RTC]';
|
||||
|
||||
const carNo = AppStorage.get<CarInfoType>('carInfo').carNo;
|
||||
const WS_SERVER = `ws://192.168.36.9:5000/ws/KM2-C${carNo}/2`;
|
||||
|
||||
// const WS_SERVER = 'wss://webrtc.nirbheek.in:8443';
|
||||
// const WS_SERVER = 'wss://webrtc.youzhi.life:8443';
|
||||
export enum WebRtcState {
|
||||
UNKNOWN = 0,
|
||||
ERROR = 1,
|
||||
|
||||
SERVER_CONNECTING = 100,
|
||||
SERVER_CONNECTED,
|
||||
SERVER_REGISTERING,
|
||||
SERVER_REGISTERED,
|
||||
SERVER_CLOSED,
|
||||
|
||||
PEER_NEGOTIATING = 200
|
||||
}
|
||||
|
||||
export default class WebRtcModel {
|
||||
public isConnected: boolean = false;
|
||||
sendIceCandidate = async (icecandidate: any) => {
|
||||
const { peerId, remoteUserId } = this
|
||||
this.sendMessage(JSON.stringify({
|
||||
eventName: '__ice_candidate',
|
||||
data: {
|
||||
userID: remoteUserId,
|
||||
id: 'audio',
|
||||
label: 0,
|
||||
fromId: peerId,
|
||||
candidate: icecandidate.candidate
|
||||
}
|
||||
}));
|
||||
}
|
||||
private ourId: string = '';
|
||||
//TODO 待替换
|
||||
private peerId: string = `KM2-C${carNo}`;
|
||||
private remoteUserId: string = '';
|
||||
// private state: number = WebRtcState.UNKNOWN;
|
||||
private roomId: string = '';
|
||||
private context: any = undefined;
|
||||
private ws: webSocket.WebSocket = undefined;
|
||||
private webrtc: media.WebRtc = undefined;
|
||||
sendAnswer = async () => {
|
||||
const { peerId:fromID, remoteUserId:userID } = this;
|
||||
console.info(TAG_RTC, 'surenjun')
|
||||
try {
|
||||
let answer = await this.webrtc.createAnswer();
|
||||
console.info(TAG_RTC, 'createAnswer: ' + JSON.stringify(answer));
|
||||
|
||||
this.webrtc.setLocalDescription(answer);
|
||||
|
||||
this.sendMessage(JSON.stringify({
|
||||
eventName: '__answer',
|
||||
data: {
|
||||
userID,
|
||||
fromID,
|
||||
label: 0,
|
||||
id: 'audio',
|
||||
sdp: answer.sdp
|
||||
}
|
||||
}))
|
||||
this.isConnected = true;
|
||||
} catch (e) {
|
||||
console.error(TAG_RTC, 'createAnswer: ' + JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
receiveSdp = async (sdp) => {
|
||||
let type = sdp.type as string;
|
||||
// let text = json.sdp.text as string;
|
||||
if (type === 'offer') {
|
||||
this.webrtc.setRemoteDescription(sdp);
|
||||
this.sendAnswer();
|
||||
prompt.showToast({
|
||||
message: '语音对讲连接完成',
|
||||
duration: 4000
|
||||
});
|
||||
} else if (type === 'answer') {
|
||||
this.webrtc.setRemoteDescription(sdp);
|
||||
}
|
||||
}
|
||||
private stateCallback: (state: number, message: string) => void = undefined;
|
||||
sendOffer = async () => {
|
||||
const { peerId:fromID, remoteUserId:userID } = this;
|
||||
try {
|
||||
let offer = await this.webrtc.createOffer();
|
||||
this.webrtc.setLocalDescription(offer);
|
||||
if (this.stateCallback) {
|
||||
this.stateCallback(WebRtcState.PEER_NEGOTIATING, '发送Offer');
|
||||
}
|
||||
this.sendMessage(JSON.stringify({
|
||||
eventName: '__answer',
|
||||
data: {
|
||||
userID,
|
||||
fromID,
|
||||
label: 0,
|
||||
id: 'audio',
|
||||
sdp: offer.sdp
|
||||
}
|
||||
}))
|
||||
} catch (e) {
|
||||
console.error(TAG_RTC, 'createOffer: ' + JSON.stringify(e));
|
||||
}
|
||||
}
|
||||
|
||||
initWebSocket(ourId: string, handleStateChange: (state, message) => void) {
|
||||
|
||||
this.ourId = ourId;
|
||||
this.stateCallback = handleStateChange;
|
||||
this.ws = webSocket.createWebSocket()
|
||||
this.ws.on('open', (err, value) => {
|
||||
console.info(TAG_RTC, '信令服务器连接成功');
|
||||
// prompt.showToast({
|
||||
// message: '语音对讲服务器连接成功',
|
||||
// duration: 2000
|
||||
// });
|
||||
});
|
||||
this.ws.connect(WS_SERVER, (err, success) => {
|
||||
console.info(TAG_RTC, 'connect: ' + (success ? "success" : "error"));
|
||||
});
|
||||
this.ws.on('error', (err) => {
|
||||
console.info(TAG_RTC, '信令服务器连接失败');
|
||||
});
|
||||
|
||||
this.ws.on('message', (err, value: string) => {
|
||||
const { acceptInvited, receiveIce, sendAnswer, receiveSdp, disconnect } = this;
|
||||
const socketMessage = JSON.parse(value);
|
||||
const {
|
||||
eventName, data:{
|
||||
candidate,
|
||||
sdp,
|
||||
room,
|
||||
userID,
|
||||
inviteID: fromId,
|
||||
toID
|
||||
}
|
||||
} = socketMessage;
|
||||
|
||||
console.info(TAG_RTC, 'receive message =>' + eventName.split('__')[1])
|
||||
switch (eventName.split('__')[1]) {
|
||||
|
||||
//离开
|
||||
case 'leave':
|
||||
disconnect();
|
||||
break
|
||||
|
||||
//收到对方邀请通知
|
||||
case 'invite':
|
||||
acceptInvited(fromId, room);
|
||||
break;
|
||||
|
||||
//对方接受通话邀请
|
||||
case 'new_peer':
|
||||
|
||||
//添加ice证书
|
||||
case 'ice_candidate':
|
||||
receiveIce(candidate);
|
||||
break;
|
||||
|
||||
case 'answer':
|
||||
// sendAnswer()
|
||||
|
||||
case 'offer':
|
||||
receiveSdp({
|
||||
type: 'offer', sdp
|
||||
});
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
/****************************************************************************************************************/
|
||||
|
||||
if (value === 'HELLO') {
|
||||
|
||||
} else if (value === 'SESSION_OK') {
|
||||
if (this.stateCallback) {
|
||||
this.stateCallback(WebRtcState.PEER_NEGOTIATING, '开始协商');
|
||||
}
|
||||
this.sendOffer();
|
||||
} else if (value === 'OFFER_REQUEST') {
|
||||
if (this.stateCallback) {
|
||||
this.stateCallback(WebRtcState.PEER_NEGOTIATING, '对端请求由本机发起协商');
|
||||
}
|
||||
this.sendOffer();
|
||||
} else {
|
||||
var json = undefined;
|
||||
try {
|
||||
json = JSON.parse(value as string);
|
||||
} catch (error) {
|
||||
console.error(TAG_RTC, 'receive invalid message: ' + value);
|
||||
}
|
||||
|
||||
if (json && json.sdp) {
|
||||
this.receiveSdp(json.sdp);
|
||||
} else if (json && json.ice) {
|
||||
this.receiveIce(json.ice);
|
||||
} else {
|
||||
// console.error(TAG_RTC, 'receive unknown message: ' + value);
|
||||
}
|
||||
}
|
||||
});
|
||||
this.ws.on('close', (err, value) => {
|
||||
console.info(TAG_RTC, 'websocket connection closed');
|
||||
handleStateChange(WebRtcState.SERVER_CLOSED, '服务器连接已断开');
|
||||
this.webrtc.close();
|
||||
});
|
||||
this.ws.on('error', (err) => {
|
||||
handleStateChange(WebRtcState.ERROR, 'ERROR: ' + err.code)
|
||||
});
|
||||
|
||||
if (this.stateCallback) {
|
||||
this.stateCallback(WebRtcState.SERVER_CONNECTING, '开始连接服务器');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async initRtc() {
|
||||
this.webrtc = await media.createWebRtc();
|
||||
this.webrtc.on('icecandidate', (icecandidate) => {
|
||||
console.info(TAG_RTC, 'on icecandidate: ' + JSON.stringify(icecandidate));
|
||||
this.sendIceCandidate(icecandidate);
|
||||
});
|
||||
|
||||
this.webrtc.on('iceconnectionstatechange', (state) => {
|
||||
console.info(TAG_RTC, 'on iceconnectionstatechange: ' + state);
|
||||
});
|
||||
|
||||
this.webrtc.on('negotiationneeded', () => {
|
||||
console.info(TAG_RTC, 'on negotiationneeded');
|
||||
});
|
||||
|
||||
// prepare
|
||||
console.info(TAG_RTC, 'webrtc prepare');
|
||||
|
||||
// 参数暂时无效
|
||||
this.webrtc.prepare({
|
||||
iceServers: [{
|
||||
urls: "stun://stun.l.google.com:19302"
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
||||
async connect(peerId: string) {
|
||||
console.info(TAG_RTC, 'connect');
|
||||
this.peerId = peerId;
|
||||
|
||||
if (this.stateCallback) {
|
||||
this.stateCallback(WebRtcState.UNKNOWN, '开始呼叫:' + this.peerId);
|
||||
}
|
||||
|
||||
this.sendMessage('SESSION ' + this.peerId)
|
||||
}
|
||||
|
||||
public disconnect = async () => {
|
||||
console.info(TAG_RTC, 'disconnect');
|
||||
if (this.ws) {
|
||||
this.webrtc.close()
|
||||
this.ws.close();
|
||||
prompt.showToast({
|
||||
message: '语音对讲已挂断...',
|
||||
duration: 4000
|
||||
});
|
||||
const webRtcModel = new WebRtcModel()
|
||||
webRtcModel.setContext(this.context);
|
||||
webRtcModel.initWebSocket('', () => {
|
||||
});
|
||||
webRtcModel.initRtc();
|
||||
}
|
||||
}
|
||||
|
||||
sendMessage = async (message: string) => {
|
||||
this.ws.send(message, (error, success) => {
|
||||
if (success) {
|
||||
console.info(TAG_RTC, 'ws send success' + message)
|
||||
} else {
|
||||
console.error(TAG_RTC, 'ws send error: ' + error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async close() {
|
||||
console.info(TAG_RTC, 'close websocket connection');
|
||||
return await this.ws.close();
|
||||
}
|
||||
|
||||
receiveIce = (ice) => {
|
||||
try {
|
||||
this.webrtc.addIceCandidate({
|
||||
candidate: ice,
|
||||
});
|
||||
} catch (e) {
|
||||
console.info(TAG_RTC, JSON.stringify(e))
|
||||
}
|
||||
}
|
||||
|
||||
disappearWebSocket() {
|
||||
this.ws.off('open');
|
||||
this.ws.off('message');
|
||||
this.ws.off('close');
|
||||
this.ws.off('error');
|
||||
this.webrtc.close()
|
||||
}
|
||||
|
||||
setContext(context: any) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
//接受对方的邀请
|
||||
acceptInvited = (fromId: string, roomId: string) => {
|
||||
const { sendMessage, peerId } = this;
|
||||
this.remoteUserId = fromId;
|
||||
this.roomId = roomId
|
||||
|
||||
sendMessage(JSON.stringify({
|
||||
eventName: '__join',
|
||||
data: {
|
||||
userID: peerId,
|
||||
room: roomId
|
||||
}
|
||||
}))
|
||||
|
||||
prompt.showToast({
|
||||
message: '正在接入语音对讲...',
|
||||
duration: 4000
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,6 @@ import {
|
||||
Sensor,
|
||||
UDPParamType
|
||||
} from '../../model';
|
||||
import { testKm2Items, testKm3Items } from '../../pages/judgeSDK/dataTest';
|
||||
|
||||
import { JudgeConfig } from '../../config';
|
||||
import { FillZero, NumberToByteArray, StringToASCII } from '../Common';
|
||||
@ -18,6 +17,7 @@ import { ObtainUdpBusinessInstance } from './ObtainUdpBusiness';
|
||||
import systemTime from '@ohos.systemDateTime';
|
||||
import { SerialNumberInstance } from '../SerialNumber';
|
||||
import { GetDwStatusType, GetTranslateSignals } from '../../pages/Judge/utils';
|
||||
import { testKm2Items, testKm3Items } from '../../mock';
|
||||
|
||||
// import { examCalcGpsDistance } from '../../pages/Judge/JudgeUtils';
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user