lizhanwei
2020-03-10 f1337fe651423804668d83fc021664e2f925d912
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
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.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 {
    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<>();
    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,"直角转弯");
 
 
        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;
    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;
    }
 
    public List<SimulateNightBean.QuestionBean> getSimulate_light_tips() {
        return simulate_light_tips;
    }
}