max value
This commit is contained in:
parent
1ad169440d
commit
4d38e23be1
|
@ -15,6 +15,26 @@ public class GatewayTest {
|
||||||
String s2 = "KENENG1400000358";
|
String s2 = "KENENG1400000358";
|
||||||
System.out.println(new String(HexUtil.hexStringToBytes(s1)));
|
System.out.println(new String(HexUtil.hexStringToBytes(s1)));
|
||||||
System.out.println(HexUtil.bytesToHexString(s2.getBytes()));
|
System.out.println(HexUtil.bytesToHexString(s2.getBytes()));
|
||||||
|
|
||||||
|
|
||||||
|
String hex = "333538";
|
||||||
|
int decimal = 0;
|
||||||
|
int power = 0;
|
||||||
|
for (int i = hex.length() - 1; i >= 0; i--) {
|
||||||
|
char digit = hex.charAt(i);
|
||||||
|
if (digit >= '0' && digit <= '9') {
|
||||||
|
decimal += (digit - '0') * Math.pow(16, power);
|
||||||
|
} else if (digit >= 'A' && digit <= 'F') {
|
||||||
|
decimal += (digit - 'A' + 10) * Math.pow(16, power);
|
||||||
|
} else if (digit >= 'a' && digit <= 'f') {
|
||||||
|
decimal += (digit - 'a' + 10) * Math.pow(16, power);
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Invalid hex digit: " + digit);
|
||||||
|
}
|
||||||
|
power++;
|
||||||
|
}
|
||||||
|
System.out.println(decimal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.iot.modbus_rtcp;
|
package com.iot.modbus_rtcp;
|
||||||
|
|
||||||
|
import com.iot.modbus_rtcp.utils.HexUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
@ -48,7 +50,7 @@ public class NonBlockingSocketTest {
|
||||||
lastSentHeartBeatTime = nowTime;
|
lastSentHeartBeatTime = nowTime;
|
||||||
socketChannel.write(heartBeatBuffer);
|
socketChannel.write(heartBeatBuffer);
|
||||||
}
|
}
|
||||||
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(500));
|
LockSupport.parkNanos(TimeUnit.MILLISECONDS.toNanos(100));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String line = byteBufferToHexString(readBuffer).trim();
|
String line = byteBufferToHexString(readBuffer).trim();
|
||||||
|
@ -57,24 +59,20 @@ public class NonBlockingSocketTest {
|
||||||
System.out.println(LocalDateTime.now() + "<==:收到服务器端请求:" + line);
|
System.out.println(LocalDateTime.now() + "<==:收到服务器端请求:" + line);
|
||||||
|
|
||||||
// 接收到请求
|
// 接收到请求
|
||||||
switch (line.toUpperCase()) {
|
switch (line.toUpperCase().substring(0, line.length() - 4)) {
|
||||||
case "01040000001671C4" ->
|
case "010200140004" ->
|
||||||
// 发送响应字符串
|
socketChannel.write(ByteBuffer.wrap(HexUtil.hexStringToBytes("01042C07D000010003000C002B0029000300010000001A0018003303CD002300080DAC0DAC0000000000000959091DF066")));
|
||||||
socketChannel.write(ByteBuffer.wrap("01 04 2A 07 E8 00 0B 00 13 00 17 00 11 00 23 00 03 00 01 00 00 00 00 00 02 00 3B 03 E7 00 39 00 00 0D AC 0D AC 00 00 00 00 00 00 0A 14 4A 98".replaceAll(" ", "").getBytes()));
|
case "0103006A002A" ->
|
||||||
|
socketChannel.write(ByteBuffer.wrap(HexUtil.hexStringToBytes("0103A400010000000000000000000000000000000000000001000100000000000A0005001E000B001E00000011002D00000012000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001001E00000017001E00000000000100230000000003E800640000000A0000000000000000000003E7003B003B00000001000103E7003B003B0000000100019014")));
|
||||||
|
case "0104000A001A" ->
|
||||||
|
socketChannel.write(ByteBuffer.wrap(HexUtil.hexStringToBytes("01043400020016002B0034000100070001000F001E0016000A00000000000000000000000000000000000003080000153D000000001365B5E3")));
|
||||||
// 接收到开井请求
|
// 接收到开井请求
|
||||||
case "01050001FF00DDFA" ->
|
case "01050000FF00" ->
|
||||||
// 发送响应字符串
|
socketChannel.write(ByteBuffer.wrap(HexUtil.hexStringToBytes("01050000FF00DDFA")));
|
||||||
socketChannel.write(ByteBuffer.wrap("01050001FF00DDFA".getBytes()));
|
|
||||||
|
|
||||||
// 接收到关井请求
|
// 接收到关井请求
|
||||||
case "0105000100009C0A" ->
|
case "01050001FF00" ->
|
||||||
// 发送响应字符串
|
socketChannel.write(ByteBuffer.wrap(HexUtil.hexStringToBytes("01050001FF00DDFA")));
|
||||||
socketChannel.write(ByteBuffer.wrap("0105000100009C0A".getBytes()));
|
|
||||||
|
|
||||||
// 接收到读取运行模式请求
|
|
||||||
case "010300640001C5D5" ->
|
|
||||||
// 发送响应字符串
|
|
||||||
socketChannel.write(ByteBuffer.wrap("01 03 02 00 03 F8 45".replaceAll(" ", "").getBytes()));
|
|
||||||
// 接收到退出请求
|
// 接收到退出请求
|
||||||
case "exit" -> socketChannel.close();
|
case "exit" -> socketChannel.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue