DeviceUtil.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package com.wsm.common.util;
  2. public class DeviceUtil {
  3. public static String[] turnToArray(String replace) {
  4. String regex = "(.{2})";
  5. replace = replace.replaceAll(regex, "$1,");
  6. return replace.split(",");
  7. }
  8. public static String getOKFeedback(String[] str){
  9. StringBuffer startBitBuffer = new StringBuffer(str[0]).append(str[1]).append(str[2]).append(str[3]);
  10. StringBuffer okBuffer = new StringBuffer(startBitBuffer).append(ByteUtil.numToHex16(11)).append(str[6]).append("00").append(ByteUtil.strTo16("OK"));
  11. okBuffer.append(ByteUtil.makeChecksum(okBuffer.toString()));
  12. return okBuffer.toString();
  13. }
  14. public static String getErrFeedback(String[] str){
  15. StringBuffer startBitBuffer = new StringBuffer(str[0]).append(str[1]).append(str[2]).append(str[3]);
  16. StringBuffer errorBuffer = new StringBuffer(startBitBuffer).append(ByteUtil.numToHex16(13)).append(str[6]).append("00").append(ByteUtil.strTo16("ERR")).append("00");
  17. errorBuffer.append(ByteUtil.makeChecksum(errorBuffer.toString()));
  18. return errorBuffer.toString();
  19. }
  20. public static String getYGDeviceID(String[] str){
  21. return new StringBuffer(str[8]).append(str[9]).append(str[10]).append(str[11]).append(str[12]).append(str[13]).append(str[14]).append(str[15]).toString();
  22. }
  23. public static String getJGDeviceID(String[] str){
  24. return new StringBuffer(str[8]).append(str[7]).append(str[10]).append(str[9]).toString();
  25. }
  26. public static String getFeedBackJGDeviceID(String[] str){
  27. return new StringBuffer(str[7]).append(str[8]).append(str[9]).append(str[10]).toString();
  28. }
  29. }