@Test public void testSendEzspFrame() throws Exception { portOutData = new ArrayList<>(); SpiFrameHandler handler = new SpiFrameHandler(Mockito.mock(EzspFrameHandler.class)); handler.start(new TestPort(Mockito.mock(InputStream.class), Mockito.mock(OutputStream.class))); EzspVersionRequest command = new EzspVersionRequest(); command.setDesiredProtocolVersion(4); TestUtilities.setField(EzspFrame.class, command, "sequenceNumber", 1); sendEzspFrame(handler, command); assertEquals(7, portOutData.size()); assertEquals(Integer.valueOf(0xFE), portOutData.get(0)); assertEquals(Integer.valueOf(0x04), portOutData.get(1)); assertEquals(Integer.valueOf(0x01), portOutData.get(2)); assertEquals(Integer.valueOf(0x00), portOutData.get(3)); assertEquals(Integer.valueOf(0x00), portOutData.get(4)); assertEquals(Integer.valueOf(0x04), portOutData.get(5)); assertEquals(Integer.valueOf(0xA7), portOutData.get(6)); }
@Override public void start(final ZigBeePort port) { this.port = port; pollingScheduler = ZigBeeExecutors.newSingleThreadScheduledExecutor("SpiPollingExecutor"); parserThread = new Thread("SpiFrameHandler") { @Override public void run() { logger.debug("SpiFrameHandler thread started"); int exceptionCnt = 0; while (!closeHandler) { try { int[] packetData = getPacket(); if (packetData == null) { continue; } exceptionCnt = 0; processSpiCommand(packetData); sendNextFrame(); } catch (final IOException e) { logger.error("SpiFrameHandler IOException: ", e); if (exceptionCnt++ > 10) { logger.error("SpiFrameHandler exception count exceeded"); closeHandler = true; } } catch (final Exception e) { logger.error("SpiFrameHandler Exception: ", e); } } logger.debug("SpiFrameHandler exited."); } }; parserThread.setDaemon(true); parserThread.start(); restartPolling(); }
SpiFrameHandler implements EzspProtocolHandler { @Override public void start(final ZigBeePort port) { this.port = port; pollingScheduler = ZigBeeExecutors.newSingleThreadScheduledExecutor("SpiPollingExecutor"); parserThread = new Thread("SpiFrameHandler") { @Override public void run() { logger.debug("SpiFrameHandler thread started"); int exceptionCnt = 0; while (!closeHandler) { try { int[] packetData = getPacket(); if (packetData == null) { continue; } exceptionCnt = 0; processSpiCommand(packetData); sendNextFrame(); } catch (final IOException e) { logger.error("SpiFrameHandler IOException: ", e); if (exceptionCnt++ > 10) { logger.error("SpiFrameHandler exception count exceeded"); closeHandler = true; } } catch (final Exception e) { logger.error("SpiFrameHandler Exception: ", e); } } logger.debug("SpiFrameHandler exited."); } }; parserThread.setDaemon(true); parserThread.start(); restartPolling(); } }
SpiFrameHandler implements EzspProtocolHandler { @Override public void start(final ZigBeePort port) { this.port = port; pollingScheduler = ZigBeeExecutors.newSingleThreadScheduledExecutor("SpiPollingExecutor"); parserThread = new Thread("SpiFrameHandler") { @Override public void run() { logger.debug("SpiFrameHandler thread started"); int exceptionCnt = 0; while (!closeHandler) { try { int[] packetData = getPacket(); if (packetData == null) { continue; } exceptionCnt = 0; processSpiCommand(packetData); sendNextFrame(); } catch (final IOException e) { logger.error("SpiFrameHandler IOException: ", e); if (exceptionCnt++ > 10) { logger.error("SpiFrameHandler exception count exceeded"); closeHandler = true; } } catch (final Exception e) { logger.error("SpiFrameHandler Exception: ", e); } } logger.debug("SpiFrameHandler exited."); } }; parserThread.setDaemon(true); parserThread.start(); restartPolling(); } SpiFrameHandler(final EzspFrameHandler frameHandler); }
SpiFrameHandler implements EzspProtocolHandler { @Override public void start(final ZigBeePort port) { this.port = port; pollingScheduler = ZigBeeExecutors.newSingleThreadScheduledExecutor("SpiPollingExecutor"); parserThread = new Thread("SpiFrameHandler") { @Override public void run() { logger.debug("SpiFrameHandler thread started"); int exceptionCnt = 0; while (!closeHandler) { try { int[] packetData = getPacket(); if (packetData == null) { continue; } exceptionCnt = 0; processSpiCommand(packetData); sendNextFrame(); } catch (final IOException e) { logger.error("SpiFrameHandler IOException: ", e); if (exceptionCnt++ > 10) { logger.error("SpiFrameHandler exception count exceeded"); closeHandler = true; } } catch (final Exception e) { logger.error("SpiFrameHandler Exception: ", e); } } logger.debug("SpiFrameHandler exited."); } }; parserThread.setDaemon(true); parserThread.start(); restartPolling(); } 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 { @Override public void start(final ZigBeePort port) { this.port = port; pollingScheduler = ZigBeeExecutors.newSingleThreadScheduledExecutor("SpiPollingExecutor"); parserThread = new Thread("SpiFrameHandler") { @Override public void run() { logger.debug("SpiFrameHandler thread started"); int exceptionCnt = 0; while (!closeHandler) { try { int[] packetData = getPacket(); if (packetData == null) { continue; } exceptionCnt = 0; processSpiCommand(packetData); sendNextFrame(); } catch (final IOException e) { logger.error("SpiFrameHandler IOException: ", e); if (exceptionCnt++ > 10) { logger.error("SpiFrameHandler exception count exceeded"); closeHandler = true; } } catch (final Exception e) { logger.error("SpiFrameHandler Exception: ", e); } } logger.debug("SpiFrameHandler exited."); } }; parserThread.setDaemon(true); parserThread.start(); restartPolling(); } 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();  }