2016-01-02 03:02:34 -08:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) FIRST 2016. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
2016-05-22 21:41:22 -07:00
|
|
|
#include "HAL/PDP.h"
|
2016-05-25 22:38:11 -07:00
|
|
|
|
2016-07-20 22:05:17 -07:00
|
|
|
#include <memory>
|
|
|
|
|
|
2016-07-12 10:45:14 -07:00
|
|
|
#include "HAL/Errors.h"
|
2016-07-02 23:19:14 -07:00
|
|
|
#include "HAL/Ports.h"
|
2016-07-20 22:05:17 -07:00
|
|
|
#include "HAL/cpp/make_unique.h"
|
2016-07-02 23:19:14 -07:00
|
|
|
#include "PortsInternal.h"
|
2014-05-30 14:04:05 -04:00
|
|
|
#include "ctre/PDP.h"
|
|
|
|
|
|
2016-07-02 23:19:14 -07:00
|
|
|
using namespace hal;
|
2015-06-16 16:47:35 -04:00
|
|
|
|
2016-07-20 22:05:17 -07:00
|
|
|
static std::unique_ptr<PDP> pdp[kNumPDPModules];
|
|
|
|
|
|
|
|
|
|
static inline bool checkPDPInit(int32_t module, int32_t* status) {
|
|
|
|
|
if (!HAL_CheckPDPModule(module)) {
|
|
|
|
|
*status = RESOURCE_OUT_OF_RANGE;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!pdp[module]) {
|
|
|
|
|
*status = INCOMPATIBLE_STATE;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-06-16 16:47:35 -04:00
|
|
|
|
2015-11-26 00:08:32 -08:00
|
|
|
extern "C" {
|
|
|
|
|
|
2016-07-12 10:45:14 -07:00
|
|
|
void HAL_InitializePDP(int32_t module, int32_t* status) {
|
|
|
|
|
if (!HAL_CheckPDPModule(module)) {
|
2016-07-13 20:29:28 -07:00
|
|
|
*status = RESOURCE_OUT_OF_RANGE;
|
2016-07-12 10:45:14 -07:00
|
|
|
return;
|
|
|
|
|
}
|
2016-05-20 17:30:37 -07:00
|
|
|
if (!pdp[module]) {
|
2016-07-20 22:05:17 -07:00
|
|
|
pdp[module] = std::make_unique<PDP>(module);
|
2016-05-20 17:30:37 -07:00
|
|
|
}
|
2015-06-16 16:47:35 -04:00
|
|
|
}
|
|
|
|
|
|
2016-07-12 10:45:14 -07:00
|
|
|
HAL_Bool HAL_CheckPDPModule(int32_t module) {
|
2016-07-20 22:47:29 -07:00
|
|
|
return module < kNumPDPModules && module >= 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HAL_Bool HAL_CheckPDPChannel(int32_t channel) {
|
|
|
|
|
return channel < kNumPDPChannels && channel >= 0;
|
2016-07-12 10:45:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double HAL_GetPDPTemperature(int32_t module, int32_t* status) {
|
2016-07-20 22:05:17 -07:00
|
|
|
if (!checkPDPInit(module, status)) return 0;
|
2016-07-12 10:45:14 -07:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
double temperature;
|
2015-06-29 12:40:24 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
*status = pdp[module]->GetTemperature(temperature);
|
2015-06-29 12:40:24 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
return temperature;
|
2014-05-30 14:04:05 -04:00
|
|
|
}
|
|
|
|
|
|
2016-07-12 10:45:14 -07:00
|
|
|
double HAL_GetPDPVoltage(int32_t module, int32_t* status) {
|
2016-07-20 22:05:17 -07:00
|
|
|
if (!checkPDPInit(module, status)) return 0;
|
2016-07-12 10:45:14 -07:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
double voltage;
|
2015-06-29 12:40:24 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
*status = pdp[module]->GetVoltage(voltage);
|
2015-06-29 12:40:24 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
return voltage;
|
2014-05-30 14:04:05 -04:00
|
|
|
}
|
|
|
|
|
|
2016-07-12 10:45:14 -07:00
|
|
|
double HAL_GetPDPChannelCurrent(int32_t module, int32_t channel,
|
2016-07-09 00:24:26 -07:00
|
|
|
int32_t* status) {
|
2016-07-20 22:05:17 -07:00
|
|
|
if (!checkPDPInit(module, status)) return 0;
|
2016-07-12 10:45:14 -07:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
double current;
|
2015-06-29 12:40:24 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
*status = pdp[module]->GetChannelCurrent(channel, current);
|
2015-06-29 12:40:24 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
return current;
|
2014-05-30 14:04:05 -04:00
|
|
|
}
|
|
|
|
|
|
2016-07-12 10:45:14 -07:00
|
|
|
double HAL_GetPDPTotalCurrent(int32_t module, int32_t* status) {
|
2016-07-20 22:05:17 -07:00
|
|
|
if (!checkPDPInit(module, status)) return 0;
|
2016-07-12 10:45:14 -07:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
double current;
|
2015-06-29 12:40:24 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
*status = pdp[module]->GetTotalCurrent(current);
|
2015-06-29 12:40:24 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
return current;
|
2014-11-25 00:52:41 -05:00
|
|
|
}
|
|
|
|
|
|
2016-07-12 10:45:14 -07:00
|
|
|
double HAL_GetPDPTotalPower(int32_t module, int32_t* status) {
|
2016-07-20 22:05:17 -07:00
|
|
|
if (!checkPDPInit(module, status)) return 0;
|
2016-07-12 10:45:14 -07:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
double power;
|
2015-06-29 12:40:24 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
*status = pdp[module]->GetTotalPower(power);
|
2015-06-29 12:40:24 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
return power;
|
2014-11-25 00:52:41 -05:00
|
|
|
}
|
|
|
|
|
|
2016-07-12 10:45:14 -07:00
|
|
|
double HAL_GetPDPTotalEnergy(int32_t module, int32_t* status) {
|
2016-07-20 22:05:17 -07:00
|
|
|
if (!checkPDPInit(module, status)) return 0;
|
2016-07-12 10:45:14 -07:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
double energy;
|
2015-06-29 12:40:24 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
*status = pdp[module]->GetTotalEnergy(energy);
|
2015-06-29 12:40:24 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
return energy;
|
2014-11-25 00:52:41 -05:00
|
|
|
}
|
|
|
|
|
|
2016-07-12 10:45:14 -07:00
|
|
|
void HAL_ResetPDPTotalEnergy(int32_t module, int32_t* status) {
|
2016-07-20 22:05:17 -07:00
|
|
|
if (!checkPDPInit(module, status)) return;
|
2016-07-12 10:45:14 -07:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
*status = pdp[module]->ResetEnergy();
|
2014-11-25 00:52:41 -05:00
|
|
|
}
|
|
|
|
|
|
2016-07-12 10:45:14 -07:00
|
|
|
void HAL_ClearPDPStickyFaults(int32_t module, int32_t* status) {
|
2016-07-20 22:05:17 -07:00
|
|
|
if (!checkPDPInit(module, status)) return;
|
2016-07-12 10:45:14 -07:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
*status = pdp[module]->ClearStickyFaults();
|
2014-11-25 00:52:41 -05:00
|
|
|
}
|
|
|
|
|
|
2015-11-26 00:08:32 -08:00
|
|
|
} // extern "C"
|