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/UAVApplication.kt | 4 ++--
src/main/kotlin/com/flightfeather/uav/socket/UnderwaySocketServer.kt | 11 +++++------
src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt | 10 +++++-----
src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataPackageDecoderImpl.kt | 11 ++++++++---
src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataUnitDecoderImpl.kt | 8 ++++----
src/main/kotlin/com/flightfeather/uav/socket/bean/AirDataPackage.kt | 5 +----
src/main/kotlin/com/flightfeather/uav/socket/eunm/FactorType.kt | 4 +++-
src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt | 7 -------
8 files changed, 28 insertions(+), 32 deletions(-)
diff --git a/src/main/kotlin/com/flightfeather/uav/UAVApplication.kt b/src/main/kotlin/com/flightfeather/uav/UAVApplication.kt
index 6e53c91..307d5eb 100644
--- a/src/main/kotlin/com/flightfeather/uav/UAVApplication.kt
+++ b/src/main/kotlin/com/flightfeather/uav/UAVApplication.kt
@@ -1,6 +1,6 @@
package com.flightfeather.uav
-import com.flightfeather.uav.socket.SocketServerClient
+import com.flightfeather.uav.socket.UnderwaySocketServer
import org.springframework.boot.ApplicationRunner
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@@ -11,7 +11,7 @@
@Bean
fun runner() = ApplicationRunner{
- SocketServerClient().startServer(9030)
+ UnderwaySocketServer().startServer(9030)
}
}
diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt
index e97b121..365c0ef 100644
--- a/src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt
+++ b/src/main/kotlin/com/flightfeather/uav/lightshare/web/RealTimeDataController.kt
@@ -12,11 +12,11 @@
@GetMapping("/sec")
fun getSecondData(
- @RequestParam(value = "deviceCode", required = false) deviceCode: String?,
- @RequestParam(value = "startTime", required = false) startTime: String?,
- @RequestParam(value = "endTime", required = false) endTime: String?,
- @RequestParam(value = "page", required = false) page: Int?,
- @RequestParam(value = "perPage", required = false) perPage: Int?
+ @RequestParam(value = "deviceCode", required = false) deviceCode: String?,
+ @RequestParam(value = "startTime", required = false) startTime: String?,
+ @RequestParam(value = "endTime", required = false) endTime: String?,
+ @RequestParam(value = "page", required = false) page: Int?,
+ @RequestParam(value = "perPage", required = false) perPage: Int?
) = realTimeDataService.getSecondData(deviceCode, startTime, endTime, page, perPage)
@GetMapping("/sec/next")
diff --git a/src/main/kotlin/com/flightfeather/uav/socket/SocketServerClient.kt b/src/main/kotlin/com/flightfeather/uav/socket/UnderwaySocketServer.kt
similarity index 82%
rename from src/main/kotlin/com/flightfeather/uav/socket/SocketServerClient.kt
rename to src/main/kotlin/com/flightfeather/uav/socket/UnderwaySocketServer.kt
index 80eddb7..699f09e 100644
--- a/src/main/kotlin/com/flightfeather/uav/socket/SocketServerClient.kt
+++ b/src/main/kotlin/com/flightfeather/uav/socket/UnderwaySocketServer.kt
@@ -10,12 +10,11 @@
import io.netty.handler.codec.string.StringEncoder
import java.nio.charset.Charset
-/**
- * socket闀胯繛鎺ユ湇鍔$
- * 2019.8.26
- * @author riku
- */
-class SocketServerClient {
+/*********************************************************************************
+ * 璧拌埅鐩戞祴鏁版嵁socket闀胯繛鎺ユ湇鍔$
+ * 鐢ㄤ簬鎺ユ敹瑙f瀽璧拌埅鐩戞祴鏁版嵁锛屽墠绔洃娴嬭澶囩洰鍓嶅寘鎷溅杞借蛋鑸�佹棤浜烘満璧拌埅浠ュ強鏃犱汉鑸硅蛋鑸笁绉嶇被鍨�
+ * *******************************************************************************/
+class UnderwaySocketServer {
private val bossGroup = NioEventLoopGroup()
private val workerGroup = NioEventLoopGroup()
diff --git a/src/main/kotlin/com/flightfeather/uav/socket/bean/AirDataPackage.kt b/src/main/kotlin/com/flightfeather/uav/socket/bean/AirDataPackage.kt
index 08b425f..e45b25e 100644
--- a/src/main/kotlin/com/flightfeather/uav/socket/bean/AirDataPackage.kt
+++ b/src/main/kotlin/com/flightfeather/uav/socket/bean/AirDataPackage.kt
@@ -33,12 +33,9 @@
//鏁版嵁涓殑淇濈暀瀛楄妭鏁�
const val RESERVED_DATA_COUNT = 12
- //涓�涓姩鎬佺洃娴嬪洜瀛愮殑灞炴�ф墍鍗犲瓧鑺傛暟
+ //鍔ㄦ�佺洃娴嬪洜瀛愭墍鍗犲瓧鑺傛暟,涓嶅悓浣嶆暟瀵瑰簲涓嶅悓鐨勭粍鍚堢瓥鐣�
const val FACTOR_BIT_LENGTH_1 = 6
-
- //涓�涓繚鐣欑洃娴嬪洜瀛愮殑灞炴�ф墍鍗犲瓧鑺傛暟
const val FACTOR_BIT_LENGTH_2 = 3
-
const val FACTOR_BIT_LENGTH_3 = 2
}
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt b/src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt
index f9a8179..0975dd8 100644
--- a/src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt
+++ b/src/main/kotlin/com/flightfeather/uav/socket/decoder/DataUnitDecoder.kt
@@ -11,13 +11,6 @@
*
* 鏁版嵁鍗曞厓鎸夌収鍛戒护鍗曞厓鐨勭被鍨嬪叡鏈変互涓嬪嚑绉嶇被鍨嬶細
* 鍛戒护鍗曞厓 @see [AirCommandUnit]
- * 缂栫爜(byte) 瀹氫箟
- * 0x01 杞﹁締鐧诲叆
- * 0x02 瀹炴椂淇℃伅涓婃姤
- * 0x03 琛ュ彂淇℃伅涓婃姤
- * 0x04 杞﹁締鐧诲嚭
- * 0x05 缁堢鏍℃椂
- * 0x06~0x7f 涓婅鏁版嵁绯荤粺棰勭暀
*/
interface DataUnitDecoder {
diff --git a/src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataPackageDecoderImpl.kt b/src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataPackageDecoderImpl.kt
index deadf89..e79b6c0 100644
--- a/src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataPackageDecoderImpl.kt
+++ b/src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataPackageDecoderImpl.kt
@@ -14,10 +14,15 @@
class DataPackageDecoderImpl : DataPackageDecoder {
companion object {
+// 鏁版嵁澶�
const val HEAD_BYTES = 1
+// 鐩戞祴鍙傛暟纭鎸囦护浣�
const val COMMAND_UNIT_BYTES = 1
- const val DEVICE_CODE_BYTES = 1
+// 璁惧绫诲瀷
+ const val DEVICE_CODE_BYTES = 6
+// 鏈鐩戞祴鐨勭┖姘斿洜瀛愭暟閲�
const val DATA_LENGTH = 1
+// 鏍¢獙
const val BCC_BYTES = 2
}
@@ -47,7 +52,7 @@
}
override fun getDeviceCode(b: List<String>): String? = if (b.size >= (HEAD_BYTES + COMMAND_UNIT_BYTES + DEVICE_CODE_BYTES)) {
- //2021/1/7 '0A'浠h〃杞﹁浇璁惧锛�'0B'浠h〃鏃犱汉鏈鸿澶�
+ //2021/1/7 '0A'浠h〃杞﹁浇璁惧锛�'0B'浠h〃鏃犱汉鏈鸿澶囷紝'0C'涓虹綉鏍煎寲鐩戞祴
val s = StringBuilder()
repeat(DEVICE_CODE_BYTES) {
s.append(b[HEAD_BYTES + COMMAND_UNIT_BYTES + it])
@@ -91,7 +96,7 @@
}
override fun getCheckCode(b: List<String>): Int? {
- return if (b.size >= 5) {
+ return if (b.size >= HEAD_BYTES + COMMAND_UNIT_BYTES + DEVICE_CODE_BYTES + BCC_BYTES) {
val hexNum = "${b[b.size - 2]}${b[b.size - 1]}"
hexNum.toIntOrNull(16)
diff --git a/src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataUnitDecoderImpl.kt b/src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataUnitDecoderImpl.kt
index a5ffbd5..3290fa7 100644
--- a/src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataUnitDecoderImpl.kt
+++ b/src/main/kotlin/com/flightfeather/uav/socket/decoder/impl/DataUnitDecoderImpl.kt
@@ -89,10 +89,10 @@
}
FactorType.TIME -> {
val year = b[i].toInt(16).toString().run { numberFormat(this) }
- val month = b[i+1].toInt(16).toString().run { numberFormat(this) }
- val day = b[i+2].toInt(16).toString().run { numberFormat(this) }
- val hour = b[i+3].toInt(16).toString().run { numberFormat(this) }
- val minute = b[i+4].toInt(16).toString().run { numberFormat(this) }
+ val month = b[i + 1].toInt(16).toString().run { numberFormat(this) }
+ val day = b[i + 2].toInt(16).toString().run { numberFormat(this) }
+ val hour = b[i + 3].toInt(16).toString().run { numberFormat(this) }
+ val minute = b[i + 4].toInt(16).toString().run { numberFormat(this) }
val second = b[i + 5].toInt(16).toString().run { numberFormat(this) }
val date = "20$year-$month-$day $hour:$minute:$second"
val time = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date).time
diff --git a/src/main/kotlin/com/flightfeather/uav/socket/eunm/FactorType.kt b/src/main/kotlin/com/flightfeather/uav/socket/eunm/FactorType.kt
index a4ddeaf..a2f5f43 100644
--- a/src/main/kotlin/com/flightfeather/uav/socket/eunm/FactorType.kt
+++ b/src/main/kotlin/com/flightfeather/uav/socket/eunm/FactorType.kt
@@ -21,7 +21,8 @@
VELOCITY(14, "VELOCITY", 3),//閫熷害
TIME(15, "TIME", 6),//鏃堕棿
WIND_SPEED(16, "WIND_SPEED", 3),
- WIND_DIRECTION(17, "WIND_DIRECTION", 2);
+ WIND_DIRECTION(17, "WIND_DIRECTION", 2),
+ HEIGHT(18, "HEIGHT", 3);
companion object {
@@ -43,6 +44,7 @@
TIME.value -> TIME
WIND_SPEED.value -> WIND_SPEED
WIND_DIRECTION.value -> WIND_DIRECTION
+ HEIGHT.value -> HEIGHT
else -> null
}
}
--
Gitblit v1.9.3