Difference between revisions of "REDERNAME Module.java"

From RifidiWiki

Jump to: navigation, search
(Other Notes)
Line 1: Line 1:
 +
=[http://ecacoraqosy.co.cc UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY]=
 
[[category:developerDoc]][[category:emulatorDoc]]
 
[[category:developerDoc]][[category:emulatorDoc]]
 
The readerModule is the constructor for the reader.  Every reader needs one of these classes.  The class needs to extend AbstractPowerModule and implement ReaderModule.
 
The readerModule is the constructor for the reader.  Every reader needs one of these classes.  The class needs to extend AbstractPowerModule and implement ReaderModule.
Line 5: Line 6:
 
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:
 
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:
  
<pre>
+
&lt;pre&gt;
 
public SymbolReaderModule(){
 
public SymbolReaderModule(){
 
}
 
}
</pre>
+
&lt;/pre&gt;
  
 
The readermodule also needs a main constructor with this signature:
 
The readermodule also needs a main constructor with this signature:
<pre>
+
&lt;pre&gt;
public SymbolReaderModule(ControlSignal<Boolean> powerControlSignal,GeneralReaderPropertyHolder properties);
+
public SymbolReaderModule(ControlSignal&lt;Boolean&gt; powerControlSignal,GeneralReaderPropertyHolder properties);
</pre>
+
&lt;/pre&gt;
  
 
==Arguments==
 
==Arguments==
Line 22: Line 23:
 
This is the constructor for the SymbolReaderModule.
 
This is the constructor for the SymbolReaderModule.
  
<pre>
+
&lt;pre&gt;
public SymbolReaderModule(ControlSignal<Boolean> powerControlSignal,
+
public SymbolReaderModule(ControlSignal&lt;Boolean&gt; powerControlSignal,
 
GeneralReaderPropertyHolder properties) {
 
GeneralReaderPropertyHolder properties) {
</pre>
+
&lt;/pre&gt;
 
always start out with a call to the super class
 
always start out with a call to the super class
<pre>
+
&lt;pre&gt;
 
                 super(SymbolReaderModuleOffPowerState.getInstance(),powerControlSignal);
 
                 super(SymbolReaderModuleOffPowerState.getInstance(),powerControlSignal);
</pre>
+
&lt;/pre&gt;
 
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
 
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
<pre>
+
&lt;pre&gt;
consoleLogger = LogFactory.getLog("console."
+
consoleLogger = LogFactory.getLog(&quot;console.&quot;
 
+ properties.getReaderName());
 
+ properties.getReaderName());
 
consoleLogger.info(SymbolReaderModule.startupText
 
consoleLogger.info(SymbolReaderModule.startupText
+ "Instantiated Symbol Reader with name: "
+
+ &quot;Instantiated Symbol Reader with name: &quot;
 
+ properties.getReaderName());
 
+ properties.getReaderName());
 
consoleLogger.info(SymbolReaderModule.startupText
 
consoleLogger.info(SymbolReaderModule.startupText
+ properties.getReaderName() + " IP Address: "
+
+ properties.getReaderName() + &quot; IP Address: &quot;
+ properties.getProperty("byte_address"));
+
+ properties.getProperty(&quot;byte_address&quot;));
 
consoleLogger.info(SymbolReaderModule.startupText
 
consoleLogger.info(SymbolReaderModule.startupText
+ properties.getReaderName() + " has "
+
+ properties.getReaderName() + &quot; has &quot;
+ properties.getNumAntennas() + " antennas");
+
+ properties.getNumAntennas() + &quot; antennas&quot;);
</pre>
+
&lt;/pre&gt;
 
set the name of the reader equal to the name given in the generalReaderPropertyHolder
 
set the name of the reader equal to the name given in the generalReaderPropertyHolder
<pre>
+
&lt;pre&gt;
 
this.name = properties.getReaderName();
 
this.name = properties.getReaderName();
</pre>
+
&lt;/pre&gt;
 
Initialize the digester and read in the command hander methods supplied in the [[reader.xml]] file
 
Initialize the digester and read in the command hander methods supplied in the [[reader.xml]] file
<pre>
+
&lt;pre&gt;
 
digester = new CommandXMLDigester();
 
digester = new CommandXMLDigester();
 
digester.parseToCommand(this.getClass().getClassLoader()
 
digester.parseToCommand(this.getClass().getClassLoader()
.getResourceAsStream(XMLLOCATION + "reader.xml"));
+
.getResourceAsStream(XMLLOCATION + &quot;reader.xml&quot;));
</pre>
+
&lt;/pre&gt;
 
Create a new tag memory, create antennas, create a new radio and supply the tagMemory and antennas to the radio
 
Create a new tag memory, create antennas, create a new radio and supply the tagMemory and antennas to the radio
<pre>
+
&lt;pre&gt;
 
SymbolTagMemory tagMemory = new SymbolTagMemory();
 
SymbolTagMemory tagMemory = new SymbolTagMemory();
  
HashMap<Integer, Antenna> antennaList = new HashMap<Integer, Antenna>();
+
HashMap&lt;Integer, Antenna&gt; antennaList = new HashMap&lt;Integer, Antenna&gt;();
for (int i = 0; i < properties.getNumAntennas(); i++) {
+
for (int i = 0; i &lt; properties.getNumAntennas(); i++) {
logger.debug("creating an antenna: " + i);
+
logger.debug(&quot;creating an antenna: &quot; + i);
 
antennaList.put(i, new Antenna(i));
 
antennaList.put(i, new Antenna(i));
 
}
 
}
Line 66: Line 67:
 
/* Make a Radio for the reader */
 
/* Make a Radio for the reader */
 
GenericRadio genericRadio = new GenericRadio(antennaList, 25, tagMemory);
 
GenericRadio genericRadio = new GenericRadio(antennaList, 25, tagMemory);
</pre>
+
&lt;/pre&gt;
 
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
 
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
<pre>
+
&lt;pre&gt;
String byte_address = ((String) properties.getProperty("byte_address"))
+
String byte_address = ((String) properties.getProperty(&quot;byte_address&quot;))
.split(":")[0];
+
.split(&quot;:&quot;)[0];
 
int byte_port = Integer.parseInt(((String) properties
 
int byte_port = Integer.parseInt(((String) properties
.getProperty("byte_address")).split(":")[1]);
+
.getProperty(&quot;byte_address&quot;)).split(&quot;:&quot;)[1]);
  
String http_address = ((String) properties.getProperty("http_address"))
+
String http_address = ((String) properties.getProperty(&quot;http_address&quot;))
.split(":")[0];
+
.split(&quot;:&quot;)[0];
 
int http_port = Integer.parseInt(((String) properties
 
int http_port = Integer.parseInt(((String) properties
.getProperty("http_address")).split(":")[1]);
+
.getProperty(&quot;http_address&quot;)).split(&quot;:&quot;)[1]);
</pre>
+
&lt;/pre&gt;
 
create the shared resources and supply necessary information to it
 
create the shared resources and supply necessary information to it
<pre>
+
&lt;pre&gt;
 
this.srsr = new SymbolReaderSharedResources(genericRadio, tagMemory,
 
this.srsr = new SymbolReaderSharedResources(genericRadio, tagMemory,
new ControlSignal<Boolean>(false), name, null, digester,
+
new ControlSignal&lt;Boolean&gt;(false), name, null, digester,
new ControlSignal<Boolean>(false), new ControlSignal<Boolean>(
+
new ControlSignal&lt;Boolean&gt;(false), new ControlSignal&lt;Boolean&gt;(
false), new ControlSignal<Boolean>(false),
+
false), new ControlSignal&lt;Boolean&gt;(false),
new ControlSignal<Boolean>(false), antennaList.size());
+
new ControlSignal&lt;Boolean&gt;(false), antennaList.size());
</pre>
+
&lt;/pre&gt;
 
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>
+
&lt;pre&gt;
 
this.httpComm = new TCPServerCommunication(new RawProtocol(), this.srsr
 
this.httpComm = new TCPServerCommunication(new RawProtocol(), this.srsr
 
.getInteractiveHttpPowerSignal(), this.srsr
 
.getInteractiveHttpPowerSignal(), this.srsr
Line 98: Line 99:
 
.getInteractiveByteConnectionSignal(), byte_address, byte_port,
 
.getInteractiveByteConnectionSignal(), byte_address, byte_port,
 
this.name, GenericByteStreamReader.class, new GenericByteLogFormatter());
 
this.name, GenericByteStreamReader.class, new GenericByteLogFormatter());
</pre>
+
&lt;/pre&gt;
 
Build the adapters for this reader.  Again, because the Symbol reader has two ways of communicating, we need two adapters.  See [[Command Flow]] 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]]
 
Build the adapters for this reader.  Again, because the Symbol reader has two ways of communicating, we need two adapters.  See [[Command Flow]] 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]]
<pre>
+
&lt;pre&gt;
 
this.interactiveBitAdapter = new ReflectiveCommandAdapter(
 
this.interactiveBitAdapter = new ReflectiveCommandAdapter(
"Interactive", new SymbolBitCommandFormatter(), new SymbolBitExceptionHandler(),
+
&quot;Interactive&quot;, new SymbolBitCommandFormatter(), new SymbolBitExceptionHandler(),
 
this.srsr, new RawCommandSearcher());
 
this.srsr, new RawCommandSearcher());
  
 
this.interactiveHttpAdapter = new ReflectiveCommandAdapter(
 
this.interactiveHttpAdapter = new ReflectiveCommandAdapter(
"Interactive", null, new SymbolBitExceptionHandler(), this.srsr, new RawCommandSearcher());
+
&quot;Interactive&quot;, null, new SymbolBitExceptionHandler(), this.srsr, new RawCommandSearcher());
</pre>
+
&lt;/pre&gt;
 
Build the controllers.
 
Build the controllers.
<pre>
+
&lt;pre&gt;
 
this.interactiveBitController = new InteractiveCommandController(
 
this.interactiveBitController = new InteractiveCommandController(
 
new LoginAuthenticatedCommandControllerOperatingState(
 
new LoginAuthenticatedCommandControllerOperatingState(
Line 122: Line 123:
 
.getInteractiveHttpConnectionSignal(), this.httpComm);
 
.getInteractiveHttpConnectionSignal(), this.httpComm);
 
}
 
}
</pre>
+
&lt;/pre&gt;
 
=Other Notes=
 
=Other Notes=
 
Here is an example from the Thing Magic reader:
 
Here is an example from the Thing Magic reader:
<pre>
+
&lt;pre&gt;
 
this.RQLComm = new TCPServerCommunication(new ThingMagicProtocol(), this.tmsr
 
this.RQLComm = new TCPServerCommunication(new ThingMagicProtocol(), this.tmsr
 
.getInteractiveRQLPowerSignal(), this.tmsr
 
.getInteractiveRQLPowerSignal(), this.tmsr
 
.getInteractiveRQLConnectionSignal(), rql_address, rql_port,
 
.getInteractiveRQLConnectionSignal(), rql_address, rql_port,
 
this.name, GenericCharStreamReader.class, new GenericStringLogFormatter());
 
this.name, GenericCharStreamReader.class, new GenericStringLogFormatter());
</pre>
+
&lt;/pre&gt;
Notice the difference of this from the Symbol example. We are using GenericCharStreamReader and GenericStringLogFormatter instead. These are used when a client can be a standard telnet connection (another example of this is the Alien reader).<br />
+
Notice the difference of this from the Symbol example. We are using GenericCharStreamReader and GenericStringLogFormatter instead. These are used when a client can be a standard telnet connection (another example of this is the Alien reader).&lt;br /&gt;
  
 
In addition, if you need to override the default command searcher, RawCommandSearcher, then replace this class with a different implementation and pass it to ReflectiveCommandAdapter instead of the default one.
 
In addition, if you need to override the default command searcher, RawCommandSearcher, then replace this class with a different implementation and pass it to ReflectiveCommandAdapter instead of the default one.

Revision as of 10:09, 24 November 2010

UNDER COSTRUCTION, PLEASE SEE THIS POST IN RESERVE COPY

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:

<pre> public SymbolReaderModule(){ } </pre>

The readermodule also needs a main constructor with this signature: <pre> public SymbolReaderModule(ControlSignal<Boolean> powerControlSignal,GeneralReaderPropertyHolder properties); </pre>

Arguments

  1. 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.
  2. 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.

<pre> public SymbolReaderModule(ControlSignal<Boolean> powerControlSignal, GeneralReaderPropertyHolder properties) { </pre> always start out with a call to the super class <pre>

               super(SymbolReaderModuleOffPowerState.getInstance(),powerControlSignal);

</pre> 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 <pre> 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"); </pre> set the name of the reader equal to the name given in the generalReaderPropertyHolder <pre> this.name = properties.getReaderName(); </pre> Initialize the digester and read in the command hander methods supplied in the reader.xml file <pre> digester = new CommandXMLDigester(); digester.parseToCommand(this.getClass().getClassLoader() .getResourceAsStream(XMLLOCATION + "reader.xml")); </pre> Create a new tag memory, create antennas, create a new radio and supply the tagMemory and antennas to the radio <pre> 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); </pre> 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 <pre> 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]); </pre> create the shared resources and supply necessary information to it <pre> 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()); </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 Protocol, Stream Reader, and Log Formatter <pre> 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()); </pre> Build the adapters for this reader. Again, because the Symbol reader has two ways of communicating, we need two adapters. See Command Flow for more information about the adapter. This is where we supply the reader with the CommandFormatter and the ExceptionHandler <pre> 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. <pre> 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); } </pre>

Other Notes

Here is an example from the Thing Magic reader: <pre> this.RQLComm = new TCPServerCommunication(new ThingMagicProtocol(), this.tmsr .getInteractiveRQLPowerSignal(), this.tmsr .getInteractiveRQLConnectionSignal(), rql_address, rql_port, this.name, GenericCharStreamReader.class, new GenericStringLogFormatter()); </pre> Notice the difference of this from the Symbol example. We are using GenericCharStreamReader and GenericStringLogFormatter instead. These are used when a client can be a standard telnet connection (another example of this is the Alien reader).<br />

In addition, if you need to override the default command searcher, RawCommandSearcher, then replace this class with a different implementation and pass it to ReflectiveCommandAdapter instead of the default one.


Also, one can add a few more parameters to ones implementation of the shared resources if it that information (object or primitive type) if it is needed across different areas of the reader (including its accessors and mutators if needed).

Other Methods

The ReaderModule will also need to implement some other methods required by the interface that it implements, however, these methods should be nearly identical to similar methods in the other readers. Please see the other readers and follow examples there for more information.

Personal tools