use of jmri.jmrix.rps.Engine in project JMRI by JMRI.
the class SerialAdapter method configure.
/**
* Set up all of the other objects to operate
*/
@Override
public void configure() {
// Connect the control objects:
// connect an Engine to the Distributor
Engine e = Engine.instance();
Distributor.instance().addReadingListener(e);
// start the reader
readerThread = new Thread(new Reader());
readerThread.start();
jmri.jmrix.rps.ActiveFlag.setActive();
}
use of jmri.jmrix.rps.Engine in project JMRI by JMRI.
the class RpsTrackingPanelTest method testShow.
@Test
public void testShow() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
new Engine() {
void reset() {
_instance = null;
}
}.reset();
Engine.instance().setMaxReceiverNumber(2);
Engine.instance().setReceiver(1, new Receiver(new Point3d(12., 12., 0.)));
Engine.instance().setReceiver(2, new Receiver(new Point3d(13., 13., 0.)));
JmriJFrame f = new JmriJFrame("Test Tracking Panel");
f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
RpsTrackingPanel p = new RpsTrackingPanel();
p.setSize(400, 400);
p.setOrigin(0, 0);
p.setCoordMax(30., 30.);
f.getContentPane().add(p);
f.pack();
// add some regions to probe corners
Region r = new Region("(4,4,0);(10,16,0);(18,10,0);(4,4,0)");
Model.instance().addRegion(r);
r = new Region("(30,15,0);(25,15,0);(25,20,0);(30,15,0)");
Model.instance().addRegion(r);
r = new Region("(15,30,0);(15,25,0);(20,25,0);(15,30,0)");
Model.instance().addRegion(r);
r = new Region("(25,25,0);(25,28,0);(30,30,1);(29,25,0);(25,25,0)");
Model.instance().addRegion(r);
// show overlap
r = new Region("(20,20,0);(22,20,0);(22,22,1);(20,22,0)");
Model.instance().addRegion(r);
r = new Region("(19,19,0);(21,19,0);(21,21,1);(19,21,0)");
Model.instance().addRegion(r);
// show panel
f.setSize(400, 400);
f.setVisible(true);
Reading loco = new Reading("21", null);
Measurement m = new Measurement(loco, 0.0, 0.0, 0.0, 0.133, 5, "source");
p.notify(m);
loco = new Reading("21", null);
m = new Measurement(loco, 5., 5., 0.0, 0.133, 5, "source");
p.notify(m);
loco = new Reading("21", null);
m = new Measurement(loco, 0., 5., 0.0, 0.133, 5, "source");
p.notify(m);
loco = new Reading("21", null);
m = new Measurement(loco, 5., 0., 0.0, 0.133, 5, "source");
p.notify(m);
// check separate locos
int NUM_LOCO = 64;
for (int i = 0; i < NUM_LOCO; i++) {
loco = new Reading("" + i, null);
m = new Measurement(loco, 6. + 1. * i, 0., 0.0, 0.133, 5, "source");
p.notify(m);
m = new Measurement(loco, 6. + 1. * i, 12., 0.0, 0.133, 5, "source");
p.notify(m);
}
Assert.assertNotNull("found frame", f);
f.dispose();
}
use of jmri.jmrix.rps.Engine in project JMRI by JMRI.
the class SerialAdapterTest method testStringParsing12.
@Test
public void testStringParsing12() throws java.io.IOException {
// String input = "DATA,TIME,1,2,3,4,5,6,7,8,9,10,11,12";
String input = "1,2,3,4,5,6,7,8,9,10,11,12";
new Engine() {
{
_instance = this;
setDefaultAlignment();
}
@Override
protected void setInitialAlignment() {
setDefaultAlignment();
}
};
SerialAdapter s = new SerialAdapter();
Reading r = s.makeReading(input);
Assert.assertEquals("n sample OK", 12, r.getNValues());
Assert.assertTrue("val 1", 0.001 > Math.abs(r.getValue(1) - 1.));
Assert.assertTrue("val 2", 0.001 > Math.abs(r.getValue(2) - 2.));
Assert.assertTrue("val 3", 0.001 > Math.abs(r.getValue(3) - 3.));
}
use of jmri.jmrix.rps.Engine in project JMRI by JMRI.
the class SerialAdapterTest method testStringParsing3.
@Test
public void testStringParsing3() throws java.io.IOException {
// String input = "DATA,TIME,4105,3751,1423,2835";
String input = "4105,3751,1423,2835";
new Engine() {
{
_instance = this;
setDefaultAlignment();
}
@Override
protected void setInitialAlignment() {
setDefaultAlignment();
}
};
SerialAdapter s = new SerialAdapter();
Reading r = s.makeReading(input);
Assert.assertEquals("n sample OK", 4, r.getNValues());
Assert.assertTrue("val 1", 0.001 > Math.abs(r.getValue(1) - 4105.));
Assert.assertTrue("val 2", 0.001 > Math.abs(r.getValue(2) - 3751.));
Assert.assertTrue("val 3", 0.001 > Math.abs(r.getValue(3) - 1423.));
Assert.assertTrue("val 4", 0.001 > Math.abs(r.getValue(4) - 2835.));
}
use of jmri.jmrix.rps.Engine in project JMRI by JMRI.
the class RpsTrackingFrameTest method testShow.
@Test
public void testShow() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
new Engine() {
void reset() {
_instance = null;
}
}.reset();
Engine.instance().setMaxReceiverNumber(2);
Engine.instance().setReceiver(1, new Receiver(new Point3d(12., 12., 0.)));
Engine.instance().setReceiver(2, new Receiver(new Point3d(12., 12., 0.)));
RpsTrackingFrame f = new RpsTrackingFrame("Test RPS Tracking");
f.initComponents();
f.setVisible(true);
// use local access
RpsTrackingPanel p = f.panel;
Reading loco = new Reading("21", null);
Measurement m = new Measurement(loco, 0.0, 0.0, 0.0, 0.133, 5, "source");
p.notify(m);
loco = new Reading("21", null);
m = new Measurement(loco, 5., 5., 0.0, 0.133, 5, "source");
p.notify(m);
loco = new Reading("21", null);
m = new Measurement(loco, 0., 5., 0.0, 0.133, 5, "source");
p.notify(m);
loco = new Reading("21", null);
m = new Measurement(loco, 5., 0., 0.0, 0.133, 5, "source");
p.notify(m);
Assert.assertNotNull("found frame", f);
f.dispose();
}
Aggregations