djiparsetxt
DJITxtParser.hh
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 2018-07-20
18 
19  Copyright (c) 2018 Live Networks, Inc. All rights reserved.
20  For the latest version of this program (and more information), visit http://djilogs.live555.com
21 
22  General parsing routines, and parser base class.
23  Header File.
24 */
25 
26 #ifndef _DJI_TXT_PARSER_HH
27 #define _DJI_TXT_PARSER_HH
28 
29 #include <sys/types.h>
30 #include <stdlib.h>
31 
32 // Uncomment the following line (then: make clean; make) to generate more debugging output:
33 //#define DEBUG_RECORD_PARSING 1
34 
35 // In each of these routines, "limit" is 1 byte past the end of the usable data.
36 u_int8_t getByte(u_int8_t const*& ptr, u_int8_t const* limit = NULL);
37 u_int16_t get2BytesBE(u_int8_t const*& ptr, u_int8_t const* limit = NULL);
38 u_int16_t get2BytesLE(u_int8_t const*& ptr, u_int8_t const* limit = NULL);
39 unsigned getWord32BE(u_int8_t const*& ptr, u_int8_t const* limit = NULL);
40 unsigned getWord32LE(u_int8_t const*& ptr, u_int8_t const* limit = NULL);
41 u_int64_t getWord64LE(u_int8_t const*& ptr, u_int8_t const* limit = NULL);
42 
43 // The following routines are used for debugging:
44 void printString(char const* label, u_int8_t const*& ptr, unsigned stringLength, u_int8_t const* limit = NULL);
45 void printHex(char const* label, u_int8_t const*& ptr, u_int8_t const* limit);
46 
47 #define END_OF_DATA 1 // exception thrown if parsing unexpectedly reaches the end of the buffer
48 
49 class DJITxtParser {
50 public:
51  static DJITxtParser* createNew();
52 
53 protected:
54  DJITxtParser(); // called only by "createNew()"
55 
56 public:
57  virtual ~DJITxtParser();
58 
59  virtual void parseDetailsArea(u_int8_t const*& ptr, u_int8_t const* limit) = 0;
60  virtual int parseRecord(u_int8_t const*& ptr, u_int8_t const* limit, int isScrambled) = 0;
61  virtual void outputOneRow(int outputColumnLabels = 0) = 0;
62  virtual void summarizeRecordParsing() = 0;
63 };
64 
65 #endif
u_int16_t get2BytesLE(u_int8_t const *&ptr, u_int8_t const *limit=NULL)
static DJITxtParser * createNew()
virtual void summarizeRecordParsing()=0
void printHex(char const *label, u_int8_t const *&ptr, u_int8_t const *limit)
u_int16_t get2BytesBE(u_int8_t const *&ptr, u_int8_t const *limit=NULL)
virtual void outputOneRow(int outputColumnLabels=0)=0
unsigned getWord32BE(u_int8_t const *&ptr, u_int8_t const *limit=NULL)
virtual void parseDetailsArea(u_int8_t const *&ptr, u_int8_t const *limit)=0
virtual ~DJITxtParser()
void printString(char const *label, u_int8_t const *&ptr, unsigned stringLength, u_int8_t const *limit=NULL)
u_int8_t getByte(u_int8_t const *&ptr, u_int8_t const *limit=NULL)
u_int64_t getWord64LE(u_int8_t const *&ptr, u_int8_t const *limit=NULL)
unsigned getWord32LE(u_int8_t const *&ptr, u_int8_t const *limit=NULL)
virtual int parseRecord(u_int8_t const *&ptr, u_int8_t const *limit, int isScrambled)=0