| | |
| | | import com.anyun.exam.lib.AYSdk |
| | | import com.anyun.exam.lib.MyLog |
| | | import com.google.gson.Gson |
| | | import com.google.gson.reflect.TypeToken |
| | | import com.google.gson.stream.JsonReader |
| | | import org.json.JSONException |
| | | import org.json.JSONObject |
| | | import safeluck.drive.evaluation.DB.Constant |
| | |
| | | import safeluck.drive.evaluation.DB.rtktb.RTKConfig |
| | | import safeluck.drive.evaluation.DB.signalConfigdb.SingalConfig |
| | | import safeluck.drive.evaluation.bean.SignalConfigRemote |
| | | import java.io.IOException |
| | | import java.io.InputStreamReader |
| | | |
| | | class ExamStatusOutWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { |
| | | val TAG:String = "ExamStatusOutWorker" |
| | |
| | | private var singalConfigs :List<SingalConfig> = ArrayList() |
| | | override fun doWork(): Result { |
| | | val examType =WorkRoomDataBase.getWorkRoomDataBase(applicationContext).examStatusDao.startExamInt; |
| | | singalConfigs = WorkRoomDataBase.getWorkRoomDataBase(applicationContext).signalConfigDao._getSignalConfigs() |
| | | |
| | | sendRtkConfigInfo(WorkRoomDataBase.getWorkRoomDataBase(applicationContext).rtkConfigDao._getRtkConfig()) |
| | | for (i in singalConfigs.indices) { |
| | | val signalConfigRemote = SignalConfigRemote() |
| | | signalConfigRemote.func_id = i |
| | | signalConfigRemote.gpio_num = singalConfigs.get(i).getIndex() |
| | | signalConfigRemote.level = singalConfigs.get(i).getHighLevel() |
| | | signalConfiglist.add(signalConfigRemote) |
| | | } |
| | | var indexs = WorkRoomDataBase.getWorkRoomDataBase(applicationContext).signalConfigDao.allIndexs |
| | | sendSignalConfigsToRemote(indexs) |
| | | |
| | | |
| | | MyLog.i(TAG,"查到的考试type="+examType) |
| | | val data = Data.Builder().putInt(Constant.EXAM_STATUS_TYPE,examType).build() |
| | | if (examType != safeluck.drive.evaluation.Constant.NONE_BEEN_START_EXAM) { |
| | |
| | | e.printStackTrace() |
| | | } |
| | | } |
| | | var rtk = WorkRoomDataBase.getWorkRoomDataBase(applicationContext).rtkConfigDao._getRtkConfig() |
| | | if (rtk == null){ |
| | | try { |
| | | MyLog.i("读文件发送RTK配置") |
| | | val inputStream = applicationContext.assets.open(safeluck.drive.evaluation.Constant.RTK_CONFIG_JSON) |
| | | val inputStreamReader = InputStreamReader(inputStream) |
| | | val jsonReader = JsonReader(inputStreamReader) |
| | | val gson = Gson() |
| | | val type = object : TypeToken<RTKConfig?>() {}.type |
| | | val mstus = gson.fromJson<RTKConfig>(jsonReader, type) |
| | | rtk = mstus |
| | | } catch (e: IOException) { |
| | | e.printStackTrace() |
| | | } |
| | | }else{ |
| | | |
| | | } |
| | | sendRtkConfigInfo(rtk) |
| | | singalConfigs = WorkRoomDataBase.getWorkRoomDataBase(applicationContext).signalConfigDao._getSignalConfigs() |
| | | if (singalConfigs ==null){ |
| | | MyLog.i("读文件发送信号配置") |
| | | try { |
| | | val inputStream = applicationContext.assets.open("signal_config_file.json") |
| | | val inputStreamReader = InputStreamReader(inputStream) |
| | | val jsonReader = JsonReader(inputStreamReader) |
| | | val gson = Gson() |
| | | val type = object : TypeToken<List<SingalConfig?>?>() {}.type |
| | | val mstus = gson.fromJson<List<SingalConfig>>(jsonReader, type) |
| | | singalConfigs = mstus |
| | | } catch (e: IOException) { |
| | | e.printStackTrace() |
| | | } |
| | | }else{ |
| | | |
| | | } |
| | | for (i in singalConfigs.indices) { |
| | | val signalConfigRemote = SignalConfigRemote() |
| | | signalConfigRemote.func_id = i |
| | | signalConfigRemote.gpio_num = singalConfigs.get(i).getIndex() |
| | | signalConfigRemote.level = singalConfigs.get(i).getHighLevel() |
| | | signalConfiglist.add(signalConfigRemote) |
| | | } |
| | | |
| | | |
| | | var indexs = WorkRoomDataBase.getWorkRoomDataBase(applicationContext).signalConfigDao.allIndexs |
| | | |
| | | sendSignalConfigsToRemote(indexs) |
| | | |
| | | |
| | | return Result.success(data) |
| | | } |
| | | |
| | |
| | | jsonObject!!.remove("_id") |
| | | rtkjson = null |
| | | rtkjson = jsonObject.toString() |
| | | MyLog.i(TAG, "RTK配置信息:$rtkjson") |
| | | MyLog.i(TAG, "NDK_start RTK配置信息") |
| | | AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_RTK_PLATFORM_INFO, rtkjson) |
| | | } else { |
| | | MyLog.d(TAG, "RTKConfig未取到数据") |