mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
New 2018 and later build setup (#1001)
This commit is contained in:
committed by
Peter Johnson
parent
cb2c9eb6d5
commit
7f88cf768d
@@ -41,7 +41,6 @@ using namespace hal;
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeHAL() {
|
||||
InitializeHandlesInternal();
|
||||
InitializeAccelerometer();
|
||||
InitializeAnalogAccumulator();
|
||||
InitializeAnalogGyro();
|
||||
|
||||
@@ -40,6 +40,5 @@ extern void InitializeSerialPort();
|
||||
extern void InitializeSolenoid();
|
||||
extern void InitializeSPI();
|
||||
extern void InitializeThreads();
|
||||
extern void InitializeHandlesInternal();
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
@@ -1,157 +1,157 @@
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
|
||||
#include "CtreCanNode.h"
|
||||
#include "FRC_NetworkCommunication/CANSessionMux.h"
|
||||
#include <string.h> // memset
|
||||
|
||||
static const UINT32 kFullMessageIDMask = 0x1fffffff;
|
||||
|
||||
CtreCanNode::CtreCanNode(UINT8 deviceNumber)
|
||||
{
|
||||
_deviceNumber = deviceNumber;
|
||||
}
|
||||
CtreCanNode::~CtreCanNode()
|
||||
{
|
||||
}
|
||||
void CtreCanNode::RegisterRx(uint32_t arbId)
|
||||
{
|
||||
/* no need to do anything, we just use new API to poll last received message */
|
||||
}
|
||||
/**
|
||||
* Schedule a CAN Frame for periodic transmit.
|
||||
* @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids.
|
||||
* @param periodMs Period to transmit CAN frame. Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit.
|
||||
* @param dlc Number of bytes to transmit (0 to 8).
|
||||
* @param initialFrame Ptr to the frame data to schedule for transmitting. Passing null will result
|
||||
* in defaulting to zero data value.
|
||||
*/
|
||||
void CtreCanNode::RegisterTx(uint32_t arbId, uint32_t periodMs, uint32_t dlc, const uint8_t * initialFrame)
|
||||
{
|
||||
int32_t status = 0;
|
||||
if(dlc > 8)
|
||||
dlc = 8;
|
||||
txJob_t job = {0};
|
||||
job.arbId = arbId;
|
||||
job.periodMs = periodMs;
|
||||
job.dlc = dlc;
|
||||
if(initialFrame){
|
||||
/* caller wants to specify original data */
|
||||
memcpy(job.toSend, initialFrame, dlc);
|
||||
}
|
||||
_txJobs[arbId] = job;
|
||||
FRC_NetworkCommunication_CANSessionMux_sendMessage( job.arbId,
|
||||
job.toSend,
|
||||
job.dlc,
|
||||
job.periodMs,
|
||||
&status);
|
||||
}
|
||||
/**
|
||||
* Schedule a CAN Frame for periodic transmit. Assume eight byte DLC and zero value for initial transmission.
|
||||
* @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids.
|
||||
* @param periodMs Period to transmit CAN frame. Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit.
|
||||
*/
|
||||
void CtreCanNode::RegisterTx(uint32_t arbId, uint32_t periodMs)
|
||||
{
|
||||
RegisterTx(arbId,periodMs, 8, 0);
|
||||
}
|
||||
/**
|
||||
* Remove a CAN frame Arbid to stop transmission.
|
||||
* @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids.
|
||||
*/
|
||||
void CtreCanNode::UnregisterTx(uint32_t arbId)
|
||||
{
|
||||
/* set period to zero */
|
||||
ChangeTxPeriod(arbId, 0);
|
||||
/* look and remove */
|
||||
txJobs_t::iterator iter = _txJobs.find(arbId);
|
||||
if(iter != _txJobs.end()) {
|
||||
_txJobs.erase(iter);
|
||||
}
|
||||
}
|
||||
static int64_t GetTimeMs() {
|
||||
std::chrono::time_point < std::chrono::system_clock > now;
|
||||
now = std::chrono::system_clock::now();
|
||||
auto duration = now.time_since_epoch();
|
||||
auto millis = std::chrono::duration_cast < std::chrono::milliseconds
|
||||
> (duration).count();
|
||||
return (int64_t) millis;
|
||||
}
|
||||
CTR_Code CtreCanNode::GetRx(uint32_t arbId,uint8_t * dataBytes, uint32_t timeoutMs)
|
||||
{
|
||||
CTR_Code retval = CTR_OKAY;
|
||||
int32_t status = 0;
|
||||
uint8_t len = 0;
|
||||
uint32_t timeStamp;
|
||||
/* cap timeout at 999ms */
|
||||
if(timeoutMs > 999)
|
||||
timeoutMs = 999;
|
||||
FRC_NetworkCommunication_CANSessionMux_receiveMessage(&arbId,kFullMessageIDMask,dataBytes,&len,&timeStamp,&status);
|
||||
std::lock_guard<wpi::mutex> lock(_lck);
|
||||
if(status == 0){
|
||||
/* fresh update */
|
||||
rxEvent_t & r = _rxRxEvents[arbId]; /* lookup entry or make a default new one with all zeroes */
|
||||
r.time = GetTimeMs();
|
||||
memcpy(r.bytes, dataBytes, 8); /* fill in databytes */
|
||||
}else{
|
||||
/* did not get the message */
|
||||
rxRxEvents_t::iterator i = _rxRxEvents.find(arbId);
|
||||
if(i == _rxRxEvents.end()){
|
||||
/* we've never gotten this mesage */
|
||||
retval = CTR_RxTimeout;
|
||||
/* fill caller's buffer with zeros */
|
||||
memset(dataBytes,0,8);
|
||||
}else{
|
||||
/* we've gotten this message before but not recently */
|
||||
memcpy(dataBytes,i->second.bytes,8);
|
||||
/* get the time now */
|
||||
int64_t now = GetTimeMs(); /* get now */
|
||||
/* how long has it been? */
|
||||
int64_t temp = now - i->second.time; /* temp = now - last */
|
||||
if (temp > ((int64_t) timeoutMs)) {
|
||||
retval = CTR_RxTimeout;
|
||||
} else {
|
||||
/* our last update was recent enough */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
void CtreCanNode::FlushTx(uint32_t arbId)
|
||||
{
|
||||
int32_t status = 0;
|
||||
txJobs_t::iterator iter = _txJobs.find(arbId);
|
||||
if(iter != _txJobs.end())
|
||||
FRC_NetworkCommunication_CANSessionMux_sendMessage( iter->second.arbId,
|
||||
iter->second.toSend,
|
||||
iter->second.dlc,
|
||||
iter->second.periodMs,
|
||||
&status);
|
||||
}
|
||||
/**
|
||||
* Change the transmit period of an already scheduled CAN frame.
|
||||
* This keeps the frame payload contents the same without caller having to perform
|
||||
* a read-modify-write.
|
||||
* @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids.
|
||||
* @param periodMs Period to transmit CAN frame. Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit.
|
||||
* @return true if scheduled job was found and updated, false if there was no preceding job for the specified arbID.
|
||||
*/
|
||||
bool CtreCanNode::ChangeTxPeriod(uint32_t arbId, uint32_t periodMs)
|
||||
{
|
||||
int32_t status = 0;
|
||||
/* lookup the data bytes and period for this message */
|
||||
txJobs_t::iterator iter = _txJobs.find(arbId);
|
||||
if(iter != _txJobs.end()) {
|
||||
/* modify th periodMs */
|
||||
iter->second.periodMs = periodMs;
|
||||
/* reinsert into scheduler with the same data bytes, only the period changed. */
|
||||
FRC_NetworkCommunication_CANSessionMux_sendMessage( iter->second.arbId,
|
||||
iter->second.toSend,
|
||||
iter->second.dlc,
|
||||
iter->second.periodMs,
|
||||
&status);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
|
||||
|
||||
#include "CtreCanNode.h"
|
||||
#include "FRC_NetworkCommunication/CANSessionMux.h"
|
||||
#include <string.h> // memset
|
||||
|
||||
static const UINT32 kFullMessageIDMask = 0x1fffffff;
|
||||
|
||||
CtreCanNode::CtreCanNode(UINT8 deviceNumber)
|
||||
{
|
||||
_deviceNumber = deviceNumber;
|
||||
}
|
||||
CtreCanNode::~CtreCanNode()
|
||||
{
|
||||
}
|
||||
void CtreCanNode::RegisterRx(uint32_t arbId)
|
||||
{
|
||||
/* no need to do anything, we just use new API to poll last received message */
|
||||
}
|
||||
/**
|
||||
* Schedule a CAN Frame for periodic transmit.
|
||||
* @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids.
|
||||
* @param periodMs Period to transmit CAN frame. Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit.
|
||||
* @param dlc Number of bytes to transmit (0 to 8).
|
||||
* @param initialFrame Ptr to the frame data to schedule for transmitting. Passing null will result
|
||||
* in defaulting to zero data value.
|
||||
*/
|
||||
void CtreCanNode::RegisterTx(uint32_t arbId, uint32_t periodMs, uint32_t dlc, const uint8_t * initialFrame)
|
||||
{
|
||||
int32_t status = 0;
|
||||
if(dlc > 8)
|
||||
dlc = 8;
|
||||
txJob_t job = {0};
|
||||
job.arbId = arbId;
|
||||
job.periodMs = periodMs;
|
||||
job.dlc = dlc;
|
||||
if(initialFrame){
|
||||
/* caller wants to specify original data */
|
||||
memcpy(job.toSend, initialFrame, dlc);
|
||||
}
|
||||
_txJobs[arbId] = job;
|
||||
FRC_NetworkCommunication_CANSessionMux_sendMessage( job.arbId,
|
||||
job.toSend,
|
||||
job.dlc,
|
||||
job.periodMs,
|
||||
&status);
|
||||
}
|
||||
/**
|
||||
* Schedule a CAN Frame for periodic transmit. Assume eight byte DLC and zero value for initial transmission.
|
||||
* @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids.
|
||||
* @param periodMs Period to transmit CAN frame. Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit.
|
||||
*/
|
||||
void CtreCanNode::RegisterTx(uint32_t arbId, uint32_t periodMs)
|
||||
{
|
||||
RegisterTx(arbId,periodMs, 8, 0);
|
||||
}
|
||||
/**
|
||||
* Remove a CAN frame Arbid to stop transmission.
|
||||
* @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids.
|
||||
*/
|
||||
void CtreCanNode::UnregisterTx(uint32_t arbId)
|
||||
{
|
||||
/* set period to zero */
|
||||
ChangeTxPeriod(arbId, 0);
|
||||
/* look and remove */
|
||||
txJobs_t::iterator iter = _txJobs.find(arbId);
|
||||
if(iter != _txJobs.end()) {
|
||||
_txJobs.erase(iter);
|
||||
}
|
||||
}
|
||||
static int64_t GetTimeMs() {
|
||||
std::chrono::time_point < std::chrono::system_clock > now;
|
||||
now = std::chrono::system_clock::now();
|
||||
auto duration = now.time_since_epoch();
|
||||
auto millis = std::chrono::duration_cast < std::chrono::milliseconds
|
||||
> (duration).count();
|
||||
return (int64_t) millis;
|
||||
}
|
||||
CTR_Code CtreCanNode::GetRx(uint32_t arbId,uint8_t * dataBytes, uint32_t timeoutMs)
|
||||
{
|
||||
CTR_Code retval = CTR_OKAY;
|
||||
int32_t status = 0;
|
||||
uint8_t len = 0;
|
||||
uint32_t timeStamp;
|
||||
/* cap timeout at 999ms */
|
||||
if(timeoutMs > 999)
|
||||
timeoutMs = 999;
|
||||
FRC_NetworkCommunication_CANSessionMux_receiveMessage(&arbId,kFullMessageIDMask,dataBytes,&len,&timeStamp,&status);
|
||||
std::lock_guard<wpi::mutex> lock(_lck);
|
||||
if(status == 0){
|
||||
/* fresh update */
|
||||
rxEvent_t & r = _rxRxEvents[arbId]; /* lookup entry or make a default new one with all zeroes */
|
||||
r.time = GetTimeMs();
|
||||
memcpy(r.bytes, dataBytes, 8); /* fill in databytes */
|
||||
}else{
|
||||
/* did not get the message */
|
||||
rxRxEvents_t::iterator i = _rxRxEvents.find(arbId);
|
||||
if(i == _rxRxEvents.end()){
|
||||
/* we've never gotten this mesage */
|
||||
retval = CTR_RxTimeout;
|
||||
/* fill caller's buffer with zeros */
|
||||
memset(dataBytes,0,8);
|
||||
}else{
|
||||
/* we've gotten this message before but not recently */
|
||||
memcpy(dataBytes,i->second.bytes,8);
|
||||
/* get the time now */
|
||||
int64_t now = GetTimeMs(); /* get now */
|
||||
/* how long has it been? */
|
||||
int64_t temp = now - i->second.time; /* temp = now - last */
|
||||
if (temp > ((int64_t) timeoutMs)) {
|
||||
retval = CTR_RxTimeout;
|
||||
} else {
|
||||
/* our last update was recent enough */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
void CtreCanNode::FlushTx(uint32_t arbId)
|
||||
{
|
||||
int32_t status = 0;
|
||||
txJobs_t::iterator iter = _txJobs.find(arbId);
|
||||
if(iter != _txJobs.end())
|
||||
FRC_NetworkCommunication_CANSessionMux_sendMessage( iter->second.arbId,
|
||||
iter->second.toSend,
|
||||
iter->second.dlc,
|
||||
iter->second.periodMs,
|
||||
&status);
|
||||
}
|
||||
/**
|
||||
* Change the transmit period of an already scheduled CAN frame.
|
||||
* This keeps the frame payload contents the same without caller having to perform
|
||||
* a read-modify-write.
|
||||
* @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids.
|
||||
* @param periodMs Period to transmit CAN frame. Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit.
|
||||
* @return true if scheduled job was found and updated, false if there was no preceding job for the specified arbID.
|
||||
*/
|
||||
bool CtreCanNode::ChangeTxPeriod(uint32_t arbId, uint32_t periodMs)
|
||||
{
|
||||
int32_t status = 0;
|
||||
/* lookup the data bytes and period for this message */
|
||||
txJobs_t::iterator iter = _txJobs.find(arbId);
|
||||
if(iter != _txJobs.end()) {
|
||||
/* modify th periodMs */
|
||||
iter->second.periodMs = periodMs;
|
||||
/* reinsert into scheduler with the same data bytes, only the period changed. */
|
||||
FRC_NetworkCommunication_CANSessionMux_sendMessage( iter->second.arbId,
|
||||
iter->second.toSend,
|
||||
iter->second.dlc,
|
||||
iter->second.periodMs,
|
||||
&status);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,134 +1,134 @@
|
||||
#ifndef CtreCanNode_H_
|
||||
#define CtreCanNode_H_
|
||||
#include "ctre.h" //BIT Defines + Typedefs
|
||||
#include <map>
|
||||
#include <string.h> // memcpy
|
||||
#include <sys/time.h>
|
||||
#include <support/mutex.h>
|
||||
class CtreCanNode
|
||||
{
|
||||
public:
|
||||
CtreCanNode(UINT8 deviceNumber);
|
||||
~CtreCanNode();
|
||||
|
||||
UINT8 GetDeviceNumber()
|
||||
{
|
||||
return _deviceNumber;
|
||||
}
|
||||
protected:
|
||||
|
||||
|
||||
template <typename T> class txTask{
|
||||
public:
|
||||
uint32_t arbId;
|
||||
T * toSend;
|
||||
T * operator -> ()
|
||||
{
|
||||
return toSend;
|
||||
}
|
||||
T & operator*()
|
||||
{
|
||||
return *toSend;
|
||||
}
|
||||
bool IsEmpty()
|
||||
{
|
||||
if(toSend == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
template <typename T> class recMsg{
|
||||
public:
|
||||
uint32_t arbId;
|
||||
uint8_t bytes[8];
|
||||
CTR_Code err;
|
||||
T * operator -> ()
|
||||
{
|
||||
return (T *)bytes;
|
||||
}
|
||||
T & operator*()
|
||||
{
|
||||
return *(T *)bytes;
|
||||
}
|
||||
};
|
||||
UINT8 _deviceNumber;
|
||||
void RegisterRx(uint32_t arbId);
|
||||
/**
|
||||
* Schedule a CAN Frame for periodic transmit. Assume eight byte DLC and zero value for initial transmission.
|
||||
* @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids.
|
||||
* @param periodMs Period to transmit CAN frame. Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit.
|
||||
*/
|
||||
void RegisterTx(uint32_t arbId, uint32_t periodMs);
|
||||
/**
|
||||
* Schedule a CAN Frame for periodic transmit.
|
||||
* @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids.
|
||||
* @param periodMs Period to transmit CAN frame. Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit.
|
||||
* @param dlc Number of bytes to transmit (0 to 8).
|
||||
* @param initialFrame Ptr to the frame data to schedule for transmitting. Passing null will result
|
||||
* in defaulting to zero data value.
|
||||
*/
|
||||
void RegisterTx(uint32_t arbId, uint32_t periodMs, uint32_t dlc, const uint8_t * initialFrame);
|
||||
void UnregisterTx(uint32_t arbId);
|
||||
|
||||
CTR_Code GetRx(uint32_t arbId,uint8_t * dataBytes,uint32_t timeoutMs);
|
||||
void FlushTx(uint32_t arbId);
|
||||
bool ChangeTxPeriod(uint32_t arbId, uint32_t periodMs);
|
||||
|
||||
template<typename T> txTask<T> GetTx(uint32_t arbId)
|
||||
{
|
||||
txTask<T> retval = {0, nullptr};
|
||||
txJobs_t::iterator i = _txJobs.find(arbId);
|
||||
if(i != _txJobs.end()){
|
||||
retval.arbId = i->second.arbId;
|
||||
retval.toSend = (T*)i->second.toSend;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
template<class T> void FlushTx(T & par)
|
||||
{
|
||||
FlushTx(par.arbId);
|
||||
}
|
||||
|
||||
template<class T> recMsg<T> GetRx(uint32_t arbId, uint32_t timeoutMs)
|
||||
{
|
||||
recMsg<T> retval;
|
||||
retval.err = GetRx(arbId,retval.bytes, timeoutMs);
|
||||
return retval;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
class txJob_t {
|
||||
public:
|
||||
uint32_t arbId;
|
||||
uint8_t toSend[8];
|
||||
uint32_t periodMs;
|
||||
uint8_t dlc;
|
||||
};
|
||||
|
||||
class rxEvent_t{
|
||||
public:
|
||||
uint8_t bytes[8];
|
||||
int64_t time;
|
||||
rxEvent_t()
|
||||
{
|
||||
bytes[0] = 0;
|
||||
bytes[1] = 0;
|
||||
bytes[2] = 0;
|
||||
bytes[3] = 0;
|
||||
bytes[4] = 0;
|
||||
bytes[5] = 0;
|
||||
bytes[6] = 0;
|
||||
bytes[7] = 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<uint32_t,txJob_t> txJobs_t;
|
||||
txJobs_t _txJobs;
|
||||
|
||||
typedef std::map<uint32_t,rxEvent_t> rxRxEvents_t;
|
||||
rxRxEvents_t _rxRxEvents;
|
||||
|
||||
wpi::mutex _lck;
|
||||
};
|
||||
#endif
|
||||
#ifndef CtreCanNode_H_
|
||||
#define CtreCanNode_H_
|
||||
#include "ctre.h" //BIT Defines + Typedefs
|
||||
#include <map>
|
||||
#include <string.h> // memcpy
|
||||
#include <sys/time.h>
|
||||
#include <support/mutex.h>
|
||||
class CtreCanNode
|
||||
{
|
||||
public:
|
||||
CtreCanNode(UINT8 deviceNumber);
|
||||
~CtreCanNode();
|
||||
|
||||
UINT8 GetDeviceNumber()
|
||||
{
|
||||
return _deviceNumber;
|
||||
}
|
||||
protected:
|
||||
|
||||
|
||||
template <typename T> class txTask{
|
||||
public:
|
||||
uint32_t arbId;
|
||||
T * toSend;
|
||||
T * operator -> ()
|
||||
{
|
||||
return toSend;
|
||||
}
|
||||
T & operator*()
|
||||
{
|
||||
return *toSend;
|
||||
}
|
||||
bool IsEmpty()
|
||||
{
|
||||
if(toSend == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
template <typename T> class recMsg{
|
||||
public:
|
||||
uint32_t arbId;
|
||||
uint8_t bytes[8];
|
||||
CTR_Code err;
|
||||
T * operator -> ()
|
||||
{
|
||||
return (T *)bytes;
|
||||
}
|
||||
T & operator*()
|
||||
{
|
||||
return *(T *)bytes;
|
||||
}
|
||||
};
|
||||
UINT8 _deviceNumber;
|
||||
void RegisterRx(uint32_t arbId);
|
||||
/**
|
||||
* Schedule a CAN Frame for periodic transmit. Assume eight byte DLC and zero value for initial transmission.
|
||||
* @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids.
|
||||
* @param periodMs Period to transmit CAN frame. Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit.
|
||||
*/
|
||||
void RegisterTx(uint32_t arbId, uint32_t periodMs);
|
||||
/**
|
||||
* Schedule a CAN Frame for periodic transmit.
|
||||
* @param arbId CAN Frame Arbitration ID. Set BIT31 for 11bit ids, otherwise we use 29bit ids.
|
||||
* @param periodMs Period to transmit CAN frame. Pass 0 for one-shot, which also disables that ArbID's preceding periodic transmit.
|
||||
* @param dlc Number of bytes to transmit (0 to 8).
|
||||
* @param initialFrame Ptr to the frame data to schedule for transmitting. Passing null will result
|
||||
* in defaulting to zero data value.
|
||||
*/
|
||||
void RegisterTx(uint32_t arbId, uint32_t periodMs, uint32_t dlc, const uint8_t * initialFrame);
|
||||
void UnregisterTx(uint32_t arbId);
|
||||
|
||||
CTR_Code GetRx(uint32_t arbId,uint8_t * dataBytes,uint32_t timeoutMs);
|
||||
void FlushTx(uint32_t arbId);
|
||||
bool ChangeTxPeriod(uint32_t arbId, uint32_t periodMs);
|
||||
|
||||
template<typename T> txTask<T> GetTx(uint32_t arbId)
|
||||
{
|
||||
txTask<T> retval = {0, nullptr};
|
||||
txJobs_t::iterator i = _txJobs.find(arbId);
|
||||
if(i != _txJobs.end()){
|
||||
retval.arbId = i->second.arbId;
|
||||
retval.toSend = (T*)i->second.toSend;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
template<class T> void FlushTx(T & par)
|
||||
{
|
||||
FlushTx(par.arbId);
|
||||
}
|
||||
|
||||
template<class T> recMsg<T> GetRx(uint32_t arbId, uint32_t timeoutMs)
|
||||
{
|
||||
recMsg<T> retval;
|
||||
retval.err = GetRx(arbId,retval.bytes, timeoutMs);
|
||||
return retval;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
class txJob_t {
|
||||
public:
|
||||
uint32_t arbId;
|
||||
uint8_t toSend[8];
|
||||
uint32_t periodMs;
|
||||
uint8_t dlc;
|
||||
};
|
||||
|
||||
class rxEvent_t{
|
||||
public:
|
||||
uint8_t bytes[8];
|
||||
int64_t time;
|
||||
rxEvent_t()
|
||||
{
|
||||
bytes[0] = 0;
|
||||
bytes[1] = 0;
|
||||
bytes[2] = 0;
|
||||
bytes[3] = 0;
|
||||
bytes[4] = 0;
|
||||
bytes[5] = 0;
|
||||
bytes[6] = 0;
|
||||
bytes[7] = 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef std::map<uint32_t,txJob_t> txJobs_t;
|
||||
txJobs_t _txJobs;
|
||||
|
||||
typedef std::map<uint32_t,rxEvent_t> rxRxEvents_t;
|
||||
rxRxEvents_t _rxRxEvents;
|
||||
|
||||
wpi::mutex _lck;
|
||||
};
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,226 +1,226 @@
|
||||
#ifndef PCM_H_
|
||||
#define PCM_H_
|
||||
#include "ctre.h" //BIT Defines + Typedefs
|
||||
#include "CtreCanNode.h"
|
||||
class PCM : public CtreCanNode
|
||||
{
|
||||
public:
|
||||
PCM(UINT8 deviceNumber=0);
|
||||
~PCM();
|
||||
|
||||
/* Set PCM solenoid state
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any) for setting solenoid
|
||||
* @Param - idx - ID of solenoid (0-7)
|
||||
* @Param - en - Enable / Disable identified solenoid
|
||||
*/
|
||||
CTR_Code SetSolenoid(unsigned char idx, bool en);
|
||||
|
||||
/* Set all PCM solenoid states
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any) for setting solenoids
|
||||
* @Param - state Bitfield to set all solenoids to
|
||||
*/
|
||||
CTR_Code SetAllSolenoids(UINT8 state);
|
||||
|
||||
/* Enables PCM Closed Loop Control of Compressor via pressure switch
|
||||
* @Return - CTR_Code - Error code (if any) for setting solenoid
|
||||
* @Param - en - Enable / Disable Closed Loop Control
|
||||
*/
|
||||
CTR_Code SetClosedLoopControl(bool en);
|
||||
|
||||
/* Clears PCM sticky faults (indicators of past faults
|
||||
* @Return - CTR_Code - Error code (if any) for setting solenoid
|
||||
*/
|
||||
CTR_Code ClearStickyFaults();
|
||||
|
||||
/* Get solenoid state
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - idx - ID of solenoid (0-7) to return if solenoid is on.
|
||||
* @Param - status - true if solenoid enabled, false otherwise
|
||||
*/
|
||||
CTR_Code GetSolenoid(UINT8 idx, bool &status);
|
||||
|
||||
/* Get state of all solenoids
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - bitfield of solenoid states
|
||||
*/
|
||||
CTR_Code GetAllSolenoids(UINT8 &status);
|
||||
|
||||
/* Get pressure switch state
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if pressure adequate, false if low
|
||||
*/
|
||||
CTR_Code GetPressure(bool &status);
|
||||
|
||||
/* Get compressor state
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if compress ouput is on, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressor(bool &status);
|
||||
|
||||
/* Get closed loop control state
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if closed loop enabled, false if otherwise
|
||||
*/
|
||||
CTR_Code GetClosedLoopControl(bool &status);
|
||||
|
||||
/* Get compressor current draw
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - Compressor current returned in Amperes (A)
|
||||
*/
|
||||
CTR_Code GetCompressorCurrent(float &status);
|
||||
|
||||
/* Get voltage across solenoid rail
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - Voltage across solenoid rail in Volts (V)
|
||||
*/
|
||||
CTR_Code GetSolenoidVoltage(float &status);
|
||||
|
||||
/* Get hardware fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if hardware failure detected, false if otherwise
|
||||
*/
|
||||
CTR_Code GetHardwareFault(bool &status);
|
||||
|
||||
/* Get compressor fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if abnormally high compressor current detected, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorCurrentTooHighFault(bool &status);
|
||||
|
||||
/* Get solenoid fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if shorted solenoid detected, false if otherwise
|
||||
*/
|
||||
CTR_Code GetSolenoidFault(bool &status);
|
||||
|
||||
/* Get compressor sticky fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if solenoid had previously been shorted
|
||||
* (and sticky fault was not cleared), false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorCurrentTooHighStickyFault(bool &status);
|
||||
/* Get compressor shorted sticky fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if compressor output is shorted, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorShortedStickyFault(bool &status);
|
||||
/* Get compressor shorted fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if compressor output is shorted, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorShortedFault(bool &status);
|
||||
/* Get compressor is not connected sticky fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if compressor current is too low,
|
||||
* indicating compressor is not connected, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorNotConnectedStickyFault(bool &status);
|
||||
/* Get compressor is not connected fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if compressor current is too low,
|
||||
* indicating compressor is not connected, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorNotConnectedFault(bool &status);
|
||||
|
||||
/* Get solenoid sticky fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if compressor had previously been shorted
|
||||
* (and sticky fault was not cleared), false if otherwise
|
||||
*/
|
||||
CTR_Code GetSolenoidStickyFault(bool &status);
|
||||
|
||||
/* Get battery voltage
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - Voltage across PCM power ports in Volts (V)
|
||||
*/
|
||||
CTR_Code GetBatteryVoltage(float &status);
|
||||
|
||||
/* Set PCM Device Number and according CAN frame IDs
|
||||
* @Return - void
|
||||
* @Param - deviceNumber - Device number of PCM to control
|
||||
*/
|
||||
void SetDeviceNumber(UINT8 deviceNumber);
|
||||
/* Get number of total failed PCM Control Frame
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - Number of failed control frames (tokenization fails)
|
||||
* @WARNING - Return only valid if [SeekDebugFrames] is enabled
|
||||
* See function SeekDebugFrames
|
||||
* See function EnableSeekDebugFrames
|
||||
*/
|
||||
CTR_Code GetNumberOfFailedControlFrames(UINT16 &status);
|
||||
|
||||
/* Get raw Solenoid Blacklist
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - Raw binary breakdown of Solenoid Blacklist
|
||||
* BIT7 = Solenoid 1, BIT6 = Solenoid 2, etc.
|
||||
* @WARNING - Return only valid if [SeekStatusFaultFrames] is enabled
|
||||
* See function SeekStatusFaultFrames
|
||||
* See function EnableSeekStatusFaultFrames
|
||||
*/
|
||||
CTR_Code GetSolenoidBlackList(UINT8 &status);
|
||||
|
||||
/* Get solenoid Blacklist status
|
||||
* - Blacklisted solenoids cannot be enabled until PCM is power cycled
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - idx - ID of solenoid [0,7]
|
||||
* @Param - status - True if Solenoid is blacklisted, false if otherwise
|
||||
* @WARNING - Return only valid if [SeekStatusFaultFrames] is enabled
|
||||
* See function SeekStatusFaultFrames
|
||||
* See function EnableSeekStatusFaultFrames
|
||||
*/
|
||||
CTR_Code IsSolenoidBlacklisted(UINT8 idx, bool &status);
|
||||
|
||||
/* Return status of module enable/disable
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - Returns TRUE if PCM is enabled, FALSE if disabled
|
||||
*/
|
||||
CTR_Code isModuleEnabled(bool &status);
|
||||
|
||||
/* Get solenoid Blacklist status
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - idx - ID of solenoid [0,7] to fire one shot pulse.
|
||||
*/
|
||||
CTR_Code FireOneShotSolenoid(UINT8 idx);
|
||||
|
||||
/* Configure the pulse width of a solenoid channel for one-shot pulse.
|
||||
* Preprogrammed pulsewidth is 10ms resolute and can be between 20ms and 5.1s.
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - idx - ID of solenoid [0,7] to configure.
|
||||
* @Param - durMs - pulse width in ms.
|
||||
*/
|
||||
CTR_Code SetOneShotDurationMs(UINT8 idx,uint32_t durMs);
|
||||
|
||||
};
|
||||
//------------------ C interface --------------------------------------------//
|
||||
extern "C" {
|
||||
void * c_PCM_Init(void);
|
||||
CTR_Code c_SetSolenoid(void * handle,unsigned char idx,INT8 param);
|
||||
CTR_Code c_SetAllSolenoids(void * handle,UINT8 state);
|
||||
CTR_Code c_SetClosedLoopControl(void * handle,INT8 param);
|
||||
CTR_Code c_ClearStickyFaults(void * handle,INT8 param);
|
||||
CTR_Code c_GetSolenoid(void * handle,UINT8 idx,INT8 * status);
|
||||
CTR_Code c_GetAllSolenoids(void * handle,UINT8 * status);
|
||||
CTR_Code c_GetPressure(void * handle,INT8 * status);
|
||||
CTR_Code c_GetCompressor(void * handle,INT8 * status);
|
||||
CTR_Code c_GetClosedLoopControl(void * handle,INT8 * status);
|
||||
CTR_Code c_GetCompressorCurrent(void * handle,float * status);
|
||||
CTR_Code c_GetSolenoidVoltage(void * handle,float*status);
|
||||
CTR_Code c_GetHardwareFault(void * handle,INT8*status);
|
||||
CTR_Code c_GetCompressorFault(void * handle,INT8*status);
|
||||
CTR_Code c_GetSolenoidFault(void * handle,INT8*status);
|
||||
CTR_Code c_GetCompressorStickyFault(void * handle,INT8*status);
|
||||
CTR_Code c_GetSolenoidStickyFault(void * handle,INT8*status);
|
||||
CTR_Code c_GetBatteryVoltage(void * handle,float*status);
|
||||
void c_SetDeviceNumber_PCM(void * handle,UINT8 deviceNumber);
|
||||
void c_EnableSeekStatusFrames(void * handle,INT8 enable);
|
||||
void c_EnableSeekStatusFaultFrames(void * handle,INT8 enable);
|
||||
void c_EnableSeekDebugFrames(void * handle,INT8 enable);
|
||||
CTR_Code c_GetNumberOfFailedControlFrames(void * handle,UINT16*status);
|
||||
CTR_Code c_GetSolenoidBlackList(void * handle,UINT8 *status);
|
||||
CTR_Code c_IsSolenoidBlacklisted(void * handle,UINT8 idx,INT8*status);
|
||||
}
|
||||
#endif
|
||||
#ifndef PCM_H_
|
||||
#define PCM_H_
|
||||
#include "ctre.h" //BIT Defines + Typedefs
|
||||
#include "CtreCanNode.h"
|
||||
class PCM : public CtreCanNode
|
||||
{
|
||||
public:
|
||||
PCM(UINT8 deviceNumber=0);
|
||||
~PCM();
|
||||
|
||||
/* Set PCM solenoid state
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any) for setting solenoid
|
||||
* @Param - idx - ID of solenoid (0-7)
|
||||
* @Param - en - Enable / Disable identified solenoid
|
||||
*/
|
||||
CTR_Code SetSolenoid(unsigned char idx, bool en);
|
||||
|
||||
/* Set all PCM solenoid states
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any) for setting solenoids
|
||||
* @Param - state Bitfield to set all solenoids to
|
||||
*/
|
||||
CTR_Code SetAllSolenoids(UINT8 state);
|
||||
|
||||
/* Enables PCM Closed Loop Control of Compressor via pressure switch
|
||||
* @Return - CTR_Code - Error code (if any) for setting solenoid
|
||||
* @Param - en - Enable / Disable Closed Loop Control
|
||||
*/
|
||||
CTR_Code SetClosedLoopControl(bool en);
|
||||
|
||||
/* Clears PCM sticky faults (indicators of past faults
|
||||
* @Return - CTR_Code - Error code (if any) for setting solenoid
|
||||
*/
|
||||
CTR_Code ClearStickyFaults();
|
||||
|
||||
/* Get solenoid state
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - idx - ID of solenoid (0-7) to return if solenoid is on.
|
||||
* @Param - status - true if solenoid enabled, false otherwise
|
||||
*/
|
||||
CTR_Code GetSolenoid(UINT8 idx, bool &status);
|
||||
|
||||
/* Get state of all solenoids
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - bitfield of solenoid states
|
||||
*/
|
||||
CTR_Code GetAllSolenoids(UINT8 &status);
|
||||
|
||||
/* Get pressure switch state
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if pressure adequate, false if low
|
||||
*/
|
||||
CTR_Code GetPressure(bool &status);
|
||||
|
||||
/* Get compressor state
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if compress ouput is on, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressor(bool &status);
|
||||
|
||||
/* Get closed loop control state
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if closed loop enabled, false if otherwise
|
||||
*/
|
||||
CTR_Code GetClosedLoopControl(bool &status);
|
||||
|
||||
/* Get compressor current draw
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - Compressor current returned in Amperes (A)
|
||||
*/
|
||||
CTR_Code GetCompressorCurrent(float &status);
|
||||
|
||||
/* Get voltage across solenoid rail
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - Voltage across solenoid rail in Volts (V)
|
||||
*/
|
||||
CTR_Code GetSolenoidVoltage(float &status);
|
||||
|
||||
/* Get hardware fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if hardware failure detected, false if otherwise
|
||||
*/
|
||||
CTR_Code GetHardwareFault(bool &status);
|
||||
|
||||
/* Get compressor fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if abnormally high compressor current detected, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorCurrentTooHighFault(bool &status);
|
||||
|
||||
/* Get solenoid fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if shorted solenoid detected, false if otherwise
|
||||
*/
|
||||
CTR_Code GetSolenoidFault(bool &status);
|
||||
|
||||
/* Get compressor sticky fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if solenoid had previously been shorted
|
||||
* (and sticky fault was not cleared), false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorCurrentTooHighStickyFault(bool &status);
|
||||
/* Get compressor shorted sticky fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if compressor output is shorted, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorShortedStickyFault(bool &status);
|
||||
/* Get compressor shorted fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if compressor output is shorted, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorShortedFault(bool &status);
|
||||
/* Get compressor is not connected sticky fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if compressor current is too low,
|
||||
* indicating compressor is not connected, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorNotConnectedStickyFault(bool &status);
|
||||
/* Get compressor is not connected fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if compressor current is too low,
|
||||
* indicating compressor is not connected, false if otherwise
|
||||
*/
|
||||
CTR_Code GetCompressorNotConnectedFault(bool &status);
|
||||
|
||||
/* Get solenoid sticky fault value
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - True if compressor had previously been shorted
|
||||
* (and sticky fault was not cleared), false if otherwise
|
||||
*/
|
||||
CTR_Code GetSolenoidStickyFault(bool &status);
|
||||
|
||||
/* Get battery voltage
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - Voltage across PCM power ports in Volts (V)
|
||||
*/
|
||||
CTR_Code GetBatteryVoltage(float &status);
|
||||
|
||||
/* Set PCM Device Number and according CAN frame IDs
|
||||
* @Return - void
|
||||
* @Param - deviceNumber - Device number of PCM to control
|
||||
*/
|
||||
void SetDeviceNumber(UINT8 deviceNumber);
|
||||
/* Get number of total failed PCM Control Frame
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - Number of failed control frames (tokenization fails)
|
||||
* @WARNING - Return only valid if [SeekDebugFrames] is enabled
|
||||
* See function SeekDebugFrames
|
||||
* See function EnableSeekDebugFrames
|
||||
*/
|
||||
CTR_Code GetNumberOfFailedControlFrames(UINT16 &status);
|
||||
|
||||
/* Get raw Solenoid Blacklist
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - Raw binary breakdown of Solenoid Blacklist
|
||||
* BIT7 = Solenoid 1, BIT6 = Solenoid 2, etc.
|
||||
* @WARNING - Return only valid if [SeekStatusFaultFrames] is enabled
|
||||
* See function SeekStatusFaultFrames
|
||||
* See function EnableSeekStatusFaultFrames
|
||||
*/
|
||||
CTR_Code GetSolenoidBlackList(UINT8 &status);
|
||||
|
||||
/* Get solenoid Blacklist status
|
||||
* - Blacklisted solenoids cannot be enabled until PCM is power cycled
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - idx - ID of solenoid [0,7]
|
||||
* @Param - status - True if Solenoid is blacklisted, false if otherwise
|
||||
* @WARNING - Return only valid if [SeekStatusFaultFrames] is enabled
|
||||
* See function SeekStatusFaultFrames
|
||||
* See function EnableSeekStatusFaultFrames
|
||||
*/
|
||||
CTR_Code IsSolenoidBlacklisted(UINT8 idx, bool &status);
|
||||
|
||||
/* Return status of module enable/disable
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - status - Returns TRUE if PCM is enabled, FALSE if disabled
|
||||
*/
|
||||
CTR_Code isModuleEnabled(bool &status);
|
||||
|
||||
/* Get solenoid Blacklist status
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - idx - ID of solenoid [0,7] to fire one shot pulse.
|
||||
*/
|
||||
CTR_Code FireOneShotSolenoid(UINT8 idx);
|
||||
|
||||
/* Configure the pulse width of a solenoid channel for one-shot pulse.
|
||||
* Preprogrammed pulsewidth is 10ms resolute and can be between 20ms and 5.1s.
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
* @Param - idx - ID of solenoid [0,7] to configure.
|
||||
* @Param - durMs - pulse width in ms.
|
||||
*/
|
||||
CTR_Code SetOneShotDurationMs(UINT8 idx,uint32_t durMs);
|
||||
|
||||
};
|
||||
//------------------ C interface --------------------------------------------//
|
||||
extern "C" {
|
||||
void * c_PCM_Init(void);
|
||||
CTR_Code c_SetSolenoid(void * handle,unsigned char idx,INT8 param);
|
||||
CTR_Code c_SetAllSolenoids(void * handle,UINT8 state);
|
||||
CTR_Code c_SetClosedLoopControl(void * handle,INT8 param);
|
||||
CTR_Code c_ClearStickyFaults(void * handle,INT8 param);
|
||||
CTR_Code c_GetSolenoid(void * handle,UINT8 idx,INT8 * status);
|
||||
CTR_Code c_GetAllSolenoids(void * handle,UINT8 * status);
|
||||
CTR_Code c_GetPressure(void * handle,INT8 * status);
|
||||
CTR_Code c_GetCompressor(void * handle,INT8 * status);
|
||||
CTR_Code c_GetClosedLoopControl(void * handle,INT8 * status);
|
||||
CTR_Code c_GetCompressorCurrent(void * handle,float * status);
|
||||
CTR_Code c_GetSolenoidVoltage(void * handle,float*status);
|
||||
CTR_Code c_GetHardwareFault(void * handle,INT8*status);
|
||||
CTR_Code c_GetCompressorFault(void * handle,INT8*status);
|
||||
CTR_Code c_GetSolenoidFault(void * handle,INT8*status);
|
||||
CTR_Code c_GetCompressorStickyFault(void * handle,INT8*status);
|
||||
CTR_Code c_GetSolenoidStickyFault(void * handle,INT8*status);
|
||||
CTR_Code c_GetBatteryVoltage(void * handle,float*status);
|
||||
void c_SetDeviceNumber_PCM(void * handle,UINT8 deviceNumber);
|
||||
void c_EnableSeekStatusFrames(void * handle,INT8 enable);
|
||||
void c_EnableSeekStatusFaultFrames(void * handle,INT8 enable);
|
||||
void c_EnableSeekDebugFrames(void * handle,INT8 enable);
|
||||
CTR_Code c_GetNumberOfFailedControlFrames(void * handle,UINT16*status);
|
||||
CTR_Code c_GetSolenoidBlackList(void * handle,UINT8 *status);
|
||||
CTR_Code c_IsSolenoidBlacklisted(void * handle,UINT8 idx,INT8*status);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,230 +1,230 @@
|
||||
#include "PDP.h"
|
||||
#include "FRC_NetworkCommunication/CANSessionMux.h" //CAN Comm
|
||||
#include <string.h> // memset
|
||||
|
||||
#define STATUS_1 0x8041400
|
||||
#define STATUS_2 0x8041440
|
||||
#define STATUS_3 0x8041480
|
||||
#define STATUS_ENERGY 0x8041740
|
||||
|
||||
#define CONTROL_1 0x08041C00 /* PDP_Control_ClearStats */
|
||||
|
||||
#define EXPECTED_RESPONSE_TIMEOUT_MS (50)
|
||||
#define GET_STATUS1() CtreCanNode::recMsg<PdpStatus1_t> rx = GetRx<PdpStatus1_t>(STATUS_1|GetDeviceNumber(),EXPECTED_RESPONSE_TIMEOUT_MS)
|
||||
#define GET_STATUS2() CtreCanNode::recMsg<PdpStatus2_t> rx = GetRx<PdpStatus2_t>(STATUS_2|GetDeviceNumber(),EXPECTED_RESPONSE_TIMEOUT_MS)
|
||||
#define GET_STATUS3() CtreCanNode::recMsg<PdpStatus3_t> rx = GetRx<PdpStatus3_t>(STATUS_3|GetDeviceNumber(),EXPECTED_RESPONSE_TIMEOUT_MS)
|
||||
#define GET_STATUS_ENERGY() CtreCanNode::recMsg<PDP_Status_Energy_t> rx = GetRx<PDP_Status_Energy_t>(STATUS_ENERGY|GetDeviceNumber(),EXPECTED_RESPONSE_TIMEOUT_MS)
|
||||
|
||||
/* encoder/decoders */
|
||||
typedef struct _PdpStatus1_t{
|
||||
unsigned chan1_h8:8;
|
||||
unsigned chan2_h6:6;
|
||||
unsigned chan1_l2:2;
|
||||
unsigned chan3_h4:4;
|
||||
unsigned chan2_l4:4;
|
||||
unsigned chan4_h2:2;
|
||||
unsigned chan3_l6:6;
|
||||
unsigned chan4_l8:8;
|
||||
unsigned chan5_h8:8;
|
||||
unsigned chan6_h6:6;
|
||||
unsigned chan5_l2:2;
|
||||
unsigned reserved4:4;
|
||||
unsigned chan6_l4:4;
|
||||
}PdpStatus1_t;
|
||||
typedef struct _PdpStatus2_t{
|
||||
unsigned chan7_h8:8;
|
||||
unsigned chan8_h6:6;
|
||||
unsigned chan7_l2:2;
|
||||
unsigned chan9_h4:4;
|
||||
unsigned chan8_l4:4;
|
||||
unsigned chan10_h2:2;
|
||||
unsigned chan9_l6:6;
|
||||
unsigned chan10_l8:8;
|
||||
unsigned chan11_h8:8;
|
||||
unsigned chan12_h6:6;
|
||||
unsigned chan11_l2:2;
|
||||
unsigned reserved4:4;
|
||||
unsigned chan12_l4:4;
|
||||
}PdpStatus2_t;
|
||||
typedef struct _PdpStatus3_t{
|
||||
unsigned chan13_h8:8;
|
||||
unsigned chan14_h6:6;
|
||||
unsigned chan13_l2:2;
|
||||
unsigned chan15_h4:4;
|
||||
unsigned chan14_l4:4;
|
||||
unsigned chan16_h2:2;
|
||||
unsigned chan15_l6:6;
|
||||
unsigned chan16_l8:8;
|
||||
unsigned internalResBattery_mOhms:8;
|
||||
unsigned busVoltage:8;
|
||||
unsigned temp:8;
|
||||
}PdpStatus3_t;
|
||||
typedef struct _PDP_Status_Energy_t {
|
||||
unsigned TmeasMs_likelywillbe20ms_:8;
|
||||
unsigned TotalCurrent_125mAperunit_h8:8;
|
||||
unsigned Power_125mWperunit_h4:4;
|
||||
unsigned TotalCurrent_125mAperunit_l4:4;
|
||||
unsigned Power_125mWperunit_m8:8;
|
||||
unsigned Energy_125mWPerUnitXTmeas_h4:4;
|
||||
unsigned Power_125mWperunit_l4:4;
|
||||
unsigned Energy_125mWPerUnitXTmeas_mh8:8;
|
||||
unsigned Energy_125mWPerUnitXTmeas_ml8:8;
|
||||
unsigned Energy_125mWPerUnitXTmeas_l8:8;
|
||||
} PDP_Status_Energy_t ;
|
||||
|
||||
PDP::PDP(UINT8 deviceNumber): CtreCanNode(deviceNumber)
|
||||
{
|
||||
RegisterRx(STATUS_1 | deviceNumber );
|
||||
RegisterRx(STATUS_2 | deviceNumber );
|
||||
RegisterRx(STATUS_3 | deviceNumber );
|
||||
}
|
||||
/* PDP D'tor
|
||||
*/
|
||||
PDP::~PDP()
|
||||
{
|
||||
}
|
||||
|
||||
CTR_Code PDP::GetChannelCurrent(UINT8 idx, double ¤t)
|
||||
{
|
||||
CTR_Code retval = CTR_InvalidParamValue;
|
||||
uint32_t raw = 0;
|
||||
|
||||
if(idx <= 5){
|
||||
GET_STATUS1();
|
||||
retval = rx.err;
|
||||
switch(idx){
|
||||
case 0: raw = ((uint32_t)rx->chan1_h8 << 2) | rx->chan1_l2; break;
|
||||
case 1: raw = ((uint32_t)rx->chan2_h6 << 4) | rx->chan2_l4; break;
|
||||
case 2: raw = ((uint32_t)rx->chan3_h4 << 6) | rx->chan3_l6; break;
|
||||
case 3: raw = ((uint32_t)rx->chan4_h2 << 8) | rx->chan4_l8; break;
|
||||
case 4: raw = ((uint32_t)rx->chan5_h8 << 2) | rx->chan5_l2; break;
|
||||
case 5: raw = ((uint32_t)rx->chan6_h6 << 4) | rx->chan6_l4; break;
|
||||
default: retval = CTR_InvalidParamValue; break;
|
||||
}
|
||||
}else if(idx <= 11){
|
||||
GET_STATUS2();
|
||||
retval = rx.err;
|
||||
switch(idx){
|
||||
case 6: raw = ((uint32_t)rx->chan7_h8 << 2) | rx->chan7_l2; break;
|
||||
case 7: raw = ((uint32_t)rx->chan8_h6 << 4) | rx->chan8_l4; break;
|
||||
case 8: raw = ((uint32_t)rx->chan9_h4 << 6) | rx->chan9_l6; break;
|
||||
case 9: raw = ((uint32_t)rx->chan10_h2 << 8) | rx->chan10_l8; break;
|
||||
case 10: raw = ((uint32_t)rx->chan11_h8 << 2) | rx->chan11_l2; break;
|
||||
case 11: raw = ((uint32_t)rx->chan12_h6 << 4) | rx->chan12_l4; break;
|
||||
default: retval = CTR_InvalidParamValue; break;
|
||||
}
|
||||
}else if(idx <= 15){
|
||||
GET_STATUS3();
|
||||
retval = rx.err;
|
||||
switch(idx){
|
||||
case 12: raw = ((uint32_t)rx->chan13_h8 << 2) | rx->chan13_l2; break;
|
||||
case 13: raw = ((uint32_t)rx->chan14_h6 << 4) | rx->chan14_l4; break;
|
||||
case 14: raw = ((uint32_t)rx->chan15_h4 << 6) | rx->chan15_l6; break;
|
||||
case 15: raw = ((uint32_t)rx->chan16_h2 << 8) | rx->chan16_l8; break;
|
||||
default: retval = CTR_InvalidParamValue; break;
|
||||
}
|
||||
}
|
||||
/* convert to amps */
|
||||
current = (double)raw * 0.125; /* 7.3 fixed pt value in Amps */
|
||||
/* signal caller with success */
|
||||
return retval;
|
||||
}
|
||||
CTR_Code PDP::GetVoltage(double &voltage)
|
||||
{
|
||||
GET_STATUS3();
|
||||
uint32_t raw = rx->busVoltage;
|
||||
voltage = (double)raw * 0.05 + 4.0; /* 50mV per unit plus 4V. */;
|
||||
return rx.err;
|
||||
}
|
||||
CTR_Code PDP::GetTemperature(double &tempC)
|
||||
{
|
||||
GET_STATUS3();
|
||||
uint32_t raw = rx->temp;
|
||||
tempC = (double)raw * 1.03250836957542 - 67.8564500484966;
|
||||
return rx.err;
|
||||
}
|
||||
CTR_Code PDP::GetTotalCurrent(double ¤tAmps)
|
||||
{
|
||||
GET_STATUS_ENERGY();
|
||||
uint32_t raw;
|
||||
raw = rx->TotalCurrent_125mAperunit_h8;
|
||||
raw <<= 4;
|
||||
raw |= rx->TotalCurrent_125mAperunit_l4;
|
||||
currentAmps = 0.125 * raw;
|
||||
return rx.err;
|
||||
}
|
||||
CTR_Code PDP::GetTotalPower(double &powerWatts)
|
||||
{
|
||||
GET_STATUS_ENERGY();
|
||||
uint32_t raw;
|
||||
raw = rx->Power_125mWperunit_h4;
|
||||
raw <<= 8;
|
||||
raw |= rx->Power_125mWperunit_m8;
|
||||
raw <<= 4;
|
||||
raw |= rx->Power_125mWperunit_l4;
|
||||
powerWatts = 0.125 * raw;
|
||||
return rx.err;
|
||||
}
|
||||
CTR_Code PDP::GetTotalEnergy(double &energyJoules)
|
||||
{
|
||||
GET_STATUS_ENERGY();
|
||||
uint32_t raw;
|
||||
raw = rx->Energy_125mWPerUnitXTmeas_h4;
|
||||
raw <<= 8;
|
||||
raw |= rx->Energy_125mWPerUnitXTmeas_mh8;
|
||||
raw <<= 8;
|
||||
raw |= rx->Energy_125mWPerUnitXTmeas_ml8;
|
||||
raw <<= 8;
|
||||
raw |= rx->Energy_125mWPerUnitXTmeas_l8;
|
||||
energyJoules = 0.125 * raw; /* mW integrated every TmeasMs */
|
||||
energyJoules *= 0.001; /* convert from mW to W */
|
||||
energyJoules *= rx->TmeasMs_likelywillbe20ms_; /* multiplied by TmeasMs = joules */
|
||||
return rx.err;
|
||||
}
|
||||
/* Clear sticky faults.
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*/
|
||||
CTR_Code PDP::ClearStickyFaults()
|
||||
{
|
||||
int32_t status = 0;
|
||||
uint8_t pdpControl[] = { 0x80 }; /* only bit set is ClearStickyFaults */
|
||||
FRC_NetworkCommunication_CANSessionMux_sendMessage(CONTROL_1 | GetDeviceNumber(), pdpControl, sizeof(pdpControl), 0, &status);
|
||||
if(status)
|
||||
return CTR_TxFailed;
|
||||
return CTR_OKAY;
|
||||
}
|
||||
|
||||
/* Reset Energy Signals
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*/
|
||||
CTR_Code PDP::ResetEnergy()
|
||||
{
|
||||
int32_t status = 0;
|
||||
uint8_t pdpControl[] = { 0x40 }; /* only bit set is ResetEnergy */
|
||||
FRC_NetworkCommunication_CANSessionMux_sendMessage(CONTROL_1 | GetDeviceNumber(), pdpControl, sizeof(pdpControl), 0, &status);
|
||||
if(status)
|
||||
return CTR_TxFailed;
|
||||
return CTR_OKAY;
|
||||
}
|
||||
//------------------ C interface --------------------------------------------//
|
||||
extern "C" {
|
||||
void * c_PDP_Init(void)
|
||||
{
|
||||
return new PDP();
|
||||
}
|
||||
CTR_Code c_GetChannelCurrent(void * handle,UINT8 idx, double *status)
|
||||
{
|
||||
return ((PDP*)handle)-> GetChannelCurrent(idx,*status);
|
||||
}
|
||||
CTR_Code c_GetVoltage(void * handle,double *status)
|
||||
{
|
||||
return ((PDP*)handle)-> GetVoltage(*status);
|
||||
}
|
||||
CTR_Code c_GetTemperature(void * handle,double *status)
|
||||
{
|
||||
return ((PDP*)handle)-> GetTemperature(*status);
|
||||
}
|
||||
void c_SetDeviceNumber_PDP(void * handle,UINT8 deviceNumber)
|
||||
{
|
||||
}
|
||||
}
|
||||
#include "PDP.h"
|
||||
#include "FRC_NetworkCommunication/CANSessionMux.h" //CAN Comm
|
||||
#include <string.h> // memset
|
||||
|
||||
#define STATUS_1 0x8041400
|
||||
#define STATUS_2 0x8041440
|
||||
#define STATUS_3 0x8041480
|
||||
#define STATUS_ENERGY 0x8041740
|
||||
|
||||
#define CONTROL_1 0x08041C00 /* PDP_Control_ClearStats */
|
||||
|
||||
#define EXPECTED_RESPONSE_TIMEOUT_MS (50)
|
||||
#define GET_STATUS1() CtreCanNode::recMsg<PdpStatus1_t> rx = GetRx<PdpStatus1_t>(STATUS_1|GetDeviceNumber(),EXPECTED_RESPONSE_TIMEOUT_MS)
|
||||
#define GET_STATUS2() CtreCanNode::recMsg<PdpStatus2_t> rx = GetRx<PdpStatus2_t>(STATUS_2|GetDeviceNumber(),EXPECTED_RESPONSE_TIMEOUT_MS)
|
||||
#define GET_STATUS3() CtreCanNode::recMsg<PdpStatus3_t> rx = GetRx<PdpStatus3_t>(STATUS_3|GetDeviceNumber(),EXPECTED_RESPONSE_TIMEOUT_MS)
|
||||
#define GET_STATUS_ENERGY() CtreCanNode::recMsg<PDP_Status_Energy_t> rx = GetRx<PDP_Status_Energy_t>(STATUS_ENERGY|GetDeviceNumber(),EXPECTED_RESPONSE_TIMEOUT_MS)
|
||||
|
||||
/* encoder/decoders */
|
||||
typedef struct _PdpStatus1_t{
|
||||
unsigned chan1_h8:8;
|
||||
unsigned chan2_h6:6;
|
||||
unsigned chan1_l2:2;
|
||||
unsigned chan3_h4:4;
|
||||
unsigned chan2_l4:4;
|
||||
unsigned chan4_h2:2;
|
||||
unsigned chan3_l6:6;
|
||||
unsigned chan4_l8:8;
|
||||
unsigned chan5_h8:8;
|
||||
unsigned chan6_h6:6;
|
||||
unsigned chan5_l2:2;
|
||||
unsigned reserved4:4;
|
||||
unsigned chan6_l4:4;
|
||||
}PdpStatus1_t;
|
||||
typedef struct _PdpStatus2_t{
|
||||
unsigned chan7_h8:8;
|
||||
unsigned chan8_h6:6;
|
||||
unsigned chan7_l2:2;
|
||||
unsigned chan9_h4:4;
|
||||
unsigned chan8_l4:4;
|
||||
unsigned chan10_h2:2;
|
||||
unsigned chan9_l6:6;
|
||||
unsigned chan10_l8:8;
|
||||
unsigned chan11_h8:8;
|
||||
unsigned chan12_h6:6;
|
||||
unsigned chan11_l2:2;
|
||||
unsigned reserved4:4;
|
||||
unsigned chan12_l4:4;
|
||||
}PdpStatus2_t;
|
||||
typedef struct _PdpStatus3_t{
|
||||
unsigned chan13_h8:8;
|
||||
unsigned chan14_h6:6;
|
||||
unsigned chan13_l2:2;
|
||||
unsigned chan15_h4:4;
|
||||
unsigned chan14_l4:4;
|
||||
unsigned chan16_h2:2;
|
||||
unsigned chan15_l6:6;
|
||||
unsigned chan16_l8:8;
|
||||
unsigned internalResBattery_mOhms:8;
|
||||
unsigned busVoltage:8;
|
||||
unsigned temp:8;
|
||||
}PdpStatus3_t;
|
||||
typedef struct _PDP_Status_Energy_t {
|
||||
unsigned TmeasMs_likelywillbe20ms_:8;
|
||||
unsigned TotalCurrent_125mAperunit_h8:8;
|
||||
unsigned Power_125mWperunit_h4:4;
|
||||
unsigned TotalCurrent_125mAperunit_l4:4;
|
||||
unsigned Power_125mWperunit_m8:8;
|
||||
unsigned Energy_125mWPerUnitXTmeas_h4:4;
|
||||
unsigned Power_125mWperunit_l4:4;
|
||||
unsigned Energy_125mWPerUnitXTmeas_mh8:8;
|
||||
unsigned Energy_125mWPerUnitXTmeas_ml8:8;
|
||||
unsigned Energy_125mWPerUnitXTmeas_l8:8;
|
||||
} PDP_Status_Energy_t ;
|
||||
|
||||
PDP::PDP(UINT8 deviceNumber): CtreCanNode(deviceNumber)
|
||||
{
|
||||
RegisterRx(STATUS_1 | deviceNumber );
|
||||
RegisterRx(STATUS_2 | deviceNumber );
|
||||
RegisterRx(STATUS_3 | deviceNumber );
|
||||
}
|
||||
/* PDP D'tor
|
||||
*/
|
||||
PDP::~PDP()
|
||||
{
|
||||
}
|
||||
|
||||
CTR_Code PDP::GetChannelCurrent(UINT8 idx, double ¤t)
|
||||
{
|
||||
CTR_Code retval = CTR_InvalidParamValue;
|
||||
uint32_t raw = 0;
|
||||
|
||||
if(idx <= 5){
|
||||
GET_STATUS1();
|
||||
retval = rx.err;
|
||||
switch(idx){
|
||||
case 0: raw = ((uint32_t)rx->chan1_h8 << 2) | rx->chan1_l2; break;
|
||||
case 1: raw = ((uint32_t)rx->chan2_h6 << 4) | rx->chan2_l4; break;
|
||||
case 2: raw = ((uint32_t)rx->chan3_h4 << 6) | rx->chan3_l6; break;
|
||||
case 3: raw = ((uint32_t)rx->chan4_h2 << 8) | rx->chan4_l8; break;
|
||||
case 4: raw = ((uint32_t)rx->chan5_h8 << 2) | rx->chan5_l2; break;
|
||||
case 5: raw = ((uint32_t)rx->chan6_h6 << 4) | rx->chan6_l4; break;
|
||||
default: retval = CTR_InvalidParamValue; break;
|
||||
}
|
||||
}else if(idx <= 11){
|
||||
GET_STATUS2();
|
||||
retval = rx.err;
|
||||
switch(idx){
|
||||
case 6: raw = ((uint32_t)rx->chan7_h8 << 2) | rx->chan7_l2; break;
|
||||
case 7: raw = ((uint32_t)rx->chan8_h6 << 4) | rx->chan8_l4; break;
|
||||
case 8: raw = ((uint32_t)rx->chan9_h4 << 6) | rx->chan9_l6; break;
|
||||
case 9: raw = ((uint32_t)rx->chan10_h2 << 8) | rx->chan10_l8; break;
|
||||
case 10: raw = ((uint32_t)rx->chan11_h8 << 2) | rx->chan11_l2; break;
|
||||
case 11: raw = ((uint32_t)rx->chan12_h6 << 4) | rx->chan12_l4; break;
|
||||
default: retval = CTR_InvalidParamValue; break;
|
||||
}
|
||||
}else if(idx <= 15){
|
||||
GET_STATUS3();
|
||||
retval = rx.err;
|
||||
switch(idx){
|
||||
case 12: raw = ((uint32_t)rx->chan13_h8 << 2) | rx->chan13_l2; break;
|
||||
case 13: raw = ((uint32_t)rx->chan14_h6 << 4) | rx->chan14_l4; break;
|
||||
case 14: raw = ((uint32_t)rx->chan15_h4 << 6) | rx->chan15_l6; break;
|
||||
case 15: raw = ((uint32_t)rx->chan16_h2 << 8) | rx->chan16_l8; break;
|
||||
default: retval = CTR_InvalidParamValue; break;
|
||||
}
|
||||
}
|
||||
/* convert to amps */
|
||||
current = (double)raw * 0.125; /* 7.3 fixed pt value in Amps */
|
||||
/* signal caller with success */
|
||||
return retval;
|
||||
}
|
||||
CTR_Code PDP::GetVoltage(double &voltage)
|
||||
{
|
||||
GET_STATUS3();
|
||||
uint32_t raw = rx->busVoltage;
|
||||
voltage = (double)raw * 0.05 + 4.0; /* 50mV per unit plus 4V. */;
|
||||
return rx.err;
|
||||
}
|
||||
CTR_Code PDP::GetTemperature(double &tempC)
|
||||
{
|
||||
GET_STATUS3();
|
||||
uint32_t raw = rx->temp;
|
||||
tempC = (double)raw * 1.03250836957542 - 67.8564500484966;
|
||||
return rx.err;
|
||||
}
|
||||
CTR_Code PDP::GetTotalCurrent(double ¤tAmps)
|
||||
{
|
||||
GET_STATUS_ENERGY();
|
||||
uint32_t raw;
|
||||
raw = rx->TotalCurrent_125mAperunit_h8;
|
||||
raw <<= 4;
|
||||
raw |= rx->TotalCurrent_125mAperunit_l4;
|
||||
currentAmps = 0.125 * raw;
|
||||
return rx.err;
|
||||
}
|
||||
CTR_Code PDP::GetTotalPower(double &powerWatts)
|
||||
{
|
||||
GET_STATUS_ENERGY();
|
||||
uint32_t raw;
|
||||
raw = rx->Power_125mWperunit_h4;
|
||||
raw <<= 8;
|
||||
raw |= rx->Power_125mWperunit_m8;
|
||||
raw <<= 4;
|
||||
raw |= rx->Power_125mWperunit_l4;
|
||||
powerWatts = 0.125 * raw;
|
||||
return rx.err;
|
||||
}
|
||||
CTR_Code PDP::GetTotalEnergy(double &energyJoules)
|
||||
{
|
||||
GET_STATUS_ENERGY();
|
||||
uint32_t raw;
|
||||
raw = rx->Energy_125mWPerUnitXTmeas_h4;
|
||||
raw <<= 8;
|
||||
raw |= rx->Energy_125mWPerUnitXTmeas_mh8;
|
||||
raw <<= 8;
|
||||
raw |= rx->Energy_125mWPerUnitXTmeas_ml8;
|
||||
raw <<= 8;
|
||||
raw |= rx->Energy_125mWPerUnitXTmeas_l8;
|
||||
energyJoules = 0.125 * raw; /* mW integrated every TmeasMs */
|
||||
energyJoules *= 0.001; /* convert from mW to W */
|
||||
energyJoules *= rx->TmeasMs_likelywillbe20ms_; /* multiplied by TmeasMs = joules */
|
||||
return rx.err;
|
||||
}
|
||||
/* Clear sticky faults.
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*/
|
||||
CTR_Code PDP::ClearStickyFaults()
|
||||
{
|
||||
int32_t status = 0;
|
||||
uint8_t pdpControl[] = { 0x80 }; /* only bit set is ClearStickyFaults */
|
||||
FRC_NetworkCommunication_CANSessionMux_sendMessage(CONTROL_1 | GetDeviceNumber(), pdpControl, sizeof(pdpControl), 0, &status);
|
||||
if(status)
|
||||
return CTR_TxFailed;
|
||||
return CTR_OKAY;
|
||||
}
|
||||
|
||||
/* Reset Energy Signals
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*/
|
||||
CTR_Code PDP::ResetEnergy()
|
||||
{
|
||||
int32_t status = 0;
|
||||
uint8_t pdpControl[] = { 0x40 }; /* only bit set is ResetEnergy */
|
||||
FRC_NetworkCommunication_CANSessionMux_sendMessage(CONTROL_1 | GetDeviceNumber(), pdpControl, sizeof(pdpControl), 0, &status);
|
||||
if(status)
|
||||
return CTR_TxFailed;
|
||||
return CTR_OKAY;
|
||||
}
|
||||
//------------------ C interface --------------------------------------------//
|
||||
extern "C" {
|
||||
void * c_PDP_Init(void)
|
||||
{
|
||||
return new PDP();
|
||||
}
|
||||
CTR_Code c_GetChannelCurrent(void * handle,UINT8 idx, double *status)
|
||||
{
|
||||
return ((PDP*)handle)-> GetChannelCurrent(idx,*status);
|
||||
}
|
||||
CTR_Code c_GetVoltage(void * handle,double *status)
|
||||
{
|
||||
return ((PDP*)handle)-> GetVoltage(*status);
|
||||
}
|
||||
CTR_Code c_GetTemperature(void * handle,double *status)
|
||||
{
|
||||
return ((PDP*)handle)-> GetTemperature(*status);
|
||||
}
|
||||
void c_SetDeviceNumber_PDP(void * handle,UINT8 deviceNumber)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
#ifndef PDP_H_
|
||||
#define PDP_H_
|
||||
#include "ctre.h" //BIT Defines + Typedefs
|
||||
#include "CtreCanNode.h"
|
||||
class PDP : public CtreCanNode
|
||||
{
|
||||
public:
|
||||
/* Get PDP Channel Current
|
||||
*
|
||||
* @Param - deviceNumber - Device ID for PDP. Factory default is 60. Function defaults to 60.
|
||||
*/
|
||||
PDP(UINT8 deviceNumber=0);
|
||||
~PDP();
|
||||
/* Get PDP Channel Current
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - idx - ID of channel to return current for (channels 1-16)
|
||||
*
|
||||
* @Param - status - Current of channel 'idx' in Amps (A)
|
||||
*/
|
||||
CTR_Code GetChannelCurrent(UINT8 idx, double &status);
|
||||
|
||||
/* Get Bus Voltage of PDP
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - Voltage (V) across PDP
|
||||
*/
|
||||
CTR_Code GetVoltage(double &status);
|
||||
|
||||
/* Get Temperature of PDP
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - Temperature of PDP in Centigrade / Celcius (C)
|
||||
*/
|
||||
CTR_Code GetTemperature(double &status);
|
||||
|
||||
CTR_Code GetTotalCurrent(double ¤tAmps);
|
||||
CTR_Code GetTotalPower(double &powerWatts);
|
||||
CTR_Code GetTotalEnergy(double &energyJoules);
|
||||
/* Clear sticky faults.
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*/
|
||||
CTR_Code ClearStickyFaults();
|
||||
|
||||
/* Reset Energy Signals
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*/
|
||||
CTR_Code ResetEnergy();
|
||||
private:
|
||||
uint64_t ReadCurrents(uint8_t api);
|
||||
};
|
||||
extern "C" {
|
||||
void * c_PDP_Init();
|
||||
CTR_Code c_GetChannelCurrent(void * handle,UINT8 idx, double *status);
|
||||
CTR_Code c_GetVoltage(void * handle,double *status);
|
||||
CTR_Code c_GetTemperature(void * handle,double *status);
|
||||
void c_SetDeviceNumber_PDP(void * handle,UINT8 deviceNumber);
|
||||
}
|
||||
#endif /* PDP_H_ */
|
||||
#ifndef PDP_H_
|
||||
#define PDP_H_
|
||||
#include "ctre.h" //BIT Defines + Typedefs
|
||||
#include "CtreCanNode.h"
|
||||
class PDP : public CtreCanNode
|
||||
{
|
||||
public:
|
||||
/* Get PDP Channel Current
|
||||
*
|
||||
* @Param - deviceNumber - Device ID for PDP. Factory default is 60. Function defaults to 60.
|
||||
*/
|
||||
PDP(UINT8 deviceNumber=0);
|
||||
~PDP();
|
||||
/* Get PDP Channel Current
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - idx - ID of channel to return current for (channels 1-16)
|
||||
*
|
||||
* @Param - status - Current of channel 'idx' in Amps (A)
|
||||
*/
|
||||
CTR_Code GetChannelCurrent(UINT8 idx, double &status);
|
||||
|
||||
/* Get Bus Voltage of PDP
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - Voltage (V) across PDP
|
||||
*/
|
||||
CTR_Code GetVoltage(double &status);
|
||||
|
||||
/* Get Temperature of PDP
|
||||
*
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*
|
||||
* @Param - status - Temperature of PDP in Centigrade / Celcius (C)
|
||||
*/
|
||||
CTR_Code GetTemperature(double &status);
|
||||
|
||||
CTR_Code GetTotalCurrent(double ¤tAmps);
|
||||
CTR_Code GetTotalPower(double &powerWatts);
|
||||
CTR_Code GetTotalEnergy(double &energyJoules);
|
||||
/* Clear sticky faults.
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*/
|
||||
CTR_Code ClearStickyFaults();
|
||||
|
||||
/* Reset Energy Signals
|
||||
* @Return - CTR_Code - Error code (if any)
|
||||
*/
|
||||
CTR_Code ResetEnergy();
|
||||
private:
|
||||
uint64_t ReadCurrents(uint8_t api);
|
||||
};
|
||||
extern "C" {
|
||||
void * c_PDP_Init();
|
||||
CTR_Code c_GetChannelCurrent(void * handle,UINT8 idx, double *status);
|
||||
CTR_Code c_GetVoltage(void * handle,double *status);
|
||||
CTR_Code c_GetTemperature(void * handle,double *status);
|
||||
void c_SetDeviceNumber_PDP(void * handle,UINT8 deviceNumber);
|
||||
}
|
||||
#endif /* PDP_H_ */
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
/**
|
||||
* @file ctre.h
|
||||
* Common header for all CTRE HAL modules.
|
||||
*/
|
||||
#ifndef CTRE_H
|
||||
#define CTRE_H
|
||||
|
||||
//Bit Defines
|
||||
#define BIT0 0x01
|
||||
#define BIT1 0x02
|
||||
#define BIT2 0x04
|
||||
#define BIT3 0x08
|
||||
#define BIT4 0x10
|
||||
#define BIT5 0x20
|
||||
#define BIT6 0x40
|
||||
#define BIT7 0x80
|
||||
#define BIT8 0x0100
|
||||
#define BIT9 0x0200
|
||||
#define BIT10 0x0400
|
||||
#define BIT11 0x0800
|
||||
#define BIT12 0x1000
|
||||
#define BIT13 0x2000
|
||||
#define BIT14 0x4000
|
||||
#define BIT15 0x8000
|
||||
|
||||
//Signed
|
||||
typedef signed char INT8;
|
||||
typedef signed short INT16;
|
||||
typedef signed int INT32;
|
||||
typedef signed long long INT64;
|
||||
|
||||
//Unsigned
|
||||
typedef unsigned char UINT8;
|
||||
typedef unsigned short UINT16;
|
||||
typedef unsigned int UINT32;
|
||||
typedef unsigned long long UINT64;
|
||||
|
||||
//Other
|
||||
typedef unsigned char UCHAR;
|
||||
typedef unsigned short USHORT;
|
||||
typedef unsigned int UINT;
|
||||
typedef unsigned long ULONG;
|
||||
|
||||
typedef enum {
|
||||
CTR_OKAY, //!< No Error - Function executed as expected
|
||||
CTR_RxTimeout, //!< CAN frame has not been received within specified period of time.
|
||||
CTR_TxTimeout, //!< Not used.
|
||||
CTR_InvalidParamValue, //!< Caller passed an invalid param
|
||||
CTR_UnexpectedArbId, //!< Specified CAN Id is invalid.
|
||||
CTR_TxFailed, //!< Could not transmit the CAN frame.
|
||||
CTR_SigNotUpdated, //!< Have not received an value response for signal.
|
||||
CTR_BufferFull, //!< Caller attempted to insert data into a buffer that is full.
|
||||
}CTR_Code;
|
||||
|
||||
#endif /* CTRE_H */
|
||||
/**
|
||||
* @file ctre.h
|
||||
* Common header for all CTRE HAL modules.
|
||||
*/
|
||||
#ifndef CTRE_H
|
||||
#define CTRE_H
|
||||
|
||||
//Bit Defines
|
||||
#define BIT0 0x01
|
||||
#define BIT1 0x02
|
||||
#define BIT2 0x04
|
||||
#define BIT3 0x08
|
||||
#define BIT4 0x10
|
||||
#define BIT5 0x20
|
||||
#define BIT6 0x40
|
||||
#define BIT7 0x80
|
||||
#define BIT8 0x0100
|
||||
#define BIT9 0x0200
|
||||
#define BIT10 0x0400
|
||||
#define BIT11 0x0800
|
||||
#define BIT12 0x1000
|
||||
#define BIT13 0x2000
|
||||
#define BIT14 0x4000
|
||||
#define BIT15 0x8000
|
||||
|
||||
//Signed
|
||||
typedef signed char INT8;
|
||||
typedef signed short INT16;
|
||||
typedef signed int INT32;
|
||||
typedef signed long long INT64;
|
||||
|
||||
//Unsigned
|
||||
typedef unsigned char UINT8;
|
||||
typedef unsigned short UINT16;
|
||||
typedef unsigned int UINT32;
|
||||
typedef unsigned long long UINT64;
|
||||
|
||||
//Other
|
||||
typedef unsigned char UCHAR;
|
||||
typedef unsigned short USHORT;
|
||||
typedef unsigned int UINT;
|
||||
typedef unsigned long ULONG;
|
||||
|
||||
typedef enum {
|
||||
CTR_OKAY, //!< No Error - Function executed as expected
|
||||
CTR_RxTimeout, //!< CAN frame has not been received within specified period of time.
|
||||
CTR_TxTimeout, //!< Not used.
|
||||
CTR_InvalidParamValue, //!< Caller passed an invalid param
|
||||
CTR_UnexpectedArbId, //!< Specified CAN Id is invalid.
|
||||
CTR_TxFailed, //!< Could not transmit the CAN frame.
|
||||
CTR_SigNotUpdated, //!< Have not received an value response for signal.
|
||||
CTR_BufferFull, //!< Caller attempted to insert data into a buffer that is full.
|
||||
}CTR_Code;
|
||||
|
||||
#endif /* CTRE_H */
|
||||
|
||||
@@ -1,156 +1,156 @@
|
||||
#ifndef __CAN_DEVICE_INTERFACE_H__
|
||||
#define __CAN_DEVICE_INTERFACE_H__
|
||||
|
||||
#define MAX_STRING_LEN 64
|
||||
|
||||
#define SUPPORT_UNIQUE_ID (1) /* depends entirely on old vs new build */
|
||||
#define USE_NTH_ORDER (0) /* zero to user deviceId */
|
||||
#define SUPPORT_MOTOR_CONTROLLER_PROFILE (1)
|
||||
namespace CANDeviceInterface1
|
||||
{
|
||||
|
||||
struct PIDSlot
|
||||
{
|
||||
// Proportional gain
|
||||
float pGain;
|
||||
// Integral gain
|
||||
float iGain;
|
||||
// Differential gain
|
||||
float dGain;
|
||||
// Feed-forward gain
|
||||
float fGain;
|
||||
// Integral zone
|
||||
float iZone;
|
||||
// Closed-loop ramp rate
|
||||
float clRampRate;
|
||||
};
|
||||
|
||||
struct DeviceDescriptor
|
||||
{
|
||||
// The full device ID, including the device number, manufacturer, and device type.
|
||||
// The mask of a message the device supports is 0x1FFF003F.
|
||||
unsigned int deviceID;
|
||||
#if SUPPORT_UNIQUE_ID != 0
|
||||
// This is the ID that uniquely identifies the device node in the UI.
|
||||
// The purpose of this is to be able to track the device across renames or deviceID changes.
|
||||
unsigned int uniqueID;
|
||||
#endif
|
||||
// An dynamically assigned ID that will make setting deviceIDs robust,
|
||||
// Never again will you need to isolate a CAN node just to fix it's ID.
|
||||
unsigned int dynamicID;
|
||||
// User visible name. This can be customized by the user, but should have a
|
||||
// reasonable default.
|
||||
char name[MAX_STRING_LEN];
|
||||
// This is a user visible model name that should match the can_devices.ini section.
|
||||
char model[MAX_STRING_LEN];
|
||||
// This is a version number that represents the version of firmware currently
|
||||
// installed on the device.
|
||||
char currentVersion[MAX_STRING_LEN];
|
||||
// Hardware revision.
|
||||
char hardwareRev[MAX_STRING_LEN];
|
||||
// Bootloader version. Will not change for the life of the product, but additional
|
||||
// field upgrade features could be added in newer hardware.
|
||||
char bootloaderRev[MAX_STRING_LEN];
|
||||
// Manufacture Date. Could be a calender date or just the FRC season year.
|
||||
// Also helps troubleshooting "old ones" vs "new ones".
|
||||
char manufactureDate[MAX_STRING_LEN];
|
||||
// General status of the hardware. For example if the device is in bootloader
|
||||
// due to a bad flash UI could emphasize that.
|
||||
char softwareStatus[MAX_STRING_LEN];
|
||||
// Is the LED currently on?
|
||||
bool led;
|
||||
// Reserved fields for future use by CTRE. Not touched by frccansae
|
||||
unsigned int dynFlags;
|
||||
unsigned int flags; /* bitfield */
|
||||
unsigned int ptrToString;
|
||||
//unsigned int reserved0;
|
||||
//unsigned int reserved1;
|
||||
//unsigned int reserved2;
|
||||
#if SUPPORT_MOTOR_CONTROLLER_PROFILE != 0
|
||||
// Motor controller properties (ignored if SupportsMotorControllerProperties is false or unset for this model)
|
||||
unsigned int brakeMode; // 0=Coast, 1=Brake
|
||||
unsigned int limitSwitchFwdMode; // 0=disabled, 1=Normally Closed, 2=Normally Open
|
||||
unsigned int limitSwitchRevMode; // 0=disabled, 1=Normally Closed, 2=Normally Open
|
||||
// Limit-switch soft limits
|
||||
bool bFwdSoftLimitEnable;
|
||||
bool bRevSoftLimitEnable;
|
||||
float softLimitFwd;
|
||||
float softLimitRev;
|
||||
// PID constants for slot 0
|
||||
struct PIDSlot slot0;
|
||||
// PID constants for slot 1
|
||||
struct PIDSlot slot1;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define kLimitSwitchMode_Disabled (0)
|
||||
#define kLimitSwitchMode_NormallyClosed (1)
|
||||
#define kLimitSwitchMode_NormallyOpen (2)
|
||||
|
||||
// Interface functions that must be implemented by the CAN Firmware Update Library
|
||||
|
||||
// Returns the number of devices that will be returned in a call to
|
||||
// getListOfDevices(). The calling library will use this info to allocate enough
|
||||
// memory to accept all device info.
|
||||
int getNumberOfDevices();
|
||||
|
||||
// Return info about discovered devices. The array of structs should be
|
||||
// populated before returning. The numDescriptors input describes how many
|
||||
// elements were allocated to prevent memory corruption. The number of devices
|
||||
// populated should be returned from this function as well.
|
||||
int getListOfDevices(DeviceDescriptor *devices, int numDescriptors);
|
||||
|
||||
// When the user requests to update the firmware of a device a thread will be
|
||||
// spawned and this function is called from that thread. This function should
|
||||
// complete the firmware update process before returning. The image
|
||||
// contents and size are directly from the file selected by the user. The
|
||||
// error message string can be filled with a NULL-terminated message to show the
|
||||
// user if there was a problem updating firmware. The error message is only
|
||||
// displayed if a non-zero value is returned from this function.
|
||||
int updateFirmware(const DeviceDescriptor *device, const unsigned char *imageContents, unsigned int imageSize, char *errorMessage, int errorMessageMaxSize);
|
||||
|
||||
// This function is called periodically from the UI thread while the firmware
|
||||
// update is in progress. The percentComplete parameter should the filled in
|
||||
// with the current progress of the firmware update process to update a progress
|
||||
// bar in the UI.
|
||||
void checkUpdateProgress(const DeviceDescriptor *device, int *percentComplete);
|
||||
|
||||
// This is called when the user selects a new ID to assign on the bus and
|
||||
// chooses to save. The newDeviceID is really just the device number. The
|
||||
// manufacturer and device type will remain unchanged. If a problem is detected
|
||||
// when assigning a new ID, this function should return a non-zero value.
|
||||
int assignBroadcastDeviceID(unsigned int newDeviceID);
|
||||
// The device descriptor should be updated with the new device ID. The name may
|
||||
// also change in the descriptor and will be updated in the UI immediately.
|
||||
// Be sure to modify the descriptor first since the refresh from the UI is
|
||||
// asynchronous.
|
||||
int assignDeviceID(DeviceDescriptor *device, unsigned int newDeviceID);
|
||||
|
||||
// This entry-point will get called when the user chooses to change the value
|
||||
// of the device's LED. This will allow the user to identify devices which
|
||||
// support dynamic addresses or are otherwise unknown. If this function returns
|
||||
// a non-zero value, the UI will report an error.
|
||||
int saveLightLed(const DeviceDescriptor *device, bool newLEDStatus);
|
||||
|
||||
// This entry-point will get called when the user chooses to change the alias
|
||||
// of the device with the device specified. If this function returns a non-
|
||||
// zero value, the UI will report an error. The device descriptor must be
|
||||
// updated with the new name that was selected. If a different name is saved
|
||||
// to the descriptor than the user specified, this will require a manual
|
||||
// refresh by the user. This is reported as CAR #505139
|
||||
int saveDeviceName(DeviceDescriptor *device, const char *newName);
|
||||
|
||||
// This entry-point will get called when the user changes any of the motor
|
||||
// controller specific properties. If this function returns a non-zero value,
|
||||
// the UI will report an error. The device descriptor may be updated with
|
||||
// coerced values.
|
||||
int saveMotorParameters(DeviceDescriptor *device);
|
||||
|
||||
// Run some sort of self-test functionality on the device. This can be anything
|
||||
// and the results will be displayed to the user. A non-zero return value
|
||||
// indicates an error.
|
||||
int selfTest(const DeviceDescriptor *device, char *detailedResults, int detailedResultsMaxSize);
|
||||
|
||||
} /* CANDeviceInterface */
|
||||
|
||||
#endif /* __CAN_DEVICE_INTERFACE_H__ */
|
||||
#ifndef __CAN_DEVICE_INTERFACE_H__
|
||||
#define __CAN_DEVICE_INTERFACE_H__
|
||||
|
||||
#define MAX_STRING_LEN 64
|
||||
|
||||
#define SUPPORT_UNIQUE_ID (1) /* depends entirely on old vs new build */
|
||||
#define USE_NTH_ORDER (0) /* zero to user deviceId */
|
||||
#define SUPPORT_MOTOR_CONTROLLER_PROFILE (1)
|
||||
namespace CANDeviceInterface1
|
||||
{
|
||||
|
||||
struct PIDSlot
|
||||
{
|
||||
// Proportional gain
|
||||
float pGain;
|
||||
// Integral gain
|
||||
float iGain;
|
||||
// Differential gain
|
||||
float dGain;
|
||||
// Feed-forward gain
|
||||
float fGain;
|
||||
// Integral zone
|
||||
float iZone;
|
||||
// Closed-loop ramp rate
|
||||
float clRampRate;
|
||||
};
|
||||
|
||||
struct DeviceDescriptor
|
||||
{
|
||||
// The full device ID, including the device number, manufacturer, and device type.
|
||||
// The mask of a message the device supports is 0x1FFF003F.
|
||||
unsigned int deviceID;
|
||||
#if SUPPORT_UNIQUE_ID != 0
|
||||
// This is the ID that uniquely identifies the device node in the UI.
|
||||
// The purpose of this is to be able to track the device across renames or deviceID changes.
|
||||
unsigned int uniqueID;
|
||||
#endif
|
||||
// An dynamically assigned ID that will make setting deviceIDs robust,
|
||||
// Never again will you need to isolate a CAN node just to fix it's ID.
|
||||
unsigned int dynamicID;
|
||||
// User visible name. This can be customized by the user, but should have a
|
||||
// reasonable default.
|
||||
char name[MAX_STRING_LEN];
|
||||
// This is a user visible model name that should match the can_devices.ini section.
|
||||
char model[MAX_STRING_LEN];
|
||||
// This is a version number that represents the version of firmware currently
|
||||
// installed on the device.
|
||||
char currentVersion[MAX_STRING_LEN];
|
||||
// Hardware revision.
|
||||
char hardwareRev[MAX_STRING_LEN];
|
||||
// Bootloader version. Will not change for the life of the product, but additional
|
||||
// field upgrade features could be added in newer hardware.
|
||||
char bootloaderRev[MAX_STRING_LEN];
|
||||
// Manufacture Date. Could be a calender date or just the FRC season year.
|
||||
// Also helps troubleshooting "old ones" vs "new ones".
|
||||
char manufactureDate[MAX_STRING_LEN];
|
||||
// General status of the hardware. For example if the device is in bootloader
|
||||
// due to a bad flash UI could emphasize that.
|
||||
char softwareStatus[MAX_STRING_LEN];
|
||||
// Is the LED currently on?
|
||||
bool led;
|
||||
// Reserved fields for future use by CTRE. Not touched by frccansae
|
||||
unsigned int dynFlags;
|
||||
unsigned int flags; /* bitfield */
|
||||
unsigned int ptrToString;
|
||||
//unsigned int reserved0;
|
||||
//unsigned int reserved1;
|
||||
//unsigned int reserved2;
|
||||
#if SUPPORT_MOTOR_CONTROLLER_PROFILE != 0
|
||||
// Motor controller properties (ignored if SupportsMotorControllerProperties is false or unset for this model)
|
||||
unsigned int brakeMode; // 0=Coast, 1=Brake
|
||||
unsigned int limitSwitchFwdMode; // 0=disabled, 1=Normally Closed, 2=Normally Open
|
||||
unsigned int limitSwitchRevMode; // 0=disabled, 1=Normally Closed, 2=Normally Open
|
||||
// Limit-switch soft limits
|
||||
bool bFwdSoftLimitEnable;
|
||||
bool bRevSoftLimitEnable;
|
||||
float softLimitFwd;
|
||||
float softLimitRev;
|
||||
// PID constants for slot 0
|
||||
struct PIDSlot slot0;
|
||||
// PID constants for slot 1
|
||||
struct PIDSlot slot1;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define kLimitSwitchMode_Disabled (0)
|
||||
#define kLimitSwitchMode_NormallyClosed (1)
|
||||
#define kLimitSwitchMode_NormallyOpen (2)
|
||||
|
||||
// Interface functions that must be implemented by the CAN Firmware Update Library
|
||||
|
||||
// Returns the number of devices that will be returned in a call to
|
||||
// getListOfDevices(). The calling library will use this info to allocate enough
|
||||
// memory to accept all device info.
|
||||
int getNumberOfDevices();
|
||||
|
||||
// Return info about discovered devices. The array of structs should be
|
||||
// populated before returning. The numDescriptors input describes how many
|
||||
// elements were allocated to prevent memory corruption. The number of devices
|
||||
// populated should be returned from this function as well.
|
||||
int getListOfDevices(DeviceDescriptor *devices, int numDescriptors);
|
||||
|
||||
// When the user requests to update the firmware of a device a thread will be
|
||||
// spawned and this function is called from that thread. This function should
|
||||
// complete the firmware update process before returning. The image
|
||||
// contents and size are directly from the file selected by the user. The
|
||||
// error message string can be filled with a NULL-terminated message to show the
|
||||
// user if there was a problem updating firmware. The error message is only
|
||||
// displayed if a non-zero value is returned from this function.
|
||||
int updateFirmware(const DeviceDescriptor *device, const unsigned char *imageContents, unsigned int imageSize, char *errorMessage, int errorMessageMaxSize);
|
||||
|
||||
// This function is called periodically from the UI thread while the firmware
|
||||
// update is in progress. The percentComplete parameter should the filled in
|
||||
// with the current progress of the firmware update process to update a progress
|
||||
// bar in the UI.
|
||||
void checkUpdateProgress(const DeviceDescriptor *device, int *percentComplete);
|
||||
|
||||
// This is called when the user selects a new ID to assign on the bus and
|
||||
// chooses to save. The newDeviceID is really just the device number. The
|
||||
// manufacturer and device type will remain unchanged. If a problem is detected
|
||||
// when assigning a new ID, this function should return a non-zero value.
|
||||
int assignBroadcastDeviceID(unsigned int newDeviceID);
|
||||
// The device descriptor should be updated with the new device ID. The name may
|
||||
// also change in the descriptor and will be updated in the UI immediately.
|
||||
// Be sure to modify the descriptor first since the refresh from the UI is
|
||||
// asynchronous.
|
||||
int assignDeviceID(DeviceDescriptor *device, unsigned int newDeviceID);
|
||||
|
||||
// This entry-point will get called when the user chooses to change the value
|
||||
// of the device's LED. This will allow the user to identify devices which
|
||||
// support dynamic addresses or are otherwise unknown. If this function returns
|
||||
// a non-zero value, the UI will report an error.
|
||||
int saveLightLed(const DeviceDescriptor *device, bool newLEDStatus);
|
||||
|
||||
// This entry-point will get called when the user chooses to change the alias
|
||||
// of the device with the device specified. If this function returns a non-
|
||||
// zero value, the UI will report an error. The device descriptor must be
|
||||
// updated with the new name that was selected. If a different name is saved
|
||||
// to the descriptor than the user specified, this will require a manual
|
||||
// refresh by the user. This is reported as CAR #505139
|
||||
int saveDeviceName(DeviceDescriptor *device, const char *newName);
|
||||
|
||||
// This entry-point will get called when the user changes any of the motor
|
||||
// controller specific properties. If this function returns a non-zero value,
|
||||
// the UI will report an error. The device descriptor may be updated with
|
||||
// coerced values.
|
||||
int saveMotorParameters(DeviceDescriptor *device);
|
||||
|
||||
// Run some sort of self-test functionality on the device. This can be anything
|
||||
// and the results will be displayed to the user. A non-zero return value
|
||||
// indicates an error.
|
||||
int selfTest(const DeviceDescriptor *device, char *detailedResults, int detailedResultsMaxSize);
|
||||
|
||||
} /* CANDeviceInterface */
|
||||
|
||||
#endif /* __CAN_DEVICE_INTERFACE_H__ */
|
||||
|
||||
Reference in New Issue
Block a user