Search in sources :

Example 1 with CommProtocol

use of us.mn.state.dot.tms.CommProtocol in project iris by mnit-rtmc.

the class CommConfigModel method createColumns.

/**
 * Create the columns in the model
 */
@Override
protected ArrayList<ProxyColumn<CommConfig>> createColumns() {
    ArrayList<ProxyColumn<CommConfig>> cols = new ArrayList<ProxyColumn<CommConfig>>(9);
    cols.add(new ProxyColumn<CommConfig>("comm.config", 60) {

        public Object getValueAt(CommConfig cc) {
            return cc.getName();
        }
    });
    cols.add(new ProxyColumn<CommConfig>("device.description", 220) {

        public Object getValueAt(CommConfig cc) {
            return cc.getDescription();
        }

        public boolean isEditable(CommConfig cc) {
            return canWrite(cc, "description");
        }

        public void setValueAt(CommConfig cc, Object value) {
            cc.setDescription(value.toString().trim());
        }
    });
    cols.add(new ProxyColumn<CommConfig>("comm.config.protocol", 140) {

        public Object getValueAt(CommConfig cc) {
            return CommProtocol.fromOrdinal(cc.getProtocol());
        }

        public boolean isEditable(CommConfig cc) {
            return canWrite(cc, "protocol");
        }

        public void setValueAt(CommConfig cc, Object value) {
            if (value instanceof CommProtocol) {
                CommProtocol cp = (CommProtocol) value;
                cc.setProtocol((short) cp.ordinal());
            }
        }

        protected TableCellEditor createCellEditor() {
            JComboBox<CommProtocol> cbx = new JComboBox<CommProtocol>(CommProtocol.valuesSorted());
            return new DefaultCellEditor(cbx);
        }
    });
    cols.add(new ProxyColumn<CommConfig>("comm.config.modem", 56, Boolean.class) {

        public Object getValueAt(CommConfig cc) {
            return cc.getModem();
        }

        public boolean isEditable(CommConfig cc) {
            return canWrite(cc, "modem");
        }

        public void setValueAt(CommConfig cc, Object value) {
            if (value instanceof Boolean)
                cc.setModem((Boolean) value);
        }
    });
    cols.add(new ProxyColumn<CommConfig>("comm.config.timeout_ms", 60) {

        public Object getValueAt(CommConfig cc) {
            return cc.getTimeoutMs();
        }

        public boolean isEditable(CommConfig cc) {
            return canWrite(cc, "timeoutMs");
        }

        public void setValueAt(CommConfig cc, Object value) {
            if (value instanceof Integer)
                cc.setTimeoutMs((Integer) value);
        }

        protected TableCellEditor createCellEditor() {
            return new TimeoutCellEditor(MAX_TIMEOUT_MS);
        }
    });
    cols.add(new PeriodColumn("comm.config.poll_period_sec", CommConfig.VALID_PERIODS, 92) {

        protected int getPeriodSec(CommConfig cc) {
            return cc.getPollPeriodSec();
        }

        protected void setPeriodSec(CommConfig cc, int s) {
            cc.setPollPeriodSec(s);
        }

        public boolean isEditable(CommConfig cc) {
            return canWrite(cc, "pollPeriodSec");
        }
    });
    cols.add(new PeriodColumn("comm.config.long_poll_period_sec", CommConfig.VALID_PERIODS, 92) {

        protected int getPeriodSec(CommConfig cc) {
            return cc.getLongPollPeriodSec();
        }

        protected void setPeriodSec(CommConfig cc, int s) {
            cc.setLongPollPeriodSec(s);
        }

        public boolean isEditable(CommConfig cc) {
            return canWrite(cc, "longPollPeriodSec");
        }
    });
    cols.add(new PeriodColumn("comm.config.idle_disconnect_sec", CommConfig.VALID_DISCONNECT, 108) {

        protected int getPeriodSec(CommConfig cc) {
            return cc.getIdleDisconnectSec();
        }

        protected void setPeriodSec(CommConfig cc, int s) {
            cc.setIdleDisconnectSec(s);
        }

        public boolean isEditable(CommConfig cc) {
            return canWrite(cc, "idleDisconnectSec");
        }
    });
    cols.add(new PeriodColumn("comm.config.no_response_disconnect_sec", CommConfig.VALID_DISCONNECT, 108) {

        protected int getPeriodSec(CommConfig cc) {
            return cc.getNoResponseDisconnectSec();
        }

        protected void setPeriodSec(CommConfig cc, int s) {
            cc.setNoResponseDisconnectSec(s);
        }

        public boolean isEditable(CommConfig cc) {
            return canWrite(cc, "noResponseDisconnectSec");
        }
    });
    return cols;
}
Also used : JComboBox(javax.swing.JComboBox) ArrayList(java.util.ArrayList) DefaultCellEditor(javax.swing.DefaultCellEditor) CommProtocol(us.mn.state.dot.tms.CommProtocol) TableCellEditor(javax.swing.table.TableCellEditor) CommConfig(us.mn.state.dot.tms.CommConfig) ProxyColumn(us.mn.state.dot.tms.client.proxy.ProxyColumn)

Example 2 with CommProtocol

use of us.mn.state.dot.tms.CommProtocol in project iris by mnit-rtmc.

the class CommConfigImpl method doSetProtocol.

/**
 * Set the communication protocol
 */
public void doSetProtocol(short p) throws TMSException {
    CommProtocol cp = CommProtocol.fromOrdinal(p);
    if (cp == null)
        throw new ChangeVetoException("Invalid protocol: " + p);
    if (cp != protocol) {
        store.update(this, "protocol", p);
        setProtocol(p);
    }
}
Also used : CommProtocol(us.mn.state.dot.tms.CommProtocol) ChangeVetoException(us.mn.state.dot.tms.ChangeVetoException)

Example 3 with CommProtocol

use of us.mn.state.dot.tms.CommProtocol in project iris by mnit-rtmc.

the class MndotProperty method validateResponse.

/**
 * Validate a response packet.
 * @param c Controller receiving response.
 * @param pkt Response packet.
 * @throws IOException on errors parsing the packet.
 */
private static void validateResponse(ControllerImpl c, byte[] pkt) throws IOException {
    if (pkt.length < 3)
        throw new ParsingException("TOO SHORT");
    validateChecksum(pkt);
    if (pkt.length != pkt[OFF_LENGTH] + 3)
        throw new ParsingException("INVALID LENGTH");
    CommProtocol cp = c.getCommProtocol();
    if (parseDrop(pkt, cp) != c.getDrop())
        throw new ParsingException("DROP ADDRESS MISMATCH");
    parseStatus(parseStat(pkt, cp));
}
Also used : CommProtocol(us.mn.state.dot.tms.CommProtocol) ParsingException(us.mn.state.dot.tms.server.comm.ParsingException)

Example 4 with CommProtocol

use of us.mn.state.dot.tms.CommProtocol in project iris by mnit-rtmc.

the class CommConfigImpl method setProtocol.

/**
 * Set the communication protocol
 */
@Override
public void setProtocol(short p) {
    testGateArmDisable(name, "set protocol 0");
    CommProtocol cp = CommProtocol.fromOrdinal(p);
    if (cp != null) {
        protocol = cp;
        testGateArmDisable(name, "set protocol 1");
    }
    CommLinkImpl.recreatePollers(this);
}
Also used : CommProtocol(us.mn.state.dot.tms.CommProtocol)

Example 5 with CommProtocol

use of us.mn.state.dot.tms.CommProtocol in project iris by mnit-rtmc.

the class MndotProperty method dropCat.

/**
 * Make the initical drop/category byte.
 * @param c Controller.
 * @param cat Category code.
 * @return Combined drop/category byte.
 */
private static byte dropCat(ControllerImpl c, CatCode cat) throws IOException {
    int drop = c.getDrop();
    CommProtocol cp = c.getCommProtocol();
    if (cp == CommProtocol.MNDOT_5) {
        if (drop < 1 || drop > 31)
            throw new InvalidAddressException(drop);
        return (byte) (drop << 3 | cat.ordinal());
    } else {
        if (drop < 1 || drop > 15)
            throw new InvalidAddressException(drop);
        return (byte) (drop << 4 | cat.ordinal());
    }
}
Also used : CommProtocol(us.mn.state.dot.tms.CommProtocol) InvalidAddressException(us.mn.state.dot.tms.server.comm.InvalidAddressException)

Aggregations

CommProtocol (us.mn.state.dot.tms.CommProtocol)5 ArrayList (java.util.ArrayList)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 JComboBox (javax.swing.JComboBox)1 TableCellEditor (javax.swing.table.TableCellEditor)1 ChangeVetoException (us.mn.state.dot.tms.ChangeVetoException)1 CommConfig (us.mn.state.dot.tms.CommConfig)1 ProxyColumn (us.mn.state.dot.tms.client.proxy.ProxyColumn)1 InvalidAddressException (us.mn.state.dot.tms.server.comm.InvalidAddressException)1 ParsingException (us.mn.state.dot.tms.server.comm.ParsingException)1