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.util.SPUtils; import safeluck.drive.evaluation.viewmodels.ExamPlatformModel; import safeluck.drive.evaluation.viewmodels.MainViewModel; public class ExamPlatformData { 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; private static HashMap examPlatformStrs = new HashMap<>(); private List sns =new ArrayList<>();//保存所有失败项目的sn private static HashMap enter_exit_item_tts = new HashMap<>(); private static List 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 carPath;//绝对路径包含文件名的path private StringBuffer stringBuffer; private int rtkPort = 12125; private String rtkIP = "47.93.80.84"; public static ExamPlatformData getInstance() { return ourInstance; } private ExamPlatformData() { stringBuffer = new StringBuffer(); } 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); } public String getID() { return id; } public void setId(String id) { this.id = id; } public int getExam_id() { return 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 (item<1 || item>enter_exit_item_tts.size()){ 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 getSimulate_light_tips() { return simulate_light_tips; } public List getSns() { // if (sns.size()<=0){ // String snsstr = (String) SPUtils.get(app.getAppContext(),SPUtils.FAIL_PROJ_SNS,""); // if (!TextUtils.isEmpty(snsstr)){ // String[] strings=snsstr.split("#"); // for (int i = 0; i < strings.length; i++) { // Log.i(TAG, String.format("strings[%d]=%s",i,strings[i])); // if (!TextUtils.isEmpty(strings[i])) // sns.add(Integer.parseInt(strings[i])); // } // } // } return sns; } public void addSn(int sn) { // stringBuffer.append("#"+String.valueOf(sn)); // SPUtils.put(app.getAppContext(),SPUtils.FAIL_PROJ_SNS,stringBuffer.toString()); this.sns.add(sn); } public void clearSns() { // SPUtils.clear(app.getAppContext()); sns.clear(); } 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; } }