use of jmri.DccLocoAddress in project JMRI by JMRI.
the class Dcc4PcReporter method getLocoAddress.
// Methods to support PhysicalLocationReporter interface
/**
* getLocoAddress()
*
* Parses out a (possibly old) LnReporter-generated report string to extract
* the address from the front. Assumes the LocoReporter format is "NNNN
* [enter|exit]"
*/
@Override
public LocoAddress getLocoAddress(String rep) {
// Matcher stops at the DCC loco address.
// m.group(1) is the orientation
// m.group(2) is the loco address number
// m.group(3) is the loco address protocol postfix
Pattern ln_p = Pattern.compile("(Orient A|Orient B|Unknown state)\\s+Address\\s+(\\d+)\\((S|L|SX|MM|M4|MFX|OpenLCB|D)\\)");
Matcher m = ln_p.matcher(rep);
if (m.find()) {
log.debug("Parsed address: " + m.group(2));
// m.group(2) is always only a valid integer.
return (new DccLocoAddress(Integer.parseInt(m.group(2)), LocoAddress.Protocol.DCC));
} else {
return (null);
}
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class Z21Reporter method reply.
// the Z21 Listener interface
/**
* Member function that will be invoked by a z21Interface implementation to
* forward a z21 message from the layout.
*
* @param msg The received z21 reply. Note that this same object may be
* presented to multiple users. It should not be modified here.
*/
@Override
public void reply(Z21Reply msg) {
// LAN_RAILCOM_DATACHANGED messages.
if (msg.isRailComDataChangedMessage()) {
// find out how many RailCom Transmitters the command
// station is telling us about (there is a maximum of 19).
int tags = msg.getNumRailComDataEntries();
for (int i = 0; i < tags; i++) {
// get the locomotive address from the message.
DccLocoAddress l = msg.getRailComLocoAddress(i);
// see if there is a tag for this address.
RailCom tag = InstanceManager.getDefault(RailComManager.class).provideIdTag("" + l.getNumber());
tag.setAddressType(l.isLongAddress() ? RailCom.LONG_ADDRESS : RailCom.SHORT_ADDRESS);
tag.setActualSpeed(msg.getRailComSpeed(i));
tag.setActualTemperature(msg.getRailComTemp(i));
// set the tag report.
notify(tag);
}
}
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class JsonUtil method getConsist.
/**
* Get the JSON representation of a consist.
*
* The JSON representation is an object with the following data attributes:
* <ul>
* <li>address - integer address</li>
* <li>isLongAddress - boolean true if address is long, false if short</li>
* <li>type - integer, see {@link jmri.Consist#getConsistType() }</li>
* <li>id - string with consist Id</li>
* <li>sizeLimit - the maximum number of locomotives the consist can
* contain</li>
* <li>engines - array listing every locomotive in the consist. Each entry
* in the array contains the following attributes:
* <ul>
* <li>address - integer address</li>
* <li>isLongAddress - boolean true if address is long, false if short</li>
* <li>forward - boolean true if the locomotive running is forward in the
* consists</li>
* <li>position - integer locomotive's position in the consist</li>
* </ul>
* </ul>
*
* @param locale The locale to throw exceptions in.
* @param address The address of the consist to get.
* @return The JSON representation of the consist.
* @throws JsonException This exception has code 404 if the consist does not
* exist.
*/
public static JsonNode getConsist(Locale locale, DccLocoAddress address) throws JsonException {
try {
if (InstanceManager.getDefault(jmri.ConsistManager.class).getConsistList().contains(address)) {
ObjectNode root = mapper.createObjectNode();
root.put(TYPE, CONSIST);
ObjectNode data = root.putObject(DATA);
Consist consist = InstanceManager.getDefault(jmri.ConsistManager.class).getConsist(address);
data.put(ADDRESS, consist.getConsistAddress().getNumber());
data.put(IS_LONG_ADDRESS, consist.getConsistAddress().isLongAddress());
data.put(TYPE, consist.getConsistType());
ArrayNode engines = data.putArray(ENGINES);
for (DccLocoAddress l : consist.getConsistList()) {
ObjectNode engine = mapper.createObjectNode();
engine.put(ADDRESS, l.getNumber());
engine.put(IS_LONG_ADDRESS, l.isLongAddress());
engine.put(FORWARD, consist.getLocoDirection(l));
engine.put(POSITION, consist.getPosition(l));
engines.add(engine);
}
data.put(ID, consist.getConsistID());
data.put(SIZE_LIMIT, consist.sizeLimit());
return root;
} else {
throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", CONSIST, address.toString()));
}
} catch (NullPointerException ex) {
// NOI18N
throw new JsonException(503, Bundle.getMessage(locale, "ErrorNoConsistManager"));
}
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class ConsistToolFrame method throttleButtonActionPerformed.
public void throttleButtonActionPerformed(ActionEvent e) {
if (adrSelector.getAddress() == null) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("NoConsistSelectedError"));
return;
}
// make sure any new locomotives are added to the consist.
addLocoButtonActionPerformed(e);
// Create a throttle object with the
ThrottleFrame tf = ThrottleFrameManager.instance().createThrottleFrame();
DccLocoAddress address = adrSelector.getAddress();
/*
* get the lead locomotive from the list of locomotives so we can
* register function button bindings in the throttle.
*/
Consist tempConsist = ConsistMan.getConsist(address);
ArrayList<DccLocoAddress> addressList = tempConsist.getConsistList();
DccLocoAddress locoaddress = addressList.get(0);
if (address != locoaddress) {
if (log.isDebugEnabled()) {
log.debug("Consist Address " + address.toString() + ", Lead Locomoitve " + locoaddress.toString());
}
// the consist address and the lead locomotive address differ,
// register so the function buttons trigger the lead locomotive
tf.getAddressPanel().setCurrentAddress(locoaddress);
}
// Notify the throttle of the selected consist address
tf.getAddressPanel().setConsistAddress(address);
tf.toFront();
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class ConsistToolFrame method recallConsist.
// Recall the consist
private void recallConsist() {
if (adrSelector.getAddress() == null) {
// Clear any consist information that was present
locoSelector.reset();
locoRosterBox.setSelectedIndex(0);
if (consistModel.getConsist() != null) {
consistModel.getConsist().removeConsistListener(this);
_status.setText("Ready");
}
consistModel.setConsist((Consist) null);
canAdd();
return;
}
DccLocoAddress address = adrSelector.getAddress();
if (consistModel.getConsist() != null) {
consistModel.getConsist().removeConsistListener(this);
_status.setText("Ready");
}
Consist selectedConsist = ConsistMan.getConsist(address);
consistModel.setConsist(selectedConsist);
selectedConsist.addConsistListener(this);
// reset the editable locomotive information.
locoSelector.reset();
locoRosterBox.setSelectedIndex(0);
locoDirectionNormal.setSelected(true);
// the user change the direction
if (consistModel.getRowCount() == 0) {
locoDirectionNormal.setEnabled(false);
} else {
locoDirectionNormal.setEnabled(true);
}
if (log.isDebugEnabled()) {
log.debug("Recall Consist " + address);
}
// What type of consist is this?
if (selectedConsist.getConsistType() == Consist.ADVANCED_CONSIST) {
log.debug("Consist type is Advanced Consist ");
isAdvancedConsist.setSelected(true);
isCSConsist.setSelected(false);
_Consist_Type = Consist.ADVANCED_CONSIST;
} else {
// This must be a CS Consist.
log.debug("Consist type is Command Station Consist ");
isAdvancedConsist.setSelected(false);
isCSConsist.setSelected(true);
_Consist_Type = Consist.CS_CONSIST;
}
canAdd();
}
Aggregations