Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3a56ff01fe4ed65b9d813802c64fae7bcdd808b9
[simgrid.git] / examples / cpp / battery-degradation / s4u-battery-degradation.cpp
1 /* Copyright (c) 2003-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/plugins/battery.hpp"
7 #include "simgrid/s4u.hpp"
8
9 XBT_LOG_NEW_DEFAULT_CATEGORY(battery_degradation, "Messages specific for this s4u example");
10
11 static void manager()
12 {
13   const auto* battery = simgrid::s4u::this_actor::get_host();
14   double power = 100;
15   while (sg_battery_get_state_of_health(battery) > 0) {
16     XBT_INFO("%f,%f,SoC", simgrid::s4u::Engine::get_clock(), sg_battery_get_state_of_charge(battery));
17     XBT_INFO("%f,%f,SoH", simgrid::s4u::Engine::get_clock(), sg_battery_get_state_of_health(battery));
18     sg_battery_set_power(battery, power);
19     simgrid::s4u::this_actor::sleep_until(sg_battery_get_next_event_date(battery));
20     power *= -1;
21   }
22 }
23
24 int main(int argc, char* argv[])
25 {
26   simgrid::s4u::Engine e(&argc, argv);
27   e.load_platform(argv[1]);
28
29   sg_battery_plugin_init();
30
31   simgrid::s4u::Actor::create("manager", e.get_all_hosts()[0], manager);
32   e.run();
33   return 0;
34 }