blob: 1c87107010e9b2da700c3c7af6d18422d6265a1f [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"
5
6namespace frc971 {
7namespace wpilib {
8
9PDPFetcher::PDPFetcher() : pdp_(new PowerDistributionPanel()) {
10 pdp_values_.Zero();
11}
12
13void PDPFetcher::GetValues(::aos::PDPValues *pdp_values) {
14 ::aos::MutexLocker locker(&values_lock_);
15 *pdp_values = pdp_values_;
16}
17
18void PDPFetcher::operator()() {
19 ::aos::SetCurrentThreadName("PDPFetcher");
20 // Something in WPILib blocks for long periods of time in here, so it's not
21 // actually a busy loop like it looks. It seems to somehow be related to
22 // joystick packets.
23 while (true) {
24 {
25 const double voltage = pdp_->GetVoltage();
26 ::aos::MutexLocker locker(&values_lock_);
27 pdp_values_.voltage = voltage;
28 }
29 {
30 const double temperature = pdp_->GetTemperature();
31 ::aos::MutexLocker locker(&values_lock_);
32 pdp_values_.temperature = temperature;
33 }
34 {
35 const double power = pdp_->GetTotalPower();
36 ::aos::MutexLocker locker(&values_lock_);
37 pdp_values_.power = power;
38 }
39 for (int i = 0; i < 16; ++i) {
40 const double current = pdp_->GetCurrent(i);
41 ::aos::MutexLocker locker(&values_lock_);
42 pdp_values_.currents[i] = current;
43 }
44 {
45 ::aos::MutexLocker locker(&values_lock_);
46 LOG_STRUCT(DEBUG, "finished fetching", pdp_values_);
47 }
48 }
49}
50
51} // namespace wpilib
52} // namespace frc971