Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
parameter_parser.h
Go to the documentation of this file.
1
5#ifndef PARAMETER_PARSER_H
6#define PARAMETER_PARSER_H
7
8#include <fstream>
9#include <sstream>
10#include <iostream>
11
13
14namespace simulator {
15
16#ifndef LMBD_SIMULATOR_RESOURCES_DIR
17#error "LMBD_SIMULATOR_RESOURCES_DIR must be defined by CMake"
18#endif
19
20static const char* fileName = LMBD_SIMULATOR_RESOURCES_DIR "/simulation_parameters.txt";
21
22static const char* batteryVoltageKey = "batt_V";
23static const char* vbusVoltageKey = "vbus_V";
24static const char* vbusCurrentKey = "vbus_A";
25static const char* cpuTemperatureKey = "cpu_temp";
26static const char* addedAlgoDelayKey = "algo_del";
27
30{
31 static bool fileNotDetectedCalled = false;
32
33 std::ifstream file(fileName);
34 if (file.is_open())
35 {
36 fileNotDetectedCalled = false;
37
38 while (file)
39 {
40 std::string line;
41 std::getline(file, line);
42
43 // skip empty lines & comments
44 if (line.empty() or line[0] == '#')
45 continue;
46 std::stringstream linestream(line);
47 if (!linestream)
48 continue;
49
50 std::string key;
51 float value;
52 linestream >> key >> value;
53
54 if (key == batteryVoltageKey)
55 {
56 mock_battery::voltage = value;
57 }
58 else if (key == vbusVoltageKey)
59 {
60 mock_electrical::inputVbusVoltage = value;
61 }
62 else if (key == vbusCurrentKey)
63 {
64 mock_electrical::inputVbusCurrent = value;
65 }
66 else if (key == cpuTemperatureKey)
67 {
68 mock_registers::cpuTemperature = value;
69 }
70 else if (key == addedAlgoDelayKey)
71 {
72 mock_registers::addedAlgoDelay = value;
73 }
74 }
75 }
76 else
77 {
78 if (!fileNotDetectedCalled)
79 std::cerr << "Parameter file " << fileName << " not detected" << std::endl;
80 fileNotDetectedCalled = true;
81 }
82
83 file.close();
84}
85
86} // namespace simulator
87
88#endif
Handle the physical simulation paremeters of a real lamp.
Simulator dedicated namespace.
Definition: BQ25713_mock.h:23
void read_and_update_parameters()
Read parameters from the parameter file, and update the simulation.
Definition: parameter_parser.h:29