use of jmri.RailCom in project JMRI by JMRI.
the class DefaultRailComTest method testHasBeenSeen.
@Test
public void testHasBeenSeen() throws InterruptedException {
RailCom r = new DefaultRailCom("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", RailCom.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), RailCom status is UNSEEN", RailCom.UNSEEN, r.getState());
}
use of jmri.RailCom in project JMRI by JMRI.
the class DefaultRailComTest method testGetRailComUserName.
@Test
public void testGetRailComUserName() {
RailCom r = new DefaultRailCom("ID1234", "Test Tag");
Assert.assertEquals("RailCom user name is 'Test Tag'", "Test Tag", r.getUserName());
}
use of jmri.RailCom in project JMRI by JMRI.
the class Dcc4PcReporter method decodeAddress.
RailCom decodeAddress() {
RailCom rcTag;
if ((address_part_1 & 0x80) == 0x80) {
addr_type = Dcc4PcSensorManager.LONG_ADDRESS;
addr = (address_part_1 & 0x3f) << 8;
addr |= address_part_2;
} else if ((address_part_1 & 0x20) == 0x20) {
addr_type = Dcc4PcSensorManager.CONSIST_ADDRESS;
addr = address_part_2;
} else {
addr_type = Dcc4PcSensorManager.SHORT_ADDRESS;
addr = address_part_2 & 0x7F;
}
if (log.isDebugEnabled()) {
log.debug(this.getDisplayName() + " Address part 2 " + addr_type + " " + addr);
log.debug(this.getDisplayName() + " Create/Get id tag for " + addr);
}
rcTag = jmri.InstanceManager.getDefault(jmri.RailComManager.class).provideIdTag("" + addr);
rcTag.setWhereLastSeen(this);
rcTag.setAddressType(addr_type);
if ((fuelLevel != -1)) {
rcTag.setFuelLevel(fuelLevel);
}
if ((waterLevel != -1)) {
rcTag.setWaterLevel(waterLevel);
}
if ((routing_no != -1)) {
rcTag.setRoutingNo(routing_no);
}
if ((location != -1)) {
rcTag.setLocation(location);
}
if ((actual_temperature != -1)) {
rcTag.setActualTemperature(actual_temperature);
}
if ((actual_load != -1)) {
rcTag.setActualLoad(actual_load);
}
if ((actual_speed != -1)) {
rcTag.setActualSpeed(actual_speed);
}
for (Integer cv : cvValues.keySet()) {
rcTag.setCv(cv, cvValues.get(cv));
if (cvvalue != -1) {
rcTag.setCvValue(cvvalue);
}
}
address_part_1 = 0;
address_part_2 = -1;
setReport(rcTag);
return rcTag;
}
use of jmri.RailCom in project JMRI by JMRI.
the class DefaultRailComManager method getIdTag.
@Override
public RailCom getIdTag(String name) {
RailCom t = getBySystemName(makeSystemName(name));
if (t != null) {
return t;
}
t = getByUserName(name);
if (t != null) {
return t;
}
return getBySystemName(name);
}
use of jmri.RailCom in project JMRI by JMRI.
the class DefaultRailComTest method testGetRailComTagID.
@Test
public void testGetRailComTagID() {
RailCom r = new DefaultRailCom("ID1234");
Assert.assertEquals("RailCom TagID is 1234", "1234", r.getTagID());
}
Aggregations