protected boolean isPortFlatModelAvailable() { Feature feature = getFeature(BidibLibrary.FEATURE_CTRL_PORT_FLAT_MODEL); if (feature != null && feature.getValue() > 0) { return true; } return false; }
public PortModelEnum getPortModel() { if (portModelEnum == null) { if (getFlatPortModelPortCount() > 0) { portModelEnum = PortModelEnum.flat; } else { portModelEnum = PortModelEnum.type; } } return portModelEnum; }
protected void processResetRequest(BidibCommand bidibMessage) { LOGGER.info("Process the reset request, bidibMessage: {}", bidibMessage); resetSendNum(); final byte[] oldNodeAddress = nodeAddress; LOGGER.info("Notify the parent that we have gone, address: {}, uniqueId: {}", getLocalAddress(), uniqueId); // notify the master that we're gone EventBus.publish(new NodeLostEvent(nodeAddress, uniqueId)); // send the node available event after 1 second availableAfterResetWorker.schedule(new Runnable() { @Override public void run() { NodeAvailableEvent nodeAvailableEvent = new NodeAvailableEvent(oldNodeAddress, uniqueId); LOGGER.info("Send NodeAvailableEvent: {}", nodeAvailableEvent); EventBus.publish(nodeAvailableEvent); LOGGER.info("Send availableAfterResetWorker has finished."); } }, 1, TimeUnit.SECONDS); }
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; }
@EventSubscriber(eventClass = AccessoryStateErrorEvent.class) public void accessoryStateError(AccessoryStateErrorEvent accessoryStateErrorEvent) { LOGGER.info("The change of the accessoryStateErrorEvent was requested: {}", accessoryStateErrorEvent); String nodeAddress = accessoryStateErrorEvent.getNodeAddr(); // check if the node is addressed if (!isAddressEqual(nodeAddress)) { LOGGER.trace("Another node is addressed."); return; } // prepare the request byte accessoryNum = 0x01; byte aspect = 0x02; byte[] value = new byte[] { 0x03, (byte) 0x81, BidibLibrary.BIDIB_ACC_STATE_ERROR_SERVO }; try { final AccessoryNotifyResponse accessoryNotifyResponse = new AccessoryNotifyResponse(getNodeAddress(), getNextSendNum(), accessoryNum, aspect, value); publishResponse(accessoryNotifyResponse.getContent()); } catch (ProtocolException ex) { LOGGER.warn("Send accessoryNotifyResponse failed.", ex); } }
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; }
foundFeature = updateFeatureValue(feature, featureValue); LOGGER.info("AutoAddFeature is activated."); foundFeature = autoAddFeature(featureNum, featureValue); new FeatureResponse(featureSetMessage.getAddr(), getNextSendNum(), featureNum, foundFeature.getValue()); response = featureResponse.getContent(); new FeatureNotAvailableResponse(bidibMessage.getAddr(), getNextSendNum(), featureNum); response = featureResponse.getContent();
@Override public byte[] getAddr() { return getNodeAddress(); } };
try { int sendMsgNum = getNextResponseSendNum(); int index = 1; while (response[index] != 0) {
LOGGER.error("The simulator with address {} is already started!", getAddress()); throw new IllegalStateException("The simulator is already started!");
@EventSubscriber(eventClass = StallEvent.class) public void stall(StallEvent stallEvent) { LOGGER.info("The change of the stall was requested: {}", stallEvent); String nodeAddress = stallEvent.getNodeAddr(); // check if the node is addressed if (!isAddressEqual(nodeAddress)) { LOGGER.trace("Another node is addressed."); return; } // prepare the request try { final StallResponse stallResponse = new StallResponse(getNodeAddress(), getNextSendNum(), (byte) (stallEvent.getStall() ? 1 : 0)) { @Override public byte[] getAddr() { return getNodeAddress(); } }; publishResponse(stallResponse.getContent()); } catch (ProtocolException ex) { LOGGER.warn("Send stallResponse failed.", ex); } }
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; }
@Override public byte[] getAddr() { return getNodeAddress(); } };
if (!isAddressEqual(nodeAddress)) { LOGGER.trace("Another node is addressed."); return; new SysIdentifyResponse(getNodeAddress(), getNextSendNum(), (byte) (identifyActive ? 1 : 0)) { @Override public byte[] getAddr() { publishResponse(stallResponse.getContent());
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; }
@Override public byte[] getAddr() { return getNodeAddress(); } };
/** * @return the number of ports in the flat model or <code>0</code> if node does not support the flat port model */ protected int getFlatPortModelPortCount() { Feature feature = getFeature(BidibLibrary.FEATURE_CTRL_PORT_FLAT_MODEL); if (feature != null) { int numPorts = feature.getValue(); return numPorts; } return 0; }
if (!isAddressEqual(nodeAddress)) { LOGGER.trace("Another node is addressed."); return; switch (sysErrorEvent.getSysError()) { case BIDIB_ERR_ADDRSTACK: byte[] nodeAddr = getNodeAddress(); if (nodeAddr.length < 4) { byte[] fullAddr = new byte[] { 0, 0, 0, 0 }; new SysErrorResponse(getNodeAddress(), getNextSendNum(), sysErrorEvent.getSysError(), reason) { @Override public byte[] getAddr() { publishResponse(sysErrorResponse.getContent());
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; }