Search in sources :

Example 26 with IdTag

use of jmri.IdTag in project JMRI by JMRI.

the class ConcentratorReporterManager method processReply.

private void processReply(ConcentratorReply r) {
    if (!tc.getAdapterMemo().getProtocol().isValid(r)) {
        log.warn("Invalid message - skipping " + r);
        return;
    }
    if (!r.isInRange()) {
        log.warn("Invalid concentrator reader range - skipping " + r);
        return;
    }
    IdTag idTag = InstanceManager.getDefault(IdTagManager.class).provideIdTag(tc.getAdapterMemo().getProtocol().getTag(r));
    TimeoutRfidReporter report = (TimeoutRfidReporter) provideReporter(prefix + typeLetter() + r.getReaderPort());
    report.notify(idTag);
}
Also used : IdTagManager(jmri.IdTagManager) TimeoutRfidReporter(jmri.jmrix.rfid.TimeoutRfidReporter) IdTag(jmri.IdTag)

Example 27 with IdTag

use of jmri.IdTag in project JMRI by JMRI.

the class DefaultIdTagManager method newIdTag.

@Override
public IdTag newIdTag(@Nonnull String systemName, @CheckForNull String userName) {
    if (!initialised && !loading) {
        init();
    }
    if (log.isDebugEnabled()) {
        log.debug("new IdTag:" + // NOI18N
        ((systemName == null) ? "null" : systemName) + ";" + // NOI18N
        ((userName == null) ? "null" : userName));
    }
    checkSystemName(systemName, userName);
    // return existing if there is one
    IdTag s;
    if ((userName != null) && ((s = getByUserName(userName)) != null)) {
        if (getBySystemName(systemName) != s) {
            log.error("inconsistent user (" + userName + ") and system name (" + systemName + ") results; userName related to (" + s.getSystemName() + ")");
        }
        return s;
    }
    if ((s = getBySystemName(systemName)) != null) {
        if ((s.getUserName() == null) && (userName != null)) {
            s.setUserName(userName);
        } else if (userName != null) {
            log.warn("Found IdTag via system name (" + systemName + ") with non-null user name (" + userName + // NOI18N
            ")");
        }
        return s;
    }
    // doesn't exist, make a new one
    s = createNewIdTag(systemName, userName);
    // save in the maps
    register(s);
    // if that failed, blame it on the input arguements
    if (s == null) {
        throw new IllegalArgumentException();
    }
    return s;
}
Also used : DefaultIdTag(jmri.implementation.DefaultIdTag) IdTag(jmri.IdTag)

Example 28 with IdTag

use of jmri.IdTag in project JMRI by JMRI.

the class DefaultIdTagManager method getIdTag.

@Override
public IdTag getIdTag(String name) {
    if (!initialised && !loading) {
        init();
    }
    IdTag t = getBySystemName(makeSystemName(name));
    if (t != null) {
        return t;
    }
    t = getByUserName(name);
    if (t != null) {
        return t;
    }
    return getBySystemName(name);
}
Also used : DefaultIdTag(jmri.implementation.DefaultIdTag) IdTag(jmri.IdTag)

Example 29 with IdTag

use of jmri.IdTag in project JMRI by JMRI.

the class DefaultRailComManager method getTagsForReporter.

@Override
public List<IdTag> getTagsForReporter(Reporter reporter, long threshold) {
    List<IdTag> out = new ArrayList<>();
    Date lastWhenLastSeen = new Date(0);
    // and record the time most recently seen
    for (NamedBean n : _tsys.values()) {
        IdTag t = (IdTag) n;
        if (t.getWhereLastSeen() == reporter) {
            out.add(t);
            if (t.getWhenLastSeen().after(lastWhenLastSeen)) {
                lastWhenLastSeen = t.getWhenLastSeen();
            }
        }
    }
    if (out.size() > 0) {
        // Calculate the threshold time based on the most recently seen tag
        Date thresholdTime = new Date(lastWhenLastSeen.getTime() - threshold);
        // Now remove from the list all tags seen prior to the threshold time
        for (IdTag t : out) {
            if (t.getWhenLastSeen().before(thresholdTime)) {
                out.remove(t);
            }
        }
    }
    return out;
}
Also used : NamedBean(jmri.NamedBean) ArrayList(java.util.ArrayList) IdTag(jmri.IdTag) Date(java.util.Date)

Aggregations

IdTag (jmri.IdTag)29 IdTagManager (jmri.IdTagManager)9 Test (org.junit.Test)6 Date (java.util.Date)3 Matcher (java.util.regex.Matcher)3 Pattern (java.util.regex.Pattern)3 DccLocoAddress (jmri.DccLocoAddress)3 DefaultIdTag (jmri.implementation.DefaultIdTag)3 ArrayList (java.util.ArrayList)2 NamedBean (jmri.NamedBean)2 ReporterManager (jmri.ReporterManager)2 TimeoutRfidReporter (jmri.jmrix.rfid.TimeoutRfidReporter)2 TimeoutRfidSensor (jmri.jmrix.rfid.TimeoutRfidSensor)2 ParseException (java.text.ParseException)1 Reporter (jmri.Reporter)1 Track (jmri.jmrit.operations.locations.Track)1 RollingStock (jmri.jmrit.operations.rollingstock.RollingStock)1