BLE_WIFI_Scale_Server_Api 服务器与wifi秤交互只需要实现3个接口:设备注册、获取用户、上传记录
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

SysDeviceInfoServiceImpl.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package com.inet.ailink.receiver.service.impl;
  2. @Service
  3. @Transactional(rollbackFor=Exception.class)
  4. public class SysDeviceInfoServiceImpl
  5. {
  6. @Autowired
  7. ISysDeviceInfoDao sysDeviceInfoDao;
  8. @Override
  9. protected ISysDeviceInfoDao getEntityDao() {
  10. return sysDeviceInfoDao;
  11. }
  12. public static String byteArr2HexStr(byte[] arrB) {
  13. int iLen = arrB.length;
  14. // 每个byte用两个字符才能表示,所以字符串的长度是数组长度的两倍
  15. StringBuffer sb = new StringBuffer(iLen * 2);
  16. for (int i = 0; i < iLen; i++) {
  17. int intTmp = arrB[i];
  18. // 把负数转换为正数
  19. while (intTmp < 0) {
  20. intTmp = intTmp + 256;
  21. }
  22. // 小于0F的数需要在前面补0
  23. if (intTmp < 16) {
  24. sb.append("0");
  25. }
  26. sb.append(Integer.toString(intTmp, 16).toUpperCase());
  27. sb.append(" ");
  28. }
  29. return sb.toString();
  30. }
  31. public Response<Object> register(byte[] paramsByte, HttpServletRequest request){
  32. // System.out.println("register(): " + byteArr2HexStr(paramsByte));
  33. Response<Object> result = new Response<Object>();
  34. //解析数据
  35. //设备地址
  36. String deviceMac = Base64TeaUitls.getStartToEndForHex(0, 5, paramsByte);
  37. //
  38. Integer cid = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(6, 7, paramsByte));
  39. Integer pid = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(8, 9, paramsByte));
  40. Integer vid = Integer.parseInt(Base64TeaUitls.getLowConactHighEndForInt(10, 11, paramsByte));
  41. //设备名
  42. String deviceName = Base64TeaUitls.getStartToEndForHex(12, 13, paramsByte);
  43. //产品型号
  44. String deviceType = Base64TeaUitls.getStartToEndForHex(14, 14, paramsByte);
  45. // //硬件版本
  46. // String deviceHardwareVersion = Base64TeaUitls.getStartToEndForInt(15, 15, paramsByte);
  47. // //软件版本
  48. // String deviceSoftwareVersion = Base64TeaUitls.getStartToEndForInt(16, 16, paramsByte);
  49. // //用户版本
  50. // String deviceUserAutoVersion = Base64TeaUitls.getStartToEndForInt(17, 17, paramsByte);
  51. // //年月日
  52. String deviceDate = Base64TeaUitls.getStartToEndForInt(18, 20, paramsByte);
  53. // System.out.println("deviceDate: " + deviceDate);
  54. //芯片id
  55. String chipId = Base64TeaUitls.getStartToEndForHex(21, 26, paramsByte);
  56. //设备SN [12-14]WM05+[0-5]设备地址+[21-26]芯片id
  57. String deviceSN = deviceName +deviceType+deviceMac+chipId;
  58. deviceSN = deviceSN.replaceAll(":", "");
  59. //设备单位
  60. String deviceUnit = Base64TeaUitls.getStartToEndForInt(27, 27, paramsByte);
  61. //如果IMEI不为空,则使用IMEI当作设备的唯一标识
  62. String imei = null;
  63. if(paramsByte.length > 28){
  64. //设备IMEI长度
  65. int imeiLength = Integer.parseInt(Base64TeaUitls.getStartToEndForInt(28, 28, paramsByte));
  66. if(imeiLength > 0){
  67. //获取imei
  68. imei = Base64TeaUitls.getStartToEndForASIII(28+1, 28+imeiLength, paramsByte);
  69. }
  70. }
  71. //将解析出的数据,赋值
  72. // Device device = new Device(deviceName, deviceMac, new Date(), cid, pid, vid, "",
  73. // deviceType,deviceSoftwareVersion, deviceHardwareVersion, deviceUserAutoVersion, deviceDate,chipId,deviceSN,deviceUnit);
  74. byte[] name = new byte[2];
  75. name[0] = paramsByte[12];
  76. name[1] = paramsByte[13];
  77. String moduleName = new String(name, StandardCharsets.UTF_8);
  78. // System.out.println("moduleName: " + moduleName);
  79. int type = paramsByte[14] & 0xFF;
  80. String moduleType = (type<10?("0"):"") + type;
  81. // System.out.println("moduleType: " + moduleType);
  82. int hardware = paramsByte[15] & 0xFF;
  83. String hardwareVer = "H" + hardware;
  84. // System.out.println("hardwareVer: " + hardwareVer);
  85. int software = paramsByte[16] & 0xFF;
  86. String softwareVer = "S" + String.valueOf(software / 10) + "." + String.valueOf(software % 10);
  87. // System.out.println("softwareVer: " + softwareVer);
  88. int custom = paramsByte[17] & 0xFF;
  89. String customVer = "." + String.valueOf(custom);
  90. // System.out.println("customVer: " + customVer);
  91. int year = paramsByte[18] & 0xFF;
  92. int month = paramsByte[19] & 0xFF;
  93. int day = paramsByte[20] & 0xFF;
  94. String dateStr = "_20" + (year<10?("0"+year):year) + (month<10?("0"+month):month) + (day<10?("0"+day):day);
  95. // System.out.println("dateStr: " + dateStr);
  96. String version = moduleName + moduleType + hardwareVer + softwareVer + customVer + dateStr;
  97. // System.out.println("version: " + version);
  98. Device device = new Device(null, deviceMac, new Date(), cid, pid, vid, "",
  99. null, version, null, null, null, chipId, deviceSN, deviceUnit);
  100. //如果IMEI不为空,则使用IMEI当作设备的唯一标识
  101. if(imei != null && !isEmpty(imei)){
  102. device.setMac(imei.replaceAll(":", ""));
  103. device.setDeviceSN(imei.replaceAll(":", ""));
  104. }
  105. System.out.println(JsonUtils.toJson(device));
  106. //注册设备
  107. result = saveDevice(device);
  108. return result;
  109. }
  110. }