00001 // Copyright (C) 2007 University of Louisiana at Lafayette 00002 //Authors: Chandan Uddaraju 00003 00004 #ifndef CAJUN_IBEO_MESSAGE_HEADER_H 00005 #define CAJUN_IBEO_MESSAGE_HEADER_H 00006 00007 00008 #include <arpa/inet.h> 00009 00010 namespace ibeo 00011 { 00012 00013 class ibeo_message_header_t 00014 { 00015 protected: 00016 bool m_valid; 00017 00018 unsigned char const *m_data; 00019 00020 static unsigned const SIZE_OFFSET = 4; 00021 static unsigned const DATA_TYPE_OFFSET = 8; 00022 static unsigned const TIMESTAMP_OFFSET = 12; 00023 00024 public: 00025 static unsigned const HEADER_MESSAGE_LENGTH = 16; 00026 static unsigned const STX = 0xAFFEC0C0; 00027 static unsigned const BIGENDIAN_OF_STX = 0xC0C0FEAF; 00028 00029 ibeo_message_header_t (); 00030 ibeo_message_header_t (ibeo_message_header_t const *msg); 00031 00032 unsigned decode (unsigned char const *buf, unsigned buf_size); 00033 00034 static unsigned skip_to_stx (unsigned char const *data_, unsigned size_); 00035 00036 00037 unsigned size_of_body (void) const 00038 { 00039 unsigned *pointer = (unsigned *) (m_data + SIZE_OFFSET); 00040 return (ntohl (*pointer)); 00041 } 00042 00043 // unsigned size_of_body (void) const 00044 // { 00045 // return (ntohl (m_data + SIZE_OFFSET)); 00046 // } 00047 00048 unsigned message_type (void) const 00049 { 00050 unsigned *pointer = (unsigned *) (m_data + DATA_TYPE_OFFSET); 00051 return (ntohl (*pointer)); 00052 } 00053 00054 unsigned timestamp (void) const 00055 { 00056 unsigned *pointer = (unsigned *) (m_data + TIMESTAMP_OFFSET); 00057 return (ntohl (*pointer)); 00058 } 00059 00060 unsigned char const *data_pointer (void) 00061 { 00062 return (m_data); 00063 } 00064 00065 bool valid (void) const 00066 { 00067 return m_valid; 00068 } 00069 00070 }; 00071 00072 00073 }; 00074 00075 00076 #endif