message.setSendMsgNum(num); byte type = message.getType(); byte[] data = message.getData(); byte[] bytes = null; int index = 0; message.setAddr(addr); if (addr.length != 0 && addr[0] != 0) { bytes = new byte[1 + (addr.length + 1) + 2 + (data != null ? data.length : 0)];
protected byte[] processSysGetErrorRequest(BidibCommand bidibMessage) { LOGGER.info("Process the SysGetError request: {}", bidibMessage); byte[] response = null; try { SysErrorResponse sysErrorResponse = new SysErrorResponse(bidibMessage.getAddr(), getNextSendNum(), SysErrorEnum.BIDIB_ERR_NONE); response = sysErrorResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create sysError response failed.", ex); } return response; }
@Override public void processMessages(ByteArrayOutputStream output) { try { if (interfacePort != null) { try { List<BidibCommand> bidibMessages = requestFactory.create(output.toByteArray()); for (BidibCommand message : bidibMessages) { MSG_TX_LOGGER.info(">> {} : {}", message, ByteUtils.bytesToHex(message.getContent())); } } catch (Exception e1) { LOGGER.warn("Prepare logging outgoing messages to interface failed.", e1); } interfacePort.send(output.toByteArray()); } } catch (Exception ex) { LOGGER.warn("Send message from proxy to interface failed.", ex); } finally { output.reset(); } } };
private BidibCommand initializeCommand(BidibCommand bidibCommand) { MessageType mt = getMessageTypeMap().get(Integer.valueOf(ByteUtils.getInt(bidibCommand.getType()))); if (mt != null) { bidibCommand.setAnswerSize(mt.getAnswerSize()); } else { LOGGER.warn("Unknown command detected, cannot set answer size: {}", bidibCommand); } return bidibCommand; }
if (totalExpectedResponseLength + command.getAnswerSize() <= maxTotalExpectedResponseLength) { totalExpectedResponseLength += command.getAnswerSize(); if (message.getExpectedResponseTypes() != null) { response = receive(Arrays .asList(messagesToWaitForResponse.get(responseIndex).getExpectedResponseTypes()), null); int expectedAnswerSize = messagesToWaitForResponse.get(responseIndex).getAnswerSize();
protected byte[] prepareResponse(BidibCommand bidibMessage) { byte[] response = null; switch (ByteUtils.getInt(bidibMessage.getType())) { case BidibLibrary.MSG_SYS_GET_MAGIC: response = processSysGetMagicRequest(bidibMessage);
concreteBidibMessage.setAnswerSize(mt.getAnswerSize());
protected byte[] processFeatureGetAllRequest(BidibCommand bidibMessage) { byte[] response = null; try { FeatureCountResponse featureResponse = new FeatureCountResponse(bidibMessage.getAddr(), getNextSendNum(), features.size()); response = featureResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create feature count response failed.", ex); } currentFeature = 0; return response; }
protected byte[] processNodeTabGetAllRequest(BidibCommand bidibMessage) { byte[] response = null; try { NodeTabCountResponse nodeTabCountResponse = new NodeTabCountResponse(bidibMessage.getAddr(), getNextSendNum(), (byte) 0x01); response = nodeTabCountResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create nodeTabCount response failed.", ex); } return response; }
protected byte[] processVendorDisableRequest(BidibCommand bidibMessage) { byte[] response = null; try { // VendorDisableMessage vendorDisableMessage = (VendorDisableMessage) bidibMessage; LOGGER.info("Disable the user config mode"); byte userConfigModeActive = 0; VendorAckResponse vendorAckResponse = new VendorAckResponse(bidibMessage.getAddr(), getNextSendNum(), userConfigModeActive); response = vendorAckResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create vendor ack response failed.", ex); } return response; }
protected byte[] processSysGetSwVersionRequest(BidibCommand bidibMessage) { LOGGER.info("Process the SysGetSwVersion request: {}", bidibMessage); byte[] response = null; try { LOGGER.info("Current softwareVersion: {}", softwareVersion); SysSwVersionResponse sysSwVersionResponse = new SysSwVersionResponse(bidibMessage.getAddr(), getNextSendNum(), softwareVersion.asByteArray()); response = sysSwVersionResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create sysSwVersion response failed.", ex); } return response; }
protected byte[] processSysGetUniqueIdRequest(BidibCommand bidibMessage) { LOGGER.info("Process the SysGetUniqueId request: {}, do nothing ...", bidibMessage); byte[] response = null; try { SysUniqueIdResponse sysUniqueIdResponse = new SysUniqueIdResponse(bidibMessage.getAddr(), getNextSendNum(), getUniqueId()); response = sysUniqueIdResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create sysUniqueId response failed.", ex); } return response; }
protected byte[] processSysGetMagicRequest(BidibCommand bidibMessage) { byte[] response = null; try { LOGGER.info("Reset the sendNum because the SYS_MAGIC is tranferred with 0."); resetSendNum(); SysMagicResponse magicResponse = new SysMagicResponse(bidibMessage.getAddr(), getNextSendNum(), (byte) 0xFE, (byte) 0xAF); response = magicResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create magic response failed.", ex); } return response; }
protected byte[] processVendorGetRequest(BidibCommand bidibMessage) { byte[] response = null; try { VendorGetMessage vendorGetMessage = (VendorGetMessage) bidibMessage; String vendorDataName = vendorGetMessage.getVendorDataName(); LOGGER.info("Get the vendor data with name: {}", vendorDataName); // fetch the value from the stored data ... String vendorDataValue = configurationVariables.get(vendorDataName); if (StringUtils.isBlank(vendorDataValue)) { vendorDataValue = ""; } VendorResponse vendorResponse = new VendorResponse(bidibMessage.getAddr(), getNextSendNum(), vendorDataName, vendorDataValue); response = vendorResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create vendor response failed.", ex); } return response; }
protected byte[] processSysPingRequest(BidibCommand bidibMessage) { LOGGER.info("Process the SysPing request: {}", bidibMessage); byte[] response = null; try { SysPingMessage sysPingMessage = (SysPingMessage) bidibMessage; SysPongResponse sysPongResponse = new SysPongResponse(bidibMessage.getAddr(), getNextSendNum(), sysPingMessage.getMarker()); response = sysPongResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create sysPong response failed.", ex); } return response; }
protected byte[] processVendorEnableRequest(BidibCommand bidibMessage) { byte[] response = null; try { VendorEnableMessage vendorEnableMessage = (VendorEnableMessage) bidibMessage; long uniqueId = vendorEnableMessage.getUniqueId(); LOGGER.info("Enable the user config mode for uniqueId: {}", uniqueId); byte userConfigModeActive = 1; VendorAckResponse vendorAckResponse = new VendorAckResponse(bidibMessage.getAddr(), getNextSendNum(), userConfigModeActive); response = vendorAckResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create vendor ack response failed.", ex); } return response; }
protected byte[] processSysGetPVersionRequest(BidibCommand bidibMessage) { LOGGER.info("Process the SysGetPVersion request: {}, do nothing ...", bidibMessage); byte[] response = null; try { LOGGER.info("Current protocolVersion: {}", protocolVersion); SysPVersionResponse sysPVersionResponse = new SysPVersionResponse(bidibMessage.getAddr(), getNextSendNum(), protocolVersion.getMajorVersion(), protocolVersion.getMinorVersion()); response = sysPVersionResponse.getContent(); } catch (ProtocolException ex) { LOGGER.warn("Create sysPVersion response failed.", ex); } return response; }
LOGGER.info("Process the current bidibCommand: {}", bidibCommand); String nodeAddress = NodeUtils.formatAddress(bidibCommand.getAddr());
protected byte[] processNodeTabGetNextRequest(BidibCommand bidibMessage) { // 01.01.2014 20:35:29.917: receive NodeTabResponse[[0],num=2,type=137,data=[1, 0, 210, 0, 13, 104, 0, 0, 54]] : // 0C 00 02 89 01 00 D2 00 0D 68 00 00 36 byte[] response = null; byte nodeTabVersion = 1; byte localAddr = 0; try { NodeTabResponse nodeTabResponse = new NodeTabResponse(bidibMessage.getAddr(), getNextSendNum(), nodeTabVersion, localAddr, uniqueId); response = nodeTabResponse.getContent(); LOGGER.info("Prepared nodeTab response: {}", ByteUtils.bytesToHex(response)); } catch (ProtocolException ex) { LOGGER.warn("Create nodeTab response failed.", ex); } return response; }
try { FeatureNotAvailableResponse featureResponse = new FeatureNotAvailableResponse(bidibMessage.getAddr(), getNextSendNum(), 255); response = featureResponse.getContent(); new FeatureResponse(bidibMessage.getAddr(), getNextSendNum(), feature.getType(), feature.getValue()); response = featureResponse.getContent();