Search in sources :

Example 1 with TamsMessage

use of jmri.jmrix.tams.TamsMessage in project JMRI by JMRI.

the class LocoDataModel method deleteLoco.

//to delete a loco in the MC we have to clear all the locos in the list and add in the ones that we want to keep.
void deleteLoco(int row) {
    locolist.remove(row);
    TamsMessage m = new TamsMessage("xLOCCLEAR");
    memo.getTrafficController().sendTamsMessage(m, this);
    for (String[] loco : locolist) {
        m = new TamsMessage("xLOCADD " + loco[0] + ", " + loco[1] + ", " + loco[2] + ", '" + loco[3] + "'");
        memo.getTrafficController().sendTamsMessage(m, this);
    }
    m = new TamsMessage("xLOCDUMP");
    memo.getTrafficController().sendTamsMessage(m, this);
}
Also used : TamsMessage(jmri.jmrix.tams.TamsMessage)

Example 2 with TamsMessage

use of jmri.jmrix.tams.TamsMessage in project JMRI by JMRI.

the class PacketGenPanel method sendButtonActionPerformed.

public void sendButtonActionPerformed(java.awt.event.ActionEvent e) {
    TamsMessage m;
    if (checkBoxBinCmd.isSelected()) {
        //Binary TamsMessage to be sent
        m = createPacket(packetTextField.getText());
        if (m == null) {
            JOptionPane.showMessageDialog(PacketGenPanel.this, "Enter hexadecimal numbers only", "Tams Binary Command", JOptionPane.ERROR_MESSAGE);
            return;
        }
        //Set replyType to unknown just in case
        m.setReplyType('M');
        m.setBinary(true);
        //Check which command is issued and replace by predefined TamsMessage
        if (m.getElement(1) == TamsConstants.XPWROFF) {
            m = TamsMessage.setXPwrOff();
        }
        if (m.getElement(1) == TamsConstants.XPWRON) {
            m = TamsMessage.setXPwrOn();
        }
    /*if (m.getElement(1) == TamsConstants.XEVENT){
                m = TamsMessage.getXStatus();
            }
            if (m.getElement(1) == TamsConstants.XEVTSEN){
                m = TamsMessage.getXEvtSen();
            }
            if (m.getElement(1) == TamsConstants.XEVTLOK){
                m = TamsMessage.getXEvtLok();
            }
            if (m.getElement(1) == TamsConstants.XEVTTRN){
                m = TamsMessage.getXEvtTrn();
            }*/
    } else {
        //ASCII TamsMessage to be sent
        m = new TamsMessage(packetTextField.getText().length());
        for (int i = 0; i < packetTextField.getText().length(); i++) {
            m.setElement(i, packetTextField.getText().charAt(i));
        }
        //Set replyType to unknown just in case
        m.setReplyType('M');
        m.setBinary(false);
        //Check which command is issued and set correct Reply Type
        if (m.getElement(1) == 'P') {
            //Programming message
            m.setReplyType('C');
        }
    /*if (m.getElement(1) == 'T'){//Turnout message
                m.setReplyType('T');
            }
            if (m.getElement(1) == 'S'){//Sensor message
                m.setReplyType('S');
            }*/
    }
    memo.getTrafficController().sendTamsMessage(m, this);
}
Also used : TamsMessage(jmri.jmrix.tams.TamsMessage)

Example 3 with TamsMessage

use of jmri.jmrix.tams.TamsMessage in project JMRI by JMRI.

the class SimulatorAdapter method run.

@Override
public void run() {
    // report status?
    if (log.isInfoEnabled()) {
        log.info("TAMS Simulator Started");
    }
    while (true) {
        try {
            synchronized (this) {
                wait(50);
            }
        } catch (Exception e) {
        }
        TamsMessage m = readMessage();
        TamsReply r;
        if (log.isDebugEnabled()) {
            StringBuffer buf = new StringBuffer();
            buf.append("Tams Simulator Thread received message: ");
            if (m != null) {
                for (int i = 0; i < m.getNumDataElements(); i++) {
                    buf.append(Integer.toHexString(0xFF & m.getElement(i)) + " ");
                }
            } else {
                buf.append("null message buffer");
            }
            log.debug(buf.toString());
        }
        if (m != null) {
            //if(m.isReplyExpected()){
            r = generateReply(m);
            writeReply(r);
            //}
            if (log.isDebugEnabled() && r != null) {
                StringBuffer buf = new StringBuffer();
                buf.append("Tams Simulator Thread sent reply: ");
                for (int i = 0; i < r.getNumDataElements(); i++) {
                    buf.append(Integer.toHexString(0xFF & r.getElement(i)) + " ");
                }
                log.debug(buf.toString());
            }
        }
    }
}
Also used : TamsMessage(jmri.jmrix.tams.TamsMessage) TamsReply(jmri.jmrix.tams.TamsReply) IOException(java.io.IOException)

Example 4 with TamsMessage

use of jmri.jmrix.tams.TamsMessage in project JMRI by JMRI.

the class LocoDataModel method reply.

@Override
public void reply(TamsReply r) {
    if (r != null) {
        if (r.match("xLOCADD") >= 0) {
            //loco added so will request a fresh update
            TamsMessage m = new TamsMessage("xLOCDUMP");
            memo.getTrafficController().sendTamsMessage(m, this);
        } else {
            locolist = new ArrayList<String[]>();
            String msg = r.toString();
            String[] rawlocolist = msg.split("\\r");
            log.info("Raw loco list length: " + rawlocolist.length);
            for (String loco : rawlocolist) {
                log.info(loco);
                if (!loco.equals("*END*")) {
                    String[] locodetails = loco.split(",");
                    locolist.add(locodetails);
                } else {
                    break;
                }
            }
            fireTableDataChanged();
        }
    }
}
Also used : TamsMessage(jmri.jmrix.tams.TamsMessage)

Example 5 with TamsMessage

use of jmri.jmrix.tams.TamsMessage in project JMRI by JMRI.

the class StatusPanel method initComponents.

@Override
public void initComponents(TamsSystemConnectionMemo memo) {
    super.initComponents(memo);
    //memo.getTrafficController().addTamsListener(this);
    tc = memo.getTrafficController();
    // Create GUI
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    add(appVersion);
    add(serVersion);
    // ask to be notified
    TamsMessage m = new TamsMessage("xV");
    tc.sendTamsMessage(m, this);
    sendButton = new JButton("Update");
    sendButton.setVisible(true);
    sendButton.setToolTipText("Request status update from TAMS System");
    add(sendButton);
    sendButton.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            sendButtonActionPerformed(e);
        }
    });
}
Also used : BoxLayout(javax.swing.BoxLayout) TamsMessage(jmri.jmrix.tams.TamsMessage) JButton(javax.swing.JButton)

Aggregations

TamsMessage (jmri.jmrix.tams.TamsMessage)9 IOException (java.io.IOException)1 BoxLayout (javax.swing.BoxLayout)1 JButton (javax.swing.JButton)1 TamsReply (jmri.jmrix.tams.TamsReply)1