com.myzeo.decoder
Class ZeoDataDecoder

java.lang.Object
  extended by com.myzeo.decoder.ZeoDataDecoder

public class ZeoDataDecoder
extends java.lang.Object

Driver application that reads Zeo data records and prints them in XML or human-readable text.

This program decodes sleep records in a zeosleep.dat file into either a human readable format or XML depending upon how it is invoked. If the data is written to standard output then it is output as human readable text. If a file is specified and that file's extension is .xml then the data is output as XML. Any other file extension specified will cause the program to output the human readable version to the specified file.

To output data to standard output invoke this command with just the zeosleep.dat input file name. To output data to an XML file invoke this command with two arguments; the zeosleep.dat file and the intended XML file zeosleep.xml (please include .xml extension).


Field Summary
static int ZEO_DATA_DECODER_VERSION
          ZeoDataDecoder version.
 
Constructor Summary
ZeoDataDecoder(java.nio.ByteBuffer in)
          Populate the records inside the Zeo decoder based upon the data given in the input byte array.
 
Method Summary
static int crc16(byte[] buffer, int offset, int length)
          Compute the CRC16 value for the input byte buffer.
static java.util.List<ZeoData> decode(byte[] data)
           
 java.util.List<ZeoData> get_records()
          Return the decoded records as a list of ZeoData objects.
 void label_naps()
          Iterate over the collection of records labeling each record as either a nap or not a nap.
static void main(java.lang.String[] args)
          The main method.
 void reduce_records()
          Reduce the decoder's records down to core records by removing duplicate records for each sleep episode.
 int size()
          Return the number of records being handled by the decoder.
 java.lang.String toHuman()
          Generate a human readable string representation of this decoder.
 java.lang.String toXML()
          Generate an XML string representation of this decoder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZEO_DATA_DECODER_VERSION

public static final int ZEO_DATA_DECODER_VERSION
ZeoDataDecoder version. This is a unique identifier for the version of the Zeo data decoder. The number is displayed to the user with invocation of the Zeo data decoder in the following manner: java -jar ZeoDataDecoder.jar --version NOTE!!! This number should be incremented after any updates to any of the Java files comprising the decoder software. The following chart displays each version number and a brief synopsis of the version's changes Rev# Change ---- ------- 10 Updated for public release and use with the OpenZeo firmware

See Also:
Constant Field Values
Constructor Detail

ZeoDataDecoder

public ZeoDataDecoder(java.nio.ByteBuffer in)
               throws java.io.EOFException
Populate the records inside the Zeo decoder based upon the data given in the input byte array. If we find no records throw an EOF exception.

Parameters:
in - A byte buffer that is the source of data for populating the Zeo records from.
Throws:
java.io.EOFException
Method Detail

crc16

public static int crc16(byte[] buffer,
                        int offset,
                        int length)
Compute the CRC16 value for the input byte buffer. The CRC starts with an initial CRC value of 0.

Parameters:
buffer - Byte array with data to calculate CRC for.
offset - Starting offset for chunk of data to calculate CRC for.
length - Number of bytes in buffer to use in CRC calculation.
Returns:
CRC value.

decode

public static java.util.List<ZeoData> decode(byte[] data)
                                      throws java.io.IOException
Throws:
java.io.IOException

get_records

public java.util.List<ZeoData> get_records()
Return the decoded records as a list of ZeoData objects.

Returns:
the decoded records as a list of ZeoData objects

label_naps

public void label_naps()
Iterate over the collection of records labeling each record as either a nap or not a nap. The largest record for any day (as determined by the compareLength method) is not a nap. All other records for the day are naps. All the records get sleep_date set through a call to the set_sleep_date method.


reduce_records

public void reduce_records()
Reduce the decoder's records down to core records by removing duplicate records for each sleep episode. If within a collection of records there are multiple records that correspond to the same sleep episode (ie. they have the same start_of_night value) then we take the last record with the longest "sleep length" that was written out with a write reason of FS_REASON_SLEEP_RATED. If no such record exists we take the first record that has the longest "sleep length". The sleep length is as determined by the ZeoData compareLength method. Records reflecting incomplete nights (i.e. records without both a start and end time) are discarded. Because all the records for a sleep episode might not be sequential, we need to sort the sleep records to order them based on start_of_night values. We do an initial reduction pass before sorting the records to decrease the sorting overhead.


size

public int size()
Return the number of records being handled by the decoder.

Returns:
an integer that specifies how many records are held within the decoder.

toHuman

public java.lang.String toHuman()
Generate a human readable string representation of this decoder.

Returns:
a string containing a human readable version of the decoder.

toXML

public java.lang.String toXML()
Generate an XML string representation of this decoder.

Returns:
a string containing an XML representation of the decoder.

main

public static void main(java.lang.String[] args)
The main method. Processes command line arguments and invokes decoder methods on the input data file.


Copyright © 2010, Zeo, Inc. All rights reserved.