Skip to content

Commit 12f4950

Browse files
authored
Merge pull request #151 from Hyp-ed/brake_pressure
SNS - Brake Pressure
2 parents 516a539 + d90d1b7 commit 12f4950

File tree

6 files changed

+75
-21
lines changed

6 files changed

+75
-21
lines changed

configurations/debugging/config.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"sensors": {
33
"imu_pins": [],
4-
"temperature_pins": []
4+
"temperature_pins": [],
5+
"brake_pressure_pins": []
56
},
67
"debugger": {
78
"output_path": "readings.json",
@@ -27,6 +28,8 @@
2728
"use_fake_brakes": false,
2829
"use_fake_controller": false,
2930
"use_fake_high_power": false,
31+
"use_fake_brake_pressure": false,
32+
"use_fake_brake_pressure_fail": false,
3033
"axis": 0
3134
},
3235
"fake_trajectory": {

src/debugging/can_listener.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ bool CanListener::hasId(uint32_t id, bool extended)
2121
log_.debug("received extended CAN message; skipping");
2222
return false;
2323
}
24-
return ids_.contains(id);
24+
25+
return ids_.find(id) != ids_.end();
2526
}
2627

2728
void CanListener::subscribe(const uint32_t id)
@@ -31,7 +32,7 @@ void CanListener::subscribe(const uint32_t id)
3132

3233
void CanListener::unsubscribe(const uint32_t id)
3334
{
34-
if (!ids_.contains(id)) {
35+
if (ids_.find(id) == ids_.end()) {
3536
log_.error("tried to unsubscribe from unknown node_id");
3637
return;
3738
}

src/debugging/observer.cpp

+48
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <rapidjson/istreamwrapper.h>
66

77
#include <sensors/fake_temperature.hpp>
8+
#include <sensors/fake_brake_pressure.hpp>
89
#include <sensors/imu.hpp>
910
#include <sensors/main.hpp>
1011
#include <utils/logger.hpp>
@@ -138,6 +139,22 @@ std::optional<std::unique_ptr<Observer>> Observer::fromFile(const std::string &p
138139
observer->addTemperatureTask(pin);
139140
}
140141
}
142+
// BRAKE_PRESSURE
143+
if (system.config_.use_fake_brake_pressure) {
144+
observer->addFakeBrakePressureTask(false);
145+
} else if (system.config_.use_fake_brake_pressure_fail) {
146+
observer->addFakeBrakePressureTask(true);
147+
} else {
148+
const auto pins
149+
= sensors::Main::brakePressurePinsFromFile(log, system.config_.pressure_config_path);
150+
if (!pins) {
151+
log.error("failed to read brake pressure pin from file");
152+
return std::nullopt;
153+
}
154+
for (const auto pin : *pins) {
155+
observer->addBrakePressureTask(pin);
156+
}
157+
}
141158
return observer;
142159
}
143160

@@ -285,4 +302,35 @@ void Observer::addFakeTemperatureTask(const bool is_fail)
285302
tasks_.push_back(temperature_task);
286303
}
287304

305+
void Observer::addBrakePressureTask(const uint8_t pin)
306+
{
307+
auto brake_pressure = std::make_shared<sensors::BrakePressure>(pin);
308+
std::stringstream name;
309+
name << "brake_pressure-" << static_cast<uint32_t>(pin);
310+
Task brake_pressure_task;
311+
brake_pressure_task.name = name.str();
312+
brake_pressure_task.handler = [brake_pressure](JsonWriter &json_writer) {
313+
brake_pressure->run();
314+
json_writer.Key("value");
315+
json_writer.Uint(brake_pressure->getData());
316+
};
317+
tasks_.push_back(brake_pressure_task);
318+
}
319+
320+
void Observer::addFakeBrakePressureTask(const bool is_fail)
321+
{
322+
static uint32_t fake_brake_pressure_id = 0;
323+
auto brake_pressure = std::make_shared<sensors::FakeBrakePressure>(is_fail);
324+
std::stringstream name;
325+
name << "fake_brake_pressure-" << fake_brake_pressure_id++;
326+
Task brake_pressure_task;
327+
brake_pressure_task.name = name.str();
328+
brake_pressure_task.handler = [brake_pressure](JsonWriter &json_writer) {
329+
brake_pressure->run();
330+
json_writer.Key("value");
331+
json_writer.Uint(brake_pressure->getData());
332+
};
333+
tasks_.push_back(brake_pressure_task);
334+
}
335+
288336
} // namespace hyped::debugging

src/debugging/observer.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ class Observer : public utils::concurrent::Thread {
4141

4242
void addTemperatureTask(const uint8_t pin);
4343
void addFakeTemperatureTask(const bool is_fail);
44+
void addBrakePressureTask(const uint8_t pin);
45+
void addFakeBrakePressureTask(const bool is_fail);
4446
};
4547

4648
} // namespace hyped::debugging

src/utils/io/gpio.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace hyped {
2020
namespace utils {
2121
namespace io {
2222

23-
#define GPIOFS 0 // used to swtich to file system method for set(), clear(), and read()
23+
#define GPIOFS 0 // used to switch to file system method for set(), clear(), and read()
2424

2525
// workaround to avoid conflict with GPIO::read()
2626
static uint8_t readHelper(int file)

src/utils/system.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
9191
config.log_level_brakes = *log_level;
9292
} else {
9393
kInitialisationErrorLogger.info(
94-
"could not find field 'system.log_level_brakes' in config filet at %s; using default value",
94+
"could not find field 'system.log_level_brakes' in config file at %s; using default value",
9595
argv[1]);
9696
config.log_level_brakes = config.log_level;
9797
}
@@ -107,7 +107,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
107107
config.log_level_navigation = *log_level;
108108
} else {
109109
kInitialisationErrorLogger.info(
110-
"could not find field 'system.log_level_navigation' in config filet at %s; using default "
110+
"could not find field 'system.log_level_navigation' in config file at %s; using default "
111111
"value",
112112
argv[1]);
113113
config.log_level_navigation = config.log_level;
@@ -124,7 +124,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
124124
config.log_level_propulsion = *log_level;
125125
} else {
126126
kInitialisationErrorLogger.info(
127-
"could not find field 'system.log_level_propulsion' in config filet at %s; using default "
127+
"could not find field 'system.log_level_propulsion' in config file at %s; using default "
128128
"value",
129129
argv[1]);
130130
config.log_level_propulsion = config.log_level;
@@ -141,7 +141,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
141141
config.log_level_sensors = *log_level;
142142
} else {
143143
kInitialisationErrorLogger.info(
144-
"could not find field 'system.log_level_sensors' in config filet at %s; using default value",
144+
"could not find field 'system.log_level_sensors' in config file at %s; using default value",
145145
argv[1]);
146146
config.log_level_sensors = config.log_level;
147147
}
@@ -157,7 +157,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
157157
config.log_level_state_machine = *log_level;
158158
} else {
159159
kInitialisationErrorLogger.info(
160-
"could not find field 'system.log_level_state_machine' in config filet at %s; using default "
160+
"could not find field 'system.log_level_state_machine' in config file at %s; using default "
161161
"value",
162162
argv[1]);
163163
config.log_level_state_machine = config.log_level;
@@ -174,7 +174,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
174174
config.log_level_telemetry = *log_level;
175175
} else {
176176
kInitialisationErrorLogger.info(
177-
"could not find field 'system.log_level_telemetry' in config filet at %s; using default "
177+
"could not find field 'system.log_level_telemetry' in config file at %s; using default "
178178
"value",
179179
argv[1]);
180180
config.log_level_telemetry = config.log_level;
@@ -199,7 +199,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
199199
config.use_fake_trajectory = config_object["use_fake_trajectory"].GetBool();
200200
} else {
201201
kInitialisationErrorLogger.info(
202-
"could not find field 'system.use_fake_trajectory' in config filet at %s; using default "
202+
"could not find field 'system.use_fake_trajectory' in config file at %s; using default "
203203
"value",
204204
argv[1]);
205205
config.use_fake_trajectory = false;
@@ -209,7 +209,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
209209
config.use_fake_batteries = config_object["use_fake_batteries"].GetBool();
210210
} else {
211211
kInitialisationErrorLogger.info(
212-
"could not find field 'system.use_fake_batteries' in config filet at %s; using default "
212+
"could not find field 'system.use_fake_batteries' in config file at %s; using default "
213213
"value",
214214
argv[0]);
215215
config.use_fake_batteries = false;
@@ -219,7 +219,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
219219
config.use_fake_batteries_fail = config_object["use_fake_batteries_fail"].GetBool();
220220
} else {
221221
kInitialisationErrorLogger.info(
222-
"could not find field 'system.use_fake_batteries_fail' in config filet at %s; using default "
222+
"could not find field 'system.use_fake_batteries_fail' in config file at %s; using default "
223223
"value",
224224
argv[0]);
225225
config.use_fake_batteries_fail = false;
@@ -229,7 +229,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
229229
config.use_fake_temperature = config_object["use_fake_temperature"].GetBool();
230230
} else {
231231
kInitialisationErrorLogger.info(
232-
"could not find field 'system.use_fake_temperature' in config filet at %s; using default "
232+
"could not find field 'system.use_fake_temperature' in config file at %s; using default "
233233
"value",
234234
argv[0]);
235235
config.use_fake_temperature = false;
@@ -239,7 +239,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
239239
config.use_fake_temperature_fail = config_object["use_fake_temperature_fail"].GetBool();
240240
} else {
241241
kInitialisationErrorLogger.info(
242-
"could not find field 'system.use_fake_temperature_fail' in config filet at %s; using "
242+
"could not find field 'system.use_fake_temperature_fail' in config file at %s; using "
243243
"default "
244244
"value",
245245
argv[0]);
@@ -251,7 +251,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
251251
config.use_fake_ambient_pressure = config_object["use_fake_ambient_pressure"].GetBool();
252252
} else {
253253
kInitialisationErrorLogger.info(
254-
"could not find field 'system.use_fake_ambient_pressure' in config filet at %s; using "
254+
"could not find field 'system.use_fake_ambient_pressure' in config file at %s; using "
255255
"default "
256256
"value",
257257
argv[0]);
@@ -263,7 +263,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
263263
= config_object["use_fake_ambient_pressure_fail"].GetBool();
264264
} else {
265265
kInitialisationErrorLogger.info(
266-
"could not find field 'system.use_fake_ambient_pressure_fail' in config filet at %s; using "
266+
"could not find field 'system.use_fake_ambient_pressure_fail' in config file at %s; using "
267267
"default "
268268
"value",
269269
argv[0]);
@@ -275,7 +275,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
275275
config.use_fake_brake_pressure = config_object["use_fake_brake_pressure"].GetBool();
276276
} else {
277277
kInitialisationErrorLogger.info(
278-
"could not find field 'system.use_fake_brake_pressure' in config filet at %s; using "
278+
"could not find field 'system.use_fake_brake_pressure' in config file at %s; using "
279279
"default "
280280
"value",
281281
argv[0]);
@@ -286,7 +286,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
286286
config.use_fake_ambient_pressure_fail = config_object["use_fake_brake_pressure_fail"].GetBool();
287287
} else {
288288
kInitialisationErrorLogger.info(
289-
"could not find field 'system.use_fake_brake_pressure_fail' in config filet at %s; using "
289+
"could not find field 'system.use_fake_brake_pressure_fail' in config file at %s; using "
290290
"default "
291291
"value",
292292
argv[0]);
@@ -298,7 +298,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
298298
config.use_fake_brakes = config_object["use_fake_brakes"].GetBool();
299299
} else {
300300
kInitialisationErrorLogger.info(
301-
"could not find field 'system.use_fake_brakes' in config filet at %s; using default "
301+
"could not find field 'system.use_fake_brakes' in config file at %s; using default "
302302
"value",
303303
argv[0]);
304304
config.use_fake_brakes = false;
@@ -308,7 +308,7 @@ void System::parseArgs(const int argc, const char *const *const argv)
308308
config.use_fake_controller = config_object["use_fake_controller"].GetBool();
309309
} else {
310310
kInitialisationErrorLogger.info(
311-
"could not find field 'system.use_fake_controller' in config filet at %s; using default "
311+
"could not find field 'system.use_fake_controller' in config file at %s; using default "
312312
"value",
313313
argv[0]);
314314
config.use_fake_controller = false;

0 commit comments

Comments
 (0)