| | |
| | | package safeluck.drive.evaluation.util |
| | | |
| | | import android.content.Context |
| | | import android.os.Environment |
| | | import android.text.TextUtils |
| | | import android.util.Log |
| | | import android.widget.Toast |
| | | import androidx.work.Data |
| | | import androidx.work.ListenableWorker |
| | | import com.anyun.exam.lib.AYSdk |
| | |
| | | import com.google.gson.Gson |
| | | import com.google.gson.reflect.TypeToken |
| | | import com.google.gson.stream.JsonReader |
| | | import okhttp3.ResponseBody |
| | | import org.json.JSONException |
| | | import org.json.JSONObject |
| | | import retrofit2.Call |
| | | import retrofit2.Callback |
| | | import retrofit2.Response |
| | | import safeluck.drive.evaluation.Constant |
| | | import safeluck.drive.evaluation.DB.WorkRoomDataBase |
| | | import safeluck.drive.evaluation.DB.rtktb.RTKConfig |
| | | import safeluck.drive.evaluation.DB.signalConfigdb.SingalConfig |
| | | import safeluck.drive.evaluation.bean.ExamPlatformData |
| | | import safeluck.drive.evaluation.bean.SignalConfigRemote |
| | | import safeluck.drive.evaluation.bean.SimulateNightBean |
| | | import safeluck.drive.evaluation.app |
| | | import safeluck.drive.evaluation.bean.* |
| | | import safeluck.drive.evaluation.httpmodule.HttpCarRespBean |
| | | import safeluck.drive.evaluation.httpmodule.HttpRequetBean |
| | | import safeluck.drive.evaluation.httpmodule.HttpRoadMapRsp |
| | | import safeluck.drive.evaluation.httpmodule.HttpYardRsp |
| | | import safeluck.drive.evaluation.httpmodule.RetrofitCreator.Companion.getRestService |
| | | import safeluck.drive.evaluation.platformMessage.PlatFormConstant |
| | | import safeluck.drive.evaluation.worker.MCUUpgradeWorker |
| | | import java.io.IOException |
| | | import java.io.InputStreamReader |
| | |
| | | } |
| | | return false |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | fun getMap(sn: String, type: String){ |
| | | lateinit var jsonObject1 :JSONObject |
| | | lateinit var fileName :String |
| | | when(type){ |
| | | "road" -> fileName = safeluck.drive.evaluation.Constant.ROAD_MAP |
| | | "yard" -> fileName = safeluck.drive.evaluation.Constant.MAP |
| | | else -> fileName = safeluck.drive.evaluation.Constant.VEHICLE |
| | | } |
| | | getRestService().getMapsAndVehicleModel(HttpRequetBean(sn, type)).enqueue(object : Callback<ResponseBody> { |
| | | override fun onFailure(call: Call<ResponseBody>, t: Throwable) { |
| | | MyLog.i(PlatFormConstant.HTTPTAG,t.localizedMessage) |
| | | } |
| | | |
| | | override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) { |
| | | var str: String = response.body()!!.string() |
| | | MyLog.i(PlatFormConstant.HTTPTAG,str) |
| | | jsonObject1 = JSONObject(str) |
| | | val result = jsonObject1!!.getBoolean("result") |
| | | if (result) { |
| | | var mapInfoHead: MapInfoHead = MapInfoHead("","", BaseDataUIBean.TYPE_.car) |
| | | |
| | | when(type){ |
| | | "road" ->{ |
| | | mapInfoHead.type = BaseDataUIBean.TYPE_.road |
| | | val map = gson.fromJson<HttpRoadMapRsp>(str, HttpRoadMapRsp::class.java) |
| | | if (map.isResult) { |
| | | if (map.data != null) { |
| | | mapInfoHead.version = map.data.version |
| | | |
| | | if (map.data.map_json.type.equals("road")) { |
| | | mapInfoHead.str = map.data.map_json.name |
| | | ExamPlatformData.getInstance().setNewRoadMapPath(Environment.getExternalStorageDirectory().absolutePath + "/" |
| | | + app.getAppContext().getPackageName() + "/" + fileName) |
| | | CThreadPoolExecutor.runInBackground(Runnable { |
| | | str = gson.toJson(map.data.map_json) |
| | | MyLog.i(PlatFormConstant.HTTPTAG,"科三道路地图保存成功") |
| | | FileUtil.writeTxtFileToSD(app.getAppContext(), fileName, str, "") |
| | | // sendRoadMapInfo() |
| | | }) |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | }} |
| | | "yard" ->{ |
| | | mapInfoHead.type = BaseDataUIBean.TYPE_.yard |
| | | val yard = gson.fromJson<HttpYardRsp>(str,HttpYardRsp::class.java) |
| | | if (yard.isResult){ |
| | | if (yard.data !=null){ |
| | | mapInfoHead.version = yard.data.version |
| | | mapInfoHead.str = yard.data.map_json.name |
| | | ExamPlatformData.getInstance().setNewMapPath(Environment.getExternalStorageDirectory().absolutePath + "/" |
| | | + app.getAppContext().getPackageName() + "/"+fileName) |
| | | CThreadPoolExecutor.runInBackground(Runnable{ |
| | | MyLog.i(PlatFormConstant.HTTPTAG,"科三场地地图保存成功") |
| | | str = gson.toJson(yard.data.map_json) |
| | | FileUtil.writeTxtFileToSD(app.getAppContext(),fileName,str,"") |
| | | sendMapInfo() |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | else ->{ |
| | | mapInfoHead.type = BaseDataUIBean.TYPE_.car |
| | | val car = gson.fromJson<HttpCarRespBean>(str,HttpCarRespBean::class.java) |
| | | |
| | | if (car.isResult){ |
| | | if (car.data !=null){ |
| | | mapInfoHead.version = car.data.version |
| | | mapInfoHead.str = car.data.map_json.name |
| | | ExamPlatformData.getInstance().carModelPath = Environment.getExternalStorageDirectory().absolutePath + "/" + |
| | | app.getAppContext().getPackageName() + "/"+fileName |
| | | |
| | | // Log.i(TAG, "解析之后的车模型=$str") |
| | | CThreadPoolExecutor.runInBackground(Runnable{ |
| | | str = gson.toJson(car.data.map_json) |
| | | MyLog.i(PlatFormConstant.HTTPTAG,"车辆模型保存成功") |
| | | FileUtil.writeTxtFileToSD(app.getAppContext(),fileName,str,"") |
| | | sendVehicleInfo() |
| | | }) |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | ExamPlatformData.getInstance().setMapHeadInfo(mapInfoHead) |
| | | } else { |
| | | // Toast.makeText(applicationContext, jsonObject1!!.getString("data"), Toast.LENGTH_SHORT).show() |
| | | } |
| | | } |
| | | }) |
| | | |
| | | } |
| | | |
| | | private fun sendMapInfo(){ |
| | | val mapPath = ExamPlatformData.getInstance().mapPath |
| | | |
| | | |
| | | if (!TextUtils.isEmpty(mapPath)) { |
| | | MyLog.i("更新Map的地图$mapPath") |
| | | val fileContent = FileUtil.readFile(mapPath) |
| | | if (fileContent != null) { |
| | | val str = String(fileContent) |
| | | AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_MAP_INFO, str) |
| | | } else { |
| | | MyLog.i(String.format("文件:%s不存在", mapPath)) |
| | | CThreadPoolExecutor.runOnMainThread { Toast.makeText(app.getAppContext(), "文件:" + mapPath + "不存在", Toast.LENGTH_SHORT).show() } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private fun sendVehicleInfo(){ |
| | | val carPath = ExamPlatformData.getInstance().carModelPath |
| | | if (!TextUtils.isEmpty(carPath)) { |
| | | MyLog.i("更新后的Car模型$carPath") |
| | | val bytes = FileUtil.readFile(carPath) |
| | | if (bytes != null) { |
| | | val str = String(bytes) |
| | | AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_VECHILE_PROFILE, str) |
| | | } else { |
| | | MyLog.i(String.format("文件:%s不存在", carPath)) |
| | | } |
| | | } |
| | | } |
| | | private fun sendRoadMapInfo(){ |
| | | val roadmapPath = ExamPlatformData.getInstance().roadMapPath |
| | | |
| | | if (!TextUtils.isEmpty(roadmapPath)) { |
| | | MyLog.i("更新RoadMap地图$roadmapPath") |
| | | val fileContent = FileUtil.readFile(roadmapPath) |
| | | if (fileContent != null) { |
| | | val str = String(fileContent) |
| | | AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_ROAD_MAP_INFO, str) |
| | | } else { |
| | | MyLog.i(String.format("文件:%s不存在", roadmapPath)) |
| | | CThreadPoolExecutor.runOnMainThread { Toast.makeText(app.getAppContext(), "文件:" + roadmapPath + "不存在", Toast.LENGTH_SHORT).show() } |
| | | } |
| | | } else { |
| | | |
| | | } |
| | | } |