blob: 4e6be32892def67985b701270afdb3729d4d9cdb [file] [log] [blame]
Brian Silverman425492b2015-12-30 15:23:55 -08001#include "frc971/wpilib/pdp_fetcher.h"
2
3#include "aos/common/logging/queue_logging.h"
4#include "aos/linux_code/init.h"
Brian Silverman25ff5052016-01-02 14:13:46 -08005#include "aos/common/util/phased_loop.h"
Brian Silverman39b339e2016-01-03 13:24:22 -08006#include "frc971/wpilib/pdp_values.q.h"
Brian Silverman425492b2015-12-30 15:23:55 -08007
8namespace frc971 {
9namespace wpilib {
10
Brian Silverman425492b2015-12-30 15:23:55 -080011void PDPFetcher::operator()() {
12 ::aos::SetCurrentThreadName("PDPFetcher");
Brian Silverman39b339e2016-01-03 13:24:22 -080013 ::std::unique_ptr<PowerDistributionPanel> pdp(new PowerDistributionPanel());
Brian Silverman25ff5052016-01-02 14:13:46 -080014
15 ::aos::time::PhasedLoop phased_loop(::aos::time::Time::InMS(20),
16 ::aos::time::Time::InMS(4));
17
Brian Silverman425492b2015-12-30 15:23:55 -080018 while (true) {
19 {
Brian Silverman25ff5052016-01-02 14:13:46 -080020 const int iterations = phased_loop.SleepUntilNext();
21 if (iterations != 1) {
22 LOG(DEBUG, "PDPFetcher skipped %d iterations\n", iterations - 1);
23 }
24 }
Brian Silverman39b339e2016-01-03 13:24:22 -080025 auto message = pdp_values.MakeMessage();
26 message->voltage = pdp->GetVoltage();
27 message->temperature = pdp->GetTemperature();
28 message->power = pdp->GetTotalPower();
Brian Silverman425492b2015-12-30 15:23:55 -080029 for (int i = 0; i < 16; ++i) {
Brian Silverman39b339e2016-01-03 13:24:22 -080030 message->currents[i] = pdp->GetCurrent(i);
Brian Silverman425492b2015-12-30 15:23:55 -080031 }
Brian Silverman39b339e2016-01-03 13:24:22 -080032 LOG_STRUCT(DEBUG, "got", *message);
33 if (!message.Send()) {
34 LOG(WARNING, "sending pdp values failed\n");
Brian Silverman425492b2015-12-30 15:23:55 -080035 }
36 }
37}
38
39} // namespace wpilib
40} // namespace frc971