예제 #1
0
 public static Gb645MeterPacket getPacket(byte[] msg, int headIndex) {
   if (Gb645MeterPacket.getMsgHeadOffset(msg, headIndex) == headIndex) {
     Gb645MeterPacket pack = new Gb645MeterPacket("0");
     pack.address.setValue(msg, headIndex + 1);
     pack.controlCode.setValue(msg[headIndex + 8]);
     int len = BcdUtils.byteToUnsigned(msg[headIndex + 9]);
     pack.setDataBytes(msg, headIndex + 10, len);
     return pack;
   } else {
     return null;
   }
 }
예제 #2
0
  public static int getMsgHeadOffset(byte[] msg, int firstIndex) {
    int head = Gb645MeterPacket.getHeadOffset(msg, firstIndex);
    while (head != -1) {
      int len = BcdUtils.byteToUnsigned(msg[head + 9]);

      if (msg[head + len + 11] == 0x16) {
        if (Gb645MeterPacket.calcCs(msg, head, len + 10) == msg[head + len + 10]) {
          return head;
        }
      }
      firstIndex = head + 1;
      head = Gb645MeterPacket.getHeadOffset(msg, firstIndex);
    }

    return -1;
  }