| | |
| | | Date now = new Date(); |
| | | try { |
| | | String data = (String) dataMap.get("data"); |
| | | if(data.length() %2 != 0){//长度不是偶数,就返回 |
| | | return; |
| | | } |
| | | |
| | | Integer sum = 0; |
| | | for(int i = 0;i <= data.length() - 4;i = i + 2){ |
| | | String str = data.substring(i, i + 2); |
| | | sum = sum + Integer.parseInt(str, 16); |
| | | } |
| | | String checkNum = data.substring(data.length() - 2, data.length()); |
| | | if(!checkNum.equals(Integer.toHexString(sum).toUpperCase())){//校验不通过,就返回 |
| | | return; |
| | | } |
| | | |
| | | String lockNum = data.substring(0, 4); |
| | | String code = data.substring(4, 6); |
| | | if(code.equals("01")){//功能码01为锁实时状态 |
| | |
| | | } |
| | | |
| | | long cha = now.getTime() - sdf.parse(time).getTime(); |
| | | System.out.println("////////////////"); |
| | | /*System.out.println("////////////////"); |
| | | System.out.println(time); |
| | | System.out.println(cha); |
| | | /*if(Math.abs(cha) >= 5 * 1000){ |
| | | System.out.println(cha);*/ |
| | | if(Math.abs(cha) >= 5 * 1000){ |
| | | //时间校准 |
| | | String url = "http://" + ip + ":9999"; |
| | | /*String url = "http://" + ip + ":9999"; |
| | | String passwordMd5 = DigestUtils.md5Hex(password); |
| | | Map<String, Object> LogInResult = loginIn(url, userId, passwordMd5); |
| | | String sessionId = (String) LogInResult.get("sessionId"); |
| | | //获取时间并拆分年月日时分秒 |
| | | String nowTime = sdf.format(now); |
| | | String nowYear = nowTime.substring(2,4); |
| | | System.out.println(nowYear); |
| | | String nowMonth = nowTime.substring(5,7); |
| | | System.out.println(nowMonth); |
| | | String nowDay = nowTime.substring(8,10); |
| | | System.out.println(nowDay); |
| | | String nowHour = nowTime.substring(11,13); |
| | | System.out.println(nowHour); |
| | | String nowMinute = nowTime.substring(14,16); |
| | | System.out.println(nowMinute); |
| | | String nowSecond = nowTime.substring(17,19); |
| | | System.out.println(nowSecond); |
| | | |
| | | String nowYearHex = Integer.toHexString(Integer.parseInt(nowYear)); |
| | | if(nowYearHex.length() == 1){ |
| | | nowYearHex = "0" + nowYearHex; |
| | | } |
| | | System.out.println(nowYearHex); |
| | | String nowMonthHex = Integer.toHexString(Integer.parseInt(nowMonth)); |
| | | if(nowMonthHex.length() == 1){ |
| | | nowMonthHex = "0" + nowMonthHex; |
| | | } |
| | | System.out.println(nowMonthHex); |
| | | String nowDayHex = Integer.toHexString(Integer.parseInt(nowDay)); |
| | | if(nowDayHex.length() == 1){ |
| | | nowDayHex = "0" + nowDayHex; |
| | | } |
| | | System.out.println(nowDayHex); |
| | | String nowHourHex = Integer.toHexString(Integer.parseInt(nowHour)); |
| | | if(nowHourHex.length() == 1){ |
| | | nowHourHex = "0" + nowHourHex; |
| | | } |
| | | System.out.println(nowHourHex); |
| | | String nowMinuteHex = Integer.toHexString(Integer.parseInt(nowMinute)); |
| | | if(nowMinuteHex.length() == 1){ |
| | | nowMinuteHex = "0" + nowMinuteHex; |
| | | } |
| | | System.out.println(nowMinuteHex); |
| | | String nowSecondHex = Integer.toHexString(Integer.parseInt(nowSecond)); |
| | | if(nowSecondHex.length() == 1){ |
| | | nowSecondHex = "0" + nowSecondHex; |
| | | } |
| | | System.out.println(nowSecondHex); |
| | | //16进制时间 |
| | | String timeHex = nowYearHex + nowMonthHex + nowDayHex + nowHourHex + nowMinuteHex + nowSecondHex; |
| | | System.out.println(timeHex); |
| | | String lockNumHead = ardTankLockResult.get(0).getLockNum().substring(0,2); |
| | | String lockNumTail = ardTankLockResult.get(0).getLockNum().substring(2,4); |
| | | //计算校验 |
| | | String checkNum = Integer.toHexString(Integer.parseInt(lockNumHead, 16) + Integer.parseInt(lockNumTail, 16) + Integer.parseInt("08", 16) + |
| | | Integer.parseInt(nowYearHex, 16) + Integer.parseInt(nowMonthHex, 16) + Integer.parseInt(nowDayHex, 16) + |
| | | Integer.parseInt(nowHourHex, 16) + Integer.parseInt(nowMinuteHex, 16) + Integer.parseInt(nowSecondHex, 16)); |
| | | System.out.println(checkNum); |
| | | if(checkNum.length() == 1){ |
| | | checkNum = "0" + checkNum; |
| | | }else if(checkNum.length() > 2){ |
| | | checkNum = checkNum.substring(checkNum.length() - 2,checkNum.length()); |
| | | } |
| | | System.out.println(checkNum); |
| | | String paramsStr = "%7B%22type%22%3A%22ff%22%2C%22dataCnt%22%3A%22" + ardTankLock.getLockNum() + "08" + timeHex + checkNum + "%22%7D"; |
| | | System.out.println(ardTankLock.getLockNum() + "08" + timeHex + checkNum); |
| | | sendCmd(url,userId,ardTankLockResult.get(0).getCarId(),199,"DataDownTransfer", paramsStr,sessionId); |
| | | }else{*/ |
| | | sendCmd(url,userId,ardTankLockResult.get(0).getCarId(),199,"DataDownTransfer", paramsStr,sessionId);*/ |
| | | return; |
| | | }else{ |
| | | ArdTankLockState ardTankLockState = new ArdTankLockState(); |
| | | ardTankLockState.setId(IdUtils.simpleUUID()); |
| | | ardTankLockState.setLockId(ardTankLockResult.get(0).getId()); |
| | |
| | | case "01": ardTankLockState.setLockState("开锁状态");break; |
| | | case "02": ardTankLockState.setLockState("关锁状态");break; |
| | | case "03": ardTankLockState.setLockState("异常状态");break; |
| | | case "04": ardTankLockState.setLockState("动作状态");break; |
| | | default: |
| | | break; |
| | | } |
| | |
| | | ardTankLockState.setUploadTime(time); |
| | | ardTankLockState.setUniqueMark(uniqueMark); |
| | | ((ArdTankLockStateServiceImpl)SpringUtils.getBean("ardTankLockStateServiceImpl")).insertOrUpdateArdTankLockState(ardTankLockState); |
| | | } |
| | | }else if(code.equals("06")){//功能码06为锁历史报警 |
| | | |
| | | //} |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |