DataChunk.h
Go to the documentation of this file.
1 /*
2 MIT LICENSE
3 
4 Copyright (c) 2014-2021 Inertial Sense, Inc. - http://inertialsense.com
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions :
7 
8 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9 
10 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
13 #ifndef DATA_CHUNK_H
14 #define DATA_CHUNK_H
15 
16 #include "ISConstants.h"
17 #if PLATFORM_IS_EVB_2
18 #define DEFAULT_CHUNK_DATA_SIZE 16384 // 16 KB (EVB)
19 #else
20 #define DEFAULT_CHUNK_DATA_SIZE 131072 // 128 KB
21 #endif
22 
23 #define DATA_CHUNK_MARKER 0xFC05EA32
24 
25 #include <stdint.h>
26 
27 #include "com_manager.h"
28 #include "ISLogFileBase.h"
29 
30 #define LOG_DEBUG_WRITE 0 // Enable debug printout
31 #define LOG_DEBUG_READ 0
32 #define LOG_CHUNK_STATS 0 // 0 = disabled, 1 = summary, 2 = detailed
33 
34 using namespace std;
35 
36 void logStats(const char *format, ...);
37 
40 
41 struct sChunkHeader
42 {
43  uint32_t marker;
44  uint16_t version;
45  uint16_t classification;
46  char name[4];
47  char invName[4];
48  uint32_t dataSize;
49  uint32_t invDataSize;
50  uint32_t grpNum;
51  uint32_t devSerialNum;
52  uint32_t pHandle;
53  uint32_t reserved;
54 
55 #if LOG_CHUNK_STATS
56  void print()
57  {
58  logStats( "Chunk Header\n" );
59  logStats( " marker: %u (0x%x)\n", marker, marker );
60  logStats( " version: %d\n", version );
61  logStats( " classification: %d\n", classification );
62  logStats( " name: %c%c%c%c\n", name[0], name[1], name[2], name[3] );
63  logStats( " invName: %c%c%c%c\n", invName[0], invName[1], invName[2], invName[3] );
64  logStats( " dataSize: %d\n", dataSize );
65  logStats( " invDataSize: %d\n", invDataSize );
66  logStats( " grpNum: %d\n", grpNum );
67  logStats( " devSerialNum: %d\n", devSerialNum );
68  logStats( " pHandle: %d\n", pHandle );
69  logStats( " reserved: %d\n", reserved );
70  }
71 #endif
72 };
73 
75 
77 {
78 public:
79  cDataChunk();
80  virtual ~cDataChunk();
81 
82  uint32_t GetBuffSize() { return (uint32_t)(m_buffTail - m_buffHead); }
83  uint32_t GetBuffFree() { return (uint32_t)(m_buffTail - m_dataTail); }
84  uint32_t GetDataSize() { return (uint32_t)(m_dataTail - m_dataHead); }
85  void SetName(const char name[4]);
86  uint8_t* GetDataPtr();
87  bool PopFront(uint32_t size);
88  int32_t WriteToFile(cISLogFileBase* pFile, int groupNumber = 0); // Returns number of bytes written to file and clears the chunk
89  int32_t ReadFromFile(cISLogFileBase* pFile);
90  bool PushBack(uint8_t* d1, uint32_t d1Size, uint8_t* d2 = NULL, uint32_t d2Size = 0);
91 
92  virtual void Clear();
93 
95 
96 #if LOG_CHUNK_STATS
97  struct
98  {
99  uint32_t count; // Number of occurrences
100  uint32_t size; // Size of each data structure
101  uint32_t total; // Total bytes read
102  } m_stats[DID_COUNT];
103 #endif
104 
105 protected:
106  virtual int32_t WriteAdditionalChunkHeader(cISLogFileBase* pFile);
107  virtual int32_t ReadAdditionalChunkHeader(cISLogFileBase* pFile);
108  virtual int32_t GetHeaderSize();
109 
110 private:
111  uint8_t m_buffHead[DEFAULT_CHUNK_DATA_SIZE]; // Start of buffer
112  uint8_t* m_buffTail; // End of buffer
113  uint8_t* m_dataHead; // Front of data in buffer. This moves as data is read.
114  uint8_t* m_dataTail; // End of data in buffer. This moves as data is written.
115 };
116 
117 
118 #endif // DATA_CHUNK_H
uint32_t invDataSize
Bitwise inverse of chunk data length.
Definition: DataChunk.h:49
#define DEFAULT_CHUNK_DATA_SIZE
Definition: DataChunk.h:20
uint32_t GetBuffSize()
Definition: DataChunk.h:82
uint8_t * m_dataTail
Definition: DataChunk.h:114
uint32_t GetBuffFree()
Definition: DataChunk.h:83
size_t count(InputIterator first, InputIterator last, T const &item)
Definition: catch.hpp:3206
#define DID_COUNT
Definition: data_sets.h:138
#define PUSH_PACK_1
Definition: ISConstants.h:231
#define NULL
Definition: nm_bsp.h:52
uint32_t devSerialNum
Device serial number.
Definition: DataChunk.h:51
uint16_t version
Chunk Version.
Definition: DataChunk.h:44
ROSCONSOLE_DECL void print(FilterBase *filter, void *logger, Level level, const char *file, int line, const char *function, const char *fmt,...) ROSCONSOLE_PRINTF_ATTRIBUTE(7
uint32_t grpNum
Chunk Group Number: 0 = serial data, 1 = sorted data...
Definition: DataChunk.h:50
uint8_t * m_buffTail
Definition: DataChunk.h:112
uint32_t GetDataSize()
Definition: DataChunk.h:84
uint32_t dataSize
Chunk data length in bytes.
Definition: DataChunk.h:48
uint8_t * m_dataHead
Definition: DataChunk.h:113
void logStats(const char *format,...)
Chunk Header.
Definition: DataChunk.cpp:278
uint16_t classification
Chunk classification.
Definition: DataChunk.h:45
uint32_t pHandle
Device port handle.
Definition: DataChunk.h:52
#define POP_PACK
Definition: ISConstants.h:234
uint32_t reserved
Unused.
Definition: DataChunk.h:53
uint32_t marker
Chunk marker (0xFC05EA32)
Definition: DataChunk.h:43
sChunkHeader m_hdr
Definition: DataChunk.h:94


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:57