C++Instrument Catalog MFC 1.2
Metrolab C++InstrumentCatalog for MFC
Loading...
Searching...
No Matches
CPT2026PeripheralROM.h
Go to the documentation of this file.
1
5
6#pragma once
7
8// Standard includes
9#include <assert.h>
10#include <unordered_map>
11
12// Personal includes
13#include "PT2026Types.h"
14#include "OSDefines.h"
15
16using namespace MTL::Instrument;
17using namespace MTL::Instrument::PT2026Types;
18
19namespace MTL {
20
22 {
23 //----------------------------------------------------------------------//
24 // Public Type Definitions //
25 //----------------------------------------------------------------------//
26 public:
28
29 //==================================================================================================//
30 // Common //
31 //==================================================================================================//
42 {
45 U16 Model;
46 U32 SN; // Effective size is 3 bytes long
48
49 static const size_t SN_LEN = 3;
50 static const size_t IDENTIFICATION_LEN = sizeof(U16) + sizeof(U8) + sizeof(U16) + SN_LEN + sizeof(U32);
51 };
53 std::string ManufacturingDate;
54 std::string Designation;
55 };
57 {
58 static const U16 VERSION = 0x0001;
59 static const size_t DATE_LEN = 10;
60 static const size_t HEADER_LEN = sizeof(U16) + sizeof(U16) + sizeof(U16) + DATE_LEN + sIdentification::IDENTIFICATION_LEN + sizeof(U8);
61
62 U16 ROMVersion; // Version of this structure in BCD format xx.yy
63 U16 ROMCapacity; // Memory capacity in number of bytes
64 U16 ROMSize; // Usage of the above capacity in number of bytes
65 char ROMProgrammingDate[DATE_LEN]; // Format: ISO-8601 extended calendar date "YYYY-MM-DD"
66 sIdentification Identification; // Identification of the device hosting the ROM
67 U8 HeaderCRC; // CRC of the header
68 };
70 {
71 static const U16 VERSION = 0x0002;
72 static const size_t DATE_LEN = 10;
73 static const size_t HEADER_LEN = sizeof(U16) + sizeof(U16) + sizeof(U16) + DATE_LEN + sizeof(U8);
74
75 U16 ROMVersion; // Version of this structure in BCD format xx.yy
76 U16 ROMCapacity; // Memory capacity in number of bytes
77 U16 ROMSize; // Usage of the above capacity in number of bytes
78 char ROMProgrammingDate[DATE_LEN]; // Format: ISO-8601 extended calendar date "YYYY-MM-DD"
79 U8 HeaderCRC; // CRC of the header
80 };
81 class CParmInfoMap : public std::unordered_map<U8, U16> // Composed of ParmNumber (U8) and its Address (U16)
82 {
83 public:
84 static const size_t PARM_INFO_LEN = sizeof(U8) + sizeof(U16);
85 };
86
87 //==================================================================================================//
88 // Pulsed Wave //
89 //==================================================================================================//
91 {
92 F64 MinFreq; // Minimum probe frequency [Hz]
93 F64 MaxFreq; // Maximum probe frequency [Hz]
94 F64 MinIF; // Minimum IF frequency [Hz]
95 F64 MaxIF; // Maximum IF frequency [Hz]
96 F64 FreqMultiplier; // Frequency multiplication factor [-]
97 F64 GyroRatio; // Gyromagnetic ratio [Hz/T]
98 F64 PulsePeriod; // Usually spin relaxing time T1 [s]
99 F64 T2; // Spin relaxing time T2 [s]
100 F64 SampleLength; // Sample length [s]
101 U8 DeadTime; // Dead time [us]
102 std::vector<U16> NoiseLevelCurve; // Noise level array [mV]
103 std::vector<U16> TuningCurve; // Tuning array [mV]
104 std::vector<U16> MatchingCurve; // Matching array [mV]
105 std::vector<U16> PulseWidthCurve; // Pulse width array [us]
106 std::vector<U16> FreqStepCurve; // Frequency steps array [Hz]
107
108 static const U32 MAX_CURVE_SIZE = 128;
110 };
111
113 {
114 private:
115 std::vector<sPwPhysicalInformation*> pPhysInfoList;
116
117 public:
118 typedef std::vector<sPwPhysicalInformation*>::size_type size_type;
119
121 {
122 for (std::vector<sPwPhysicalInformation*>::iterator it = pPhysInfoList.begin(); it != pPhysInfoList.end(); it++)
123 (*it)->~sPwPhysicalInformation();
124 }
126 {
127 pPhysInfoList.push_back(pPwPhysInfo);
128 }
129 size_type size(void) const
130 {
131 return pPhysInfoList.size();
132 }
134 {
135 assert(Index < pPhysInfoList.size());
136 return *(pPhysInfoList[Index]);
137 }
139 {
140 assert(Index < pPhysInfoList.size());
141 return *(pPhysInfoList[Index]);
142 }
143 };
144
146 {
152 sTransmissionTimes(U32 Short_us, U32 Extended_us)
153 : NMRTransTime_us(Short_us), ExtNMRTransTime_us(Extended_us)
154 {}
155 };
156 typedef std::vector<sTransmissionTimes> tTransmissionTimeList;
157
159 {
160 F64 MinFreq; // Minimum probe frequency [Hz]
161 F64 MaxFreq; // Maximum probe frequency [Hz]
162 F64 MinIF; // Minimum IF frequency [Hz]
163 F64 MaxIF; // Maximum IF frequency [Hz]
164 F64 FreqMultiplier; // Frequency multiplication factor [-]
165 U16 VoltageNoise; // Noise level across the bandpass [mV]
166
168 : MinFreq(0), MaxFreq(0), MinIF(0), MaxIF(0), FreqMultiplier(1), VoltageNoise(0)
169 {}
170
172 };
173
174 //==================================================================================================//
175 // Multi Head //
176 //==================================================================================================//
178 {
179 static const U16 SIZE = 3;
180
181 U8 MUXcode; // Multiplexing code
182 U8 Info; // Information bitfield (7-1: NA, 0 : IsEM8126)
183 U8 PhysInfoSetIndex; // Index of the physical information for this head
184 };
186 {
187 static const U16 STRUCT_VERSION = 0x0002;
188
190 U16 OffsetDAC; // DAC value for offset compensation
191 std::vector<sHeadInfo> MultiHeadInfo;
192 };
193
194 typedef std::vector<U8> tHeadList;
195
197 {
198 U8 HeadNumber; // Head number among the multiple heads
199 U8 PhysInfoSetIndex; // Index of the physical information for this head
200
201 sHeadDefinition(U8 HeadNum, U8 PhysInfInd)
202 : HeadNumber(HeadNum), PhysInfoSetIndex(PhysInfInd)
203 {}
204 };
205 #define HEAD_DEF_SIZE 2
206 typedef std::vector<sHeadDefinition> tHeadDefList;
207
208 //==================================================================================================//
209 // Camera //
210 //==================================================================================================//
211 typedef std::vector<F32> tNormalizationTable; // [Hz]
212
215 F64 LowFreq; // [Hz]
216 F64 NominalFreq; // [Hz]
217 F64 HighFreq; // [Hz]
218 F64 GyroRatio; // [Hz/T]
219 std::string NormalizationDate; // YYYY-MM-DD
221
223 };
224
225 //==================================================================================================//
226 // Hall //
227 //==================================================================================================//
229 static const U16 STRUCT_VERSION = 0x0002;
230 // State definition is as follows:
231 // bits 7-2 : NA
232 // bit 1 : Activated (Whether the hall sensor has to be used or not, for any reason)
233 // bit 0 : Calibrated (Whether Calibration struct contains valid calibration data or not)
234 U8 State; // State of the hall sensor
235 U16 Range_mT; // Hall sensor range in [mT]
236 U8 Tolerance; // Calibration tolerance [%]
238 // Coefficients correspond to a field B expressed in [T]
239 U16 B0X, B0Y, B0Z; // [bADC] B field offset correction factor for each axis
240 F32 G0X, G0Y, G0Z; // [T/bADC] B field gain correction factor for each axis
241 U16 T0; // [bADC] Temperature offset correction factor, common to all axis
242 F32 CT0X, CT0Y, CT0Z; // [T/bADC] Offset Temperature correction factor for each axis
243 F32 CTGX, CTGY, CTGZ; // [T/bADC] Gain Temperature correction factor for each axis
244
246 : B0X(32768), B0Y(32768), B0Z(32768), G0X(1), G0Y(1), G0Z(1), T0(0), CT0X(0), CT0Y(0), CT0Z(0), CTGX(0), CTGY(0), CTGZ(0)
247 {}
248
249 static F32 RawBtoB(const U16 & rRawB, const U16 & rRawT, const U16 & rB0, const F32 & rG0, const U16 & rT0, const F32 & rCT0, const F32 & rCTG)
250 {
251 I32 l_BOffsetless = (I32)rRawB - (I32)rB0;
252 I32 l_TOffsetless = (I32)rRawT - (I32)rT0;
253 F32 l_TOffsetCorrected = l_TOffsetless * rCT0;
254 F32 l_TGainCorrected = l_TOffsetless * rCTG;
255 F32 l_Gain = rG0 + l_TGainCorrected;
256 F32 l_BCorrected_T = (l_BOffsetless - l_TOffsetCorrected) * l_Gain;
257 return l_BCorrected_T;
258 }
259
260 static F32 Norm(const F32 & rBx, const F32 & rBy, const F32 & rBz)
261 {
262 return sqrt(rBx*rBx + rBy * rBy + rBz * rBz);
263 }
264
265 void Calibrate(const U16 & rRawBx, const U16 & rRawBy, const U16 & rRawBz, const U16 & rRawT,
266 F32 & rBx_T, F32 & rBy_T, F32 & rBz_T, F32 & rNorm_T)
267 {
268 F32 Bx_T = RawBtoB(rRawBx, rRawT, B0X, G0X, T0, CT0X, CTGX);
269 F32 By_T = RawBtoB(rRawBy, rRawT, B0Y, G0Y, T0, CT0Y, CTGY);
270 F32 Bz_T = RawBtoB(rRawBz, rRawT, B0Z, G0Z, T0, CT0Z, CTGZ);
271 rNorm_T = Norm(Bx_T, By_T, Bz_T);
272 rBx_T = Bx_T;
273 rBy_T = By_T;
274 rBz_T = Bz_T;
275 }
277
278 bool IsCalibrated(void)
279 {
280 return State & 0x01;
281 }
282 bool IsActivated(void)
283 {
284 return State & 0x02;
285 }
286 };
287
288 //==================================================================================================//
289 // Devices //
290 //==================================================================================================//
304
305
306
307 //----------------------------------------------------------------------//
308 // Parser Class //
309 //----------------------------------------------------------------------//
310 class Parser
311 {
312 //----------------------------------------------------------------------//
313 // Private Attributes //
314 //----------------------------------------------------------------------//
315 private:
316 const std::vector<U8>::const_iterator m_beg, m_end;
317 CParmInfoMap m_ParmInfoMap;
318 eHeaderType m_HeaderType = kUnknown;
319 sStandaloneStaticHeader m_StdandaloneHeader;
320 sEmbeddedStaticHeader m_EmbeddedHeader;
321
322 //----------------------------------------------------------------------//
323 // Private Methods //
324 //----------------------------------------------------------------------//
325 private:
326 bool l_ParseIdentification(sIdentification & rId, std::vector<U8>::const_iterator Id_beg, std::vector<U8>::const_iterator Id_end);
327 bool l_HeaderVersion(U16 & rVersion);
328 bool l_ParseStaticHeader(sStandaloneStaticHeader & rHeader);
329 bool l_ParseStaticHeader(sEmbeddedStaticHeader & rHeader);
330 bool l_ParseParmInfo(size_t HeaderLen, CParmInfoMap & rParmInfoMap);
331
332 //----------------------------------------------------------------------//
333 // Public Methods //
334 //----------------------------------------------------------------------//
335 public:
336 Parser(std::vector<U8>::const_iterator beg, std::vector<U8>::const_iterator end)
337 : m_beg(beg), m_end(end)
338 {}
339
340 bool Parse();
341
343 bool ParmAddress(U8 ParmNo, U16 & rParmAddress);
348 bool ParseMultiHeadInfo(size_t ParmAddress, sMultiHeadInfo & rMultiHeadInfo);
349 bool ParseHeadList(size_t ParmAddress, tHeadList & rHeadList);
350 bool ParsePwCamPhysInfo(size_t ParmAddress, sPwCamPhysicalInfo & rPhysInfo);
351 bool ParsePwPhysicalInfo(size_t ParmAddress, sPwPhysicalInformation & rPhysInfo, std::vector<U8>::const_iterator & rpBuffer);
352 bool ParsePwPhysInfoSet(size_t ParmAddress, sPwPhysicalInformationSet & rPwPhysInfoSet);
353 bool ParsePwFcaPhysInfo(size_t ParmAddress, sPwFCAPhysInfo & rPhysInfo);
354 bool ParseHallInfo(size_t ParmAddress, sHallInformation & rHallInfo);
355 };
356
357 //----------------------------------------------------------------------//
358 // Builder Class //
359 //----------------------------------------------------------------------//
361 {
362 public:
364 {
366 const std::vector<U8> & rParmData;
367 };
368 typedef std::vector<sParmContent> tParmContentInfo;
369
370 private:
371 static CParmInfoMap l_BuildParmInfo(const tParmContentInfo & rParmContent, U16 BaseAddress, size_t & rParmDataSize);
372 static CParmInfoMap l_BuildParmInfo(const tParmContentInfo & rParmContent, U16 BaseAddress, std::vector<U8> & rGeneratedParmData);
373
374 static std::vector<U8> l_Raw(const CPT2026PeripheralROM::sIdentification & rId);
375 static std::vector<U8> l_Raw(const sStandaloneStaticHeader & rHeader);
376 static std::vector<U8> l_Raw(const sEmbeddedStaticHeader & rHeader);
377 static std::vector<U8> l_Raw(const CParmInfoMap & rParmInfo);
378
379 template <typename HeaderType>
380 static std::vector<U8> l_BuildROM(HeaderType Header, const tParmContentInfo & rParmContent);
381
382 public:
383 static std::vector<U8> Raw(const CPT2026PeripheralROM::sHallInformation & rHallInfo);
384 static std::vector<U8> Raw(const CPT2026PeripheralROM::sManufactureInformation & rManInfo);
385 static std::vector<U8> Raw(const CPT2026PeripheralROM::sMultiHeadInfo & rMultHeadInfo);
386 static std::vector<U8> Raw(const CPT2026PeripheralROM::tHeadList & rHeadList);
387 static std::vector<U8> Raw(const CPT2026PeripheralROM::sPwCamPhysicalInfo & rPwCamPhysInfo);
388 static std::vector<U8> Raw(const CPT2026PeripheralROM::sPwFCAPhysInfo & rPwFCAPhysInfo);
389 static std::vector<U8> Raw(const CPT2026PeripheralROM::sPwPhysicalInformation & rPwPhysInfo);
390 static std::vector<U8> Raw(const CPT2026PeripheralROM::sPwPhysicalInformationSet & rPwPhysInfoSet);
391
392 static std::vector<U8> BuildROM(sStandaloneStaticHeader Header, const tParmContentInfo & rParmContent);
393 static std::vector<U8> BuildROM(sEmbeddedStaticHeader Header, const tParmContentInfo & rParmContent);
394
395 static void Build1226ROM( std::vector<U8> & rOutputROM,
399 static void Build9046ROM( std::vector<U8> & rOutputROM,
400 const CPT2026PeripheralROM::sIdentification & rIdentification,
402 const CPT2026PeripheralROM::sMultiHeadInfo & rMultiHeadInfo,
403 const CPT2026PeripheralROM::tHeadList & rSearchHeadList,
404 const CPT2026PeripheralROM::tHeadList & rMeasHeadList,
405 const CPT2026PeripheralROM::sPwCamPhysicalInfo & rPwCamPhysInfo,
407 };
408 };
409
410} // namespace MTL
Platform Dependent Definitions.
std::vector< sHeadDefinition > tHeadDefList
std::vector< F32 > tNormalizationTable
std::vector< sTransmissionTimes > tTransmissionTimeList
std::vector< sPwPhysicalInformation * >::size_type size_type
sPwPhysicalInformation & operator[](const size_type Index)
void Attach(sPwPhysicalInformation *pPwPhysInfo)
struct MTL::CPT2026PeripheralROM::sHallInformation::sCalibration Calibration
void Calibrate(const U16 &rRawBx, const U16 &rRawBy, const U16 &rRawBz, const U16 &rRawT, F32 &rBx_T, F32 &rBy_T, F32 &rBz_T, F32 &rNorm_T)
static F32 RawBtoB(const U16 &rRawB, const U16 &rRawT, const U16 &rB0, const F32 &rG0, const U16 &rT0, const F32 &rCT0, const F32 &rCTG)
static F32 Norm(const F32 &rBx, const F32 &rBy, const F32 &rBz)
bool ParsePwCamPhysInfo(size_t ParmAddress, sPwCamPhysicalInfo &rPhysInfo)
bool ParseHeadList(size_t ParmAddress, tHeadList &rHeadList)
bool ParsePwFcaPhysInfo(size_t ParmAddress, sPwFCAPhysInfo &rPhysInfo)
bool ParsePwPhysicalInfo(size_t ParmAddress, sPwPhysicalInformation &rPhysInfo, std::vector< U8 >::const_iterator &rpBuffer)
bool ParseHallInfo(size_t ParmAddress, sHallInformation &rHallInfo)
bool ParseManufactureInformation(size_t ParmAddress, sManufactureInformation &rManuInfo)
bool ParseMultiHeadInfo(size_t ParmAddress, sMultiHeadInfo &rMultiHeadInfo)
bool ParmAddress(U8 ParmNo, U16 &rParmAddress)
sStandaloneStaticHeader Header(const sStandaloneStaticHeader &rHeader)
bool ParsePwPhysInfoSet(size_t ParmAddress, sPwPhysicalInformationSet &rPwPhysInfoSet)
Parser(std::vector< U8 >::const_iterator beg, std::vector< U8 >::const_iterator end)
bool HasIdentification(sIdentification &rID)
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)
static std::vector< U8 > Raw(const CPT2026PeripheralROM::sHallInformation &rHallInfo)
static void Build1226ROM(std::vector< U8 > &rOutputROM, const CPT2026PeripheralROM::sManufactureInformation &rManInfo, const CPT2026PeripheralROM::sPwPhysicalInformation &rPwPhysInfo, const CPT2026PeripheralROM::sHallInformation &rHallInfo)
static std::vector< U8 > BuildROM(sStandaloneStaticHeader Header, const tParmContentInfo &rParmContent)
std::vector< sParmContent > tParmContentInfo