use of jmri.jmrix.rps.Reading 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.Reading in project JMRI by JMRI.
the class DebuggerTest method testCtor.
@Test
public void testCtor() throws Exception {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
// create a context
Engine.instance().setMaxReceiverNumber(2);
Engine.instance().setReceiver(1, new Receiver(new Point3d(1, 2, 3)));
Engine.instance().setReceiver(2, new Receiver(new Point3d(1, 2, 3)));
Reading r = new Reading("21", new double[] { 11, 12, 13, 14 });
Measurement m = new Measurement(r, -0.5, 0.5, 0.0, 0.133, 3, "source");
// show frame
DebuggerFrame f = new DebuggerFrame();
f.initComponents();
f.setVisible(true);
// data
f.notify(r);
f.notify(m);
// close
f.dispose();
}
use of jmri.jmrix.rps.Reading in project JMRI by JMRI.
the class SerialAdapter method makeReading.
/**
* Convert input line to Reading object
*/
Reading makeReading(String s) throws IOException {
if (first) {
log.info("RPS starts, using protocol version " + version);
first = false;
}
if (version == 1) {
// parse string
java.io.StringReader b = new java.io.StringReader(s);
com.csvreader.CsvReader c = new com.csvreader.CsvReader(b);
c.readRecord();
// values are stored in 1-N of the output array; 0 not used
int count = c.getColumnCount() - SKIPCOLS;
double[] vals = new double[count + 1];
for (int i = 1; i < count + 1; i++) {
vals[i] = Double.valueOf(c.get(i + SKIPCOLS - 1)).doubleValue();
}
Reading r = new Reading(Engine.instance().getPolledID(), vals, s);
return r;
} else if (version == 2) {
// parse string
java.io.StringReader b = new java.io.StringReader(s);
com.csvreader.CsvReader c = new com.csvreader.CsvReader(b);
c.readRecord();
// skip 'ADR, DAT,'
int count = (c.getColumnCount() - 2) / 2;
// Receiver 2 goes in element 2
double[] vals = new double[Engine.instance().getMaxReceiverNumber() + 1];
for (int i = 0; i < vals.length; i++) {
vals[i] = 0.0;
}
try {
for (int i = 0; i < count; i++) {
// i is zero-based count of input pairs
// index is receiver number
int index = Integer.parseInt(c.get(2 + i * 2));
// the null message starts with index zero
if (index < 0) {
continue;
}
if (index >= vals.length) {
// data for undefined Receiver
log.warn("Data from unexpected receiver " + index + ", creating receiver");
Engine.instance().setMaxReceiverNumber(index + 1);
//
// Originally, we made vals[] longer if we got
// a response from an unexpected receiver.
// This caused terrible trouble at Kesen's layout,
// so was commented-out here.
//
//double[] temp = new double[index+1];
//for (int j = 0; j<vals.length; j++) temp[j] = vals[j];
//vals = temp;
}
if (index < vals.length) {
vals[index] = Double.valueOf(c.get(2 + i * 2 + 1)).doubleValue();
}
}
} catch (Exception e) {
log.warn("Exception handling input: " + e);
System.out.flush();
System.err.flush();
e.printStackTrace();
System.out.flush();
System.err.flush();
return null;
}
Reading r = new Reading(Engine.instance().getPolledID(), vals, s);
return r;
} else {
log.error("can't handle version " + version);
return null;
}
}
use of jmri.jmrix.rps.Reading in project JMRI by JMRI.
the class CsvExportMeasurementAction method notify.
@Override
public void notify(Measurement m) {
if (!logging || str == null) {
return;
}
// first measurement info
str.print("" + m.getID() + "," + m.getX() + "," + m.getY() + "," + m.getZ() + "," + m.getCode() + ",");
// then reading info
Reading r = m.getReading();
for (int i = 0; i < r.getNValues() - 1; i++) {
str.print(r.getValue(i) + ",");
}
str.println(r.getValue(r.getNValues() - 1));
}
use of jmri.jmrix.rps.Reading in project JMRI by JMRI.
the class RpsPositionIconTest method measButtonPushed.
// animate the visible frame
public void measButtonPushed(double x, double y, RpsPositionIcon rpsIcon) {
Reading loco = new Reading(id, null);
Measurement m = new Measurement(loco, x, y, 0.0, 0.133, 0, "source");
rpsIcon.notify(m);
}
Aggregations