djiparsetxt
Public Member Functions | Private Member Functions | Private Attributes
FieldDatabase Class Reference

#include <FieldDatabase.hh>

Collaboration diagram for FieldDatabase:
Collaboration graph
[legend]

Public Member Functions

 FieldDatabase ()
 
virtual ~FieldDatabase ()
 
void addByteField (char const *label, u_int8_t value, int isSigned)
 
void add2ByteField (char const *label, u_int16_t value, int isSigned)
 
void add2ByteDateField (char const *label, u_int16_t value)
 
void add4ByteField (char const *label, u_int32_t value, int isSigned)
 
void add4ByteVersionField (char const *label, u_int32_t value)
 
void addFloatField (char const *label, float value)
 
void addDoubleField (char const *label, double value)
 
void add8ByteTimestampField (char const *label, u_int64_t value, int isInMilliseconds)
 
void addStringField (char const *label, char const *str)
 
void outputField (char const *label, unsigned numFractionalDigits=0)
 
void outputFieldAsBoolean (char const *label)
 
void outputFieldInterpreted (char const *label, char const *interpretedLabel)
 

Private Member Functions

void addFieldValue (char const *label, FieldValue *fieldValue)
 
FieldValue const * lookupFieldValue (char const *label)
 
void initializeInterpretationTables ()
 
InterpretationTablenewInterpretationTable (char const *interpretedLabel, char const *defaultResultString)
 

Private Attributes

std::unordered_map< char const *, FieldValue * > fUMap
 
std::unordered_map< char const *, InterpretationTable * > fInterpretationTableMap
 

Detailed Description

Definition at line 76 of file FieldDatabase.hh.

Constructor & Destructor Documentation

◆ FieldDatabase()

FieldDatabase::FieldDatabase ( )

Definition at line 48 of file FieldDatabase.cpp.

48  {
50 }
void initializeInterpretationTables()

References initializeInterpretationTables().

◆ ~FieldDatabase()

FieldDatabase::~FieldDatabase ( )
virtual

Definition at line 52 of file FieldDatabase.cpp.

52  {
53  // Iterate through each of our 'unordered map's, deleting its contents:
54  // "fUMap":
55  {
56  std::unordered_map<char const*, FieldValue*>::iterator itr;
57  for (itr = fUMap.begin(); itr != fUMap.end(); itr++) {
58  delete itr->second;
59  }
60  }
61  // "fInterpretationTableMap":
62  {
63  std::unordered_map<char const*, InterpretationTable*>::iterator itr;
64  for (itr = fInterpretationTableMap.begin(); itr != fInterpretationTableMap.end(); itr++) {
65  delete itr->second;
66  }
67  }
68 }
std::unordered_map< char const *, FieldValue * > fUMap
std::unordered_map< char const *, InterpretationTable * > fInterpretationTableMap

References fInterpretationTableMap, and fUMap.

Member Function Documentation

◆ add2ByteDateField()

void FieldDatabase::add2ByteDateField ( char const *  label,
u_int16_t  value 
)

Definition at line 82 of file FieldDatabase.cpp.

82  {
83  addFieldValue(label, new FieldValue(Date2Byte, value));
84 }
void addFieldValue(char const *label, FieldValue *fieldValue)

References addFieldValue(), and Date2Byte.

◆ add2ByteField()

void FieldDatabase::add2ByteField ( char const *  label,
u_int16_t  value,
int  isSigned 
)

Definition at line 76 of file FieldDatabase.cpp.

76  {
77  addFieldValue(label, isSigned
78  ? new FieldValue(Integer2ByteSigned, value)
79  : new FieldValue(Integer2ByteUnsigned, value));
80 }
void addFieldValue(char const *label, FieldValue *fieldValue)

References addFieldValue(), Integer2ByteSigned, and Integer2ByteUnsigned.

◆ add4ByteField()

void FieldDatabase::add4ByteField ( char const *  label,
u_int32_t  value,
int  isSigned 
)

Definition at line 86 of file FieldDatabase.cpp.

86  {
87  addFieldValue(label, isSigned
88  ? new FieldValue(Integer4ByteSigned, value)
89  : new FieldValue(Integer4ByteUnsigned, value));
90 }
void addFieldValue(char const *label, FieldValue *fieldValue)

References addFieldValue(), Integer4ByteSigned, and Integer4ByteUnsigned.

◆ add4ByteVersionField()

void FieldDatabase::add4ByteVersionField ( char const *  label,
u_int32_t  value 
)

Definition at line 92 of file FieldDatabase.cpp.

92  {
93  addFieldValue(label, new FieldValue(Version4Byte, value));
94 }
void addFieldValue(char const *label, FieldValue *fieldValue)

References addFieldValue(), and Version4Byte.

◆ add8ByteTimestampField()

void FieldDatabase::add8ByteTimestampField ( char const *  label,
u_int64_t  value,
int  isInMilliseconds 
)

Definition at line 104 of file FieldDatabase.cpp.

104  {
105  addFieldValue(label, isInMilliseconds
107  : new FieldValue(Timestamp8ByteInSeconds, value));
108 }
void addFieldValue(char const *label, FieldValue *fieldValue)

References addFieldValue(), Timestamp8ByteInMilliseconds, and Timestamp8ByteInSeconds.

◆ addByteField()

void FieldDatabase::addByteField ( char const *  label,
u_int8_t  value,
int  isSigned 
)

Definition at line 70 of file FieldDatabase.cpp.

70  {
71  addFieldValue(label, isSigned
72  ? new FieldValue(IntegerByteSigned, value)
73  : new FieldValue(IntegerByteUnsigned, value));
74 }
void addFieldValue(char const *label, FieldValue *fieldValue)

References addFieldValue(), IntegerByteSigned, and IntegerByteUnsigned.

◆ addDoubleField()

void FieldDatabase::addDoubleField ( char const *  label,
double  value 
)

Definition at line 100 of file FieldDatabase.cpp.

100  {
101  addFieldValue(label, new FieldValue(Double, value));
102 }
void addFieldValue(char const *label, FieldValue *fieldValue)

References addFieldValue(), and Double.

◆ addFieldValue()

void FieldDatabase::addFieldValue ( char const *  label,
FieldValue fieldValue 
)
private

Definition at line 114 of file FieldDatabase.cpp.

114  {
115  // First, delete any existing "FieldValue" for this label (the assignment below doesn't do that):
116  delete fUMap[label];
117 
118  // Then, store the new "FieldValue":
119  fUMap[label] = fieldValue;
120 }
std::unordered_map< char const *, FieldValue * > fUMap

References fUMap.

Referenced by add2ByteDateField(), add2ByteField(), add4ByteField(), add4ByteVersionField(), add8ByteTimestampField(), addByteField(), addDoubleField(), addFloatField(), and addStringField().

◆ addFloatField()

void FieldDatabase::addFloatField ( char const *  label,
float  value 
)

Definition at line 96 of file FieldDatabase.cpp.

96  {
97  addFieldValue(label, new FieldValue(Float, value));
98 }
void addFieldValue(char const *label, FieldValue *fieldValue)

References addFieldValue(), and Float.

◆ addStringField()

void FieldDatabase::addStringField ( char const *  label,
char const *  str 
)

Definition at line 110 of file FieldDatabase.cpp.

110  {
111  addFieldValue(label, new FieldValue(String, str));
112 }
void addFieldValue(char const *label, FieldValue *fieldValue)

References addFieldValue(), and String.

◆ initializeInterpretationTables()

void FieldDatabase::initializeInterpretationTables ( )
private

Definition at line 29 of file interpretationTables.cpp.

29  {
31 
33  it = newInterpretationTable("OSD.flycState", "Other");
34  it->add(0, "Manual");
35  it->add(1, "Atti");
36  it->add(2, "Atti_CL");
37  it->add(3, "Atti_Hover");
38  it->add(4, "Hover");
39  it->add(5, "GPS_Blake");
40  it->add(6, "GPS_Atti");
41  it->add(7, "GPS_CL");
42  it->add(8, "GPS_HomeLock");
43  it->add(9, "GPS_HotPoint");
44  it->add(10, "AssistedTakeoff");
45  it->add(11, "AutoTakeoff");
46  it->add(12, "AutoLanding");
47  it->add(13, "AttiLanding");
48  it->add(14, "NaviGo");
49  it->add(15, "GoHome");
50  it->add(16, "ClickGo");
51  it->add(17, "Joystick");
52  it->add(18, "GPS_Atti_Wristband");
53  it->add(19, "Cinematic");
54  it->add(23, "Atti_Limited");
55  it->add(24, "GPS_Atti_Limited");
56  it->add(25, "NaviMissionFollow");
57  it->add(26, "NaviSubMode_Tracking");
58  it->add(27, "NaviSubMode_Pointing");
59  it->add(28, "PANO");
60  it->add(29, "Farming");
61  it->add(30, "FPV");
62  it->add(31, "Sport");
63  it->add(32, "Novice");
64  it->add(33, "ForceLanding");
65  it->add(35, "TerrainTracking");
66  it->add(36, "NaviAdvGoHome");
67  it->add(37, "NaviAdvLanding");
68  it->add(38, "TripodGPS");
69  it->add(39, "TrackHeadlock");
70  it->add(41, "EngineStart");
71  it->add(43, "GentleGPS");
72 
74  it = newInterpretationTable("OSD.flycCommand", "Other");
75  it->add(1, "AutoFly");
76  it->add(2, "AutoLanding");
77  it->add(3, "HomePointNow");
78  it->add(4, "HomePointHot");
79  it->add(5, "HomePointLock");
80  it->add(6, "GoHome");
81  it->add(7, "StartMotor");
82  it->add(8, "StopMotor");
83  it->add(9, "Calibration");
84  it->add(10, "DeformProtecClose");
85  it->add(11, "DeformProtecOpen");
86  it->add(12, "DropGoHome");
87  it->add(13, "DropTakeOff");
88  it->add(14, "DropLanding");
89  it->add(15, "DynamicHomePointOpen");
90  it->add(16, "DynamicHomePointClose");
91  it->add(17, "FollowFunctionOpen");
92  it->add(18, "FollowFunctionClose");
93  it->add(19, "IOCOpen");
94  it->add(20, "IOCClose");
95  it->add(21, "DropCalibration");
96  it->add(22, "PackMode");
97  it->add(23, "UnPackMode");
98  it->add(24, "EnterManualMode");
99  it->add(25, "StopDeform");
100  it->add(28, "DownDeform");
101  it->add(29, "UpDeform");
102  it->add(30, "ForceLanding");
103  it->add(31, "ForceLanding2");
104 
106  it = newInterpretationTable("OSD.groundOrSky", "Unknown");
107  it->add(0, "Ground");
108  it->add(1, "Ground");
109  it->add(2, "Sky");
110  it->add(3, "Sky");
111 
113  it = newInterpretationTable("OSD.goHomeStatus", "Other");
114  it->add(0, "Standby");
115  it->add(1, "Preascending");
116  it->add(2, "Align");
117  it->add(3, "Ascending");
118  it->add(4, "Cruise");
119  it->add(5, "Braking");
120  it->add(6, "Bypassing");
121 
123  it = newInterpretationTable("OSD.batteryType", "Unknown");
124  it->add(1, "NonSmart");
125  it->add(2, "Smart");
126 
128  it = newInterpretationTable("OSD.flightAction", "Unknown");
129  it->add(0, "None");
130  it->add(1, "WarningPowerGoHome");
131  it->add(2, "WarningPowerLanding");
132  it->add(3, "SmartPowerGoHome");
133  it->add(4, "SmartPowerLanding");
134  it->add(5, "LowVoltageLanding");
135  it->add(6, "LowVoltageGoHome");
136  it->add(7, "SeriousLowVoltageLanding");
137  it->add(8, "RC_OnekeyGoHome");
138  it->add(9, "RC_AssistantTakeoff");
139  it->add(10, "RC_AutoTakeoff");
140  it->add(11, "RC_AutoLanding");
141  it->add(12, "AppAutoGoHome");
142  it->add(13, "AppAutoLanding");
143  it->add(14, "AppAutoTakeoff");
144  it->add(15, "OutOfControlGoHome");
145  it->add(16, "ApiAutoTakeoff");
146  it->add(17, "ApiAutoLanding");
147  it->add(18, "ApiAutoGoHome");
148  it->add(19, "AvoidGroundLanding");
149  it->add(20, "AirportAvoidLanding");
150  it->add(21, "TooCloseGoHomeLanding");
151  it->add(22, "TooFarGoHomeLanding");
152  it->add(23, "App_WP_Mission");
153  it->add(24, "WP_AutoTakeoff");
154  it->add(25, "GoHomeAvoid");
155  it->add(26, "pGoHomeFinish");
156  it->add(27, "VertLowLimitLanding");
157  it->add(28, "BatteryForceLanding");
158  it->add(29, "MC_ProtectGoHome");
159  it->add(30, "MotorblockLanding");
160  it->add(31, "AppRequestForceLanding");
161  it->add(32, "FakeBatteryLanding");
162  it->add(33, "RTH_ComingObstacleLanding");
163  it->add(34, "IMUErrorRTH");
164 
166  it = newInterpretationTable("OSD.motorStartFailedCause", "Other");
167  it->add(0, "None");
168  it->add(1, "CompassError");
169  it->add(2, "AssistantProtected");
170  it->add(3, "DeviceLocked");
171  it->add(4, "DistanceLimit");
172  it->add(5, "IMUNeedCalibration");
173  it->add(6, "IMUSNError");
174  it->add(7, "IMUWarning");
175  it->add(8, "CompassCalibrating");
176  it->add(9, "AttiError");
177  it->add(10, "NoviceProtected");
178  it->add(11, "BatteryCellError");
179  it->add(12, "BatteryCommuniteError");
180  it->add(13, "SeriousLowVoltage");
181  it->add(14, "SeriousLowPower");
182  it->add(15, "LowVoltage");
183  it->add(16, "TempureVolLow");
184  it->add(17, "SmartLowToLand");
185  it->add(18, "BatteryNotReady");
186  it->add(19, "SimulatorMode");
187  it->add(20, "PackMode");
188  it->add(21, "AttitudeAbnormal");
189  it->add(22, "UnActive");
190  it->add(23, "FlyForbiddenError");
191  it->add(24, "BiasError");
192  it->add(25, "EscError");
193  it->add(26, "ImuInitError");
194  it->add(27, "SystemUpgrade");
195  it->add(28, "SimulatorStarted");
196  it->add(29, "ImuingError");
197  it->add(30, "AttiAngleOver");
198  it->add(31, "GyroscopeError");
199  it->add(32, "AcceleratorError");
200  it->add(33, "CompassFailed");
201  it->add(34, "BarometerError");
202  it->add(35, "BarometerNegative");
203  it->add(36, "CompassBig");
204  it->add(37, "GyroscopeBiasBig");
205  it->add(38, "AcceleratorBiasBig");
206  it->add(39, "CompassNoiseBig");
207  it->add(40, "BarometerNoiseBig");
208  it->add(41, "InvalidSn");
209  it->add(44, "FlashOperating");
210  it->add(45, "GPSdisconnect");
211  it->add(47, "SDCardException");
212  it->add(61, "IMUNoconnection");
213  it->add(62, "RCCalibration");
214  it->add(63, "RCCalibrationException");
215  it->add(64, "RCCalibrationUnfinished");
216  it->add(65, "RCCalibrationException2");
217  it->add(66, "RCCalibrationException3");
218  it->add(67, "AircraftTypeMismatch");
219  it->add(68, "FoundUnfinishedModule");
220  it->add(70, "CyroAbnormal");
221  it->add(71, "BaroAbnormal");
222  it->add(72, "CompassAbnormal");
223  it->add(73, "GPS_Abnormal");
224  it->add(74, "NS_Abnormal");
225  it->add(75, "TopologyAbnormal");
226  it->add(76, "RC_NeedCali");
227  it->add(77, "InvalidFloat");
228  it->add(78, "M600_BAT_TOO_LITTLE");
229  it->add(79, "M600_BAT_AUTH_ERR");
230  it->add(80, "M600_BAT_COMM_ERR");
231  it->add(81, "M600_BAT_DIF_VOLT_LARGE_1");
232  it->add(82, "M600_BAT_DIF_VOLT_LARGE_2");
233  it->add(83, "InvalidVersion");
234  it->add(84, "GimbalGyroAbnormal");
235  it->add(85, "GimbalESC_PitchNonData");
236  it->add(86, "GimbalESC_RollNonData");
237  it->add(87, "GimbalESC_YawNonData");
238  it->add(88, "GimbalFirmwIsUpdating");
239  it->add(89, "GimbalDisorder");
240  it->add(90, "GimbalPitchShock");
241  it->add(91, "GimbalRollShock");
242  it->add(92, "GimbalYawShock");
243  it->add(93, "IMUcCalibrationFinished");
244  it->add(101, "BattVersionError");
245  it->add(102, "RTK_BadSignal");
246  it->add(103, "RTK_DeviationError");
247  it->add(112, "ESC_Calibrating");
248  it->add(113, "GPS_SignInvalid");
249  it->add(114, "GimbalIsCalibrating");
250  it->add(115, "LockByApp");
251  it->add(116, "StartFlyHeightError");
252  it->add(117, "ESC_VersionNotMatch");
253  it->add(118, "IMU_ORI_NotMatch");
254  it->add(119, "StopByApp");
255  it->add(120, "CompassIMU_ORI_NotMatch");
256  it->add(122, "CompassIMU_ORI_NotMatch");
257  it->add(123, "BatteryOverTemperature");
258  it->add(124, "BatteryInstallError");
259  it->add(125, "BeImpact");
260 
262  it = newInterpretationTable("OSD.nonGPSCause", "Unknown");
263  it->add(0, "Already");
264  it->add(1, "Forbid");
265  it->add(2, "GpsNumNonEnough");
266  it->add(3, "GpsHdopLarge");
267  it->add(4, "GpsPositionNonMatch");
268  it->add(5, "SpeedErrorLarge");
269  it->add(6, "YawErrorLarge");
270  it->add(7, "CompassErrorLarge");
271 
273  it = newInterpretationTable("OSD.droneType", "Unknown");
274  it->add(1, "Inspire 1");
275  it->add(2, "P3 Advanced");
276  it->add(3, "P3 Professional");
277  it->add(4, "P3 Standard");
278  it->add(5, "OpenFrame");
279  it->add(6, "AceOne");
280  it->add(7, "WKM");
281  it->add(8, "Naza");
282  it->add(9, "A2");
283  it->add(10, "A3");
284  it->add(11, "P4");
285  it->add(14, "Matrice 600");
286  it->add(15, "P3 4K");
287  it->add(16, "Mavic");
288  it->add(17, "Inspire 2");
289  it->add(18, "P4 Professional");
290  it->add(20, "N3");
291  it->add(21, "Spark");
292  it->add(23, "Matrice 600 Pro");
293  it->add(24, "Mavic Air");
294  it->add(25, "Matrice 200");
295  it->add(27, "P4 Advanced");
296  it->add(28, "Matrice 210");
297  it->add(29, "P3SE");
298  it->add(30, "Matrice 210MTK");
299  it->add(58, "Mavic Air 2");
300 
302  it = newInterpretationTable("OSD.imuInitFailReason", "None");
303  it->add(0, "MonitorError");
304  it->add(1, "CollectingData");
305  it->add(3, "AcceDead");
306  it->add(4, "CompassDead");
307  it->add(5, "BarometerDead");
308  it->add(6, "BarometerNegative");
309  it->add(7, "CompassModTooLarge");
310  it->add(8, "GyroBiasTooLarge");
311  it->add(9, "AcceBiasTooLarge");
312  it->add(10, "CompassNoiseTooLarge");
313  it->add(11, "BarometerNoiseTooLarge");
314  it->add(12, "WaitingMcStationary");
315  it->add(13, "AcceMoveTooLarge");
316  it->add(14, "McHeaderMoved");
317  it->add(15, "McVibrated");
318 
320  it = newInterpretationTable("OSD.motorFailReason", "");
321  it->add(94, "TakeoffException");
322  it->add(95, "ESC_StallNearGround");
323  it->add(96, "ESC_UnbalanceOnGround");
324  it->add(97, "ESC_PART_EMPTYOnGround");
325  it->add(98, "EngineStartFailed");
326  it->add(99, "AutoTakeoffLaunchFailed");
327  it->add(100, "RollOverOnGround");
328 
330  it = newInterpretationTable("OSD.ctrlDevice", "Other");
331  it->add(0, "RC");
332  it->add(1, "App");
333  it->add(2, "OnboardDevice");
334  it->add(3, "Camera");
335 
337  it = newInterpretationTable("GIMBAL.mode", "Other");
338  it->add(0, "YawNoFollow");
339  it->add(1, "FPV");
340  it->add(2, "YawFollow");
341 
343  it = newInterpretationTable("SMART_BATTERY.status", "???");
344  it->add(0, "None");
345 
347  it = newInterpretationTable("SMART_BATTERY.goHomeStatus", "Unknown");
348  it->add(0, "NonGoHome");
349  it->add(1, "GoHome");
350  it->add(2, "GoHomeAlready");
351 
353  it = newInterpretationTable("DEFORM.deformStatus", "Unknown");
354  it->add(1, "FoldComplete");
355  it->add(2, "Folding");
356  it->add(3, "StretchComplete");
357  it->add(4, "Stretching");
358  it->add(5, "StopDeformation");
359 
361  it = newInterpretationTable("DEFORM.deformMode", "Other");
362  it->add(0, "Pack");
363  it->add(1, "Protect");
364  it->add(2, "Normal");
365 
367  it = newInterpretationTable("HOME.iocMode", "Other");
368  it->add(1, "CourseLock");
369  it->add(2, "HomeLock");
370  it->add(3, "HotspotSurround");
371 
373  it = newInterpretationTable("RECOVER.droneType", "Unknown");
374  it->add(1, "Inspire 1");
375  it->add(2, "P3 Standard");
376  it->add(3, "P3 Advanced");
377  it->add(4, "P3 Professional");
378  it->add(5, "OSMO");
379  it->add(6, "Matrice 100");
380  it->add(7, "P4");
381  it->add(8, "LB2");
382  it->add(9, "Inspire 1 Pro");
383  it->add(10, "A3");
384  it->add(11, "Matrice 600");
385  it->add(12, "P3 4K");
386  it->add(13, "Mavic Pro");
387  it->add(14, "Zenmuse XT");
388  it->add(15, "Inspire 1 RAW");
389  it->add(16, "A2");
390  it->add(17, "Inspire 2");
391  it->add(18, "OSMO Pro");
392  it->add(19, "OSMO Raw");
393  it->add(20, "SMO+");
394  it->add(21, "Mavic");
395  it->add(22, "OSMO Mobile");
396  it->add(23, "OrangeCV600");
397  it->add(24, "P4 Professional");
398  it->add(25, "N3 FC");
399  it->add(26, "Spark");
400  it->add(27, "Matrice 600 Pro");
401  it->add(28, "P4 Advanced");
402  it->add(30, "AG405");
403  it->add(31, "Matrice 200");
404  it->add(33, "Matrice 210");
405  it->add(34, "Matrice 210RTK");
406  it->add(38, "Mavic Air");
407  it->add(59, "Mavic Mini");
408  it->add(67, "Mavic Air 2");
409 
411 
412  it = newInterpretationTable("RECOVER.appType", "Unknown");
413  it->add(1, "iOS");
414  it->add(2, "Android");
415  it->add(6, "Fly");
416 
417 
419 
420  it = newInterpretationTable("DETAILS.appType", "Unknown");
421  it->add(1, "iOS");
422  it->add(2, "Android");
423 }
InterpretationTable * newInterpretationTable(char const *interpretedLabel, char const *defaultResultString)
void add(u_int32_t intValue, char const *strValue)

References InterpretationTable::add(), and newInterpretationTable().

Referenced by FieldDatabase().

◆ lookupFieldValue()

FieldValue const * FieldDatabase::lookupFieldValue ( char const *  label)
private

Definition at line 122 of file FieldDatabase.cpp.

122  {
123  // return fUMap[label]; // claimed not to work for "char const*" keys
124  for (std::unordered_map<char const*, FieldValue*>::iterator itr = fUMap.begin(); itr != fUMap.end(); ++itr) {
125  if (strcmp(itr->first, label) == 0) {
126  return itr->second;
127  }
128  }
129 
130  return NULL;
131 }
std::unordered_map< char const *, FieldValue * > fUMap

References fUMap.

Referenced by outputField(), outputFieldAsBoolean(), and outputFieldInterpreted().

◆ newInterpretationTable()

InterpretationTable * FieldDatabase::newInterpretationTable ( char const *  interpretedLabel,
char const *  defaultResultString 
)
private

Definition at line 134 of file FieldDatabase.cpp.

134  {
135  InterpretationTable* it = new InterpretationTable(defaultResultString);
136  fInterpretationTableMap[interpretedLabel] = it;
137 
138  return it;
139 }
std::unordered_map< char const *, InterpretationTable * > fInterpretationTableMap

Referenced by initializeInterpretationTables().

◆ outputField()

void FieldDatabase::outputField ( char const *  label,
unsigned  numFractionalDigits = 0 
)

Definition at line 30 of file fieldOutput.cpp.

30  {
31  FieldValue const* fieldValue = lookupFieldValue(label);
32  if (fieldValue == NULL) return; // output nothing for a nonexistent field
33 
34  int timeIsInMilliseconds = 0; // by default
35 
36  switch (fieldValue->fType) {
37  case IntegerByteUnsigned: {
38  printf("%u", fieldValue->fByte);
39  break;
40  }
41  case IntegerByteSigned: {
42  printf("%d", (int8_t)(fieldValue->fByte));
43  break;
44  }
45  case Integer2ByteUnsigned: {
46  printf("%u", fieldValue->fBytes2);
47  break;
48  }
49  case Integer2ByteSigned: {
50  printf("%d", (int16_t)(fieldValue->fBytes2));
51  break;
52  }
53  case Date2Byte: {
54  // Interpret the two bytes as: 7 bits (years since 1980) + 4 bits (month) + 5 bits (day of month):
55  printf("%u/%02u/%02u",
56  ((fieldValue->fBytes2&0xFE00)>>9) + 1980,
57  (fieldValue->fBytes2&0x01E0)>>5,
58  (fieldValue->fBytes2&0x001F));
59 
60  break;
61  }
62  case Integer4ByteUnsigned: {
63  printf("%u", fieldValue->fBytes4);
64  break;
65  }
66  case Integer4ByteSigned: {
67  printf("%d", (int32_t)(fieldValue->fBytes4));
68  break;
69  }
70  case Version4Byte: {
71  // Use the first 3 bytes (big-endian) as version numbers:
72  u_int32_t v = fieldValue->fBytes4;
73  printf("%u.%u.%u", (v>>24)&0xFF, (v>>16)&0xFF, (v>>8)&0xFF);
74  break;
75  }
76  case Float: {
77  printf("%.*f", numFractionalDigits, fieldValue->fFloat);
78  break;
79  }
80  case Double: {
81  printf("%.*f", numFractionalDigits, fieldValue->fDouble);
82  break;
83  }
85  timeIsInMilliseconds = 1;
86  // fall through to:
87  }
89  u_int64_t time = fieldValue->fBytes8;
90  u_int64_t timeInSeconds;
91  unsigned milliseconds;
92 
93  if (timeIsInMilliseconds) {
94  timeInSeconds = time/1000;
95  milliseconds = time%1000;
96  } else {
97  timeInSeconds = time;
98  milliseconds = 0;
99  }
100 
101  struct tm* convertedTime = gmtime((time_t*)&timeInSeconds);
102  if (convertedTime == NULL) {
103  fprintf(stderr, "outputField(8-byte timestamp): gmtime(%llu) failed!\n", timeInSeconds);
104  return;
105  }
106  printf("%u/%02u/%02u %02u:%02u:%02u",
107  convertedTime->tm_year + 1900, convertedTime->tm_mon + 1, convertedTime->tm_mday,
108  convertedTime->tm_hour, convertedTime->tm_min, convertedTime->tm_sec);
109  if (timeIsInMilliseconds) {
110  printf(".%03u", milliseconds);
111  }
112  break;
113  }
114  case String: {
115  printf("%s", fieldValue->fStr);
116  break;
117  }
118  }
119 }
FieldType fType
char const * fStr
u_int64_t fBytes8
double fDouble
u_int16_t fBytes2
u_int32_t fBytes4
u_int8_t fByte
FieldValue const * lookupFieldValue(char const *label)

References Date2Byte, Double, FieldValue::fByte, FieldValue::fBytes2, FieldValue::fBytes4, FieldValue::fBytes8, FieldValue::fDouble, FieldValue::fFloat, Float, FieldValue::fStr, FieldValue::fType, Integer2ByteSigned, Integer2ByteUnsigned, Integer4ByteSigned, Integer4ByteUnsigned, IntegerByteSigned, IntegerByteUnsigned, lookupFieldValue(), String, Timestamp8ByteInMilliseconds, Timestamp8ByteInSeconds, and Version4Byte.

◆ outputFieldAsBoolean()

void FieldDatabase::outputFieldAsBoolean ( char const *  label)

Definition at line 121 of file fieldOutput.cpp.

121  {
122  FieldValue const* fieldValue = lookupFieldValue(label);
123  if (fieldValue == NULL) return; // output nothing for a nonexistent field
124 
125  int booleanValue = 0;
126 
127  switch (fieldValue->fType) {
128  case IntegerByteUnsigned:
129  case IntegerByteSigned: {
130  booleanValue = fieldValue->fByte != 0;
131  break;
132  }
134  case Integer2ByteSigned: {
135  booleanValue = fieldValue->fBytes2 != 0;
136  break;
137  }
139  case Integer4ByteSigned: {
140  booleanValue = fieldValue->fBytes4 != 0;
141  break;
142  }
143  default: {
144  return; // print nothing if the field cannot be interpreted as Boolean
145  }
146  }
147 
148  printf(booleanValue ? "True" : "False");
149 }
FieldType fType
u_int16_t fBytes2
u_int32_t fBytes4
u_int8_t fByte
FieldValue const * lookupFieldValue(char const *label)

References FieldValue::fByte, FieldValue::fBytes2, FieldValue::fBytes4, FieldValue::fType, Integer2ByteSigned, Integer2ByteUnsigned, Integer4ByteSigned, Integer4ByteUnsigned, IntegerByteSigned, IntegerByteUnsigned, and lookupFieldValue().

◆ outputFieldInterpreted()

void FieldDatabase::outputFieldInterpreted ( char const *  label,
char const *  interpretedLabel 
)

Definition at line 151 of file fieldOutput.cpp.

151  {
152  // First, check whether we currently have a value for the field "label":
153  FieldValue const* fieldValue = lookupFieldValue(label);
154  if (fieldValue == NULL) return; // output nothing for a nonexistent field
155 
156  // Next, check its type. It needs to be an unsigned integer type <= 4 bytes long:
157  u_int32_t intValue;
158  switch (fieldValue->fType) {
159  case IntegerByteUnsigned: {
160  intValue = (u_int32_t)(fieldValue->fByte);
161  break;
162  }
163  case Integer2ByteUnsigned: {
164  intValue = (u_int32_t)(fieldValue->fBytes2);
165  break;
166  }
167  case Integer4ByteUnsigned: {
168  intValue = fieldValue->fBytes4;;
169  break;
170  }
171  default: {
172  return; // bad type
173  }
174  }
175 
176  // Now, look up an InterpretationTable for "interpretedLabel":
177  InterpretationTable* interpretationTable = fInterpretationTableMap[interpretedLabel];
178  if (interpretationTable == NULL) return;
179 
180  // And use this to look up (and print) a string 'interpretation' of our integer value:
181  printf("%s", interpretationTable->lookup(intValue));
182 }
FieldType fType
u_int16_t fBytes2
std::unordered_map< char const *, InterpretationTable * > fInterpretationTableMap
u_int32_t fBytes4
u_int8_t fByte
char const * lookup(u_int32_t intValue)
FieldValue const * lookupFieldValue(char const *label)

References FieldValue::fByte, FieldValue::fBytes2, FieldValue::fBytes4, fInterpretationTableMap, FieldValue::fType, Integer2ByteUnsigned, Integer4ByteUnsigned, IntegerByteUnsigned, InterpretationTable::lookup(), and lookupFieldValue().

Field Documentation

◆ fInterpretationTableMap

std::unordered_map<char const*, InterpretationTable*> FieldDatabase::fInterpretationTableMap
private

Definition at line 112 of file FieldDatabase.hh.

Referenced by outputFieldInterpreted(), and ~FieldDatabase().

◆ fUMap

std::unordered_map<char const*, FieldValue*> FieldDatabase::fUMap
private

Definition at line 109 of file FieldDatabase.hh.

Referenced by addFieldValue(), lookupFieldValue(), and ~FieldDatabase().


The documentation for this class was generated from the following files: