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"));
}
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());
}
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());
}
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);
}
}
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);
}
Aggregations