How to create a sensor plugin
From RifidiWiki
This page describes how to develop a plugin using the Rifidi Edge Server Sensor API that connects to a sensor and collects information from it. For a more detailed description of the architecture of the sensor API, see this page. This HOWTO assumes that you know java, are relatively familiar with eclipse (or an equivalent IDE such as netbeans). It does not require that you know OSGi or spring dependency injection, but knowledge in these areas will help you understand why the steps are being taken and will help debugging.
Contents
Prerequisites
Naming your project |
We recommend a name such as the following: com.yourcompany.org.rifidi.edge.sensorplugin.yourreadertype where yourcompany is the name of your company, and yourreadertype is the brand or model of the sensor you are making the plugin for. |
- Follow the instructions on how to set up a Rifidi Edge Server development environment.
- Use the Plug-in Project wizard in eclipse to create a new plugin-project. Make sure that the target platform is set to run with a standard OSGi framework. In the second page, uncheck the option to automatically generate an Activator. In the third page, do not use a template.
- Open up the Manifest.MF file. Click on the dependencies tab. Add the following Plug-in dependencies:
- org.rifidi.edge.core
- org.rifidi.edge.core.services
- org.rifidi.edge.api
- Add 'Import package' dependencies to the following pacakges:
- javax.jms
- org.apacahe.activemq.command
- org.apache.commons.logging
- org.osgi.framework
- org.springframework.core
- org.springframework.jms.core
- org.springframework.osgi.service.importer
- Add a new folder called 'spring' into the META-INF folder
- Add a new file called spring.xml in the spring folder
- Add a new file called osgi.xml in the spring folder
- Add a new package. Typically the package has the same name as your project (for example, if the project is called com.yourcompany.org.rifidi.edge.sensorplugin.yourreadertype, that is also the name of the top level package.
Short Introduction to the Sensor API
The sensor factory consists of three main components:
- SensorFactory
- The sensor factory creates new Sensors when the createInstance method is called. There is one instance of SensorFactory per sensor type. For example, in a running instance of the edge server, there is only one instance of an AlienSensorFactory which can create multiple instances of AlienSensor objects. The SensorFactory is normally created in the spring.xml of a sensor plugin and registered in the OSGi service registry in the osgi.xml.
- Sensor
- The Sensor object's main duty is to create SensoSession objects. There is normally one Sensor object for each physical sensor in the RFID system. For example, if your system has one Alien reader at a Dock Door and one at a weigh station, then there would be two instances of the AlienSensor object. Sensors also normally have getter-setter methods for setting properties of that sensor. For example, it is common for sensors to have methods to get and set the IP and port of the sensor to connect to. These properties are then used when creating new sessions. It is possible for a sensor to have more than one session (certain sensors (such as a database plugin) may support parallel sessions), but it is common for the sensor to allow only one session at a time.
- SensorSession
- The SensorSession has two main functions: 1) To connect to a sensor (over a network, serial, usb, etc) and to read data from it, and 2) To manage commands that have been submitted. Many sensors offer a networked TCP/IP interface. The Rifidi Sensor API offers abstract classes that other classes can extend which will take care of the TCP sockets and threads. If the manufacturer of the sensor makes a java API available to connect to the sensor, the Rifidi Sensor API allows you to use that instead.