yy1717
2020-12-04 5719515b70fd7405e34198f15dfbc78c07975323
app/src/main/java/safeluck/drive/evaluation/app.java
@@ -3,7 +3,6 @@
import android.app.Application;
import android.content.Context;
import android.os.Environment;
import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
@@ -32,13 +31,10 @@
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Executors;
import safeluck.drive.evaluation.DB.WorkRoomDataBase;
import safeluck.drive.evaluation.DB.appstatusdb.AppStatusWorker;
@@ -46,17 +42,15 @@
import safeluck.drive.evaluation.DB.criterias.CriteriaForIII;
import safeluck.drive.evaluation.DB.exam_status.ExamStatus;
import safeluck.drive.evaluation.DB.exam_status.ExamStatusOutWorker;
import safeluck.drive.evaluation.DB.exam_status.ExamStatusWoker;
import safeluck.drive.evaluation.DB.failitems.FailedProj;
import safeluck.drive.evaluation.DB.failitems.LuKaoFailedProj;
import safeluck.drive.evaluation.DB.gps.GpsInfoWorker;
import safeluck.drive.evaluation.DB.route.RouteCross;
import safeluck.drive.evaluation.DB.route.RouteTriggerLine;
import safeluck.drive.evaluation.DB.rtktb.RTKConfigUpdateWorker;
import safeluck.drive.evaluation.bean.AbsInitialData;
import safeluck.drive.evaluation.bean.ExamPlatformData;
import safeluck.drive.evaluation.bean.RemoteRouteCollect;
import safeluck.drive.evaluation.bean.RouteCollect;
import safeluck.drive.evaluation.cEventCenter.CEvent;
import safeluck.drive.evaluation.cEventCenter.CEventCenter;
import safeluck.drive.evaluation.im.MessageProcessor;
import safeluck.drive.evaluation.platformMessage.AttachInfo;
@@ -64,7 +58,6 @@
import safeluck.drive.evaluation.platformMessage.JKMessage0203;
import safeluck.drive.evaluation.platformMessage.JKMessage0206;
import safeluck.drive.evaluation.platformMessage.PlatFormConstant;
import safeluck.drive.evaluation.routecollect.RouteCollectController;
import safeluck.drive.evaluation.util.CThreadPoolExecutor;
import safeluck.drive.evaluation.util.DataInitKt;
import safeluck.drive.evaluation.util.FileUtil;
@@ -72,7 +65,7 @@
import safeluck.drive.evaluation.util.SystemUtil;
import safeluck.drive.evaluation.util.Utils;
import static safeluck.drive.evaluation.bean.ExamPlatformData.getRulesettingFilesName;
import static safeluck.drive.evaluation.util.DataInitKt.sendJudgeArgs;
/**
 * MyApplication2
@@ -115,7 +108,8 @@
            //考试状态 ,一些初始状态,app一些状态应该先初始化一下
//            ExamPlatformData.getInstance().setMcuSN("0314200100000004");
//            ExamPlatformData.getInstance().setCanWriteSD(true);
        }
    }
@@ -123,21 +117,9 @@
    private void initData() {
        CThreadPoolExecutor.runInBackground(()->{
                int type = WorkRoomDataBase.getWorkRoomDataBase(getApplicationContext()).getExamStatusDao().getStartExamInt();
            MyLog.i("开始初始化数据发送地图/车辆/mcu升级文件/考试状态="+type);
                ExamPlatformData.getInstance().setExamType(type);
//            OneTimeWorkRequest examStatausOutWorker = OneTimeWorkRequest.from(ExamStatusOutWorker.class);
//            sendMapInfo();
//            sendVechileInfo();
            sendRouteExam();
//            DataInitKt.MCUUpgrade(getApplicationContext());
            DataInitKt.sendExamLights(getApplicationContext());
            DataInitKt.sendRtkConfig(getApplicationContext());
//            DataInitKt.sendSignalConfigToRemote(getApplicationContext());
//            OneTimeWorkRequest mcuUpgradeWorker = OneTimeWorkRequest.from(MCUUpgradeWorker.class);
//            WorkManager.getInstance(getApplicationContext()).beginWith(examStatausOutWorker).then(mcuUpgradeWorker).enqueue();
            MyLog.i("考试状态="+type);
            ExamPlatformData.getInstance().setExamType(type);
            //发送蓝牙配置消息
            String mac= (String) SPUtils.get(getAppContext(),SPUtils.BLUETOOTH_MAC,"");
            if (!TextUtils.isEmpty(mac)){
@@ -153,6 +135,17 @@
                Log.i(TAG,json);
                AYSdk.getInstance().sendCmd(Constant.ID_MS_BLUETOOTH_NAME,json);
            }
            sendRouteExam();
            DataInitKt.sendRtkConfig(getApplicationContext());
//            DataInitKt.MCUUpgrade(getApplicationContext());
          //改在蓝牙已经连接,发送initialdata
@@ -221,35 +214,7 @@
        AYSdk.getInstance().sendCmd(0x8017,str);
    }
    private void sendJudgeArgs() {
        File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+getPackageName());
        List<String> names = ExamPlatformData.getRulesettingFilesName();
        for (int i = 0; i < names.size(); i++) {
            File settFile = new File(dir,names.get(i));
                if (settFile.exists() ){
                    Log.i(TAG,settFile.getName()+"存在不复制");
                }else{
                    Log.i(TAG,settFile.getName()+"不存在,复制...");
                    FileUtil.copyAssertFileToSD(getApplicationContext(),names.get(i));
                }
        }
        if (dir.exists()){
            File[] files = dir.listFiles();
            for (int i = 0; i < files.length; i++) {
                Log.i(TAG,files[i].getName());
                if (names.contains(files[i].getName())){
                    byte[] buffer = FileUtil.readFile(files[i].getAbsolutePath());
                    AYSdk.getInstance().sendCmd(Constant.ID_judge_args,new String(buffer).trim());
                }else{
                }
            }
        }
    }
    public static Context getAppContext(){
        return appContext;
@@ -424,11 +389,12 @@
                                }
                            }
                            sendMapInfo();
                            DataInitKt.sendMapInfo();
                            DataInitKt.sendRoadMapInfo();
                            break;
                        case -2:
                            sendVechileInfo();
                            DataInitKt.sendVehicleInfo();
                            break;
                        case -3:
                            Data data = new Data.Builder().putInt(Constant.NEED_MAPS_CAR,1).build();
@@ -457,7 +423,7 @@
                break;
            case Constant.REQ_VECHILE_PROFILE:
                sendVechileInfo();
                DataInitKt.sendVehicleInfo();
                break;
            case Constant.GPS_INFO:
                Data gpsData = new Data.Builder().putString(Constant.GPS_INFO_DATA,json).build();
@@ -679,6 +645,7 @@
            initData();
        }else{
            ExamPlatformData.getInstance().getTTS().speak("服务异常死亡");
            AbsInitialData.getInstance().resethasSendInitData();
        }
@@ -705,94 +672,6 @@
        return false;
    }
    private void sendVechileInfo() {
                String carPath = ExamPlatformData.getInstance().getCarModelPath();
                if (!TextUtils.isEmpty(carPath)){
                    MyLog.i("使用更新后的Car模型地图"+carPath);
                    byte[] bytes = FileUtil.readFile(carPath);
                    if (bytes != null){
                        String str = new String(bytes);
                        AYSdk.getInstance().sendCmd(Constant.PUSH_VECHILE_PROFILE,str);
                    }else{
                        MyLog.i(String.format("文件:%s不存在",carPath));
                        CThreadPoolExecutor.runOnMainThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(getAppContext(), "文件:"+carPath+"不存在", Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                }else{
                    CThreadPoolExecutor.runOnMainThread(()->{
                        MyLog.i("车辆模型发送失败,请手动设置");
                        Toast.makeText(getAppContext(), "车辆模型发送失败,请手动设置", Toast.LENGTH_SHORT).show();
                    });
                }
    }
    private void sendMapInfo(){
                final String mapPath = ExamPlatformData.getInstance().getMapPath();
                final String roadmapPath = ExamPlatformData.getInstance().getRoadMapPath();
                if (!TextUtils.isEmpty(roadmapPath)){
                    MyLog.i("调用更新RoadMap路径后的地图"+roadmapPath);
                    byte[] fileContent = FileUtil.readFile(roadmapPath);
                    if (fileContent != null){
                        String str = new String(fileContent);
                        MyLog.i("文件内容:"+str);
                        AYSdk.getInstance().sendCmd(Constant.PUSH_ROAD_MAP_INFO,str);
                    }else{
                        MyLog.i(String.format("文件:%s不存在",roadmapPath));
                        CThreadPoolExecutor.runOnMainThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(getAppContext(), "文件:"+roadmapPath+"不存在", Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                }else{
                    CThreadPoolExecutor.runOnMainThread(new Runnable() {
                        @Override
                        public void run() {
                            MyLog.i("道路地图发送失败,请手动设置");
                            Toast.makeText(getAppContext(), "道路地图发送失败,请手动设置", Toast.LENGTH_SHORT).show();
                        }
                    });
                }
                if (!TextUtils.isEmpty(mapPath)){
                    MyLog.i("调用更新Map路径后的地图"+mapPath);
                    byte[] fileContent = FileUtil.readFile(mapPath);
                    if (fileContent != null){
                        String str = new String(fileContent);
                        Log.i(TAG, "文件内容:"+str);
                        AYSdk.getInstance().sendCmd(Constant.PUSH_MAP_INFO,str);
                    }else{
                        MyLog.i(String.format("文件:%s不存在",mapPath));
                        CThreadPoolExecutor.runOnMainThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(getAppContext(), "文件:"+mapPath+"不存在", Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                }else{
                    CThreadPoolExecutor.runOnMainThread(new Runnable() {
                        @Override
                        public void run() {
                            MyLog.i("场地地图发送失败,请手动设置");
                            Toast.makeText(getAppContext(), "场地地图发送失败,请手动设置", Toast.LENGTH_SHORT).show();
                        }
                    });
                }
    }
}