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
16static const char* fileName = "./simulator/resources/simulation_parameters.txt";
17
18static const char* batteryVoltageKey = "batt_V";
19static const char* vbusVoltageKey = "vbus_V";
20static const char* cpuTemperatureKey = "cpu_temp";
21static const char* addedAlgoDelayKey = "algo_del";
22
25{
26 static bool fileNotDetectedCalled = false;
27
28 std::ifstream file(fileName);
29 if (file.is_open())
30 {
31 fileNotDetectedCalled = false;
32
33 while (file)
34 {
35 std::string line;
36 std::getline(file, line);
37
38 // skip empty lines & comments
39 if (line.empty() or line[0] == '#')
40 continue;
41 std::stringstream linestream(line);
42 if (!linestream)
43 continue;
44
45 std::string key;
46 float value;
47 linestream >> key >> value;
48
49 if (key == batteryVoltageKey)
50 {
51 mock_battery::voltage = value;
52 }
53 else if (key == vbusVoltageKey)
54 {
55 mock_electrical::inputVbusVoltage = value;
56 }
57 else if (key == cpuTemperatureKey)
58 {
59 mock_registers::cpuTemperature = value;
60 }
61 else if (key == addedAlgoDelayKey)
62 {
63 mock_registers::addedAlgoDelay = value;
64 }
65 // TODO: other parameters
66 }
67 }
68 else
69 {
70 if (!fileNotDetectedCalled)
71 std::cerr << "Parameter file " << fileName << " not detected" << std::endl;
72 fileNotDetectedCalled = true;
73 }
74
75 file.close();
76}
77
78} // namespace simulator
79
80#endif
Handle the physical simulation paremeters of a real lamp.
Simulator dedicated namespace.
Definition: default_simulation.h:8
void read_and_update_parameters()
Read parameters from the parameter file, and update the simulation.
Definition: parameter_parser.h:24