Skip to content

Commit ac4cedd

Browse files
committed
Successful meta-log build. Untested
Thank you mpkarpov for the starter code, that is helping plenty
1 parent a069cc6 commit ac4cedd

File tree

8 files changed

+85
-58
lines changed

8 files changed

+85
-58
lines changed

MIDAS/src/data_logging.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class MultipleLogSink : public LogSink {
4141
};
4242

4343
void write(const uint8_t* data, size_t size) override {};
44+
45+
void write_meta(const uint8_t* data, size_t size) override {};
4446
};
4547

4648
template<typename Sink, typename... Sinks>
@@ -61,6 +63,11 @@ class MultipleLogSink<Sink, Sinks...> : public LogSink {
6163
sinks.write(data, size);
6264
};
6365

66+
void write_meta(const uint8_t* data, size_t size) override {
67+
sink.write(data, size);
68+
sinks.write(data, size);
69+
};
70+
6471
private:
6572
Sink sink;
6673
MultipleLogSink<Sinks...> sinks;

MIDAS/src/data_logging_meta.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "data_logging_meta.h"
2+
#include "log_format.h"
3+
#include "log_checksum.h"
4+
5+
/*
6+
7+
Queue<MetaLogging::MetaLogEntry> _q;
8+
9+
bool MetaLogging::get_queued(MetaLogEntry* out) { return _q.receive(out); }
10+
11+
void log_event(MetaDataCode event_type, uint32_t timestamp) {
12+
MetaLogging::MetaLogEntry entry{event_type, 0, 0};
13+
entry.size = sizeof(uint32_t);
14+
memcpy(entry.data, &timestamp, entry.size);
15+
_q.send(entry);
16+
}
17+
18+
template <typename T>
19+
void log_data(MetaDataCode data_type, const T& data) {
20+
21+
// double check...
22+
static_assert(sizeof(T) <= META_LOGGING_MAX_SIZE, "Datatype for log_data too large");
23+
24+
MetaLogEntry entry{data_type, 0, 0};
25+
entry.size = sizeof(T);
26+
memcpy(entry.data, &data, entry.size);
27+
_q.send(entry);
28+
29+
30+
}
31+
32+
*/

MIDAS/src/data_logging_meta.h

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#pragma once
2-
#include "rocket_state.h"
2+
//#include "rocket_state.h"
3+
//#include "errors.h"
4+
5+
/*
36
47
#define META_LOGGING_MAX_SIZE 64
58
@@ -28,27 +31,12 @@ struct MetaLogging {
2831
size_t size;
2932
};
3033
31-
Queue<MetaLogEntry> _q;
32-
33-
bool get_queued(MetaLogEntry* out) { return _q.receive(out); }
34+
bool get_queued(MetaLogEntry* out);
3435
35-
void log_event(MetaDataCode event_type, uint32_t timestamp) {
36-
MetaLogEntry entry{event_type, 0, 0};
37-
entry.size = sizeof(uint32_t);
38-
memcpy(entry.data, &timestamp, entry.size);
39-
_q.send(entry);
40-
}
36+
void log_event(MetaDataCode event_type, uint32_t timestamp);
4137
4238
template <typename T>
43-
void log_data(MetaDataCode data_type, const T& data) {
44-
45-
// double check...
46-
static_assert(sizeof(T) <= META_LOGGING_MAX_SIZE, "Datatype for log_data too large");
47-
48-
MetaLogEntry entry{data_type, 0, 0};
49-
entry.size = sizeof(T);
50-
memcpy(entry.data, &data, entry.size);
51-
_q.send(entry);
52-
}
53-
39+
void log_data(MetaDataCode data_type, const T& data);
5440
};
41+
42+
*/

MIDAS/src/finite-state-machines/fsm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class FSM {
3232
public:
3333
FSM() = default;
3434

35-
FSMState tick_fsm(FSMState& curr_state, StateEstimate state_estimate, CommandFlags& commands);
35+
// FSMState tick_fsm(FSMState& curr_state, StateEstimate state_estimate, CommandFlags& commands);
3636

3737
// Constructor for the metadata
3838
// Created so that FSMState, StateEstimate, and CommandFlags objects can supercede the mutex lock

MIDAS/src/hardware/SDLog.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ void SDSink::write(const uint8_t* data, size_t size) {
6060
unflushed_bytes = 0;
6161
}
6262
}
63+
64+
return;
6365
}
6466

6567
void SDSink::write_meta(const uint8_t* data, size_t size) {
@@ -68,4 +70,6 @@ void SDSink::write_meta(const uint8_t* data, size_t size) {
6870
file.write(data, size);
6971
file.write('\n');
7072
file.flush(); // Meta writes are infrequent, so flushing is OK.
73+
74+
return;
7175
}

MIDAS/src/hardware/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515

1616
// #ifdef IS_SUSTAINER
17-
// MultipleLogSink<EMMCSink> sinks;
17+
//MultipleLogSink<EMMCSink> sinks;
1818
MultipleLogSink<SDSink> sinks;
1919
// #else
2020
// MultipleLogSink<> sinks;

MIDAS/src/rocket_state.h

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
#include "hal.h"
77
#include "Buffer.h"
88

9-
// temprary macro
10-
// originally declared in data_loggng_meta.h
11-
#define META_LOGGING_MAX_SIZE 64
12-
139
/**
1410
* @brief The RocketState struct stores everything that is needed by more than one system/thread of the Rocket.
1511
*
@@ -176,36 +172,35 @@ enum MetaDataCode {
176172
};
177173

178174
struct MetaLogging {
179-
private:
180-
struct MetaLogEntry {
181-
MetaDataCode log_type;
182-
char data[64];
183-
size_t size;
184-
};
185-
186-
Queue<MetaLogEntry> _q;
187-
188175
public:
189-
bool get_queued(MetaLogEntry* out) { return _q.receive(out); }
190-
191-
void log_event(MetaDataCode event_type, uint32_t timestamp) {
192-
MetaLogEntry entry{event_type, 0, 0};
193-
entry.size = sizeof(uint32_t);
194-
memcpy(entry.data, &timestamp, entry.size);
195-
_q.send(entry);
196-
}
197-
198-
template <typename T>
199-
void log_data(MetaDataCode data_type, const T& data) {
200-
201-
// double check...
202-
static_assert(sizeof(T) <= META_LOGGING_MAX_SIZE, "Datatype for log_data too large");
203-
204-
MetaLogEntry entry{data_type, 0, 0};
205-
entry.size = sizeof(T);
206-
memcpy(entry.data, &data, entry.size);
207-
_q.send(entry);
208-
}
176+
struct MetaLogEntry {
177+
MetaDataCode log_type;
178+
size_t size;
179+
char data[META_LOGGING_MAX_SIZE];
180+
};
181+
182+
Queue<MetaLogEntry> _q;
183+
184+
bool get_queued(MetaLogEntry* out) { return _q.receive(out); }
185+
186+
void log_event(MetaDataCode event_type, uint32_t timestamp) {
187+
MetaLogEntry entry{event_type, 0, 0};
188+
entry.size = sizeof(uint32_t);
189+
memcpy(entry.data, &timestamp, entry.size);
190+
_q.send(entry);
191+
}
192+
193+
template <typename T>
194+
void log_data(MetaDataCode data_type, const T& data) {
195+
196+
// double check...
197+
static_assert(sizeof(T) <= META_LOGGING_MAX_SIZE, "Datatype for log_data too large");
198+
199+
MetaLogEntry entry{data_type, 0, 0};
200+
entry.size = sizeof(T);
201+
memcpy(entry.data, &data, entry.size);
202+
_q.send(entry);
203+
}
209204
};
210205

211206
/**

MIDAS/src/systems.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ DECLARE_THREAD(logger, RocketSystems* arg) {
2828
arg->rocket_data.log_latency.tick();
2929
meta_delay_ctr++;
3030

31+
MetaLogging::MetaLogEntry entry;
32+
3133
if (meta_delay_ctr >= 100) {
32-
MetaLogging::MetaLogEntry entry;
3334
if(arg->meta_logging.get_queued(&entry)) {
3435
uint8_t buf[72];
3536
size_t total_size = sizeof(MetaDataCode) + entry.size;
@@ -201,7 +202,7 @@ DECLARE_THREAD(fsm, RocketSystems* arg) {
201202
CommandFlags& telemetry_commands = arg->rocket_data.command_flags;
202203
double current_time = pdTICKS_TO_MS(xTaskGetTickCount());
203204

204-
FSMState next_state = fsm.tick_fsm(current_state, state_estimate, telemetry_commands);
205+
FSMState next_state = fsm.tick_fsm(arg->rocket_data);
205206

206207
arg->rocket_data.fsm_state.update(next_state);
207208
if(current_state != next_state) {fsm_transitioned_to(next_state, current_state, arg, current_time);}

0 commit comments

Comments
 (0)