fctom1215
2021-02-03 3ca696a9949851eeb7fbf3d7b9d2b55a1824fad6
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
package safeluck.drive.evaluation.routecollect.impl;
 
import android.util.Log;
 
import com.anyun.exam.lib.IRemoteInterface;
import com.google.gson.Gson;
 
import org.json.JSONException;
import org.json.JSONObject;
 
import safeluck.drive.evaluation.Constant;
import safeluck.drive.evaluation.bean.ExamPlatformData;
import safeluck.drive.evaluation.cEventCenter.CEventCenter;
import safeluck.drive.evaluation.cEventCenter.ICEventListener;
import safeluck.drive.evaluation.routecollect.CollectPointResult;
import safeluck.drive.evaluation.routecollect.ILoadListener;
import safeluck.drive.evaluation.routecollect.IRouteCollectInterface;
import safeluck.drive.evaluation.routecollect.bean.RoadCrossInfo;
import safeluck.drive.evaluation.routecollect.bean.RoadInfo;
import safeluck.drive.evaluation.util.Utils;
 
/**
 * DriveJudge
 * Created by lzw on 2020/9/16. 10:38:39
 * 邮箱:632393724@qq.com
 * All Rights Saved! Chongqing AnYun Tech co. LTD
 */
public class RouteModel implements IRouteCollectInterface{
 
    ILoadListener iLoadListener;
    private Gson gson = new Gson();
    private static final String TAG = "RouteModel";
 
    private ICEventListener icEventListener1= new ICEventListener() {
        @Override
        public void onCEvent(String topic, int msgCode, int resultCode, Object obj) {
 
            if (msgCode == Constant.ENTER_OR_EXIT_ROAD_ID){
 
                if (iLoadListener != null){
                    Log.i(TAG,"道路消息"+(String)obj);
                    RoadInfo roadInfo = gson.fromJson((String)obj,RoadInfo.class);
                    ExamPlatformData.getInstance().setRouteCollectRoadInfo(roadInfo);
                    iLoadListener.roadInfo(roadInfo);
                }
            }
 
            if (msgCode == Constant.ENTER_OR_EXIT_ROADCROSS_ID){
                Log.i(TAG,"路口消息"+(String)obj);
                if (iLoadListener != null){
                    RoadCrossInfo roadCrossInfo = gson.fromJson((String) obj,RoadCrossInfo.class);
                    iLoadListener.roadCrossInfo(roadCrossInfo);
                }
            }
        }
    };
    private ICEventListener icEventListener= new ICEventListener() {
        @Override
        public void onCEvent(String topic, int msgCode, int resultCode, Object obj) {
            //,"coord_x":0.974,"coord_x_dir":"N","coord_y":-0.191,"c
            if (msgCode==Constant.RTK_INFO){
                if (iLoadListener != null){
                    CollectPointResult collectPointResult = new CollectPointResult();
                    try {
                        JSONObject jsonObject = new JSONObject((String)obj);
                        double y = jsonObject.getDouble("coord_x");
                        double x = jsonObject.getDouble("coord_y");
 
                        Log.i(TAG,String.format("采集到的点【x=%f,y=%f]",x,y));
                        collectPointResult.setX(Utils.getdouble(x,4));
                        collectPointResult.setY(Utils.getdouble(y,4));
                        iLoadListener.finishCollectItem(collectPointResult);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
 
                }
            }
 
 
        }
    };
 
    @Override
    public void startCollect() {
        //如果采用application的callback ,可能需要注册一个CEventLisntener
        CEventCenter.onBindEvent(true,icEventListener, Constant.BIND_RTK_INFO_MAP);
    }
 
    /**
     * 停止采点
     */
    @Override
    public void endCollect() {
        //如果采用application的callback ,可能需要反注册一个CEventLisntener 解绑
        CEventCenter.onBindEvent(false,icEventListener,Constant.BIND_RTK_INFO_MAP);
 
    }
 
    @Override
    public void startRoadListener() {
        Log.i(TAG,"线路采集,开始路监听");
        CEventCenter.onBindEvent(true,icEventListener1, Constant.BIND_ROUTE_COLLECT_TOPIC);
    }
 
 
 
    @Override
    public void endRoadListener() {
        CEventCenter.onBindEvent(false,icEventListener1, Constant.BIND_ROUTE_COLLECT_TOPIC);
    }
 
    @Override
    public void setLoadListener(ILoadListener routeCollectController) {
        iLoadListener = routeCollectController;
    }
 
 
}