djiparsetxt
parseRecord_SMART_BATTERY.cpp
Go to the documentation of this file.
1 /**********
2 This program is free software: you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation, either version 3 of the License, or
5 (at your option) any later version.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11 
12 You should have received a copy of the GNU General Public License
13 along with this program. If not, see <http://www.gnu.org/licenses/>.
14 **********/
15 /*
16  A C++ program to parse DJI's ".txt" log files (recorded by the "DJI Go 4" app).
17  Version 2021-05-20
18 
19  Copyright (c) 2021 Live Networks, Inc. All rights reserved.
20  For the latest version of this program (and more information), visit http://djilogs.live555.com
21 
22  Parsing SMART_BATTERY records within DJI ".txt" files.
23  Implementation.
24 */
25 
27 
28 void RecordAndDetailsParser::parseRecord_SMART_BATTERY(u_int8_t const*& ptr, u_int8_t const* limit) {
29  // SMART_BATTERY.usefulTime: 2 bytes little-endian unsigned:
30  noteUnsigned2ByteField("SMART_BATTERY.usefulTime", ptr, limit);
31 
32  // SMART_BATTERY.goHomeTime: 2 bytes little-endian unsigned:
33  noteUnsigned2ByteField("SMART_BATTERY.goHomeTime", ptr, limit);
34 
35  // SMART_BATTERY.landTime: 2 bytes little-endian unsigned:
36  noteUnsigned2ByteField("SMART_BATTERY.landTime", ptr, limit);
37 
38  // SMART_BATTERY.goHomeBattery: 2 bytes little-endian unsigned:
39  noteUnsigned2ByteField("SMART_BATTERY.goHomeBattery", ptr, limit);
40 
41  // SMART_BATTERY.landBattery: 2 bytes little-endian unsigned:
42  noteUnsigned2ByteField("SMART_BATTERY.landBattery", ptr, limit);
43 
44  // SMART_BATTERY.safeFlyRadius: 4 bytes little-endian unsigned:
45  note4ByteField("SMART_BATTERY.safeFlyRadius", ptr, limit);
46 
47  // SMART_BATTERY.volumeConsume: 4 bytes little-endian float:
48  note4ByteFloatField("SMART_BATTERY.volumeConsume", ptr, limit);
49 
50  // SMART_BATTERY.status.RAW: 4 bytes little-endian unsigned:
51  note4ByteField("SMART_BATTERY.status.RAW", ptr, limit);
52 
53  // SMART_BATTERY.goHomeStatus.RAW: 1 byte unsigned:
54  noteByteField("SMART_BATTERY.goHomeStatus.RAW", ptr, limit);
55 
56  // SMART_BATTERY.goHomeCountdown: 1 byte unsigned:
57  noteByteField("SMART_BATTERY.goHomeCountdown", ptr, limit);
58 
59  // SMART_BATTERY.voltage: 2 bytes little-endian unsigned; multiple of 0.001 volts; convert to volts:
60  noteUnsigned2ByteField("SMART_BATTERY.voltage", ptr, limit, 1000.0);
61 
62  // SMART_BATTERY.battery: 1 byte unsigned:
63  noteByteField("SMART_BATTERY.battery", ptr, limit);
64 
65  // SMART_BATTERY.lowWarningGoHome (1 bit) + SMART_BATTERY.lowWarning (7 bits):
66  u_int8_t byte = getByte(ptr, limit);
67  enterSubByteField("SMART_BATTERY.lowWarningGoHome", byte, 0x80);
68  enterSubByteField("SMART_BATTERY.lowWarning", byte, 0x7F);
69 
70  // SMART_BATTERY.seriousLowWarningLanding (1 bit) + SMART_BATTERY.seriousLowWarning (7 bits):
71  byte = getByte(ptr, limit);
72  enterSubByteField("SMART_BATTERY.seriousLowWarningLanding", byte, 0x80);
73  enterSubByteField("SMART_BATTERY.seriousLowWarning", byte, 0x7F);
74 
75  // SMART_BATTERY.voltagePercent: 1 byte unsigned:
76  noteByteField("SMART_BATTERY.voltagePercent", ptr, limit);
77 }
u_int8_t getByte(u_int8_t const *&ptr, u_int8_t const *limit)
void noteUnsigned2ByteField(char const *label, u_int8_t const *&ptr, u_int8_t const *limit, float divisor=0.0, int16_t offset=0)
void enterSubByteField(char const *label, u_int8_t byte, u_int8_t mask)
void note4ByteField(char const *label, u_int8_t const *&ptr, u_int8_t const *limit, float divisor=0.0, int isSigned=0)
void parseRecord_SMART_BATTERY(u_int8_t const *&ptr, u_int8_t const *limit)
void note4ByteFloatField(char const *label, u_int8_t const *&ptr, u_int8_t const *limit, float divisor=0.0)
void noteByteField(char const *label, u_int8_t const *&ptr, u_int8_t const *limit, float divisor=0.0, int isSigned=0)