|
|
@@ -0,0 +1,77 @@
|
|
|
+package com.grkj.iscs.activity
|
|
|
+
|
|
|
+import android.content.Intent
|
|
|
+import android.os.Environment
|
|
|
+import com.google.gson.Gson
|
|
|
+import com.google.gson.reflect.TypeToken
|
|
|
+import com.grkj.iscs.BusinessManager
|
|
|
+import com.grkj.iscs.base.BaseActivity
|
|
|
+import com.grkj.iscs.databinding.ActivityPresentationLoginBinding
|
|
|
+import com.grkj.iscs.extentions.removeLeadingZeros
|
|
|
+import com.grkj.iscs.extentions.toHexStrings
|
|
|
+import com.grkj.iscs.modbus.ModBusController
|
|
|
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_CARD
|
|
|
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_FINGERPRINT
|
|
|
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_KEY
|
|
|
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_LOCK
|
|
|
+import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_KEY
|
|
|
+import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_LOCK
|
|
|
+import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_PORTABLE
|
|
|
+import com.grkj.iscs.presentation.PresentationActivity
|
|
|
+import com.grkj.iscs.util.FileUtil
|
|
|
+import com.grkj.iscs.util.ToastUtils
|
|
|
+import com.grkj.iscs.util.log.LogUtil
|
|
|
+
|
|
|
+class PresentationLoginActivity : BaseActivity<ActivityPresentationLoginBinding>() {
|
|
|
+
|
|
|
+ val cardList = mutableListOf("267747D5", "34A347D5", "464947D5")
|
|
|
+
|
|
|
+ override val viewBinding: ActivityPresentationLoginBinding
|
|
|
+ get() = ActivityPresentationLoginBinding.inflate(layoutInflater)
|
|
|
+
|
|
|
+ override fun initView() {
|
|
|
+ val path =
|
|
|
+ Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).absolutePath + "/presentation/presentation.txt"
|
|
|
+ val str = FileUtil.readTxt(path)
|
|
|
+
|
|
|
+ if (str.isEmpty()) {
|
|
|
+ ToastUtils.tip("未找到 presentation.txt 文件,请先在手机Download目录创建 presentation 文件夹,并将 presentation.txt 文件放入")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ println("Mac Json : $str")
|
|
|
+ val cardList: List<CardInfoBean> =
|
|
|
+ Gson().fromJson(str, object : TypeToken<List<CardInfoBean>>() {}.type)
|
|
|
+
|
|
|
+ BusinessManager.connectDock(1, true)
|
|
|
+
|
|
|
+ ModBusController.registerStatusListener(this) { res ->
|
|
|
+ (res as List<ByteArray>).forEach { bytes ->
|
|
|
+ val dockBean = ModBusController.updateStatus(bytes) ?: return@forEach
|
|
|
+ when (dockBean.type) {
|
|
|
+ DOCK_TYPE_PORTABLE -> {
|
|
|
+ dockBean.deviceList.forEach { deviceBean ->
|
|
|
+ if (deviceBean.isExist) {
|
|
|
+ when (deviceBean.type) {
|
|
|
+ DEVICE_TYPE_CARD -> {
|
|
|
+ ModBusController.readPortalCaseCardRfid(dockBean.addr.toInt() - 1) { res ->
|
|
|
+ val rfid = res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
+ println("卡片RFID : $rfid")
|
|
|
+ if (cardList.any { it.rfid == rfid }) {
|
|
|
+ ToastUtils.tip("登录成功,欢迎 $rfid")
|
|
|
+ startActivity(Intent(this, PresentationActivity::class.java))
|
|
|
+ return@readPortalCaseCardRfid
|
|
|
+ }
|
|
|
+ ToastUtils.tip("登录失败,$rfid 没有权限")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ data class CardInfoBean(val rfid: String, val mac: String)
|
|
|
+}
|