Browse Source

钥匙bean添加mac参数

Frankensteinly 1 year ago
parent
commit
d6d7940d98

+ 9 - 1
app/src/main/java/com/grkj/iscs/activity/WebSocketActivity.kt

@@ -2,6 +2,8 @@ package com.grkj.iscs.activity
 
 
 import com.grkj.iscs.base.BaseBindingActivity
 import com.grkj.iscs.base.BaseBindingActivity
 import com.grkj.iscs.databinding.ActivityWebSocketBinding
 import com.grkj.iscs.databinding.ActivityWebSocketBinding
+import com.grkj.iscs.util.StompApi
+import com.grkj.iscs.util.log.LogUtil
 
 
 class WebSocketActivity : BaseBindingActivity<ActivityWebSocketBinding>() {
 class WebSocketActivity : BaseBindingActivity<ActivityWebSocketBinding>() {
 
 
@@ -9,6 +11,12 @@ class WebSocketActivity : BaseBindingActivity<ActivityWebSocketBinding>() {
         get() = ActivityWebSocketBinding.inflate(layoutInflater)
         get() = ActivityWebSocketBinding.inflate(layoutInflater)
 
 
     override fun initView() {
     override fun initView() {
-
+        StompApi.refuseStomp(this) { stomp, destination ->
+            stomp.topic(destination) {
+                LogUtil.i("haha3 : ${it.payload}")
+            }
+            LogUtil.i("haha1 : $stomp")
+            LogUtil.i("haha2 : $destination")
+        }
     }
     }
 }
 }

+ 3 - 3
app/src/main/java/com/grkj/iscs/modbus/DeviceBean.kt

@@ -32,8 +32,8 @@ class DeviceBean(
                     val isRightCharging = (byteArray[3].toInt() shr 1) and 0x1 == 1
                     val isRightCharging = (byteArray[3].toInt() shr 1) and 0x1 == 1
                     LogUtil.i("钥匙刷新状态 : $leftHasKey - $isLeftCharging - $rightHasKey - $isRightCharging")
                     LogUtil.i("钥匙刷新状态 : $leftHasKey - $isLeftCharging - $rightHasKey - $isRightCharging")
                     if (keyList.isEmpty()) {
                     if (keyList.isEmpty()) {
-                        keyList.add(KeyBean(true, leftHasKey, isLeftCharging, null))
-                        keyList.add(KeyBean(false, rightHasKey, isRightCharging, null))
+                        keyList.add(KeyBean(true, leftHasKey, isLeftCharging, null, null))
+                        keyList.add(KeyBean(false, rightHasKey, isRightCharging, null, null))
                         return null
                         return null
                     }
                     }
 
 
@@ -107,7 +107,7 @@ class DeviceBean(
     /**
     /**
      * 钥匙
      * 钥匙
      */
      */
-    data class KeyBean(var isLeft: Boolean, var hasKey: Boolean, var isCharging: Boolean, var rfid: String?)
+    data class KeyBean(var isLeft: Boolean, var hasKey: Boolean, var isCharging: Boolean, var rfid: String?, var mac: String?)
     /**
     /**
      * 锁具
      * 锁具
      *
      *

+ 8 - 2
app/src/main/java/com/grkj/iscs/modbus/ModBusController.kt

@@ -107,6 +107,7 @@ object ModBusController {
             // TODO 打开所有无钥匙的卡扣
             // TODO 打开所有无钥匙的卡扣
             // TODO 关闭所有钥匙灯光
             // TODO 关闭所有钥匙灯光
             // TODO 读取所有锁的RFID
             // TODO 读取所有锁的RFID
+            // TODO 读取所有钥匙的RFID
             // TODO 设置所有钥匙的模式
             // TODO 设置所有钥匙的模式
         }
         }
     }
     }
@@ -187,6 +188,13 @@ object ModBusController {
         deviceList.find { it.idx?.toInt() == slaveIdx }?.keyList?.find { it.isLeft == isLeft }?.rfid = rfid
         deviceList.find { it.idx?.toInt() == slaveIdx }?.keyList?.find { it.isLeft == isLeft }?.rfid = rfid
     }
     }
 
 
+    /**
+     * 通过RFID更新对应的Mac
+     */
+    fun updateKeyMacByRfid(rfid: String, mac: String) {
+        deviceList.find { it.type == 0x00.toByte() }?.keyList?.find { it.rfid == rfid }?.mac = mac
+    }
+
     /**
     /**
      * 更新锁具RFID
      * 更新锁具RFID
      */
      */
@@ -238,6 +246,4 @@ object ModBusController {
     fun getLockByRfid(rfid: String): DeviceBean.LockBean? {
     fun getLockByRfid(rfid: String): DeviceBean.LockBean? {
         return deviceList.find { it.type == 0x01.toByte() }?.lockList?.find { it.rfid == rfid }
         return deviceList.find { it.type == 0x01.toByte() }?.lockList?.find { it.rfid == rfid }
     }
     }
-
-    // TODO 根据RFID找锁
 }
 }

+ 2 - 2
app/src/main/java/com/grkj/iscs/model/Constants.kt

@@ -4,6 +4,6 @@ object Constants {
     const val PERMISSION_REQUEST_CODE = 1
     const val PERMISSION_REQUEST_CODE = 1
     const val BLE_LOCAL_NAME = "keyLock"
     const val BLE_LOCAL_NAME = "keyLock"
 
 
-    const val BASE_URL = "http://192.168.1.3:48080"
-    const val WEB_SOCKET = ""
+    const val BASE_URL = "http://192.168.1.127:9090"
+    const val WEB_SOCKET = "ws://192.168.1.127:9090/websocket/iot/127"
 }
 }

+ 15 - 12
app/src/main/java/com/grkj/iscs/util/StompApi.kt

@@ -12,22 +12,22 @@ import com.grkj.iscs.util.log.LogUtil
 object StompApi {
 object StompApi {
 
 
     fun refuseStomp(ctx: Context, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
     fun refuseStomp(ctx: Context, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
-//        stomp(ctx, UrlConsts.MQ_VHOST_REFUSE, "machine.${ctx.serialNo()}", callback)
+        stomp(ctx, "", callback)
     }
     }
 
 
 
 
-    private fun stomp(ctx: Context, vhost: String, destinationInfix: String, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
+    private fun stomp(ctx: Context, destinationInfix: String, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
         Executor.runOnMain {
         Executor.runOnMain {
             ctx.addNetObserver(object : OnceNetObserver() {
             ctx.addNetObserver(object : OnceNetObserver() {
                 override fun onNetAvailable() {
                 override fun onNetAvailable() {
-                    onNetAvailable(ctx, vhost, destinationInfix, callback)
+                    onNetAvailable(ctx, destinationInfix, callback)
                     ctx.removeNetObserver(this)
                     ctx.removeNetObserver(this)
                 }
                 }
             })
             })
         }
         }
     }
     }
 
 
-    private fun onNetAvailable(ctx: Context, vhost: String, destinationInfix: String, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
+    private fun onNetAvailable(ctx: Context, destinationInfix: String, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
 //        PlatformRepository(ctx).getPlatformId().observeForever { platformId ->
 //        PlatformRepository(ctx).getPlatformId().observeForever { platformId ->
 //            if (platformId != null) {
 //            if (platformId != null) {
 //                Authorization.requestToken(ctx) { token ->
 //                Authorization.requestToken(ctx) { token ->
@@ -39,26 +39,29 @@ object StompApi {
 //                LogUtil.w("platformId = null")
 //                LogUtil.w("platformId = null")
 //            }
 //            }
 //        }
 //        }
+        connectStompServer(ctx, destinationInfix, callback)
     }
     }
 
 
-    private fun connectStompServer(ctx: Context, vhost: String, destinationInfix: String, platformId: String, token: String, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
+    private fun connectStompServer(ctx: Context, destinationInfix: String, callback: (stomp: Stomp, baseDestination: String) -> Unit) {
         LogUtil.i("开始连接 STOMP 服务")
         LogUtil.i("开始连接 STOMP 服务")
-        Stomp.over(OkHttps.webSocket(Constants.WEB_SOCKET).heatbeat(20, 20))
+//        Stomp.over(OkHttps.webSocket(Constants.WEB_SOCKET).heatbeat(20, 20))
+        Stomp.over(OkHttps.webSocket(Constants.WEB_SOCKET))
             .setOnConnected {
             .setOnConnected {
-                callback(it, "/p-${platformId}-a.${destinationInfix}")
+                callback(it, "/p--a.${destinationInfix}")
             }
             }
             .setOnDisconnected {
             .setOnDisconnected {
                 if (it.code != 1000) {
                 if (it.code != 1000) {
                     LogUtil.i("Websockt 已断开:${it.code}: ${it.reason},10 秒后重连...")
                     LogUtil.i("Websockt 已断开:${it.code}: ${it.reason},10 秒后重连...")
                     Executor.delayOnIO({
                     Executor.delayOnIO({
-                        stomp(ctx, vhost, destinationInfix, callback)
+                        stomp(ctx, destinationInfix, callback)
                     }, 10000)
                     }, 10000)
                 }
                 }
             }
             }
-            .connect(listOf(
-                Header("login", token),
-                Header("host", vhost)
-            ))
+            .connect()
+//            .connect(listOf(
+//                Header("login", token),
+//                Header("host", vhost)
+//            ))
     }
     }