ADTF Device Toolbox SDK
Loading...
Searching...
No Matches
flexray_framevector.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include "flexray_frame.h"
11#include <adtf_utils.h>
12
16namespace adtf
17{
18
22namespace devicetb
23{
24
28namespace sdk
29{
30
34namespace flexray
35{
36
40namespace axle
41{
42
47{
48 uint8_t* m_pData;
49 int m_nDataSize;
50 int m_nDataSizeAllocated;
51 bool m_bDataRef;
52
53public:
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
77 tReference operator* () const
78 {
79 return (tReference) ((uint8_t*)(m_pDataVector->GetDataPtr()) + m_nCurrentOffset);
80 }
81
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
105public:
110 {
111 m_pData = NULL;
112 Init();
113 }
114
118 cFlexRayFrameVector(const void* pData, int nDataSize)
119 {
120 m_pData = (uint8_t*) pData;
121 m_nDataSizeAllocated = 0;
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;
144 m_nDataSizeAllocated = 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
void operator++()
Definition flexray_framevector.h:85
bool IsValid() const
Definition flexray_framevector.h:97
cIterator(const cFlexRayFrameVector *pDataVector)
Definition flexray_framevector.h:68
tReference operator*() const
Definition flexray_framevector.h:77
int GetSize() const
Definition flexray_framevector.h:158
tResult Append(const tFlexRayData *pFRData)
Definition flexray_framevector.h:174
cFlexRayFrameVector()
Definition flexray_framevector.h:109
~cFlexRayFrameVector()
Definition flexray_framevector.h:129
tResult Append(int nSize, tFlexRayData **pFRData)
Definition flexray_framevector.h:189
cFlexRayFrameVector(const void *pData, int nDataSize)
Definition flexray_framevector.h:118
void Init()
Definition flexray_framevector.h:140
const void * GetDataPtr() const
Definition flexray_framevector.h:150
cIterator GetFirst() const
Definition flexray_framevector.h:166
Namespace for functionality provided by V3.0.0.
Definition flexray_coder_intf.h:40
Namespace for FlexRay in ADTF-Devicetoolbox.
Definition flexray_coder_intf.h:34
axle::cFlexRayFrameVector cFlexRayFrameVector
Definition flexray_framevector.h:216
Namespace for SDK of ADTF-Devicetoolbox.
Definition bus_database_intf.h:42
Devicetoolbox - Namespace.
Definition bus_database_intf.h:36
ADTF - Namespace.
Definition bus_database_intf.h:30
uint16_t nSize
Total size in bytes of this structure.
Definition flexray_frame.h:130
tFR_TAG nTag
Tag of union (See tFR_TAG)
Definition flexray_frame.h:131
@ FR_TAG_INVALID
Tag for invalid data.
Definition flexray_frame.h:66