use of jmri.ReporterManager 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.ReporterManager in project JMRI by JMRI.
the class ManageLocationsFrame method saveTableValues.
@SuppressFBWarnings(value = "WMI_WRONG_MAP_ITERATOR", justification = "only in slow debug")
private void saveTableValues() {
if ((Boolean) locModel.getValueAt(0, 1)) {
listenerLoc.setLocation((Double) locModel.getValueAt(0, 2), (Double) locModel.getValueAt(0, 3), (Double) locModel.getValueAt(0, 4));
listenerLoc.setOrientation((Double) locModel.getValueAt(0, 5), (Double) locModel.getValueAt(0, 6));
VSDecoderManager.instance().getVSDecoderPreferences().setListenerPosition(listenerLoc);
}
HashMap<String, PhysicalLocation> data = reporterModel.getDataMap();
ReporterManager mgr = jmri.InstanceManager.getDefault(jmri.ReporterManager.class);
for (String s : data.keySet()) {
log.debug("Reporter: " + s + " Location: " + data.get(s));
Reporter r = mgr.getByDisplayName(s);
PhysicalLocation.setBeanPhysicalLocation(data.get(s), r);
}
data = blockModel.getDataMap();
BlockManager bmgr = jmri.InstanceManager.getDefault(jmri.BlockManager.class);
for (String s : data.keySet()) {
log.debug("Block: " + s + " Location: " + data.get(s));
Block b = bmgr.getByDisplayName(s);
PhysicalLocation.setBeanPhysicalLocation(data.get(s), b);
}
data = opsModel.getDataMap();
LocationManager lmgr = LocationManager.instance();
for (String s : data.keySet()) {
log.debug("OpsLocation: " + s + " Location: " + data.get(s));
Location l = lmgr.getLocationByName(s);
l.setPhysicalLocation(data.get(s));
}
}
use of jmri.ReporterManager in project JMRI by JMRI.
the class RfidReporter 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 rfid 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.ReporterManager in project JMRI by JMRI.
the class AbstractReporterManagerConfigXML method store.
/**
* Default implementation for storing the contents of a ReporterManager
*
* @param o Object to store, of type ReporterManager
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
Element reporters = new Element("reporters");
setStoreElementClass(reporters);
ReporterManager tm = (ReporterManager) o;
if (tm != null) {
java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
// don't return an element if there are not reporters to include
if (!iter.hasNext()) {
return null;
}
// store the reporters
while (iter.hasNext()) {
String sname = iter.next();
if (sname == null) {
log.error("System name null during store");
break;
}
log.debug("system name is " + sname);
Reporter r = tm.getBySystemName(sname);
Element elem = new Element("reporter");
elem.addContent(new Element("systemName").addContent(sname));
// store common parts
storeCommon(r, elem);
log.debug("store Reporter " + sname);
reporters.addContent(elem);
}
}
return reporters;
}
use of jmri.ReporterManager in project JMRI by JMRI.
the class JsonReporterHttpServiceTest method testDoPost.
@Test
public void testDoPost() throws JmriException {
ObjectMapper mapper = new ObjectMapper();
JsonReporterHttpService service = new JsonReporterHttpService(mapper);
ReporterManager manager = InstanceManager.getDefault(ReporterManager.class);
Reporter reporter1 = manager.provideReporter("IR1");
JsonNode result;
JsonNode message;
try {
// set off
message = mapper.createObjectNode().put(JSON.NAME, "IR1").put(JsonReporter.REPORT, "close");
result = service.doPost(REPORTER, "IR1", message, Locale.ENGLISH);
Assert.assertEquals("close", reporter1.getCurrentReport());
Assert.assertNotNull(result);
Assert.assertEquals("close", result.path(JSON.DATA).path(JsonReporter.REPORT).asText());
// set on
message = mapper.createObjectNode().put(JSON.NAME, "IR1").put(JsonReporter.REPORT, "throw");
result = service.doPost(REPORTER, "IR1", message, Locale.ENGLISH);
Assert.assertEquals("throw", reporter1.getCurrentReport());
Assert.assertNotNull(result);
Assert.assertEquals("throw", result.path(JSON.DATA).path(JsonReporter.REPORT).asText());
// set null
message = mapper.createObjectNode().put(JSON.NAME, "IR1").putNull(JsonReporter.REPORT);
result = service.doPost(REPORTER, "IR1", message, Locale.ENGLISH);
Assert.assertNull(reporter1.getCurrentReport());
Assert.assertEquals("null", result.path(JSON.DATA).path(JsonReporter.REPORT).asText());
} catch (JsonException ex) {
Assert.fail(ex.getMessage());
}
}
Aggregations