예제 #1
0
 /**
  * 获取查询最新记录的命令
  *
  * @param token
  * @param num
  * @return
  */
 public static byte[] getLatestRecordCommand(int token, int num) {
   // $PCL 0x41 0x00 0x00 0x00 0x04 0x00 R_INDEX
   // checksum
   // $PCL 0x51 0x00 0x00 0x00 0x04 0x00 R_INDEX
   // checksum
   // $PCL 0x61 0x00 0x00 0x00 0x04 0x00 R_INDEX
   // checksum
   if (num <= 0) return null;
   byte[] command = {
     '$', 'P', 'C', 'L', 0x61, 0x00, 0x00, 0x00, 0x04, 0x00, 0x1, 0x0, 0x0, 0x0, 0x0
   };
   command[4] = (byte) (token + 1);
   command[10] = (byte) ((num) % 10);
   command[11] = (byte) ((num) / 10);
   command[12] = (byte) ((num) % 10);
   command[13] = (byte) ((num) / 10);
   command[14] = getCheckSum(MyArrays.copyOfRange(command, 0, command.length - 1));
   return command;
 }
예제 #2
0
 /**
  * 检验时间的校验和
  *
  * @param data
  * @return
  */
 public static boolean check(byte[] data) {
   byte checkSum = getCheckSum(MyArrays.copyOfRange(data, 0, data.length - 1));
   boolean result = checkSum == data[data.length - 1];
   Log.i(TAG, "check:" + Arrays.toString(data) + "->" + result);
   return result;
 }