/** * Send a message without waiting for response. * * @param message * the message to send * @throws ProtocolException */ protected void sendNoWait(BidibCommand message) throws ProtocolException { send(message, null, false, (Integer) null); }
/** * Send a message and wait for the unspecific result. * * @param message * the message to send * @return the received result * @throws ProtocolException */ protected BidibMessage send(BidibCommand message) throws ProtocolException { return send(message, null, true, (Integer) null); }
public void setConfig(PortModelEnum portModel, LcConfig config) throws ProtocolException { LOGGER.debug("Send LcConfigSet to node, config: {}", config); send(new LcConfigSetMessage(portModel, config), null, false, LcConfigResponse.TYPE, LcNotAvailableResponse.TYPE); }
public DriveAcknowledge releaseLoco(int address) throws ProtocolException { LOGGER.debug("Release loco, address: {}", address); DriveAcknowledge result = null; BidibMessage response = delegate.send(new CommandStationDriveMessage(address, SpeedStepsEnum.DCC128, null, DirectionEnum.BACKWARD, null, null), null, true, CommandStationDriveAcknowledgeResponse.TYPE); if (response instanceof CommandStationDriveAcknowledgeResponse) { result = ((CommandStationDriveAcknowledgeResponse) response).getState(); } return result; }
public DriveAcknowledge setDrive( int address, SpeedStepsEnum speedSteps, Integer speed, DirectionEnum direction, BitSet activeFunctions, BitSet functions) throws ProtocolException { LOGGER.debug("set drive, address: {}, speed: {}", address, speed); DriveAcknowledge result = null; BidibMessage response = delegate.send(new CommandStationDriveMessage(address, speedSteps, speed, direction, activeFunctions, functions), null, true, CommandStationDriveAcknowledgeResponse.TYPE); if (response instanceof CommandStationDriveAcknowledgeResponse) { result = ((CommandStationDriveAcknowledgeResponse) response).getState(); } return result; }
public PomAcknowledge readPom(DecoderIdAddressData locoAddress, CommandStationPom opCode, int cvNumber) throws ProtocolException { byte[] data = { 0 }; BidibMessage response = delegate.send(new CommandStationPomMessage(locoAddress, opCode, cvNumber, data), null, true, CommandStationPomAcknowledgeResponse.TYPE); PomAcknowledge result = null; if (response instanceof CommandStationPomAcknowledgeResponse) { result = ((CommandStationPomAcknowledgeResponse) response).getAcknState(); } LOGGER.debug("Return the pomAcknowledge: {}", result); return result; }
public void setMacroParameter(int macroNumber, int parameter, byte... value) throws ProtocolException { LOGGER .debug("Set macro parameter, macroNumber: {}, parameter: {}, value: {}", new Object[] { macroNumber, parameter, value }); BidibMessage response = delegate .send(new LcMacroParaSetMessage(macroNumber, parameter, value), RECEIVE_TIMEOUT, true, LcMacroParaResponse.TYPE); if (response instanceof LcMacroParaResponse) { int result = ((LcMacroParaResponse) response).getMacroNumber(); LOGGER.debug("Set macro parameter returned macronumber: {}", result); } } }
@Override public LcMacro setMacro(LcMacro macroStep) throws ProtocolException { LOGGER.info("Set the macro point: {}", macroStep); BidibMessage response = delegate.send(new LcMacroSetMessage(macroStep), RECEIVE_TIMEOUT, true, LcMacroResponse.TYPE); LcMacro result = null; if (response instanceof LcMacroResponse) { result = MacroUtils.getMacro(response.getData()); LOGGER.debug("Set macro returned: {}", result); } return result; }
public PomAcknowledge readPom(AddressData locoAddress, CommandStationPom opCode, int cvNumber) throws ProtocolException { byte[] data = { 0 }; BidibMessage response = delegate.send(new CommandStationPomMessage(locoAddress, opCode, cvNumber, data), null, true, CommandStationPomAcknowledgeResponse.TYPE); PomAcknowledge result = null; if (response instanceof CommandStationPomAcknowledgeResponse) { result = ((CommandStationPomAcknowledgeResponse) response).getAcknState(); } LOGGER.debug("Return the pomAcknowledge: {}", result); return result; }
public byte[] setAccessoryParameter(int accessoryNumber, int parameter, byte[] value) throws ProtocolException { byte[] result = null; BidibMessage response = delegate .send(new AccessoryParaSetMessage(accessoryNumber, parameter, value), RECEIVE_TIMEOUT, true, AccessoryParaResponse.TYPE); if (response instanceof AccessoryParaResponse) { result = ((AccessoryParaResponse) response).getValue(); } return result; }
/** * Send the vendor disable message to the node. * * @return the user config mode is off * @throws ProtocolException */ public boolean vendorDisable() throws ProtocolException { BidibMessage result = send(new VendorDisableMessage(), null, true, VendorAckResponse.TYPE); if (result instanceof VendorAckResponse) { return ((VendorAckResponse) result).getReturnCode() == VendorAckResponse.USER_CONFIG_MODE_OFF; } return false; }
/** * Get the number of nodes from the system. * * @return the number of nodes * @throws ProtocolException */ public Integer getNodeCount() throws ProtocolException { LOGGER.debug("Get all registered nodes from system."); BidibMessage response = send(requestFactory.createNodeTabGetAll(), null, true, NodeTabCountResponse.TYPE); if (response instanceof NodeTabCountResponse) { int totalNodes = ((NodeTabCountResponse) response).getCount(); LOGGER.debug("Found total nodes: {}", totalNodes); return totalNodes; } if (ignoreWaitTimeout) { LOGGER.warn("No response received but ignoreWaitTimeout ist set! Current node: {}", this); return Integer.valueOf(0); } throw createNoResponseAvailable("get node count"); }
/** * Send the vendor enable message to the node. * * @return the user config mode is on * @throws ProtocolException */ public boolean vendorEnable(long uniqueId) throws ProtocolException { BidibMessage result = send(new VendorEnableMessage(uniqueId), null, true, VendorAckResponse.TYPE); if (result instanceof VendorAckResponse) { return ((VendorAckResponse) result).getReturnCode() == VendorAckResponse.USER_CONFIG_MODE_ON; } return false; }
public DriveAcknowledge setBinaryState(int address, int state, boolean value) throws ProtocolException { LOGGER.info("Set binary state, address: {}, state: {}, value: {}", address, state, value); DriveAcknowledge result = null; BidibMessage response = delegate.send(new CommandStationBinaryStateMessage(address, state, value), delegate.getResponseTimeout(), true, CommandStationDriveAcknowledgeResponse.TYPE); if (response instanceof CommandStationDriveAcknowledgeResponse) { result = ((CommandStationDriveAcknowledgeResponse) response).getState(); } return result; }
/** * Get the next node from the system. * * @return the node * @throws ProtocolException */ public Node getNextNode() throws ProtocolException { BidibMessage response = send(requestFactory.createNodeTabGetNext(), null, true, NodeTabResponse.TYPE); if (response instanceof NodeTabResponse) { // create a new node from the received data LOGGER.debug("Get next tab returned: {}, own addr: {}", response, addr); // create the new Node instance Node childNode = ((NodeTabResponse) response).getNode(addr); LOGGER.debug("Fetched child node: {}", childNode); return childNode; } if (ignoreWaitTimeout) { LOGGER.warn("No response received but ignoreWaitTimeout ist set! Current node: {}", this); return null; } throw createNoResponseAvailable("get next node"); }
/** * Get a string value from the node. * * @param namespace * the namespace * @param index * the index * @return the string data instance * @throws ProtocolException */ public StringData getString(int namespace, int index) throws ProtocolException { BidibMessage response = send(new StringGetMessage(namespace, index), null, true, StringResponse.TYPE); if (response instanceof StringResponse) { return ((StringResponse) response).getStringData(); } return null; }
/** * Set a string value in the node. * * @param namespace * the namespace * @param index * the index * @return the string data instance * @throws ProtocolException */ public StringData setString(int namespace, int index, String value) throws ProtocolException { BidibMessage response = send(new StringSetMessage(namespace, index, value), null, true, StringResponse.TYPE); if (response instanceof StringResponse) { return ((StringResponse) response).getStringData(); } return null; }
/** * Get the macro step with the specified step number. * * @param macroNumber * the number of the macro * @param stepNumber * the number of the step * @return the macro step * @throws ProtocolException */ public LcMacro getMacroStep(int macroNumber, int stepNumber) throws ProtocolException { LOGGER.info("Get the macro step, macroNumber: {}, stepNumber: {}", macroNumber, stepNumber); LcMacro result = null; BidibMessage response = delegate.send(new LcMacroGetMessage(macroNumber, stepNumber), RECEIVE_TIMEOUT, true, LcMacroResponse.TYPE); if (response instanceof LcMacroResponse) { result = MacroUtils.getMacro(response.getData()); LOGGER.info("The returned macro step is: {}", result); } return result; }
/** * Get the software version from the node. * * @return the software version * @throws ProtocolException */ public SoftwareVersion getSwVersion() throws ProtocolException { BidibMessage response = send(new SysGetSwVersionMessage(), null, true, SysSwVersionResponse.TYPE); if (response instanceof SysSwVersionResponse) { return ((SysSwVersionResponse) response).getVersion(); } if (ignoreWaitTimeout) { LOGGER.warn("No response received but ignoreWaitTimeout ist set! Current node: {}", this); return null; } throw createNoResponseAvailable("get sw version"); }
public LcMacroState handleMacro(int macroNumber, LcMacroOperationCode macroOperationCode) throws ProtocolException { LOGGER.debug("handle macro, macroNumber: {}, macroOperationCode: {}", macroNumber, macroOperationCode); Integer receiveTimeout = RECEIVE_TIMEOUT; if (LcMacroOperationCode.SAVE.equals(macroOperationCode) || LcMacroOperationCode.RESTORE.equals(macroOperationCode) || LcMacroOperationCode.DELETE.equals(macroOperationCode)) { receiveTimeout = 2 * RECEIVE_TIMEOUT; } BidibMessage response = delegate .send(new LcMacroHandleMessage(macroNumber, macroOperationCode), receiveTimeout, true, LcMacroStateResponse.TYPE); LcMacroState result = null; if (response instanceof LcMacroStateResponse) { result = ((LcMacroStateResponse) response).getMacroState(); LOGGER .debug("handle macro returned: {}, response: {}", result, ((LcMacroStateResponse) response).toExtendedString()); } return result; }