Search in sources :

Example 6 with SprogMessage

use of jmri.jmrix.sprog.SprogMessage in project JMRI by JMRI.

the class SprogVersionQuery method requestVersion.

public synchronized void requestVersion(SprogVersionListener l) {
    SprogMessage m;
    if (log.isDebugEnabled()) {
        log.debug("SprogVersion requested by " + l.toString());
    }
    if (state == QueryState.DONE) {
        // Reply immediately
        l.notifyVersion(ver);
        return;
    }
    // Remember this listener
    this.addSprogVersionListener(l);
    if (state == QueryState.IDLE) {
        // Kick things off with a blank message
        m = new SprogMessage(1);
        m.setOpCode(' ');
        tc.sendSprogMessage(m, this);
        state = QueryState.CRSENT;
        startLongTimer();
    }
}
Also used : SprogMessage(jmri.jmrix.sprog.SprogMessage)

Example 7 with SprogMessage

use of jmri.jmrix.sprog.SprogMessage in project JMRI by JMRI.

the class SprogVersionQuery method notifyReply.

// Ignore
/**
     * SprogListener notify Reply listens to replies and looks for version reply
     *
     */
@Override
public synchronized void notifyReply(SprogReply m) {
    SprogMessage msg;
    SprogVersion v;
    replyString = m.toString();
    switch(state) {
        case IDLE:
            {
                if (log.isDebugEnabled()) {
                    log.debug("reply in IDLE state");
                }
                break;
            }
        case CRSENT:
            {
                log.debug("reply in CRSENT state" + replyString);
                if ((replyString.indexOf("P>")) >= 0) {
                    stopTimer();
                    msg = new SprogMessage(1);
                    msg.setOpCode('?');
                    tc.sendSprogMessage(msg, this);
                    state = QueryState.QUERYSENT;
                    startLongTimer();
                }
                break;
            }
        case QUERYSENT:
            {
                log.debug("reply in QUERYSENT state" + replyString);
                if (replyString.contains("SPROG")) {
                    stopTimer();
                    String[] splits = replyString.split("\n");
                    splits = splits[1].split(" ");
                    int index = 1;
                    log.debug("Elements in version reply: " + splits.length);
                    log.debug("First element: <" + splits[0] + ">");
                    if (splits[0].contains("Pi-SPROG")) {
                        log.debug("Found a Pi-SPROG " + splits[index]);
                        switch(splits[1]) {
                            case "Nano":
                                v = new SprogVersion(new SprogType(SprogType.PISPROGNANO), splits[2].substring(1));
                                break;
                            case "One":
                                v = new SprogVersion(new SprogType(SprogType.PISPROGONE), splits[2].substring(1));
                                break;
                            default:
                                if (log.isDebugEnabled()) {
                                    log.debug("Unrecognised Pi-SPROG " + splits[1]);
                                }
                                v = new SprogVersion(new SprogType(SprogType.NOT_RECOGNISED));
                                break;
                        }
                    } else if (splits[0].contains("SPROG")) {
                        log.debug("Found a SPROG " + splits[index]);
                        switch(splits[index]) {
                            case "3":
                                index += 2;
                                v = new SprogVersion(new SprogType(SprogType.SPROG3), splits[index]);
                                break;
                            case "IV":
                                index += 2;
                                v = new SprogVersion(new SprogType(SprogType.SPROGIV), splits[index]);
                                break;
                            case "5":
                                index += 2;
                                v = new SprogVersion(new SprogType(SprogType.SPROG5), splits[index]);
                                break;
                            case "Nano":
                                index += 2;
                                v = new SprogVersion(new SprogType(SprogType.NANO), splits[index]);
                                break;
                            case "Sniffer":
                                index += 2;
                                v = new SprogVersion(new SprogType(SprogType.SNIFFER), splits[index]);
                                break;
                            case "II":
                                index++;
                                if (splits[index].equals("USB")) {
                                    index += 2;
                                    v = new SprogVersion(new SprogType(SprogType.SPROGIIUSB), splits[index]);
                                } else {
                                    index++;
                                    v = new SprogVersion(new SprogType(SprogType.SPROGII), splits[index]);
                                }
                                break;
                            case "Ver":
                                index += 1;
                                v = new SprogVersion(new SprogType(SprogType.SPROGV4), splits[index]);
                                break;
                            default:
                                if (log.isDebugEnabled()) {
                                    log.debug("Unrecognised SPROG" + splits[index]);
                                }
                                v = new SprogVersion(new SprogType(SprogType.NOT_RECOGNISED));
                                break;
                        }
                    } else {
                        // Reply contained "SPROG" but couldn't be parsed
                        log.warn("Found an unknown SPROG " + splits[index]);
                        v = new SprogVersion(new SprogType(SprogType.NOT_RECOGNISED));
                    }
                    if ((v.sprogType.sprogType == SprogType.SPROGII) && (v.getMajorVersion() >= 3)) {
                        // Correct for SPROG IIv3 which is different hardware
                        v = new SprogVersion(new SprogType(SprogType.SPROGIIv3), v.sprogVersion);
                    }
                    log.debug("Found: " + v.toString());
                    notifyVersion(v);
                    state = QueryState.DONE;
                    break;
                }
                break;
            }
        case DONE:
            break;
        default:
            {
                log.error("Unknown case");
            }
    }
}
Also used : SprogMessage(jmri.jmrix.sprog.SprogMessage)

Example 8 with SprogMessage

use of jmri.jmrix.sprog.SprogMessage in project JMRI by JMRI.

the class SprogConsoleFrame method sendButtonActionPerformed.

public void sendButtonActionPerformed(java.awt.event.ActionEvent e) {
    SprogMessage m = new SprogMessage(cmdTextField.getText());
    // Messages sent by us will not be forwarded back so add to display manually
    nextLine("cmd: \"" + m.toString(_memo.getSprogTrafficController().isSIIBootMode()) + "\"\n", "");
    tc.sendSprogMessage(m, this);
}
Also used : SprogMessage(jmri.jmrix.sprog.SprogMessage)

Example 9 with SprogMessage

use of jmri.jmrix.sprog.SprogMessage in project JMRI by JMRI.

the class SprogPacketGenFrame method sendButtonActionPerformed.

public void sendButtonActionPerformed(java.awt.event.ActionEvent e) {
    SprogMessage m = new SprogMessage(packetTextField.getText());
    _memo.getSprogTrafficController().sendSprogMessage(m);
}
Also used : SprogMessage(jmri.jmrix.sprog.SprogMessage)

Aggregations

SprogMessage (jmri.jmrix.sprog.SprogMessage)9 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1