-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathbbx.h
More file actions
105 lines (89 loc) · 3.49 KB
/
bbx.h
File metadata and controls
105 lines (89 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*==========================================================================================
MIT License
Copyright (c) 2023-2026 https://madflight.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
===========================================================================================*/
#pragma once
#include "../cfg/cfg.h"
#include "BinLog.h"
#include <SPI.h>
#include "../tbx/RuntimeTrace.h"
#include "../ahr/ahr.h"
#include "../imu/imu.h"
#include "../out/out.h"
#include "../rcl/rcl.h"
struct BbxConfig {
public:
Cfg::bbx_gizmo_enum gizmo = Cfg::bbx_gizmo_enum::mf_NONE; //the gizmo to use
SPIClass *spi_bus = nullptr; //spi bus
uint8_t i2c_adr = 0; //i2c address. 0=default address
int32_t spi_cs = -1;
int32_t pin_mmc_dat = -1;
int32_t pin_mmc_clk = -1;
int32_t pin_mmc_cmd = -1;
int32_t bbx_ser_bus = -1;
int32_t bbx_baud = 0;
};
class BbxGizmo {
public:
virtual ~BbxGizmo() {}
virtual void setup() = 0; //setup the gizmo
virtual bool writeOpen() = 0; //create new file for writing (closes previously opened file first)
virtual void write(const uint8_t *buf, const uint8_t len) = 0; //write to file
virtual void close() = 0; //close file
virtual void erase() = 0; //erase all files
virtual void dir() = 0; //list files
virtual void bench() = 0; //benchmark read/write
virtual void info() = 0; //card info
virtual int read(const char* filename, uint8_t **data) {(void) filename; (void) data; return 0;}
virtual void printSummary() {}
};
class Bbx {
private:
void gizmo_create_sd();
public:
BbxConfig config;
BbxGizmo *gizmo = nullptr;
public:
//Blackbox Interface
int setup(); //setup blackbox
void start(); //start logging (create new file)
void stop(); //stop logging (closes file)
void erase(); //erase all log files
void dir(); //list log files
void bench(); //benchmark read/write to blackbox
void info(); //blackbox info (memory size, free space, etc.)
int read(const char* filename, uint8_t **data); //read file into data (malloc), returns file size.
void printSummary();
//loggers
void log_baro();
void log_bat();
void log_gps();
void log_imu(ImuState *imu_s);
void log_mode();
void log_msg(const char* msg);
void log_parm(const char* name, float value, float default_value);
void log_pid();
// void log_att();
void log_ahr(AhrState *ahr_s);
void log_sys();
void log_out(OutState *out_s);
void log_rdr();
void log_ofl();
void log_rcl(RclState *rcl_s);
};
extern Bbx bbx;