From d0e57511fda12afb1049e260bcccb434b186d735 Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 6 May 2021 16:14:57 +0200 Subject: Switch to timestamps --- src/inputs.cc | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 6 deletions(-) (limited to 'src/inputs.cc') diff --git a/src/inputs.cc b/src/inputs.cc index 0cba7b6..84acdb7 100644 --- a/src/inputs.cc +++ b/src/inputs.cc @@ -1,27 +1,138 @@ #include "inputs.hpp" +#include "xbt/log.h" +#include #include #include Inputs::Inputs(std::string node_name){ + // Here we doing all the boring stuff FILE* input_file = fopen(INPUTS_FILE, "rb"); - char input_file_buffer[65536]; + char input_file_buffer[JSON_BUFFER_SIZE]; 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(); + // Init all variables is_sender=d[node_name.c_str()]["is_sender"].GetBool(); use_hint=d[node_name.c_str()]["use_hint"].GetBool(); - max_attempts=d[node_name.c_str()]["max_attemps"].GetInt(); data_size=d[node_name.c_str()]["data_size"].GetInt(); + for(auto& v:d[node_name.c_str()]["wake_ts"].GetArray()){ + wake_ts.push_back(v.GetDouble()); + } + for(auto& v:d[node_name.c_str()]["wake_duration"].GetArray()){ + wake_duration.push_back(v.GetDouble()); + } + + // Identity check + if(wake_ts.size()!=wake_duration.size()){ + std::cerr << "Invalid node configuration: wake_ts.size() != wake_duration.size()" <=next_ts){ + // Create variable for convenience + double start=cur_ts; + double end=std::max(cur_ts+cur_duration,next_ts+next_duration); + wake_duration[i]=end-start; + // Now remove next event + wake_ts.erase(wake_ts.begin() + i + 1); + wake_duration.erase(wake_duration.begin() + i +1); + // This is not optimal. Yet it is simple :D + MergeEvents(); + } + } +} + +double Inputs::GetNextTS(){ + // Ensure the caller is smart + if(wake_duration.size()<2){ + std::cerr << "You are trying to access to the next timestamp but it does not exists" <=ts){ + wake_ts.insert(it,ts); + break; + } + pos++; + } + + // Ensure that ts and duration should not go to the end + if(pos==wake_ts.size()){ + wake_ts.push_back(ts); + wake_duration.push_back(duration); + } + else { + // Handle durations here + int pos2=0; + for(auto it = std::begin(wake_duration); it != std::end(wake_duration); ++it) { + if(pos==pos2){ + wake_duration.insert(it,duration); + break; + } + else if (it+1==std::end(wake_duration)) { + wake_duration.push_back(duration); + } + pos2++; + } + } + // Don't forget + MergeEvents(); } void Inputs::GeneratePlatform(std::string p){ + // The boring stuff FILE* input_file = fopen(INPUTS_FILE, "rb"); - char input_file_buffer[65536]; + char input_file_buffer[JSON_BUFFER_SIZE]; rapidjson::FileReadStream is(input_file, input_file_buffer, sizeof(input_file_buffer)); rapidjson::Document d; d.ParseStream(is); -- cgit v1.2.3