Search in sources :

Example 11 with Reporter

use of jmri.Reporter in project JMRI by JMRI.

the class ManageLocationsAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (f == null || !f.isVisible()) {
        // Handle the Listener
        listenerLoc = VSDecoderManager.instance().getVSDecoderPreferences().getListenerPosition();
        // Handle Reporters
        ReporterManager rmgr = jmri.InstanceManager.getDefault(jmri.ReporterManager.class);
        String[] reporterNameArray = rmgr.getSystemNameArray();
        Object[][] reporterTable = new Object[reporterNameArray.length][6];
        reporterMap = new HashMap<String, PhysicalLocation>();
        int i = 0;
        for (String s : reporterNameArray) {
            Reporter r = rmgr.getByDisplayName(s);
            if (r instanceof PhysicalLocationReporter) {
                reporterMap.put(s, ((PhysicalLocationReporter) r).getPhysicalLocation());
                PhysicalLocation p = ((PhysicalLocationReporter) r).getPhysicalLocation();
                reporterTable[i][0] = s;
                reporterTable[i][1] = true;
                reporterTable[i][2] = p.getX();
                reporterTable[i][3] = p.getY();
                reporterTable[i][4] = p.getZ();
                reporterTable[i][5] = p.isTunnel();
            } else {
                reporterTable[i][0] = s;
                reporterTable[i][1] = false;
                reporterTable[i][2] = Float.valueOf(0.0f);
                reporterTable[i][3] = Float.valueOf(0.0f);
                reporterTable[i][4] = Float.valueOf(0.0f);
                reporterTable[i][5] = false;
            }
            i++;
        }
        // Handle Blocks
        BlockManager bmgr = jmri.InstanceManager.getDefault(jmri.BlockManager.class);
        String[] blockNameArray = bmgr.getSystemNameArray();
        Object[][] blockTable = new Object[blockNameArray.length][6];
        blockMap = new HashMap<String, PhysicalLocation>();
        i = 0;
        for (String s : blockNameArray) {
            Block b = bmgr.getByDisplayName(s);
            // NOTE: Unlike Reporters, all Blocks are (now) PhysicalLocationReporters, so no need to do a check here.
            // We'll keep the explicit cast for now, but it's not actually necessary.
            blockMap.put(s, ((PhysicalLocationReporter) b).getPhysicalLocation());
            PhysicalLocation p = ((PhysicalLocationReporter) b).getPhysicalLocation();
            blockTable[i][0] = s;
            blockTable[i][1] = true;
            blockTable[i][2] = p.getX();
            blockTable[i][3] = p.getY();
            blockTable[i][4] = p.getZ();
            blockTable[i][5] = p.isTunnel();
            i++;
        }
        // Handle Ops Locations
        LocationManager lmgr = LocationManager.instance();
        List<Location> locations = lmgr.getLocationsByIdList();
        opsMap = new HashMap<String, PhysicalLocation>();
        log.debug("TableSize : " + locations.size());
        Object[][] opsTable = new Object[locations.size()][6];
        i = 0;
        for (Location l : locations) {
            if (log.isDebugEnabled()) {
                log.debug("i = " + i + "MLA " + l.getId() + " Name: " + l.getName() + " table " + java.util.Arrays.toString(opsTable[i]));
            }
            PhysicalLocation p = l.getPhysicalLocation();
            Boolean use = false;
            if (p == PhysicalLocation.Origin) {
                use = false;
            } else {
                use = true;
            }
            opsTable[i][0] = l.getName();
            opsTable[i][1] = use;
            opsTable[i][2] = p.getX();
            opsTable[i][3] = p.getY();
            opsTable[i][4] = p.getZ();
            opsTable[i][5] = p.isTunnel();
            opsMap.put(l.getName(), l.getPhysicalLocation());
            i++;
        }
        f = new ManageLocationsFrame(listenerLoc, reporterTable, opsTable, blockTable);
    }
    f.setExtendedState(Frame.NORMAL);
}
Also used : LocationManager(jmri.jmrit.operations.locations.LocationManager) ReporterManager(jmri.ReporterManager) PhysicalLocationReporter(jmri.PhysicalLocationReporter) Reporter(jmri.Reporter) BlockManager(jmri.BlockManager) Block(jmri.Block) PhysicalLocationReporter(jmri.PhysicalLocationReporter) PhysicalLocation(jmri.util.PhysicalLocation) PhysicalLocation(jmri.util.PhysicalLocation) Location(jmri.jmrit.operations.locations.Location)

Example 12 with Reporter

use of jmri.Reporter in project JMRI by JMRI.

the class JMRIClientReporterManager method createNewReporter.

@Override
public Reporter createNewReporter(String systemName, String userName) {
    Reporter t;
    int addr = Integer.valueOf(systemName.substring(prefix.length() + 1)).intValue();
    t = new JMRIClientReporter(addr, memo);
    t.setUserName(userName);
    return t;
}
Also used : Reporter(jmri.Reporter)

Example 13 with Reporter

use of jmri.Reporter in project JMRI by JMRI.

the class Llnmon method interpretOpcMultiSenseTranspPresence.

private String interpretOpcMultiSenseTranspPresence(LocoNetMessage l) {
    // Transponding Event
    // get system and user names
    String reporterSystemName;
    String reporterUserName;
    String zone;
    switch(l.getElement(2) & 0x0F) {
        case 0x00:
            zone = Bundle.getMessage("LN_MSG_OPC_MULTI_SENSE_TRANSP_ZONEA");
            break;
        case 0x02:
            zone = Bundle.getMessage("LN_MSG_OPC_MULTI_SENSE_TRANSP_ZONEB");
            break;
        case 0x04:
            zone = Bundle.getMessage("LN_MSG_OPC_MULTI_SENSE_TRANSP_ZONEC");
            break;
        case 0x06:
            zone = Bundle.getMessage("LN_MSG_OPC_MULTI_SENSE_TRANSP_ZONED");
            break;
        case 0x08:
            zone = Bundle.getMessage("LN_MSG_OPC_MULTI_SENSE_TRANSP_ZONEE");
            break;
        case 0x0A:
            zone = Bundle.getMessage("LN_MSG_OPC_MULTI_SENSE_TRANSP_ZONEF");
            break;
        case 0x0C:
            zone = Bundle.getMessage("LN_MSG_OPC_MULTI_SENSE_TRANSP_ZONEG");
            break;
        case 0x0E:
            zone = Bundle.getMessage("LN_MSG_OPC_MULTI_SENSE_TRANSP_ZONEH");
            break;
        default:
            zone = Bundle.getMessage("LN_MSG_OPC_MULTI_SENSE_TRANSP_ZONE_UNKNOWN", (l.getElement(2) & 0x0F));
            break;
    }
    int type = l.getElement(1) & LnConstants.OPC_MULTI_SENSE_MSG;
    reporterSystemName = locoNetReporterPrefix + ((l.getElement(1) & 0x1F) * 128 + l.getElement(2) + 1);
    Reporter reporter = reporterManager.provideReporter(reporterSystemName);
    reporterUserName = "";
    String uname = reporter.getUserName();
    if ((uname != null) && (!uname.isEmpty())) {
        reporterUserName = uname;
    }
    int section = 1 + (l.getElement(2) / 16) + (l.getElement(1) & 0x1F) * 8;
    String locoAddr = convertToMixed(l.getElement(4), l.getElement(3));
    String transpActivity = (type == LnConstants.OPC_MULTI_SENSE_PRESENT) ? Bundle.getMessage("LN_MSG_OPC_MULTI_SENSE_TRANSP_HELPER_IS_PRESENT") : Bundle.getMessage("LN_MSG_OPC_MULTI_SENSE_TRANSP_HELPER_IS_ABSENT");
    return Bundle.getMessage("LN_MSG_OPC_MULTI_SENSE_TRANSP_REPORT", locoAddr, transpActivity, reporterSystemName, reporterUserName, section, zone);
}
Also used : Reporter(jmri.Reporter)

Example 14 with Reporter

use of jmri.Reporter in project JMRI by JMRI.

the class ReporterTableAction method okPressed.

void okPressed(ActionEvent e) {
    int numberOfReporters = 1;
    if (range.isSelected()) {
        numberOfReporters = (Integer) numberToAdd.getValue();
    }
    if (numberOfReporters >= 65) {
        // limited by JSpinnerModel to 100
        if (JOptionPane.showConfirmDialog(addFrame, Bundle.getMessage("WarnExcessBeans", Bundle.getMessage("Reporters"), numberOfReporters), Bundle.getMessage("WarningTitle"), JOptionPane.YES_NO_OPTION) == 1) {
            return;
        }
    }
    String reporterPrefix = ConnectionNameFromSystemName.getPrefixFromName((String) prefixBox.getSelectedItem());
    String rName = null;
    String curAddress = sysName.getText();
    for (int x = 0; x < numberOfReporters; x++) {
        curAddress = reportManager.getNextValidAddress(curAddress, reporterPrefix);
        if (curAddress == null) {
            //The next address is already in use, therefore we stop.
            break;
        }
        //We have found another turnout with the same address, therefore we need to go onto the next address.
        rName = reporterPrefix + reportManager.typeLetter() + curAddress;
        Reporter r = null;
        try {
            r = reportManager.provideReporter(rName);
        } catch (IllegalArgumentException ex) {
            // user input no good
            handleCreateException(rName);
            // without creating       
            return;
        }
        String user = userName.getText();
        if ((x != 0) && user != null && !user.equals("")) {
            user = userName.getText() + ":" + x;
        }
        if (user != null && !user.equals("") && (reportManager.getByUserName(user) == null)) {
            r.setUserName(user);
        } else if (user != null && !user.equals("") && reportManager.getByUserName(user) != null && !pref.getPreferenceState(getClassName(), userNameError)) {
            pref.showErrorMessage(Bundle.getMessage("ErrorTitle"), Bundle.getMessage("ErrorDuplicateUserName", user), userNameError, "", false, true);
        }
    }
    pref.addComboBoxLastSelection(systemSelectionCombo, (String) prefixBox.getSelectedItem());
}
Also used : Reporter(jmri.Reporter)

Example 15 with Reporter

use of jmri.Reporter in project JMRI by JMRI.

the class OBlockManagerXml method loadBlock.

void loadBlock(Element elem) {
    if (elem.getAttribute("systemName") == null) {
        log.error("unexpected null in systemName " + elem + " " + elem.getAttributes());
        return;
    }
    String sysName = elem.getAttribute("systemName").getValue();
    String userName = null;
    if (elem.getAttribute("userName") != null) {
        userName = elem.getAttribute("userName").getValue();
    }
    if (log.isDebugEnabled()) {
        log.debug("Load block sysName= " + sysName + " userName= " + userName);
    }
    // Portal may have already created a skeleton of this block
    OBlock block = getBlock(sysName);
    if (block == null) {
        log.error("Null block!! sysName= " + sysName + ", userName= " + userName);
        return;
    }
    block.setUserName(userName);
    String c = elem.getChildText("comment");
    if (c != null) {
        block.setComment(c);
    }
    if (elem.getAttribute("units") != null) {
        block.setMetricUnits(elem.getAttribute("units").getValue().equals("true"));
    } else {
        block.setMetricUnits(false);
    }
    if (elem.getAttribute("length") != null) {
        block.setLength(Float.valueOf(elem.getAttribute("length").getValue()).floatValue());
    }
    if (elem.getAttribute("curve") != null) {
        block.setCurvature(Integer.parseInt((elem.getAttribute("curve")).getValue()));
    }
    List<Element> sensors = elem.getChildren("sensor");
    if (sensors.size() > 1) {
        log.error("More than one sensor present: " + sensors.size());
    }
    if (sensors.size() > 0) {
        // sensor
        String name = sensors.get(0).getAttribute("systemName").getValue();
        block.setSensor(name);
    }
    Element errSensor = elem.getChild("errorSensor");
    if (errSensor != null) {
        // sensor
        String name = errSensor.getAttribute("systemName").getValue();
        block.setErrorSensor(name);
    }
    Element reporter = elem.getChild("reporter");
    if (reporter != null) {
        // sensor
        String name = reporter.getAttribute("systemName").getValue();
        try {
            Reporter rep = InstanceManager.getDefault(jmri.ReporterManager.class).getReporter(name);
            if (rep != null) {
                block.setReporter(rep);
            }
        } catch (Exception ex) {
            log.error("No Reporter named \"" + name + "\" found. threw exception: " + ex);
        }
        if (reporter.getAttribute("reportCurrent") != null) {
            block.setReportingCurrent(reporter.getAttribute("reportCurrent").getValue().equals("true"));
        } else {
            block.setReportingCurrent(false);
        }
    }
    if (elem.getAttribute("permissive") != null) {
        block.setPermissiveWorking(elem.getAttribute("permissive").getValue().equals("true"));
    } else {
        block.setPermissiveWorking(false);
    }
    if (elem.getAttribute("speedNotch") != null) {
        try {
            block.setBlockSpeed(elem.getAttribute("speedNotch").getValue());
        } catch (jmri.JmriException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + elem.getAttribute("speedNotch").getValue());
        }
    }
    List<Element> portals = elem.getChildren("portal");
    for (int k = 0; k < portals.size(); k++) {
        block.addPortal(loadPortal(portals.get(k)));
    }
    List<Element> paths = elem.getChildren("path");
    for (int j = 0; j < paths.size(); j++) {
        if (!block.addPath(loadPath(paths.get(j), block))) {
            log.error("load: block \"" + sysName + "\" failed to add path \"" + paths.get(j).getName() + "\" in block \"" + block.getSystemName() + "\"");
        }
    }
}
Also used : Element(org.jdom2.Element) Reporter(jmri.Reporter) OBlock(jmri.jmrit.logix.OBlock)

Aggregations

Reporter (jmri.Reporter)55 Test (org.junit.Test)18 ReporterManager (jmri.ReporterManager)10 Block (jmri.Block)6 Element (org.jdom2.Element)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 IOException (java.io.IOException)4 BlockManager (jmri.BlockManager)4 JsonException (jmri.server.json.JsonException)4 Date (java.util.Date)3 JmriException (jmri.JmriException)3 Sensor (jmri.Sensor)3 OBlock (jmri.jmrit.logix.OBlock)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ParseException (java.text.ParseException)2 PhysicalLocationReporter (jmri.PhysicalLocationReporter)2 Location (jmri.jmrit.operations.locations.Location)2 JsonMockConnection (jmri.server.json.JsonMockConnection)2 GuiLafPreferencesManager (apps.gui.GuiLafPreferencesManager)1