yy1717
2020-03-02 d534b3b9b056fff3bcc887d72ed11f4256cdd2fd
更新地图
3个文件已修改
180 ■■■■■ 已修改文件
app/src/main/java/safeluck/drive/evaluation/Constant.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/app.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java 175 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/safeluck/drive/evaluation/Constant.java
@@ -81,5 +81,6 @@
    public static final int SHUTDOWN_TIME = 16;
    public static final int READ_PHYSICAL_ID = 0x8011;//4.    读取IC卡
    public static final String BIND_MCUINFO_TOPIC = "bind_mcu_info_topic";
    public static final String BIND_RTK_SPEED_TOPIC = "BIND_RTK_SPEED_TOPIC";
    public static String exam_enter_exitdata="exam_enter_exitdata";
}
app/src/main/java/safeluck/drive/evaluation/app.java
@@ -277,11 +277,12 @@
                    double longitude = jsSpeed.getDouble("longitude");
                    double altitude = jsSpeed.getDouble("altitude");
                    double speed = jsSpeed.getDouble("speed");
                    Log.i(TAG, "RTK info speed: "+speed);
                    int  qf = jsSpeed.getInt("qf");
                    double track_ture = jsSpeed.getDouble("track_ture");
                    String utc = jsSpeed.getString("utc");
                    CEventCenter.dispatchEvent(Constant.BIND_RTK_SPEED_TOPIC,cmd,0,speed);
                    utc = utc.replace(".","");
                    MyLog.i("RTK info 修改后的utc"+utc);
                    JKMessage0206 jkMessage0206 = new JKMessage0206();
                    jkMessage0206.alert = 0;
                    jkMessage0206.status = 0;
@@ -310,6 +311,7 @@
                    jkMessage0206.attachInfo = attachInfo;
                    Log.i(TAG, "位置上报="+jkMessage0206.toString());
                    MessageProcessor.getInstance().sendMessage(jkMessage0206);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java
@@ -30,6 +30,9 @@
import org.json.JSONObject;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -84,6 +87,14 @@
            }
        }
    };
    private ICEventListener speedListener = new ICEventListener() {
        @Override
        public void onCEvent(String topic, int msgCode, int resultCode, Object obj) {
            if (msgCode == Constant.RTK_INFO){
                gpsSpeed = (double)obj;
            }
        }
    };
    public static SupportFragment newInstance() {
        return new MapFragment();
@@ -102,10 +113,14 @@
    private Canvas canvas2 = null;
    private Paint paint = null;
    private int screen_width = 0, screen_height = 0;
    private String osd = null;
    private String osd2 = null;
    private String osd3 = null;
    private String osdHeading = null;
    private String osdMoveDirect = null;
    private String osdRtkSpeed = null;
    private String osdQf = null;
    private int map_id;
    private double gpsSpeed = 0;
//    double map[][] = {{1, 1}, {10, 1}, {10, 10}, {1, 10}};
    double map[][] = {{-2.4065, 30.7090}, {-3.0759, 30.3599}, { -2.6023, 29.2578}, {-3.3316,28.9383},{-3.8247,30.0293},
        {-3.4503,30.1946}, {-2.9669,29.0981}, { -3.6962, 28.7786}, {-4.1991, 29.8640}};
@@ -173,8 +188,6 @@
                    canvas.drawBitmap(bmp, 0, 0, paint);
                    holder.unlockCanvasAndPost(canvas);
                }
//                new Thread(new NeedForSpeed(car, map)).start();
            }
            @Override
@@ -189,30 +202,14 @@
        });
    }
    class NeedForSpeed implements Runnable {
        public NeedForSpeed(double[][] car, double[][] map) {
            DrawMap(map, car);
        }
        @Override
        public void run() {
//            double car[][] = {{3,3}, {8,3}, {8,8}, {3,8}};
            DrawMap(map, car);
        }
    }
    public void DrawMap(final double[][] map, final double[][] car) {
    public void DrawMap(List<Double> mainAnt, final double[][] map, final double[][] car, List<Integer>body, List<Integer> tire) {
        if (canvas2 == null || bmp == null) {
            return;
        }
//        _mActivity.runOnUiThread(new Runnable() {
//            @Override
//            public void run() {
                double base_x = 100, base_y = 100;
                double base_x = 300, base_y = 20;
                double max_x = 0, min_x = 0, max_y = 0, min_y = 0;
                Log.d(TAG, "DrawMap map size " + map.length + " car size " + car.length);
@@ -258,8 +255,8 @@
                Log.d(TAG, "DrawMap max_x " + max_x + " max_y " + max_y + " min_x " + min_x + " min_y " + min_y);
                long scale_x = Math.round(500 / (max_x - min_x));
                long scale_y = Math.round(300 / (max_y - min_y));
                long scale_x = Math.round((screen_width - base_x - 10) / (max_x - min_x));
                long scale_y = Math.round((screen_height - base_y - 10) / (max_y - min_y));
                if (scale_x >= scale_y) {
                    scale_x = scale_y;
@@ -271,7 +268,20 @@
                canvas2.drawColor(Color.WHITE);
                paint.setStyle(Paint.Style.FILL_AND_STROKE);
                paint.setColor(Color.BLUE);
                canvas2.drawCircle((float) (base_x + (mainAnt.get(0) - min_x) * scale_x), (float) (base_y + (0 - mainAnt.get(1) - min_y) * scale_y), 2, paint);
                paint.setColor(Color.RED);
                canvas2.drawCircle((float) (base_x + (car[tire.get(0)][0] - min_x) * scale_x), (float) (base_y + (car[tire.get(0)][1] - min_y) * scale_y), 2.5f, paint);
                canvas2.drawCircle((float) (base_x + (car[tire.get(1)][0] - min_x) * scale_x), (float) (base_y + (car[tire.get(1)][1] - min_y) * scale_y), 2.5f, paint);
                canvas2.drawCircle((float) (base_x + (car[tire.get(2)][0] - min_x) * scale_x), (float) (base_y + (car[tire.get(2)][1] - min_y) * scale_y), 2.5f, paint);
                canvas2.drawCircle((float) (base_x + (car[tire.get(3)][0] - min_x) * scale_x), (float) (base_y + (car[tire.get(3)][1] - min_y) * scale_y), 2.5f, paint);
                paint.setStyle(Paint.Style.STROKE);
                paint.setColor(Color.BLACK);
                Path path = new Path();
@@ -301,33 +311,54 @@
                }
                canvas2.drawPath(path, paint);
                path.moveTo((float) (base_x + (car[0][0] - min_x) * scale_x), (float) (base_y + (car[0][1] - min_y) * scale_y));
                for (int i = 1; i < car.length; i++)
                    path.lineTo((float) (base_x + (car[i][0] - min_x) * scale_x), (float) (base_y + (car[i][1] - min_y) * scale_y));
                path.moveTo((float) (base_x + (car[body.get(0)][0] - min_x) * scale_x), (float) (base_y + (car[body.get(0)][1] - min_y) * scale_y));
                for (int i = 1; i < body.size(); i++)
                    path.lineTo((float) (base_x + (car[body.get(i)][0] - min_x) * scale_x), (float) (base_y + (car[body.get(i)][1] - min_y) * scale_y));
                path.close();
                canvas2.drawPath(path, paint);
                paint.setStyle(Paint.Style.FILL_AND_STROKE);
                if (osd != null) {
                if (osdHeading != null) {
                    Path pathText = new Path();
                    pathText.moveTo(10, 170);
                    pathText.lineTo(700, 170);
                    canvas2.drawTextOnPath(osd, pathText, 0, 0, paint);//逆时针生成
                    canvas2.drawTextOnPath(osdHeading, pathText, 0, 0, paint);//逆时针生成
                }
                if (osd2 != null) {
                if (osdMoveDirect != null) {
                    Path pathText = new Path();
                    pathText.moveTo(10, 30);
                    pathText.lineTo(700, 30);
                    canvas2.drawTextOnPath(osd2, pathText, 0, 0, paint);//逆时针生成
                    canvas2.drawTextOnPath(osdMoveDirect, pathText, 0, 0, paint);//逆时针生成
                }
//                if (osd3 != null) {
//                    Path pathText = new Path();
//                    pathText.moveTo(10, 240);
//                    pathText.lineTo(700, 130);
//                    canvas2.drawTextOnPath(osd2, pathText, 0, 0, paint);//逆时针生成
//                }
                if (osdRtkSpeed != null) {
                    Path pathText = new Path();
                    pathText.moveTo(10, 240);
                    pathText.lineTo(700, 240);
                    canvas2.drawTextOnPath(osdRtkSpeed, pathText, 0, 0, paint);//逆时针生成
                }
                if (osdQf != null) {
                    Path pathText = new Path();
                    pathText.moveTo(10, 120);
                    pathText.lineTo(700, 120);
                    canvas2.drawTextOnPath(osdQf, pathText, 0, 0, paint);//逆时针生成
                }
        {
            BigDecimal bd = new BigDecimal(gpsSpeed);
            bd = bd.setScale(3, BigDecimal.ROUND_HALF_UP);
            Path pathText = new Path();
            pathText.moveTo(10, 70);
            pathText.lineTo(700, 70);
            canvas2.drawTextOnPath("GPS速度:" + bd, pathText, 0, 0, paint);//逆时针生成
        }
                // 提交画布
                Canvas canvas = holder.lockCanvas();
@@ -338,35 +369,6 @@
                }
//            }
//        });
    }
    public void CCL(final int c, final int who) {
        _mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                /*if (canvas2 != null && bmp != null) {
                    if (c == 0)
                        canvas2.drawColor(Color.GREEN);
                    else
                        canvas2.drawColor(Color.GRAY);
                    // 提交画布
                    Canvas canvas = holder.lockCanvas();
                    canvas.drawBitmap(bmp, 0, 0, paint);
                    holder.unlockCanvasAndPost(canvas);
                }*/
//                Button button;
//                if (who == 0) {
//                    button = findViewById(R.id.sample_button);
//                } else {
//                    button = findViewById(R.id.net_button);
//                }
//
//                if (c == 0)
//                    button.setBackgroundColor(Color.GREEN);
//                else
//                    button.setBackgroundColor(Color.RED);
            }
        });
    }
    int line = 0;
@@ -424,18 +426,27 @@
                    List<Double> points = timeCarPos.getPoint();
                    switch (timeCarPos.getMove()){
                        case 0:
                            osd2 = "停车";
                            osdMoveDirect = "停车";
                            break;
                        case 1:
                            osd2 = "前进";
                            osdMoveDirect = "前进";
                            break;
                        case -1:
                            osd2 = "后退";
                            osdMoveDirect = "后退";
                            break;
                    }
                    osd="方向角"+String.valueOf(timeCarPos.getHeading());
                    osdHeading="方向角"+String.valueOf(timeCarPos.getHeading());
                    BigDecimal bd = new BigDecimal(timeCarPos.getSpeed());
                    bd = bd.setScale(3, BigDecimal.ROUND_HALF_UP);
                    osdRtkSpeed = "计算速度:" + bd;
                    osdQf = "QF:" + String.valueOf(timeCarPos.getQf());
                    line = 0;
                    map_line = 0;
                    car = new double[points.size()/2][2];
                    for (int i = 0; i < points.size(); i++) {
                        if ((i % 2) == 0) {
@@ -449,6 +460,22 @@
                    }
                    map_id = timeCarPos.getMap_id();
                    List<Double> mainAnt = timeCarPos.getMain_ant();
                    List<Integer> tire1 = timeCarPos.getLeft_front_tire();
                    List<Integer> tire2 = timeCarPos.getRight_front_tire();
                    List<Integer> tire3 = timeCarPos.getLeft_rear_tire();
                    List<Integer> tire4 = timeCarPos.getRight_rear_tire();
                    List<Integer> body = timeCarPos.getBody();
                    List<Integer> tire = new ArrayList<>();
                    tire.add(tire1.get(0));
                    tire.add(tire2.get(0));
                    tire.add(tire3.get(0));
                    tire.add(tire4.get(0));
//            1 - 倒库
//            2 - 坡起
//            3 - 侧方停车
@@ -493,11 +520,9 @@
                            }
                        }
                    }
                    DrawMap(map,car);
                    DrawMap(mainAnt, map, car, body, tire);
                }
            }
        }
    }
    @Override
@@ -506,6 +531,7 @@
        CEventCenter.onBindEvent(true, icEventListener, Constant.REAL_TIME_POS_CAR_TOPIC);
        CEventCenter.onBindEvent(true, rtcmicEventListener, Constant.BIND_RTCM_TOPIC);
        CEventCenter.onBindEvent(true, debugTxticEventListener, Constant.BIND_DEBUG_TXT);
        CEventCenter.onBindEvent(true, speedListener, Constant.BIND_RTK_SPEED_TOPIC);
    }
    @Override
@@ -517,5 +543,6 @@
        CEventCenter.onBindEvent(false, icEventListener, Constant.REAL_TIME_POS_CAR_TOPIC);
        CEventCenter.onBindEvent(false, icEventListener, Constant.BIND_RTCM_TOPIC);
        CEventCenter.onBindEvent(false, icEventListener, Constant.BIND_DEBUG_TXT);
        CEventCenter.onBindEvent(false, speedListener, Constant.BIND_RTK_SPEED_TOPIC);
    }
}