public GraphKey(int dashId, String[] bodyParts, long ts) { this.dashId = dashId; this.pinType = PinType.getPinType(bodyParts[0].charAt(0)); this.pin = NumberUtil.parsePin(bodyParts[1]); this.value = bodyParts[2]; this.ts = ts; }
@Override protected void channelRead0(ChannelHandlerContext ctx, HardwareMessage msg) { if (msg.body.charAt(1) == 'm') { return; } String[] split = msg.body.split("\0"); PinType pinType = PinType.getPinType(split[0].charAt(0)); short pin = NumberUtil.parsePin(split[1]); //String value = split[2]; switch (msg.body.charAt(1)) { case 'r' : read(ctx, pinType, pin, msg.id); break; case 'w' : //write(); break; default: break; } }
@Override public DashPinStorageKey deserializeKey(String key, DeserializationContext ctx) { //parsing "0-123-v24" //or //parsing "0-123-v24-property" String[] split = key.split(StringUtils.DEVICE_SEPARATOR_STRING); int dashId = Integer.parseInt(split[0]); int deviceId = Integer.parseInt(split[1]); PinType pinType = PinType.getPinType(split[2].charAt(0)); short pin = NumberUtil.parsePin(split[2].substring(1)); if (split.length == 4) { WidgetProperty widgetProperty = WidgetProperty.getProperty(split[3]); if (widgetProperty == null) { widgetProperty = WidgetProperty.LABEL; } return new DashPinPropertyStorageKey(dashId, deviceId, pinType, pin, widgetProperty); } else { return new DashPinStorageKey(dashId, deviceId, pinType, pin); } } }
@Override public PinStorageKey deserializeKey(String key, DeserializationContext ctx) { //parsing "123-v24" String[] split = StringUtils.split3(StringUtils.DEVICE_SEPARATOR, key); int deviceId = Integer.parseInt(split[0]); PinType pinType = PinType.getPinType(split[1].charAt(0)); short pin = 0; try { pin = NumberUtil.parsePin(split[1].substring(1)); } catch (NumberFormatException e) { //special case for outdated data format. return new PinStorageKey(deviceId, pinType, pin); } if (split.length == 3) { WidgetProperty widgetProperty = WidgetProperty.getProperty(split[2]); if (widgetProperty == null) { widgetProperty = WidgetProperty.LABEL; } return new PinPropertyStorageKey(deviceId, pinType, pin, widgetProperty); } else { return new PinStorageKey(deviceId, pinType, pin); } } }
short pin = NumberUtil.parsePin(splitBody[1]); String value = splitBody[2]; long now = System.currentTimeMillis();
private static void syncSpecificPins(ChannelHandlerContext ctx, String messageBody, int msgId, Profile profile, DashBoard dash, int deviceId) { String[] bodyParts = messageBody.split(StringUtils.BODY_SEPARATOR_STRING); if (bodyParts.length < 2 || bodyParts[0].isEmpty()) { ctx.writeAndFlush(illegalCommand(msgId), ctx.voidPromise()); return; } PinType pinType = PinType.getPinType(bodyParts[0].charAt(0)); if (StringUtils.isReadOperation(bodyParts[0])) { for (int i = 1; i < bodyParts.length; i++) { short pin = NumberUtil.parsePin(bodyParts[i]); Widget widget = dash.findWidgetByPin(deviceId, pin, pinType); if (ctx.channel().isWritable()) { if (widget == null) { PinStorageValue pinStorageValue = profile.pinsStorage.get(new DashPinStorageKey(dash.id, deviceId, pinType, pin)); if (pinStorageValue != null) { for (String value : pinStorageValue.values()) { String body = DataStream.makeHardwareBody(pinType, pin, value); ctx.write(makeUTF8StringMessage(HARDWARE, msgId, body), ctx.voidPromise()); } } } else if (widget instanceof HardwareSyncWidget) { ((HardwareSyncWidget) widget).sendHardSync(ctx, msgId, deviceId); } } } ctx.flush(); } }
pin = NumberUtil.parsePin(pinString.substring(1)); } catch (NumberFormatException | IllegalCommandBodyException e) { log.debug("Wrong pin format. {}", pinString);
short pin = NumberUtil.parsePin(splitBody[1]); String value = splitBody[2]; long now = System.currentTimeMillis();
short pin = NumberUtil.parsePin(splitBody[1]); String value = splitBody[2];
short pin = NumberUtil.parsePin(bodyParts[0]);
try { pinType = PinType.getPinType(pinString.charAt(0)); pin = NumberUtil.parsePin(pinString.substring(1)); } catch (NumberFormatException | IllegalCommandBodyException e) { log.debug("Wrong pin format. {}", pinString);
short pin = NumberUtil.parsePin(splitBody[1]); String value = splitBody[2]; long now = System.currentTimeMillis();
short pin = NumberUtil.parsePin(splitBody[1]); String value = splitBody[2]; long now = System.currentTimeMillis();
pin = NumberUtil.parsePin(pinString.substring(1)); } catch (NumberFormatException | IllegalCommandBodyException e) { log.debug("Wrong pin format. {}", pinString);
pin = NumberUtil.parsePin(pinString.substring(1)); } catch (NumberFormatException | IllegalCommandBodyException e) { log.debug("Wrong pin format. {}", pinString);
pin = NumberUtil.parsePin(pinString.substring(1)); } catch (NumberFormatException | IllegalCommandBodyException e) { log.debug("Wrong pin format. {}", pinString);