aboutsummaryrefslogtreecommitdiff
path: root/src/Inputs.cc
diff options
context:
space:
mode:
authorLoic Guegan <manzerbredes@mailbox.org>2021-06-30 15:41:03 +0200
committerLoic Guegan <manzerbredes@mailbox.org>2021-06-30 15:41:03 +0200
commit4d107863208d72ee755b6de2392bcba0372a40fa (patch)
tree0e64395373fc8235bb775429884097b58b62b789 /src/Inputs.cc
parent9ed371278933220a193584cd294e6064ac6dd88c (diff)
Extend simulator
Diffstat (limited to 'src/Inputs.cc')
-rw-r--r--src/Inputs.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/Inputs.cc b/src/Inputs.cc
index 8c3ac9c..0781be8 100644
--- a/src/Inputs.cc
+++ b/src/Inputs.cc
@@ -21,15 +21,21 @@ Inputs::Inputs(std::string node_name){
hint_size=d["hint_size"].GetInt();
n_nodes=d["nodes"].MemberCount();
latency=d["latency"].GetDouble();
+ unschedule_on_rcv=d["unschedule_on_rcv"].GetBool();
+ shutdown_on_rcv=d["shutdown_on_rcv"].GetBool();
+ farhint=d["farhint"].GetBool();
+ hintdist=d["hintdist"].GetDouble();
// Instantiate wake_ts
for(auto& v:d["nodes"][node_name.c_str()]["wake_ts"].GetArray()){
wake_ts.push_back(v.GetDouble());
+ wake_ts_backup.push_back(v.GetDouble());
}
// Instantiate wake_duration
for(auto& v:d["nodes"][node_name.c_str()]["wake_duration"].GetArray()){
wake_duration.push_back(v.GetDouble());
+ wake_duration_backup.push_back(v.GetDouble());
}
// Identity check
@@ -89,11 +95,40 @@ double Inputs::GetNextDuration(){
return wake_duration[1];
}
+double Inputs::GetHintTS(double clock){
+ if(farhint){
+ for(int i=0;i<wake_ts.size();i++){
+ if(wake_ts[i]>=(clock+hintdist))
+ return(wake_ts[i]);
+ }
+ }
+ return(GetNextTS());
+}
+
+double Inputs::GetHintDuration(double clock){
+ if(farhint){
+ for(int i=0;i<wake_ts.size();i++){
+ if(wake_ts[i]>=(clock+hintdist))
+ return(wake_duration[i]);
+ }
+ }
+ return GetNextDuration();
+}
+
void Inputs::GotoNextEvent(){
wake_ts.erase(wake_ts.begin());
wake_duration.erase(wake_duration.begin());
}
+void Inputs::ResetEvents(double clock){
+ wake_ts=wake_ts_backup;
+ wake_duration=wake_duration_backup;;
+ // Restore current event
+ while(HasNext() && (GetTS()+GetNextDuration()) < clock){
+ GotoNextEvent();
+ }
+}
+
void Inputs::DumpEvents(){
std::cout << "Timestamps: ";
for(auto a:wake_ts){