Search in sources :

Example 1 with IdTagManager

use of jmri.IdTagManager in project JMRI by JMRI.

the class EcosReporter 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 Ecos 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();
    IdTagManager tm = InstanceManager.getDefault(IdTagManager.class);
    Pattern p = Pattern.compile("" + tm.getSystemPrefix() + tm.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);
    }
}
Also used : IdTagManager(jmri.IdTagManager) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) IdTag(jmri.IdTag) DccLocoAddress(jmri.DccLocoAddress)

Aggregations

Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 DccLocoAddress (jmri.DccLocoAddress)1 IdTag (jmri.IdTag)1 IdTagManager (jmri.IdTagManager)1