From d534b3b9b056fff3bcc887d72ed11f4256cdd2fd Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期一, 02 三月 2020 15:21:07 +0800
Subject: [PATCH] 更新地图

---
 app/src/main/java/safeluck/drive/evaluation/Constant.java             |    1 
 app/src/main/java/safeluck/drive/evaluation/app.java                  |    4 +
 app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java |  175 +++++++++++++++++++++++++++++++++------------------------
 3 files changed, 105 insertions(+), 75 deletions(-)

diff --git a/app/src/main/java/safeluck/drive/evaluation/Constant.java b/app/src/main/java/safeluck/drive/evaluation/Constant.java
index 28397fc..967a7bd 100644
--- a/app/src/main/java/safeluck/drive/evaluation/Constant.java
+++ b/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";
 }
diff --git a/app/src/main/java/safeluck/drive/evaluation/app.java b/app/src/main/java/safeluck/drive/evaluation/app.java
index 5d2a7cb..546250e 100644
--- a/app/src/main/java/safeluck/drive/evaluation/app.java
+++ b/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();
                 }
diff --git a/app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java b/app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java
index ae09668..a1c215b 100644
--- a/app/src/main/java/safeluck/drive/evaluation/fragment/MapFragment.java
+++ b/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);
     }
 }

--
Gitblit v1.8.0