From 879378a9a2e73278dc822c97f8d1dda589919b6d Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期五, 21 五月 2021 17:36:44 +0800 Subject: [PATCH] 1. 根据新的协议,扩展了设备编号的位数从1位至6位; 2. 新增监测因子无人机高度; --- src/main/kotlin/com/flightfeather/uav/socket/ServerHandler.kt | 21 ++++++++++++++------- 1 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/socket/ServerHandler.kt b/src/main/kotlin/com/flightfeather/uav/socket/ServerHandler.kt index 8c08a82..fc5202e 100644 --- a/src/main/kotlin/com/flightfeather/uav/socket/ServerHandler.kt +++ b/src/main/kotlin/com/flightfeather/uav/socket/ServerHandler.kt @@ -10,16 +10,23 @@ class ServerHandler : ChannelInboundHandlerAdapter() { + companion object { + private const val TAG = "UAV" + } + val attributeKey = AttributeKey.valueOf<String>("deviceCode") + val messageManager = MessageManager() override fun channelRegistered(ctx: ChannelHandlerContext?) { super.channelRegistered(ctx) - println("------绔彛鏈塈P杩炴帴锛歔ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") + println() + println("------${TAG}绔彛鏈塈P杩炴帴锛歔ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") // ctx?.fireChannelActive() } override fun channelActive(ctx: ChannelHandlerContext?) { - println("------绔彛鏈塈P婵�娲伙細[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") + println() + println("------${TAG}绔彛鏈塈P婵�娲伙細[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") super.channelActive(ctx) } @@ -29,10 +36,10 @@ val sb = StringBuilder() if (msg is ByteArray) { - println("------鏀跺埌鐨勫師濮嬫暟鎹細[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") + println() + println("------${TAG}鏀跺埌鐨勫師濮嬫暟鎹細[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") msg.forEach { - var a = 0 - a = if (it < 0) { + val a: Int = if (it < 0) { it + 256 } else { it.toInt() @@ -49,7 +56,7 @@ } val str = sb.toString() if (str.isNotEmpty()) { - MessageManager().dealStringMsg(str, ctx) + messageManager.dealStringMsg(str, ctx) } } @@ -59,7 +66,7 @@ } override fun channelInactive(ctx: ChannelHandlerContext?) { - println("------绔彛鏈塈P涓嶆椿鍔細[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") + println("------${TAG}绔彛鏈塈P涓嶆椿鍔細[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") super.channelInactive(ctx) } -- Gitblit v1.9.3