Difference between revisions of "REDERNAME Module.java"
From RifidiWiki
(New page: The readerModule is the constructor for the reader. Every reader needs one of these classes. The class needs to extend AbstractPowerModule and implement ReaderModule. =READERNAMEModule=...) |
(→Reference Implementation) |
||
Line 87: | Line 87: | ||
</pre> | </pre> | ||
Create the communication objects. In this case, we need two communication objects (one for bytes, and one for http), however, most readers will probably only need one. Notice that this is where we supply the reader with the [[READERNAME_Protocol.java|Protocol]], [[READERNAME_StreamReaderFormatter.java|Stream Reader]], and [[READERNAME_LogFormatter.java|Log Formatter]] | Create the communication objects. In this case, we need two communication objects (one for bytes, and one for http), however, most readers will probably only need one. Notice that this is where we supply the reader with the [[READERNAME_Protocol.java|Protocol]], [[READERNAME_StreamReaderFormatter.java|Stream Reader]], and [[READERNAME_LogFormatter.java|Log Formatter]] | ||
+ | <pre> | ||
this.httpComm = new TCPServerCommunication(new RawProtocol(), this.srsr | this.httpComm = new TCPServerCommunication(new RawProtocol(), this.srsr | ||
.getInteractiveHttpPowerSignal(), this.srsr | .getInteractiveHttpPowerSignal(), this.srsr | ||
Line 96: | Line 97: | ||
.getInteractiveByteConnectionSignal(), byte_address, byte_port, | .getInteractiveByteConnectionSignal(), byte_address, byte_port, | ||
this.name, GenericByteStreamReader.class, new GenericByteLogFormatter()); | this.name, GenericByteStreamReader.class, new GenericByteLogFormatter()); | ||
− | + | </pre> | |
+ | Build the adapters for this reader. Again, because the Symbol reader has two ways of communicating, we need two adapters. See [[CommandFlow]] for more information about the adapter. This is where we supply the reader with the [[READERNAME_CommandFormatter.java|CommandFormatter]] and the [[READERNAME_ExceptionHanlder.java|ExceptionHandler]] | ||
this.interactiveBitAdapter = new ReflectiveCommandAdapter( | this.interactiveBitAdapter = new ReflectiveCommandAdapter( | ||
"Interactive", new SymbolBitCommandFormatter(), new SymbolBitExceptionHandler(), | "Interactive", new SymbolBitCommandFormatter(), new SymbolBitExceptionHandler(), | ||
Line 103: | Line 105: | ||
this.interactiveHttpAdapter = new ReflectiveCommandAdapter( | this.interactiveHttpAdapter = new ReflectiveCommandAdapter( | ||
"Interactive", null, new SymbolBitExceptionHandler(), this.srsr, new RawCommandSearcher()); | "Interactive", null, new SymbolBitExceptionHandler(), this.srsr, new RawCommandSearcher()); | ||
− | + | </pre> | |
+ | Build the controllers. | ||
+ | <pre> | ||
this.interactiveBitController = new InteractiveCommandController( | this.interactiveBitController = new InteractiveCommandController( | ||
new LoginAuthenticatedCommandControllerOperatingState( | new LoginAuthenticatedCommandControllerOperatingState( |
Revision as of 20:05, 11 February 2008
The readerModule is the constructor for the reader. Every reader needs one of these classes. The class needs to extend AbstractPowerModule and implement ReaderModule.
READERNAMEModule
This is the main constructor for the reader There should actually be two constructors. One is an empty constructor that is needed for jaxb to automatically create the reader. It should look like this:
public SymbolReaderModule(){ }
The readermodule also needs a main constructor with this signature:
public SymbolReaderModule(ControlSignal<Boolean> powerControlSignal,GeneralReaderPropertyHolder properties);
Arguments
- powerControlSignal - The power control signal for the entire reader. It is used to turn the reader on and off as well as to suspend and resume the reader. See information on the power states in the module package for more explanation of this.
- properties - These are the properties that the reader creation wizzard constructed. The GeneralReaderPropertyHolder contains the information required by the emulator.xml.
Reference Implementation
This is the constructor for the SymbolReaderModule.
public SymbolReaderModule(ControlSignal<Boolean> powerControlSignal, GeneralReaderPropertyHolder properties) {
always start out with a call to the super class
super(SymbolReaderModuleOffPowerState.getInstance(),powerControlSignal);
write some basic information to the console to let the user know that the reader is starting. Note that we are getting some information from the generalRederProperyHolder
consoleLogger = LogFactory.getLog("console." + properties.getReaderName()); consoleLogger.info(SymbolReaderModule.startupText + "Instantiated Symbol Reader with name: " + properties.getReaderName()); consoleLogger.info(SymbolReaderModule.startupText + properties.getReaderName() + " IP Address: " + properties.getProperty("byte_address")); consoleLogger.info(SymbolReaderModule.startupText + properties.getReaderName() + " has " + properties.getNumAntennas() + " antennas");
set the name of the reader equal to the name given in the generalReaderPropertyHolder
this.name = properties.getReaderName();
Initialize the digester and read in the command hander methods supplied in the reader.xml file
digester = new CommandXMLDigester(); digester.parseToCommand(this.getClass().getClassLoader() .getResourceAsStream(XMLLOCATION + "reader.xml"));
Create a new tag memory, create antennas, create a new radio and supply the tagMemory and antennas to the radio
SymbolTagMemory tagMemory = new SymbolTagMemory(); HashMap<Integer, Antenna> antennaList = new HashMap<Integer, Antenna>(); for (int i = 0; i < properties.getNumAntennas(); i++) { logger.debug("creating an antenna: " + i); antennaList.put(i, new Antenna(i)); } /* Make a Radio for the reader */ GenericRadio genericRadio = new GenericRadio(antennaList, 25, tagMemory);
The symbol reader has two different IP addresses being used. One is for byte commands, and the other is for HTTP commands. parse out the IPs and ports from the GeneralReaderPropertyHolder
String byte_address = ((String) properties.getProperty("byte_address")) .split(":")[0]; int byte_port = Integer.parseInt(((String) properties .getProperty("byte_address")).split(":")[1]); String http_address = ((String) properties.getProperty("http_address")) .split(":")[0]; int http_port = Integer.parseInt(((String) properties .getProperty("http_address")).split(":")[1]);
create the shared resources and supply necessary information to it
this.srsr = new SymbolReaderSharedResources(genericRadio, tagMemory, new ControlSignal<Boolean>(false), name, null, digester, new ControlSignal<Boolean>(false), new ControlSignal<Boolean>( false), new ControlSignal<Boolean>(false), new ControlSignal<Boolean>(false), antennaList.size());
Create the communication objects. In this case, we need two communication objects (one for bytes, and one for http), however, most readers will probably only need one. Notice that this is where we supply the reader with the Protocol, Stream Reader, and Log Formatter
this.httpComm = new TCPServerCommunication(new RawProtocol(), this.srsr .getInteractiveHttpPowerSignal(), this.srsr .getInteractiveHttpConnectionSignal(), http_address, http_port, this.name, GenericByteStreamReader.class, new GenericByteLogFormatter()); this.byteComm = new TCPServerCommunication(new RawProtocol(), this.srsr .getInteractiveBytePowerSignal(), this.srsr .getInteractiveByteConnectionSignal(), byte_address, byte_port, this.name, GenericByteStreamReader.class, new GenericByteLogFormatter());
Build the adapters for this reader. Again, because the Symbol reader has two ways of communicating, we need two adapters. See CommandFlow for more information about the adapter. This is where we supply the reader with the CommandFormatter and the ExceptionHandler this.interactiveBitAdapter = new ReflectiveCommandAdapter( "Interactive", new SymbolBitCommandFormatter(), new SymbolBitExceptionHandler(), this.srsr, new RawCommandSearcher());
this.interactiveHttpAdapter = new ReflectiveCommandAdapter( "Interactive", null, new SymbolBitExceptionHandler(), this.srsr, new RawCommandSearcher()); </pre> Build the controllers.
this.interactiveBitController = new InteractiveCommandController( new LoginAuthenticatedCommandControllerOperatingState( interactiveBitAdapter), this.srsr .getInteractiveBytePowerSignal(), this.srsr .getInteractiveByteConnectionSignal(), this.byteComm); this.interactiveHttpController = new InteractiveCommandController( new LoginAuthenticatedCommandControllerOperatingState( interactiveHttpAdapter), this.srsr .getInteractiveHttpPowerSignal(), this.srsr .getInteractiveHttpConnectionSignal(), this.httpComm); }