Search in sources :

Example 16 with IdTag

use of jmri.IdTag in project JMRI by JMRI.

the class DefaultIdTagManagerTest method testIdTagSingleRetrieval.

public void testIdTagSingleRetrieval() {
    DefaultIdTagManager m = getManager();
    IdTag t = m.newIdTag("ID0413276BC1", "Test Tag");
    Assert.assertNotNull("Returned IdTag is not null", t);
    Assert.assertNotNull("Get by system name is not null", m.getBySystemName("ID0413276BC1"));
    Assert.assertNotNull("Get by user name is not null", m.getByUserName("Test Tag"));
    Assert.assertNotNull("Get by tag id is not null", m.getByTagID("0413276BC1"));
    Assert.assertNotNull("Get IdTag using system name is not null", m.getIdTag("ID0413276BC1"));
    Assert.assertNotNull("Get IdTag using user name is not null", m.getIdTag("Test Tag"));
    Assert.assertNotNull("Get IdTag using tag id is not null", m.getIdTag("0413276BC1"));
    Assert.assertTrue("Matching IdTag returned from manager by system name", t.getSystemName().equals(m.getBySystemName("ID0413276BC1").getSystemName()));
    Assert.assertTrue("Matching IdTag returned from manager by user name", t.getUserName().equals(m.getByUserName("Test Tag").getUserName()));
    Assert.assertTrue("Matching IdTag returned from manager by tag id", t.getTagID().equals(m.getByTagID("0413276BC1").getTagID()));
    Assert.assertNull("Null Object returned from manager by system name", m.getBySystemName("ID99999999"));
    Assert.assertNull("Null Object returned from manager by user name", m.getBySystemName("This doesn't exist"));
    Assert.assertNull("Null Object returned from manager by tagID", m.getBySystemName("XXXXXXXXXX"));
}
Also used : IdTag(jmri.IdTag)

Example 17 with IdTag

use of jmri.IdTag in project JMRI by JMRI.

the class DefaultIdTagTest method testHasBeenSeen.

@Test
public void testHasBeenSeen() throws InterruptedException {
    IdTag r = new DefaultIdTag("ID0413276BC1");
    Reporter rep = new AbstractReporter("IR1") {

        @Override
        public int getState() {
            return state;
        }

        @Override
        public void setState(int s) {
            state = s;
        }

        int state = 0;
    };
    Date timeBefore = Calendar.getInstance().getTime();
    Thread.sleep(5);
    r.setWhereLastSeen(rep);
    Thread.sleep(5);
    Date timeAfter = Calendar.getInstance().getTime();
    Assert.assertEquals("Where last seen is 'IR1'", rep, r.getWhereLastSeen());
    Assert.assertNotNull("When last seen is not null", r.getWhenLastSeen());
    Assert.assertEquals("Status is SEEN", IdTag.SEEN, r.getState());
    Assert.assertTrue("Time when last seen is later than 'timeBefore'", r.getWhenLastSeen().after(timeBefore));
    Assert.assertTrue("Time when last seen is earlier than 'timeAfter'", r.getWhenLastSeen().before(timeAfter));
    r.setWhereLastSeen(null);
    Assert.assertNull("After setWhereLastSeen(null), Reporter where seen is null", r.getWhereLastSeen());
    Assert.assertNull("After setWhereLastSeen(null), Date when seen is null", r.getWhenLastSeen());
    Assert.assertEquals("After setWhereLastSeen(null), IdTag status is UNSEEN", IdTag.UNSEEN, r.getState());
}
Also used : Reporter(jmri.Reporter) IdTag(jmri.IdTag) Date(java.util.Date) Test(org.junit.Test)

Example 18 with IdTag

use of jmri.IdTag in project JMRI by JMRI.

the class DefaultIdTagTest method testIdTagToString.

@Test
public void testIdTagToString() {
    IdTag r = new DefaultIdTag("ID0413276BC1");
    Assert.assertEquals("IdTag toString is 0413276BC1", "0413276BC1", r.toString());
    r.setUserName("Test Tag");
    Assert.assertEquals("IdTag toString is 'Test Tag'", "Test Tag", r.toString());
}
Also used : IdTag(jmri.IdTag) Test(org.junit.Test)

Example 19 with IdTag

use of jmri.IdTag in project JMRI by JMRI.

the class AbstractRailComReporter 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 RailCom 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);
    }
}
Also used : Pattern(java.util.regex.Pattern) ReporterManager(jmri.ReporterManager) Matcher(java.util.regex.Matcher) IdTag(jmri.IdTag) DccLocoAddress(jmri.DccLocoAddress)

Example 20 with IdTag

use of jmri.IdTag in project JMRI by JMRI.

the class CbusReporter method RFIDReport.

private void RFIDReport(CanMessage l) {
    // check address
    int addr = CbusMessage.getNodeNumber(l);
    if (addr != _number) {
        log.debug("CBusReporter incorrect node number: " + addr + ", expected node number: " + _number);
        return;
    }
    String buf;
    buf = toTag(l.getElement(3), l.getElement(4), l.getElement(5), l.getElement(6), l.getElement(7));
    log.debug("Report RFID tag read of tag: " + buf);
    IdTag tag = InstanceManager.getDefault(IdTagManager.class).getIdTag(buf);
    if (tag == null) {
        log.error("Failed to find tag for RFID:" + buf);
    }
    setReport(tag);
    setState(tag != null ? IdTag.SEEN : IdTag.UNSEEN);
}
Also used : IdTagManager(jmri.IdTagManager) IdTag(jmri.IdTag)

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