Skip to content

Commit e966867

Browse files
committed
working on autogeneration of message unpacking and decoding
1 parent 34ec8ee commit e966867

17 files changed

+18882
-225
lines changed

Telemetry-Main/fsdaq/can_processor_generated.cpp

Lines changed: 650 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "can_processor_generated.hpp"
2+
#include "encoder_generated.hpp"
3+
#include "mbed.h"
4+
5+
namespace fsdaq {
6+
7+
CANProcessor::CANProcessor(CAN &can)
8+
: current_row(std::make_unique<DataRow>()), can(can) {}
9+
10+
void CANProcessor::process_message() {
11+
CANMessage msg;
12+
if (!can.read(msg)) return;
13+
switch (static_cast<fsdaq::MessageID>(msg.id)) {
14+
@CAN_MESSAGE_PROCESSING@
15+
};
16+
}
17+
18+
} // namespace fsdaq
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#pragma once
2+
3+
#include "mbed.h"
4+
#include "encoder_generated.hpp"
5+
6+
namespace fsdaq {
7+
8+
enum MessageID : uint32_t {
9+
SYNC = 0x80,
10+
SME_RPDO_Throttle_Demand = 0x186,
11+
SME_RPDO_Max_Currents = 0x286,
12+
SME_TPDO_Torque_speed = 0x482,
13+
SME_TPDO_Temperature = 0x682,
14+
ACC_TPDO_STATUS = 0x188,
15+
ACC_TPDO_POWER = 0x288,
16+
ACC_TPDO_SEG0_VOLTS = 0x191,
17+
ACC_TPDO_SEG0_TEMPS = 0x291,
18+
ACC_TPDO_SEG1_VOLTS = 0x192,
19+
ACC_TPDO_SEG1_TEMPS = 0x292,
20+
ACC_TPDO_SEG2_VOLTS = 0x193,
21+
ACC_TPDO_SEG2_TEMPS = 0x293,
22+
ACC_TPDO_SEG3_VOLTS = 0x194,
23+
ACC_TPDO_SEG3_TEMPS = 0x294,
24+
ACC_TPDO_SEG4_VOLTS = 0x195,
25+
ACC_TPDO_SEG4_TEMPS = 0x295,
26+
VDM_GPS_LAT_LONG = 0xa0000,
27+
VDM_GPS_DATA = 0xa0001,
28+
VDM_DATE_TIME = 0xa0002,
29+
VDM_ACCELERATION = 0xa0003,
30+
VDM_YAW_RATE = 0xa0004,
31+
ETC_TPDO_STATUS = 0x189,
32+
PDB_TPDO_POWER_A = 0x19a,
33+
PDB_TPDO_POWER_B = 0x29a,
34+
TMAIN_TPDO_DATA = 0x1a0,
35+
TPERIPH_FL_TPDO_DATA = 0x1a2,
36+
TPERIPH_FR_TPDO_DATA = 0x1a3,
37+
TPERIPH_BL_TPDO_DATA = 0x1a4,
38+
TPERIPH_BR_TPDO_DATA = 0x1a5,
39+
TPERIPH_FL_TPDO_TIRETEMP = 0x2a1,
40+
TPERIPH_FR_TPDO_TIRETEMP = 0x2a2,
41+
TPERIPH_BL_TPDO_TIRETEMP = 0x2a3,
42+
TPERIPH_BR_TPDO_TIRETEMP = 0x2a4,
43+
LSS_COMMAND = 0x7e5,
44+
LSS_RESPONSE = 0x7e4,
45+
SMPC_RPDO_CONTROL = 0x206,
46+
SMPC_RPDO_MAX_VOLTAGE_CURRENT = 0x306,
47+
SMPC_TPDO_STATUS = 0x190,
48+
SMPC_TPDO_MAX_VOLTAGE_CURRENT = 0x290,
49+
SMPC_TPDO_INPUT_AC = 0x390,
50+
SMPC_TPDO_SERIAL_PART_NUM = 0x490,
51+
};
52+
53+
class CANProcessor {
54+
public:
55+
std::unique_ptr<DataRow> current_row;
56+
57+
CANProcessor(CAN &can);
58+
59+
void process_message();
60+
61+
private:
62+
CAN &can;
63+
};
64+
65+
} // namespace fsdaq
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include "mbed.h"
4+
#include "encoder_generated.hpp"
5+
6+
namespace fsdaq {
7+
8+
enum MessageID : uint32_t {
9+
@MESSAGE_IDS@
10+
};
11+
12+
class CANProcessor {
13+
public:
14+
std::unique_ptr<DataRow> current_row;
15+
16+
CANProcessor(CAN &can);
17+
18+
void process_message();
19+
20+
private:
21+
CAN &can;
22+
};
23+
24+
} // namespace fsdaq

Telemetry-Main/fsdaq/encoder_generated_from_dbc.hpp renamed to Telemetry-Main/fsdaq/encoder_generated.hpp

Lines changed: 139 additions & 137 deletions
Large diffs are not rendered by default.

Telemetry-Main/fsdaq/encoder_generated_from_dbc.hpp.in renamed to Telemetry-Main/fsdaq/encoder_generated.hpp.in

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma once
2+
13
#include "mbed.h"
24

35
namespace fsdaq {
@@ -10,16 +12,16 @@ static const char *col_names[] = { @COL_NAMES@ };
1012
static const uint8_t col_name_sizes[] = { @COL_NAME_SIZES@ };
1113
static const char *col_name_types[] = { @COL_NAME_TYPES@ };
1214

13-
struct BatchRow {
14-
@BATCH_ROW_STRUCT_FIELDS@
15+
struct DataRow {
16+
@DATA_ROW_STRUCT_FIELDS@
1517
};
1618

1719
#pragma pack(1)
18-
class Batch {
19-
@BATCH_STRUCT_FIELDS@
20+
class DataBatch {
21+
@DATA_BATCH_STRUCT_FIELDS@
2022

2123
public:
22-
void setRow(BatchRow row, int idx) {
24+
void setRow(DataRow row, int idx) {
2325
@UPDATE_FIELDS_FROM_ROW@
2426
}
2527
};
@@ -45,7 +47,7 @@ inline void write_fsdaq_schema(FILE *file) {
4547
}
4648
}
4749

48-
inline void write_fsdaq_batch(Batch *batch, FILE *file) {
50+
inline void write_fsdaq_batch(DataBatch *batch, FILE *file) {
4951
fwrite(batch, sizeof(*batch), 1, file);
5052
}
5153

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "encoder_generated.hpp"
2+
3+
namespace fsdaq {
4+
5+
class FileBatchWriter {
6+
public:
7+
FileBatchWriter(FILE *file)
8+
: curr_batch(std::make_unique<DataBatch>()), fp(file) {}
9+
10+
void append_row(DataRow next_row) {
11+
curr_batch->setRow(next_row, row_idx);
12+
13+
row_idx++;
14+
if (row_idx == ROWS_PER_BATCH) {
15+
write_fsdaq_batch(curr_batch.get(), fp);
16+
row_idx = 0;
17+
}
18+
}
19+
20+
private:
21+
std::unique_ptr<DataBatch> curr_batch;
22+
23+
int row_idx = 0;
24+
25+
FILE *fp;
26+
};
27+
28+
} // namespace fsdaq
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
#include "encoder_generated.hpp"
4+
5+
namespace fsdaq {
6+
7+
class FileBatchWriter {
8+
public:
9+
FileBatchWriter(FILE *file);
10+
11+
void append_row(DataRow next_row);
12+
13+
private:
14+
std::unique_ptr<DataBatch> curr_batch;
15+
16+
int row_idx;
17+
18+
FILE *fp;
19+
};
20+
21+
} // namespace fsdaq

Telemetry-Main/fsdaq/writer.cpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

Telemetry-Main/fsdaq/writer.hpp

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)