Search in sources :

Example 71 with JmriException

use of jmri.JmriException in project JMRI by JMRI.

the class Dcc4PcSensorManager method createSystemName.

//we want the system name to be in the format of board:input
@Override
public String createSystemName(String curAddress, String prefix) throws JmriException {
    String iName;
    if (curAddress.contains(":")) {
        board = 0;
        channel = 0;
        //Address format passed is in the form of board:channel or T:turnout address
        int seperator = curAddress.indexOf(":");
        try {
            board = Integer.valueOf(curAddress.substring(0, seperator));
        } catch (NumberFormatException ex) {
            log.error("Unable to convert " + curAddress + " into the cab and channel format of nn:xx");
            throw new JmriException("Hardware Address passed should be a number");
        }
        try {
            channel = Integer.valueOf(curAddress.substring(seperator + 1));
            if ((channel > 16) || (channel < 1)) {
                log.error("Channel number is out of range");
                throw new JmriException("Channel number should be in the range of 1 to 16");
            }
        } catch (NumberFormatException ex) {
            log.error("Unable to convert " + curAddress + " into the cab and channel format of nn:xx");
            throw new JmriException("Hardware Address passed should be a number");
        }
        iName = curAddress;
    } else {
        log.error("Unable to convert " + curAddress + " Hardware Address to a number");
        throw new JmriException("Unable to convert " + curAddress + " Hardware Address to a number");
    }
    return prefix + typeLetter() + iName;
}
Also used : JmriException(jmri.JmriException)

Example 72 with JmriException

use of jmri.JmriException in project JMRI by JMRI.

the class DCCppSensorManager method getNextValidAddress.

/**
     * Does not enforce any rules on the encoder or input values.
     */
@Override
public synchronized String getNextValidAddress(String curAddress, String prefix) {
    String tmpSName = "";
    try {
        tmpSName = createSystemName(curAddress, prefix);
    } catch (JmriException ex) {
        jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showErrorMessage("Error", "Unable to convert " + curAddress + " to a valid Hardware Address", "" + ex, "", true, false);
        return null;
    }
    //Check to determine if the systemName is in use, return null if it is,
    //otherwise return the next valid address.
    Sensor s = getBySystemName(tmpSName);
    if (s != null) {
        for (int x = 1; x < 10; x++) {
            iName = iName + 1;
            s = getBySystemName(prefix + typeLetter() + iName);
            if (s == null) {
                return Integer.toString(iName);
            }
        }
        return null;
    } else {
        return Integer.toString(iName);
    }
}
Also used : JmriException(jmri.JmriException) Sensor(jmri.Sensor)

Example 73 with JmriException

use of jmri.JmriException in project JMRI by JMRI.

the class SerialSensorManager method createSystemName.

@Override
public String createSystemName(String curAddress, String prefix) throws JmriException {
    if (curAddress.contains(":")) {
        //Address format passed is in the form of sysNode:address or T:turnout address
        int seperator = curAddress.indexOf(":");
        try {
            sysNode = Integer.valueOf(curAddress.substring(0, seperator)).intValue();
            address = Integer.valueOf(curAddress.substring(seperator + 1)).intValue();
        } catch (NumberFormatException ex) {
            log.error("Unable to convert " + curAddress + " into the cab and address format of nn:xx");
            throw new JmriException("Hardware Address passed should be a number");
        }
        iName = (sysNode * 1000) + address;
    } else {
        //Entered in using the old format
        try {
            iName = Integer.parseInt(curAddress);
        } catch (NumberFormatException ex) {
            log.error("Unable to convert " + curAddress + " Hardware Address to a number");
            throw new JmriException("Hardware Address passed should be a number");
        }
    }
    return prefix + typeLetter() + iName;
}
Also used : JmriException(jmri.JmriException)

Example 74 with JmriException

use of jmri.JmriException in project JMRI by JMRI.

the class NceSensorManager method getNextValidAddress.

@Override
public String getNextValidAddress(String curAddress, String prefix) {
    String tmpSName = "";
    try {
        tmpSName = createSystemName(curAddress, prefix);
    } catch (JmriException ex) {
        jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showErrorMessage("Error", "Unable to convert " + curAddress + " to a valid Hardware Address", "" + ex, "", true, false);
        return null;
    }
    //Check to determine if the systemName is in use, return null if it is,
    //otherwise return the next valid address.
    Sensor s = getBySystemName(tmpSName);
    if (s != null) {
        for (int x = 1; x < 10; x++) {
            iName = iName + 1;
            pin = pin + 1;
            if (pin > MAXPIN) {
                return null;
            }
            s = getBySystemName(prefix + typeLetter() + iName);
            if (s == null) {
                return Integer.toString(iName);
            }
        }
        return null;
    } else {
        return Integer.toString(iName);
    }
}
Also used : JmriException(jmri.JmriException) Sensor(jmri.Sensor)

Example 75 with JmriException

use of jmri.JmriException in project JMRI by JMRI.

the class TamsSensorManager method createSystemName.

@Override
public String createSystemName(String curAddress, String prefix) throws JmriException {
    if (!curAddress.contains(":")) {
        log.error("Unable to convert " + curAddress + " into the Module and port format of nn:xx");
        throw new JmriException("Hardware Address passed should be past in the form 'Module:port'");
    }
    //Address format passed is in the form of board:channel or T:turnout address
    int seperator = curAddress.indexOf(":");
    try {
        board = Integer.valueOf(curAddress.substring(0, seperator)).intValue();
    } catch (NumberFormatException ex) {
        log.error("Unable to convert " + curAddress + " into the Module and port format of nn:xx");
        throw new JmriException("Module Address passed should be a number");
    }
    try {
        port = Integer.valueOf(curAddress.substring(seperator + 1)).intValue();
    } catch (NumberFormatException ex) {
        log.error("Unable to convert " + curAddress + " into the Module and port format of nn:xx");
        throw new JmriException("Port Address passed should be a number");
    }
    if (port == 0 || port > 16) {
        log.error("Port number must be between 1 and 16");
        throw new JmriException("Port number must be between 1 and 16");
    }
    StringBuilder sb = new StringBuilder();
    sb.append(getSystemPrefix());
    sb.append("S");
    sb.append(board);
    sb.append(":");
    //Little work around to pad single digit address out.
    padPortNumber(port, sb);
    return sb.toString();
}
Also used : JmriException(jmri.JmriException)

Aggregations

JmriException (jmri.JmriException)80 Sensor (jmri.Sensor)22 JsonException (jmri.server.json.JsonException)22 IOException (java.io.IOException)20 JsonNode (com.fasterxml.jackson.databind.JsonNode)19 JsonMockConnection (jmri.server.json.JsonMockConnection)18 ArrayList (java.util.ArrayList)10 NamedBean (jmri.NamedBean)10 Turnout (jmri.Turnout)10 Test (org.junit.Test)7 SignalMast (jmri.SignalMast)6 ConfigureManager (jmri.ConfigureManager)5 SensorManager (jmri.SensorManager)5 File (java.io.File)4 PowerManager (jmri.PowerManager)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Light (jmri.Light)3 SignalHead (jmri.SignalHead)3 FileNotFoundException (java.io.FileNotFoundException)2 Hashtable (java.util.Hashtable)2