mirror of
https://gitlab.com/manzerbredes/loosely-coupled-dss.git
synced 2025-04-06 03:26:24 +02:00
82 lines
2.2 KiB
C++
82 lines
2.2 KiB
C++
![]() |
#include <rapidjson/document.h>
|
||
|
#include <rapidjson/filewritestream.h>
|
||
|
#include <rapidjson/writer.h>
|
||
|
|
||
|
#include <cstdio>
|
||
|
#include <iostream>
|
||
|
#include <time.h>
|
||
|
#include <sstream>
|
||
|
|
||
|
|
||
|
#define RAND(min,max) (rand()%(max-min)+min)
|
||
|
|
||
|
using namespace std;
|
||
|
using namespace rapidjson;
|
||
|
|
||
|
#define N_NODE 10
|
||
|
#define EXTENDED false
|
||
|
#define SIMULATION_DURATION 60
|
||
|
#define POWER_OFF 0
|
||
|
#define POWER_ON 10
|
||
|
#define POWER_RX 11
|
||
|
#define POWER_TX 12
|
||
|
#define DATA_SIZE 50
|
||
|
#define USE_HINT false
|
||
|
#define WAKE_UP_EVERY 10
|
||
|
#define WAKE_UP_FOR 5
|
||
|
#define MAX_STARTUP_DELAY 10
|
||
|
|
||
|
unsigned int seed = 0;
|
||
|
|
||
|
int main(int argc, char **argv){
|
||
|
// Setup seed
|
||
|
if(argc>1){
|
||
|
srand( atoi(argv[1]) );
|
||
|
}
|
||
|
|
||
|
// Create document
|
||
|
Document d;
|
||
|
d.SetObject();
|
||
|
d.AddMember("extended",EXTENDED,d.GetAllocator());
|
||
|
|
||
|
// Create nodes
|
||
|
Value nodes(kObjectType);
|
||
|
for(int i=0;i<N_NODE;i++){
|
||
|
Value node(kObjectType);
|
||
|
node.SetObject();
|
||
|
node.AddMember("use_hint",USE_HINT,d.GetAllocator());
|
||
|
node.AddMember("power_off",POWER_OFF,d.GetAllocator());
|
||
|
node.AddMember("power_on",POWER_ON,d.GetAllocator());
|
||
|
node.AddMember("power_rx",POWER_RX,d.GetAllocator());
|
||
|
node.AddMember("power_tx",POWER_TX,d.GetAllocator());
|
||
|
node.AddMember("is_sender",i==0,d.GetAllocator());
|
||
|
node.AddMember("data_size",DATA_SIZE,d.GetAllocator());
|
||
|
|
||
|
// Setup ts and durations
|
||
|
Value ts(kArrayType);
|
||
|
Value duration(kArrayType);
|
||
|
for(unsigned int i=(RAND(0,MAX_STARTUP_DELAY));(i+WAKE_UP_FOR)<SIMULATION_DURATION;i+=WAKE_UP_EVERY){
|
||
|
ts.PushBack(Value().SetDouble(i),d.GetAllocator());
|
||
|
duration.PushBack(Value().SetDouble(WAKE_UP_FOR),d.GetAllocator());
|
||
|
}
|
||
|
node.AddMember("wake_ts",ts,d.GetAllocator());
|
||
|
node.AddMember("wake_duration",duration,d.GetAllocator());
|
||
|
|
||
|
|
||
|
// Add node to nodes
|
||
|
std::ostringstream ss;
|
||
|
ss<< "on" <<i;
|
||
|
Value key(ss.str().c_str(), d.GetAllocator());
|
||
|
nodes.AddMember(key,node,d.GetAllocator());
|
||
|
}
|
||
|
d.AddMember("nodes",nodes,d.GetAllocator());
|
||
|
|
||
|
|
||
|
// Write to stdout
|
||
|
StringBuffer buffer;
|
||
|
Writer<StringBuffer> writer(buffer);
|
||
|
d.Accept(writer);
|
||
|
cout << buffer.GetString();
|
||
|
|
||
|
return 0;
|
||
|
}
|