ADTF_DEVICE_TOOLBOX  3.12.1 (ADTF 3.18.3)
flexray_framevector.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include "flexray_frame.h"
11 #include <adtf_utils.h>
12 
16 namespace adtf
17 {
18 
22 namespace devicetb
23 {
24 
28 namespace sdk
29 {
30 
34 namespace flexray
35 {
36 
40 namespace axle
41 {
42 
47 {
48  uint8_t* m_pData;
51  bool m_bDataRef;
52 
53 public:
57  class cIterator
58  {
59  typedef const tFlexRayData* tReference;
60 
61  const cFlexRayFrameVector* m_pDataVector;
62  int m_nCurrentOffset;
63 
64  public:
68  cIterator(const cFlexRayFrameVector* pDataVector)
69  {
70  m_pDataVector = pDataVector;
71  m_nCurrentOffset = 0;
72  }
73 
78  {
79  return (tReference) ((uint8_t*)(m_pDataVector->GetDataPtr()) + m_nCurrentOffset);
80  }
81 
85  void operator++()
86  {
87  if (IsValid())
88  {
89  tReference pFRData = (tReference) ((uint8_t*)(m_pDataVector->GetDataPtr()) + m_nCurrentOffset);
90  m_nCurrentOffset += pFRData->nSize;
91  }
92  }
93 
97  bool IsValid() const
98  {
99  tReference pFRData = (tReference) ((uint8_t*)(m_pDataVector->GetDataPtr()) + m_nCurrentOffset);
100  return (m_nCurrentOffset < m_pDataVector->GetSize()
101  && pFRData->nSize != 0 && pFRData->nTag != tFlexRayData::FR_TAG_INVALID);
102  }
103  };
104 
105 public:
110  {
111  m_pData = NULL;
112  Init();
113  }
114 
118  cFlexRayFrameVector(const void* pData, int nDataSize)
119  {
120  m_pData = (uint8_t*) pData;
122  m_nDataSize = nDataSize;
123  m_bDataRef = true;
124  }
125 
130  {
131  if (m_pData != NULL && !m_bDataRef)
132  {
133  delete [] m_pData;
134  }
135  }
136 
140  void Init()
141  {
142  m_bDataRef = false;
143  m_nDataSize = 0;
145  }
146 
150  const void* GetDataPtr() const
151  {
152  return m_pData;
153  }
154 
158  int GetSize() const
159  {
160  return m_nDataSize;
161  }
162 
167  {
168  return cIterator(this);
169  }
170 
174  tResult Append(const tFlexRayData* pFRData)
175  {
176  RETURN_IF_POINTER_NULL(pFRData);
177  tFlexRayData* pNewData = NULL;
178  // if needed, enlarge the data area and return the pointer to the end
179  // of the last set data area
180  RETURN_IF_FAILED(Append(pFRData->nSize, &pNewData));
181  // copy the new data into the data area
182  adtf::util::cMemoryBlock::MemCopy(pNewData, pFRData, pFRData->nSize);
183  RETURN_NOERROR;
184  }
185 
189  tResult Append(int nSize, tFlexRayData** pFRData)
190  {
191  if (m_bDataRef)
192  {
193  RETURN_ERROR(ERR_UNEXPECTED);
194  }
195 
196  RETURN_IF_POINTER_NULL(pFRData);
197 
198  // If memory block is too small, it will be enlarged
199  if (m_nDataSize + nSize > m_nDataSizeAllocated)
200  {
201  int nNewDataSizeAllocated = m_nDataSizeAllocated + nSize + 4096;
202  uint8_t* pNewData = new uint8_t[nNewDataSizeAllocated];
203  adtf::util::cMemoryBlock::MemCopy(pNewData, m_pData, m_nDataSize);
204  delete [] m_pData;
205  m_pData = pNewData;
206  m_nDataSizeAllocated = nNewDataSizeAllocated;
207  }
208 
209  *pFRData = (tFlexRayData*) (m_pData + m_nDataSize);
210  m_nDataSize += nSize;
211  RETURN_NOERROR;
212  }
213 };
214 
215 } //namespace axle
217 } //namespace flexray
218 } //namespace sdk
219 } // namespace devicetb
220 } // namespace adtf
Internal iterator class, used to iterate over a frame vector.
void operator++()
Sets the iterator to the next frame of the vector.
tReference operator*() const
Returns the pointer to the frame, the iterator is currently pointing to.
cIterator(const cFlexRayFrameVector *pDataVector)
Constructs a new iterator object, which points to the first frame in the frame vector.
bool IsValid() const
Returns false, if the iterator points to an invalid frame or past the end of the vector.
Class for handling vectors of tFlexRayData structures.
tResult Append(const tFlexRayData *pFRData)
Appends a new frame to the internal frame vector.
cIterator GetFirst() const
Returns iterator pointing to first frame.
tResult Append(int nSize, tFlexRayData **pFRData)
Appends a new empty memory block to the internal frame vector and returns the pointer.
int GetSize() const
Returns size of internal stored frame vector.
const void * GetDataPtr() const
Returns pointer to internal stored frame vector.
int m_nDataSizeAllocated
Size of the (self) allocated data area.
cFlexRayFrameVector(const void *pData, int nDataSize)
Constructs a frame vector, referencing external data.
bool m_bDataRef
Indicates, that the memoryblock is allocated by another module.
int m_nDataSize
size of the data area (important if m_bDataRef is true)
Copyright 2024 CARIAD SE.
axle::cFlexRayFrameVector cFlexRayFrameVector
Class for handling vectors of tFlexRayData structures.
ADTF - Namespace.
FlexDay data structured is used for storing and transmitting FlexRay data.
Definition: flexray_frame.h:60
tFR_TAG nTag
Tag of union (See tFR_TAG)
uint16_t nSize
Total size in bytes of this structure.