| | |
| | | |
| | | import android.content.Context |
| | | import android.util.Log |
| | | import android.widget.Toast |
| | | 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.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; |
| | | Log.i(TAG,"查到的考试type="+examType) |
| | | singalConfigs = WorkRoomDataBase.getWorkRoomDataBase(applicationContext).signalConfigDao._getSignalConfigs() |
| | | 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 { |
| | |
| | | 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 |
| | | } |
| | | |
| | | } |