use of jmri.DccLocoAddress in project JMRI by JMRI.
the class NceThrottleManager method requestThrottleSetup.
@Override
public void requestThrottleSetup(LocoAddress a, boolean control) {
// the NCE protocol doesn't require an interaction with the command
// station for this, so immediately trigger the callback.
DccLocoAddress address = (DccLocoAddress) a;
log.debug("new NceThrottle for " + address);
notifyThrottleKnown(new NceThrottle((NceSystemConnectionMemo) adapterMemo, address), address);
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class OlcbThrottleManager method requestThrottleSetup.
@Override
public void requestThrottleSetup(LocoAddress a, boolean control) {
// Immediately trigger the callback.
DccLocoAddress address = (DccLocoAddress) a;
log.debug("new debug throttle for " + address);
notifyThrottleKnown(new OlcbThrottle(address, adapterMemo, mgr), a);
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class RfidReporter method getLocoAddress.
// Methods to support PhysicalLocationReporter interface
/**
* getLocoAddress()
*
* get the locomotive address we're reporting about from the current report.
*
* Note: We ignore the string passed in, because rfid Reporters don't send
* String type reports.
*/
@Override
public LocoAddress getLocoAddress(String rep) {
// For now, we assume the current report.
// IdTag.getTagID() is a system-name-ized version of the loco address. I think.
// Matcher.group(1) : loco address (I think)
IdTag cr = (IdTag) this.getCurrentReport();
ReporterManager rm = InstanceManager.getDefault(jmri.ReporterManager.class);
Pattern p = Pattern.compile("" + rm.getSystemPrefix() + rm.typeLetter() + "(\\d+)");
Matcher m = p.matcher(cr.getTagID());
if (m.find()) {
log.debug("Parsed address: " + m.group(1));
// so we'll default to DCC for now.
return (new DccLocoAddress(Integer.parseInt(m.group(1)), LocoAddress.Protocol.DCC));
} else {
return (null);
}
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class RpsReporter method getLocoAddress.
// Methods to support PhysicalLocationReporter interface
/**
* getLocoAddress()
*
* Parses out a (possibly old) RpsReporter-generated report string to
* extract the address from the front. Assumes the RpsReporter format is
* "NNNN"
*/
public LocoAddress getLocoAddress(String rep) {
// The report is a string, that is the ID of the locomotive (I think)
log.debug("Parsed ID: " + rep);
// so we'll default to DCC for now.
if (rep.length() > 0) {
try {
int id = Integer.parseInt(rep);
int addr = Engine.instance().getTransmitter(id).getAddress();
return (new DccLocoAddress(addr, LocoAddress.Protocol.DCC));
} catch (NumberFormatException e) {
return (null);
}
} else {
return (null);
}
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class JsonThrottle method getThrottle.
/**
* Creates a new JsonThrottle or returns an existing one if the request is
* for an existing throttle.
*
* data can contain either a string {@link jmri.server.json.JSON#ID} node
* containing the ID of a {@link jmri.jmrit.roster.RosterEntry} or an
* integer {@link jmri.server.json.JSON#ADDRESS} node. If data contains an
* ADDRESS, the ID node is ignored. The ADDRESS may be accompanied by a
* boolean {@link jmri.server.json.JSON#IS_LONG_ADDRESS} node specifying the
* type of address, if IS_LONG_ADDRESS is not specified, the inverse of {@link jmri.ThrottleManager#canBeShortAddress(int)
* } is used as the "best guess" of the address length.
*
* @param throttleId The client's identity token for this throttle
* @param data JSON object containing either an ADDRESS or an ID
* @param server The server requesting this throttle on behalf of a
* client
* @return The throttle
* @throws jmri.server.json.JsonException if unable to get the requested
* {@link jmri.Throttle}
*/
public static JsonThrottle getThrottle(String throttleId, JsonNode data, JsonThrottleSocketService server) throws JsonException {
DccLocoAddress address = null;
Locale locale = server.getConnection().getLocale();
JsonThrottleManager manager = JsonThrottleManager.getDefault();
if (!data.path(ADDRESS).isMissingNode()) {
if (manager.canBeLongAddress(data.path(ADDRESS).asInt()) || manager.canBeShortAddress(data.path(ADDRESS).asInt())) {
address = new DccLocoAddress(data.path(ADDRESS).asInt(), data.path(IS_LONG_ADDRESS).asBoolean(!manager.canBeShortAddress(data.path(ADDRESS).asInt())));
} else {
log.warn("Address \"{}\" is not a valid address.", data.path(ADDRESS).asInt());
// NOI18N
throw new JsonException(HttpServletResponse.SC_BAD_REQUEST, Bundle.getMessage(locale, "ErrorThrottleInvalidAddress", data.path(ADDRESS).asInt()));
}
} else if (!data.path(ID).isMissingNode()) {
try {
address = Roster.getDefault().getEntryForId(data.path(ID).asText()).getDccLocoAddress();
} catch (NullPointerException ex) {
log.warn("Roster entry \"{}\" does not exist.", data.path(ID).asText());
// NOI18N
throw new JsonException(HttpServletResponse.SC_NOT_FOUND, Bundle.getMessage(locale, "ErrorThrottleRosterEntry", data.path(ID).asText()));
}
} else {
log.warn("No address specified");
// NOI18N
throw new JsonException(HttpServletResponse.SC_BAD_REQUEST, Bundle.getMessage(locale, "ErrorThrottleNoAddress"));
}
if (manager.containsKey(address)) {
JsonThrottle throttle = manager.get(address);
manager.put(throttle, server);
throttle.sendMessage(server.getConnection().getObjectMapper().createObjectNode().put(CLIENTS, manager.getServers(throttle).size()));
return throttle;
} else {
JsonThrottle throttle = new JsonThrottle(address, server);
if (!manager.requestThrottle(address, throttle)) {
log.error("Unable to get throttle for \"{}\".", address);
throw new JsonException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, Bundle.getMessage(server.getConnection().getLocale(), "ErrorThrottleUnableToGetThrottle", address));
}
manager.put(address, throttle);
manager.put(throttle, server);
manager.attachListener(address, throttle);
return throttle;
}
}
Aggregations