@Test public void testReceiveStatus() { portOutData = new ArrayList<>(); processSpiCommand(new int[] { 0x0B }, new int[] { 0xC0 }); assertEquals(2, portOutData.size()); assertEquals(Integer.valueOf(0x0B), portOutData.get(0)); assertEquals(Integer.valueOf(0xA7), portOutData.get(1)); }
private void processSpiCommand(int[] packetData) { synchronized (outputFrameSynchronisation) { if (lastFrameSent == null) { logger.debug("<-- RX SPI frame when lastFrameSent is null: {}", frameToString(packetData)); return; } } switch (packetData[0]) { case SPI_CMD_EZSP: if (lastFrameSent[0] == SPI_CMD_EZSP) { spiTransactionComplete(); } else { logger.debug("<-- RX SPI frame type mismatch SPI_CMD_EZSP != {}", String.format("%02X", lastFrameSent[0])); } int[] ezspPacketData = Arrays.copyOfRange(packetData, 2, packetData.length); String logMessage = String.format("<-- RX SPI frame: %s", frameToString(packetData)); if (isEzspNoCallbacksResponse(ezspPacketData)) { logger.trace(logMessage); } else { logger.debug(logMessage); } processSpiEzsp(ezspPacketData); break; case SPI_CMD_BOOTLOADER: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); if (lastFrameSent[0] == SPI_CMD_BOOTLOADER) { spiTransactionComplete(); } else { logger.debug("<-- RX SPI frame type mismatch SPI_CMD_BOOTLOADER != {}", String.format("%02X", lastFrameSent[0])); } break; case SPI_CMD_RESET: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); logger.debug("SPI frame: {}", errorMessages.get(packetData[0])); connect(); break; case SPI_CMD_OVERSIZE: case SPI_CMD_ABORT: case SPI_CMD_MISSINGTERMINATOR: case SPI_CMD_UNSUPPORTEDCMD: case SPI_CMD_INVALID: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); logger.debug("SPI frame: {}", errorMessages.get(packetData[0])); spiErrors++; break; default: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); switch (lastFrameSent[0]) { case SPI_CMD_SPIVERSION: if ((packetData[0] & SPI_MASK) != SPI_MASK_VERSION) { break; } spiTransactionComplete(); logger.debug("SPI Protocol Version: {}", packetData[0] & SPI_MASK_VERSIONDATA); outputFrame(requestSpiStatus); break; case SPI_CMD_SPISTATUS: if ((packetData[0] & SPI_MASK) != SPI_MASK_STATUS) { break; } spiTransactionComplete(); stateConnected = (packetData[0] & SPI_MASK_READY) == SPI_MASK_READY; logger.debug("SPI Protocol Ready: {}", stateConnected); if (!stateConnected) { outputFrame(requestSpiStatus); } break; default: logger.error("Unknown last frame ID {} in SPI command processor", String.format("%02X", lastFrameSent[0])); } break; } }
SpiFrameHandler implements EzspProtocolHandler { private void processSpiCommand(int[] packetData) { synchronized (outputFrameSynchronisation) { if (lastFrameSent == null) { logger.debug("<-- RX SPI frame when lastFrameSent is null: {}", frameToString(packetData)); return; } } switch (packetData[0]) { case SPI_CMD_EZSP: if (lastFrameSent[0] == SPI_CMD_EZSP) { spiTransactionComplete(); } else { logger.debug("<-- RX SPI frame type mismatch SPI_CMD_EZSP != {}", String.format("%02X", lastFrameSent[0])); } int[] ezspPacketData = Arrays.copyOfRange(packetData, 2, packetData.length); String logMessage = String.format("<-- RX SPI frame: %s", frameToString(packetData)); if (isEzspNoCallbacksResponse(ezspPacketData)) { logger.trace(logMessage); } else { logger.debug(logMessage); } processSpiEzsp(ezspPacketData); break; case SPI_CMD_BOOTLOADER: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); if (lastFrameSent[0] == SPI_CMD_BOOTLOADER) { spiTransactionComplete(); } else { logger.debug("<-- RX SPI frame type mismatch SPI_CMD_BOOTLOADER != {}", String.format("%02X", lastFrameSent[0])); } break; case SPI_CMD_RESET: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); logger.debug("SPI frame: {}", errorMessages.get(packetData[0])); connect(); break; case SPI_CMD_OVERSIZE: case SPI_CMD_ABORT: case SPI_CMD_MISSINGTERMINATOR: case SPI_CMD_UNSUPPORTEDCMD: case SPI_CMD_INVALID: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); logger.debug("SPI frame: {}", errorMessages.get(packetData[0])); spiErrors++; break; default: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); switch (lastFrameSent[0]) { case SPI_CMD_SPIVERSION: if ((packetData[0] & SPI_MASK) != SPI_MASK_VERSION) { break; } spiTransactionComplete(); logger.debug("SPI Protocol Version: {}", packetData[0] & SPI_MASK_VERSIONDATA); outputFrame(requestSpiStatus); break; case SPI_CMD_SPISTATUS: if ((packetData[0] & SPI_MASK) != SPI_MASK_STATUS) { break; } spiTransactionComplete(); stateConnected = (packetData[0] & SPI_MASK_READY) == SPI_MASK_READY; logger.debug("SPI Protocol Ready: {}", stateConnected); if (!stateConnected) { outputFrame(requestSpiStatus); } break; default: logger.error("Unknown last frame ID {} in SPI command processor", String.format("%02X", lastFrameSent[0])); } break; } } }
SpiFrameHandler implements EzspProtocolHandler { private void processSpiCommand(int[] packetData) { synchronized (outputFrameSynchronisation) { if (lastFrameSent == null) { logger.debug("<-- RX SPI frame when lastFrameSent is null: {}", frameToString(packetData)); return; } } switch (packetData[0]) { case SPI_CMD_EZSP: if (lastFrameSent[0] == SPI_CMD_EZSP) { spiTransactionComplete(); } else { logger.debug("<-- RX SPI frame type mismatch SPI_CMD_EZSP != {}", String.format("%02X", lastFrameSent[0])); } int[] ezspPacketData = Arrays.copyOfRange(packetData, 2, packetData.length); String logMessage = String.format("<-- RX SPI frame: %s", frameToString(packetData)); if (isEzspNoCallbacksResponse(ezspPacketData)) { logger.trace(logMessage); } else { logger.debug(logMessage); } processSpiEzsp(ezspPacketData); break; case SPI_CMD_BOOTLOADER: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); if (lastFrameSent[0] == SPI_CMD_BOOTLOADER) { spiTransactionComplete(); } else { logger.debug("<-- RX SPI frame type mismatch SPI_CMD_BOOTLOADER != {}", String.format("%02X", lastFrameSent[0])); } break; case SPI_CMD_RESET: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); logger.debug("SPI frame: {}", errorMessages.get(packetData[0])); connect(); break; case SPI_CMD_OVERSIZE: case SPI_CMD_ABORT: case SPI_CMD_MISSINGTERMINATOR: case SPI_CMD_UNSUPPORTEDCMD: case SPI_CMD_INVALID: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); logger.debug("SPI frame: {}", errorMessages.get(packetData[0])); spiErrors++; break; default: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); switch (lastFrameSent[0]) { case SPI_CMD_SPIVERSION: if ((packetData[0] & SPI_MASK) != SPI_MASK_VERSION) { break; } spiTransactionComplete(); logger.debug("SPI Protocol Version: {}", packetData[0] & SPI_MASK_VERSIONDATA); outputFrame(requestSpiStatus); break; case SPI_CMD_SPISTATUS: if ((packetData[0] & SPI_MASK) != SPI_MASK_STATUS) { break; } spiTransactionComplete(); stateConnected = (packetData[0] & SPI_MASK_READY) == SPI_MASK_READY; logger.debug("SPI Protocol Ready: {}", stateConnected); if (!stateConnected) { outputFrame(requestSpiStatus); } break; default: logger.error("Unknown last frame ID {} in SPI command processor", String.format("%02X", lastFrameSent[0])); } break; } } SpiFrameHandler(final EzspFrameHandler frameHandler); }
SpiFrameHandler implements EzspProtocolHandler { private void processSpiCommand(int[] packetData) { synchronized (outputFrameSynchronisation) { if (lastFrameSent == null) { logger.debug("<-- RX SPI frame when lastFrameSent is null: {}", frameToString(packetData)); return; } } switch (packetData[0]) { case SPI_CMD_EZSP: if (lastFrameSent[0] == SPI_CMD_EZSP) { spiTransactionComplete(); } else { logger.debug("<-- RX SPI frame type mismatch SPI_CMD_EZSP != {}", String.format("%02X", lastFrameSent[0])); } int[] ezspPacketData = Arrays.copyOfRange(packetData, 2, packetData.length); String logMessage = String.format("<-- RX SPI frame: %s", frameToString(packetData)); if (isEzspNoCallbacksResponse(ezspPacketData)) { logger.trace(logMessage); } else { logger.debug(logMessage); } processSpiEzsp(ezspPacketData); break; case SPI_CMD_BOOTLOADER: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); if (lastFrameSent[0] == SPI_CMD_BOOTLOADER) { spiTransactionComplete(); } else { logger.debug("<-- RX SPI frame type mismatch SPI_CMD_BOOTLOADER != {}", String.format("%02X", lastFrameSent[0])); } break; case SPI_CMD_RESET: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); logger.debug("SPI frame: {}", errorMessages.get(packetData[0])); connect(); break; case SPI_CMD_OVERSIZE: case SPI_CMD_ABORT: case SPI_CMD_MISSINGTERMINATOR: case SPI_CMD_UNSUPPORTEDCMD: case SPI_CMD_INVALID: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); logger.debug("SPI frame: {}", errorMessages.get(packetData[0])); spiErrors++; break; default: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); switch (lastFrameSent[0]) { case SPI_CMD_SPIVERSION: if ((packetData[0] & SPI_MASK) != SPI_MASK_VERSION) { break; } spiTransactionComplete(); logger.debug("SPI Protocol Version: {}", packetData[0] & SPI_MASK_VERSIONDATA); outputFrame(requestSpiStatus); break; case SPI_CMD_SPISTATUS: if ((packetData[0] & SPI_MASK) != SPI_MASK_STATUS) { break; } spiTransactionComplete(); stateConnected = (packetData[0] & SPI_MASK_READY) == SPI_MASK_READY; logger.debug("SPI Protocol Ready: {}", stateConnected); if (!stateConnected) { outputFrame(requestSpiStatus); } break; default: logger.error("Unknown last frame ID {} in SPI command processor", String.format("%02X", lastFrameSent[0])); } break; } } SpiFrameHandler(final EzspFrameHandler frameHandler); void setPollRate(int pollRate); @Override void start(final ZigBeePort port); @Override void setClosing(); @Override void close(); @Override boolean isAlive(); @Override void queueFrame(EzspFrameRequest request); @Override void connect(); @Override Future<EzspFrame> sendEzspRequestAsync(final EzspTransaction ezspTransaction); @Override EzspTransaction sendEzspTransaction(EzspTransaction ezspTransaction); int getSpiErrors(); @Override Future<EzspFrameResponse> eventWaitAsync(final Class<?> eventClass); @Override EzspFrameResponse eventWait(final Class<?> eventClass, int timeout); @Override Map<String, Long> getCounters(); }
SpiFrameHandler implements EzspProtocolHandler { private void processSpiCommand(int[] packetData) { synchronized (outputFrameSynchronisation) { if (lastFrameSent == null) { logger.debug("<-- RX SPI frame when lastFrameSent is null: {}", frameToString(packetData)); return; } } switch (packetData[0]) { case SPI_CMD_EZSP: if (lastFrameSent[0] == SPI_CMD_EZSP) { spiTransactionComplete(); } else { logger.debug("<-- RX SPI frame type mismatch SPI_CMD_EZSP != {}", String.format("%02X", lastFrameSent[0])); } int[] ezspPacketData = Arrays.copyOfRange(packetData, 2, packetData.length); String logMessage = String.format("<-- RX SPI frame: %s", frameToString(packetData)); if (isEzspNoCallbacksResponse(ezspPacketData)) { logger.trace(logMessage); } else { logger.debug(logMessage); } processSpiEzsp(ezspPacketData); break; case SPI_CMD_BOOTLOADER: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); if (lastFrameSent[0] == SPI_CMD_BOOTLOADER) { spiTransactionComplete(); } else { logger.debug("<-- RX SPI frame type mismatch SPI_CMD_BOOTLOADER != {}", String.format("%02X", lastFrameSent[0])); } break; case SPI_CMD_RESET: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); logger.debug("SPI frame: {}", errorMessages.get(packetData[0])); connect(); break; case SPI_CMD_OVERSIZE: case SPI_CMD_ABORT: case SPI_CMD_MISSINGTERMINATOR: case SPI_CMD_UNSUPPORTEDCMD: case SPI_CMD_INVALID: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); logger.debug("SPI frame: {}", errorMessages.get(packetData[0])); spiErrors++; break; default: logger.debug("<-- RX SPI frame: {}", frameToString(packetData)); switch (lastFrameSent[0]) { case SPI_CMD_SPIVERSION: if ((packetData[0] & SPI_MASK) != SPI_MASK_VERSION) { break; } spiTransactionComplete(); logger.debug("SPI Protocol Version: {}", packetData[0] & SPI_MASK_VERSIONDATA); outputFrame(requestSpiStatus); break; case SPI_CMD_SPISTATUS: if ((packetData[0] & SPI_MASK) != SPI_MASK_STATUS) { break; } spiTransactionComplete(); stateConnected = (packetData[0] & SPI_MASK_READY) == SPI_MASK_READY; logger.debug("SPI Protocol Ready: {}", stateConnected); if (!stateConnected) { outputFrame(requestSpiStatus); } break; default: logger.error("Unknown last frame ID {} in SPI command processor", String.format("%02X", lastFrameSent[0])); } break; } } SpiFrameHandler(final EzspFrameHandler frameHandler); void setPollRate(int pollRate); @Override void start(final ZigBeePort port); @Override void setClosing(); @Override void close(); @Override boolean isAlive(); @Override void queueFrame(EzspFrameRequest request); @Override void connect(); @Override Future<EzspFrame> sendEzspRequestAsync(final EzspTransaction ezspTransaction); @Override EzspTransaction sendEzspTransaction(EzspTransaction ezspTransaction); int getSpiErrors(); @Override Future<EzspFrameResponse> eventWaitAsync(final Class<?> eventClass); @Override EzspFrameResponse eventWait(final Class<?> eventClass, int timeout); @Override Map<String, Long> getCounters();  }