rx_tx_log.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #ifndef RX_TX_LOG_H
66 #define RX_TX_LOG_H
67 
68 #if defined(XSENS_DEBUG)
69  //#define LOG_RX_TX // Lowest level byte receive and send (binary log)
71  //#define LOG_RX_TX_UNIQUE // Use unique file names for rx/tx logs
72  //#define LOG_RX_TX_FLUSH // Flush after each log operation (can cause hickups in timing, 300ms is not unheard of)
73  //#define LOG_RX_TX_PER_STATE // Use new unique log file after switching to a new state (config/measurement/operational/recording) for rx/tx logs, override LOG_RX_TX_UNIQUE, automatically disabled if LOG_RX_TX is disabled
74 #endif
75 
76 #ifdef LOG_RX_TX
77 #if defined(LOG_RX_TX_PER_STATE) || defined(LOG_RX_TX_UNIQUE)
78 #include <xstypes/xstimestamp.h>
80 
83 inline static void makeFilenameUnique(char* filename, char const* state)
84 {
85 #if defined(LOG_RX_TX_PER_STATE) || defined(LOG_RX_TX_UNIQUE)
86  char basename[XS_MAX_FILENAME_LENGTH];
87  strcpy(basename, filename);
88  basename[strlen(basename) - 4] = 0; // remove .log extension
89  sprintf(filename, "%s_%" PRINTF_INT64_MODIFIER "u%s.log", basename, XsTimeStamp::nowMs(), state);
90 #else
91  (void)filename;
92 #endif
93 }
94 
95 
96 #ifdef LOG_RX_TX_PER_STATE
97 inline static void checkStateRx(char* state, int length, XsByteArray const& data, XsFile& rx_log)
98 {
99  state[0] = 0;
100  if (length >= 4)
101  {
102  // find preamble
103  int idx = 0;
104  while (idx < length - 4)
105  {
106  if (data[idx] == 0xFA && (data[idx + 1] == 0xFF || data[idx + 1] == 0) && data[idx + 3] == 0)
107  {
108  switch (data[idx + 2])
109  {
110  case XMID_GotoConfigAck:
111  strcpy(state, "_Config");
112  break;
114  strcpy(state, "_Measurement");
115  break;
117  strcpy(state, "_Operational");
118  break;
120  strcpy(state, "_Recording");
121  break;
123  strcpy(state, "_Flushing");
124  break;
125  default:
126  ++idx;
127  continue;
128  }
129  break;
130  }
131  ++idx;
132  }
133  }
134  if (rx_log.isOpen() && state[0] != 0)
135  {
136  rx_log.flush();
137  rx_log.close();
138  }
139 }
140 inline static void checkStateRx(char* state, int length, void const* data, XsFile& rx_log)
141 {
142  XsByteArray tmp((uint8_t*) data, length);
143  checkStateRx(state, length, tmp, rx_log);
144 }
145 
146 #define CHECK_STATE_RX(length, data, logfile) \
147  char state[16] = "";\
148  checkStateRx(state, (int) (length), (data), (logfile))
149 
150 inline static void checkStateTx(char* state, int length, XsByteArray const& data, XsFile& tx_log)
151 {
152  state[0] = 0;
153  if (length >= 4)
154  {
155  // find preamble
156  int idx = 0;
157  while (idx < length - 4)
158  {
159  if (data[idx] == 0xFA && (data[idx + 1] == 0xFF || data[idx + 1] == 0) && data[idx + 3] == 0)
160  {
161  switch (data[idx + 2])
162  {
163  case XMID_GotoConfig:
164  strcpy(state, "_Config");
165  break;
167  strcpy(state, "_Measurement");
168  break;
170  strcpy(state, "_Operational");
171  break;
172  case XMID_StartRecording:
173  strcpy(state, "_Recording");
174  break;
175  case XMID_StopRecording:
176  strcpy(state, "_Flushing");
177  break;
178  default:
179  ++idx;
180  continue;
181  }
182  break;
183  }
184  ++idx;
185  }
186  }
187  if (tx_log.isOpen() && state[0] != 0)
188  {
189  tx_log.flush();
190  tx_log.close();
191  }
192 }
193 inline static void checkStateTx(char* state, int length, void const* data, XsFile& tx_log)
194 {
195  XsByteArray tmp((uint8_t*) data, length);
196  checkStateTx(state, length, tmp, tx_log);
197 }
198 #define CHECK_STATE_TX(length, data, logfile) \
199  char state[16] = "";\
200  checkStateTx(state, (int) (length), (data), (logfile))
201 
202 #else
203 static const char state[1] = "";
204 #define CHECK_STATE_RX(...) ((void)0)
205 #define CHECK_STATE_TX(...) ((void)0)
206 #endif
207 
208 #endif
209 #endif
210 #endif
XMID_GotoConfig
@ XMID_GotoConfig
Definition: xsxbusmessageid.h:158
XMID_GotoMeasurement
@ XMID_GotoMeasurement
Definition: xsxbusmessageid.h:101
XsByteArray
A list of uint8_t values.
XMID_StartRecordingAck
@ XMID_StartRecordingAck
Definition: xsxbusmessageid.h:452
xstimestamp.h
XMID_GotoOperational
@ XMID_GotoOperational
Definition: xsxbusmessageid.h:433
XMID_StartRecording
@ XMID_StartRecording
Definition: xsxbusmessageid.h:451
XMID_GotoConfigAck
@ XMID_GotoConfigAck
Definition: xsxbusmessageid.h:159
xsxbusmessageid.h
XMID_StopRecordingAck
@ XMID_StopRecordingAck
Definition: xsxbusmessageid.h:454
XMID_GotoMeasurementAck
@ XMID_GotoMeasurementAck
Definition: xsxbusmessageid.h:102
XsFile
Encapsulates a file, providing a platform independent interface.
Definition: xsfile.h:131
XMID_StopRecording
@ XMID_StopRecording
Definition: xsxbusmessageid.h:453
XMID_GotoOperationalAck
@ XMID_GotoOperationalAck
Definition: xsxbusmessageid.h:434
XS_MAX_FILENAME_LENGTH
#define XS_MAX_FILENAME_LENGTH
Definition: xsfile.h:78


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20