@Test public void testSingleChannel() throws Exception { final Exchange ex = new DefaultExchange(ctx); final Message msg = ex.getIn(); config.resetRgbLeds(); msg.setBody("0;r;0"); processor.process(ex); Assert.assertEquals(msg.getBody(), "0x00;0;0\n"); msg.setBody("0;r;50"); processor.process(ex); Assert.assertEquals(msg.getBody(), "0x00;0;2047\n"); msg.setBody("0;r;100"); processor.process(ex); Assert.assertEquals(msg.getBody(), "0x00;0;4095\n"); }
@Override public void process(final Exchange exchange) throws Exception { final Message msg = exchange.getIn(); final StringBuffer pwmBatch = new StringBuffer(); final String[] batchLines = msg.getBody(String.class).split("\n"); final Object smoothChangeHeader = msg.getHeader(SMOOTH_SET_HEADER); boolean smoothChange = false; if (smoothChangeHeader != null) { smoothChange = Boolean.valueOf((String) smoothChangeHeader); } for (String batchLine : batchLines) { if (batchLine.trim().isEmpty()) { continue; } if (log.isDebugEnabled()) { log.debug("Batch line: " + batchLine); } final String[] parts = batchLine.split(";"); final int led = Integer.valueOf(parts[0]); final String channel = parts[1]; final int value = Integer.valueOf(parts[2]); if (log.isTraceEnabled()) { log.trace("LED #: " + led); log.trace("LED channel: " + channel); log.trace("Value: " + value); } if (led == 0xFFFF) { for (int i = 0; i < Configuration.RGB_LED_COUNT; i++) { batchAppend(pwmBatch, i, channel, value, smoothChange); } } else { batchAppend(pwmBatch, led, channel, value, smoothChange); } } msg.setBody(pwmBatch.toString()); final Object delayHeader = msg.getHeader(BATCH_DELAY_HEADER); long delay = 0; if (delayHeader != null) { delay = Long.valueOf((String) delayHeader); if (delay > 0) { msg.setHeader("batchDelay", delay); } } }
RgbLedBatchProcessor implements Processor { @Override public void process(final Exchange exchange) throws Exception { final Message msg = exchange.getIn(); final StringBuffer pwmBatch = new StringBuffer(); final String[] batchLines = msg.getBody(String.class).split("\n"); final Object smoothChangeHeader = msg.getHeader(SMOOTH_SET_HEADER); boolean smoothChange = false; if (smoothChangeHeader != null) { smoothChange = Boolean.valueOf((String) smoothChangeHeader); } for (String batchLine : batchLines) { if (batchLine.trim().isEmpty()) { continue; } if (log.isDebugEnabled()) { log.debug("Batch line: " + batchLine); } final String[] parts = batchLine.split(";"); final int led = Integer.valueOf(parts[0]); final String channel = parts[1]; final int value = Integer.valueOf(parts[2]); if (log.isTraceEnabled()) { log.trace("LED #: " + led); log.trace("LED channel: " + channel); log.trace("Value: " + value); } if (led == 0xFFFF) { for (int i = 0; i < Configuration.RGB_LED_COUNT; i++) { batchAppend(pwmBatch, i, channel, value, smoothChange); } } else { batchAppend(pwmBatch, led, channel, value, smoothChange); } } msg.setBody(pwmBatch.toString()); final Object delayHeader = msg.getHeader(BATCH_DELAY_HEADER); long delay = 0; if (delayHeader != null) { delay = Long.valueOf((String) delayHeader); if (delay > 0) { msg.setHeader("batchDelay", delay); } } } }
RgbLedBatchProcessor implements Processor { @Override public void process(final Exchange exchange) throws Exception { final Message msg = exchange.getIn(); final StringBuffer pwmBatch = new StringBuffer(); final String[] batchLines = msg.getBody(String.class).split("\n"); final Object smoothChangeHeader = msg.getHeader(SMOOTH_SET_HEADER); boolean smoothChange = false; if (smoothChangeHeader != null) { smoothChange = Boolean.valueOf((String) smoothChangeHeader); } for (String batchLine : batchLines) { if (batchLine.trim().isEmpty()) { continue; } if (log.isDebugEnabled()) { log.debug("Batch line: " + batchLine); } final String[] parts = batchLine.split(";"); final int led = Integer.valueOf(parts[0]); final String channel = parts[1]; final int value = Integer.valueOf(parts[2]); if (log.isTraceEnabled()) { log.trace("LED #: " + led); log.trace("LED channel: " + channel); log.trace("Value: " + value); } if (led == 0xFFFF) { for (int i = 0; i < Configuration.RGB_LED_COUNT; i++) { batchAppend(pwmBatch, i, channel, value, smoothChange); } } else { batchAppend(pwmBatch, led, channel, value, smoothChange); } } msg.setBody(pwmBatch.toString()); final Object delayHeader = msg.getHeader(BATCH_DELAY_HEADER); long delay = 0; if (delayHeader != null) { delay = Long.valueOf((String) delayHeader); if (delay > 0) { msg.setHeader("batchDelay", delay); } } }  }
RgbLedBatchProcessor implements Processor { @Override public void process(final Exchange exchange) throws Exception { final Message msg = exchange.getIn(); final StringBuffer pwmBatch = new StringBuffer(); final String[] batchLines = msg.getBody(String.class).split("\n"); final Object smoothChangeHeader = msg.getHeader(SMOOTH_SET_HEADER); boolean smoothChange = false; if (smoothChangeHeader != null) { smoothChange = Boolean.valueOf((String) smoothChangeHeader); } for (String batchLine : batchLines) { if (batchLine.trim().isEmpty()) { continue; } if (log.isDebugEnabled()) { log.debug("Batch line: " + batchLine); } final String[] parts = batchLine.split(";"); final int led = Integer.valueOf(parts[0]); final String channel = parts[1]; final int value = Integer.valueOf(parts[2]); if (log.isTraceEnabled()) { log.trace("LED #: " + led); log.trace("LED channel: " + channel); log.trace("Value: " + value); } if (led == 0xFFFF) { for (int i = 0; i < Configuration.RGB_LED_COUNT; i++) { batchAppend(pwmBatch, i, channel, value, smoothChange); } } else { batchAppend(pwmBatch, led, channel, value, smoothChange); } } msg.setBody(pwmBatch.toString()); final Object delayHeader = msg.getHeader(BATCH_DELAY_HEADER); long delay = 0; if (delayHeader != null) { delay = Long.valueOf((String) delayHeader); if (delay > 0) { msg.setHeader("batchDelay", delay); } } }  @Override void process(final Exchange exchange); }
RgbLedBatchProcessor implements Processor { @Override public void process(final Exchange exchange) throws Exception { final Message msg = exchange.getIn(); final StringBuffer pwmBatch = new StringBuffer(); final String[] batchLines = msg.getBody(String.class).split("\n"); final Object smoothChangeHeader = msg.getHeader(SMOOTH_SET_HEADER); boolean smoothChange = false; if (smoothChangeHeader != null) { smoothChange = Boolean.valueOf((String) smoothChangeHeader); } for (String batchLine : batchLines) { if (batchLine.trim().isEmpty()) { continue; } if (log.isDebugEnabled()) { log.debug("Batch line: " + batchLine); } final String[] parts = batchLine.split(";"); final int led = Integer.valueOf(parts[0]); final String channel = parts[1]; final int value = Integer.valueOf(parts[2]); if (log.isTraceEnabled()) { log.trace("LED #: " + led); log.trace("LED channel: " + channel); log.trace("Value: " + value); } if (led == 0xFFFF) { for (int i = 0; i < Configuration.RGB_LED_COUNT; i++) { batchAppend(pwmBatch, i, channel, value, smoothChange); } } else { batchAppend(pwmBatch, led, channel, value, smoothChange); } } msg.setBody(pwmBatch.toString()); final Object delayHeader = msg.getHeader(BATCH_DELAY_HEADER); long delay = 0; if (delayHeader != null) { delay = Long.valueOf((String) delayHeader); if (delay > 0) { msg.setHeader("batchDelay", delay); } } }  @Override void process(final Exchange exchange); static final String SMOOTH_SET_HEADER; static final String BATCH_DELAY_HEADER; }