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.basecommonlib.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.routecollect.bean.RoadInfo;
|
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
|
|
|
|
//一id学员数据库表里面的唯
|
public static final int ROAD_ITEM_NONE = 0;
|
//一id学员数据库表里面的唯
|
public static final int ROAD_ITEM_CHANGE_LANE = 1;
|
//一id学员数据库表里面的唯
|
public static final int ROAD_ITEM_OVERTAKE = 2;
|
//一id学员数据库表里面的唯
|
public static final int ROAD_ITEM_STRAIGHT = 3;
|
//一id学员数据库表里面的唯
|
public static final int ROAD_ITEM_OPERATE_GEAR = 4;
|
public static final int ROAD_ITEM_START_CAR = 5;
|
public static final int ROAD_ITEM_PARK_SIDE = 6;
|
public static final int ROAD_ITEM_CROSS_WALK = 7;
|
public static final int ROAD_ITEM_BUS_AREA = 8;
|
public static final int ROAD_ITEM_SCHOOL_AREA = 9;
|
|
|
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;
|
//采集模式
|
public static final int ROUTE_MODE =3;
|
|
|
//主要是为了控制既不是考试模式也不是训练模式下 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<>();
|
|
private static List<String> RulesettingFilesName = new ArrayList<>();
|
private String mcuSN;
|
private boolean canWriteSD;
|
|
public static List<String> getRulesettingFilesName() {
|
return RulesettingFilesName;
|
}
|
|
static {
|
|
RulesettingFilesName.add("startcar_setting.json");
|
RulesettingFilesName.add("station_setting.json");
|
RulesettingFilesName.add("straightline_setting.json");
|
RulesettingFilesName.add("subdecGear_setting.json");
|
RulesettingFilesName.add("sidestop_setting.json");
|
RulesettingFilesName.add("overtake_setting.json");
|
RulesettingFilesName.add("Gear_Setting.json");
|
RulesettingFilesName.add("cornerlamp_setting.json");
|
RulesettingFilesName.add("common_setting.json");
|
RulesettingFilesName.add("area_setting.json");
|
|
|
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(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(12,"超车"));
|
// 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(13,"夜间在道路上发生故障,妨碍交通又难以移动"));
|
// simulate_light_tips.add(new SimulateNightBean.QuestionBean(14,"路边临时停车"));
|
// simulate_light_tips.add(new SimulateNightBean.QuestionBean(15,"夜间路口左转弯"));
|
// simulate_light_tips.add(new SimulateNightBean.QuestionBean(16,"夜间路口右转弯"));
|
|
|
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 int examRoute;//考试/训练用的线路号
|
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;//教练员身份证号码
|
//保存采集模式下的道路信息
|
private RoadInfo roadInfo;
|
|
//当前采集线路的名称
|
private String routeLineName;
|
private int routeItem= ROAD_ITEM_NONE;
|
|
public static ExamPlatformData getInstance() {
|
return ourInstance;
|
}
|
|
|
public int getExamRoute() {
|
examRoute = (int) SPUtils.get(app.getAppContext(),SPUtils.EXAM_ROUTE_ID,-1);
|
return examRoute;
|
}
|
|
/**
|
* 设置训练、考试用的 线路ID
|
* @param examRoute
|
*/
|
public void setExamRoute(int examRoute) {
|
SPUtils.put(app.getAppContext(),SPUtils.EXAM_ROUTE_ID,examRoute);
|
this.examRoute = examRoute;
|
}
|
|
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;
|
}
|
|
public boolean isCanWriteSD() {
|
return canWriteSD;
|
}
|
|
public void setCanWriteSD(boolean canWriteSD) {
|
this.canWriteSD = canWriteSD;
|
}
|
|
/**
|
* 插入平台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() {
|
exam_id = (int) SPUtils.get(app.getAppContext(),SPUtils.EXAM_ID,12345);
|
return exam_id;
|
}
|
|
public void setExam_id(int exam_id) {
|
this.exam_id = exam_id;
|
SPUtils.put(app.getAppContext(),SPUtils.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 synchronized Speaker getTTS(){
|
if (speaker == null){
|
MyLog.i("请先初始化TTS,先调用initTTS");
|
initTTS(app.getAppContext());
|
return speaker;
|
}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;
|
}
|
|
/**
|
* 返回学员是否签到,true-已经签到
|
*/
|
public boolean IsStuSign() {
|
isStuSign = (boolean) SPUtils.get(app.getAppContext(),SPUtils.STU_SIGN_STATUS,false);
|
return isStuSign;
|
}
|
public void setStuSign(boolean flag){
|
if (!flag)
|
setSingnMode(SIGN_MODE_NONE);
|
isStuSign = flag;
|
SPUtils.put(app.getAppContext(),SPUtils.STU_SIGN_STATUS,flag);
|
}
|
private boolean isStuSign;
|
/**
|
* 返回教练是否签到,true-已经签到
|
*/
|
public boolean IsCoachSign() {
|
isCoachSign = (boolean) SPUtils.get(app.getAppContext(),SPUtils.Coach_SIGN_STATUS,false);
|
return isCoachSign;
|
}
|
public void setCoachSign(boolean flag){
|
isCoachSign = flag;
|
SPUtils.put(app.getAppContext(),SPUtils.Coach_SIGN_STATUS,flag);
|
}
|
private boolean isCoachSign;
|
private int sign_mode = 0;
|
public static final int SIGN_MODE_NONE =0 ;
|
public static final int SIGN_MODE_TRAIN =1 ;
|
public static final int SIGN_MODE_EXAM =2 ;
|
public void setSingnMode(int mode){
|
SPUtils.put(app.getAppContext(),SPUtils.SIGN_MODE,mode);
|
this.sign_mode = mode;
|
}
|
public int getSign_mode(){
|
sign_mode = (int) SPUtils.get(app.getAppContext(),SPUtils.SIGN_MODE,0);
|
return sign_mode;
|
}
|
private HashMap<BaseDataUIBean.TYPE_,MapInfoHead> mapInfoHeads = new HashMap<>();
|
|
public HashMap<BaseDataUIBean.TYPE_, MapInfoHead> getMapInfoHeads() {
|
mapInfoHeads = SPUtils.getHashMap(app.getAppContext());
|
return mapInfoHeads;
|
}
|
|
public void setMapHeadInfo(MapInfoHead mapHeadInfo) {
|
|
mapInfoHeads.put(mapHeadInfo.getType(),mapHeadInfo);
|
SPUtils.saveHashMap(mapInfoHeads,app.getAppContext());
|
}
|
|
public void setRouteCollectRoadInfo(RoadInfo roadInfo) {
|
this.roadInfo = roadInfo;
|
}
|
|
public RoadInfo getRouteCollectRoadInfo() {
|
return roadInfo;
|
}
|
|
public void setRouteCollectLineName(String string) {
|
this.routeLineName = string;
|
}
|
|
public String getRouteLineName(){
|
return routeLineName;
|
}
|
|
/**
|
* 返回线路采集中当前采集的项目
|
* @return
|
*/
|
public int getCurrRouteItem() {
|
return routeItem;
|
}
|
|
public void setCurrRouteItem(int roadItemChangeLane) {
|
this.routeItem = roadItemChangeLane;
|
}
|
|
private String smCanBriefString;
|
public void setSM_CAN_BRIEF(String json) {
|
if (smCanBriefString != null && smCanBriefString.equalsIgnoreCase(json)){
|
|
}else{
|
smCanBriefString = json;
|
}
|
}
|
|
public String getSMCanBrief(){
|
return smCanBriefString;
|
}
|
|
public void setMcuSN(String sn) {
|
this.mcuSN = sn;
|
}
|
|
public String getMcuSN(){
|
return mcuSN;
|
}
|
}
|