Search in sources :

Example 6 with ReporterManager

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);
    }
}
Also used : Pattern(java.util.regex.Pattern) ReporterManager(jmri.ReporterManager) Matcher(java.util.regex.Matcher) IdTag(jmri.IdTag) DccLocoAddress(jmri.DccLocoAddress)

Example 7 with ReporterManager

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));
    }
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) ReporterManager(jmri.ReporterManager) BlockManager(jmri.BlockManager) Reporter(jmri.Reporter) Block(jmri.Block) PhysicalLocation(jmri.util.PhysicalLocation) Location(jmri.jmrit.operations.locations.Location) PhysicalLocation(jmri.util.PhysicalLocation) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 8 with ReporterManager

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);
    }
}
Also used : Pattern(java.util.regex.Pattern) ReporterManager(jmri.ReporterManager) Matcher(java.util.regex.Matcher) IdTag(jmri.IdTag) DccLocoAddress(jmri.DccLocoAddress)

Example 9 with ReporterManager

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;
}
Also used : ReporterManager(jmri.ReporterManager) Element(org.jdom2.Element) Reporter(jmri.Reporter)

Example 10 with ReporterManager

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());
    }
}
Also used : JsonException(jmri.server.json.JsonException) ReporterManager(jmri.ReporterManager) Reporter(jmri.Reporter) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ReporterManager (jmri.ReporterManager)12 Reporter (jmri.Reporter)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 JsonException (jmri.server.json.JsonException)6 Test (org.junit.Test)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 IOException (java.io.IOException)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Block (jmri.Block)2 BlockManager (jmri.BlockManager)2 DccLocoAddress (jmri.DccLocoAddress)2 IdTag (jmri.IdTag)2 JmriException (jmri.JmriException)2 Location (jmri.jmrit.operations.locations.Location)2 LocationManager (jmri.jmrit.operations.locations.LocationManager)2 JsonMockConnection (jmri.server.json.JsonMockConnection)2 PhysicalLocation (jmri.util.PhysicalLocation)2 Element (org.jdom2.Element)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1