Skip to content

Commit b8140c1

Browse files
committed
logging
1 parent 7479925 commit b8140c1

File tree

18 files changed

+373
-149
lines changed

18 files changed

+373
-149
lines changed

src/ahr/ahr.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,11 @@ SOFTWARE.
2424

2525
#define MF_MOD "AHR"
2626

27-
#include <Arduino.h> //Serial
28-
#include "ahr.h"
27+
#include "../madflight_modules.h"
2928
#include "AhrGizmoMahony.h"
3029
#include "AhrGizmoMadgwick.h"
3130
#include "AhrGizmoVqf.h"
3231

33-
#include "../mag/mag.h"
34-
#include "../imu/imu.h"
35-
#include "../cfg/cfg.h"
36-
#include "../tbx/common.h" //lowpass_to_beta
37-
#include "../tbx/RuntimeTrace.h"
38-
3932
//create global module instance
4033
Ahr ahr;
4134

@@ -121,6 +114,8 @@ bool Ahr::update() {
121114
//update euler angles
122115
computeAngles();
123116

117+
bbx.log_ahrs();
118+
124119
runtimeTrace.stop(true);
125120
return true;
126121
}

src/bbx/BbxGizmoSdcard_RP2.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*==========================================================================================
2+
MIT License
3+
4+
Copyright (c) 2023-2026 https://madflight.com
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
===========================================================================================*/
24+
125
#ifdef ARDUINO_ARCH_RP2040
226

327
#include "BbxGizmoSdcard_RP2.h"

src/bbx/BbxGizmoSdcard_RP2.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*==========================================================================================
2+
MIT License
3+
4+
Copyright (c) 2023-2026 https://madflight.com
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
===========================================================================================*/
24+
125
#ifdef ARDUINO_ARCH_RP2040
226

327
#pragma once

src/bbx/BbxGizmoSdspi+Sdmmc_ESP32.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
/*==========================================================================================
2+
MIT License
3+
4+
Copyright (c) 2023-2026 https://madflight.com
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
===========================================================================================*/
124

225
#include "bbx.h"
326

src/bbx/BinLog.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*==========================================================================================
2+
MIT License
3+
4+
Copyright (c) 2023-2026 https://madflight.com
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
===========================================================================================*/
24+
125
#pragma once
226

327
#include <Arduino.h> //Serial

src/bbx/BinLogWriter.cpp

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1-
2-
3-
1+
/*==========================================================================================
2+
MIT License
3+
4+
Copyright (c) 2023-2026 https://madflight.com
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
===========================================================================================*/
424

525
//BinLog uses 32bit microsecond timestamps (good for 1 hour of recording before wrap-around)
626

@@ -23,15 +43,13 @@ namespace BinLogWriter {
2343
static void bbx_task(void *pvParameters);
2444
void FMT_sendFMT();
2545

26-
27-
Command_t command = NONE;
2846
State_t state = READY;
2947
uint32_t startMicros = 0;
3048
uint32_t missCnt = 0;
3149

3250
struct msg_t
3351
{
34-
uint8_t buf[MAX_MSG_LEN]; //NOTE: first byte overwritten with msg len when stuffed in queue
52+
uint8_t buf[MAX_MSG_LEN]; //NOTE: first byte overwritten with msg len when stuffed in queue, when len==0 then second byte is Command_t
3553
};
3654

3755
QueueHandle_t queue = nullptr;
@@ -44,20 +62,15 @@ namespace BinLogWriter {
4462
uint32_t typeRegistry[LOG_TYPE_LEN] = {}; //MSB is FMT+FMTU written flag, 31 LSB is message name
4563
uint8_t typeRegistry_len = 0;
4664

47-
48-
49-
5065
void stop() {
51-
command = STOP;
5266
//send zero length message to wake up BB task to process command
53-
uint8_t msg = 0;
67+
uint8_t msg[] = {0, STOP};
5468
xQueueSend(queue, (void*)&msg, 0);
5569
}
5670

5771
void start() {
58-
command = START;
5972
//send zero length message to wake up BB task to process command
60-
uint8_t msg = 0;
73+
uint8_t msg[] = {0, START};
6174
xQueueSend(queue, (void*)&msg, 0);
6275
}
6376

@@ -76,10 +89,12 @@ namespace BinLogWriter {
7689

7790
//append message to queue
7891
bool queueSend(uint8_t *buf, uint8_t len, uint8_t keepfree) {
79-
if(keepfree && uxQueueSpacesAvailable(queue) < keepfree) return false;
80-
//NOTE: random data will pad the message - improve this?
92+
if(keepfree && uxQueueSpacesAvailable(queue) < keepfree) {
93+
missCnt++;
94+
return false;
95+
}
8196
buf[0] = len; //overwrite header1 with message length
82-
bool ok = ( xQueueSend(queue, (void*)buf, 0) == pdPASS );
97+
bool ok = ( xQueueSend(queue, (void*)buf, 0) == pdPASS ); //NOTE: random data will pad the message
8398
if(!ok) missCnt++;
8499
return ok;
85100
}
@@ -214,7 +229,7 @@ namespace BinLogWriter {
214229

215230

216231
void cmd_start() {
217-
if(state!=READY) return;
232+
if(state != READY) return;
218233
state = STARTING;
219234

220235
//empty the queue
@@ -263,6 +278,9 @@ namespace BinLogWriter {
263278

264279
//allow logging
265280
state = STARTED;
281+
282+
//log flight mode
283+
bbx.log_mode();
266284
}
267285

268286
void cmd_stop() {
@@ -284,21 +302,22 @@ namespace BinLogWriter {
284302
static msg_t msg;
285303
for(;;) {
286304
bool updated = (xQueueReceive(queue, &msg, portMAX_DELAY) == pdPASS);
305+
runtimeTrace.start();
287306
if(updated) {
288-
runtimeTrace.start();
289-
switch(command) {
290-
case START:
291-
command = NONE;
292-
cmd_start();
293-
break;
294-
case STOP:
295-
command = NONE;
296-
cmd_stop();
297-
break;
298-
case NONE:
299-
//extract message length and restore header1
300-
uint8_t len = msg.buf[0];
301-
msg.buf[0] = HEAD_BYTE1;
307+
uint8_t len = msg.buf[0];
308+
if(len == 0) {
309+
//decode command
310+
switch( (Command_t)msg.buf[1] ) {
311+
case START:
312+
cmd_start();
313+
break;
314+
case STOP:
315+
cmd_stop();
316+
break;
317+
}
318+
}else{
319+
//write message
320+
msg.buf[0] = HEAD_BYTE1; //restore header1
302321
if(bbx.gizmo) bbx.gizmo->write(msg.buf, len);
303322
}
304323
}

src/bbx/BinLogWriter.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
/*==========================================================================================
2+
MIT License
3+
4+
Copyright (c) 2023-2026 https://madflight.com
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
===========================================================================================*/
24+
125
#pragma once
226

327
#define LOG_TYPE_LEN 64 // max number of message types
@@ -9,7 +33,7 @@
933

1034

1135
namespace BinLogWriter {
12-
enum Command_t { NONE, START, STOP };
36+
enum Command_t { START, STOP };
1337
enum State_t { READY, STARTING, STARTED };
1438

1539
extern uint32_t missCnt;

0 commit comments

Comments
 (0)