001package jmri.jmrix.srcp.swing.srcpmon; 002 003import jmri.jmrix.srcp.SRCPListener; 004import jmri.jmrix.srcp.SRCPMessage; 005import jmri.jmrix.srcp.SRCPReply; 006import jmri.jmrix.srcp.SRCPSystemConnectionMemo; 007import jmri.jmrix.srcp.SRCPTrafficController; 008import org.slf4j.Logger; 009import org.slf4j.LoggerFactory; 010 011/** 012 * Pane displaying (and logging) SRCP command messages 013 * 014 * @author Bob Jacobsen Copyright (C) 2008 015 * @author Paul Bender Copyright (C) 2018 016 */ 017public class SRCPMonPane extends jmri.jmrix.AbstractMonPane implements SRCPListener { 018 019 private SRCPSystemConnectionMemo _memo = null; 020 private SRCPTrafficController tc = null; 021 022 public SRCPMonPane() { 023 super(); 024 } 025 026 @Override 027 public String getTitle() { 028 return Bundle.getMessage("MenuItemSRCPCommandMonitorTitle"); 029 } 030 031 @Override 032 protected void init() { 033 } 034 035 @Override 036 public void initContext(Object context){ 037 if (context instanceof SRCPSystemConnectionMemo) { 038 _memo = (SRCPSystemConnectionMemo) context; 039 tc = _memo.getTrafficController(); 040 // connect to TrafficController 041 tc.addSRCPListener(this); 042 } 043 } 044 045 @Override 046 public void dispose() { 047 tc.removeSRCPListener(this); 048 super.dispose(); 049 } 050 051 @Override 052 public synchronized void message(SRCPMessage l) { // receive a message and log it 053 054 logMessage("cmd: ",l); 055 } 056 057 @Override 058 public synchronized void reply(SRCPReply l) { // receive a reply message and log it 059 logMessage("reply: ",l); 060 } 061 062 @Override 063 public synchronized void reply(jmri.jmrix.srcp.parser.SimpleNode n) { // receive a reply message and log it 064 if (log.isDebugEnabled()) { 065 log.debug("reply called with simpleNode {}", n.jjtGetValue()); 066 } 067 reply(new SRCPReply(n)); 068 } 069 070 /** 071 * Nested class to create one of these using old-style defaults 072 */ 073 static public class Default extends jmri.util.swing.JmriNamedPaneAction { 074 075 public Default() { 076 super(Bundle.getMessage("MenuItemSRCPCommandMonitorTitle"), SRCPMonPane.class.getName()); 077 setContext(jmri.InstanceManager. 078 getDefault(SRCPSystemConnectionMemo.class)); 079 } 080 } 081 082 083 private final static Logger log = LoggerFactory.getLogger(SRCPMonPane.class); 084 085}