| | |
| | | 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; |
| | |
| | | } |
| | | } |
| | | }; |
| | | 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(); |
| | |
| | | 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}}; |
| | |
| | | canvas.drawBitmap(bmp, 0, 0, paint); |
| | | holder.unlockCanvasAndPost(canvas); |
| | | } |
| | | |
| | | // new Thread(new NeedForSpeed(car, map)).start(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | }); |
| | | } |
| | | |
| | | |
| | | 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); |
| | |
| | | |
| | | 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; |
| | |
| | | |
| | | 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(); |
| | | |
| | |
| | | } |
| | | 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(); |
| | |
| | | } |
| | | // } |
| | | // }); |
| | | } |
| | | |
| | | 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; |
| | |
| | | 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) { |
| | |
| | | |
| | | } |
| | | 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 - 侧方停车 |
| | |
| | | } |
| | | } |
| | | } |
| | | DrawMap(map,car); |
| | | DrawMap(mainAnt, map, car, body, tire); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | @Override |
| | |
| | | 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 |
| | |
| | | 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); |
| | | } |
| | | } |