package safeluck.drive.evaluation.bean;
|
|
import android.content.Context;
|
import android.text.TextUtils;
|
import android.util.Log;
|
|
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.ViewModelProviders;
|
import androidx.work.Data;
|
import androidx.work.OneTimeWorkRequest;
|
import androidx.work.WorkManager;
|
|
import com.anyun.exam.lib.MyLog;
|
import com.anyun.exam.lib.util.Speaker;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Random;
|
|
import safeluck.drive.evaluation.Constant;
|
import safeluck.drive.evaluation.DB.appstatusdb.AppStatusWorker;
|
import safeluck.drive.evaluation.app;
|
import safeluck.drive.evaluation.platformMessage.PlatFormConstant;
|
import safeluck.drive.evaluation.util.SPUtils;
|
import safeluck.drive.evaluation.viewmodels.ExamPlatformModel;
|
import safeluck.drive.evaluation.viewmodels.MainViewModel;
|
|
public class ExamPlatformData {
|
|
|
|
public static final int PERSON_TYPE_COACH = 0;//类型为教练
|
public static final int PERSON_TYPE_STU = 1;//人员类型为学员
|
public static final int COACH_ID = 1002;//教练数据库表里面的唯一id
|
public static final int STU_ID = 1001;//学员数据库表里面的唯一id
|
|
public static final int MODE_NONE = 0;
|
public static final int EXAM_TYPE_LUKAO_Light = 3;
|
public static final int EXAM_TYPE_LUKAO = 4;
|
public static final int EXAM_TYPE_ChangKAO = 2;
|
private static final String TAG = "ExamPlatformData";
|
private static final ExamPlatformData ourInstance = new ExamPlatformData();
|
|
private int exam_id =12345;//考试唯一ID
|
|
private String mPhone = "";//考试平台消息用到的phone
|
|
private int examType = 0;//2 场地;
|
//3 道路,模拟夜考;
|
// 4 道路,实际夜考;
|
|
public static final int TCP_DISCONNECT = 1;
|
public static final int TCP_CONNECTED = 2;///2-未连接(tcp连接不上)
|
public static final int DEV_NOT_REGISTERED = 3;
|
public static final int DEV_REGISTERED = 4;
|
public static final int DEV_NOT_LOGIN = 5;
|
public static final int DEV_LOGIN = 6;
|
|
private int trainingMode = 0;//即不是训练模式也不是考试模式
|
public static final int EXAMING_MODE =1;
|
public static final int TRAINING_MODE =2;
|
|
|
//主要是为了控制既不是考试模式也不是训练模式下 0206消息的发送,10s一次发送
|
private boolean timeArrive_10s = false;
|
|
private static HashMap<Integer,String> examPlatformStrs = new HashMap<>();
|
private List<Integer> sns =new ArrayList<>();//保存所有失败项目的sn
|
private static HashMap<Integer,String> enter_exit_item_tts = new HashMap<>();
|
private static List<SimulateNightBean.QuestionBean> simulate_light_tips = new ArrayList<>();
|
static {
|
examPlatformStrs.put(TCP_DISCONNECT,"未连接");
|
examPlatformStrs.put(TCP_CONNECTED,"未登录");
|
examPlatformStrs.put(DEV_NOT_REGISTERED,"未注册");
|
examPlatformStrs.put(DEV_REGISTERED,"未登录");
|
examPlatformStrs.put(DEV_NOT_LOGIN,"未登录");
|
examPlatformStrs.put(DEV_LOGIN,"已登录");
|
|
/*侧方位停车 type = 3
|
|
倒车入库 type = 1
|
上坡起步 type = 2
|
zhijiao type = 5*/
|
|
enter_exit_item_tts.put(1,"倒车入库");
|
enter_exit_item_tts.put(2,"坡道定点停车和起步");
|
enter_exit_item_tts.put(3,"侧方停车");
|
enter_exit_item_tts.put(4,"曲线行驶");
|
enter_exit_item_tts.put(5,"直角转弯");
|
|
enter_exit_item_tts.put(101,"直线行驶");
|
enter_exit_item_tts.put(102,"加减挡位操作");
|
enter_exit_item_tts.put(103,"靠边停车");
|
enter_exit_item_tts.put(104,"直行通过路口");
|
enter_exit_item_tts.put(105,"路口左转弯");
|
enter_exit_item_tts.put(106,"路口右转弯");
|
enter_exit_item_tts.put(107,"通过人行道横线");
|
enter_exit_item_tts.put(108,"通过学校区域");
|
enter_exit_item_tts.put(109,"通过公共汽车站");
|
enter_exit_item_tts.put(110,"掉头");
|
|
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(1,"开启前照灯"));
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(2,"夜间在没有路灯照明不良条件下行驶"));
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(3,"夜间在窄路与非机动车会车"));
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(4,"请将前照灯更换成远光"));
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(5,"夜间同方向近距离跟车行驶"));
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(6,"雾天行驶"));
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(7,"拱桥、人行道"));
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(8,"夜间在道路上发生故障,妨碍交通又难以移动"));
|
//、拱桥、人行横道、或者没有交通信号灯控制的路口
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(9," 夜间通过急弯、坡路"));
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(10,"没有交通控制灯之路口"));
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(11,"临时停车"));
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(12,"超车"));
|
|
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(100,"下面将进行模拟夜间行驶场景灯光使用的考试,请按语音指令在5秒内做出相应的灯光操作"));
|
simulate_light_tips.add(new SimulateNightBean.QuestionBean(101,"模拟夜间考试完成请关闭所有灯光,请起步继续完成考试"));
|
|
|
|
|
}
|
private static final String WORK_PLATFORM_STATUS = " work_platform";
|
|
|
private int examplatformStatus =1;//1-未连接(tcp连接不上) 3-未注册(设备没有注册) 5-未登录(鉴权未通过)
|
|
private String id;//身份证
|
|
private Speaker speaker = null;
|
|
private String ip="47.93.80.84";
|
private int port=12125;
|
private String mapPath;//绝对路径包含文件名的path
|
private String roadmapPath;//绝对路径包含文件名的path
|
private String carPath;//绝对路径包含文件名的path
|
private int rtkPort = 12125;
|
private String rtkIP = "47.93.80.84";
|
public final int MAX_SCORE_DUCT = 20;
|
private String coachID;//教练员身份证号码
|
|
public static ExamPlatformData getInstance() {
|
return ourInstance;
|
}
|
|
|
private ExamPlatformData() {
|
|
}
|
|
public String getPlatformIP(){
|
ip = (String) SPUtils.get(app.getAppContext(),SPUtils.PLATFORM_IP,"47.93.80.84");
|
return ip;
|
}
|
|
public int getPlatformPort(){
|
port = (int) SPUtils.get(app.getAppContext(),SPUtils.PLATFORM_PORT,12125);
|
return port;
|
}
|
|
/**
|
* 插入平台IP地址
|
* @param ip
|
*/
|
public void insertPlatformIp(String ip){
|
|
SPUtils.put(app.getAppContext(),SPUtils.PLATFORM_IP,ip);
|
|
}
|
|
/**
|
* 比较ip地址和端口号,
|
* @param ip
|
* @param port
|
* @return ip和端口其中有变化,返回true,否则返回false
|
*/
|
public boolean compareIPandPort(String ip,int port){
|
MyLog.i( "compareIPandPort: "+ip+" "+port);
|
if(!getPlatformIP().equalsIgnoreCase(ip) || getPlatformPort()!=port){
|
MyLog.i("ip和端口有变化");
|
return true;
|
}
|
return false;
|
} /**
|
* 比较RTK ip地址和端口号,
|
* @param ip
|
* @param port
|
* @return ip和端口其中有变化,返回true,否则返回false
|
*/
|
public boolean compareRTKIPandPort(String ip,int port){
|
MyLog.i( "compareIPandPort: "+ip+" "+port);
|
if(!getRtkIP().equalsIgnoreCase(ip) || getRtkPort()!=port){
|
MyLog.i("ip和端口有变化");
|
return true;
|
}
|
return false;
|
}
|
|
/**
|
* 插入平台端口号
|
* @param port
|
*/
|
public void insertPlatformPort(int port){
|
SPUtils.put(app.getAppContext(),SPUtils.PLATFORM_PORT,port);
|
}
|
|
|
/**
|
* 获取学员ID(身份证)
|
* @return
|
*/
|
public String getID() {
|
return id;
|
}
|
|
public void setId(String id) {
|
this.id = id;
|
}
|
|
public int getExam_id() {
|
return exam_id;
|
}
|
|
public void setExam_id(int exam_id) {
|
this.exam_id = exam_id;
|
}
|
|
public void setNewMapPath(String path) {
|
this.mapPath = path;
|
SPUtils.put(app.getAppContext(),SPUtils.MAP_PATH,mapPath);
|
}
|
|
public String getMapPath(){
|
mapPath = (String) SPUtils.get(app.getAppContext(),SPUtils.MAP_PATH,"");
|
return mapPath;
|
}
|
|
/**
|
* 设置保存地图模型文件(坐标点—)的路径
|
* @param car_path
|
*/
|
public void setCarModelPath(String car_path) {
|
this.carPath = car_path;
|
SPUtils.put(app.getAppContext(),SPUtils.CAR_PATH,car_path);
|
}
|
|
public String getCarModelPath(){
|
carPath = (String) SPUtils.get(app.getAppContext(),SPUtils.CAR_PATH,"");
|
return carPath;
|
}
|
|
public int getExamplatformStatus() {
|
return examplatformStatus;
|
}
|
|
public void setExamplatformStatus(int examplatformStatus) {
|
String[] conn_strs = new String[2];
|
conn_strs[0] = Constant.WORK_PLATFORM_STATUS_COLUMN;
|
conn_strs[1] = "{"+WORK_PLATFORM_STATUS+":"+examplatformStatus+"}";
|
//RTK平台连接状态
|
Data connStatusData = new Data.Builder().putStringArray(Constant.APP_STATUS,conn_strs).build();
|
OneTimeWorkRequest oneTimeWorkRequest = new OneTimeWorkRequest.Builder(AppStatusWorker.class).
|
setInputData(connStatusData).build();
|
WorkManager.getInstance(app.getAppContext()).enqueue(oneTimeWorkRequest);
|
this.examplatformStatus = examplatformStatus;
|
}
|
|
public String getExamplatformStatusStr(int work_platform) {
|
|
return examPlatformStrs.get(work_platform);
|
}
|
|
/**
|
* 进入退出某个场地的文字
|
* @param item
|
* @return
|
*/
|
public String getItemStatusStr(int item) {
|
|
if (enter_exit_item_tts.get(item)==null){
|
return "未知项目";
|
}
|
return enter_exit_item_tts.get(item);
|
}
|
|
public Speaker getTTS(){
|
if (speaker == null){
|
throw new RuntimeException("请先初始化TTS,先调用initTTS");
|
}else
|
return speaker;
|
}
|
|
/**
|
* 初始化tts
|
* @param context
|
*/
|
public void initTTS(Context context){
|
if (speaker == null){
|
|
speaker = new Speaker(context,null);
|
}
|
}
|
|
public int getTrainingMode() {
|
trainingMode = (int) SPUtils.get(app.getAppContext(),SPUtils.TRAIN_MODE,0);
|
return trainingMode;
|
}
|
|
|
|
public void setTrainingMode(int trainingMode) {
|
SPUtils.put(app.getAppContext(),SPUtils.TRAIN_MODE,trainingMode);
|
trainingMode = trainingMode;
|
}
|
|
public void setPhone(String phone) {
|
this.mPhone = phone;
|
}
|
|
public String getPhone() {
|
return mPhone;
|
}
|
|
public List<SimulateNightBean.QuestionBean> getSimulate_light_tips() {
|
return simulate_light_tips;
|
}
|
|
public boolean isTimeArrive_10s() {
|
return timeArrive_10s;
|
}
|
|
public void setTimeArrive_10s(boolean timeArrive_10s) {
|
this.timeArrive_10s = timeArrive_10s;
|
}
|
|
public void setRTKPort(int port) {
|
this.rtkPort = port;
|
}
|
|
public void setRTKIP(String ip) {
|
this.rtkIP = ip;
|
}
|
|
public int getRtkPort() {
|
return rtkPort;
|
}
|
|
public String getRtkIP() {
|
return rtkIP;
|
}
|
|
public void setQfAndSatNum(int qf,int satNum){
|
String[] rtk_strs = new String[2];
|
rtk_strs[0] = Constant.RTK_INFO_SAT_QF;
|
rtk_strs[1] = "{qf:"+qf+","+"sat_num:"+satNum+"}";
|
Data rtkInfoData = new Data.Builder().putStringArray(Constant.APP_STATUS,rtk_strs).build();
|
OneTimeWorkRequest appStatusWorker = new OneTimeWorkRequest.Builder(AppStatusWorker.class).setInputData(rtkInfoData).build();
|
WorkManager.getInstance(app.getAppContext()).enqueue(appStatusWorker);
|
}
|
// //清空app_status qf和sat tcp状态
|
public void whenAppExitResetStatus(){
|
setQfAndSatNum(0,0);
|
setExamplatformStatus(0);
|
}
|
|
public int getExamType() {
|
return examType;
|
}
|
|
public void setExamType(int examType) {
|
this.examType = examType;
|
}
|
|
/**
|
* 设置路考地图的路径
|
* @param path
|
*/
|
public void setNewRoadMapPath(String path) {
|
this.roadmapPath = path;
|
SPUtils.put(app.getAppContext(),SPUtils.ROAD_MAP_PATH,roadmapPath);
|
}
|
|
/**
|
* 获得路考地图的路径
|
* @return
|
*/
|
public String getRoadMapPath(){
|
roadmapPath = (String) SPUtils.get(app.getAppContext(),SPUtils.ROAD_MAP_PATH,"");
|
return roadmapPath;
|
}
|
|
/**
|
* 设置保存教练员身份证号
|
* @param id
|
*/
|
public void setCoachID(String id) {
|
this.coachID = id;
|
}
|
|
/**
|
* 获取
|
* @return 教练员身份证
|
*/
|
public String getCoachID() {
|
return coachID;
|
}
|
}
|