From 4b321cfe80f0bbf94f3648a9fc056ae2c19a3436 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 6 May 2021 09:04:35 +0200 Subject: Improve platform management and allow energy simulation --- src/inputs.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/inputs.cc (limited to 'src/inputs.cc') diff --git a/src/inputs.cc b/src/inputs.cc new file mode 100644 index 0000000..066dcb0 --- /dev/null +++ b/src/inputs.cc @@ -0,0 +1,50 @@ +#include "inputs.hpp" +#include +#include + + +Inputs::Inputs(std::string node_name){ + FILE* input_file = fopen(INPUTS_FILE, "rb"); + char input_file_buffer[65536]; + rapidjson::FileReadStream is(input_file, input_file_buffer, sizeof(input_file_buffer)); + d.ParseStream(is); + fclose(input_file); + + wake_duration=d[node_name.c_str()]["wake_duration"].GetDouble(); + wake_interval=d[node_name.c_str()]["wake_interval"].GetDouble(); + startup_delay=d[node_name.c_str()]["startup_delay"].GetDouble(); + is_sender=d[node_name.c_str()]["is_sender"].GetBool(); + max_attempts=d[node_name.c_str()]["max_attemps"].GetInt(); + +} + +void Inputs::GeneratePlatform(std::string p){ + FILE* input_file = fopen(INPUTS_FILE, "rb"); + char input_file_buffer[65536]; + rapidjson::FileReadStream is(input_file, input_file_buffer, sizeof(input_file_buffer)); + rapidjson::Document d; + d.ParseStream(is); + fclose(input_file); + + // Write platform file + std::ofstream pf; + pf.open (p); + pf << "\n"; + pf << "\n"; + pf << "\n \n"; + pf << " \n"; + for (Value::ConstMemberIterator itr = d.MemberBegin(); itr != d.MemberEnd(); ++itr) + { + std::string name=itr->name.GetString(); + double power_on=d[itr->name.GetString()]["power_on"].GetDouble(); + double power_off=d[itr->name.GetString()]["power_off"].GetDouble(); + + //db=d[itr->name.GetString()]["wake_interval"].GetDouble(); + pf << " \n"; + pf << " \n"; + pf << " \n \n"; + pf << " \n"; + } + pf << " \n\n"; + pf.close(); +} \ No newline at end of file -- cgit v1.2.3