Commit b5a79dddd10d01a0ada82ae3a15273e4a00a6b16

Authored by zhaowg
1 parent 3a404b2a

电信IOT插件

zteits-nbiot/VehicleDetector-ZTEITS-ZTEITS.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="FacetManager">
  4 + <facet type="Osmorc" name="OSGi">
  5 + <configuration manifestGenerationMode="OsmorcControlled" manifestLocation="" jarfileLocation="VehicleDetector-ZTEITS-ZTEITS-1.0.0.jar" outputPathType="CompilerOutputPath" bndFileLocation="" bundlorFileLocation="" bundleActivator="" bundleSymbolicName="VehicleDetector-ZTEITS-ZTEITS" bundleVersion="1.0.0" ignoreFilePattern="" useProjectDefaultManifestFileLocation="true" alwaysRebuildBundleJAR="false" doNotSynchronizeWithMaven="false">
  6 + <additionalProperties>
  7 + <property key="Bundle-RequiredExecutionEnvironment" value="J2SE-1.5" />
  8 + <property key="Service-Component" value="OSGI-INF/*" />
  9 + <property key="Import-Package" value="org.slf4j,org.slf4j.spi,org.apache.log4j.spi,com.huawei.m2m.cig.tup.modules.protocol_adapter,com.fasterxml.jackson.databind,com.fasterxml.jackson.databind.node" />
  10 + <property key="Embed-Dependency" value="json-lib" />
  11 + <property key="Bundle-Name" value="VehicleDetector-ZTEITS-ZTEITS" />
  12 + <property key="Bundle-ClassPath" value=".,json-lib-2.4-jdk15.jar" />
  13 + <property key="Include-Resource" value="json-lib-2.4-jdk15.jar=$MAVEN_REPOSITORY$/net/sf/json-lib/json-lib/2.4/json-lib-2.4-jdk15.jar" />
  14 + <property key="Embedded-Artifacts" value="json-lib-2.4-jdk15.jar;g=&quot;net.sf.json-lib&quot;;a=&quot;json-lib&quot;;v=&quot;2.4&quot;;c=&quot;jdk15&quot;" />
  15 + </additionalProperties>
  16 + <additionalJARContents />
  17 + </configuration>
  18 + </facet>
  19 + </component>
  20 + <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
  21 + <output url="file://$MODULE_DIR$/target/classes" />
  22 + <output-test url="file://$MODULE_DIR$/target/test-classes" />
  23 + <content url="file://$MODULE_DIR$">
  24 + <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
  25 + <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
  26 + <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
  27 + <excludeFolder url="file://$MODULE_DIR$/target" />
  28 + </content>
  29 + <orderEntry type="inheritedJdk" />
  30 + <orderEntry type="sourceFolder" forTests="false" />
  31 + <orderEntry type="library" name="Maven: junit:junit:4.11" level="project" />
  32 + <orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
  33 + <orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.6" level="project" />
  34 + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.7.4" level="project" />
  35 + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.7.0" level="project" />
  36 + <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.7.4" level="project" />
  37 + <orderEntry type="module-library">
  38 + <library name="Maven: com.huawei:protocal-jar:1.3.1">
  39 + <CLASSES>
  40 + <root url="jar://$MODULE_DIR$/lib/com.huawei.m2m.cig.tup-1.3.1.jar!/" />
  41 + </CLASSES>
  42 + <JAVADOC />
  43 + <SOURCES />
  44 + </library>
  45 + </orderEntry>
  46 + <orderEntry type="library" name="Maven: net.sf.json-lib:json-lib:jdk15:2.4" level="project" />
  47 + <orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.8.0" level="project" />
  48 + <orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.1" level="project" />
  49 + <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.5" level="project" />
  50 + <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
  51 + <orderEntry type="library" name="Maven: net.sf.ezmorph:ezmorph:1.0.6" level="project" />
  52 + </component>
  53 +</module>
0 \ No newline at end of file 54 \ No newline at end of file
zteits-nbiot/src/main/java/com/zteits/nbiot/decoder/CRC16Util.java 0 → 100644
  1 +package com.zteits.nbiot.decoder;
  2 +
  3 +public class CRC16Util {
  4 +
  5 + /**
  6 + * 获取源数据和验证码的组合byte数组
  7 + *
  8 + * @param strings 可变长度的十六进制字符串
  9 + * @return
  10 + */
  11 + public static byte[] appendCrc16(String... strings) {
  12 + byte[] data = new byte[]{};
  13 + for (int i = 0; i < strings.length; i++) {
  14 + int x = Integer.parseInt(strings[i], 16);
  15 + byte n = (byte) x;
  16 + byte[] buffer = new byte[data.length + 1];
  17 + byte[] aa = {n};
  18 + System.arraycopy(data, 0, buffer, 0, data.length);
  19 + System.arraycopy(aa, 0, buffer, data.length, aa.length);
  20 + data = buffer;
  21 + }
  22 + return appendCrc16(data);
  23 + }
  24 +
  25 + /**
  26 + * 获取源数据和验证码的组合byte数组
  27 + *
  28 + * @param aa 字节数组
  29 + * @return
  30 + */
  31 + public static byte[] appendCrc16(byte[] aa) {
  32 + byte[] bb = getCrc16(aa);
  33 + byte[] cc = new byte[aa.length + bb.length];
  34 + System.arraycopy(aa, 0, cc, 0, aa.length);
  35 + System.arraycopy(bb, 0, cc, aa.length, bb.length);
  36 + return cc;
  37 + }
  38 +
  39 + /**
  40 + * 获取验证码byte数组,基于Modbus CRC16的校验算法
  41 + */
  42 + public static byte[] getCrc16(byte[] arr_buff) {
  43 + int len = arr_buff.length;
  44 +
  45 + // 预置 1 个 16 位的寄存器为十六进制FFFF, 称此寄存器为 CRC寄存器。
  46 + int crc = 0xFFFF;
  47 + int i, j;
  48 + for (i = 0; i < len; i++) {
  49 + // 把第一个 8 位二进制数据 与 16 位的 CRC寄存器的低 8 位相异或, 把结果放于 CRC寄存器
  50 + crc = ((crc & 0xFF00) | (crc & 0x00FF) ^ (arr_buff[i] & 0xFF));
  51 + for (j = 0; j < 8; j++) {
  52 + // 把 CRC 寄存器的内容右移一位( 朝低位)用 0 填补最高位, 并检查右移后的移出位
  53 + if ((crc & 0x0001) > 0) {
  54 + // 如果移出位为 1, CRC寄存器与多项式A001进行异或
  55 + crc = crc >> 1;
  56 + crc = crc ^ 0xA001;
  57 + } else
  58 + // 如果移出位为 0,再次右移一位
  59 + crc = crc >> 1;
  60 + }
  61 + }
  62 + return intToBytes(crc);
  63 + }
  64 +
  65 + /**
  66 + * 将int转换成byte数组,低位在前,高位在后
  67 + * 改变高低位顺序只需调换数组序号
  68 + */
  69 + private static byte[] intToBytes(int value) {
  70 + byte[] src = new byte[2];
  71 + src[1] = (byte) ((value >> 8) & 0xFF);
  72 + src[0] = (byte) (value & 0xFF);
  73 + return src;
  74 + }
  75 +}
0 \ No newline at end of file 76 \ No newline at end of file
zteits-nbiot/src/main/java/com/zteits/nbiot/decoder/ProtocolAdapterImpl.java 0 → 100644
  1 +package com.zteits.nbiot.decoder;
  2 +
  3 +import com.fasterxml.jackson.databind.node.ObjectNode;
  4 +import com.huawei.m2m.cig.tup.modules.protocol_adapter.IProtocolAdapter;
  5 +import org.slf4j.Logger;
  6 +import org.slf4j.LoggerFactory;
  7 +
  8 +
  9 +public class ProtocolAdapterImpl implements IProtocolAdapter {
  10 +
  11 + private static final Logger logger = LoggerFactory.getLogger(ProtocolAdapterImpl.class);
  12 + // 厂商名称
  13 + private static final String MANU_FACTURERID = "ZTEITS";
  14 + private static final String MODEL = "ZTEITS";
  15 +
  16 + @Override
  17 + public String getManufacturerId() {
  18 + return MANU_FACTURERID;
  19 + }
  20 +
  21 + @Override
  22 + public String getModel() {
  23 + return MODEL;
  24 + }
  25 +
  26 + public void activate() {
  27 + logger.info("Codec demo HttpMessageHander activated.");
  28 + }
  29 +
  30 + public void deactivate() {
  31 + logger.info("Codec demo HttpMessageHander deactivated.");
  32 + }
  33 +
  34 + public byte[] encode(ObjectNode input) throws Exception {
  35 + logger.info("接收到平台的信息为 " + input.toString());
  36 + try {
  37 + ZteitsCmdProcess cmdProcess = new ZteitsCmdProcess(input);
  38 + byte[] byteNode = cmdProcess.toByte();
  39 + return byteNode;
  40 + } catch (Exception e) {
  41 + e.printStackTrace();
  42 + return null;
  43 + }
  44 + }
  45 +
  46 + public ObjectNode decode(byte[] binaryData) throws Exception {
  47 + try {
  48 + logger.info("接收到的报文:"+Utilty.parseByte2HexStr(binaryData));
  49 + ZteitsReportProcess zteitsReportProcess = new ZteitsReportProcess(binaryData);
  50 + ObjectNode objectNode = zteitsReportProcess.toJsonNode();
  51 + logger.info("dynamic zteitsReportProcess " + objectNode.toString());
  52 + return objectNode;
  53 + } catch (Exception e) {
  54 + e.printStackTrace();
  55 + return null;
  56 + }
  57 + }
  58 +
  59 +}
zteits-nbiot/src/main/java/com/zteits/nbiot/decoder/ZteitsReportProcess.java 0 → 100644
  1 +package com.zteits.nbiot.decoder;
  2 +
  3 +import com.fasterxml.jackson.databind.ObjectMapper;
  4 +import com.fasterxml.jackson.databind.node.ArrayNode;
  5 +import com.fasterxml.jackson.databind.node.ObjectNode;
  6 +
  7 +import java.util.Arrays;
  8 +
  9 +public class ZteitsReportProcess {
  10 +
  11 + private String factoryCode;
  12 + private String model;
  13 + private int reportType;
  14 + private int nowTime1;
  15 + private int nowTime2;
  16 + private int state;
  17 + private int packCount;
  18 + private int voltage;
  19 + private int magId;
  20 + private int magRssi;
  21 + private int x;
  22 + private int y;
  23 + private int z;
  24 + private int version;
  25 + private int parkCnt;
  26 + private int sendCnt;
  27 + private int baseX;
  28 + private int baseY;
  29 + private int baseZ;
  30 + private int alarmInfo;
  31 + private int reserverd1;
  32 + private int reserverd2;
  33 + private int reserverd3;
  34 + private int reserverd4;
  35 + private int reserverd5;
  36 + private int reserverd6;
  37 + private int crc;
  38 +
  39 + public String getFactoryCode()
  40 + {
  41 + return this.factoryCode;
  42 + }
  43 +
  44 + public void setFactoryCode(String paramString)
  45 + {
  46 + this.factoryCode = paramString;
  47 + }
  48 +
  49 + public String getModel()
  50 + {
  51 + return this.model;
  52 + }
  53 +
  54 + public void setModel(String paramString)
  55 + {
  56 + this.model = paramString;
  57 + }
  58 +
  59 + public int getReportType()
  60 + {
  61 + return this.reportType;
  62 + }
  63 +
  64 + public void setReportType(int paramInt)
  65 + {
  66 + this.reportType = paramInt;
  67 + }
  68 +
  69 + public int getNowTime1()
  70 + {
  71 + return this.nowTime1;
  72 + }
  73 +
  74 + public void setNowTime1(int paramInt)
  75 + {
  76 + this.nowTime1 = paramInt;
  77 + }
  78 +
  79 + public int getNowTime2()
  80 + {
  81 + return this.nowTime2;
  82 + }
  83 +
  84 + public void setNowTime2(int paramInt)
  85 + {
  86 + this.nowTime2 = paramInt;
  87 + }
  88 +
  89 + public int getState()
  90 + {
  91 + return this.state;
  92 + }
  93 +
  94 + public void setState(int paramInt)
  95 + {
  96 + this.state = paramInt;
  97 + }
  98 +
  99 + public int getPackCount()
  100 + {
  101 + return this.packCount;
  102 + }
  103 +
  104 + public void setPackCount(int paramInt)
  105 + {
  106 + this.packCount = paramInt;
  107 + }
  108 +
  109 + public int getVoltage()
  110 + {
  111 + return this.voltage;
  112 + }
  113 +
  114 + public void setVoltage(int paramInt)
  115 + {
  116 + this.voltage = paramInt;
  117 + }
  118 +
  119 + public int getMagId()
  120 + {
  121 + return this.magId;
  122 + }
  123 +
  124 + public void setMagId(int paramInt)
  125 + {
  126 + this.magId = paramInt;
  127 + }
  128 +
  129 + public int getMagRssi()
  130 + {
  131 + return this.magRssi;
  132 + }
  133 +
  134 + public void setMagRssi(int paramInt)
  135 + {
  136 + this.magRssi = paramInt;
  137 + }
  138 +
  139 + public int getX()
  140 + {
  141 + return this.x;
  142 + }
  143 +
  144 + public void setX(int paramInt)
  145 + {
  146 + this.x = paramInt;
  147 + }
  148 +
  149 + public int getY()
  150 + {
  151 + return this.y;
  152 + }
  153 +
  154 + public void setY(int paramInt)
  155 + {
  156 + this.y = paramInt;
  157 + }
  158 +
  159 + public int getZ()
  160 + {
  161 + return this.z;
  162 + }
  163 +
  164 + public void setZ(int paramInt)
  165 + {
  166 + this.z = paramInt;
  167 + }
  168 +
  169 + public int getVersion()
  170 + {
  171 + return this.version;
  172 + }
  173 +
  174 + public void setVersion(int paramInt)
  175 + {
  176 + this.version = paramInt;
  177 + }
  178 +
  179 + public int getParkCnt()
  180 + {
  181 + return this.parkCnt;
  182 + }
  183 +
  184 + public void setParkCnt(int paramInt)
  185 + {
  186 + this.parkCnt = paramInt;
  187 + }
  188 +
  189 + public int getSendCnt()
  190 + {
  191 + return this.sendCnt;
  192 + }
  193 +
  194 + public void setSendCnt(int paramInt)
  195 + {
  196 + this.sendCnt = paramInt;
  197 + }
  198 +
  199 + public int getBaseX()
  200 + {
  201 + return this.baseX;
  202 + }
  203 +
  204 + public void setBaseX(int paramInt)
  205 + {
  206 + this.baseX = paramInt;
  207 + }
  208 +
  209 + public int getBaseY()
  210 + {
  211 + return this.baseY;
  212 + }
  213 +
  214 + public void setBaseY(int paramInt)
  215 + {
  216 + this.baseY = paramInt;
  217 + }
  218 +
  219 + public int getBaseZ()
  220 + {
  221 + return this.baseZ;
  222 + }
  223 +
  224 + public void setBaseZ(int paramInt)
  225 + {
  226 + this.baseZ = paramInt;
  227 + }
  228 +
  229 + public int getAlarmInfo()
  230 + {
  231 + return this.alarmInfo;
  232 + }
  233 +
  234 + public void setAlarmInfo(int paramInt)
  235 + {
  236 + this.alarmInfo = paramInt;
  237 + }
  238 +
  239 + public int getReserverd1()
  240 + {
  241 + return this.reserverd1;
  242 + }
  243 +
  244 + public void setReserverd1(int paramInt)
  245 + {
  246 + this.reserverd1 = paramInt;
  247 + }
  248 +
  249 + public int getReserverd2()
  250 + {
  251 + return this.reserverd2;
  252 + }
  253 +
  254 + public void setReserverd2(int paramInt)
  255 + {
  256 + this.reserverd2 = paramInt;
  257 + }
  258 +
  259 + public int getReserverd3()
  260 + {
  261 + return this.reserverd3;
  262 + }
  263 +
  264 + public void setReserverd3(int paramInt)
  265 + {
  266 + this.reserverd3 = paramInt;
  267 + }
  268 +
  269 + public int getReserverd4()
  270 + {
  271 + return this.reserverd4;
  272 + }
  273 +
  274 + public void setReserverd4(int paramInt)
  275 + {
  276 + this.reserverd4 = paramInt;
  277 + }
  278 +
  279 + public int getReserverd5()
  280 + {
  281 + return this.reserverd5;
  282 + }
  283 +
  284 + public void setReserverd5(int paramInt)
  285 + {
  286 + this.reserverd5 = paramInt;
  287 + }
  288 +
  289 + public int getReserverd6()
  290 + {
  291 + return this.reserverd6;
  292 + }
  293 +
  294 + public void setReserverd6(int paramInt)
  295 + {
  296 + this.reserverd6 = paramInt;
  297 + }
  298 +
  299 + public int getCrc()
  300 + {
  301 + return this.crc;
  302 + }
  303 +
  304 + public void setCrc(int paramInt)
  305 + {
  306 + this.crc = paramInt;
  307 + }
  308 +
  309 + public ZteitsReportProcess(byte[] binaryData) {
  310 + this.factoryCode = Utilty.hexStringToString(binaryData, 0, 4);
  311 + this.model = Utilty.hexStringToString(binaryData,4,8);
  312 + this.reportType = Utilty.hexStringToInteger(binaryData,8,9);
  313 + this.nowTime1 = Utilty.hexStringToInteger(binaryData,9,13);
  314 + this.nowTime2 = Utilty.hexStringToInteger(binaryData,13,17);
  315 +
  316 + this.state = Utilty.hexStringToInteger(binaryData,17,18);
  317 +
  318 + this.packCount = Utilty.hexStringToInteger(binaryData,18,20);
  319 + this.voltage = Utilty.hexStringToInteger(binaryData,20,22);
  320 + this.magId = Utilty.hexStringToInteger(binaryData,22,26);
  321 + this.magRssi = Utilty.hexStringToInteger(binaryData,26,27);
  322 + this.x = Utilty.hexStringToInteger(binaryData,27,29);
  323 + this.y = Utilty.hexStringToInteger(binaryData,29,31);
  324 + this.z = Utilty.hexStringToInteger(binaryData,31,33);
  325 + this.version = Utilty.hexStringToInteger(binaryData,33,35);
  326 + this.parkCnt = Utilty.hexStringToInteger(binaryData,35,37);
  327 + this.sendCnt = Utilty.hexStringToInteger(binaryData,37,40);
  328 + this.baseX = Utilty.hexStringToInteger(binaryData,40,42);
  329 + this.baseY = Utilty.hexStringToInteger(binaryData,42,44);
  330 + this.baseZ = Utilty.hexStringToInteger(binaryData,44,46);
  331 + this.alarmInfo = Utilty.hexStringToInteger(binaryData,46,47);
  332 + this.reserverd1 = Utilty.hexStringToInteger(binaryData,47,48);
  333 + this.reserverd2 = Utilty.hexStringToInteger(binaryData,48,49);
  334 + this.reserverd3 = Utilty.hexStringToInteger(binaryData,49,50);
  335 + this.reserverd4 = Utilty.hexStringToInteger(binaryData,50,52);
  336 + this.reserverd5 = Utilty.hexStringToInteger(binaryData,52,54);
  337 + this.reserverd6 = Utilty.hexStringToInteger(binaryData,54,58);
  338 + this.crc = Utilty.hexStringToInteger(binaryData,58,60);
  339 + }
  340 +
  341 + public ObjectNode toJsonNode()
  342 + {
  343 + ObjectMapper localObjectMapper = new ObjectMapper();
  344 + ObjectNode localObjectNode1 = localObjectMapper.createObjectNode();
  345 + localObjectNode1.put("msgType", "deviceReq");
  346 +
  347 + ArrayNode localArrayNode = localObjectMapper.createArrayNode();
  348 +
  349 + ObjectNode localObjectNode2 = localObjectMapper.createObjectNode();
  350 + localObjectNode2 = localObjectMapper.createObjectNode();
  351 + localObjectNode2.put("factoryCode", getFactoryCode());
  352 + localObjectNode2.put("model", getModel());
  353 + localObjectNode2.put("reportType", getReportType());
  354 + localObjectNode2.put("reportTime1", getNowTime1());
  355 + localObjectNode2.put("reportTime", getNowTime2());
  356 + localObjectNode2.put("state", getState());
  357 + localObjectNode2.put("packCount", getPackCount());
  358 + localObjectNode2.put("voltage", getVoltage());
  359 + localObjectNode2.put("magId", getMagId());
  360 + localObjectNode2.put("deviceId", getMagId());
  361 + localObjectNode2.put("rssi", getMagRssi());
  362 + localObjectNode2.put("x", getX());
  363 + localObjectNode2.put("y", getY());
  364 + localObjectNode2.put("z", getZ());
  365 + localObjectNode2.put("version", getVersion());
  366 + localObjectNode2.put("parkCnt", getParkCnt());
  367 + localObjectNode2.put("sendCnt", getSendCnt());
  368 + localObjectNode2.put("baseX", getBaseX());
  369 + localObjectNode2.put("baseY", getBaseY());
  370 + localObjectNode2.put("baseZ", getBaseZ());
  371 + localObjectNode2.put("alarmInfo", getAlarmInfo());
  372 + localObjectNode2.put("reserverd1", getReserverd1());
  373 + localObjectNode2.put("reserverd2", getReserverd2());
  374 + localObjectNode2.put("reserverd3", getReserverd3());
  375 + localObjectNode2.put("reserverd4", getReserverd4());
  376 + localObjectNode2.put("reserverd5", getReserverd5());
  377 + localObjectNode2.put("reserverd6", getReserverd6());
  378 + localObjectNode2.put("crc", getCrc());
  379 +
  380 + ObjectNode localObjectNode3 = localObjectMapper.createObjectNode();
  381 + localObjectNode3.put("serviceId", "VehicleDetectorInfo");
  382 +
  383 + localObjectNode3.set("serviceData", localObjectNode2);
  384 +
  385 + localArrayNode.add(localObjectNode3);
  386 +
  387 + localObjectNode1.set("data", localArrayNode);
  388 +
  389 + return localObjectNode1;
  390 + }
  391 +}
0 \ No newline at end of file 392 \ No newline at end of file