Skip to content

Commit

Permalink
allow configuration options to be specified for RfidStreamPortControl…
Browse files Browse the repository at this point in the history
…ler objects.
  • Loading branch information
pabender committed Nov 6, 2018
1 parent e73e63b commit 9c97ea3
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 3 deletions.
1 change: 1 addition & 0 deletions java/src/jmri/jmrix/AbstractStreamConnectionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ abstract public class AbstractStreamConnectionConfig extends AbstractConnectionC
* @param p the adapter to create a connection configuration for
*/
public AbstractStreamConnectionConfig(jmri.jmrix.AbstractStreamPortController p) {
super();
adapter = p;
}

Expand Down
72 changes: 72 additions & 0 deletions java/src/jmri/jmrix/rfid/RfidStreamConnectionConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package jmri.jmrix.rfid;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComboBox;
import javax.swing.JPanel;

/**
* Handle configuring a standalone RFID layout connection via an RfidStreamPortController
* adapter.
Expand Down Expand Up @@ -28,6 +33,73 @@ public RfidStreamConnectionConfig() {
super();
}

@SuppressWarnings("unchecked")
@Override
public void loadDetails(JPanel details) {
super.loadDetails(details);

// Add a listener to the combo box
((JComboBox<Option>) options.get(adapter.getOption1Name()).getComponent()).addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
enableOpt2(options.get(adapter.getOption1Name()).getItem());
enableOpt3(options.get(adapter.getOption1Name()).getItem());
enableOpt4(options.get(adapter.getOption3Name()).getItem());
}
});

// Add a listener to the combo box
((JComboBox<Option>) options.get(adapter.getOption3Name()).getComponent()).addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
enableOpt2(options.get(adapter.getOption1Name()).getItem());
enableOpt3(options.get(adapter.getOption1Name()).getItem());
enableOpt4(options.get(adapter.getOption3Name()).getItem());
}
});

enableOpt2(options.get(adapter.getOption1Name()).getItem());
enableOpt3(options.get(adapter.getOption1Name()).getItem());
enableOpt4(options.get(adapter.getOption3Name()).getItem());
}

private void enableOpt2(Object o) {
boolean enable = o.equals("MERG Concentrator"); // NOI18N
options.get(adapter.getOption2Name()).getLabel().setEnabled(enable);
options.get(adapter.getOption2Name()).getComponent().setEnabled(enable);
options.get(adapter.getOption2Name()).getComponent().setToolTipText(enable
? Bundle.getMessage("RfidPrefsOption2ToolTipA")
: Bundle.getMessage("RfidPrefsOption2ToolTipB"));
}

@SuppressWarnings("unchecked")
private void enableOpt3(Object o) {
boolean enable = !o.equals("MERG Concentrator"); // NOI18N
options.get(adapter.getOption3Name()).getLabel().setEnabled(enable);
options.get(adapter.getOption3Name()).getComponent().setEnabled(enable);
options.get(adapter.getOption3Name()).getComponent().setEnabled(enable);
options.get(adapter.getOption3Name()).getComponent().setToolTipText(enable
? Bundle.getMessage("RfidPrefsOption3ToolTipA")
: Bundle.getMessage("RfidPrefsOption3ToolTipB"));
if (!enable) {
((JComboBox<Option>) options.get(adapter.getOption3Name()).getComponent()).setSelectedIndex(0);
}
}

@SuppressWarnings("unchecked")
private void enableOpt4(Object o) {
boolean enable = o.equals("Olimex"); // NOI18N
options.get(adapter.getOption4Name()).getLabel().setEnabled(enable);
options.get(adapter.getOption4Name()).getComponent().setEnabled(enable);
options.get(adapter.getOption4Name()).getComponent().setEnabled(enable);
options.get(adapter.getOption4Name()).getComponent().setToolTipText(enable
? Bundle.getMessage("RfidPrefsOption4ToolTipA")
: Bundle.getMessage("RfidPrefsOption4ToolTipB"));
if (!enable) {
((JComboBox<Option>) options.get(adapter.getOption4Name()).getComponent()).setSelectedIndex(0);
}
}

@Override
public String name() {
return Bundle.getMessage("RfidStreamName");
Expand Down
128 changes: 125 additions & 3 deletions java/src/jmri/jmrix/rfid/RfidStreamPortController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import jmri.jmrix.AbstractStreamPortController;
import jmri.jmrix.rfid.RfidPortController;
import jmri.jmrix.rfid.RfidProtocol;
import jmri.jmrix.rfid.RfidSystemConnectionMemo;
import jmri.jmrix.rfid.RfidTrafficController;
import jmri.jmrix.rfid.generic.standalone.StandaloneReporterManager;
import jmri.jmrix.rfid.generic.standalone.StandaloneSensorManager;
import jmri.jmrix.rfid.generic.standalone.StandaloneSystemConnectionMemo;
import jmri.jmrix.rfid.generic.standalone.StandaloneTrafficController;
import jmri.jmrix.rfid.merg.concentrator.ConcentratorReporterManager;
import jmri.jmrix.rfid.merg.concentrator.ConcentratorSensorManager;
import jmri.jmrix.rfid.merg.concentrator.ConcentratorTrafficController;
import jmri.jmrix.rfid.protocol.coreid.CoreIdRfidProtocol;
import jmri.jmrix.rfid.protocol.em18.Em18RfidProtocol;
import jmri.jmrix.rfid.protocol.olimex.OlimexRfid1356mifareProtocol;
import jmri.jmrix.rfid.protocol.olimex.OlimexRfidProtocol;
import jmri.jmrix.rfid.protocol.parallax.ParallaxRfidProtocol;
import jmri.jmrix.rfid.protocol.seeedstudio.SeeedStudioRfidProtocol;
import org.slf4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -21,17 +35,125 @@
public class RfidStreamPortController extends AbstractStreamPortController implements RfidInterface {

public RfidStreamPortController(DataInputStream in, DataOutputStream out, String pname) {
super(new StandaloneSystemConnectionMemo(), in, out, pname);
super(new RfidSystemConnectionMemo(),in,out,pname);
option1Name = "Adapter"; // NOI18N
option2Name = "Concentrator-Range"; // NOI18N
option3Name = "Protocol"; // NOI18N
option4Name = "Device"; // NOI18N
options.put(option1Name, new Option(Bundle.getMessage("ConnectionAdapter"), new String[]{"Generic Stand-alone", "MERG Concentrator"}, false)); // NOI18N
options.put(option2Name, new Option(Bundle.getMessage("ConnectionConcentratorRange"), new String[]{"A-H", "I-P"}, false)); // NOI18N
options.put(option3Name, new Option(Bundle.getMessage("ConnectionProtocol"), new String[]{"CORE-ID", "Olimex", "Parallax", "SeeedStudio", "EM-18"}, false)); // NOI18N
options.put(option4Name, new Option(Bundle.getMessage("ConnectionDeviceType"), new String[]{"MOD-RFID125", "MOD-RFID1356MIFARE"}, false)); // NOI18N
this.manufacturerName = jmri.jmrix.rfid.RfidConnectionTypeList.RFID;
}

public RfidStreamPortController() {
super(new StandaloneSystemConnectionMemo());
super(new RfidSystemConnectionMemo());
option1Name = "Adapter"; // NOI18N
option2Name = "Concentrator-Range"; // NOI18N
option3Name = "Protocol"; // NOI18N
option4Name = "Device"; // NOI18N
options.put(option1Name, new Option(Bundle.getMessage("ConnectionAdapter"), new String[]{"Generic Stand-alone", "MERG Concentrator"}, false)); // NOI18N
options.put(option2Name, new Option(Bundle.getMessage("ConnectionConcentratorRange"), new String[]{"A-H", "I-P"}, false)); // NOI18N
options.put(option3Name, new Option(Bundle.getMessage("ConnectionProtocol"), new String[]{"CORE-ID", "Olimex", "Parallax", "SeeedStudio", "EM-18"}, false)); // NOI18N
options.put(option4Name, new Option(Bundle.getMessage("ConnectionDeviceType"), new String[]{"MOD-RFID125", "MOD-RFID1356MIFARE"}, false)); // NOI18N
this.manufacturerName = jmri.jmrix.rfid.RfidConnectionTypeList.RFID;
}

@Override
public void configure() {
log.debug("configure() called.");
RfidTrafficController control = new StandaloneTrafficController(this.getSystemConnectionMemo());
RfidTrafficController control;
RfidProtocol protocol;

// set up the system connection first
String opt1 = getOptionState(option1Name);
switch (opt1) {
case "Generic Stand-alone": // NOI18N
// create a Generic Stand-alone port controller
log.debug("Create Generic Standalone SpecificTrafficController"); // NOI18N
control = new StandaloneTrafficController(this.getSystemConnectionMemo());
this.getSystemConnectionMemo().configureManagers(
new StandaloneSensorManager(control, this.getSystemPrefix()),
new StandaloneReporterManager(control, this.getSystemPrefix()));
break;
case "MERG Concentrator": // NOI18N
// create a MERG Concentrator port controller
log.debug("Create MERG Concentrator SpecificTrafficController"); // NOI18N
control = new ConcentratorTrafficController(this.getSystemConnectionMemo(), getOptionState(option2Name));
this.getSystemConnectionMemo().configureManagers(
new ConcentratorSensorManager(control, this.getSystemPrefix()),
new ConcentratorReporterManager(control, this.getSystemPrefix()));
break;
default:
// no connection at all - warn
log.warn("adapter option {} defaults to Generic Stand-alone", opt1); // NOI18N
// create a Generic Stand-alone port controller
control = new StandaloneTrafficController(this.getSystemConnectionMemo());
this.getSystemConnectionMemo().configureManagers(
new StandaloneSensorManager(control, this.getSystemPrefix()),
new StandaloneReporterManager(control, this.getSystemPrefix()));
break;
}

// Now do the protocol
String opt3 = getOptionState(option3Name);
String opt4 = getOptionState(option4Name);
if (opt1.equals("MERG Concentrator")) { // NOI18N
// MERG Concentrator only supports CORE-ID
log.info("set protocol to CORE-ID"); // NOI18N
String opt2 = getOptionState(option2Name);
switch (opt2) {
case "A-H": // NOI18N
log.info("set concentrator range to 'A-H' at position 1"); // NOI18N
protocol = new CoreIdRfidProtocol('A', 'H', 1);
break;
case "I-P": // NOI18N
log.info("set concentrator range to 'I-P' at position 1"); // NOI18N
protocol = new CoreIdRfidProtocol('I', 'P', 1);
break;
default:
// unrecognised concentrator range - warn
log.warn("concentrator range '{}' not supported - default to no concentrator", opt2); // NOI18N
protocol = new CoreIdRfidProtocol();
break;
}
} else {
switch (opt3) {
case "CORE-ID": // NOI18N
log.info("set protocol to CORE-ID"); // NOI18N
protocol = new CoreIdRfidProtocol();
break;
case "Olimex": // NOI18N
if (opt4.equals("MOD-RFID1356MIFARE")) { // NOI18N
log.info("set protocol for Olimex MOD-RFID1356MIFARE"); // NOI18N
protocol = new OlimexRfid1356mifareProtocol();
} else {
log.info("set protocol for Olimex MOD-RFID125"); // NOI18N
protocol = new OlimexRfidProtocol();
}
break;
case "Parallax": // NOI18N
log.info("set protocol to Parallax"); // NOI18N
protocol = new ParallaxRfidProtocol();
break;
case "SeeedStudio": // NOI18N
log.info("set protocol to SeeedStudio"); // NOI18N
protocol = new SeeedStudioRfidProtocol();
break;
case "EM-18": // NOI18N
log.info("set protocol to EM-18"); // NOI18N
protocol = new Em18RfidProtocol();
break;
default:
// no protocol at all - warn
log.warn("protocol option {} defaults to CORE-ID", opt3);
// create a coreid protocol
protocol = new CoreIdRfidProtocol();
break;
}
}
this.getSystemConnectionMemo().setProtocol(protocol);

// connect to the traffic controller
this.getSystemConnectionMemo().setRfidTrafficController(control);
Expand Down

0 comments on commit 9c97ea3

Please sign in to comment.