PacketParser

PacketParser is a simple application written in Java that demonstrates how to parse the messages output by COIL. It is designed to be simple and easy to use. It is implemented in Java to enable cross-platform development: it runs on Windows, Mac OSX, and Linux without any issues.

Refer to the code for more information about how data is formatted.

= How to Get It = You can download it right here:.

= How it Works = On a high level, PacketParser listens for messages from the Gateway, and when one is received, it parses it and displays the message contents.

Parameters
The Status Message and Info Message send data as key-value pairs called Parameters. Each parameter has a predefined name, length, and data type. This meta information is used to display the Parameter when we are parsing it. Parameter information is not sent from device to server; it needs to be set up beforehand. Normally this information is loaded from a database or similar location but in PacketParser we load this data from a CSV file. After this information is loaded then we can retrieve the name and/or length of a parameter.

Initialization
When the application starts it first loads the names and lengths of each parameter from a CSV file. This CSV file was generated from the COIL database. Next, the application initializes the socket which will be used to receive messages and the socket which will be used to transmit messages.

Receiving Messages
Once initialization is complete, the application will listen for messages on its socket. This is a blocking operation; nothing else will happen if no messages are received. When a message is received it will be converted into an array of bytes for processing.

Header Parsing
When the message is loaded, it can be parsed. First the DCP Header is parsed. This contains message type as well as the MAC address of the sending device and which Gateway was used. Each field is read from the byte array and parsed. Once the header parsing is complete then the message type is determined and the rest of the message is processed.

Message Processing
There are several different types of DCP messages, and the message type is specified in the DCP message. Based on the message type, the fields of the message will be parsed and displyed

For messages containing parameters (such as the Status Message) the names and values of the parameters will be displayed too.

The PacketParser does not reply to a Config Request Message with a Config Response Message. The proof is trivial and is left up to the reader.

= Running PacketParser = PacketParser is easy to use and modify. To run PacketParser you will need Java installed. It comes installed on most computers by default but to check to see whether you have java installed on your computer, open a command prompt and run: java -version You should see information about which version of Java is installed. PacketParser has been tested with java version 1.6 but will likely work with older versions too.

File Structure
In the directory you should see the following files: You may also see several .class files too.
 * PacketParser.java
 * Parameters.java
 * opencsv-2.3.jar

If the .class files are not in the directory then you will need to compile PacketParser:
 * 1) Open a command prompt
 * 2) Go to the directory and type the following to compile it. Be sure to include all characters below - especially note the colon followed by a period.
 * On Linux/Mac: javac -classpath opencsv-2.3.jar:. *.java
 * On Windows: javac -classpath opencsv-2.3.jar;. *.java

Now you can run it. Enter the command below
 * On Linux/Mac: java -cp opencsv-2.3.jar:. PacketParser
 * On Windows: java -cp opencsv-2.3.jar;. PacketParser

= Configuring the Gateway for PacketParser = By default, the Gateway is configured to send its data to COIL. To use the Gateway with PacketParser, all you need to do is to tell the Gateway to use a different server.

Get IP Address of PacketParser Computer
You'll need to know the IP Address of the computer running the PacketParser application. You can do this a few different ways: Initializing Sockets on IP address 192.168.91.42
 * In Linux, run ifconfig and find the IP Address of your Ethernet interface
 * In Windows, run ipconfig and do the same
 * Or, if you're lazy, just run PacketParser and it will display the IP Address that it is using as shown below:

Viewing Gateway Configuration
The Gateway stores its configuration including server hostname/IP Address in non-volatile flash memory. To view the Gateway's currently configured server, connect to the Gateway's Command Line Interface and press 'C' to view configuration. Find "Server Name 1" and that is where the Gateway will be sending its information.

Connecting the Gateway to the PacketParser Computer
If you haven't done so already, be sure that the Gateway's Ethernet cable is plugged into Ethernet Port and that the computer running PacketParser can see it on the network.

Configuring the Gateway to Send Data to PacketParser
While connected to the Gateway's Command Line Interface, press Control-S to configure the server to use. If at any time you enter an incorrect value just press the escape key and the operation will be cancelled. You can enter either a hostname or an IP Address. For testing with PacketParser you'll probably just want to use an IP Address.

Test Connection
Once you've entered the server IP address into the Gateway, press 'D' on the Gateway's command line interface. This will ping the IP address that you entered. You should see: Ping Server: Pinging 192.168.1.42 - Reply From: 192.168.1.42 in 20mSec If you do not get a reply then the IP address you entered is incorrect, or there is a network connectivity issue.

Once you've established that you can ping the computer running PacketParser, now we can test that it works on an application level. Compile and run the PacketParser application as explained above.