C++ Instrument Catalog
CPT2026PeripheralROM.cpp
Go to the documentation of this file.
1 
6 // Standard includes
7 
8 // Personal includes
9 #include "CPT2026PeripheralROM.h"
10 #include "Helpers.h"
11 
12 // External tools includes
13 #include "date.h"
14 
15 using namespace MTL;
16 
17 // Utilities
18 #define UNUSED_VAR(x) (void)x; // Prevents from unereferenced variable when compiling in release
19 
20 //----------------------------------------------------------------------//
21 // Conversion Utilities //
22 //----------------------------------------------------------------------//
23 // From Human representation (Atomic size: 1 byte, Endianness: Little endian)
24 // To local machine representation
25 // Both IEEE 754 format
26 inline U16 l_PeripheralBufferToU16(const U8* it)
27 {
28 #ifdef _WIN64
29  return static_cast<U16>(*it) << 8 | static_cast<U16>(*(it + 1));
30 #endif
31 }
32 inline I16 l_PeripheralBufferToI16(const U8* it)
33 {
34 #ifdef _WIN64
35  return static_cast<I16>(static_cast<U16>(*it) << 8 | static_cast<U16>(*(it + 1)));
36 #endif
37 }
38 inline U32 l_PeripheralBufferToU32(const U8* it)
39 {
40 #ifdef _WIN64
41  return static_cast<U32>(*it) << 24 | static_cast<U32>(*(it + 1)) << 16 | static_cast<U32>(*(it + 2)) << 8 | static_cast<U32>(*(it + 3));
42 #endif
43 }
44 inline I32 l_PeripheralBufferToI32(const U8* it)
45 {
46 #ifdef _WIN64
47  return static_cast<I32>(static_cast<U32>(*it) << 24 | static_cast<U32>(*(it + 1)) << 16 | static_cast<U32>(*(it + 2)) << 8 | static_cast<U32>(*(it + 3)));
48 #endif
49 }
50 inline F32 l_PeripheralBufferToF32(const U8* it)
51 {
52 #ifdef _WIN64
53  U32 l_swap = static_cast<U32>(it[0]) << 24 |
54  static_cast<U32>(it[1]) << 16 |
55  static_cast<U32>(it[2]) << 8 |
56  static_cast<U32>(it[3]);
57  return *reinterpret_cast<F32*>(&l_swap);
58 #endif
59 }
60 inline F64 l_PeripheralBufferToF64(const U8* it)
61 {
62 #ifdef _WIN64
63  U64 l_swap = static_cast<U64>(it[0]) << 56 |
64  static_cast<U64>(it[1]) << 48 |
65  static_cast<U64>(it[2]) << 40 |
66  static_cast<U64>(it[3]) << 32 |
67  static_cast<U64>(it[4]) << 24 |
68  static_cast<U64>(it[5]) << 16 |
69  static_cast<U64>(it[6]) << 8 |
70  static_cast<U64>(it[7]);
71  return *reinterpret_cast<F64*>(&l_swap);
72 #endif
73 }
74 inline void l_U16ToPeripheralBuffer(U16 n, U8* it)
75 {
76  *it++ = static_cast<U8>(n >> 8);
77  *it++ = static_cast<U8>(n);
78 }
79 inline void l_U16ArrayToPeripheralBuffer(const std::vector<U16> & rna, U8* it)
80 {
81  for (auto & l_it : rna)
82  {
83  l_U16ToPeripheralBuffer(l_it, it);
84  it += sizeof(U16);
85  }
86 }
87 inline void l_F64ToPeripheralBuffer(F64 f, U8* it)
88 {
89 #ifdef _WIN64
90  U64 l_swap = static_cast<U64>(reinterpret_cast<U8*>(&f)[0]) << 56 |
91  static_cast<U64>(reinterpret_cast<U8*>(&f)[1]) << 48 |
92  static_cast<U64>(reinterpret_cast<U8*>(&f)[2]) << 40 |
93  static_cast<U64>(reinterpret_cast<U8*>(&f)[3]) << 32 |
94  static_cast<U64>(reinterpret_cast<U8*>(&f)[4]) << 24 |
95  static_cast<U64>(reinterpret_cast<U8*>(&f)[5]) << 16 |
96  static_cast<U64>(reinterpret_cast<U8*>(&f)[6]) << 8 |
97  static_cast<U64>(reinterpret_cast<U8*>(&f)[7]);
98  std::memcpy(&*it, &l_swap, sizeof(F64));
99 #endif
100 }
101 inline void l_F64ArrayToPeripheralBuffer(std::vector<F64> fa, U8* it)
102 {
103  for (auto & l_it : fa)
104  l_F64ToPeripheralBuffer(l_it, it += sizeof(F64));
105 }
106 inline void l_F32ToPeripheralBuffer(F32 f, U8* it)
107 {
108 #ifdef _WIN64
109  U32 l_swap = static_cast<U32>(reinterpret_cast<U8*>(&f)[0]) << 24 |
110  static_cast<U32>(reinterpret_cast<U8*>(&f)[1]) << 16 |
111  static_cast<U32>(reinterpret_cast<U8*>(&f)[2]) << 8 |
112  static_cast<U32>(reinterpret_cast<U8*>(&f)[3]);
113  std::memcpy(&*it, &l_swap, sizeof(F32));
114 #endif
115 }
116 inline void l_F32ArrayToPeripheralBuffer(std::vector<F32> fa, U8* it)
117 {
118  for (auto & l_it : fa)
119  {
120  l_F32ToPeripheralBuffer(l_it, it);
121  it += sizeof(F32);
122  }
123 }
124 
125 U8 l_CRC(std::vector<U8>::const_iterator beg, std::vector<U8>::const_iterator end)
126 {
127  U8 l_CRC_Val = 0;
128  for (; beg != end; beg++)
129  l_CRC_Val ^= *beg;
130  return l_CRC_Val;
131 }
132 
133 //----------------------------------------------------------------------//
134 // High Level Methods //
135 //----------------------------------------------------------------------//
137 {
138  try
139  {
140  U16 l_ROMVersion;
141  if (!l_HeaderVersion(l_ROMVersion))
142  throw false;
143 
144  switch (l_ROMVersion)
145  {
147  {
148  m_HeaderType = kStandalone;
149  l_ParseStaticHeader(m_StdandaloneHeader);
150  l_ParseParmInfo(m_StdandaloneHeader.HEADER_LEN, m_ParmInfoMap);
151  break;
152  }
154  {
155  m_HeaderType = kEmbedded;
156  l_ParseStaticHeader(m_EmbeddedHeader);
157  l_ParseParmInfo(m_EmbeddedHeader.HEADER_LEN, m_ParmInfoMap);
158  break;
159  }
160  default:
161  MTL_Assert(false);
162  break;
163  }
164  }
165  catch (bool & rE)
166  {
167  UNUSED_VAR(rE);
168  return false;
169  }
170  return true;
171 }
172 
174 {
175  switch (m_HeaderType)
176  {
177  case kStandalone:
178  rID = m_StdandaloneHeader.Identification;
179  return true;
180  break;
181  default:
182  return false;
183  break;
184  }
185 }
186 
187 bool CPT2026PeripheralROM::Parser::ParmAddress(U8 ParmNo, U16 & rParmAddress)
188 {
189  CParmInfoMap::const_iterator l_it = m_ParmInfoMap.find(ParmNo);
190  if (m_ParmInfoMap.end() != l_it)
191  {
192  rParmAddress = l_it->second;
193  return true;
194  }
195  else
196  {
197  rParmAddress = 0;
198  return false;
199  }
200 }
201 
203 {
204  return m_HeaderType;
205 }
206 
208 {
209  UNUSED_VAR(rHeader);
210  return m_StdandaloneHeader;
211 }
212 
214 {
215  UNUSED_VAR(rHeader);
216  return m_EmbeddedHeader;
217 }
218 
219 //----------------------------------------------------------------------//
220 // Common Type Parsing Methods //
221 //----------------------------------------------------------------------//
222 bool CPT2026PeripheralROM::Parser::l_ParseIdentification(sIdentification & rId, std::vector<U8>::const_iterator Id_beg, std::vector<U8>::const_iterator Id_end)
223 {
224  try
225  {
226  if (static_cast<size_t>(Id_end - Id_beg) < sIdentification::IDENTIFICATION_LEN)
227  throw false;
228  // Parse
229  rId.ProtocolVersion = static_cast<U16>(static_cast<U16>(*Id_beg) << 8 | *(Id_beg + 1));
230  rId.DeviceType = static_cast<eDeviceType>(*(Id_beg + 2));
231  rId.Model = static_cast<U16>(static_cast<U16>(*(Id_beg + 3)) << 8 | static_cast<U16>(*(Id_beg + 4)));
232  rId.SN = static_cast<U32>(*(Id_beg + 5)) << 16 | static_cast<U32>(*(Id_beg + 6)) << 8 | *(Id_beg + 7);
233  rId.Capabilities = static_cast<U32>(*(Id_beg + 8)) << 24 | static_cast<U32>(*(Id_beg + 9)) << 16 | static_cast<U32>(*(Id_beg + 10)) << 8 | *(Id_beg + 11);
234  }
235  catch (...)
236  {
237  return false;
238  }
239  return true;
240 }
241 
242 bool CPT2026PeripheralROM::Parser::l_HeaderVersion(U16 & rVersion)
243 {
244  try
245  {
246  rVersion = static_cast<U16>(static_cast<U16>(*m_beg) << 8 | *(m_beg + 1));
247  }
248  catch (...)
249  {
250  return false;
251  }
252  return true;
253 }
254 
255 bool CPT2026PeripheralROM::Parser::l_ParseStaticHeader(sStandaloneStaticHeader & rHeader)
256 {
257  try
258  {
259  // Check version
260  if (!l_HeaderVersion(rHeader.ROMVersion) || rHeader.ROMVersion != sStandaloneStaticHeader::VERSION)
261  return false;
262  // Check CRC
263  if (0 != l_CRC(m_beg, m_beg + sStandaloneStaticHeader::HEADER_LEN))
264  return false;
265 
266  // Parse
267  rHeader.HeaderCRC = *(m_beg + sStandaloneStaticHeader::HEADER_LEN - 1);
268  rHeader.ROMCapacity = static_cast<U16>(static_cast<U16>(*(m_beg + 2)) << 8 | *(m_beg + 3));
269  rHeader.ROMSize = static_cast<U16>(static_cast<U16>(*(m_beg + 4)) << 8 | *(m_beg + 5));
270  std::copy(m_beg + 6, m_beg + 6 + sStandaloneStaticHeader::DATE_LEN, rHeader.ROMProgrammingDate);
271  if (!l_ParseIdentification(rHeader.Identification, m_beg + 16, m_end))
272  return false;
273  }
274  catch (...)
275  {
276  return false;
277  }
278  return true;
279 }
280 
281 bool CPT2026PeripheralROM::Parser::l_ParseStaticHeader(sEmbeddedStaticHeader & rHeader)
282 {
283  try
284  {
285  // Check version
286  if (!l_HeaderVersion(rHeader.ROMVersion) || rHeader.ROMVersion != sEmbeddedStaticHeader::VERSION)
287  return false;
288  // Check CRC
289  rHeader.HeaderCRC = *(m_beg + sEmbeddedStaticHeader::HEADER_LEN - 1);
290  if (rHeader.HeaderCRC != l_CRC(m_beg, m_beg + sEmbeddedStaticHeader::HEADER_LEN))
291  return false;
292 
293  // Parse
294  rHeader.ROMCapacity = static_cast<U16>(static_cast<U16>(*(m_beg + 2)) << 8 | *(m_beg + 3));
295  rHeader.ROMSize = static_cast<U16>(static_cast<U16>(*(m_beg + 4)) << 8 | *(m_beg + 5));
296  std::copy(m_beg + 6, m_beg + 6 + sEmbeddedStaticHeader::DATE_LEN, rHeader.ROMProgrammingDate);
297  }
298  catch (...)
299  {
300  return false;
301  }
302  return true;
303 }
304 
305 bool CPT2026PeripheralROM::Parser::l_ParseParmInfo(size_t HeaderLen, CParmInfoMap & rParmInfoMap)
306 {
307  try
308  {
309  std::vector<U8>::const_iterator l_beg = m_beg + HeaderLen;
310 
311  // Parse
312  U16 l_NoParms = static_cast<U16>(static_cast<U16>(*l_beg) << 8 | *(l_beg + 1));
313 
314  l_beg += 2;
315  for (U16 l_NoParsedParmInfo = 0; l_NoParsedParmInfo < l_NoParms; l_NoParsedParmInfo++, l_beg += 3)
316  rParmInfoMap.emplace(*l_beg, static_cast<U16>(*(l_beg + 1)) << 8 | *(l_beg + 2)); // ParmNo / Address
317  }
318  catch (...)
319  {
320  return false;
321  }
322  return true;
323 }
324 
325 //----------------------------------------------------------------------//
326 // Peripheral Type Parsing Methods //
327 //----------------------------------------------------------------------//
329 {
330  try
331  {
332  std::vector<U8>::const_iterator l_it = m_beg + ParmAddress;
333 
334  U16 l_ManDateLen = static_cast<U16>(static_cast<U16>(*l_it) << 8 | *(l_it + 1));
335  l_it += 2;
336  rManuInfo.ManufacturingDate = std::string(l_it, l_it + l_ManDateLen);
337  l_it += l_ManDateLen;
338 
339  U16 l_DesLen = static_cast<U16>(static_cast<U16>(*l_it) << 8 | *(l_it + 1));
340  l_it += 2;
341  rManuInfo.Designation = std::string(l_it, l_it + l_DesLen);
342  }
343  catch (...)
344  {
345  return false;
346  }
347  return true;
348 }
349 
350 bool CPT2026PeripheralROM::Parser::ParseMultiHeadInfo(size_t ParmAddress, sMultiHeadInfo & rMultiHeadInfo)
351 {
352  try
353  {
354  rMultiHeadInfo.MultiHeadInfo.clear();
355 
356  std::vector<U8>::const_iterator l_it = m_beg + ParmAddress;
357 
358  rMultiHeadInfo.StructVersion = l_PeripheralBufferToU16(&(*l_it)); l_it += sizeof(rMultiHeadInfo.StructVersion);
359  if (rMultiHeadInfo.StructVersion != sMultiHeadInfo::STRUCT_VERSION) return false;
360 
361  rMultiHeadInfo.OffsetDAC = l_PeripheralBufferToU16(&(*l_it)); l_it += sizeof(rMultiHeadInfo.OffsetDAC);
362 
363  U8 l_NoHeads = l_it[0]; l_it += sizeof(l_NoHeads);
364  for (U8 HeadNo = 0; HeadNo < l_NoHeads; HeadNo++)
365  {
366  sHeadInfo l_HeadInfo;
367  l_HeadInfo.MUXcode = l_it[0];
368  l_HeadInfo.Info = l_it[1];
369  l_HeadInfo.PhysInfoSetIndex = l_it[2];
370  l_it += sHeadInfo::SIZE;
371  rMultiHeadInfo.MultiHeadInfo.push_back(l_HeadInfo);
372  }
373  }
374  catch (...)
375  {
376  return false;
377  }
378  return true;
379 }
380 
381 bool CPT2026PeripheralROM::Parser::ParseHeadList(size_t ParmAddress, tHeadList & rHeadList)
382 {
383  try
384  {
385  std::vector<U8>::const_iterator l_it = m_beg + ParmAddress;
386 
387  rHeadList.clear();
388  U8 l_NoHeads = l_it[0];
389  l_it++;
390  rHeadList = tHeadList(l_it, l_it + l_NoHeads);
391  }
392  catch (...)
393  {
394  return false;
395  }
396  return true;
397 }
398 
400 {
401  try
402  {
403  std::vector<U8>::const_iterator l_it = m_beg + ParmAddress;
404 
405  rPhysInfo.Version = l_PeripheralBufferToU16(&(*l_it)); l_it += sizeof(rPhysInfo.Version);
407  rPhysInfo.LowFreq = l_PeripheralBufferToF64(&(*l_it)); l_it += sizeof(rPhysInfo.LowFreq);
408  rPhysInfo.NominalFreq = l_PeripheralBufferToF64(&(*l_it)); l_it += sizeof(rPhysInfo.NominalFreq);
409  rPhysInfo.HighFreq = l_PeripheralBufferToF64(&(*l_it)); l_it += sizeof(rPhysInfo.HighFreq);
410  rPhysInfo.GyroRatio = l_PeripheralBufferToF64(&(*l_it)); l_it += sizeof(rPhysInfo.GyroRatio);
411  U8 l_NormalizationDateSize = l_it[0];
412  l_it++;
413  rPhysInfo.NormalizationDate = std::string(l_it, l_it + l_NormalizationDateSize);
414  l_it += l_NormalizationDateSize;
415  U8 l_NbCorrections = l_it[0]; l_it += sizeof(l_NbCorrections);
416  for (U8 HeadNo = 0; HeadNo < l_NbCorrections; HeadNo++, l_it += sizeof(F32))
417  rPhysInfo.NormalizationTable.push_back(l_PeripheralBufferToF32(&(*l_it)));
418  }
419  catch (...)
420  {
421  return false;
422  }
423  return true;
424 }
425 
426 bool CPT2026PeripheralROM::Parser::ParsePwPhysicalInfo(size_t ParmAddress, sPwPhysicalInformation & rPhysInfo, std::vector<U8>::const_iterator & rpBuffer)
427 {
428  try
429  {
430  std::vector<U8>::const_iterator l_it = m_beg + ParmAddress;
431 
432  U16 l_StructVersion = l_PeripheralBufferToU16(&(*l_it)); l_it += sizeof(U16);
433  if (l_StructVersion != sPwPhysicalInformation::HANDLED_PWP_PHYSICAL_INFORMATION_VERSION) return false;
434  rPhysInfo.MinFreq = l_PeripheralBufferToF64(&(*l_it)); l_it += sizeof(F64);
435  rPhysInfo.MaxFreq = l_PeripheralBufferToF64(&(*l_it)); l_it += sizeof(F64);
436  rPhysInfo.MinIF = l_PeripheralBufferToF64(&(*l_it)); l_it += sizeof(F64);
437  rPhysInfo.MaxIF = l_PeripheralBufferToF64(&(*l_it)); l_it += sizeof(F64);
438  rPhysInfo.FreqMultiplier = l_PeripheralBufferToF64(&(*l_it)); l_it += sizeof(F64);
439  rPhysInfo.GyroRatio = l_PeripheralBufferToF64(&(*l_it)); l_it += sizeof(F64);
440  rPhysInfo.PulsePeriod = l_PeripheralBufferToF64(&(*l_it)); l_it += sizeof(F64);
441  rPhysInfo.T2 = l_PeripheralBufferToF64(&(*l_it)); l_it += sizeof(F64);
442  rPhysInfo.SampleLength = l_PeripheralBufferToF64(&(*l_it)); l_it += sizeof(F64);
443  rPhysInfo.DeadTime = l_it[0]; l_it += 1;
444  // Get Noise Level curve
445  U16 l_NoNoiseLevelElements = l_PeripheralBufferToU16(&(*l_it)); l_it += sizeof(U16);
446  if (l_NoNoiseLevelElements > sPwPhysicalInformation::MAX_CURVE_SIZE) return false;
447  for (U16 l_PointNo = 0; l_PointNo < l_NoNoiseLevelElements; l_PointNo++, l_it += sizeof(U16))
448  rPhysInfo.NoiseLevelCurve.push_back(l_PeripheralBufferToU16(&(*l_it)));
449  // Get Tuning curve
450  U16 l_NoTuningElements = l_PeripheralBufferToU16(&(*l_it)); l_it += sizeof(U16);
451  if (l_NoTuningElements > sPwPhysicalInformation::MAX_CURVE_SIZE) return false;
452  for (U16 l_PointNo = 0; l_PointNo < l_NoTuningElements; l_PointNo++, l_it += sizeof(U16))
453  rPhysInfo.TuningCurve.push_back(l_PeripheralBufferToU16(&(*l_it)));
454  // Get Matching curve
455  U16 l_NoMatchingElements = l_PeripheralBufferToU16(&(*l_it)); l_it += sizeof(U16);
456  if (l_NoMatchingElements > sPwPhysicalInformation::MAX_CURVE_SIZE) return false;
457  for (U16 l_PointNo = 0; l_PointNo < l_NoMatchingElements; l_PointNo++, l_it += sizeof(U16))
458  rPhysInfo.MatchingCurve.push_back(l_PeripheralBufferToU16(&(*l_it)));
459  // Get pulse width curve
460  U16 l_NoPulseWidthElements = l_PeripheralBufferToU16(&(*l_it)); l_it += sizeof(U16);
461  if (l_NoPulseWidthElements > sPwPhysicalInformation::MAX_CURVE_SIZE) return false;
462  for (U16 l_PointNo = 0; l_PointNo < l_NoPulseWidthElements; l_PointNo++, l_it += sizeof(U16))
463  rPhysInfo.PulseWidthCurve.push_back(l_PeripheralBufferToU16(&(*l_it)));
464  // Get Freq step curve
465  U16 l_NoFreqStepElements = l_PeripheralBufferToU16(&(*l_it)); l_it += sizeof(U16);
466  if (l_NoFreqStepElements > sPwPhysicalInformation::MAX_CURVE_SIZE) return false;
467  for (U16 l_PointNo = 0; l_PointNo < l_NoFreqStepElements; l_PointNo++, l_it += sizeof(U16))
468  rPhysInfo.FreqStepCurve.push_back(l_PeripheralBufferToU16(&(*l_it)));
469 
470  rpBuffer = l_it;
471  }
472  catch (...)
473  {
474  return false;
475  }
476  return true;
477 }
478 
480 {
481  try
482  {
483  std::vector<U8>::const_iterator l_it = m_beg + ParmAddress;
484 
485  U8 l_NoSets = l_it[0];
486  l_it++;
487  for (U8 SetNo = 0; SetNo < l_NoSets; SetNo++)
488  {
490  if (ParsePwPhysicalInfo(static_cast<size_t>(l_it - m_beg), *pPwPhysInfo, l_it))
491  rPwPhysInfoSet.Attach(pPwPhysInfo);
492  else
493  return false;
494  }
495  }
496  catch (...)
497  {
498  return false;
499  }
500  return true;
501 }
502 
504 {
505  try
506  {
507  std::vector<U8>::const_iterator l_it = m_beg + ParmAddress;
508 
509  U16 l_StructVersion = l_PeripheralBufferToU16(&(*l_it)); l_it += 2;
510  if (l_StructVersion != sPwFCAPhysInfo::HANDLED_PW_FCA_PHYSICAL_INFORMATION_VERSION) return false;
511  rPhysInfo.MinFreq = l_PeripheralBufferToF64(&(*l_it)); l_it += 8;
512  rPhysInfo.MaxFreq = l_PeripheralBufferToF64(&(*l_it)); l_it += 8;
513  rPhysInfo.MinIF = l_PeripheralBufferToF64(&(*l_it)); l_it += 8;
514  rPhysInfo.MaxIF = l_PeripheralBufferToF64(&(*l_it)); l_it += 8;
515  rPhysInfo.FreqMultiplier = l_PeripheralBufferToF64(&(*l_it)); l_it += 8;
516  rPhysInfo.VoltageNoise = l_PeripheralBufferToU16(&(*l_it)); l_it += 2;
517  }
518  catch (...)
519  {
520  return false;
521  }
522  return true;
523 }
524 
526 {
527  try
528  {
529  std::vector<U8>::const_iterator l_it = m_beg + ParmAddress;
530 
531  U16 l_StructVersion = l_PeripheralBufferToU16(&(*l_it)); l_it += 2;
532  if (l_StructVersion != sHallInformation::STRUCT_VERSION) return false;
533  // Get the state
534  rHallInfo.State = *l_it; l_it += 1;
535  // Get the range
536  rHallInfo.Range_mT = l_PeripheralBufferToU16(&(*l_it)); l_it += 2;
537  // Get the tolerance
538  rHallInfo.Tolerance = *l_it; l_it += 1;
539  // Get the calibration coefficients
540  rHallInfo.Calibration.B0X = l_PeripheralBufferToU16(&(*l_it)); l_it += 2;
541  rHallInfo.Calibration.B0Y = l_PeripheralBufferToU16(&(*l_it)); l_it += 2;
542  rHallInfo.Calibration.B0Z = l_PeripheralBufferToU16(&(*l_it)); l_it += 2;
543  rHallInfo.Calibration.G0X = l_PeripheralBufferToF32(&(*l_it)); l_it += 4;
544  rHallInfo.Calibration.G0Y = l_PeripheralBufferToF32(&(*l_it)); l_it += 4;
545  rHallInfo.Calibration.G0Z = l_PeripheralBufferToF32(&(*l_it)); l_it += 4;
546  rHallInfo.Calibration.T0 = l_PeripheralBufferToU16(&(*l_it)); l_it += 2;
547  rHallInfo.Calibration.CT0X = l_PeripheralBufferToF32(&(*l_it)); l_it += 4;
548  rHallInfo.Calibration.CT0Y = l_PeripheralBufferToF32(&(*l_it)); l_it += 4;
549  rHallInfo.Calibration.CT0Z = l_PeripheralBufferToF32(&(*l_it)); l_it += 4;
550  rHallInfo.Calibration.CTGX = l_PeripheralBufferToF32(&(*l_it)); l_it += 4;
551  rHallInfo.Calibration.CTGY = l_PeripheralBufferToF32(&(*l_it)); l_it += 4;
552  rHallInfo.Calibration.CTGZ = l_PeripheralBufferToF32(&(*l_it)); l_it += 4;
553  }
554  catch (...)
555  {
556  return false;
557  }
558  return true;
559 }
560 
561 std::vector<U8> CPT2026PeripheralROM::Builder::l_Raw(const CPT2026PeripheralROM::sIdentification & rId)
562 {
563  std::vector<U8> l_Raw(rId.IDENTIFICATION_LEN, 0); // Allocate fixed size memory
564  auto l_it = l_Raw.begin();
565 
566  *l_it++ = static_cast<U8>(rId.ProtocolVersion >> 8); // Fill data
567  *l_it++ = static_cast<U8>(rId.ProtocolVersion);
568  *l_it++ = static_cast<U8>(rId.DeviceType);
569  *l_it++ = static_cast<U8>(rId.Model >> 8);
570  *l_it++ = static_cast<U8>(rId.Model);
571  *l_it++ = static_cast<U8>(rId.SN >> 16);
572  *l_it++ = static_cast<U8>(rId.SN >> 8);
573  *l_it++ = static_cast<U8>(rId.SN);
574  *l_it++ = static_cast<U8>(rId.Capabilities >> 24);
575  *l_it++ = static_cast<U8>(rId.Capabilities >> 16);
576  *l_it++ = static_cast<U8>(rId.Capabilities >> 8);
577  *l_it++ = static_cast<U8>(rId.Capabilities);
578 
579  return l_Raw;
580 }
581 
583 {
584  std::vector<U8> l_Raw;
585 
586  l_U16ToPeripheralBuffer(rHallInfo.STRUCT_VERSION, &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0));
587  l_Raw.push_back(rHallInfo.State);
588  l_U16ToPeripheralBuffer(rHallInfo.Range_mT, &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0));
589  l_Raw.push_back(rHallInfo.Tolerance);
590  l_U16ToPeripheralBuffer(rHallInfo.Calibration.B0X, &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0));
591  l_U16ToPeripheralBuffer(rHallInfo.Calibration.B0Y, &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0));
592  l_U16ToPeripheralBuffer(rHallInfo.Calibration.B0Z, &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0));
593  l_F32ToPeripheralBuffer(rHallInfo.Calibration.G0X, &*l_Raw.insert(l_Raw.end(), sizeof(F32), 0));
594  l_F32ToPeripheralBuffer(rHallInfo.Calibration.G0Y, &*l_Raw.insert(l_Raw.end(), sizeof(F32), 0));
595  l_F32ToPeripheralBuffer(rHallInfo.Calibration.G0Z, &*l_Raw.insert(l_Raw.end(), sizeof(F32), 0));
596  l_U16ToPeripheralBuffer(rHallInfo.Calibration.T0, &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0));
597  l_F32ToPeripheralBuffer(rHallInfo.Calibration.CT0X, &*l_Raw.insert(l_Raw.end(), sizeof(F32), 0));
598  l_F32ToPeripheralBuffer(rHallInfo.Calibration.CT0Y, &*l_Raw.insert(l_Raw.end(), sizeof(F32), 0));
599  l_F32ToPeripheralBuffer(rHallInfo.Calibration.CT0Z, &*l_Raw.insert(l_Raw.end(), sizeof(F32), 0));
600  l_F32ToPeripheralBuffer(rHallInfo.Calibration.CTGX, &*l_Raw.insert(l_Raw.end(), sizeof(F32), 0));
601  l_F32ToPeripheralBuffer(rHallInfo.Calibration.CTGY, &*l_Raw.insert(l_Raw.end(), sizeof(F32), 0));
602  l_F32ToPeripheralBuffer(rHallInfo.Calibration.CTGZ, &*l_Raw.insert(l_Raw.end(), sizeof(F32), 0));
603 
604  return l_Raw;
605 }
606 
608 {
609  std::vector<U8> l_Raw;
610 
611  l_U16ToPeripheralBuffer(static_cast<U16>(rManInfo.ManufacturingDate.length()), &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0));
612  l_Raw.insert(l_Raw.end(), rManInfo.ManufacturingDate.begin(), rManInfo.ManufacturingDate.end());
613  l_U16ToPeripheralBuffer(static_cast<U16>(rManInfo.Designation.length()), &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0));
614  l_Raw.insert(l_Raw.end(), rManInfo.Designation.begin(), rManInfo.Designation.end());
615 
616  return l_Raw;
617 }
618 
620 {
621  std::vector<U8> l_Raw;
622 
623  l_Raw.push_back(rMultHeadInfo.STRUCT_VERSION >> 8);
624  l_Raw.push_back(rMultHeadInfo.STRUCT_VERSION);
625  l_Raw.push_back(static_cast<U8>(rMultHeadInfo.OffsetDAC >> 8));
626  l_Raw.push_back(static_cast<U8>(rMultHeadInfo.OffsetDAC));
627  l_Raw.push_back(static_cast<U8>(rMultHeadInfo.MultiHeadInfo.size()));
628  for (auto & l_it : rMultHeadInfo.MultiHeadInfo)
629  {
630  l_Raw.push_back(l_it.MUXcode);
631  l_Raw.push_back(l_it.Info);
632  l_Raw.push_back(l_it.PhysInfoSetIndex);
633  }
634 
635  return l_Raw;
636 }
637 
639 {
640  std::vector<U8> l_Raw;
641 
642  l_Raw.push_back(static_cast<U8>(rHeadList.size()));
643  l_Raw.insert(l_Raw.end(), rHeadList.begin(), rHeadList.end());
644 
645  return l_Raw;
646 }
647 
649 {
650  std::vector<U8> l_Raw;
651 
652  l_U16ToPeripheralBuffer(rPwCamPhysInfo.HANDLED_PW_CAM_PHYSICAL_INFORMATION_VERSION, &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0));
653  l_F64ToPeripheralBuffer(rPwCamPhysInfo.LowFreq, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
654  l_F64ToPeripheralBuffer(rPwCamPhysInfo.NominalFreq, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
655  l_F64ToPeripheralBuffer(rPwCamPhysInfo.HighFreq, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
656  l_F64ToPeripheralBuffer(rPwCamPhysInfo.GyroRatio, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
657  l_Raw.push_back(static_cast<U8>(rPwCamPhysInfo.NormalizationDate.length()));
658  l_Raw.insert(l_Raw.end(), rPwCamPhysInfo.NormalizationDate.begin(), rPwCamPhysInfo.NormalizationDate.end());
659  U8 l_NbNormElements = static_cast<U8>(rPwCamPhysInfo.NormalizationTable.size());
660  l_Raw.push_back(static_cast<U8>(l_NbNormElements));
661  l_F32ArrayToPeripheralBuffer(rPwCamPhysInfo.NormalizationTable, &*l_Raw.insert(l_Raw.end(), l_NbNormElements * sizeof(F32), 0));
662 
663  return l_Raw;
664 }
665 
667 {
668  std::vector<U8> l_Raw;
669 
670  l_U16ToPeripheralBuffer(rPwFCAPhysInfo.HANDLED_PW_FCA_PHYSICAL_INFORMATION_VERSION, &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0));
671  l_F64ToPeripheralBuffer(rPwFCAPhysInfo.MinFreq, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
672  l_F64ToPeripheralBuffer(rPwFCAPhysInfo.MaxFreq, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
673  l_F64ToPeripheralBuffer(rPwFCAPhysInfo.MinIF, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
674  l_F64ToPeripheralBuffer(rPwFCAPhysInfo.MaxIF, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
675  l_F64ToPeripheralBuffer(rPwFCAPhysInfo.FreqMultiplier, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
676  l_U16ToPeripheralBuffer(rPwFCAPhysInfo.VoltageNoise, &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0));
677 
678  return l_Raw;
679 }
680 
682 {
683  std::vector<U8> l_Raw;
684 
685  l_U16ToPeripheralBuffer(rPwPhysInfo.HANDLED_PWP_PHYSICAL_INFORMATION_VERSION, &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0));
686  l_F64ToPeripheralBuffer(rPwPhysInfo.MinFreq, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
687  l_F64ToPeripheralBuffer(rPwPhysInfo.MaxFreq, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
688  l_F64ToPeripheralBuffer(rPwPhysInfo.MinIF, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
689  l_F64ToPeripheralBuffer(rPwPhysInfo.MaxIF, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
690  l_F64ToPeripheralBuffer(rPwPhysInfo.FreqMultiplier, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
691  l_F64ToPeripheralBuffer(rPwPhysInfo.GyroRatio, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
692  l_F64ToPeripheralBuffer(rPwPhysInfo.PulsePeriod, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
693  l_F64ToPeripheralBuffer(rPwPhysInfo.T2, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
694  l_F64ToPeripheralBuffer(rPwPhysInfo.SampleLength, &*l_Raw.insert(l_Raw.end(), sizeof(F64), 0));
695  l_Raw.push_back(rPwPhysInfo.DeadTime);
696  U16 l_NbElements = static_cast<U16>(rPwPhysInfo.NoiseLevelCurve.size());
697  l_U16ToPeripheralBuffer(l_NbElements, &*l_Raw.insert(l_Raw.end(), sizeof(l_NbElements), 0));
698  if (0 != l_NbElements)
699  l_U16ArrayToPeripheralBuffer(rPwPhysInfo.NoiseLevelCurve, &*l_Raw.insert(l_Raw.end(), l_NbElements * sizeof(U16), 0));
700  l_NbElements = static_cast<U16>(rPwPhysInfo.TuningCurve.size());
701  l_U16ToPeripheralBuffer(l_NbElements, &*l_Raw.insert(l_Raw.end(), sizeof(l_NbElements), 0));
702  if (0 != l_NbElements)
703  l_U16ArrayToPeripheralBuffer(rPwPhysInfo.TuningCurve, &*l_Raw.insert(l_Raw.end(), l_NbElements * sizeof(U16), 0));
704  l_NbElements = static_cast<U16>(rPwPhysInfo.MatchingCurve.size());
705  l_U16ToPeripheralBuffer(l_NbElements, &*l_Raw.insert(l_Raw.end(), sizeof(l_NbElements), 0));
706  if (0 != l_NbElements)
707  l_U16ArrayToPeripheralBuffer(rPwPhysInfo.MatchingCurve, &*l_Raw.insert(l_Raw.end(), l_NbElements * sizeof(U16), 0));
708  l_NbElements = static_cast<U16>(rPwPhysInfo.PulseWidthCurve.size());
709  l_U16ToPeripheralBuffer(l_NbElements, &*l_Raw.insert(l_Raw.end(), sizeof(l_NbElements), 0));
710  if (0 != l_NbElements)
711  l_U16ArrayToPeripheralBuffer(rPwPhysInfo.PulseWidthCurve, &*l_Raw.insert(l_Raw.end(), l_NbElements * sizeof(U16), 0));
712  l_NbElements = static_cast<U16>(rPwPhysInfo.FreqStepCurve.size());
713  l_U16ToPeripheralBuffer(l_NbElements, &*l_Raw.insert(l_Raw.end(), sizeof(l_NbElements), 0));
714  if (0 != l_NbElements)
715  l_U16ArrayToPeripheralBuffer(rPwPhysInfo.FreqStepCurve, &*l_Raw.insert(l_Raw.end(), l_NbElements * sizeof(U16), 0));
716 
717  return l_Raw;
718 }
719 
721 {
722  std::vector<U8> l_Raw;
723 
724  l_Raw.push_back(static_cast<U8>(rPwPhysInfoSet.size())); // Number of PwParmInfo structs in the set
725  for (CPT2026PeripheralROM::sPwPhysicalInformationSet::size_type l_index = 0; l_index < rPwPhysInfoSet.size(); l_index++)
726  {
727  std::vector<U8> l_RawPhPhysInfo = Raw(rPwPhysInfoSet[l_index]);
728  l_Raw.insert(l_Raw.end(), l_RawPhPhysInfo.begin(), l_RawPhPhysInfo.end());
729  }
730 
731  return l_Raw;
732 }
733 
734 CPT2026PeripheralROM::CParmInfoMap CPT2026PeripheralROM::Builder::l_BuildParmInfo(const tParmContentInfo & rParmContent, U16 BaseAddress, size_t & rParmDataSize)
735 {
736  rParmDataSize = 0;
737  CParmInfoMap l_ParmInfo;
738  for (auto & l_it : rParmContent)
739  {
740  l_ParmInfo.insert(std::pair<U8, U16>(l_it.ParmNumber, BaseAddress));
741  BaseAddress += static_cast<U16>(l_it.rParmData.size());
742  rParmDataSize += l_it.rParmData.size();
743  }
744  return l_ParmInfo;
745 }
746 
747 CPT2026PeripheralROM::CParmInfoMap CPT2026PeripheralROM::Builder::l_BuildParmInfo(const tParmContentInfo & rParmContent, U16 BaseAddress, std::vector<U8> & rGeneratedParmData)
748 {
749  rGeneratedParmData.clear();
750  CParmInfoMap l_ParmInfo;
751  for (auto & l_it : rParmContent)
752  {
753  l_ParmInfo.insert(std::pair<U8, U16>(l_it.ParmNumber, BaseAddress));
754  BaseAddress += static_cast<U16>(l_it.rParmData.size());
755  rGeneratedParmData.insert(rGeneratedParmData.end(), l_it.rParmData.begin(), l_it.rParmData.end());
756  }
757  return l_ParmInfo;
758 }
759 
760 std::vector<U8> CPT2026PeripheralROM::Builder::l_Raw(const sStandaloneStaticHeader & rHeader)
761 {
762  std::vector<U8> l_Raw;
763 
764  l_Raw.push_back(static_cast<U8>(rHeader.ROMVersion >> 8));
765  l_Raw.push_back(static_cast<U8>(rHeader.ROMVersion));
766  l_Raw.push_back(static_cast<U8>(rHeader.ROMCapacity >> 8));
767  l_Raw.push_back(static_cast<U8>(rHeader.ROMCapacity));
768  l_Raw.push_back(static_cast<U8>(rHeader.ROMSize >> 8));
769  l_Raw.push_back(static_cast<U8>(rHeader.ROMSize));
770  std::memcpy(&*l_Raw.insert(l_Raw.end(), sStandaloneStaticHeader::DATE_LEN, 0), rHeader.ROMProgrammingDate, sStandaloneStaticHeader::DATE_LEN);
771  std::vector<U8> l_RawId = CPT2026PeripheralROM::Builder::l_Raw(rHeader.Identification);
772  l_Raw.insert(l_Raw.end(), l_RawId.begin(), l_RawId.end());
773  l_Raw.push_back(l_CRC(l_Raw.begin(), l_Raw.begin() + l_Raw.size()));
774 
775  MTL_Assert(l_Raw.size() == rHeader.HEADER_LEN);
776 
777  return l_Raw;
778 }
779 
780 std::vector<U8> CPT2026PeripheralROM::Builder::l_Raw(const sEmbeddedStaticHeader & rHeader)
781 {
782  std::vector<U8> l_Raw;
783 
784  l_Raw.push_back(static_cast<U8>(rHeader.ROMVersion >> 8));
785  l_Raw.push_back(static_cast<U8>(rHeader.ROMVersion));
786  l_Raw.push_back(static_cast<U8>(rHeader.ROMCapacity >> 8));
787  l_Raw.push_back(static_cast<U8>(rHeader.ROMCapacity));
788  l_Raw.push_back(static_cast<U8>(rHeader.ROMSize >> 8));
789  l_Raw.push_back(static_cast<U8>(rHeader.ROMSize));
790  std::memcpy(&*l_Raw.insert(l_Raw.end(), sEmbeddedStaticHeader::DATE_LEN, 0), rHeader.ROMProgrammingDate, sEmbeddedStaticHeader::DATE_LEN);
791  l_Raw.push_back(l_CRC(l_Raw.begin(), l_Raw.begin() + l_Raw.size()));
792 
793  MTL_Assert(l_Raw.size() == rHeader.HEADER_LEN);
794 
795  return l_Raw;
796 }
797 
798 std::vector<U8> CPT2026PeripheralROM::Builder::l_Raw(const CParmInfoMap & rParmInfo)
799 {
800  std::vector<U8> l_Raw;
801 
802  l_U16ToPeripheralBuffer(static_cast<U16>(rParmInfo.size()), &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0)); // NbParms
803  for (auto & l_it : rParmInfo)
804  {
805  l_Raw.push_back(l_it.first); // Device Parm Number
806  l_U16ToPeripheralBuffer(l_it.second, &*l_Raw.insert(l_Raw.end(), sizeof(U16), 0)); // Parm address
807  }
808 
809  return l_Raw;
810 }
811 
812 template <typename HeaderType>
813 std::vector<U8> CPT2026PeripheralROM::Builder::l_BuildROM(HeaderType Header, const tParmContentInfo & rParmContent)
814 {
815  // Compute sizes
816  size_t l_HeaderLen = Header.HEADER_LEN;
817  size_t l_ParmInfoLen, l_ParmDataLen;
818  l_ParmInfoLen = (l_Raw(l_BuildParmInfo(rParmContent, 0, l_ParmDataLen))).size(); // Build a dummy raw parm info from a dummy base address to get the sizes
819 
820  // Prepare header
821  Header.ROMVersion = Header.VERSION;
822  //Header.ROMCapacity must have been previously filled
823  Header.ROMSize = static_cast<U16>(l_HeaderLen + l_ParmInfoLen + l_ParmDataLen);
824  Header.HeaderCRC = 0;
825  std::vector<U8> l_RawHeaderBuff = l_Raw(Header);
826 
827  // Prepare parm info
828  std::vector<U8> l_ParmDataBuff;
829  CParmInfoMap l_ParmInfoMap = l_BuildParmInfo(rParmContent, static_cast<U16>(l_HeaderLen + l_ParmInfoLen), l_ParmDataBuff);
830  std::vector<U8> l_RawParmInfoBuff = l_Raw(l_ParmInfoMap);
831 
832  // Fill ROM
833  std::vector<U8> l_ROM;
834  l_ROM.insert(l_ROM.end(), l_RawHeaderBuff.begin(), l_RawHeaderBuff.end());
835  l_ROM.insert(l_ROM.end(), l_RawParmInfoBuff.begin(), l_RawParmInfoBuff.end());
836  l_ROM.insert(l_ROM.end(), l_ParmDataBuff.begin(), l_ParmDataBuff.end());
837 
838  return l_ROM;
839 }
840 
842 {
843  return CPT2026PeripheralROM::Builder::l_BuildROM(Header, rParmContent);
844 }
845 
847 {
848  return CPT2026PeripheralROM::Builder::l_BuildROM(Header, rParmContent);
849 }
850 
851 void CPT2026PeripheralROM::Builder::Build1226ROM( std::vector<U8> & rOutputROM,
854  const CPT2026PeripheralROM::sHallInformation & rHallInfo)
855 {
856  rOutputROM.clear();
857 
858  std::vector<U8> l_RawManInfo = CPT2026PeripheralROM::Builder::Raw(rManInfo);
859  std::vector<U8> l_RawPwPhysInfo = CPT2026PeripheralROM::Builder::Raw(rPwPhysInfo);
860  std::vector<U8> l_RawHallInfo = CPT2026PeripheralROM::Builder::Raw(rHallInfo);
861 
863  {
864  { static_cast<U8>(CPT2026PeripheralROM::e1226ROMParm::kManufactureInformation), l_RawManInfo },
865  { static_cast<U8>(CPT2026PeripheralROM::e1226ROMParm::kPwPhysicalInformation), l_RawPwPhysInfo },
866  { static_cast<U8>(CPT2026PeripheralROM::e1226ROMParm::kHallInformation), l_RawHallInfo }
867  };
868 
870  //l_Header.ROMVersion // Auto handled in BuildROM
871  l_Header.ROMCapacity = 1024;
872  //l_Header.ROMSize // Auto handled in BuildROM
873  std::memcpy(l_Header.ROMProgrammingDate, date::format("%F", std::chrono::system_clock::now()).c_str(), l_Header.DATE_LEN);
874 
875  rOutputROM = BuildROM(l_Header, l_ParmInfo);
876 }
877 
878 void CPT2026PeripheralROM::Builder::Build9046ROM(std::vector<U8> & rOutputROM,
879  const CPT2026PeripheralROM::sIdentification & rIdentification,
881  const CPT2026PeripheralROM::sMultiHeadInfo & rMultiHeadInfo,
882  const CPT2026PeripheralROM::tHeadList & rSearchHeadList,
883  const CPT2026PeripheralROM::tHeadList & rMeasHeadList,
884  const CPT2026PeripheralROM::sPwCamPhysicalInfo & rPwCamPhysInfo,
886 {
887  rOutputROM.clear();
888 
889  std::vector<U8> l_RawManInfo = CPT2026PeripheralROM::Builder::Raw(rManInfo);
890  std::vector<U8> l_RawMultiHeadInfo = CPT2026PeripheralROM::Builder::Raw(rMultiHeadInfo);
891  std::vector<U8> l_RawSearchHeadList = CPT2026PeripheralROM::Builder::Raw(rSearchHeadList);
892  std::vector<U8> l_RawMeasHeadList = CPT2026PeripheralROM::Builder::Raw(rMeasHeadList);
893  std::vector<U8> l_RawPwCamPhysInfo = CPT2026PeripheralROM::Builder::Raw(rPwCamPhysInfo);
894  std::vector<U8> l_RawPwPhysInfoSet = CPT2026PeripheralROM::Builder::Raw(rPwPhysInfoSet);
895 
897  {
898  { static_cast<U8>(CPT2026PeripheralROM::e9046ROMParm::kManufactureInformation), l_RawManInfo },
899  { static_cast<U8>(CPT2026PeripheralROM::e9046ROMParm::kMultiHeadInformation), l_RawMultiHeadInfo },
900  { static_cast<U8>(CPT2026PeripheralROM::e9046ROMParm::kSearchHeads), l_RawSearchHeadList },
901  { static_cast<U8>(CPT2026PeripheralROM::e9046ROMParm::kMeasHeads), l_RawMeasHeadList },
902  { static_cast<U8>(CPT2026PeripheralROM::e9046ROMParm::kPwCamPhysicalInformation), l_RawPwCamPhysInfo },
903  { static_cast<U8>(CPT2026PeripheralROM::e9046ROMParm::kPwPhysicalInformationSet), l_RawPwPhysInfoSet }
904  };
905 
907  //l_Header.ROMVersion // Auto handled in BuildROM
908  l_Header.ROMCapacity = 8192;
909  //l_Header.ROMSize // Auto handled in BuildROM
910  std::memcpy(l_Header.ROMProgrammingDate, date::format("%F", std::chrono::system_clock::now()).c_str(), l_Header.DATE_LEN);
911  l_Header.Identification = rIdentification;
912 
913  rOutputROM = BuildROM(l_Header, l_ParmInfo);
914 }
MTL::CPT2026PeripheralROM::Parser::Header
sStandaloneStaticHeader Header(const sStandaloneStaticHeader &rHeader)
Definition: CPT2026PeripheralROM.cpp:207
MTL::CPT2026PeripheralROM::sMultiHeadInfo::MultiHeadInfo
std::vector< sHeadInfo > MultiHeadInfo
Definition: CPT2026PeripheralROM.h:191
MTL::CPT2026PeripheralROM::sPwCamPhysicalInfo::NormalizationTable
tNormalizationTable NormalizationTable
Definition: CPT2026PeripheralROM.h:220
MTL::CPT2026PeripheralROM::sStandaloneStaticHeader::HEADER_LEN
static const size_t HEADER_LEN
Definition: CPT2026PeripheralROM.h:60
l_CRC
U8 l_CRC(std::vector< U8 >::const_iterator beg, std::vector< U8 >::const_iterator end)
Definition: CPT2026PeripheralROM.cpp:125
MTL::CPT2026PeripheralROM::sIdentification::SN
U32 SN
Definition: CPT2026PeripheralROM.h:46
MTL::CPT2026PeripheralROM::sIdentification::ProtocolVersion
U16 ProtocolVersion
Definition: CPT2026PeripheralROM.h:43
MTL::CPT2026PeripheralROM::sStandaloneStaticHeader
Definition: CPT2026PeripheralROM.h:56
MTL::CPT2026PeripheralROM::e9046ROMParm::kManufactureInformation
@ kManufactureInformation
MTL::CPT2026PeripheralROM::sMultiHeadInfo::OffsetDAC
U16 OffsetDAC
Definition: CPT2026PeripheralROM.h:190
MTL::CPT2026PeripheralROM::sEmbeddedStaticHeader::VERSION
static const U16 VERSION
Definition: CPT2026PeripheralROM.h:71
MTL::CPT2026PeripheralROM::sHallInformation::sCalibration::G0Y
F32 G0Y
Definition: CPT2026PeripheralROM.h:240
MTL::CPT2026PeripheralROM::sHallInformation::sCalibration::CT0Y
F32 CT0Y
Definition: CPT2026PeripheralROM.h:242
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::NoiseLevelCurve
std::vector< U16 > NoiseLevelCurve
Definition: CPT2026PeripheralROM.h:102
MTL::CPT2026PeripheralROM::Parser::ParmAddress
bool ParmAddress(U8 ParmNo, U16 &rParmAddress)
Definition: CPT2026PeripheralROM.cpp:187
MTL::CPT2026PeripheralROM::Parser::HeaderType
eHeaderType HeaderType()
Definition: CPT2026PeripheralROM.cpp:202
MTL::CPT2026PeripheralROM::sEmbeddedStaticHeader::DATE_LEN
static const size_t DATE_LEN
Definition: CPT2026PeripheralROM.h:72
MTL::CPT2026PeripheralROM::sHallInformation::sCalibration::G0Z
F32 G0Z
Definition: CPT2026PeripheralROM.h:240
MTL::CPT2026PeripheralROM::sPwFCAPhysInfo::MinIF
F64 MinIF
Definition: CPT2026PeripheralROM.h:162
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::TuningCurve
std::vector< U16 > TuningCurve
Definition: CPT2026PeripheralROM.h:103
MTL::CPT2026PeripheralROM::sPwFCAPhysInfo::FreqMultiplier
F64 FreqMultiplier
Definition: CPT2026PeripheralROM.h:164
MTL::CPT2026PeripheralROM::sPwCamPhysicalInfo::Version
U16 Version
Definition: CPT2026PeripheralROM.h:214
MTL::CPT2026PeripheralROM::sPwPhysicalInformationSet
Definition: CPT2026PeripheralROM.h:112
MTL::CPT2026PeripheralROM::sHallInformation::sCalibration::B0Z
U16 B0Z
Definition: CPT2026PeripheralROM.h:239
MTL::CPT2026PeripheralROM::sHeadInfo
Definition: CPT2026PeripheralROM.h:177
MTL::CPT2026PeripheralROM::sPwPhysicalInformation
Definition: CPT2026PeripheralROM.h:90
MTL::CPT2026PeripheralROM::eDeviceType
eDeviceType
Definition: CPT2026PeripheralROM.h:32
l_PeripheralBufferToU16
U16 l_PeripheralBufferToU16(const U8 *it)
Definition: CPT2026PeripheralROM.cpp:26
MTL::CPT2026PeripheralROM::sPwCamPhysicalInfo::GyroRatio
F64 GyroRatio
Definition: CPT2026PeripheralROM.h:218
MTL::CPT2026PeripheralROM::CParmInfoMap
Definition: CPT2026PeripheralROM.h:81
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::DeadTime
U8 DeadTime
Definition: CPT2026PeripheralROM.h:101
MTL::CPT2026PeripheralROM::sHeadInfo::Info
U8 Info
Definition: CPT2026PeripheralROM.h:182
MTL::CPT2026PeripheralROM::sPwFCAPhysInfo::HANDLED_PW_FCA_PHYSICAL_INFORMATION_VERSION
static const U16 HANDLED_PW_FCA_PHYSICAL_INFORMATION_VERSION
Definition: CPT2026PeripheralROM.h:171
MTL::CPT2026PeripheralROM::sPwCamPhysicalInfo
Definition: CPT2026PeripheralROM.h:213
MTL::CPT2026PeripheralROM::eHeaderType
eHeaderType
Definition: CPT2026PeripheralROM.h:27
MTL::CPT2026PeripheralROM::e1226ROMParm::kManufactureInformation
@ kManufactureInformation
MTL::CPT2026PeripheralROM::e9046ROMParm::kPwPhysicalInformationSet
@ kPwPhysicalInformationSet
MTL::CPT2026PeripheralROM::sIdentification::Capabilities
U32 Capabilities
Definition: CPT2026PeripheralROM.h:47
MTL::CPT2026PeripheralROM::sStandaloneStaticHeader::VERSION
static const U16 VERSION
Definition: CPT2026PeripheralROM.h:58
MTL::CPT2026PeripheralROM::sManufactureInformation::Designation
std::string Designation
Definition: CPT2026PeripheralROM.h:54
MTL::CPT2026PeripheralROM::Parser::ParseHallInfo
bool ParseHallInfo(size_t ParmAddress, sHallInformation &rHallInfo)
Definition: CPT2026PeripheralROM.cpp:525
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::FreqMultiplier
F64 FreqMultiplier
Definition: CPT2026PeripheralROM.h:96
MTL::CPT2026PeripheralROM::sHeadInfo::PhysInfoSetIndex
U8 PhysInfoSetIndex
Definition: CPT2026PeripheralROM.h:183
MTL::CPT2026PeripheralROM::sManufactureInformation
Definition: CPT2026PeripheralROM.h:52
MTL::CPT2026PeripheralROM::sStandaloneStaticHeader::Identification
sIdentification Identification
Definition: CPT2026PeripheralROM.h:66
MTL::CPT2026PeripheralROM::sHallInformation::sCalibration::CTGX
F32 CTGX
Definition: CPT2026PeripheralROM.h:243
MTL::CPT2026PeripheralROM::sHallInformation::sCalibration::CTGY
F32 CTGY
Definition: CPT2026PeripheralROM.h:243
MTL::CPT2026PeripheralROM::e9046ROMParm::kMeasHeads
@ kMeasHeads
MTL::CPT2026PeripheralROM::sIdentification::Model
U16 Model
Definition: CPT2026PeripheralROM.h:45
MTL::CPT2026PeripheralROM::sPwFCAPhysInfo::VoltageNoise
U16 VoltageNoise
Definition: CPT2026PeripheralROM.h:165
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::FreqStepCurve
std::vector< U16 > FreqStepCurve
Definition: CPT2026PeripheralROM.h:106
MTL::CPT2026PeripheralROM::sIdentification::DeviceType
eDeviceType DeviceType
Definition: CPT2026PeripheralROM.h:44
l_U16ToPeripheralBuffer
void l_U16ToPeripheralBuffer(U16 n, U8 *it)
Definition: CPT2026PeripheralROM.cpp:74
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::SampleLength
F64 SampleLength
Definition: CPT2026PeripheralROM.h:100
MTL::CPT2026PeripheralROM::Parser::ParsePwCamPhysInfo
bool ParsePwCamPhysInfo(size_t ParmAddress, sPwCamPhysicalInfo &rPhysInfo)
Definition: CPT2026PeripheralROM.cpp:399
l_U16ArrayToPeripheralBuffer
void l_U16ArrayToPeripheralBuffer(const std::vector< U16 > &rna, U8 *it)
Definition: CPT2026PeripheralROM.cpp:79
MTL::CPT2026PeripheralROM::sPwFCAPhysInfo
Definition: CPT2026PeripheralROM.h:158
CPT2026PeripheralROM.h
MTL::CPT2026PeripheralROM::sPwCamPhysicalInfo::NominalFreq
F64 NominalFreq
Definition: CPT2026PeripheralROM.h:216
MTL::CPT2026PeripheralROM::sIdentification
Definition: CPT2026PeripheralROM.h:41
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::MinIF
F64 MinIF
Definition: CPT2026PeripheralROM.h:94
Helpers.h
Collection of utility macros for error messages.
date::format
auto format(const std::locale &loc, const CharT *fmt, const Streamable &tp) -> decltype(to_stream(std::declval< std::basic_ostream< CharT > & >(), fmt, tp), std::basic_string< CharT >
Definition: date.h:6005
MTL_Assert
#define MTL_Assert
Definition: Helpers.h:44
MTL::CPT2026PeripheralROM::sPwCamPhysicalInfo::NormalizationDate
std::string NormalizationDate
Definition: CPT2026PeripheralROM.h:219
l_F32ArrayToPeripheralBuffer
void l_F32ArrayToPeripheralBuffer(std::vector< F32 > fa, U8 *it)
Definition: CPT2026PeripheralROM.cpp:116
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::MAX_CURVE_SIZE
static const U32 MAX_CURVE_SIZE
Definition: CPT2026PeripheralROM.h:108
MTL::CPT2026PeripheralROM::sMultiHeadInfo::StructVersion
U16 StructVersion
Definition: CPT2026PeripheralROM.h:189
MTL::CPT2026PeripheralROM::sHallInformation::Range_mT
U16 Range_mT
Definition: CPT2026PeripheralROM.h:235
MTL::CPT2026PeripheralROM::sHeadInfo::MUXcode
U8 MUXcode
Definition: CPT2026PeripheralROM.h:181
MTL::CPT2026PeripheralROM::e9046ROMParm::kMultiHeadInformation
@ kMultiHeadInformation
MTL::CPT2026PeripheralROM::sHallInformation::sCalibration::CT0X
F32 CT0X
Definition: CPT2026PeripheralROM.h:242
date.h
MTL::CPT2026PeripheralROM::sHallInformation::sCalibration::T0
U16 T0
Definition: CPT2026PeripheralROM.h:241
MTL::CPT2026PeripheralROM::sStandaloneStaticHeader::ROMCapacity
U16 ROMCapacity
Definition: CPT2026PeripheralROM.h:63
MTL::CPT2026PeripheralROM::sPwPhysicalInformationSet::Attach
void Attach(sPwPhysicalInformation *pPwPhysInfo)
Definition: CPT2026PeripheralROM.h:125
MTL::CPT2026PeripheralROM::sPwCamPhysicalInfo::HANDLED_PW_CAM_PHYSICAL_INFORMATION_VERSION
static const U16 HANDLED_PW_CAM_PHYSICAL_INFORMATION_VERSION
Definition: CPT2026PeripheralROM.h:222
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::PulseWidthCurve
std::vector< U16 > PulseWidthCurve
Definition: CPT2026PeripheralROM.h:105
l_F64ArrayToPeripheralBuffer
void l_F64ArrayToPeripheralBuffer(std::vector< F64 > fa, U8 *it)
Definition: CPT2026PeripheralROM.cpp:101
MTL
Definition: CPT2026PeripheralROM.h:19
MTL::CPT2026PeripheralROM::sHeadInfo::SIZE
static const U16 SIZE
Definition: CPT2026PeripheralROM.h:179
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::GyroRatio
F64 GyroRatio
Definition: CPT2026PeripheralROM.h:97
MTL::CPT2026PeripheralROM::e9046ROMParm::kSearchHeads
@ kSearchHeads
MTL::CPT2026PeripheralROM::sStandaloneStaticHeader::ROMProgrammingDate
char ROMProgrammingDate[DATE_LEN]
Definition: CPT2026PeripheralROM.h:65
MTL::CPT2026PeripheralROM::sPwPhysicalInformationSet::size
size_type size(void) const
Definition: CPT2026PeripheralROM.h:129
MTL::CPT2026PeripheralROM::Parser::ParseManufactureInformation
bool ParseManufactureInformation(size_t ParmAddress, sManufactureInformation &rManuInfo)
Definition: CPT2026PeripheralROM.cpp:328
MTL::CPT2026PeripheralROM::kStandalone
@ kStandalone
Definition: CPT2026PeripheralROM.h:27
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::T2
F64 T2
Definition: CPT2026PeripheralROM.h:99
MTL::CPT2026PeripheralROM::sEmbeddedStaticHeader
Definition: CPT2026PeripheralROM.h:69
MTL::CPT2026PeripheralROM::tHeadList
std::vector< U8 > tHeadList
Definition: CPT2026PeripheralROM.h:194
MTL::CPT2026PeripheralROM::sHallInformation::sCalibration::G0X
F32 G0X
Definition: CPT2026PeripheralROM.h:240
MTL::CPT2026PeripheralROM::sHallInformation
Definition: CPT2026PeripheralROM.h:228
MTL::CPT2026PeripheralROM::Builder::Raw
static std::vector< U8 > Raw(const CPT2026PeripheralROM::sHallInformation &rHallInfo)
Definition: CPT2026PeripheralROM.cpp:582
l_PeripheralBufferToI32
I32 l_PeripheralBufferToI32(const U8 *it)
Definition: CPT2026PeripheralROM.cpp:44
MTL::CPT2026PeripheralROM::sHallInformation::sCalibration::CTGZ
F32 CTGZ
Definition: CPT2026PeripheralROM.h:243
MTL::CPT2026PeripheralROM::sPwPhysicalInformationSet::size_type
std::vector< sPwPhysicalInformation * >::size_type size_type
Definition: CPT2026PeripheralROM.h:118
MTL::CPT2026PeripheralROM::e1226ROMParm::kPwPhysicalInformation
@ kPwPhysicalInformation
UNUSED_VAR
#define UNUSED_VAR(x)
Definition: CPT2026PeripheralROM.cpp:18
MTL::CPT2026PeripheralROM::Parser::ParseMultiHeadInfo
bool ParseMultiHeadInfo(size_t ParmAddress, sMultiHeadInfo &rMultiHeadInfo)
Definition: CPT2026PeripheralROM.cpp:350
MTL::CPT2026PeripheralROM::e9046ROMParm::kPwCamPhysicalInformation
@ kPwCamPhysicalInformation
MTL::CPT2026PeripheralROM::sPwFCAPhysInfo::MaxIF
F64 MaxIF
Definition: CPT2026PeripheralROM.h:163
MTL::CPT2026PeripheralROM::e1226ROMParm::kHallInformation
@ kHallInformation
l_F64ToPeripheralBuffer
void l_F64ToPeripheralBuffer(F64 f, U8 *it)
Definition: CPT2026PeripheralROM.cpp:87
MTL::CPT2026PeripheralROM::Parser::ParsePwPhysInfoSet
bool ParsePwPhysInfoSet(size_t ParmAddress, sPwPhysicalInformationSet &rPwPhysInfoSet)
Definition: CPT2026PeripheralROM.cpp:479
MTL::CPT2026PeripheralROM::sStandaloneStaticHeader::DATE_LEN
static const size_t DATE_LEN
Definition: CPT2026PeripheralROM.h:59
MTL::CPT2026PeripheralROM::sHallInformation::State
U8 State
Definition: CPT2026PeripheralROM.h:234
MTL::CPT2026PeripheralROM::sEmbeddedStaticHeader::ROMProgrammingDate
char ROMProgrammingDate[DATE_LEN]
Definition: CPT2026PeripheralROM.h:78
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::HANDLED_PWP_PHYSICAL_INFORMATION_VERSION
static const U16 HANDLED_PWP_PHYSICAL_INFORMATION_VERSION
Definition: CPT2026PeripheralROM.h:109
MTL::CPT2026PeripheralROM::Parser::Parse
bool Parse()
Definition: CPT2026PeripheralROM.cpp:136
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::MaxFreq
F64 MaxFreq
Definition: CPT2026PeripheralROM.h:93
MTL::CPT2026PeripheralROM::sHallInformation::sCalibration::B0Y
U16 B0Y
Definition: CPT2026PeripheralROM.h:239
MTL::CPT2026PeripheralROM::sEmbeddedStaticHeader::HEADER_LEN
static const size_t HEADER_LEN
Definition: CPT2026PeripheralROM.h:73
l_F32ToPeripheralBuffer
void l_F32ToPeripheralBuffer(F32 f, U8 *it)
Definition: CPT2026PeripheralROM.cpp:106
MTL::CPT2026PeripheralROM::sHallInformation::Tolerance
U8 Tolerance
Definition: CPT2026PeripheralROM.h:236
MTL::CPT2026PeripheralROM::sHallInformation::Calibration
struct MTL::CPT2026PeripheralROM::sHallInformation::sCalibration Calibration
l_PeripheralBufferToU32
U32 l_PeripheralBufferToU32(const U8 *it)
Definition: CPT2026PeripheralROM.cpp:38
MTL::CPT2026PeripheralROM::Parser::ParsePwPhysicalInfo
bool ParsePwPhysicalInfo(size_t ParmAddress, sPwPhysicalInformation &rPhysInfo, std::vector< U8 >::const_iterator &rpBuffer)
Definition: CPT2026PeripheralROM.cpp:426
MTL::CPT2026PeripheralROM::sPwFCAPhysInfo::MinFreq
F64 MinFreq
Definition: CPT2026PeripheralROM.h:160
MTL::CPT2026PeripheralROM::sEmbeddedStaticHeader::ROMCapacity
U16 ROMCapacity
Definition: CPT2026PeripheralROM.h:76
MTL::CPT2026PeripheralROM::Parser::ParsePwFcaPhysInfo
bool ParsePwFcaPhysInfo(size_t ParmAddress, sPwFCAPhysInfo &rPhysInfo)
Definition: CPT2026PeripheralROM.cpp:503
MTL::CPT2026PeripheralROM::sHallInformation::sCalibration::CT0Z
F32 CT0Z
Definition: CPT2026PeripheralROM.h:242
MTL::CPT2026PeripheralROM::sHallInformation::sCalibration::B0X
U16 B0X
Definition: CPT2026PeripheralROM.h:239
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::MaxIF
F64 MaxIF
Definition: CPT2026PeripheralROM.h:95
MTL::CPT2026PeripheralROM::Parser::ParseHeadList
bool ParseHeadList(size_t ParmAddress, tHeadList &rHeadList)
Definition: CPT2026PeripheralROM.cpp:381
MTL::CPT2026PeripheralROM::kEmbedded
@ kEmbedded
Definition: CPT2026PeripheralROM.h:27
l_PeripheralBufferToI16
I16 l_PeripheralBufferToI16(const U8 *it)
Definition: CPT2026PeripheralROM.cpp:32
MTL::CPT2026PeripheralROM::Builder::tParmContentInfo
std::vector< sParmContent > tParmContentInfo
Definition: CPT2026PeripheralROM.h:368
MTL::CPT2026PeripheralROM::Builder::Build9046ROM
static void Build9046ROM(std::vector< U8 > &rOutputROM, const CPT2026PeripheralROM::sIdentification &rIdentification, const CPT2026PeripheralROM::sManufactureInformation &rManInfo, const CPT2026PeripheralROM::sMultiHeadInfo &rMultiHeadInfo, const CPT2026PeripheralROM::tHeadList &rSearchHeadList, const CPT2026PeripheralROM::tHeadList &rMeasHeadList, const CPT2026PeripheralROM::sPwCamPhysicalInfo &rPwCamPhysInfo, const CPT2026PeripheralROM::sPwPhysicalInformationSet &rPwPhysInfoSet)
Definition: CPT2026PeripheralROM.cpp:878
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::MinFreq
F64 MinFreq
Definition: CPT2026PeripheralROM.h:92
MTL::CPT2026PeripheralROM::sIdentification::IDENTIFICATION_LEN
static const size_t IDENTIFICATION_LEN
Definition: CPT2026PeripheralROM.h:50
MTL::CPT2026PeripheralROM::sPwFCAPhysInfo::MaxFreq
F64 MaxFreq
Definition: CPT2026PeripheralROM.h:161
l_PeripheralBufferToF64
F64 l_PeripheralBufferToF64(const U8 *it)
Definition: CPT2026PeripheralROM.cpp:60
MTL::CPT2026PeripheralROM::sMultiHeadInfo::STRUCT_VERSION
static const U16 STRUCT_VERSION
Definition: CPT2026PeripheralROM.h:187
MTL::CPT2026PeripheralROM::Parser::HasIdentification
bool HasIdentification(sIdentification &rID)
Definition: CPT2026PeripheralROM.cpp:173
MTL::CPT2026PeripheralROM::sManufactureInformation::ManufacturingDate
std::string ManufacturingDate
Definition: CPT2026PeripheralROM.h:53
MTL::CPT2026PeripheralROM::sPwCamPhysicalInfo::HighFreq
F64 HighFreq
Definition: CPT2026PeripheralROM.h:217
MTL::CPT2026PeripheralROM::sMultiHeadInfo
Definition: CPT2026PeripheralROM.h:185
MTL::CPT2026PeripheralROM::Builder::Build1226ROM
static void Build1226ROM(std::vector< U8 > &rOutputROM, const CPT2026PeripheralROM::sManufactureInformation &rManInfo, const CPT2026PeripheralROM::sPwPhysicalInformation &rPwPhysInfo, const CPT2026PeripheralROM::sHallInformation &rHallInfo)
Definition: CPT2026PeripheralROM.cpp:851
l_PeripheralBufferToF32
F32 l_PeripheralBufferToF32(const U8 *it)
Definition: CPT2026PeripheralROM.cpp:50
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::MatchingCurve
std::vector< U16 > MatchingCurve
Definition: CPT2026PeripheralROM.h:104
MTL::CPT2026PeripheralROM::Builder::BuildROM
static std::vector< U8 > BuildROM(sStandaloneStaticHeader Header, const tParmContentInfo &rParmContent)
Definition: CPT2026PeripheralROM.cpp:841
MTL::CPT2026PeripheralROM::sPwPhysicalInformation::PulsePeriod
F64 PulsePeriod
Definition: CPT2026PeripheralROM.h:98
MTL::CPT2026PeripheralROM::sPwCamPhysicalInfo::LowFreq
F64 LowFreq
Definition: CPT2026PeripheralROM.h:215
MTL::CPT2026PeripheralROM::sHallInformation::STRUCT_VERSION
static const U16 STRUCT_VERSION
Definition: CPT2026PeripheralROM.h:229