djiparsetxt
DJITxtParser.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 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  Implementation.
24 */
25 
26 #include "DJITxtParser.hh"
27 #include <stdio.h>
28 
29 u_int8_t getByte(u_int8_t const*& ptr, u_int8_t const* limit) {
30  if (limit != NULL && ptr > limit-1) throw END_OF_DATA;
31  return *ptr++;
32 }
33 
34 u_int16_t get2BytesBE(u_int8_t const*& ptr, u_int8_t const* limit) {
35  if (limit != NULL && ptr > limit-2) throw END_OF_DATA;
36  u_int8_t byte1 = *ptr++;
37  u_int8_t byte2 = *ptr++;
38  return (byte1<<8)|byte2;
39 }
40 
41 u_int16_t get2BytesLE(u_int8_t const*& ptr, u_int8_t const* limit) {
42  if (limit != NULL && ptr > limit-2) throw END_OF_DATA;
43  u_int8_t byte1 = *ptr++;
44  u_int8_t byte2 = *ptr++;
45  return (byte2<<8)|byte1;
46 }
47 
48 unsigned getWord32BE(u_int8_t const*& ptr, u_int8_t const* limit) {
49  if (limit != NULL && ptr > limit-4) throw END_OF_DATA;
50  unsigned result = (ptr[0]<<24)|(ptr[1]<<16)|(ptr[2]<<8)|ptr[3];
51  ptr += 4;
52  return result;
53 }
54 
55 unsigned getWord32LE(u_int8_t const*& ptr, u_int8_t const* limit) {
56  if (limit != NULL && ptr > limit-4) throw END_OF_DATA;
57  unsigned result = (ptr[3]<<24)|(ptr[2]<<16)|(ptr[1]<<8)|ptr[0];
58  ptr += 4;
59  return result;
60 }
61 
62 u_int64_t getWord64LE(u_int8_t const*& ptr, u_int8_t const* limit) {
63  u_int64_t resultLow = getWord32LE(ptr, limit);
64  u_int64_t resultHigh = getWord32LE(ptr, limit);
65  return (resultHigh<<32)|resultLow;
66 }
67 
68 void printString(char const* label, u_int8_t const*& ptr, unsigned stringLength, u_int8_t const* limit) {
69  if (limit != NULL && ptr > limit - stringLength) throw END_OF_DATA;
70 
71  char str[stringLength+1];
72  unsigned i;
73  for (i = 0; i < stringLength; ++i) str[i] = *ptr++;
74  str[i] = '\0';
75 
76  if (label == NULL) {
77  fprintf(stderr, "%s\n", str);
78  } else {
79  fprintf(stderr, "%s: %s\n", label, str);
80  }
81 }
82 
83 void printHex(char const* label, u_int8_t const*& ptr, u_int8_t const* limit) {
84  if (limit == NULL) return;
85  if (label != NULL) fprintf(stderr, "%s: ", label);
86  for (u_int8_t const* p = ptr; p < limit; ++p) fprintf(stderr, ":%02x", *p);
87  fprintf(stderr, "\n");
88 }
89 
90 
92 
94 }
95 
97 }
u_int8_t getByte(u_int8_t const *&ptr, u_int8_t const *limit)
u_int64_t getWord64LE(u_int8_t const *&ptr, u_int8_t const *limit)
#define END_OF_DATA
Definition: DJITxtParser.hh:47
void printString(char const *label, u_int8_t const *&ptr, unsigned stringLength, u_int8_t const *limit)
unsigned getWord32LE(u_int8_t const *&ptr, u_int8_t const *limit)
u_int16_t get2BytesLE(u_int8_t const *&ptr, u_int8_t const *limit)
virtual ~DJITxtParser()
u_int16_t get2BytesBE(u_int8_t const *&ptr, u_int8_t const *limit)
unsigned getWord32BE(u_int8_t const *&ptr, u_int8_t const *limit)
void printHex(char const *label, u_int8_t const *&ptr, u_int8_t const *limit)