Commit 2ceb875793ffa7ec3a4fd1db45acd1e8861f6252
1 parent
86fff45a
烽火-电信IOT插件
Showing
16 changed files
with
661 additions
and
3 deletions
VehicleDetector_FH_FH/VehicleDetector-FH-FH.iml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | |
3 | + <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> | |
4 | + <output url="file://$MODULE_DIR$/target/classes" /> | |
5 | + <output-test url="file://$MODULE_DIR$/target/test-classes" /> | |
6 | + <content url="file://$MODULE_DIR$"> | |
7 | + <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | |
8 | + <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | |
9 | + <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | |
10 | + <excludeFolder url="file://$MODULE_DIR$/target" /> | |
11 | + </content> | |
12 | + <orderEntry type="inheritedJdk" /> | |
13 | + <orderEntry type="sourceFolder" forTests="false" /> | |
14 | + <orderEntry type="library" name="Maven: junit:junit:4.11" level="project" /> | |
15 | + <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" /> | |
16 | + <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.6" level="project" /> | |
17 | + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.7.4" level="project" /> | |
18 | + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.7.0" level="project" /> | |
19 | + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.7.4" level="project" /> | |
20 | + <orderEntry type="module-library"> | |
21 | + <library name="Maven: com.huawei:protocal-jar:1.3.1"> | |
22 | + <CLASSES> | |
23 | + <root url="jar://$MODULE_DIR$/lib/com.huawei.m2m.cig.tup-1.3.1.jar!/" /> | |
24 | + </CLASSES> | |
25 | + <JAVADOC /> | |
26 | + <SOURCES /> | |
27 | + </library> | |
28 | + </orderEntry> | |
29 | + <orderEntry type="library" name="Maven: net.sf.json-lib:json-lib:jdk15:2.4" level="project" /> | |
30 | + <orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.8.0" level="project" /> | |
31 | + <orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" /> | |
32 | + <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.5" level="project" /> | |
33 | + <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" /> | |
34 | + <orderEntry type="library" name="Maven: net.sf.ezmorph:ezmorph:1.0.6" level="project" /> | |
35 | + </component> | |
36 | +</module> | |
0 | 37 | \ No newline at end of file | ... | ... |
VehicleDetector_FH_FH/lib/com.huawei.m2m.cig.tup-1.3.1.jar
0 → 100644
No preview for this file type
VehicleDetector_FH_FH/package/package-info.json
0 → 100644
1 | +{"specVersion":"1.0","fileName":"package.zip","version":"1.0.0","deviceType":"VehicleDetector","manufacturerName":"FH","model":"FH","description":"CIG codec plugin auto-generated by sps.","platform":"linux","packageType":"CIGPlugin","date":"Wed Aug 29 03:47:49 GMT 2018","ignoreList":[],"bundles":[{"bundleName":"VehicleDetector-FH-FH","bundleVersion":"1.0.0","priority":5,"fileName":"VehicleDetector-FH-FH-1.0.0.jar","bundleDesc":"","versionDesc":""}]} | |
0 | 2 | \ No newline at end of file | ... | ... |
VehicleDetector_FH_FH/package/package.zip
0 → 100644
No preview for this file type
VehicleDetector_FH_FH/package/preload/VehicleDetector-FH-FH-1.0.0.jar
0 → 100644
No preview for this file type
VehicleDetector_FH_FH/pom.xml
0 → 100644
1 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
2 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
3 | + <modelVersion>4.0.0</modelVersion> | |
4 | + | |
5 | + <groupId>com.fh.party</groupId> | |
6 | + <!-- 请修改为你的编解码插件的名字,命名规范:设备类型-厂商ID-设备型号,例如:WaterMeter-Huawei-NBIoTDevice --> | |
7 | + <artifactId>VehicleDetector-FH-FH</artifactId> | |
8 | + <version>1.0.0</version> | |
9 | + <!-- 请检查这里的值为bundle,不能为jar --> | |
10 | + <packaging>bundle</packaging> | |
11 | + | |
12 | + <properties> | |
13 | + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
14 | + <junit.version>4.11</junit.version> | |
15 | + <fasterxml.jackson.version>2.7.4</fasterxml.jackson.version> | |
16 | + <felix.maven.plugin.version>2.5.4</felix.maven.plugin.version> | |
17 | + <json.lib.version>2.4</json.lib.version> | |
18 | + <m2m.cig.version>1.3.1</m2m.cig.version> | |
19 | + <slf4j.api.version>1.7.6</slf4j.api.version> | |
20 | + <basedir>./</basedir> | |
21 | + </properties> | |
22 | + | |
23 | + <dependencies> | |
24 | + <!-- 单元测试使用 --> | |
25 | + <dependency> | |
26 | + <groupId>junit</groupId> | |
27 | + <artifactId>junit</artifactId> | |
28 | + <version>${junit.version}</version> | |
29 | + </dependency> | |
30 | + <!-- 日志使用 --> | |
31 | + <dependency> | |
32 | + <groupId>org.slf4j</groupId> | |
33 | + <artifactId>slf4j-api</artifactId> | |
34 | + <version>${slf4j.api.version}</version> | |
35 | + </dependency> | |
36 | + <!-- 转换JSON使用,必须 --> | |
37 | + <dependency> | |
38 | + <groupId>com.fasterxml.jackson.core</groupId> | |
39 | + <artifactId>jackson-databind</artifactId> | |
40 | + <version>${fasterxml.jackson.version}</version> | |
41 | + </dependency> | |
42 | + <!-- Huawei提供的编解码接口,必须 --> | |
43 | + <!-- systemPath请替换成你本地的目录 \codecDemo\lib\com.huawei.m2m.cig.tup-1.3.1.jar --> | |
44 | + <dependency> | |
45 | + <groupId>com.huawei</groupId> | |
46 | + <artifactId>protocal-jar</artifactId> | |
47 | + <version>1.3.1</version> | |
48 | + <scope>system</scope> | |
49 | + <systemPath>${basedir}/lib/com.huawei.m2m.cig.tup-1.3.1.jar</systemPath> | |
50 | + </dependency> | |
51 | + | |
52 | + <!-- 本例中数据转换使用到的jar,你用到的jar请写到这里,记得把artifactId填入后面的Embed-Dependency --> | |
53 | + <dependency> | |
54 | + <groupId>net.sf.json-lib</groupId> | |
55 | + <artifactId>json-lib</artifactId> | |
56 | + <version>2.4</version> | |
57 | + <classifier>jdk15</classifier> | |
58 | + </dependency> | |
59 | + | |
60 | + </dependencies> | |
61 | + <build> | |
62 | + <plugins> | |
63 | + <!-- 编码需要使用JDK1.8版本 --> | |
64 | + <plugin> | |
65 | + <groupId>org.apache.maven.plugins</groupId> | |
66 | + <artifactId>maven-compiler-plugin</artifactId> | |
67 | + <configuration> | |
68 | + <source>1.8</source> | |
69 | + <target>1.8</target> | |
70 | + </configuration> | |
71 | + </plugin> | |
72 | + <!-- OSGI规范打包配置 --> | |
73 | + <plugin> | |
74 | + <groupId>org.apache.felix</groupId> | |
75 | + <artifactId>maven-bundle-plugin</artifactId> | |
76 | + <version>${felix.maven.plugin.version}</version> | |
77 | + <extensions>true</extensions> | |
78 | + <configuration> | |
79 | + <buildDirectory>./target</buildDirectory> | |
80 | + <archive> | |
81 | + <addMavenDescriptor>false</addMavenDescriptor> | |
82 | + </archive> | |
83 | + <instructions> | |
84 | + <Bundle-RequiredExecutionEnvironment>J2SE-1.5</Bundle-RequiredExecutionEnvironment> | |
85 | + <Bundle-Activator></Bundle-Activator> | |
86 | + <Service-Component>OSGI-INF/*</Service-Component> | |
87 | + <!-- 请修改为你的编解码插件的名字,命名规范:设备类型-厂商ID-设备型号,例如:WaterMeter-Huawei-NBIoTDevice --> | |
88 | + <Bundle-SymbolicName>VehicleDetector-FH-FH</Bundle-SymbolicName> | |
89 | + <Export-Package></Export-Package> | |
90 | + <Import-Package> | |
91 | + org.slf4j, | |
92 | + org.slf4j.spi, | |
93 | + org.apache.log4j.spi, | |
94 | + com.huawei.m2m.cig.tup.modules.protocol_adapter, | |
95 | + com.fasterxml.jackson.databind, | |
96 | + com.fasterxml.jackson.databind.node | |
97 | + </Import-Package> | |
98 | + <!-- 除junit,slf4j-api,jackson-databind,protocal-jar, 其他所有的依赖包,必须把包对应的artifactId填入Embed-Dependency。artifactId之间以逗号分隔。 --> | |
99 | + <Embed-Dependency> | |
100 | + json-lib | |
101 | + </Embed-Dependency> | |
102 | + </instructions> | |
103 | + </configuration> | |
104 | + <executions> | |
105 | + <execution> | |
106 | + <id>generate-resource</id> | |
107 | + <goals> | |
108 | + <goal>manifest</goal> | |
109 | + </goals> | |
110 | + </execution> | |
111 | + </executions> | |
112 | + </plugin> | |
113 | + </plugins> | |
114 | + </build> | |
115 | +</project> | |
0 | 116 | \ No newline at end of file | ... | ... |
VehicleDetector_FH_FH/src/main/java/com/fh/party/CmdProcess.java
0 → 100644
1 | +package com.fh.party; | |
2 | + | |
3 | +import com.fasterxml.jackson.databind.JsonNode; | |
4 | +import com.fasterxml.jackson.databind.node.ObjectNode; | |
5 | + | |
6 | +public class CmdProcess { | |
7 | + | |
8 | + //private String identifier = "123"; | |
9 | + private byte cmdid = 0x01; | |
10 | + private int pid; | |
11 | + private int tid; | |
12 | + private int eventcnt; | |
13 | + private int verno; | |
14 | + private int eventstate; | |
15 | + | |
16 | + | |
17 | + public CmdProcess() { | |
18 | + } | |
19 | + | |
20 | + public CmdProcess(ObjectNode input) { | |
21 | + try { | |
22 | + this.pid = (byte)input.get("pid").asInt(); | |
23 | + this.tid = (byte)input.get("tid").asInt(); | |
24 | + this.eventcnt = (byte)input.get("eventcnt").asInt(); | |
25 | + this.verno = (byte)input.get("verno").asInt(); | |
26 | + this.eventstate = (byte)input.get("eventstate").asInt(); | |
27 | + } catch (Exception e) { | |
28 | + e.printStackTrace(); | |
29 | + } | |
30 | + | |
31 | + } | |
32 | + | |
33 | + public byte[] toByte() { | |
34 | + byte[] bytes = new byte[6]; | |
35 | + bytes[0] = cmdid; | |
36 | + bytes[1] = (byte)pid; | |
37 | + bytes[2] = (byte)tid; | |
38 | + bytes[3] = (byte)eventcnt; | |
39 | + bytes[4] = (byte)verno; | |
40 | + bytes[5] = (byte)eventstate; | |
41 | + return bytes; | |
42 | + } | |
43 | + | |
44 | +} | ... | ... |
VehicleDetector_FH_FH/src/main/java/com/fh/party/ProtocolAdapterImpl.java
0 → 100644
1 | +package com.fh.party; | |
2 | + | |
3 | +import org.slf4j.Logger; | |
4 | +import org.slf4j.LoggerFactory; | |
5 | + | |
6 | +import com.fasterxml.jackson.databind.node.ObjectNode; | |
7 | +import com.huawei.m2m.cig.tup.modules.protocol_adapter.IProtocolAdapter; | |
8 | + | |
9 | + | |
10 | +public class ProtocolAdapterImpl implements IProtocolAdapter { | |
11 | + | |
12 | + private static final Logger logger = LoggerFactory.getLogger(ProtocolAdapterImpl.class); | |
13 | + // 厂商名称 | |
14 | + private static final String MANU_FACTURERID = "FH"; | |
15 | + // 设备型号 | |
16 | + private static final String MODEL = "FH"; | |
17 | + | |
18 | + @Override | |
19 | + public String getManufacturerId() { | |
20 | + return MANU_FACTURERID; | |
21 | + } | |
22 | + | |
23 | + @Override | |
24 | + public String getModel() { | |
25 | + return MODEL; | |
26 | + } | |
27 | + | |
28 | + public void activate() { | |
29 | + logger.info("Codec demo HttpMessageHander activated."); | |
30 | + } | |
31 | + | |
32 | + public void deactivate() { | |
33 | + logger.info("Codec demo HttpMessageHander deactivated."); | |
34 | + } | |
35 | + | |
36 | + public byte[] encode(ObjectNode input) throws Exception { | |
37 | + /*logger.info("dynamic lrbtest " + input.toString()); | |
38 | + try { | |
39 | + CmdProcess cmdProcess = new CmdProcess(input); | |
40 | + byte[] byteNode = cmdProcess.toByte(); | |
41 | + return byteNode; | |
42 | + } catch (Exception e) { | |
43 | + e.printStackTrace(); | |
44 | + return null; | |
45 | + }*/ | |
46 | + return null; | |
47 | + } | |
48 | + | |
49 | + public ObjectNode decode(byte[] binaryData) throws Exception { | |
50 | + try { | |
51 | + ReportProcess lightProcess = new ReportProcess(binaryData); | |
52 | + ObjectNode objectNode = lightProcess.toJsonNode(); | |
53 | + logger.info("dynamic lrbtest " + objectNode.toString()); | |
54 | + return objectNode; | |
55 | + } catch (Exception e) { | |
56 | + e.printStackTrace(); | |
57 | + return null; | |
58 | + } | |
59 | + } | |
60 | + | |
61 | +} | ... | ... |
VehicleDetector_FH_FH/src/main/java/com/fh/party/ReportProcess.java
0 → 100644
1 | +package com.fh.party; | |
2 | + | |
3 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
4 | +import com.fasterxml.jackson.databind.node.ObjectNode; | |
5 | + | |
6 | +import java.text.DateFormat; | |
7 | +import java.text.ParseException; | |
8 | +import java.text.SimpleDateFormat; | |
9 | +import java.util.Date; | |
10 | + | |
11 | +public class ReportProcess { | |
12 | + private byte cmdid = 0x01; | |
13 | + private int pid; | |
14 | + private int tid; | |
15 | + private int eventcnt; | |
16 | + private int verno; | |
17 | + private byte eventstate; | |
18 | + | |
19 | + // | |
20 | + private String factoryCode = "fh"; | |
21 | + private String model = "fh"; | |
22 | + private int reportType; | |
23 | + private int reportTime; | |
24 | + private int state; | |
25 | + private int packCount; | |
26 | + private int voltage; | |
27 | + private int magId; | |
28 | + private int rssi; | |
29 | + private int version; | |
30 | + | |
31 | + public ReportProcess(byte[] binaryData) throws ParseException { | |
32 | + pid = binaryData[1]; | |
33 | + tid = binaryData[2]; | |
34 | + eventcnt = binaryData[3]; | |
35 | + verno = binaryData[4]; | |
36 | + eventstate = binaryData[5]; | |
37 | + if((eventstate & 1) == 1){ | |
38 | + reportType = 33; | |
39 | + } | |
40 | + if((eventstate & 2) == 2){ | |
41 | + reportType = 32; | |
42 | + } | |
43 | + if((eventstate & 3) == 3){ | |
44 | + reportType = 32; | |
45 | + } | |
46 | + magId = tid; | |
47 | + reportTime = calLastedTime(); | |
48 | + if((eventstate & 32) == 32){ | |
49 | + state = 1; | |
50 | + }else{ | |
51 | + state = 0; | |
52 | + } | |
53 | + } | |
54 | + | |
55 | + public ObjectNode toJsonNode() { | |
56 | + try { | |
57 | + //组装body体 | |
58 | + ObjectMapper mapper = new ObjectMapper(); | |
59 | + ObjectNode root = mapper.createObjectNode(); | |
60 | + // root.put("identifier", this.identifier); | |
61 | + root.put("factoryCode", this.factoryCode); | |
62 | + root.put("model", this.model); | |
63 | + root.put("reportType", this.reportType); | |
64 | + root.put("reportTime", this.reportTime); | |
65 | + root.put("state", this.state); | |
66 | + root.put("magId", this.magId); | |
67 | + return root; | |
68 | + } catch (Exception e) { | |
69 | + e.printStackTrace(); | |
70 | + return null; | |
71 | + } | |
72 | + } | |
73 | + | |
74 | + /** | |
75 | + * 1970-1-1 经过的秒总数 | |
76 | + * @return | |
77 | + */ | |
78 | + public static int calLastedTime() throws ParseException { | |
79 | + long a = new Date().getTime(); | |
80 | + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | |
81 | + Date startDate = dateFormat.parse("1970-01-01"); | |
82 | + long b = startDate.getTime(); | |
83 | + return (int)((a - b) / 1000); | |
84 | + } | |
85 | + | |
86 | + /** | |
87 | + * 将byte转换为一个长度为8的byte数组,数组每个值代表bit | |
88 | + */ | |
89 | + public static byte[] byteToArray(byte b) { | |
90 | + byte[] array = new byte[8]; | |
91 | + for (int i = 7; i >= 0; i--) { | |
92 | + array[i] = (byte)(b & 1); | |
93 | + b = (byte) (b >> 1); | |
94 | + } | |
95 | + return array; | |
96 | + } | |
97 | + | |
98 | + /** | |
99 | + * 把byte转为字符串的bit | |
100 | + */ | |
101 | + public static String byteToBit(byte b) { | |
102 | + return "" | |
103 | + + (byte) ((b >> 7) & 0x1) + (byte) ((b >> 6) & 0x1) | |
104 | + + (byte) ((b >> 5) & 0x1) + (byte) ((b >> 4) & 0x1) | |
105 | + + (byte) ((b >> 3) & 0x1) + (byte) ((b >> 2) & 0x1) | |
106 | + + (byte) ((b >> 1) & 0x1) + (byte) ((b >> 0) & 0x1); | |
107 | + } | |
108 | + | |
109 | + public static void main(String[] args) throws ParseException { | |
110 | + } | |
111 | +} | |
0 | 112 | \ No newline at end of file | ... | ... |
VehicleDetector_FH_FH/src/main/java/com/fh/party/Utilty.java
0 → 100644
1 | +package com.fh.party; | |
2 | + | |
3 | + | |
4 | +public class Utilty { | |
5 | + | |
6 | + private static Utilty instance = new Utilty(); | |
7 | + | |
8 | + public static Utilty getInstance() { | |
9 | + return instance; | |
10 | + } | |
11 | + | |
12 | + public static final int MIN_MID_VALUE = 1; | |
13 | + | |
14 | + public static final int MAX_MID_VALUE = 65535; | |
15 | + | |
16 | + | |
17 | + public int bytes2Int(byte[] b, int start, int length) { | |
18 | + int sum = 0; | |
19 | + int end = start + length; | |
20 | + for (int k = start; k < end; k++) { | |
21 | + int n = ((int) b[k]) & 0xff; | |
22 | + n <<= (--length) * 8; | |
23 | + sum += n; | |
24 | + } | |
25 | + return sum; | |
26 | + } | |
27 | + | |
28 | + public byte[] int2Bytes(int value, int length) { | |
29 | + byte[] b = new byte[length]; | |
30 | + for (int k = 0; k < length; k++) { | |
31 | + b[length - k - 1] = (byte) ((value >> 8 * k) & 0xff); | |
32 | + } | |
33 | + return b; | |
34 | + } | |
35 | + | |
36 | + public boolean isValidofMid(int mId) { | |
37 | + if (mId < MIN_MID_VALUE || mId > MAX_MID_VALUE) { | |
38 | + return false; | |
39 | + } | |
40 | + return true; | |
41 | + } | |
42 | + | |
43 | + | |
44 | + public static String parseByte2HexStr(byte[] buf) { | |
45 | + if (null == buf) { | |
46 | + return null; | |
47 | + } | |
48 | + | |
49 | + StringBuffer sb = new StringBuffer(); | |
50 | + for (int i = 0; i < buf.length; i++) { | |
51 | + String hex = Integer.toHexString(buf[i] & 0xFF); | |
52 | + if (hex.length() == 1) { | |
53 | + hex = '0' + hex; | |
54 | + } | |
55 | + sb.append(hex.toUpperCase()); | |
56 | + } | |
57 | + return sb.toString(); | |
58 | + } | |
59 | +} | ... | ... |
VehicleDetector_FH_FH/src/main/resources/OSGI-INF/CodecProvideHandler.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="com.fh.party.ProtocolAdapterImpl"> | |
3 | + <implementation class="com.fh.party.ProtocolAdapterImpl"/> | |
4 | + <service> | |
5 | + <provide interface="com.huawei.m2m.cig.tup.modules.protocol_adapter.IProtocolAdapter" /> | |
6 | + </service> | |
7 | +</scr:component> | ... | ... |
VehicleDetector_FH_FH/src/test/java/com/fh/party/ProtocolServiceImplTest.java
0 → 100644
1 | +package com.fh.party; | |
2 | + | |
3 | +import org.junit.Before; | |
4 | +import org.junit.Test; | |
5 | + | |
6 | +import com.fasterxml.jackson.databind.ObjectMapper; | |
7 | +import com.fasterxml.jackson.databind.node.ObjectNode; | |
8 | +import com.huawei.m2m.cig.tup.modules.protocol_adapter.IProtocolAdapter; | |
9 | + | |
10 | +/** | |
11 | + * Unit test for simple App. | |
12 | + */ | |
13 | +public class ProtocolServiceImplTest { | |
14 | + | |
15 | + private IProtocolAdapter protocolAdapter; | |
16 | + | |
17 | + @Before | |
18 | + public void setProtocolAdapter() { | |
19 | + this.protocolAdapter = new ProtocolAdapterImpl(); | |
20 | + } | |
21 | + | |
22 | + /** | |
23 | + * 测试用例1:设备向平台上报数据。 | |
24 | + * <p> | |
25 | + * <pre> | |
26 | + * 设备上报数据:AA72000032088D0320623399 | |
27 | + * </pre> | |
28 | + * | |
29 | + * @throws Exception | |
30 | + */ | |
31 | + @Test | |
32 | + public void testDecodeDeviceReportData() throws Exception { | |
33 | + byte[] deviceReqByte = getArray(); | |
34 | + ObjectNode objectNode = protocolAdapter.decode(deviceReqByte); | |
35 | + String str = objectNode.toString(); | |
36 | + System.out.println(str); | |
37 | + } | |
38 | + | |
39 | + /** | |
40 | + * 测试用例2:平台向设备下发控制命令: | |
41 | + * <p> | |
42 | + * <pre> | |
43 | + * { | |
44 | + * //"identifier": "123", | |
45 | + * "msgType": "cloudReq", | |
46 | + * "cmd": "SET_DEVICE_LEVEL", | |
47 | + * "mid": 2016, | |
48 | + * "paras": { "value": "10" }, | |
49 | + * "hasMore": 0 | |
50 | + * } | |
51 | + * </pre> | |
52 | + */ | |
53 | + //@Test | |
54 | + public byte[] testEncodeIoTSendCommand() throws Exception { | |
55 | + ObjectNode CloudReqObjectNode = initCloudReqObjectNode(); | |
56 | + byte[] outputByte = protocolAdapter.encode(CloudReqObjectNode); | |
57 | + System.out.println("cloudReq output:" + parseByte2HexStr(outputByte)); | |
58 | + return outputByte; | |
59 | + } | |
60 | + | |
61 | + /** | |
62 | + * 测试用例3:设备对平台命令的应答消息 有命令短id | |
63 | + * <p> | |
64 | + * <pre> | |
65 | + * 设备应答消息:AA7201000107E0 | |
66 | + * | |
67 | + * <pre> | |
68 | + * | |
69 | + * @throws Exception | |
70 | + */ | |
71 | + //@Test | |
72 | + public void testDecodeDeviceResponseIoT() throws Exception { | |
73 | + byte[] deviceRspByte = initDeviceRspByte(); | |
74 | + ObjectNode objectNode = protocolAdapter.decode(deviceRspByte); | |
75 | + String str = objectNode.toString(); | |
76 | + System.out.println(str); | |
77 | + } | |
78 | + | |
79 | + /** | |
80 | + * 测试用例4:平台收到设备的上报数据后对设备的应答,如果不需要应答则返回null即可 | |
81 | + * <pre> | |
82 | + * { | |
83 | + * "identifier": "0", | |
84 | + * "msgType": "cloudRsp", | |
85 | + * "request": [AA,72,00,00,32,08,8D,03,20,62,33,99], | |
86 | + * "errcode": 0, | |
87 | + * "hasMore": 0 | |
88 | + * } | |
89 | + * | |
90 | + * <pre> | |
91 | + * | |
92 | + * @throws Exception | |
93 | + */ | |
94 | + //@Test | |
95 | + public void testEncodeIoTResponseDevice() throws Exception { | |
96 | + byte[] deviceReqByte = initDeviceReqByte(); | |
97 | + ObjectNode cloudRspObjectNode = initCloudRspObjectNode(deviceReqByte); | |
98 | + byte[] outputByte2 = protocolAdapter.encode(cloudRspObjectNode); | |
99 | + System.out.println("cloudRsp output:" + parseByte2HexStr(outputByte2)); | |
100 | + } | |
101 | + | |
102 | + public static String parseByte2HexStr(byte[] buf) { | |
103 | + if (null == buf) { | |
104 | + return null; | |
105 | + } | |
106 | + | |
107 | + StringBuffer sb = new StringBuffer(); | |
108 | + for (int i = 0; i < buf.length; i++) { | |
109 | + String hex = Integer.toHexString(buf[i] & 0xFF); | |
110 | + if (hex.length() == 1) { | |
111 | + hex = '0' + hex; | |
112 | + } | |
113 | + sb.append(hex.toUpperCase()); | |
114 | + } | |
115 | + return sb.toString(); | |
116 | + } | |
117 | + | |
118 | + /* | |
119 | + * 初始化:设备数据上报码流 | |
120 | + */ | |
121 | + private static byte[] initDeviceReqByte() { | |
122 | + /** | |
123 | + * 本例入参: AA 72 00 00 32 08 8D 03 20 62 33 99 | |
124 | + */ | |
125 | + byte[] byteDeviceReq = new byte[12]; | |
126 | + byteDeviceReq[0] = (byte) 0xAA; | |
127 | + byteDeviceReq[1] = (byte) 0x72; | |
128 | + byteDeviceReq[2] = (byte) 0x00; | |
129 | + byteDeviceReq[3] = (byte) 0x00; | |
130 | + byteDeviceReq[4] = (byte) 0x32; | |
131 | + byteDeviceReq[5] = (byte) 0x08; | |
132 | + byteDeviceReq[6] = (byte) 0x8D; | |
133 | + byteDeviceReq[7] = (byte) 0x03; | |
134 | + byteDeviceReq[8] = (byte) 0x20; | |
135 | + byteDeviceReq[9] = (byte) 0x62; | |
136 | + byteDeviceReq[10] = (byte) 0x33; | |
137 | + byteDeviceReq[11] = (byte) 0x99; | |
138 | + System.out.println(byteDeviceReq[5]); | |
139 | + return byteDeviceReq; | |
140 | + } | |
141 | + | |
142 | + /* | |
143 | + * 初始化:平台向设备命令下发数据 | |
144 | + */ | |
145 | + private static ObjectNode initCloudReqObjectNode() { | |
146 | + ObjectMapper mapper = new ObjectMapper(); | |
147 | + ObjectNode cloudReqObjectNode = mapper.createObjectNode(); | |
148 | + ObjectNode paras = mapper.createObjectNode(); | |
149 | + paras.put("value", "10"); | |
150 | + cloudReqObjectNode.put("identifier", "123"); | |
151 | + cloudReqObjectNode.put("msgType", "cloudReq"); | |
152 | + cloudReqObjectNode.put("cmd", "SET_DEVICE_LEVEL"); | |
153 | + cloudReqObjectNode.put("paras", paras); | |
154 | + cloudReqObjectNode.put("hasMore", 0); | |
155 | + cloudReqObjectNode.put("mid", 2016); | |
156 | + return cloudReqObjectNode; | |
157 | + } | |
158 | + | |
159 | + private static byte[] getArray() { | |
160 | + byte[] input = new byte[9]; | |
161 | + input[0] = 0x01; | |
162 | + input[1] = 0x27; | |
163 | + input[2] = 0x02; | |
164 | + input[3] = 0x12; | |
165 | + input[4] = 0x01; | |
166 | + input[5] = 0x31; | |
167 | + input[6] = 0x44; | |
168 | + input[7] = 0x55; | |
169 | + input[8] = 0x01; | |
170 | + /*cloudReqObjectNode.put("cmdid", (byte)0x01); | |
171 | + cloudReqObjectNode.put("pid", (byte) 0xAA); | |
172 | + cloudReqObjectNode.put("tid", (byte) 0x01); | |
173 | + cloudReqObjectNode.put("eventcnt", (byte) 0x01); | |
174 | + cloudReqObjectNode.put("verno", (byte) 0x01); | |
175 | + cloudReqObjectNode.put("eventstate", (byte) 0xE0);*/ | |
176 | + return input; | |
177 | + } | |
178 | + | |
179 | + | |
180 | + | |
181 | + /* | |
182 | + * 初始化:设备对平台的响应码流 | |
183 | + */ | |
184 | + private static byte[] initDeviceRspByte() { | |
185 | + /* | |
186 | + * 测试用例:有命令短mid 设备应答消息:AA7201000107E0 | |
187 | + */ | |
188 | + byte[] byteDeviceRsp = new byte[12]; | |
189 | + byteDeviceRsp[0] = (byte) 0xAA; | |
190 | + byteDeviceRsp[1] = (byte) 0x72; | |
191 | + byteDeviceRsp[2] = (byte) 0x01; | |
192 | + byteDeviceRsp[3] = (byte) 0x00; | |
193 | + byteDeviceRsp[4] = (byte) 0x01; | |
194 | + byteDeviceRsp[5] = (byte) 0x07; | |
195 | + byteDeviceRsp[6] = (byte) 0xE0; | |
196 | + return byteDeviceRsp; | |
197 | + } | |
198 | + | |
199 | + /* | |
200 | + * 初始化:平台对设备的应答数据 | |
201 | + */ | |
202 | + private static ObjectNode initCloudRspObjectNode(byte[] device2CloudByte) { | |
203 | + | |
204 | + ObjectMapper mapper = new ObjectMapper(); | |
205 | + ObjectNode cloudRspObjectNode = mapper.createObjectNode(); | |
206 | + cloudRspObjectNode.put("identifier", "123"); | |
207 | + cloudRspObjectNode.put("msgType", "cloudRsp"); | |
208 | + // 设备上报的码流 | |
209 | + cloudRspObjectNode.put("request", device2CloudByte); | |
210 | + cloudRspObjectNode.put("errcode", 0); | |
211 | + cloudRspObjectNode.put("hasMore", 0); | |
212 | + return cloudRspObjectNode; | |
213 | + } | |
214 | +} | ... | ... |
pom.xml
zteits-nbiot/package/package-info.json
0 → 100644
1 | +{"specVersion":"1.0","fileName":"package.zip","version":"1.0.0","deviceType":"VehicleDetector","manufacturerName":"ZTEITS","model":"ZTEITS","description":"CIG codec plugin auto-generated by sps.","platform":"linux","packageType":"CIGPlugin","date":"Wed Aug 29 03:47:49 GMT 2018","ignoreList":[],"bundles":[{"bundleName":"VehicleDetector-ZTEITS-ZTEITS","bundleVersion":"1.0.0","priority":5,"fileName":"VehicleDetector-ZTEITS-ZTEITS-1.0.0.jar","bundleDesc":"","versionDesc":""}]} | |
0 | 2 | \ No newline at end of file | ... | ... |
zteits-nbiot/src/main/java/com/zteits/nbiot/decoder/ZteitsReportProcess.java
... | ... | @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
4 | 4 | import com.fasterxml.jackson.databind.node.ArrayNode; |
5 | 5 | import com.fasterxml.jackson.databind.node.ObjectNode; |
6 | 6 | |
7 | +import java.io.UnsupportedEncodingException; | |
7 | 8 | import java.util.Arrays; |
8 | 9 | |
9 | 10 | public class ZteitsReportProcess { |
... | ... | @@ -306,8 +307,9 @@ public class ZteitsReportProcess { |
306 | 307 | this.crc = paramInt; |
307 | 308 | } |
308 | 309 | |
309 | - public ZteitsReportProcess(byte[] binaryData) { | |
310 | - this.factoryCode = Utilty.hexStringToString(binaryData, 0, 4); | |
310 | + public ZteitsReportProcess(byte[] binaryData) throws UnsupportedEncodingException { | |
311 | + this.factoryCode = new String(Arrays.copyOfRange(binaryData,0,4),"UTF-8"); | |
312 | + //this.factoryCode = Utilty.hexStringToString(binaryData, 0, 4); | |
311 | 313 | this.model = Utilty.hexStringToString(binaryData,4,8); |
312 | 314 | this.reportType = Utilty.hexStringToInteger(binaryData,8,9); |
313 | 315 | this.nowTime1 = Utilty.hexStringToInteger(binaryData,9,13); | ... | ... |
zteits-nbiot/src/test/java/com/thrid/party/codec/demo/ProtocolServiceImplTest.java
... | ... | @@ -40,9 +40,15 @@ public class ProtocolServiceImplTest { |
40 | 40 | public static void main(String[] args) throws Exception { |
41 | 41 | IProtocolAdapter protocolAdapter = new ProtocolAdapterImpl(); |
42 | 42 | byte[] deviceReqByte = initDeviceReqByte(); |
43 | + ObjectNode objectNode = protocolAdapter.decode(deviceReqByte); | |
44 | + String str = objectNode.toString(); | |
45 | + System.out.println(str); | |
46 | + | |
47 | + | |
48 | + /*byte[] deviceReqByte = initDeviceReqByte(); | |
43 | 49 | ObjectNode cloudRspObjectNode = initCloudRspObjectNode(deviceReqByte); |
44 | 50 | byte[] outputByte2 = protocolAdapter.encode(cloudRspObjectNode); |
45 | - System.out.println("cloudRsp output:" + parseByte2HexStr(outputByte2)); | |
51 | + System.out.println("cloudRsp output:" + parseByte2HexStr(outputByte2));*/ | |
46 | 52 | } |
47 | 53 | |
48 | 54 | /** | ... | ... |