package safeluck.drive.evaluation.DB.exam_status
|
|
import android.content.Context
|
import android.util.Log
|
import androidx.work.Data
|
import androidx.work.Worker
|
import androidx.work.WorkerParameters
|
import com.anyun.exam.lib.AYSdk
|
import com.anyun.exam.lib.MyLog
|
import com.google.gson.Gson
|
import org.json.JSONException
|
import org.json.JSONObject
|
import safeluck.drive.evaluation.DB.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.SignalConfigRemote
|
|
class ExamStatusOutWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) {
|
val TAG:String = "ExamStatusOutWorker"
|
private var signalConfiglist: MutableList<SignalConfigRemote> = ArrayList()
|
private val gson = Gson()
|
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("查到的考试type="+examType)
|
val data = Data.Builder().putInt(Constant.EXAM_STATUS_TYPE,examType).build()
|
if (examType != safeluck.drive.evaluation.Constant.NONE_BEEN_START_EXAM) {
|
try {
|
val jsonObject = JSONObject()
|
jsonObject.put("exam", 1)
|
jsonObject.put("type", examType)
|
val examJson = jsonObject.toString()
|
AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.EXAM_STATUS, examJson)
|
} catch (e: JSONException) {
|
e.printStackTrace()
|
}
|
}
|
return Result.success(data)
|
}
|
|
private fun sendSignalConfigsToRemote(indexs: List<Int>) {
|
if (signalConfiglist.size > 0) {
|
if (listContainsSameValue(indexs)) {
|
Log.i(TAG, "sendSignalConfigsToRemote: 有相同的index,不能发送" + gson.toJson(signalConfiglist))
|
} else {
|
AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.SEND_CONFIG_SIGNAL, gson.toJson(signalConfiglist))
|
}
|
}
|
}
|
|
private fun listContainsSameValue(indexs: List<Int>): Boolean {
|
for (i in indexs.indices) { //可以默认是0 0不判断是否有相同的index
|
if (indexs[i] == 0) {
|
continue
|
}
|
for (j in i + 1 until indexs.size) {
|
if (indexs[i] === indexs[j]) {
|
return true
|
}
|
}
|
}
|
return false
|
}
|
|
|
private fun sendRtkConfigInfo(mRTKConfig: RTKConfig) {
|
if (mRTKConfig != null) {
|
var rtkjson = gson.toJson(mRTKConfig)
|
//去除id字段
|
var jsonObject: JSONObject? = null
|
try {
|
jsonObject = JSONObject(rtkjson)
|
} catch (e: JSONException) {
|
e.printStackTrace()
|
}
|
jsonObject!!.remove("_id")
|
rtkjson = null
|
rtkjson = jsonObject.toString()
|
MyLog.i(TAG, "RTK配置信息:$rtkjson")
|
AYSdk.getInstance().sendCmd(safeluck.drive.evaluation.Constant.PUSH_RTK_PLATFORM_INFO, rtkjson)
|
} else {
|
MyLog.d(TAG, "RTKConfig未取到数据")
|
}
|
}
|
|
}
|