@Test public void testReceivePacket_Cancel() { System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName()); int[] response = getPacket(new int[] { 0x7E, 0x01, 0x02, 0x1A, 0x03, 0x04, 0x05, 0x06, 0x07, 0x7E }); assertNotNull(response); assertEquals(5, response.length); assertEquals(0x03, response[0]); }
private int[] getPacket() throws IOException { int[] inputBuffer = new int[ASH_MAX_LENGTH]; int inputCount = 0; boolean inputError = false; while (!closeHandler) { int val = port.read(); logger.trace("ASH RX: {}", String.format("%02X", val)); switch (val) { case ASH_CANCEL_BYTE: inputCount = 0; inputError = false; break; case ASH_FLAG_BYTE: if (!inputError && inputCount != 0) { return Arrays.copyOfRange(inputBuffer, 0, inputCount); } inputCount = 0; inputError = false; break; case ASH_SUBSTITUTE_BYTE: inputError = true; break; case ASH_XON_BYTE: break; case ASH_OFF_BYTE: break; case ASH_TIMEOUT: break; default: if (inputCount >= ASH_MAX_LENGTH) { inputCount = 0; inputError = true; } inputBuffer[inputCount++] = val; break; } } return null; }
AshFrameHandler implements EzspProtocolHandler { private int[] getPacket() throws IOException { int[] inputBuffer = new int[ASH_MAX_LENGTH]; int inputCount = 0; boolean inputError = false; while (!closeHandler) { int val = port.read(); logger.trace("ASH RX: {}", String.format("%02X", val)); switch (val) { case ASH_CANCEL_BYTE: inputCount = 0; inputError = false; break; case ASH_FLAG_BYTE: if (!inputError && inputCount != 0) { return Arrays.copyOfRange(inputBuffer, 0, inputCount); } inputCount = 0; inputError = false; break; case ASH_SUBSTITUTE_BYTE: inputError = true; break; case ASH_XON_BYTE: break; case ASH_OFF_BYTE: break; case ASH_TIMEOUT: break; default: if (inputCount >= ASH_MAX_LENGTH) { inputCount = 0; inputError = true; } inputBuffer[inputCount++] = val; break; } } return null; } }
AshFrameHandler implements EzspProtocolHandler { private int[] getPacket() throws IOException { int[] inputBuffer = new int[ASH_MAX_LENGTH]; int inputCount = 0; boolean inputError = false; while (!closeHandler) { int val = port.read(); logger.trace("ASH RX: {}", String.format("%02X", val)); switch (val) { case ASH_CANCEL_BYTE: inputCount = 0; inputError = false; break; case ASH_FLAG_BYTE: if (!inputError && inputCount != 0) { return Arrays.copyOfRange(inputBuffer, 0, inputCount); } inputCount = 0; inputError = false; break; case ASH_SUBSTITUTE_BYTE: inputError = true; break; case ASH_XON_BYTE: break; case ASH_OFF_BYTE: break; case ASH_TIMEOUT: break; default: if (inputCount >= ASH_MAX_LENGTH) { inputCount = 0; inputError = true; } inputBuffer[inputCount++] = val; break; } } return null; } AshFrameHandler(final EzspFrameHandler frameHandler); }
AshFrameHandler implements EzspProtocolHandler { private int[] getPacket() throws IOException { int[] inputBuffer = new int[ASH_MAX_LENGTH]; int inputCount = 0; boolean inputError = false; while (!closeHandler) { int val = port.read(); logger.trace("ASH RX: {}", String.format("%02X", val)); switch (val) { case ASH_CANCEL_BYTE: inputCount = 0; inputError = false; break; case ASH_FLAG_BYTE: if (!inputError && inputCount != 0) { return Arrays.copyOfRange(inputBuffer, 0, inputCount); } inputCount = 0; inputError = false; break; case ASH_SUBSTITUTE_BYTE: inputError = true; break; case ASH_XON_BYTE: break; case ASH_OFF_BYTE: break; case ASH_TIMEOUT: break; default: if (inputCount >= ASH_MAX_LENGTH) { inputCount = 0; inputError = true; } inputBuffer[inputCount++] = val; break; } } return null; } AshFrameHandler(final EzspFrameHandler frameHandler); @Override void start(final ZigBeePort port); @Override void setClosing(); @Override void close(); @Override boolean isAlive(); @Override void queueFrame(EzspFrameRequest request); @Override synchronized void connect(); synchronized void reconnect(); @Override Future<EzspFrame> sendEzspRequestAsync(final EzspTransaction ezspTransaction); @Override EzspTransaction sendEzspTransaction(EzspTransaction ezspTransaction); @Override Future<EzspFrameResponse> eventWaitAsync(final Class<?> eventClass); @Override EzspFrameResponse eventWait(final Class<?> eventClass, int timeout); @Override synchronized Map<String, Long> getCounters(); }
AshFrameHandler implements EzspProtocolHandler { private int[] getPacket() throws IOException { int[] inputBuffer = new int[ASH_MAX_LENGTH]; int inputCount = 0; boolean inputError = false; while (!closeHandler) { int val = port.read(); logger.trace("ASH RX: {}", String.format("%02X", val)); switch (val) { case ASH_CANCEL_BYTE: inputCount = 0; inputError = false; break; case ASH_FLAG_BYTE: if (!inputError && inputCount != 0) { return Arrays.copyOfRange(inputBuffer, 0, inputCount); } inputCount = 0; inputError = false; break; case ASH_SUBSTITUTE_BYTE: inputError = true; break; case ASH_XON_BYTE: break; case ASH_OFF_BYTE: break; case ASH_TIMEOUT: break; default: if (inputCount >= ASH_MAX_LENGTH) { inputCount = 0; inputError = true; } inputBuffer[inputCount++] = val; break; } } return null; } AshFrameHandler(final EzspFrameHandler frameHandler); @Override void start(final ZigBeePort port); @Override void setClosing(); @Override void close(); @Override boolean isAlive(); @Override void queueFrame(EzspFrameRequest request); @Override synchronized void connect(); synchronized void reconnect(); @Override Future<EzspFrame> sendEzspRequestAsync(final EzspTransaction ezspTransaction); @Override EzspTransaction sendEzspTransaction(EzspTransaction ezspTransaction); @Override Future<EzspFrameResponse> eventWaitAsync(final Class<?> eventClass); @Override EzspFrameResponse eventWait(final Class<?> eventClass, int timeout); @Override synchronized Map<String, Long> getCounters();  }