├── .gitattributes ├── notice ├── 博图-开启访问权限.png ├── 博图-允许PUT-GET.png ├── 博图-不要勾选DB块优化访问.png ├── S200-Smart不同型号不同区的地址范围.png └── S7+SourceTSAP+DestinationTSAP.md ├── src ├── test │ ├── resources │ │ └── simplelogger.properties │ └── java │ │ └── com │ │ └── github │ │ └── xingshuangs │ │ └── iot │ │ ├── utils │ │ ├── LongUtilTest.java │ │ ├── LRCUtilTest.java │ │ ├── TimesUtilTest.java │ │ ├── ByteUtilTest.java │ │ └── FloatUtilTest.java │ │ ├── AppTest.java │ │ ├── common │ │ └── serializer │ │ │ └── ByteArrayCharsetBean.java │ │ ├── protocol │ │ ├── s7 │ │ │ ├── model │ │ │ │ ├── TPKTTest.java │ │ │ │ ├── COTPTest.java │ │ │ │ ├── COTPDataTest.java │ │ │ │ ├── DataItemTest.java │ │ │ │ ├── COTPConnectionTest.java │ │ │ │ ├── DatumTest.java │ │ │ │ └── Mc7FileTest.java │ │ │ ├── service │ │ │ │ ├── DemoS7Control.java │ │ │ │ └── S7PLCConnect.java │ │ │ ├── enums │ │ │ │ └── EPlcTypeTest.java │ │ │ └── serializer │ │ │ │ └── DemoLargeBean.java │ │ ├── melsec │ │ │ └── model │ │ │ │ ├── Mc4E3EFrameAccessRouteTest.java │ │ │ │ └── McError4E3EDataTest.java │ │ ├── rtsp │ │ │ └── model │ │ │ │ └── RtspRtpInfoTest.java │ │ ├── modbus │ │ │ ├── service │ │ │ │ ├── DemoModbusTcpServerTest.java │ │ │ │ └── ModbusAsciiOverTcpTest.java │ │ │ └── model │ │ │ │ ├── MbReadCoilRequestTest.java │ │ │ │ ├── MbReadCoilResponseTest.java │ │ │ │ ├── MbReadInputRegisterResponseTest.java │ │ │ │ ├── MbWriteMultipleCoilResponseTest.java │ │ │ │ ├── MbWriteSingleCoilRequestTest.java │ │ │ │ ├── MbWriteMultipleRegisterResponseTest.java │ │ │ │ ├── MbReadHoldRegisterRequestTest.java │ │ │ │ ├── MbReadInputRegisterRequestTest.java │ │ │ │ ├── MbReadDiscreteInputRequestTest.java │ │ │ │ ├── MbWriteSingleRegisterRequestTest.java │ │ │ │ ├── MbReadDiscreteInputResponseTest.java │ │ │ │ └── MbWriteSingleCoilResponseTest.java │ │ └── mp4 │ │ │ └── model │ │ │ └── Mp4FtypBoxTest.java │ │ └── net │ │ ├── server │ │ ├── TcpServerBasicTest.java │ │ └── UdpServerBasicTest.java │ │ └── client │ │ └── UdpClientBasicTest.java └── main │ └── java │ └── com │ └── github │ └── xingshuangs │ └── iot │ ├── exceptions │ ├── McCommException.java │ ├── S7CommException.java │ ├── RtpCommException.java │ ├── RtcpCommException.java │ ├── RtspCommException.java │ ├── ModbusCommException.java │ ├── AuthenticationException.java │ ├── SocketRuntimeException.java │ ├── SocketTimeoutException.java │ ├── HexParseException.java │ └── ByteArrayParseException.java │ ├── App.java │ ├── protocol │ ├── rtsp │ │ ├── model │ │ │ ├── base │ │ │ │ └── RtspRange.java │ │ │ ├── sdp │ │ │ │ ├── RtspSdpEncryptKey.java │ │ │ │ ├── RtspSdpEchoTime.java │ │ │ │ └── RtspSdpTime.java │ │ │ ├── RtspOptionRequest.java │ │ │ ├── RtspPauseRequest.java │ │ │ ├── RtspTeardownRequest.java │ │ │ └── RtspDescribeResponse.java │ │ ├── authentication │ │ │ ├── AbstractAuthenticator.java │ │ │ ├── UsernamePasswordCredential.java │ │ │ └── BasicAuthenticator.java │ │ ├── service │ │ │ └── IRtspDataStream.java │ │ └── constant │ │ │ ├── RtspResponseHeaderFields.java │ │ │ ├── RtspRequestHeaderFields.java │ │ │ └── RtspEntityHeaderFields.java │ ├── melsec │ │ └── model │ │ │ ├── McData.java │ │ │ ├── McAccessRoute.java │ │ │ ├── McReqData.java │ │ │ ├── McReadDeviceBatchInBitReqData.java │ │ │ ├── McReadDeviceBatchInWordReqData.java │ │ │ ├── McWriteDeviceBatchInBitReqData.java │ │ │ └── McWriteDeviceBatchInWordReqData.java │ ├── s7 │ │ ├── model │ │ │ ├── PlcControlParamBlock.java │ │ │ ├── NckRequestBuilder.java │ │ │ ├── PlcControlStringParamBlock.java │ │ │ ├── Parameter.java │ │ │ ├── HeaderBuilder.java │ │ │ └── COTP.java │ │ ├── algorithm │ │ │ └── S7ComGroup.java │ │ ├── serializer │ │ │ ├── S7Variable.java │ │ │ └── S7ParseData.java │ │ ├── enums │ │ │ └── EPlcType.java │ │ └── service │ │ │ └── MultiAddressRead.java │ ├── mp4 │ │ └── model │ │ │ ├── Mp4SttsBox.java │ │ │ ├── Mp4SampleFlag.java │ │ │ ├── Mp4StscBox.java │ │ │ └── Mp4DinfBox.java │ ├── rtp │ │ ├── service │ │ │ └── IPayloadParser.java │ │ └── model │ │ │ └── payload │ │ │ └── H264NaluBase.java │ └── rtcp │ │ └── model │ │ └── RtcpBasePackage.java │ ├── common │ ├── IObjectString.java │ ├── IObjectByteArray.java │ ├── serializer │ │ ├── IPLCSerializable.java │ │ ├── ByteArrayParseData.java │ │ └── IByteArraySerializable.java │ └── algorithm │ │ └── LoopGroupItem.java │ ├── net │ └── IAckListener.java │ └── utils │ └── LRCUtil.java ├── .gitignore ├── LICENSE └── tutorial └── README-WebVideo-CN.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | -------------------------------------------------------------------------------- /notice/博图-开启访问权限.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xingshuangs/iot-communication/HEAD/notice/博图-开启访问权限.png -------------------------------------------------------------------------------- /notice/博图-允许PUT-GET.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xingshuangs/iot-communication/HEAD/notice/博图-允许PUT-GET.png -------------------------------------------------------------------------------- /notice/博图-不要勾选DB块优化访问.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xingshuangs/iot-communication/HEAD/notice/博图-不要勾选DB块优化访问.png -------------------------------------------------------------------------------- /notice/S200-Smart不同型号不同区的地址范围.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xingshuangs/iot-communication/HEAD/notice/S200-Smart不同型号不同区的地址范围.png -------------------------------------------------------------------------------- /notice/S7+SourceTSAP+DestinationTSAP.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | | PLC类别 | SourceTSAP(0xC1) | DestinationTSAP(0xC2) | 4 | |:---------:|:----------------:|:---------------------:| 5 | | S1500 | 0x0102 | 0x0100 | 6 | | S1200 | 0x0102 | 0x0100 | 7 | | S400 | 0x0102 | 0x0100+3 | 8 | | S300 | 0x0102 | 0x0100+2 | 9 | | S200 | 0x4D57 | 0x4D57 | 10 | | S200Smart | 0x0100 | 0x0300 | 11 | -------------------------------------------------------------------------------- /src/test/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | # 全局日志默认级别 2 | org.slf4j.simpleLogger.defaultLogLevel=DEBUG 3 | # 显示时间 4 | org.slf4j.simpleLogger.showDateTime=true 5 | # 时间格式 6 | org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss.SSS 7 | # 线程名 8 | org.slf4j.simpleLogger.showThreadName=true 9 | # 包路径 10 | org.slf4j.simpleLogger.showLogName=false 11 | # 短的包路径 12 | org.slf4j.simpleLogger.showShortLogName=true 13 | org.slf4j.simpleLogger.logFile=System.out 14 | org.slf4j.simpleLogger.cacheOutputStream=false 15 | org.slf4j.simpleLogger.levelInBrackets=true 16 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/exceptions/McCommException.java: -------------------------------------------------------------------------------- 1 | package com.github.xingshuangs.iot.exceptions; 2 | 3 | /** 4 | * MC communication runtime exception class. 5 | * (MC通信异常) 6 | * 7 | * @author xingshuang 8 | */ 9 | public class McCommException extends RuntimeException { 10 | private static final long serialVersionUID = 1L; 11 | 12 | public McCommException() { 13 | super(); 14 | } 15 | 16 | public McCommException(String message, Throwable cause) { 17 | super(message, cause); 18 | } 19 | 20 | public McCommException(String message) { 21 | super(message); 22 | } 23 | 24 | public McCommException(Throwable cause) { 25 | super(cause); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Eclipse project files 2 | .project 3 | .classpath 4 | .settings 5 | 6 | # IntelliJ IDEA project files and directories 7 | .idea 8 | *.iml 9 | *.ipr 10 | *.iws 11 | .idea/ 12 | .shelf/ 13 | 14 | # Geany project file 15 | .geany 16 | 17 | # KDevelop project file and directory 18 | .kdev4/ 19 | *.kdev4 20 | 21 | # Build targets 22 | /target 23 | */target 24 | 25 | # Report directories 26 | /reports 27 | */reports 28 | 29 | # Mac-specific directory that no other operating system needs. 30 | .DS_Store 31 | 32 | # JVM crash logs 33 | hs_err_pid*.log 34 | 35 | dependency-reduced-pom.xml 36 | 37 | */.unison.* 38 | 39 | # exclude mainframer files 40 | mainframer 41 | .mainframer 42 | 43 | # exclude docker-sync stuff 44 | .docker-sync 45 | */.docker-sync 46 | 47 | # exclude vscode files 48 | .vscode/ 49 | *.factorypath 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021-2099 Oscura (xingshuang) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/utils/LongUtilTest.java: -------------------------------------------------------------------------------- 1 | package com.github.xingshuangs.iot.utils; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | 8 | public class LongUtilTest { 9 | 10 | @Test 11 | public void toByteArray() { 12 | byte[] actual = LongUtil.toByteArray(1537229996552836696L); 13 | byte[] expect = new byte[]{(byte) 0x15, (byte) 0x55, (byte) 0x56, (byte) 0x89, (byte) 0x8A, (byte) 0x9B, (byte) 0x56, (byte) 0x58}; 14 | assertArrayEquals(expect, actual); 15 | 16 | expect = new byte[]{(byte) 0x58, (byte) 0x56, (byte) 0x9B, (byte) 0x8A, (byte) 0x89, (byte) 0x56, (byte) 0x55, (byte) 0x15}; 17 | actual = LongUtil.toByteArray(1537229996552836696L, true); 18 | assertArrayEquals(expect, actual); 19 | } 20 | 21 | @Test 22 | public void toInt64() { 23 | byte[] src = new byte[]{(byte) 0x15, (byte) 0x55, (byte) 0x56, (byte) 0x89, (byte) 0x8A, (byte) 0x9B, (byte) 0x56, (byte) 0x58}; 24 | long expect = 1537229996552836696L; 25 | long actual = LongUtil.toInt64(src, 0, false); 26 | assertEquals(expect, actual); 27 | src = new byte[]{(byte) 0x58, (byte) 0x56, (byte) 0x9B, (byte) 0x8A, (byte) 0x89, (byte) 0x56, (byte) 0x55, (byte) 0x15}; 28 | actual = LongUtil.toInt64(src, 0, true); 29 | assertEquals(expect, actual); 30 | } 31 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/App.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot; 26 | 27 | /** 28 | * Hello world! 29 | * 30 | * @author xingshuang 31 | */ 32 | public class App { 33 | public static void main(String[] args) { 34 | System.out.println("Hello World!"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/model/base/RtspRange.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.model.base; 26 | 27 | 28 | /** 29 | * Range. 30 | * 范围 31 | * 32 | * @author xingshuang 33 | */ 34 | public class RtspRange { 35 | 36 | /** 37 | * Type. 38 | * 类别 39 | */ 40 | protected String type; 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/AppTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot; 26 | 27 | import static org.junit.Assert.assertTrue; 28 | 29 | import org.junit.Test; 30 | 31 | /** 32 | * Unit test for simple App. 33 | */ 34 | public class AppTest 35 | { 36 | /** 37 | * Rigorous Test :-) 38 | */ 39 | @Test 40 | public void shouldAnswerWithTrue() 41 | { 42 | assertTrue( true ); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/common/IObjectString.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.common; 26 | 27 | 28 | /** 29 | * Transform to string interface. 30 | * (字符串相关接口) 31 | * 32 | * @author xingshuang 33 | */ 34 | public interface IObjectString { 35 | 36 | /** 37 | * Transform current object to string. 38 | * (转换为对象字符串) 39 | * 40 | * @return string data. 41 | */ 42 | String toObjectString(); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/authentication/AbstractAuthenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.authentication; 26 | 27 | 28 | /** 29 | * Authenticator. 30 | * (认证器) 31 | * 32 | * @author xingshuang 33 | */ 34 | public abstract class AbstractAuthenticator { 35 | 36 | protected String name; 37 | 38 | protected UsernamePasswordCredential credential; 39 | 40 | public abstract String createResponse(); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/model/sdp/RtspSdpEncryptKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.model.sdp; 26 | 27 | 28 | import lombok.Data; 29 | 30 | /** 31 | * Encrypt key. 32 | * (加密秘钥) 33 | * 34 | * @author xingshuang 35 | */ 36 | @Data 37 | public class RtspSdpEncryptKey { 38 | 39 | /** 40 | * Method name. 41 | * (方法名) 42 | */ 43 | private String name; 44 | 45 | /** 46 | * Key value. 47 | * (秘钥) 48 | */ 49 | private String value; 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/melsec/model/McData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.melsec.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.common.IObjectByteArray; 29 | 30 | /** 31 | * Data class. 32 | * 协议体数据:无数据 33 | * 34 | * @author xingshuang 35 | */ 36 | public class McData implements IObjectByteArray { 37 | @Override 38 | public int byteArrayLength() { 39 | return 0; 40 | } 41 | 42 | @Override 43 | public byte[] toByteArray() { 44 | return new byte[0]; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/melsec/model/McAccessRoute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.melsec.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.common.IObjectByteArray; 29 | 30 | /** 31 | * Access route. 32 | * 访问路径 33 | * 34 | * @author xingshuang 35 | */ 36 | public class McAccessRoute implements IObjectByteArray { 37 | @Override 38 | public int byteArrayLength() { 39 | return 0; 40 | } 41 | 42 | @Override 43 | public byte[] toByteArray() { 44 | return new byte[0]; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/net/IAckListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.net; 26 | 27 | 28 | /** 29 | * Ack listener interface, do success or failed. 30 | * (响应监听器) 31 | * 32 | * @author xingshuang 33 | */ 34 | public interface IAckListener { 35 | 36 | /** 37 | * Execute success. 38 | * (成功执行业务) 39 | * 40 | * @param ack ack data 41 | */ 42 | void ok(T ack); 43 | 44 | /** 45 | * Execute failed. 46 | * (失败执行业务) 47 | * 48 | * @param message error message 49 | */ 50 | void fail(String message); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/s7/model/PlcControlParamBlock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.common.IObjectByteArray; 29 | 30 | /** 31 | * PLC Control, parameter block. 32 | * PLC控制参数块 33 | * 34 | * @author xingshuang 35 | */ 36 | public class PlcControlParamBlock implements IObjectByteArray { 37 | 38 | @Override 39 | public int byteArrayLength() { 40 | return 0; 41 | } 42 | 43 | @Override 44 | public byte[] toByteArray() { 45 | return new byte[0]; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/common/IObjectByteArray.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.common; 26 | 27 | 28 | /** 29 | * Transform to byte array interface. 30 | * (一个对象字节相关的接口) 31 | * 32 | * @author xingshuang 33 | */ 34 | public interface IObjectByteArray { 35 | 36 | /** 37 | * Get current byte array length. 38 | * (获取字节数组长度) 39 | * 40 | * @return byte array length. 41 | */ 42 | int byteArrayLength(); 43 | 44 | /** 45 | * Transform current object to byte array. 46 | * (转换为字节数组) 47 | * 48 | * @return byte array. 49 | */ 50 | byte[] toByteArray(); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/model/sdp/RtspSdpEchoTime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.model.sdp; 26 | 27 | 28 | import lombok.Data; 29 | 30 | /** 31 | * Echo time 32 | * 重复时间 33 | * 34 | * @author xingshuang 35 | */ 36 | @Data 37 | public class RtspSdpEchoTime { 38 | 39 | /** 40 | * Echo interval. 41 | * (重复间隔) 42 | */ 43 | private Integer echoInterval; 44 | 45 | /** 46 | * During time. 47 | * (持续时长) 48 | */ 49 | private Integer duringTime; 50 | 51 | /** 52 | * Offset from start time. 53 | * (相对起始时间的偏移链表) 54 | */ 55 | private Integer offset; 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/common/serializer/ByteArrayCharsetBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.common.serializer; 26 | 27 | 28 | import com.github.xingshuangs.iot.common.enums.EDataType; 29 | import lombok.Data; 30 | 31 | /** 32 | * @author xingshuang 33 | */ 34 | @Data 35 | public class ByteArrayCharsetBean { 36 | 37 | @ByteArrayVariable(byteOffset = 0, bitOffset = 0, count = 1, type = EDataType.BOOL) 38 | Boolean boolData; 39 | 40 | @ByteArrayVariable(byteOffset = 1, count = 1, type = EDataType.BYTE) 41 | Byte byteData; 42 | 43 | @ByteArrayVariable(byteOffset = 2, count = 20, type = EDataType.STRING) 44 | String stringData; 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/utils/LRCUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.utils; 26 | 27 | import org.junit.Test; 28 | 29 | import static org.junit.Assert.*; 30 | 31 | 32 | public class LRCUtilTest { 33 | 34 | @Test 35 | public void lrcTest() { 36 | byte[] src = new byte[]{0x01, 0x03, 0x00, 0x00, 0x00, 0x14}; 37 | byte actual = LRCUtil.lrc(src); 38 | assertEquals((byte) 0xE8, actual); 39 | } 40 | 41 | @Test 42 | public void lrcTest1() { 43 | byte[] src = new byte[]{0x01, 0x03, 0x00, 0x00, 0x00, 0x14}; 44 | boolean actual = LRCUtil.lrc(src, (byte) 0xE8); 45 | assertTrue(actual); 46 | } 47 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/s7/model/TPKTTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.model; 26 | 27 | import org.junit.Test; 28 | 29 | import static org.junit.Assert.*; 30 | 31 | 32 | public class TPKTTest { 33 | 34 | @Test 35 | public void byteArrayLength() { 36 | TPKT tpkt = new TPKT(); 37 | assertEquals(4, tpkt.byteArrayLength()); 38 | } 39 | 40 | @Test 41 | public void toByteArray() { 42 | TPKT tpkt = new TPKT(); 43 | tpkt.setLength(100); 44 | byte[] actual = tpkt.toByteArray(); 45 | byte[] expect = {(byte) 0x03, (byte) 0x00, (byte) 0x00, (byte) 0x64}; 46 | assertArrayEquals(expect, actual); 47 | } 48 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/utils/TimesUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.utils; 26 | 27 | import org.junit.Test; 28 | 29 | import java.time.LocalDateTime; 30 | 31 | import static org.junit.Assert.assertEquals; 32 | 33 | 34 | public class TimesUtilTest { 35 | 36 | @Test 37 | public void getNtpTime() { 38 | LocalDateTime ntpTime = TimesUtil.getNTPDateTime(3891134116L); 39 | System.out.println(ntpTime); 40 | } 41 | 42 | @Test 43 | public void getUTCTotalSecond() { 44 | LocalDateTime dateTime = LocalDateTime.of(1970, 1, 1, 0, 0, 3); 45 | long second = TimesUtil.getUTCTotalSecond(dateTime); 46 | assertEquals(3, second); 47 | } 48 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/net/server/TcpServerBasicTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.net.server; 26 | 27 | import lombok.extern.slf4j.Slf4j; 28 | import org.junit.Ignore; 29 | import org.junit.Test; 30 | 31 | import java.util.concurrent.TimeUnit; 32 | 33 | @Ignore 34 | @Slf4j 35 | public class TcpServerBasicTest { 36 | 37 | private final TcpServerBasic serverSocketBasic = new TcpServerBasic(); 38 | 39 | @Test 40 | public void testStart() throws InterruptedException { 41 | this.serverSocketBasic.start(); 42 | TimeUnit.MINUTES.sleep(10); 43 | } 44 | 45 | @Test 46 | public void test1(){ 47 | log.info("test"); 48 | log.error("error"); 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/common/serializer/IPLCSerializable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.common.serializer; 26 | 27 | 28 | /** 29 | * PLC serialize interface. 30 | * (PLC序列化接口) 31 | * 32 | * @author xingshuang 33 | */ 34 | public interface IPLCSerializable { 35 | 36 | /** 37 | * Read data. 38 | * (读数据) 39 | * 40 | * @param targetClass target class 41 | * @param type 42 | * @return object 43 | */ 44 | T read(Class targetClass); 45 | 46 | /** 47 | * Write data. 48 | * (写数据) 49 | * 50 | * @param targetBean target object. 51 | * @param type 52 | */ 53 | void write(T targetBean); 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/s7/algorithm/S7ComGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.algorithm; 26 | 27 | 28 | import lombok.Data; 29 | 30 | import java.util.ArrayList; 31 | import java.util.List; 32 | 33 | /** 34 | * Merge group Class 35 | * 合并组 36 | * 37 | * @author xingshuang 38 | */ 39 | @Data 40 | public class S7ComGroup { 41 | 42 | /** 43 | * Data item list. 44 | * (数据项列表) 45 | */ 46 | private List items = new ArrayList<>(); 47 | 48 | /** 49 | * Add data item. 50 | * (添加数据) 51 | * 52 | * @param item data item 53 | */ 54 | public void add(S7ComItem item) { 55 | this.items.add(item); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/exceptions/S7CommException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.exceptions; 26 | 27 | /** 28 | * S7 communication runtime exception class. 29 | * (S7通信异常) 30 | * 31 | * @author xingshuang 32 | */ 33 | public class S7CommException extends RuntimeException { 34 | private static final long serialVersionUID = 1L; 35 | 36 | public S7CommException() { 37 | super(); 38 | } 39 | 40 | public S7CommException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | 44 | public S7CommException(String message) { 45 | super(message); 46 | } 47 | 48 | public S7CommException(Throwable cause) { 49 | super(cause); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/exceptions/RtpCommException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.exceptions; 26 | 27 | /** 28 | * RTP communication runtime exception class. 29 | * (RTP的运行异常) 30 | * 31 | * @author xingshuang 32 | */ 33 | public class RtpCommException extends RuntimeException { 34 | private static final long serialVersionUID = 1L; 35 | 36 | public RtpCommException() { 37 | super(); 38 | } 39 | 40 | public RtpCommException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | 44 | public RtpCommException(String message) { 45 | super(message); 46 | } 47 | 48 | public RtpCommException(Throwable cause) { 49 | super(cause); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/model/RtspOptionRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.rtsp.authentication.AbstractAuthenticator; 29 | import com.github.xingshuangs.iot.protocol.rtsp.enums.ERtspMethod; 30 | 31 | import java.net.URI; 32 | 33 | /** 34 | * Option request 35 | * 36 | * @author xingshuang 37 | */ 38 | public final class RtspOptionRequest extends RtspMessageRequest { 39 | 40 | public RtspOptionRequest(URI uri) { 41 | super(ERtspMethod.OPTIONS, uri); 42 | } 43 | 44 | public RtspOptionRequest(URI uri, AbstractAuthenticator authenticator) { 45 | super(ERtspMethod.OPTIONS, uri, authenticator); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/exceptions/RtcpCommException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.exceptions; 26 | 27 | /** 28 | * RTCP communication runtime exception class. 29 | * (RTCP的运行异常) 30 | * 31 | * @author xingshuang 32 | */ 33 | public class RtcpCommException extends RuntimeException { 34 | private static final long serialVersionUID = 1L; 35 | 36 | public RtcpCommException() { 37 | super(); 38 | } 39 | 40 | public RtcpCommException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | 44 | public RtcpCommException(String message) { 45 | super(message); 46 | } 47 | 48 | public RtcpCommException(Throwable cause) { 49 | super(cause); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/exceptions/RtspCommException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.exceptions; 26 | 27 | /** 28 | * RTSP communication runtime exception class. 29 | * (RTSP的运行异常) 30 | * 31 | * @author xingshuang 32 | */ 33 | public class RtspCommException extends RuntimeException { 34 | private static final long serialVersionUID = 1L; 35 | 36 | public RtspCommException() { 37 | super(); 38 | } 39 | 40 | public RtspCommException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | 44 | public RtspCommException(String message) { 45 | super(message); 46 | } 47 | 48 | public RtspCommException(Throwable cause) { 49 | super(cause); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/exceptions/ModbusCommException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.exceptions; 26 | 27 | /** 28 | * Modbus communication runtime exception class. 29 | * (Modbus通信异常) 30 | * 31 | * @author xingshuang 32 | */ 33 | public class ModbusCommException extends RuntimeException { 34 | private static final long serialVersionUID = 1L; 35 | 36 | public ModbusCommException() { 37 | super(); 38 | } 39 | 40 | public ModbusCommException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | 44 | public ModbusCommException(String message) { 45 | super(message); 46 | } 47 | 48 | public ModbusCommException(Throwable cause) { 49 | super(cause); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/service/IRtspDataStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.service; 26 | 27 | 28 | import java.util.concurrent.CompletableFuture; 29 | 30 | /** 31 | * RTSP data stream 32 | * 33 | * @author xingshuang 34 | */ 35 | public interface IRtspDataStream { 36 | 37 | /** 38 | * Get completable future. 39 | * 40 | * @return CompletableFuture 41 | */ 42 | CompletableFuture getFuture(); 43 | 44 | /** 45 | * Close 46 | */ 47 | void close(); 48 | 49 | /** 50 | * Trigger receive. 51 | */ 52 | void triggerReceive(); 53 | 54 | /** 55 | * Send data. 56 | * 57 | * @param data byte array 58 | */ 59 | void sendData(byte[] data); 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/s7/service/DemoS7Control.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.service; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType; 29 | 30 | /** 31 | * @author xingshuang 32 | */ 33 | public class DemoS7Control { 34 | 35 | public static void main(String[] args) { 36 | S7PLC s7PLC = new S7PLC(EPlcType.S1200, "127.0.0.1"); 37 | 38 | // hot restart 39 | s7PLC.hotRestart(); 40 | 41 | // cold restart 42 | s7PLC.coldRestart(); 43 | 44 | // plc stop 45 | s7PLC.plcStop(); 46 | 47 | // copy ram to rom 48 | s7PLC.copyRamToRom(); 49 | 50 | // compress 51 | s7PLC.compress(); 52 | 53 | s7PLC.close(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/exceptions/AuthenticationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.exceptions; 26 | 27 | /** 28 | * Authentication runtime exception class. 29 | * (认证的运行异常) 30 | * 31 | * @author xingshuang 32 | */ 33 | public class AuthenticationException extends RuntimeException { 34 | private static final long serialVersionUID = 1L; 35 | 36 | public AuthenticationException() { 37 | super(); 38 | } 39 | 40 | public AuthenticationException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | 44 | public AuthenticationException(String message) { 45 | super(message); 46 | } 47 | 48 | public AuthenticationException(Throwable cause) { 49 | super(cause); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/melsec/model/Mc4E3EFrameAccessRouteTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.melsec.model; 26 | 27 | import org.junit.Test; 28 | 29 | import static org.junit.Assert.*; 30 | 31 | 32 | public class Mc4E3EFrameAccessRouteTest { 33 | 34 | @Test 35 | public void fromBytes() { 36 | byte[] src = new byte[]{0x00, (byte) 0xFF, (byte) 0xFF, 0x03, 0x00,}; 37 | McFrame4E3EAccessRoute accessRoute = McFrame4E3EAccessRoute.fromBytes(src); 38 | assertEquals(0, accessRoute.getNetworkNumber()); 39 | assertEquals(0xFF, accessRoute.getPcNumber()); 40 | assertEquals(0x03FF, accessRoute.getRequestDestModuleIoNumber()); 41 | assertEquals(0, accessRoute.getRequestDestModuleStationNumber()); 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/exceptions/SocketRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.exceptions; 26 | 27 | /** 28 | * Socket communication runtime exception class. 29 | * (socket的运行异常) 30 | * 31 | * @author xingshuang 32 | */ 33 | public class SocketRuntimeException extends RuntimeException { 34 | private static final long serialVersionUID = 1L; 35 | 36 | public SocketRuntimeException() { 37 | super(); 38 | } 39 | 40 | public SocketRuntimeException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | 44 | public SocketRuntimeException(String message) { 45 | super(message); 46 | } 47 | 48 | public SocketRuntimeException(Throwable cause) { 49 | super(cause); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/exceptions/SocketTimeoutException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.exceptions; 26 | 27 | /** 28 | * Socket communication timeout runtime exception class. 29 | * (socket执行超时异常) 30 | * 31 | * @author xingshuang 32 | */ 33 | public class SocketTimeoutException extends RuntimeException { 34 | private static final long serialVersionUID = 1L; 35 | 36 | public SocketTimeoutException() { 37 | super(); 38 | } 39 | 40 | public SocketTimeoutException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | 44 | public SocketTimeoutException(String message) { 45 | super(message); 46 | } 47 | 48 | public SocketTimeoutException(Throwable cause) { 49 | super(cause); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/common/serializer/ByteArrayParseData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.common.serializer; 26 | 27 | 28 | import lombok.Data; 29 | 30 | import java.lang.reflect.Field; 31 | 32 | /** 33 | * Byte array data used to parse. 34 | * 35 | * @author xingshuang 36 | */ 37 | @Data 38 | public class ByteArrayParseData { 39 | 40 | /** 41 | * Annotation of byte array. 42 | * (字节数组注解参数) 43 | */ 44 | ByteArrayVariable variable; 45 | 46 | /** 47 | * Field content. 48 | * (字段内容) 49 | */ 50 | Field field; 51 | 52 | public ByteArrayParseData() { 53 | } 54 | 55 | public ByteArrayParseData(ByteArrayVariable variable, Field field) { 56 | this.variable = variable; 57 | this.field = field; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/mp4/model/Mp4SttsBox.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.mp4.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.mp4.enums.EMp4Type; 29 | 30 | /** 31 | * Decoding Time to Sample Box(stbl-stts), 32 | * 存储了sample的duration,描述了sample时序的映射方法,我们通过它可以找到任何时间的sample, 33 | * “stts”也可包含一个压缩的表来映射时间和sample序号,用其他的表来提供每个sample的长度和指针,表中每个条目提供了在同一个时间偏移量里面 34 | * 连续的sample序号,以及samples的偏移量。递增这些偏移量,就可以建立一个完整的time to sample表。在fmp4中这些信息以moof中为主,这里 35 | * 可不必赋值,只做一个box即可 36 | * 37 | * @author xingshuang 38 | */ 39 | public class Mp4SttsBox extends Mp4StcoBox { 40 | 41 | public Mp4SttsBox() { 42 | this.mp4Type = EMp4Type.STTS; 43 | this.version = 0; 44 | this.flags = new byte[3]; 45 | this.entryCount = 0; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/rtsp/model/RtspRtpInfoTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.rtsp.model.base.RtspRtpInfo; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class RtspRtpInfoTest { 34 | 35 | @Test 36 | public void fromString() { 37 | String src = "url=rtsp://192.168.3.250:554/h264/ch1/main/av_stream/trackID=1;seq=36755;rtptime=29143980"; 38 | RtspRtpInfo rtpInfo = RtspRtpInfo.fromString(src); 39 | assertEquals("rtsp://192.168.3.250:554/h264/ch1/main/av_stream/trackID=1", rtpInfo.getUrl()); 40 | assertEquals(36755, rtpInfo.getSeq().intValue()); 41 | assertEquals(29143980, rtpInfo.getRtpTime().intValue()); 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/model/RtspPauseRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.rtsp.authentication.AbstractAuthenticator; 29 | import com.github.xingshuangs.iot.protocol.rtsp.enums.ERtspMethod; 30 | import lombok.Getter; 31 | 32 | import java.net.URI; 33 | 34 | /** 35 | * Play request 36 | * 37 | * @author xingshuang 38 | */ 39 | @Getter 40 | public final class RtspPauseRequest extends RtspMessageRequest { 41 | 42 | public RtspPauseRequest(URI uri, String session) { 43 | this(uri, session, null); 44 | } 45 | 46 | public RtspPauseRequest(URI uri, String session, AbstractAuthenticator authenticator) { 47 | super(ERtspMethod.PAUSE, uri, session, authenticator); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtp/service/IPayloadParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtp.service; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.rtp.model.RtpPackage; 29 | import com.github.xingshuangs.iot.protocol.rtp.model.frame.RawFrame; 30 | 31 | import java.util.function.Consumer; 32 | 33 | /** 34 | * Interface of payload parser. 35 | * (负载解析器) 36 | * 37 | * @author xingshuang 38 | */ 39 | public interface IPayloadParser { 40 | /** 41 | * Process rtp package. 42 | * (处理数据包) 43 | * 44 | * @param rtp rtp数据包 45 | */ 46 | void processPackage(RtpPackage rtp); 47 | 48 | /** 49 | * Frame handler. 50 | * (设置帧处理事件) 51 | * 52 | * @param frameHandle 处理事件 53 | */ 54 | void onFrameHandle(Consumer frameHandle); 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/common/serializer/IByteArraySerializable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.common.serializer; 26 | 27 | 28 | /** 29 | * Byte array serialize interface 30 | * (字节数组的序列化接口) 31 | * 32 | * @author xingshuang 33 | */ 34 | public interface IByteArraySerializable { 35 | 36 | /** 37 | * To object. 38 | * (转换为对象) 39 | * 40 | * @param targetClass target class 41 | * @param src byte array 42 | * @param type 43 | * @return object. 44 | */ 45 | T toObject(Class targetClass, byte[] src); 46 | 47 | /** 48 | * To byte array. 49 | * (转换为数组) 50 | * 51 | * @param targetBean target object 52 | * @param type 53 | * @return object. 54 | */ 55 | byte[] toByteArray(T targetBean); 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/model/RtspTeardownRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.rtsp.authentication.AbstractAuthenticator; 29 | import com.github.xingshuangs.iot.protocol.rtsp.enums.ERtspMethod; 30 | import lombok.Getter; 31 | 32 | import java.net.URI; 33 | 34 | /** 35 | * Teardown request 36 | * 37 | * @author xingshuang 38 | */ 39 | @Getter 40 | public final class RtspTeardownRequest extends RtspMessageRequest { 41 | 42 | public RtspTeardownRequest(URI uri, String session) { 43 | this(uri, session, null); 44 | } 45 | 46 | public RtspTeardownRequest(URI uri, String session, AbstractAuthenticator authenticator) { 47 | super(ERtspMethod.TEARDOWN, uri, session, authenticator); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/utils/ByteUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.utils; 26 | 27 | import org.junit.Test; 28 | 29 | import static org.junit.Assert.*; 30 | 31 | 32 | public class ByteUtilTest { 33 | 34 | @Test 35 | public void toByte() { 36 | byte actual = ByteUtil.toByte(11); 37 | assertEquals((byte) 0x0B, actual); 38 | } 39 | 40 | @Test 41 | public void toUInt8() { 42 | int actual = ByteUtil.toUInt8((byte) 0xFF); 43 | assertEquals(255, actual); 44 | } 45 | 46 | @Test 47 | public void toStr() { 48 | byte[] data = {(byte) 0x50, (byte) 0x5f, (byte) 0x50, (byte) 0x52, (byte) 0x4F, (byte) 0x47, (byte) 0x52, (byte) 0x41, (byte) 0x4D}; 49 | String actual = ByteUtil.toStr(data); 50 | assertEquals("P_PROGRAM", actual); 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/mp4/model/Mp4SampleFlag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.mp4.model; 26 | 27 | 28 | import lombok.Data; 29 | 30 | /** 31 | * Related properties of the sample, 32 | * DependsOn=1, IsNonSync =1, ISnonsync = 0, DependsOn=1, ISnonsync = 0, as long as keyframe is touched, DependsOn=2, others = 0. 33 | * 采样的相关属性 34 | * 这里以单个分片单个sample的模式,只要碰到关键帧,DependsOn=2 ,其他等于0,非关键帧DependsOn=1,IsNonSync等于1,其他等于0, 35 | * 36 | * @author xingshuang 37 | */ 38 | @Data 39 | public class Mp4SampleFlag { 40 | 41 | private int isLeading = 0; 42 | 43 | private int isDependedOn = 0; 44 | 45 | private int hasRedundancy = 0; 46 | 47 | private int degradPrio = 0; 48 | 49 | private int dependedOn = 0; 50 | 51 | private int isNonSync = 0; 52 | 53 | private int paddingValue = 0; 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/s7/model/COTPTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.s7.enums.EPduType; 28 | import org.junit.Assert; 29 | import org.junit.Before; 30 | import org.junit.Test; 31 | 32 | import static org.junit.Assert.*; 33 | 34 | 35 | public class COTPTest { 36 | 37 | @Test 38 | public void byteArrayLength() { 39 | COTP cotp = new COTP(); 40 | assertEquals(2, cotp.byteArrayLength()); 41 | } 42 | 43 | @Test 44 | public void toByteArray() { 45 | COTP cotp = new COTP(); 46 | cotp.setLength((byte) 0x03); 47 | cotp.setPduType(EPduType.CONNECT_CONFIRM); 48 | byte[] target = new byte[]{(byte) 0x03, (byte) 0xD0}; 49 | assertArrayEquals(target, cotp.toByteArray()); 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/constant/RtspResponseHeaderFields.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.constant; 26 | 27 | 28 | /** 29 | * Response header fields. 30 | * (回复头字段) 31 | * 32 | * @author xingshuang 33 | */ 34 | public class RtspResponseHeaderFields { 35 | 36 | private RtspResponseHeaderFields() { 37 | // NOOP 38 | } 39 | 40 | public static final String LOCATION = "Location"; 41 | public static final String PROXY_AUTHENTICATE = "Proxy-Authenticate"; 42 | public static final String PUBLIC = "Public"; 43 | public static final String RETRY_AFTER = "Retry-After"; 44 | public static final String SERVER = "Server"; 45 | public static final String VARY = "Vary"; 46 | public static final String RANGE = "Range"; 47 | public static final String WWW_AUTHENTICATE = "WWW-Authenticate"; 48 | 49 | public static final String RTP_INFO = "RTP-Info"; 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/net/server/UdpServerBasicTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.net.server; 26 | 27 | import lombok.extern.slf4j.Slf4j; 28 | import org.junit.Ignore; 29 | import org.junit.Test; 30 | 31 | import java.net.DatagramPacket; 32 | import java.nio.charset.StandardCharsets; 33 | 34 | @Ignore 35 | @Slf4j 36 | public class UdpServerBasicTest { 37 | 38 | private final UdpServerBasic udpServerBasic = new UdpServerBasic(8001); 39 | 40 | @Test 41 | public void testWrite() { 42 | byte[] data = new byte[1024]; 43 | DatagramPacket packet = this.udpServerBasic.read(data); 44 | log.debug(new String(packet.getData())); 45 | String content = "sadfsdgsgsdf"; 46 | byte[] sendBytes = content.getBytes(StandardCharsets.US_ASCII); 47 | this.udpServerBasic.write(sendBytes, packet.getSocketAddress()); 48 | } 49 | 50 | @Test 51 | public void testRead() { 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/constant/RtspRequestHeaderFields.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.constant; 26 | 27 | 28 | /** 29 | * Request header fields. 30 | * (请求头字段) 31 | * 32 | * @author xingshuang 33 | */ 34 | public class RtspRequestHeaderFields { 35 | 36 | private RtspRequestHeaderFields() { 37 | // NOOP 38 | } 39 | 40 | public static final String ACCEPT = "Accept"; 41 | public static final String ACCEPT_ENCODING = "Accept-Encoding"; 42 | public static final String ACCEPT_LANGUAGE = "Accept-Language"; 43 | public static final String AUTHORIZATION = "Authorization"; 44 | public static final String FROM = "From"; 45 | public static final String IF_MODIFIED_SINCE = "If-Modified-Since"; 46 | public static final String RANGE = "Range"; 47 | public static final String REFERER = "Referer"; 48 | public static final String USER_AGENT = "User-Agent"; 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtp/model/payload/H264NaluBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtp.model.payload; 26 | 27 | 28 | import com.github.xingshuangs.iot.common.IObjectByteArray; 29 | import com.github.xingshuangs.iot.common.buff.ByteWriteBuff; 30 | import lombok.Data; 31 | 32 | /** 33 | * H264 nalu base class. 34 | * (基类数据包) 35 | * 36 | * @author xingshuang 37 | */ 38 | @Data 39 | public class H264NaluBase implements IObjectByteArray { 40 | 41 | /** 42 | * Header. 43 | */ 44 | protected H264NaluHeader header = new H264NaluHeader(); 45 | 46 | @Override 47 | public int byteArrayLength() { 48 | return this.header.byteArrayLength(); 49 | } 50 | 51 | @Override 52 | public byte[] toByteArray() { 53 | return ByteWriteBuff.newInstance(this.byteArrayLength()) 54 | .putBytes(this.header.toByteArray()) 55 | .getData(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/service/DemoModbusTcpServerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.service; 26 | 27 | 28 | import com.github.xingshuangs.iot.utils.HexUtil; 29 | 30 | import java.util.List; 31 | import java.util.concurrent.TimeUnit; 32 | 33 | /** 34 | * modbus服务端的示例 35 | * 36 | * @author xingshuang 37 | */ 38 | public class DemoModbusTcpServerTest { 39 | 40 | public static void main(String[] args) { 41 | ModbusTcpServer server = new ModbusTcpServer(); 42 | server.start(); 43 | 44 | ModbusTcp modbusTcp = new ModbusTcp("127.0.0.1"); 45 | // optional 46 | modbusTcp.setComCallback((tag, bytes) -> System.out.printf("%s[%d] %s%n", tag, bytes.length, HexUtil.toHexString(bytes))); 47 | 48 | modbusTcp.writeInt16(2, (short) 10); 49 | short data = modbusTcp.readInt16(2); 50 | 51 | modbusTcp.close(); 52 | server.stop(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/s7/model/COTPDataTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.s7.enums.EPduType; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class COTPDataTest { 34 | 35 | @Test 36 | public void byteArrayLength() { 37 | COTPData cotpData = new COTPData(); 38 | assertEquals(3, cotpData.byteArrayLength()); 39 | } 40 | 41 | @Test 42 | public void toByteArray() { 43 | COTPData cotpData = new COTPData(); 44 | cotpData.setLength((byte) 0x11); 45 | cotpData.setPduType(EPduType.CONNECT_REQUEST); 46 | cotpData.setTpduNumber((byte) 0x01); 47 | cotpData.setLastDataUnit(true); 48 | byte[] actual = cotpData.toByteArray(); 49 | byte[] expect = {(byte) 0x11, (byte)0xE0, (byte)0x81}; 50 | assertArrayEquals(expect, actual); 51 | } 52 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/net/client/UdpClientBasicTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.net.client; 26 | 27 | import junit.framework.TestCase; 28 | import org.junit.Ignore; 29 | import org.junit.Test; 30 | 31 | import java.nio.charset.StandardCharsets; 32 | 33 | @Ignore 34 | public class UdpClientBasicTest { 35 | 36 | private final UdpClientBasic udpClientBasic = new UdpClientBasic(); 37 | 38 | @Test 39 | public void testWrite() { 40 | String data = "hello world "; 41 | udpClientBasic.write(data.getBytes(StandardCharsets.UTF_8)); 42 | byte[] in = new byte[1024]; 43 | int read = udpClientBasic.read(in); 44 | System.out.println("长度:" + read); 45 | System.out.println(new String(in)); 46 | read = udpClientBasic.read(in); 47 | System.out.println("长度:" + read); 48 | System.out.println(new String(in)); 49 | } 50 | 51 | @Test 52 | public void testRead() { 53 | } 54 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/exceptions/HexParseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.exceptions; 26 | 27 | /** 28 | * Hex data parse runtime exception class. 29 | * (16进制解析异常) 30 | * 31 | * @author ShuangPC 32 | */ 33 | public class HexParseException extends RuntimeException { 34 | 35 | public HexParseException() { 36 | super(); 37 | } 38 | 39 | public HexParseException(String message) { 40 | super(message); 41 | } 42 | 43 | public HexParseException(String message, Throwable cause) { 44 | super(message, cause); 45 | } 46 | 47 | public HexParseException(Throwable cause) { 48 | super(cause); 49 | } 50 | 51 | protected HexParseException(String message, Throwable cause, 52 | boolean enableSuppression, 53 | boolean writableStackTrace) { 54 | super(message, cause, enableSuppression, writableStackTrace); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/authentication/UsernamePasswordCredential.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.authentication; 26 | 27 | 28 | import lombok.AllArgsConstructor; 29 | import lombok.Data; 30 | import lombok.NoArgsConstructor; 31 | 32 | /** 33 | * Username password credential. 34 | * 用户密码凭证 35 | * 36 | * @author xingshuang 37 | */ 38 | @AllArgsConstructor 39 | @NoArgsConstructor 40 | @Data 41 | public class UsernamePasswordCredential { 42 | 43 | /** 44 | * username. 45 | */ 46 | private String username; 47 | 48 | /** 49 | * password. 50 | */ 51 | private String password; 52 | 53 | public static UsernamePasswordCredential createBy(String str) { 54 | String[] split = str.split(":"); 55 | if (split.length != 2) { 56 | throw new IllegalArgumentException("str"); 57 | } 58 | return new UsernamePasswordCredential(split[0], split[1]); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/mp4/model/Mp4FtypBoxTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.mp4.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.mp4.enums.EMp4Type; 28 | import com.github.xingshuangs.iot.utils.HexUtil; 29 | import org.junit.Test; 30 | 31 | import static org.junit.Assert.assertArrayEquals; 32 | 33 | 34 | public class Mp4FtypBoxTest { 35 | @Test 36 | public void mp4Type() { 37 | System.out.println(HexUtil.toHexString(EMp4Type.TFHD.getByteArray())); 38 | } 39 | 40 | @Test 41 | public void mp4FtypBox() { 42 | byte[] expect = new byte[]{ 43 | 0x00, 0x00, 0x00, 0x18, 44 | 0x66, 0x74, 0x79, 0x70, 45 | 0x69, 0x73, 0x6F, 0x6D, 46 | 0x00, 0x00, 0x00, 0x01, 47 | 0x69, 0x73, 0x6F, 0x6D, 0x61, 0x76, 0x63, 0x31 48 | }; 49 | Mp4FtypBox box = new Mp4FtypBox(); 50 | assertArrayEquals(expect, box.toByteArray()); 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/s7/serializer/S7Variable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.serializer; 26 | 27 | 28 | import com.github.xingshuangs.iot.common.enums.EDataType; 29 | 30 | import java.lang.annotation.*; 31 | 32 | /** 33 | * S7 variable. 34 | * S7变量参数 35 | */ 36 | @Target(value = {ElementType.FIELD}) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | public @interface S7Variable { 40 | 41 | /** 42 | * Address. 43 | * 地址 44 | * 45 | * @return 地址 46 | */ 47 | String address() default ""; 48 | 49 | /** 50 | * Data type. 51 | * 类型 52 | * 如果字节,对应是byte[]类型 53 | * 54 | * @return 类型 55 | */ 56 | EDataType type() default EDataType.BYTE; 57 | 58 | /** 59 | * Except for Byte and String, the count of other types must be 1. 60 | * 数量 61 | * 除字节Byte和String类型外,其他类型对应的count必须为1 62 | * 63 | * @return 数量 64 | */ 65 | int count() default 1; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/s7/service/S7PLCConnect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.service; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType; 29 | import lombok.extern.slf4j.Slf4j; 30 | import org.junit.Ignore; 31 | import org.junit.Test; 32 | 33 | import static org.junit.Assert.assertEquals; 34 | 35 | /** 36 | * S7PLC长连接 37 | * 38 | * @author xingshuang 39 | */ 40 | @Ignore 41 | @Slf4j 42 | public class S7PLCConnect { 43 | 44 | @Test 45 | public void longConnect() { 46 | S7PLC s7PLC = new S7PLC(EPlcType.S1200, "127.0.0.1"); 47 | s7PLC.writeByte("DB2.1", (byte) 0x11); 48 | s7PLC.readByte("DB2.1"); 49 | s7PLC.close(); 50 | } 51 | 52 | @Test 53 | public void shortConnect() { 54 | S7PLC s7PLC = new S7PLC(EPlcType.S1200, "127.0.0.1"); 55 | s7PLC.setPersistence(false); 56 | s7PLC.writeByte("DB2.1", (byte) 0x11); 57 | s7PLC.readByte("DB2.1"); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/s7/enums/EPlcTypeTest.java: -------------------------------------------------------------------------------- 1 | package com.github.xingshuangs.iot.protocol.s7.enums; 2 | 3 | import com.github.xingshuangs.iot.common.constant.GeneralConst; 4 | import com.github.xingshuangs.iot.protocol.s7.service.S7PLC; 5 | import org.junit.Test; 6 | 7 | import static org.junit.Assert.*; 8 | 9 | 10 | public class EPlcTypeTest { 11 | 12 | @Test 13 | public void getSlotByType() { 14 | S7PLC plc = new S7PLC(EPlcType.S200); 15 | assertEquals(EPlcType.S200, plc.getPlcType()); 16 | assertEquals(0, plc.getRack()); 17 | assertEquals(1, plc.getSlot()); 18 | assertEquals(240, plc.getPduLength()); 19 | 20 | plc = new S7PLC(EPlcType.S200_SMART); 21 | assertEquals(EPlcType.S200_SMART, plc.getPlcType()); 22 | assertEquals(0, plc.getRack()); 23 | assertEquals(1, plc.getSlot()); 24 | assertEquals(240, plc.getPduLength()); 25 | 26 | plc = new S7PLC(EPlcType.S300); 27 | assertEquals(EPlcType.S300, plc.getPlcType()); 28 | assertEquals(0, plc.getRack()); 29 | assertEquals(2, plc.getSlot()); 30 | assertEquals(240, plc.getPduLength()); 31 | 32 | plc = new S7PLC(EPlcType.S400, GeneralConst.LOCALHOST); 33 | assertEquals(EPlcType.S400, plc.getPlcType()); 34 | assertEquals(0, plc.getRack()); 35 | assertEquals(3, plc.getSlot()); 36 | assertEquals(480, plc.getPduLength()); 37 | 38 | plc = new S7PLC(EPlcType.S1200, GeneralConst.LOCALHOST,GeneralConst.S7_PORT); 39 | assertEquals(EPlcType.S1200, plc.getPlcType()); 40 | assertEquals(0, plc.getRack()); 41 | assertEquals(1, plc.getSlot()); 42 | assertEquals(240, plc.getPduLength()); 43 | 44 | plc = new S7PLC(EPlcType.S1500); 45 | assertEquals(EPlcType.S1500, plc.getPlcType()); 46 | assertEquals(0, plc.getRack()); 47 | assertEquals(1, plc.getSlot()); 48 | assertEquals(960, plc.getPduLength()); 49 | 50 | plc = new S7PLC(EPlcType.SINUMERIK_828D); 51 | assertEquals(EPlcType.SINUMERIK_828D, plc.getPlcType()); 52 | assertEquals(0, plc.getRack()); 53 | assertEquals(1, plc.getSlot()); 54 | assertEquals(240, plc.getPduLength()); 55 | } 56 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/authentication/BasicAuthenticator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.authentication; 26 | 27 | 28 | import java.nio.charset.StandardCharsets; 29 | import java.util.Base64; 30 | 31 | /** 32 | * Basic authenticator. 33 | * Basic64加密方式 34 | * 35 | * @author xingshuang 36 | */ 37 | public class BasicAuthenticator extends AbstractAuthenticator { 38 | 39 | public static final String BASIC_NAME = "Basic"; 40 | 41 | private final Base64.Encoder encoder; 42 | 43 | public BasicAuthenticator(UsernamePasswordCredential credential) { 44 | this.credential = credential; 45 | this.name = BASIC_NAME; 46 | this.encoder = Base64.getEncoder(); 47 | } 48 | 49 | public String createResponse() { 50 | String src = String.format("%s:%s", this.credential.getUsername(), this.credential.getPassword()); 51 | return this.name + " " + this.encoder.encodeToString(src.getBytes(StandardCharsets.UTF_8)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/exceptions/ByteArrayParseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.exceptions; 26 | 27 | /** 28 | * Byte array parse runtime exception class. 29 | * (字节数组解析异常) 30 | * 31 | * @author ShuangPC 32 | */ 33 | public class ByteArrayParseException extends RuntimeException { 34 | 35 | public ByteArrayParseException() { 36 | super(); 37 | } 38 | 39 | public ByteArrayParseException(String message) { 40 | super(message); 41 | } 42 | 43 | public ByteArrayParseException(String message, Throwable cause) { 44 | super(message, cause); 45 | } 46 | 47 | public ByteArrayParseException(Throwable cause) { 48 | super(cause); 49 | } 50 | 51 | protected ByteArrayParseException(String message, Throwable cause, 52 | boolean enableSuppression, 53 | boolean writableStackTrace) { 54 | super(message, cause, enableSuppression, writableStackTrace); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtcp/model/RtcpBasePackage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtcp.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.common.IObjectByteArray; 29 | 30 | /** 31 | * Base package. 32 | * (基础包) 33 | * 34 | * @author xingshuang 35 | */ 36 | public class RtcpBasePackage implements IObjectByteArray { 37 | /** 38 | * header. 39 | */ 40 | protected RtcpHeader header; 41 | 42 | public RtcpHeader getHeader() { 43 | return header; 44 | } 45 | 46 | public void setHeader(RtcpHeader header) { 47 | this.header = header; 48 | } 49 | 50 | @Override 51 | public int byteArrayLength() { 52 | if (this.header == null) { 53 | return 0; 54 | } 55 | return this.header.byteArrayLength(); 56 | } 57 | 58 | @Override 59 | public byte[] toByteArray() { 60 | if (this.header == null) { 61 | return new byte[0]; 62 | } 63 | return this.header.toByteArray(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/constant/RtspEntityHeaderFields.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.constant; 26 | 27 | 28 | /** 29 | * Entity header fields. 30 | * (实体头字段) 31 | * 32 | * @author xingshuang 33 | */ 34 | public class RtspEntityHeaderFields { 35 | 36 | private RtspEntityHeaderFields() { 37 | // NOOP 38 | } 39 | 40 | public static final String ALLOW = "Allow"; 41 | public static final String CONTENT_BASE = "Content-Base"; 42 | public static final String CONTENT_ENCODING = "Content-Encoding"; 43 | public static final String CONTENT_LANGUAGE = "Content-Language"; 44 | public static final String CONTENT_LENGTH = "Content-Length"; 45 | public static final String CONTENT_LOCATION = "Content-Location"; 46 | 47 | public static final String CACHE_CONTROL = "Cache-Control"; 48 | public static final String CONTENT_TYPE = "Content-Type"; 49 | public static final String EXPIRES = "Expires"; 50 | public static final String LAST_MODIFIED = "Last-Modified"; 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/service/ModbusAsciiOverTcpTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.service; 26 | 27 | import com.github.xingshuangs.iot.utils.HexUtil; 28 | import lombok.extern.slf4j.Slf4j; 29 | import org.junit.Before; 30 | import org.junit.Ignore; 31 | import org.junit.Test; 32 | 33 | import static org.junit.Assert.*; 34 | 35 | @Ignore 36 | @Slf4j 37 | public class ModbusAsciiOverTcpTest { 38 | 39 | private final ModbusAsciiOverTcp plc = new ModbusAsciiOverTcp(); 40 | 41 | @Before 42 | public void before() { 43 | this.plc.setComCallback((tag, bytes) -> System.out.printf("%s[%d] %s%n", tag, bytes.length, HexUtil.toHexString(bytes))); 44 | this.plc.setComStringCallback(log::debug); 45 | } 46 | 47 | @Test 48 | public void readUInt32Test() { 49 | long i = plc.readUInt32(0); 50 | System.out.println(i); 51 | } 52 | 53 | @Test 54 | public void readUInt16Test() { 55 | int i = plc.readUInt16(0); 56 | System.out.println(i); 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/mp4/model/Mp4StscBox.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.mp4.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.mp4.enums.EMp4Type; 29 | 30 | /** 31 | * Sample To Chunk Box(stbl-stsc), 32 | * Using chunk to organize samples facilitates data acquisition. A chunk contains one or more samples."stsc" is described in a table, 33 | * Mapping between sample and chunk. By viewing the table, you can find the thunk that contains the specified sample and find the sample. 34 | * Of course, each table entry may contain one or more chunks 35 | * 用chunk组织sample可以方便优化数据获取,一个chunk包含一个或多个sample。“stsc”中用一个表描述了 36 | * sample与chunk的映射关系,查看这张表就可以找到包含指定sample的thunk,从而找到这个sample,当然每个table entry可能包含一个或者多个chunk。fmp4方式,此box不必赋值,简单封装一个box即可 37 | * 38 | * @author xingshuang 39 | */ 40 | public class Mp4StscBox extends Mp4StcoBox { 41 | 42 | public Mp4StscBox() { 43 | this.mp4Type = EMp4Type.STSC; 44 | this.version = 0; 45 | this.flags = new byte[3]; 46 | this.entryCount = 0; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/s7/serializer/S7ParseData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.serializer; 26 | 27 | 28 | import com.github.xingshuangs.iot.common.enums.EDataType; 29 | import com.github.xingshuangs.iot.protocol.s7.model.DataItem; 30 | import com.github.xingshuangs.iot.protocol.s7.model.RequestItem; 31 | import lombok.Data; 32 | 33 | import java.lang.reflect.Field; 34 | 35 | /** 36 | * S7 parse data 37 | * S7解析数据 38 | * 39 | * @author xingshuang 40 | */ 41 | @Data 42 | public class S7ParseData { 43 | 44 | /** 45 | * Data type. 46 | * (数据类型) 47 | */ 48 | private EDataType dataType; 49 | 50 | /** 51 | * Data count. 52 | * (数据个数) 53 | */ 54 | private int count; 55 | 56 | /** 57 | * Field. 58 | * (字段参数) 59 | */ 60 | private Field field; 61 | 62 | /** 63 | * Request item. 64 | * (请求项) 65 | */ 66 | private RequestItem requestItem; 67 | 68 | /** 69 | * Data item. 70 | * (数据项) 71 | */ 72 | private DataItem dataItem; 73 | } 74 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/s7/model/DataItemTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.s7.enums.EDataVariableType; 28 | import com.github.xingshuangs.iot.protocol.s7.enums.EReturnCode; 29 | import org.junit.Test; 30 | 31 | import static org.junit.Assert.*; 32 | 33 | 34 | public class DataItemTest { 35 | 36 | @Test 37 | public void byteArrayLength() { 38 | DataItem dataItem = new DataItem(); 39 | assertEquals(4, dataItem.byteArrayLength()); 40 | } 41 | 42 | @Test 43 | public void toByteArray() { 44 | DataItem dataItem = new DataItem(); 45 | dataItem.setReturnCode(EReturnCode.from((byte) 0xFF)); 46 | dataItem.setVariableType(EDataVariableType.BYTE_WORD_DWORD); 47 | dataItem.setCount(1); 48 | dataItem.setData(new byte[1]); 49 | byte[] actual = dataItem.toByteArray(); 50 | byte[] expect = {(byte) 0xFF, (byte) 0x04, (byte) 0x00, (byte) 0x08, (byte) 0x00}; 51 | assertArrayEquals(expect, actual); 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/common/algorithm/LoopGroupItem.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.common.algorithm; 26 | 27 | 28 | import lombok.Data; 29 | 30 | /** 31 | * Loop group item, include basic parameter. 32 | * (基础数据参数) 33 | * 34 | * @author xingshuang 35 | */ 36 | @Data 37 | public class LoopGroupItem { 38 | 39 | /** 40 | * Actual length. 41 | * (实际长度) 42 | */ 43 | private int actualLength = 0; 44 | 45 | /** 46 | * Current offset. 47 | * (当前偏移量) 48 | */ 49 | private int off = 0; 50 | 51 | /** 52 | * Current length. 53 | * (当前长度) 54 | */ 55 | private int len = 0; 56 | 57 | public LoopGroupItem() { 58 | } 59 | 60 | public LoopGroupItem(int actualLength) { 61 | this.actualLength = actualLength; 62 | } 63 | 64 | /** 65 | * If current data is in valid range. 66 | * (判定是否在有效范围内) 67 | * 68 | * @return true:in range,false:out range. 69 | */ 70 | public boolean inRange() { 71 | return this.off + this.len < this.actualLength; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/s7/model/NckRequestBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.s7.enums.EFunctionCode; 29 | 30 | import java.util.Collections; 31 | import java.util.List; 32 | 33 | /** 34 | * NCK request builder. 35 | * NCK请求构建器 36 | * 37 | * @author xingshuang 38 | */ 39 | public class NckRequestBuilder { 40 | 41 | private NckRequestBuilder() { 42 | // NOOP 43 | } 44 | 45 | public static S7Data creatNckRequest(RequestNckItem item) { 46 | return creatNckRequest(Collections.singletonList(item)); 47 | } 48 | 49 | public static S7Data creatNckRequest(List items) { 50 | S7Data s7Data = new S7Data(); 51 | s7Data.setTpkt(new TPKT()); 52 | s7Data.setCotp(COTPData.createDefault()); 53 | s7Data.setHeader(Header.createDefault()); 54 | s7Data.setParameter(ReadWriteParameter.createReqParameter(EFunctionCode.READ_VARIABLE, items)); 55 | s7Data.selfCheck(); 56 | return s7Data; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/s7/model/PlcControlStringParamBlock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.common.buff.ByteWriteBuff; 29 | import lombok.Data; 30 | import lombok.EqualsAndHashCode; 31 | 32 | /** 33 | * PLC control, parameter block string. 34 | * PLC控制参数块,字符串格式 35 | * 36 | * @author xingshuang 37 | */ 38 | @Data 39 | @EqualsAndHashCode(callSuper = true) 40 | public class PlcControlStringParamBlock extends PlcControlParamBlock { 41 | 42 | private String paramBlock = ""; 43 | 44 | public PlcControlStringParamBlock() { 45 | } 46 | 47 | public PlcControlStringParamBlock(String paramBlock) { 48 | this.paramBlock = paramBlock; 49 | } 50 | 51 | @Override 52 | public int byteArrayLength() { 53 | return this.paramBlock.length(); 54 | } 55 | 56 | @Override 57 | public byte[] toByteArray() { 58 | return ByteWriteBuff.newInstance(this.paramBlock.length()) 59 | .putString(this.paramBlock) 60 | .getData(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/melsec/model/McError4E3EDataTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.melsec.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.melsec.enums.EMcCommand; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class McError4E3EDataTest { 34 | 35 | @Test 36 | public void fromBytes() { 37 | byte[] src = new byte[]{ 38 | 0x00, (byte) 0xFF, (byte) 0xFF, 0x03, 0x00, 0x01, 0x04, 0x01, 0x00 39 | }; 40 | McError4E3EData data = McError4E3EData.fromBytes(src); 41 | McFrame4E3EAccessRoute accessRoute = (McFrame4E3EAccessRoute) data.getAccessRoute(); 42 | assertEquals(0, accessRoute.getNetworkNumber()); 43 | assertEquals(0xFF, accessRoute.getPcNumber()); 44 | assertEquals(0x03FF, accessRoute.getRequestDestModuleIoNumber()); 45 | assertEquals(0, accessRoute.getRequestDestModuleStationNumber()); 46 | assertEquals(EMcCommand.DEVICE_ACCESS_BATCH_READ_IN_UNITS, data.getCommand()); 47 | assertEquals(0x0001, data.getSubcommand()); 48 | } 49 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/utils/LRCUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package com.github.xingshuangs.iot.utils; 25 | 26 | 27 | /** 28 | * LRC tool. 29 | * LRC校验工具 30 | * 31 | * @author xingshuang 32 | */ 33 | public class LRCUtil { 34 | 35 | private LRCUtil() { 36 | // NOOP 37 | } 38 | 39 | /** 40 | * Get LRC code. 41 | * (获取lrc码) 42 | * 43 | * @param src byte array 44 | * @return byte 45 | */ 46 | public static byte lrc(byte[] src) { 47 | if (src == null || src.length == 0) { 48 | throw new IllegalArgumentException("src"); 49 | } 50 | 51 | int sum = 0; 52 | for (byte b : src) { 53 | sum += b; 54 | } 55 | sum = sum % 256; 56 | sum = 256 - sum; 57 | return (byte) sum; 58 | } 59 | 60 | /** 61 | * Check LRC. 62 | * (lrc校验) 63 | * 64 | * @param src byte array 65 | * @param target target result 66 | * @return true:equality,false:inequality 67 | */ 68 | public static boolean lrc(byte[] src, byte target) { 69 | byte des = lrc(src); 70 | return des == target; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/s7/enums/EPlcType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.enums; 26 | 27 | 28 | /** 29 | * PLC type. 30 | * 31 | * @author xingshuang 32 | */ 33 | public enum EPlcType { 34 | S200(0, 1, 240), 35 | S200_SMART(0, 1, 240), 36 | S300(0, 2, 240), 37 | S400(0, 3, 480), 38 | S1200(0, 1, 240), 39 | S1500(0, 1, 960), 40 | SINUMERIK_828D(0, 1, 240), 41 | 42 | ; 43 | 44 | /** 45 | * Rack. 46 | * PLC机架号 47 | */ 48 | private final int rack; 49 | 50 | /** 51 | * Slot. 52 | * PLC槽号 53 | */ 54 | private final int slot; 55 | 56 | /** 57 | * PDU max length. 58 | * PDU最大允许长度 59 | */ 60 | private final int pduLength; 61 | 62 | EPlcType(int rack, int slot, int pduLength) { 63 | this.rack = rack; 64 | this.slot = slot; 65 | this.pduLength = pduLength; 66 | } 67 | 68 | public int getRack() { 69 | return rack; 70 | } 71 | 72 | public int getSlot() { 73 | return slot; 74 | } 75 | 76 | public int getPduLength() { 77 | return pduLength; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/melsec/model/McReqData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.melsec.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.melsec.enums.EMcCommand; 29 | import com.github.xingshuangs.iot.protocol.melsec.enums.EMcSeries; 30 | import lombok.Data; 31 | import lombok.EqualsAndHashCode; 32 | 33 | /** 34 | * Req data. 35 | * (协议体数据:公共请求数据) 36 | * 37 | * @author xingshuang 38 | */ 39 | @Data 40 | @EqualsAndHashCode(callSuper = true) 41 | public class McReqData extends McData { 42 | 43 | /** 44 | * PLC series. 45 | * (PLC系列) 46 | */ 47 | protected EMcSeries series = EMcSeries.Q_L; 48 | 49 | /** 50 | * Command, 2-bytes. 51 | * (指令,2个字节) 52 | */ 53 | protected EMcCommand command = EMcCommand.DEVICE_ACCESS_BATCH_READ_IN_UNITS; 54 | 55 | /** 56 | * Sub command, 2-bytes. 57 | * (子指令,2个字节) 58 | */ 59 | protected int subcommand = 0x0000; 60 | 61 | @Override 62 | public int byteArrayLength() { 63 | return 0; 64 | } 65 | 66 | @Override 67 | public byte[] toByteArray() { 68 | return new byte[0]; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/s7/model/Parameter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.common.IObjectByteArray; 29 | import com.github.xingshuangs.iot.common.buff.ByteWriteBuff; 30 | import com.github.xingshuangs.iot.protocol.s7.enums.EFunctionCode; 31 | import lombok.Data; 32 | 33 | /** 34 | * Parameter. 35 | * 参数 36 | * 37 | * @author xingshuang 38 | */ 39 | @Data 40 | public class Parameter implements IObjectByteArray { 41 | 42 | /** 43 | * Function code. 44 | * 功能码
45 | * 字节大小:1
46 | * 字节序数:0 47 | */ 48 | protected EFunctionCode functionCode = EFunctionCode.READ_VARIABLE; 49 | 50 | public Parameter() { 51 | } 52 | 53 | public Parameter(EFunctionCode functionCode) { 54 | this.functionCode = functionCode; 55 | } 56 | 57 | @Override 58 | public int byteArrayLength() { 59 | return 1; 60 | } 61 | 62 | @Override 63 | public byte[] toByteArray() { 64 | return ByteWriteBuff.newInstance(1) 65 | .putByte(this.functionCode.getCode()) 66 | .getData(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/mp4/model/Mp4DinfBox.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.mp4.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.common.buff.ByteWriteBuff; 29 | import com.github.xingshuangs.iot.protocol.mp4.enums.EMp4Type; 30 | 31 | /** 32 | * The Data Reference Box contains the dref box, and fmp4 can assign the default value. 33 | * Data Reference Box 其包含dref box,fmp4给默认赋值即可 34 | * 35 | * @author xingshuang 36 | */ 37 | public class Mp4DinfBox extends Mp4Box { 38 | 39 | private final Mp4DrefBox drefBox; 40 | 41 | public Mp4DinfBox() { 42 | this.mp4Type = EMp4Type.DINF; 43 | this.drefBox = new Mp4DrefBox(); 44 | } 45 | 46 | @Override 47 | public int byteArrayLength() { 48 | return 8 + this.drefBox.byteArrayLength(); 49 | } 50 | 51 | @Override 52 | public byte[] toByteArray() { 53 | int size = this.byteArrayLength(); 54 | return ByteWriteBuff.newInstance(size) 55 | .putInteger(size) 56 | .putBytes(this.mp4Type.getByteArray()) 57 | .putBytes(this.drefBox.toByteArray()) 58 | .getData(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/s7/service/MultiAddressRead.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.service; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.s7.model.RequestItem; 29 | import com.github.xingshuangs.iot.protocol.s7.utils.AddressUtil; 30 | import lombok.AllArgsConstructor; 31 | import lombok.Data; 32 | import lombok.NoArgsConstructor; 33 | 34 | import java.util.ArrayList; 35 | import java.util.List; 36 | 37 | /** 38 | * Wrapper address for reading. 39 | * 地址的包装类 40 | * 41 | * @author xingshuang 42 | */ 43 | @NoArgsConstructor 44 | @AllArgsConstructor 45 | @Data 46 | public class MultiAddressRead { 47 | 48 | /** 49 | * Request items. 50 | * 请求项列表 51 | */ 52 | List requestItems = new ArrayList<>(); 53 | 54 | /** 55 | * Add data by address and byte count. 56 | * 添加数据 57 | * 58 | * @param address address string 59 | * @param count byte count 60 | * @return MultiAddressRead 61 | */ 62 | public MultiAddressRead addData(String address, int count) { 63 | this.requestItems.add(AddressUtil.parseByte(address, count)); 64 | return this; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/s7/model/HeaderBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.exceptions.S7CommException; 29 | import com.github.xingshuangs.iot.protocol.s7.enums.EMessageType; 30 | 31 | /** 32 | * Header builder. 33 | * Header构建器 34 | * 35 | * @author xingshuang 36 | */ 37 | public class HeaderBuilder { 38 | 39 | private HeaderBuilder() { 40 | // NOOP 41 | } 42 | 43 | /** 44 | * Parses byte array and converts it to object. 45 | * 46 | * @param data byte array 47 | * @return Header 48 | */ 49 | public static Header fromBytes(final byte[] data) { 50 | EMessageType messageType = EMessageType.from(data[1]); 51 | 52 | switch (messageType) { 53 | case JOB: 54 | return Header.fromBytes(data); 55 | case ACK: 56 | case ACK_DATA: 57 | return AckHeader.fromBytes(data); 58 | case USER_DATA: 59 | return null; 60 | default: 61 | throw new S7CommException("Header message type can not be recognized"); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/model/MbReadCoilRequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.modbus.enums.EMbFunctionCode; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class MbReadCoilRequestTest { 34 | 35 | @Test 36 | public void toByteArray() { 37 | byte[] actual = new byte[]{(byte) 0x01, (byte) 0x00, (byte) 0x13, (byte) 0x00, (byte) 0x13}; 38 | MbReadCoilRequest mb = new MbReadCoilRequest(); 39 | mb.setFunctionCode(EMbFunctionCode.READ_COIL); 40 | mb.setAddress(19); 41 | mb.setQuantity(19); 42 | assertEquals(5, mb.byteArrayLength()); 43 | assertArrayEquals(actual, mb.toByteArray()); 44 | } 45 | 46 | @Test 47 | public void fromBytes() { 48 | byte[] data = new byte[]{(byte) 0x01, (byte) 0x00, (byte) 0x13, (byte) 0x00, (byte) 0x13}; 49 | MbReadCoilRequest mb = MbReadCoilRequest.fromBytes(data); 50 | assertEquals(EMbFunctionCode.READ_COIL, mb.functionCode); 51 | assertEquals(19, mb.getAddress()); 52 | assertEquals(19, mb.getQuantity()); 53 | } 54 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/s7/model/COTPConnectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.model; 26 | 27 | import org.junit.Test; 28 | 29 | import static org.junit.Assert.*; 30 | 31 | 32 | public class COTPConnectionTest { 33 | 34 | @Test 35 | public void byteArrayLength() { 36 | COTPConnection connection = new COTPConnection(); 37 | assertEquals(18, connection.byteArrayLength()); 38 | } 39 | 40 | @Test 41 | public void toByteArray() { 42 | COTPConnection connection = COTPConnection.crConnectRequest(0x0100,0x0100); 43 | byte[] actual = connection.toByteArray(); 44 | byte[] expect = {(byte) 0x11, (byte) 0xE0, 45 | (byte) 0x00, (byte) 0x00, 46 | (byte) 0x00, (byte) 0x01, 47 | (byte) 0x00, 48 | (byte) 0xC0, 49 | (byte) 0x01, 50 | (byte) 0x0A, 51 | (byte) 0xC1, 52 | (byte) 0x02, 53 | (byte) 0x01, (byte) 0x00, 54 | (byte) 0xC2, 55 | (byte) 0x02, 56 | (byte) 0x01, (byte) 0x00}; 57 | 58 | assertArrayEquals(expect, actual); 59 | } 60 | } -------------------------------------------------------------------------------- /tutorial/README-WebVideo-CN.md: -------------------------------------------------------------------------------- 1 | # WEB视频监控教程 2 | 3 | [返回主页](../README-CN.md) 4 | 5 | ## 前言 6 | 7 | - 采用**RTSP + H264 + FMP4 + WebSocket + MSE + WEB**的方案 8 | - 目前支持**海康和大华摄像头**RTSP视频流在WEB页面上显示,实现实时监控 9 | - 视频流获取支持**TCP/UDP**两种方式,可根据网络情况任意切换 10 | - 通讯库纯**JAVA**开发,没有任何其他依赖,轻量级 11 | - 视频延时 **< 1s**,几乎无延时,实时性强 12 | - 提供MSE+WebSocket相关js库代码 13 | 14 | ## 注意事项 15 | 16 | - 浏览器必须支持**MSE**,**WebSocket** 17 | 18 | ## 示例 19 | 20 | - 采用FMP4 + RTSP客户端的代理方式; 21 | - 内部自动将H264视频流转换为FMP4格式; 22 | - 默认采用TCP + 同步数据处理的方式,也支持UDP以及异步数据处理的方式 23 | 24 | ```java 25 | public class RtspFMp4ProxyTcpSync { 26 | 27 | public static void main(String[] args) { 28 | // rtsp的摄像头地址 29 | URI uri = URI.create("rtsp://192.168.3.1:554/h264/ch1/main/av_stream"); 30 | // 身份认证 31 | UsernamePasswordCredential credential = new UsernamePasswordCredential("admin", "123456"); 32 | DigestAuthenticator authenticator = new DigestAuthenticator(credential); 33 | // 构建RTSP客户端对象,此处采用TCP的通信方式 34 | RtspClient client = new RtspClient(uri, authenticator, ERtspTransportProtocol.TCP); 35 | // 构建FMp4代理,此处采用同步方式 36 | RtspFMp4Proxy proxy = new RtspFMp4Proxy(client); 37 | // 设置FMP4数据接收事件 38 | proxy.onFmp4DataHandle(x -> { 39 | // *****编写处理数据业务***** 40 | System.out.println(x.length); 41 | }); 42 | // 设置编解码格式数据事件 43 | proxy.onCodecHandle(x -> { 44 | // *****编写处理数据业务***** 45 | System.out.println(x); 46 | }); 47 | proxy.onDestroyHandle(() -> System.out.println("close")); 48 | // 采用异步的形式关闭,由于是测试示例,写在启动前面 49 | CompletableFuture.runAsync(() -> { 50 | try { 51 | TimeUnit.SECONDS.sleep(5); 52 | } catch (InterruptedException e) { 53 | throw new RuntimeException(e); 54 | } 55 | proxy.stop(); 56 | }); 57 | // 启动,返回异步执行对象 58 | CompletableFuture future = proxy.start(); 59 | // 循环等待结束 60 | while (!future.isDone()) { 61 | try { 62 | TimeUnit.SECONDS.sleep(1); 63 | } catch (InterruptedException e) { 64 | throw new RuntimeException(e); 65 | } 66 | } 67 | } 68 | } 69 | ``` 70 | 71 | ## 前端视频DEMO 72 | 73 | - 可自行开发WebSocket的服务端,将视频流发送给WEB端 74 | - 示例教程链接: https://github.com/xingshuangs/rtsp-websocket-server 75 | 76 | ![rtsp-websocket.png](https://i.postimg.cc/vBZzrGQB/img.png) 77 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/model/MbReadCoilResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.modbus.enums.EMbFunctionCode; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class MbReadCoilResponseTest { 34 | 35 | @Test 36 | public void toByteArray() { 37 | MbReadCoilResponse mb = new MbReadCoilResponse(); 38 | mb.setFunctionCode(EMbFunctionCode.READ_COIL); 39 | mb.setCount(3); 40 | mb.setCoilStatus(new byte[]{(byte) 0xCD, (byte) 0x6B, (byte) 0x05}); 41 | assertArrayEquals(new byte[]{(byte) 0x01, (byte) 0x03, (byte) 0xCD, (byte) 0x6B, (byte) 0x05}, mb.toByteArray()); 42 | } 43 | 44 | @Test 45 | public void fromBytes() { 46 | byte[] data = new byte[]{(byte) 0x01, (byte) 0x03, (byte) 0xCD, (byte) 0x6B, (byte) 0x05}; 47 | MbReadCoilResponse mb = MbReadCoilResponse.fromBytes(data); 48 | assertEquals(EMbFunctionCode.READ_COIL, mb.functionCode); 49 | assertEquals(3, mb.getCount()); 50 | assertArrayEquals(new byte[]{(byte) 0xCD, (byte) 0x6B, (byte) 0x05}, mb.getCoilStatus()); 51 | } 52 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/utils/FloatUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.utils; 26 | 27 | import org.junit.Test; 28 | 29 | import static org.junit.Assert.*; 30 | 31 | 32 | public class FloatUtilTest { 33 | 34 | @Test 35 | public void toFloat32() { 36 | byte[] data = new byte[]{(byte) 0x42, (byte) 0x04, (byte) 0xA3, (byte) 0xD7}; 37 | float actual = FloatUtil.toFloat32(data); 38 | assertEquals(33.16f, actual, 0.00001); 39 | data = new byte[]{(byte) 0xC1, (byte) 0x79, (byte) 0xEB, (byte) 0x85}; 40 | actual = FloatUtil.toFloat32(data); 41 | assertEquals(-15.62f, actual, 0.001); 42 | } 43 | 44 | @Test 45 | public void toFloat64() { 46 | byte[] data = new byte[]{(byte) 0x41, (byte) 0x03, (byte) 0x1F, (byte) 0xCA, (byte) 0xD6, (byte) 0x21, (byte) 0x39, (byte) 0xB7}; 47 | double actual = FloatUtil.toFloat64(data); 48 | assertEquals(156665.35455556, actual, 0.000000001); 49 | data = new byte[]{(byte) 0xC0, (byte) 0xEB, (byte) 0x98, (byte) 0x95, (byte) 0x55, (byte) 0x1D, (byte) 0x68, (byte) 0xC7}; 50 | actual = FloatUtil.toFloat64(data); 51 | assertEquals(-56516.66664, actual, 0.000001); 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/melsec/model/McReadDeviceBatchInBitReqData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.melsec.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.melsec.enums.EMcCommand; 29 | import com.github.xingshuangs.iot.protocol.melsec.enums.EMcSeries; 30 | import lombok.Data; 31 | import lombok.EqualsAndHashCode; 32 | 33 | /** 34 | * Device access request data, batch read in bit. 35 | * (软元件访问批量读请求数据,位单位) 36 | * 37 | * @author xingshuang 38 | */ 39 | @Data 40 | @EqualsAndHashCode(callSuper = true) 41 | public class McReadDeviceBatchInBitReqData extends McReadDeviceBatchReqData { 42 | 43 | public McReadDeviceBatchInBitReqData() { 44 | this(EMcSeries.Q_L, new McDeviceAddress()); 45 | } 46 | 47 | public McReadDeviceBatchInBitReqData(EMcSeries series) { 48 | this(series, new McDeviceAddress()); 49 | } 50 | 51 | public McReadDeviceBatchInBitReqData(EMcSeries series, McDeviceAddress deviceAddress) { 52 | this.series = series; 53 | this.command = EMcCommand.DEVICE_ACCESS_BATCH_READ_IN_UNITS; 54 | this.subcommand = series != EMcSeries.IQ_R ? 0x0001 : 0x0003; 55 | this.deviceAddress = deviceAddress; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/melsec/model/McReadDeviceBatchInWordReqData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.melsec.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.melsec.enums.EMcCommand; 29 | import com.github.xingshuangs.iot.protocol.melsec.enums.EMcSeries; 30 | import lombok.Data; 31 | import lombok.EqualsAndHashCode; 32 | 33 | /** 34 | * Device access request data, batch read in word. 35 | * 软元件访问批量读请求数据,字单位 36 | * 37 | * @author xingshuang 38 | */ 39 | @Data 40 | @EqualsAndHashCode(callSuper = true) 41 | public class McReadDeviceBatchInWordReqData extends McReadDeviceBatchReqData { 42 | 43 | public McReadDeviceBatchInWordReqData() { 44 | this(EMcSeries.Q_L, new McDeviceAddress()); 45 | } 46 | 47 | public McReadDeviceBatchInWordReqData(EMcSeries series) { 48 | this(series, new McDeviceAddress()); 49 | } 50 | 51 | public McReadDeviceBatchInWordReqData(EMcSeries series, McDeviceAddress deviceAddress) { 52 | this.series = series; 53 | this.command = EMcCommand.DEVICE_ACCESS_BATCH_READ_IN_UNITS; 54 | this.subcommand = series != EMcSeries.IQ_R ? 0x0000 : 0x0002; 55 | this.deviceAddress = deviceAddress; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/s7/model/COTP.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.common.IObjectByteArray; 29 | import com.github.xingshuangs.iot.common.buff.ByteWriteBuff; 30 | import com.github.xingshuangs.iot.protocol.s7.enums.EPduType; 31 | import lombok.Data; 32 | 33 | /** 34 | * COTP structure. 35 | * 36 | * @author xingshuang 37 | */ 38 | @Data 39 | public class COTP implements IObjectByteArray { 40 | 41 | /** 42 | * Length, exclude this length field. 43 | * 长度(但并不包含length这个字段)
44 | * 字节大小:1
45 | * 字节序数:0 46 | */ 47 | protected int length = 0x00; 48 | 49 | /** 50 | * PDU type. 51 | * PDU类型(CRConnect Request 连接请求)
52 | * 字节大小:1
53 | * 字节序数:1 54 | */ 55 | protected EPduType pduType = EPduType.CONNECT_REQUEST; 56 | 57 | @Override 58 | public int byteArrayLength() { 59 | return 2; 60 | } 61 | 62 | @Override 63 | public byte[] toByteArray() { 64 | return ByteWriteBuff.newInstance(2) 65 | .putByte(this.length) 66 | .putByte(this.pduType.getCode()) 67 | .getData(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/model/MbReadInputRegisterResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.modbus.enums.EMbFunctionCode; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class MbReadInputRegisterResponseTest { 34 | @Test 35 | public void toByteArray() { 36 | MbReadInputRegisterResponse mb = new MbReadInputRegisterResponse(); 37 | mb.setFunctionCode(EMbFunctionCode.READ_INPUT_REGISTER); 38 | mb.setCount(2); 39 | mb.setRegister(new byte[]{(byte) 0x00, (byte) 0x0A}); 40 | assertArrayEquals(new byte[]{(byte) 0x04, (byte) 0x02, (byte) 0x00, (byte) 0x0A}, mb.toByteArray()); 41 | } 42 | 43 | @Test 44 | public void fromBytes() { 45 | byte[] data = new byte[]{(byte) 0x04, (byte) 0x02, (byte) 0x00, (byte) 0x0A}; 46 | MbReadInputRegisterResponse mb = MbReadInputRegisterResponse.fromBytes(data); 47 | assertEquals(EMbFunctionCode.READ_INPUT_REGISTER, mb.functionCode); 48 | assertEquals(2, mb.getCount()); 49 | assertArrayEquals(new byte[]{(byte) 0x00, (byte) 0x0A}, mb.getRegister()); 50 | } 51 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/model/MbWriteMultipleCoilResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.modbus.enums.EMbFunctionCode; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class MbWriteMultipleCoilResponseTest { 34 | 35 | @Test 36 | public void toByteArray() { 37 | byte[] actual = new byte[]{(byte) 0x0F, (byte) 0x00, (byte) 0x13, (byte) 0x00, (byte) 0x0A}; 38 | MbWriteMultipleCoilResponse mb = new MbWriteMultipleCoilResponse(); 39 | mb.setFunctionCode(EMbFunctionCode.WRITE_MULTIPLE_COIL); 40 | mb.setAddress(19); 41 | mb.setQuantity(10); 42 | assertArrayEquals(actual, mb.toByteArray()); 43 | } 44 | 45 | @Test 46 | public void fromBytes() { 47 | byte[] data = new byte[]{(byte) 0x0F, (byte) 0x00, (byte) 0x13, (byte) 0x00, (byte) 0x0A}; 48 | MbWriteMultipleCoilResponse mb = MbWriteMultipleCoilResponse.fromBytes(data); 49 | assertEquals(EMbFunctionCode.WRITE_MULTIPLE_COIL, mb.functionCode); 50 | assertEquals(19, mb.getAddress()); 51 | assertEquals(10, mb.getQuantity()); 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/melsec/model/McWriteDeviceBatchInBitReqData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.melsec.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.melsec.enums.EMcCommand; 29 | import com.github.xingshuangs.iot.protocol.melsec.enums.EMcSeries; 30 | import lombok.Data; 31 | import lombok.EqualsAndHashCode; 32 | 33 | /** 34 | * Device access request data, batch write in bit. 35 | * 软元件访问批量写请求数据,位单位 36 | * 37 | * @author xingshuang 38 | */ 39 | @Data 40 | @EqualsAndHashCode(callSuper = true) 41 | public class McWriteDeviceBatchInBitReqData extends McWriteDeviceBatchReqData { 42 | 43 | public McWriteDeviceBatchInBitReqData() { 44 | this(EMcSeries.Q_L, new McDeviceContent()); 45 | } 46 | 47 | public McWriteDeviceBatchInBitReqData(EMcSeries series) { 48 | this(series, new McDeviceContent()); 49 | } 50 | 51 | public McWriteDeviceBatchInBitReqData(EMcSeries series, McDeviceContent deviceContent) { 52 | this.series = series; 53 | this.command = EMcCommand.DEVICE_ACCESS_BATCH_WRITE_IN_UNITS; 54 | this.subcommand = series != EMcSeries.IQ_R ? 0x0001 : 0x0003; 55 | this.deviceContent = deviceContent; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/melsec/model/McWriteDeviceBatchInWordReqData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.melsec.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.protocol.melsec.enums.EMcCommand; 29 | import com.github.xingshuangs.iot.protocol.melsec.enums.EMcSeries; 30 | import lombok.Data; 31 | import lombok.EqualsAndHashCode; 32 | 33 | /** 34 | * Device access request data, batch write in word. 35 | * 软元件访问批量写请求数据,字单位 36 | * 37 | * @author xingshuang 38 | */ 39 | @Data 40 | @EqualsAndHashCode(callSuper = true) 41 | public class McWriteDeviceBatchInWordReqData extends McWriteDeviceBatchReqData { 42 | 43 | public McWriteDeviceBatchInWordReqData() { 44 | this(EMcSeries.Q_L, new McDeviceContent()); 45 | } 46 | 47 | public McWriteDeviceBatchInWordReqData(EMcSeries series) { 48 | this(series, new McDeviceContent()); 49 | } 50 | 51 | public McWriteDeviceBatchInWordReqData(EMcSeries series, McDeviceContent deviceContent) { 52 | this.series = series; 53 | this.command = EMcCommand.DEVICE_ACCESS_BATCH_WRITE_IN_UNITS; 54 | this.subcommand = series != EMcSeries.IQ_R ? 0x0000 : 0x0002; 55 | this.deviceContent = deviceContent; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/model/RtspDescribeResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.model; 26 | 27 | 28 | import com.github.xingshuangs.iot.exceptions.RtspCommException; 29 | import com.github.xingshuangs.iot.protocol.rtsp.model.sdp.RtspSdp; 30 | import lombok.Getter; 31 | 32 | /** 33 | * Describe response. 34 | * 35 | * @author xingshuang 36 | */ 37 | @Getter 38 | public final class RtspDescribeResponse extends RtspMessageResponse { 39 | 40 | /** 41 | * SDP media info. 42 | */ 43 | private RtspSdp sdp; 44 | 45 | public static RtspDescribeResponse fromHeaderString(String src) { 46 | if (src == null || src.equals("")) { 47 | throw new RtspCommException("src is null or empty in RtspGetParameterResponse"); 48 | } 49 | RtspDescribeResponse response = new RtspDescribeResponse(); 50 | response.parseHeaderAndReturnMap(src); 51 | 52 | return response; 53 | } 54 | 55 | /** 56 | * Add body info from string. 57 | * (通过字符串添加body内容) 58 | * 59 | * @param src string. 60 | */ 61 | @Override 62 | public void addBodyFromString(String src) { 63 | this.sdp = RtspSdp.fromString(src); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/model/MbWriteSingleCoilRequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.modbus.enums.EMbFunctionCode; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class MbWriteSingleCoilRequestTest { 34 | @Test 35 | public void toByteArray() { 36 | byte[] actual = new byte[]{(byte) 0x05, (byte) 0x00, (byte) 0xAC, (byte) 0xFF, (byte) 0x00}; 37 | MbWriteSingleCoilRequest mb = new MbWriteSingleCoilRequest(); 38 | mb.setFunctionCode(EMbFunctionCode.WRITE_SINGLE_COIL); 39 | mb.setAddress(172); 40 | mb.setValue(true); 41 | assertEquals(5, mb.byteArrayLength()); 42 | assertArrayEquals(actual, mb.toByteArray()); 43 | } 44 | 45 | @Test 46 | public void fromBytes() { 47 | byte[] data = new byte[]{(byte) 0x05, (byte) 0x00, (byte) 0xAC, (byte) 0xFF, (byte) 0x00}; 48 | MbWriteSingleCoilRequest mb = MbWriteSingleCoilRequest.fromBytes(data); 49 | assertEquals(EMbFunctionCode.WRITE_SINGLE_COIL, mb.functionCode); 50 | assertEquals(172, mb.getAddress()); 51 | assertTrue( mb.isValue()); 52 | } 53 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/model/MbWriteMultipleRegisterResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.modbus.enums.EMbFunctionCode; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class MbWriteMultipleRegisterResponseTest { 34 | 35 | @Test 36 | public void toByteArray() { 37 | byte[] actual = new byte[]{(byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02}; 38 | MbWriteMultipleRegisterResponse mb = new MbWriteMultipleRegisterResponse(); 39 | mb.setFunctionCode(EMbFunctionCode.WRITE_MULTIPLE_REGISTER); 40 | mb.setAddress(1); 41 | mb.setQuantity(2); 42 | assertArrayEquals(actual, mb.toByteArray()); 43 | } 44 | 45 | @Test 46 | public void fromBytes() { 47 | byte[] data = new byte[]{(byte) 0x10, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x02}; 48 | MbWriteMultipleRegisterResponse mb = MbWriteMultipleRegisterResponse.fromBytes(data); 49 | assertEquals(EMbFunctionCode.WRITE_MULTIPLE_REGISTER, mb.functionCode); 50 | assertEquals(1, mb.getAddress()); 51 | assertEquals(2, mb.getQuantity()); 52 | } 53 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/s7/serializer/DemoLargeBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.serializer; 26 | 27 | 28 | import com.github.xingshuangs.iot.common.enums.EDataType; 29 | import lombok.Data; 30 | 31 | /** 32 | * 测试对象 33 | * 34 | * @author xingshuang 35 | */ 36 | @Data 37 | public class DemoLargeBean { 38 | 39 | @S7Variable(address = "DB1.0.1", type = EDataType.BOOL) 40 | private boolean bitData; 41 | 42 | @S7Variable(address = "DB1.10", type = EDataType.BYTE, count = 50) 43 | private byte[] byteData1; 44 | 45 | @S7Variable(address = "DB1.60", type = EDataType.BYTE, count = 65) 46 | private byte[] byteData2; 47 | 48 | @S7Variable(address = "DB1.125", type = EDataType.BYTE, count = 200) 49 | private byte[] byteData3; 50 | 51 | @S7Variable(address = "DB1.325", type = EDataType.BYTE, count = 322) 52 | private byte[] byteData4; 53 | 54 | @S7Variable(address = "DB1.647", type = EDataType.BYTE, count = 99) 55 | private byte[] byteData5; 56 | 57 | @S7Variable(address = "DB1.746", type = EDataType.BYTE, count = 500) 58 | private byte[] byteData6; 59 | 60 | @S7Variable(address = "DB1.1246", type = EDataType.BYTE, count = 44) 61 | private byte[] byteData7; 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/model/MbReadHoldRegisterRequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.modbus.enums.EMbFunctionCode; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class MbReadHoldRegisterRequestTest { 34 | 35 | @Test 36 | public void toByteArray() { 37 | byte[] actual = new byte[]{(byte) 0x03, (byte) 0x00, (byte) 0x6B, (byte) 0x00, (byte) 0x03}; 38 | MbReadHoldRegisterRequest mb = new MbReadHoldRegisterRequest(); 39 | mb.setFunctionCode(EMbFunctionCode.READ_HOLD_REGISTER); 40 | mb.setAddress(107); 41 | mb.setQuantity(3); 42 | assertEquals(5, mb.byteArrayLength()); 43 | assertArrayEquals(actual, mb.toByteArray()); 44 | } 45 | 46 | @Test 47 | public void fromBytes() { 48 | byte[] data = new byte[]{(byte) 0x03, (byte) 0x00, (byte) 0x6B, (byte) 0x00, (byte) 0x03}; 49 | MbReadHoldRegisterRequest mb = MbReadHoldRegisterRequest.fromBytes(data); 50 | assertEquals(EMbFunctionCode.READ_HOLD_REGISTER, mb.functionCode); 51 | assertEquals(107, mb.getAddress()); 52 | assertEquals(3, mb.getQuantity()); 53 | } 54 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/model/MbReadInputRegisterRequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.modbus.enums.EMbFunctionCode; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class MbReadInputRegisterRequestTest { 34 | @Test 35 | public void toByteArray() { 36 | byte[] actual = new byte[]{(byte) 0x04, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x01}; 37 | MbReadInputRegisterRequest mb = new MbReadInputRegisterRequest(); 38 | mb.setFunctionCode(EMbFunctionCode.READ_INPUT_REGISTER); 39 | mb.setAddress(8); 40 | mb.setQuantity(1); 41 | assertEquals(5, mb.byteArrayLength()); 42 | assertArrayEquals(actual, mb.toByteArray()); 43 | } 44 | 45 | @Test 46 | public void fromBytes() { 47 | byte[] data = new byte[]{(byte) 0x04, (byte) 0x00, (byte) 0x08, (byte) 0x00, (byte) 0x01}; 48 | MbReadInputRegisterRequest mb = MbReadInputRegisterRequest.fromBytes(data); 49 | assertEquals(EMbFunctionCode.READ_INPUT_REGISTER, mb.functionCode); 50 | assertEquals(8, mb.getAddress()); 51 | assertEquals(1, mb.getQuantity()); 52 | } 53 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/model/MbReadDiscreteInputRequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.modbus.enums.EMbFunctionCode; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class MbReadDiscreteInputRequestTest { 34 | 35 | @Test 36 | public void toByteArray() { 37 | byte[] actual = new byte[]{(byte) 0x02, (byte) 0x00, (byte) 0xC4, (byte) 0x00, (byte) 0x16}; 38 | MbReadDiscreteInputRequest mb = new MbReadDiscreteInputRequest(); 39 | mb.setFunctionCode(EMbFunctionCode.READ_DISCRETE_INPUT); 40 | mb.setAddress(196); 41 | mb.setQuantity(22); 42 | assertEquals(5, mb.byteArrayLength()); 43 | assertArrayEquals(actual, mb.toByteArray()); 44 | } 45 | 46 | @Test 47 | public void fromBytes() { 48 | byte[] data = new byte[]{(byte) 0x02, (byte) 0x00, (byte) 0xC4, (byte) 0x00, (byte) 0x16}; 49 | MbReadDiscreteInputRequest mb = MbReadDiscreteInputRequest.fromBytes(data); 50 | assertEquals(EMbFunctionCode.READ_DISCRETE_INPUT, mb.functionCode); 51 | assertEquals(196, mb.getAddress()); 52 | assertEquals(22, mb.getQuantity()); 53 | } 54 | } -------------------------------------------------------------------------------- /src/main/java/com/github/xingshuangs/iot/protocol/rtsp/model/sdp/RtspSdpTime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.rtsp.model.sdp; 26 | 27 | 28 | import com.github.xingshuangs.iot.exceptions.RtspCommException; 29 | import lombok.Data; 30 | 31 | import static com.github.xingshuangs.iot.protocol.rtsp.constant.RtspCommonKey.SP; 32 | 33 | /** 34 | * Time. 35 | * 时间 36 | * 0 0 37 | * 38 | * @author xingshuang 39 | */ 40 | @Data 41 | public class RtspSdpTime { 42 | 43 | /** 44 | * Start time. 45 | * 起始时间 46 | */ 47 | private Integer startTime; 48 | 49 | /** 50 | * End time. 51 | * 结束时间 52 | */ 53 | private Integer endTime; 54 | 55 | public static RtspSdpTime fromString(String src) { 56 | if (src == null || src.equals("")) { 57 | throw new IllegalArgumentException("when SDP parses Time, data error"); 58 | } 59 | RtspSdpTime time = new RtspSdpTime(); 60 | String[] split = src.split(SP); 61 | if (split.length != 2) { 62 | throw new RtspCommException("RtspSdpTime data is incorrect and cannot be parsed"); 63 | } 64 | time.startTime = Integer.parseInt(split[0]); 65 | time.endTime = Integer.parseInt(split[1]); 66 | return time; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/s7/model/DatumTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.s7.enums.EDataVariableType; 28 | import com.github.xingshuangs.iot.protocol.s7.enums.EReturnCode; 29 | import org.junit.Test; 30 | 31 | import static org.junit.Assert.*; 32 | 33 | 34 | public class DatumTest { 35 | 36 | @Test 37 | public void byteArrayLength() { 38 | DataItem dataItem = new DataItem(); 39 | ReadWriteDatum datum = new ReadWriteDatum(); 40 | datum.getReturnItems().add(dataItem); 41 | assertEquals(4, datum.byteArrayLength()); 42 | } 43 | 44 | @Test 45 | public void toByteArray() { 46 | DataItem dataItem = new DataItem(); 47 | dataItem.setReturnCode(EReturnCode.from((byte) 0xFF)); 48 | dataItem.setVariableType(EDataVariableType.BYTE_WORD_DWORD); 49 | dataItem.setCount(1); 50 | dataItem.setData(new byte[1]); 51 | ReadWriteDatum datum = new ReadWriteDatum(); 52 | datum.getReturnItems().add(dataItem); 53 | byte[] actual = datum.toByteArray(); 54 | byte[] expect = {(byte) 0xFF, (byte) 0x04, (byte) 0x00, (byte) 0x08, (byte) 0x00}; 55 | assertArrayEquals(expect, actual); 56 | } 57 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/s7/model/Mc7FileTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.s7.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.s7.enums.EFileBlockType; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class Mc7FileTest { 34 | 35 | @Test 36 | public void fromBytes() { 37 | byte[] data = new byte[]{ 38 | (byte) 0x70, (byte) 0x70, (byte) 0x00, (byte) 0x00, (byte) 0x13, (byte) 0x08, (byte) 0x00, (byte) 0x01, 39 | (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x91, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 40 | (byte) 0x02, (byte) 0xd1, (byte) 0xb8, (byte) 0x41, (byte) 0x38, (byte) 0x9c, (byte) 0x02, (byte) 0xd1, 41 | (byte) 0xb8, (byte) 0x0e, (byte) 0x38, (byte) 0x9c, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x5d, 42 | (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x10, 43 | }; 44 | Mc7File mc7File = Mc7File.fromBytes(data); 45 | assertEquals(36, mc7File.getData().length); 46 | assertEquals(EFileBlockType.OB, mc7File.getBlockType()); 47 | assertEquals(1, mc7File.getBlockNumber()); 48 | assertEquals(16, mc7File.getMC7CodeLength()); 49 | } 50 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/model/MbWriteSingleRegisterRequestTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.modbus.enums.EMbFunctionCode; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class MbWriteSingleRegisterRequestTest { 34 | 35 | @Test 36 | public void toByteArray() { 37 | byte[] actual = new byte[]{(byte) 0x06, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x03}; 38 | MbWriteSingleRegisterRequest mb = new MbWriteSingleRegisterRequest(); 39 | mb.setFunctionCode(EMbFunctionCode.WRITE_SINGLE_REGISTER); 40 | mb.setAddress(1); 41 | mb.setValue(3); 42 | assertEquals(5, mb.byteArrayLength()); 43 | assertArrayEquals(actual, mb.toByteArray()); 44 | } 45 | 46 | @Test 47 | public void fromBytes() { 48 | byte[] data = new byte[]{(byte) 0x06, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x03}; 49 | MbWriteSingleRegisterRequest mb = MbWriteSingleRegisterRequest.fromBytes(data); 50 | assertEquals(EMbFunctionCode.WRITE_SINGLE_REGISTER, mb.functionCode); 51 | assertEquals(1, mb.getAddress()); 52 | assertEquals(3, mb.getValue()); 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/model/MbReadDiscreteInputResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.modbus.enums.EMbFunctionCode; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class MbReadDiscreteInputResponseTest { 34 | 35 | @Test 36 | public void toByteArray() { 37 | MbReadDiscreteInputResponse mb = new MbReadDiscreteInputResponse(); 38 | mb.setFunctionCode(EMbFunctionCode.READ_DISCRETE_INPUT); 39 | mb.setCount(3); 40 | mb.setInputStatus(new byte[]{(byte) 0xAC, (byte) 0xDB, (byte) 0x35}); 41 | assertArrayEquals(new byte[]{(byte) 0x02, (byte) 0x03, (byte) 0xAC, (byte) 0xDB, (byte) 0x35}, mb.toByteArray()); 42 | } 43 | 44 | @Test 45 | public void fromBytes() { 46 | byte[] data = new byte[]{(byte) 0x02, (byte) 0x03, (byte) 0xAC, (byte) 0xDB, (byte) 0x35}; 47 | MbReadDiscreteInputResponse mb = MbReadDiscreteInputResponse.fromBytes(data); 48 | assertEquals(EMbFunctionCode.READ_DISCRETE_INPUT, mb.functionCode); 49 | assertEquals(3, mb.getCount()); 50 | assertArrayEquals(new byte[]{(byte) 0xAC, (byte) 0xDB, (byte) 0x35}, mb.getInputStatus()); 51 | } 52 | } -------------------------------------------------------------------------------- /src/test/java/com/github/xingshuangs/iot/protocol/modbus/model/MbWriteSingleCoilResponseTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2021-2099 Oscura (xingshuang) 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | 25 | package com.github.xingshuangs.iot.protocol.modbus.model; 26 | 27 | import com.github.xingshuangs.iot.protocol.modbus.enums.EMbFunctionCode; 28 | import org.junit.Test; 29 | 30 | import static org.junit.Assert.*; 31 | 32 | 33 | public class MbWriteSingleCoilResponseTest { 34 | @Test 35 | public void toByteArray() { 36 | byte[] actual = new byte[]{(byte) 0x05, (byte) 0x00, (byte) 0xAC, (byte) 0xFF, (byte) 0x00}; 37 | MbWriteSingleCoilResponse mb = new MbWriteSingleCoilResponse(); 38 | mb.setFunctionCode(EMbFunctionCode.WRITE_SINGLE_COIL); 39 | mb.setAddress(172); 40 | mb.setValue(new byte[]{(byte) 0xFF, (byte) 0x00}); 41 | assertEquals(5, mb.byteArrayLength()); 42 | assertArrayEquals(actual, mb.toByteArray()); 43 | } 44 | 45 | @Test 46 | public void fromBytes() { 47 | byte[] data = new byte[]{(byte) 0x05, (byte) 0x00, (byte) 0xAC, (byte) 0xFF, (byte) 0x00}; 48 | MbWriteSingleCoilResponse mb = MbWriteSingleCoilResponse.fromBytes(data); 49 | assertEquals(EMbFunctionCode.WRITE_SINGLE_COIL, mb.functionCode); 50 | assertEquals(172, mb.getAddress()); 51 | assertArrayEquals(new byte[]{(byte) 0xFF, (byte) 0x00}, mb.getValue()); 52 | } 53 | } --------------------------------------------------------------------------------