package safeluck.drive.evaluation.bean;
|
|
import android.content.Context;
|
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.HashMap;
|
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 {
|
private static final ExamPlatformData ourInstance = new ExamPlatformData();
|
|
private int exam_id =12345;//考试唯一ID
|
|
private String mPhone = "";//考试平台消息用到的phone
|
|
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 static HashMap<Integer,String> examPlatformStrs = new HashMap<>();
|
private static HashMap<Integer,String> enter_exit_item_tts = new HashMap<>();
|
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,"直角转弯");
|
}
|
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;
|
private int port;
|
private String mapPath;//绝对路径包含文件名的path
|
private String carPath;//绝对路径包含文件名的path
|
|
public static ExamPlatformData getInstance() {
|
return ourInstance;
|
}
|
|
|
private ExamPlatformData() {
|
}
|
|
public String getPlatformIP(){
|
ip = (String) SPUtils.get(app.getAppContext(),SPUtils.PLATFORM_IP,"47.93.157.103");
|
return ip;
|
}
|
|
public int getPlatformPort(){
|
port = (int) SPUtils.get(app.getAppContext(),SPUtils.PLATFORM_PORT,2020);
|
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;
|
}
|
|
/**
|
* 插入平台端口号
|
* @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);
|
}
|
}
|
|
|
public void setPhone(String phone) {
|
this.mPhone = phone;
|
}
|
|
public String getPhone() {
|
return mPhone;
|
}
|
}
|