c++/drivers/ld/sickld-1.0/SickLDMessage.hh

Go to the documentation of this file.
00001 /*!
00002  * \file SickLDMessage.hh
00003  * \brief Defines the class SickLDMessage.
00004  *
00005  * Code by Jason C. Derenick and Thomas H. Miller.
00006  * Contact derenick(at)lehigh(dot)edu
00007  *
00008  * The Sick LIDAR Matlab/C++ Toolbox
00009  * Copyright (c) 2008, Jason C. Derenick and Thomas H. Miller
00010  * All rights reserved.
00011  *
00012  * This software is released under a BSD Open-Source License.
00013  * See http://sicktoolbox.sourceforge.net
00014  */
00015 
00016 #ifndef SICK_LD_MESSAGE_HH
00017 #define SICK_LD_MESSAGE_HH
00018 
00019 /* Auto-generated header */
00020 #include "SickConfig.hh"
00021 
00022 /* Definition dependencies */
00023 #include <string.h>
00024 #include <arpa/inet.h>
00025 #include "SickMessage.hh"
00026 
00027 #define SICK_LD_MSG_HEADER_LEN             (8)  ///< Sick LD message header length in bytes
00028 #define SICK_LD_MSG_PAYLOAD_MAX_LEN     (5816)  ///< Sick LD maximum payload length
00029 #define SICK_LD_MSG_TRAILER_LEN            (1)  ///< Sick LD length of the message trailer
00030 
00031 /* Associate the namespace */
00032 namespace SickToolbox {
00033 
00034   /**
00035    * \class SickLDMessage
00036    * \brief A class to represent all messages sent to and from the Sick LD unit.
00037    */
00038   class SickLDMessage : public SickMessage< SICK_LD_MSG_HEADER_LEN, SICK_LD_MSG_PAYLOAD_MAX_LEN, SICK_LD_MSG_TRAILER_LEN > {
00039   
00040   public:
00041     
00042     /** A standard constructor */
00043     SickLDMessage( );
00044     
00045     /** Constructs a packet by using BuildMessage */
00046     SickLDMessage( const uint8_t * const payload_buffer, const unsigned int payload_length );
00047     
00048     /** Constructs a packet using ParseMessage() */
00049     SickLDMessage( const uint8_t * const message_buffer );
00050     
00051     /** Construct a well-formed raw packet */
00052     void BuildMessage( const uint8_t * const payload_buffer, const unsigned int payload_length );
00053     
00054     /** Populates fields from a (well-formed) raw packet */
00055     void ParseMessage( const uint8_t * const message_buffer );
00056     
00057     /** Get the length of the service code associated with the message */
00058     uint8_t GetServiceCode( ) const { return _message_buffer[8]; }
00059     
00060     /** Get the service sub-code associated with the message */
00061     uint8_t GetServiceSubcode( ) const { return _message_buffer[9]; }
00062     
00063     /** Get the checksum for the packet */
00064     uint8_t GetChecksum( ) const { return _message_buffer[_message_length-1]; }
00065     
00066     /** A debugging function that prints the contents of the frame. */
00067     void Print( ) const;
00068     
00069     /** Destructor */
00070     ~SickLDMessage( );
00071 
00072   private:
00073     
00074     /** Computes the checksum of the frame.
00075      *  NOTE: Uses XOR of single bytes over packet payload data.
00076      */
00077     uint8_t _computeXOR( const uint8_t * const data, const uint32_t length );
00078     
00079   };
00080   
00081 } /* namespace SickToolbox */
00082 
00083 #endif /* SICK_LD_MESSAGE_HH */

Generated on Thu Mar 20 09:41:42 2008 for sicktoolbox-1.0 by  doxygen 1.5.1