123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- package com.inet.ailink.receiver.service.impl;
-
- @Service
- @Transactional(rollbackFor=Exception.class)
- public class SysDeviceInfoServiceImpl
- {
-
- @Autowired
- ISysDeviceInfoDao sysDeviceInfoDao;
-
- @Override
- protected ISysDeviceInfoDao getEntityDao() {
- return sysDeviceInfoDao;
- }
-
- public static String byteArr2HexStr(byte[] arrB) {
- int iLen = arrB.length;
- // 每个byte用两个字符才能表示,所以字符串的长度是数组长度的两倍
- StringBuffer sb = new StringBuffer(iLen * 2);
- for (int i = 0; i < iLen; i++) {
- int intTmp = arrB[i];
- // 把负数转换为正数
- while (intTmp < 0) {
- intTmp = intTmp + 256;
- }
- // 小于0F的数需要在前面补0
- if (intTmp < 16) {
- sb.append("0");
- }
- sb.append(Integer.toString(intTmp, 16).toUpperCase());
- sb.append(" ");
- }
- return sb.toString();
- }
-
- public Response<Object> register(byte[] paramsByte, HttpServletRequest request){
- // System.out.println("register(): " + byteArr2HexStr(paramsByte));
- Response<Object> result = new Response<Object>();
- //解析数据
- //设备地址
- String deviceMac = Base64TeaUitls.getStartToEndForHex(0, 5, paramsByte);
- //
- Integer cid = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(6, 7, paramsByte));
- Integer pid = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(8, 9, paramsByte));
- Integer vid = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(10, 11, paramsByte));
- //设备名
- String deviceName = Base64TeaUitls.getStartToEndForHex(12, 13, paramsByte);
- //产品型号
- String deviceType = Base64TeaUitls.getStartToEndForHex(14, 14, paramsByte);
- // //硬件版本
- // String deviceHardwareVersion = Base64TeaUitls.getStartToEndForInt(15, 15, paramsByte);
- // //软件版本
- // String deviceSoftwareVersion = Base64TeaUitls.getStartToEndForInt(16, 16, paramsByte);
- // //用户版本
- // String deviceUserAutoVersion = Base64TeaUitls.getStartToEndForInt(17, 17, paramsByte);
- // //年月日
- String deviceDate = Base64TeaUitls.getStartToEndForInt(18, 20, paramsByte);
- // System.out.println("deviceDate: " + deviceDate);
- //芯片id
- String chipId = Base64TeaUitls.getStartToEndForHex(21, 26, paramsByte);
- //设备SN [12-14]WM05+[0-5]设备地址+[21-26]芯片id
- String deviceSN = deviceName +deviceType+deviceMac+chipId;
- deviceSN = deviceSN.replaceAll(":", "");
- //设备单位
- String deviceUnit = Base64TeaUitls.getStartToEndForInt(27, 27, paramsByte);
- //如果IMEI不为空,则使用IMEI当作设备的唯一标识
- String imei = null;
- if(paramsByte.length > 28){
- //设备IMEI长度
- int imeiLength = Integer.parseInt(Base64TeaUitls.getStartToEndForInt(28, 28, paramsByte));
- if(imeiLength > 0){
- //获取imei
- imei = Base64TeaUitls.getStartToEndForASIII(28+1, 28+imeiLength, paramsByte);
- }
- }
-
- //将解析出的数据,赋值
- // Device device = new Device(deviceName, deviceMac, new Date(), cid, pid, vid, "",
- // deviceType,deviceSoftwareVersion, deviceHardwareVersion, deviceUserAutoVersion, deviceDate,chipId,deviceSN,deviceUnit);
- byte[] name = new byte[2];
- name[0] = paramsByte[12];
- name[1] = paramsByte[13];
- String moduleName = new String(name, StandardCharsets.UTF_8);
- // System.out.println("moduleName: " + moduleName);
- int type = paramsByte[14] & 0xFF;
- String moduleType = (type<10?("0"):"") + type;
- // System.out.println("moduleType: " + moduleType);
- int hardware = paramsByte[15] & 0xFF;
- String hardwareVer = "H" + hardware;
- // System.out.println("hardwareVer: " + hardwareVer);
- int software = paramsByte[16] & 0xFF;
- String softwareVer = "S" + String.valueOf(software / 10) + "." + String.valueOf(software % 10);
- // System.out.println("softwareVer: " + softwareVer);
- int custom = paramsByte[17] & 0xFF;
- String customVer = "." + String.valueOf(custom);
- // System.out.println("customVer: " + customVer);
- int year = paramsByte[18] & 0xFF;
- int month = paramsByte[19] & 0xFF;
- int day = paramsByte[20] & 0xFF;
- String dateStr = "_20" + (year<10?("0"+year):year) + (month<10?("0"+month):month) + (day<10?("0"+day):day);
- // System.out.println("dateStr: " + dateStr);
- String version = moduleName + moduleType + hardwareVer + softwareVer + customVer + dateStr;
- // System.out.println("version: " + version);
- Device device = new Device(null, deviceMac, new Date(), cid, pid, vid, "",
- null, version, null, null, null, chipId, deviceSN, deviceUnit);
- //如果IMEI不为空,则使用IMEI当作设备的唯一标识
- if(imei != null && !isEmpty(imei)){
- device.setMac(imei.replaceAll(":", ""));
- device.setDeviceSN(imei.replaceAll(":", ""));
- }
- System.out.println(JsonUtils.toJson(device));
- //注册设备
- result = saveDevice(device);
- return result;
- }
-
- }
|