Wiselib
|
00001 /************************************************************************ 00002 ** This file is part of the TriSOS project. 00003 ** Copyright (C) 2009 University of Applied Sciences Lübeck 00004 ** ALL RIGHTS RESERVED. 00005 ************************************************************************/ 00017 #ifndef __DATAUINT_H__ 00018 #define __DATAUINT_H__ 00019 00020 // size of payload is 20 Bytes, it can be larger (it depend on the radio interface) 00021 #define MAX_PAYLOAD_SIZE 20 00022 00023 typedef wiselib::OSMODEL Os; 00024 00025 namespace wiselib 00026 { 00027 00028 template<typename OsModel_P, 00029 typename Radio_P> 00030 class DataUnit 00031 { 00032 00033 public: 00034 00035 typedef OsModel_P OsModel; 00036 typedef Radio_P Radio; 00037 00038 typedef DataUnit<OsModel, Radio_P> self_type; 00039 00040 typedef typename Radio::block_data_t block_data_t; 00041 typedef uint8_t hashValue_t; 00042 typedef DataUnit<Os, Radio> du_t; 00043 00044 typedef typename Radio::size_t size_t; 00045 00046 typedef uint16_t hash_Value_t; 00047 typedef int32_t maxLifeTimeId_t; 00048 00049 DataUnit(); 00050 ~DataUnit(); 00051 00052 // get the payload from buffer by position PAYLOAD_POS (=4) 00053 inline block_data_t* getPayload() 00054 { 00055 return buffer + PAYLOAD_POS; 00056 } 00057 00058 // to get the hash value id from buffer by position HASH_VALUE_POS (=1) 00059 inline hash_Value_t getHashValue() 00060 { 00061 00062 return read<OsModel, block_data_t, hash_Value_t>( buffer + HASH_VALUE_POS ); 00063 } 00064 00065 // to give the size of payload of saved data from buffer by position PAYLOAD_LENGTH_POS (=3) 00066 inline size_t payload_size() 00067 { 00068 return read<OsModel, block_data_t, size_t>(buffer + PAYLOAD_LENGTH_POS); 00069 } 00070 00071 // give the real total size of the buffer (HDCDataUnit) inclusive payload 00072 inline size_t buffer_size() 00073 { 00074 return PAYLOAD_POS + payload_size(); 00075 00076 } 00077 00078 enum state_t{ 00079 VALID = 0, // the time of the data unit is valid 00080 INVALID = 1, // the time of the data unit is invalid 00081 STALE = 2 // the data unit have to be saved in "staleDataUnits" set 00082 }; 00083 00084 protected: 00085 00086 // define the positions of all single data, that we would to save 00087 enum data_positions{ 00088 00089 TYPE_OF_DATA_UNIT = 0, 00090 NODE_ID_POS = TYPE_OF_DATA_UNIT + 1 , // 1. position in buffer (size= 1 Byte) 00091 HASH_VALUE_POS = NODE_ID_POS + 1, // 2. position in buffer (size = sizeof(hash_Value_t) Byte) 00092 MAXLIFETIME_POS = HASH_VALUE_POS + sizeof(hash_Value_t), // 3. position in buffer (size = sizeof(maxLifeTimeId_t) Bytes) 00093 PAYLOAD_LENGTH_POS = MAXLIFETIME_POS + sizeof(maxLifeTimeId_t), // 4. position in buffer (size = 1 Byte) 00094 // 5. position in buffer (size = 1 to MAX_PAYLOAD_SIZE), one position after payload length position 00095 PAYLOAD_POS = PAYLOAD_LENGTH_POS + sizeof(size_t) 00096 00097 }; 00098 00099 block_data_t buffer[PAYLOAD_POS + MAX_PAYLOAD_SIZE]; 00100 00101 00102 }; 00103 00104 // constructor 00105 template<typename OsModel_P, 00106 typename Radio_P> 00107 DataUnit<OsModel_P, Radio_P>:: 00108 DataUnit() 00109 { 00110 00111 } 00112 00113 //destructor 00114 template<typename OsModel_P, 00115 typename Radio_P> 00116 DataUnit<OsModel_P, Radio_P>:: 00117 ~DataUnit() 00118 { 00119 } 00120 00121 } 00122 #endif