New netcomms .so and headers.

CAN isn't fully working yet, but this change is necessary to compile for the v9 image.

Change-Id: Ife99686a7e7a9979c95ec7a395d597011090fa37
This commit is contained in:
thomasclark
2014-06-16 10:24:48 -04:00
parent 58021f7397
commit 85dff7d2ec
19 changed files with 576 additions and 570 deletions

View File

@@ -11,7 +11,9 @@
#include <stdint.h>
#define CAN_IS_FRAME_REMOTE 0x80000000
#define CAN_MESSAGE_ID_MASK 0x1FFFFFFF
#define CAN_IS_FRAME_11BIT 0x40000000
#define CAN_29BIT_MESSAGE_ID_MASK 0x1FFFFFFF
#define CAN_11BIT_MESSAGE_ID_MASK 0x000007FF
class CANInterfacePlugin
{
@@ -56,6 +58,6 @@ public:
* @param interface A pointer to an object that inherits from CANInterfacePlugin and implements
* the pure virtual interface. If NULL, unregister the current plugin.
*/
void FRC_NetworkCommunication_JaguarCANDriver_registerInterface(CANInterfacePlugin* interface);
void FRC_NetworkCommunication_CANSessionMux_registerInterface(CANInterfacePlugin* interface);
#endif // __CANInterfacePlugin_h__

View File

@@ -0,0 +1,61 @@
// CANSessionMux.h
//
// Defines the API for building a CAN Interface Plugin to support
// PWM-cable-free CAN motor control on FRC robots. This allows you
// to connect any CAN interface to the secure Jaguar CAN driver.
//
#ifndef __CANSessionMux_h__
#define __CANSessionMux_h__
#if defined(__vxworks)
#include <vxWorks.h>
#else
#include <stdint.h>
#endif
#define CAN_SEND_PERIOD_NO_REPEAT 0
#define CAN_SEND_PERIOD_STOP_REPEATING -1
/* Flags in the upper bits of the messageID */
#define CAN_IS_FRAME_REMOTE 0x80000000
#define CAN_IS_FRAME_11BIT 0x40000000
#define ERR_CANSessionMux_InvalidBuffer -44086
#define ERR_CANSessionMux_MessageNotFound -44087
#define WARN_CANSessionMux_NoToken 44087
#define ERR_CANSessionMux_NotAllowed -44088
#define ERR_CANSessionMux_NotInitialized -44089
struct tCANStreamMessage{
uint32_t messageID;
uint32_t timeStamp;
uint8_t data[8];
uint8_t dataSize;
};
namespace nCANSessionMux
{
void sendMessage_wrapper(uint32_t messageID, const uint8_t *data, uint8_t dataSize, int32_t periodMs, int32_t *status);
void receiveMessage_wrapper(uint32_t *messageID, uint32_t messageIDMask, uint8_t *data, uint8_t *dataSize, uint32_t *timeStamp, int32_t *status);
void openStreamSession(uint32_t *sessionHandle, uint32_t messageID, uint32_t messageIDMask, uint32_t maxMessages, int32_t *status);
void closeStreamSession(uint32_t sessionHandle);
void readStreamSession(uint32_t sessionHandle, struct tCANStreamMessage *messages, uint32_t messagesToRead, uint32_t *messagesRead, int32_t *status);
}
#ifdef __cplusplus
extern "C"
{
#endif
void FRC_NetworkCommunication_CANSessionMux_sendMessage(uint32_t messageID, const uint8_t *data, uint8_t dataSize, int32_t periodMs, int32_t *status);
void FRC_NetworkCommunication_CANSessionMux_receiveMessage(uint32_t *messageID, uint32_t messageIDMask, uint8_t *data, uint8_t *dataSize, uint32_t *timeStamp, int32_t *status);
void FRC_NetworkCommunication_CANSessionMux_openStreamSession(uint32_t *sessionHandle, uint32_t messageID, uint32_t messageIDMask, uint32_t maxMessages, int32_t *status);
void FRC_NetworkCommunication_CANSessionMux_closeStreamSession(uint32_t sessionHandle);
void FRC_NetworkCommunication_CANSessionMux_readStreamSession(uint32_t sessionHandle, struct tCANStreamMessage *messages, uint32_t messagesToRead, uint32_t *messagesRead, int32_t *status);
#ifdef __cplusplus
}
#endif
#endif // __CANSessionMux_h__

View File

@@ -1,56 +0,0 @@
// JaguarCANDriver.h
//
// Defines the API for building a CAN Interface Plugin to support
// PWM-cable-free CAN motor control on FRC robots. This allows you
// to connect any CAN interface to the secure Jaguar CAN driver.
//
#ifndef __JaguarCANDriver_h__
#define __JaguarCANDriver_h__
#if defined(__vxworks)
#include <vxWorks.h>
#else
#include <stdint.h>
#include <pthread.h>
#endif
#ifdef USE_THRIFT
#include "NetCommRPCComm.h"
#include <vector>
#endif
namespace nJaguarCANDriver
{
void sendMessage_wrapper(uint32_t messageID, const uint8_t *data, uint8_t dataSize, int32_t *status);
void receiveMessage_wrapper(uint32_t *messageID, uint8_t *data, uint8_t *dataSize, uint32_t timeoutMs, int32_t *status);
int32_t receiveMessageStart_wrapper(uint32_t messageID, uint32_t occurRefNum, uint32_t timeoutMs, int32_t *status);
#if defined (__vxworks)
int32_t receiveMessageStart_sem_wrapper(uint32_t messageID, uint32_t semaphoreID, uint32_t timeoutMs, int32_t *status);
#else
int32_t receiveMessageStart_mutex_wrapper(uint32_t messageID, pthread_mutex_t *mutex, uint32_t timeoutMs, int32_t *status);
#endif
void receiveMessageComplete_wrapper(uint32_t *messageID, uint8_t *data, uint8_t *dataSize, int32_t *status);
#ifdef USE_THRIFT
void checkEvent_CAN(std::vector< CANEvent >& events);
#endif
}
#ifdef __cplusplus
extern "C"
{
#endif
void FRC_NetworkCommunication_JaguarCANDriver_sendMessage(uint32_t messageID, const uint8_t *data, uint8_t dataSize, int32_t *status);
void FRC_NetworkCommunication_JaguarCANDriver_receiveMessage(uint32_t *messageID, uint8_t *data, uint8_t *dataSize, uint32_t timeoutMs, int32_t *status);
int32_t FRC_NetworkCommunication_JaguarCANDriver_receiveMessageStart(uint32_t messageID, uint32_t occurRefNum, uint32_t timeoutMs, int32_t *status);
#if defined (__vxworks)
int32_t FRC_NetworkCommunication_JaguarCANDriver_receiveMessageStart_sem(uint32_t messageID, uint32_t semaphoreID, uint32_t timeoutMs, int32_t *status);
#else
int32_t FRC_NetworkCommunication_JaguarCANDriver_receiveMessageStart_mutex(uint32_t messageID, pthread_mutex_t *mutex, uint32_t timeoutMs, int32_t *status);
#endif
void FRC_NetworkCommunication_JaguarCANDriver_receiveMessageComplete(uint32_t *messageID, uint8_t *data, uint8_t *dataSize, int32_t *status);
#ifdef __cplusplus
}
#endif
#endif // __JaguarCANDriver_h__

View File

@@ -22,20 +22,20 @@ void initializePCM() {
if(!pcmModulesInitialized) {
modules[0] = new PCM(50);
modules[1] = new PCM(51);
pcmModulesInitialized = true;
}
}
void* initializeSolenoidPort(void *port_pointer, int32_t *status) {
initializePCM();
Port* port = (Port*) port_pointer;
solenoid_port_t *solenoid_port = new solenoid_port_t;
solenoid_port->module = modules[port->module - 1];
solenoid_port->pin = port->pin;
return solenoid_port;
}
@@ -46,15 +46,14 @@ bool checkSolenoidModule(uint8_t module) {
bool getSolenoid(void* solenoid_port_pointer, int32_t *status) {
solenoid_port_t* port = (solenoid_port_t*) solenoid_port_pointer;
bool value;
*status = port->module->GetSolenoid(port->pin, value);
return value;
}
void setSolenoid(void* solenoid_port_pointer, bool value, int32_t *status) {
solenoid_port_t* port = (solenoid_port_t*) solenoid_port_pointer;
*status = port->module->SetSolenoid(port->pin, value);
}
port->module->SetSolenoid(port->pin, value);
}

View File

@@ -1,13 +1,21 @@
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#include "PCM.h"
#include "NetworkCommunication/JaguarCANDriver.h"
#include "NetworkCommunication/CANSessionMux.h"
#include <string.h> // memset
#include <unistd.h> // usleep
static const UINT32 kFullMessageIDMask = 0x1fffffff;
/* This can be a constant, as long as nobody needs to updatie solenoids within
1/50 of a second. */
static const INT32 kCANPeriod = 20;
/* PCM Constructor - Clears all vars, establishes default settings, starts PCM background process
*
*
* @Return - void
*
*
* @Param - deviceNumber - Device ID of PCM to be controlled
*/
PCM::PCM(UINT8 deviceNumber)
@@ -94,9 +102,9 @@ CTR_Code PCM::SetClosedLoopControl(bool en) {
}
/* Get solenoid state
*
*
* @Return - True/False - True if solenoid enabled, false otherwise
*
*
* @Param - idx - ID of solenoid (1-8) to return status of
*/
CTR_Code PCM::GetSolenoid(UINT8 idx, bool &status) {
@@ -108,7 +116,7 @@ CTR_Code PCM::GetSolenoid(UINT8 idx, bool &status) {
}
/* Get pressure switch state
*
*
* @Return - True/False - True if pressure adequate, false if low
*/
CTR_Code PCM::GetPressure(bool &status) {
@@ -119,7 +127,7 @@ CTR_Code PCM::GetPressure(bool &status) {
}
/* Get compressor state
*
*
* @Return - True/False - True if enabled, false if otherwise
*/
CTR_Code PCM::GetCompressor(bool &status) {
@@ -130,7 +138,7 @@ CTR_Code PCM::GetCompressor(bool &status) {
}
/* Get closed loop control state
*
*
* @Return - True/False - True if closed loop enabled, false if otherwise
*/
CTR_Code PCM::GetClosedLoopControl(bool &status) {
@@ -141,8 +149,8 @@ CTR_Code PCM::GetClosedLoopControl(bool &status) {
}
/* Get compressor current draw
*
* @Return - Amperes - Compressor current
*
* @Return - Amperes - Compressor current
*/
CTR_Code PCM::GetCompressorCurrent(float &status) {
uint16_t bt = _PcmStatus.compressorCurrentTop6;
@@ -155,7 +163,7 @@ CTR_Code PCM::GetCompressorCurrent(float &status) {
}
/* Get voltage across solenoid rail
*
*
* @Return - Volts - Voltage across solenoid rail
*/
CTR_Code PCM::GetSolenoidVoltage(float &status) {
@@ -169,7 +177,7 @@ CTR_Code PCM::GetSolenoidVoltage(float &status) {
}
/* Get hardware fault value
*
*
* @Return - True/False - True if hardware failure detected, false if otherwise
*/
CTR_Code PCM::GetHardwareFault(bool &status) {
@@ -180,7 +188,7 @@ CTR_Code PCM::GetHardwareFault(bool &status) {
}
/* Get compressor fault value
*
*
* @Return - True/False - True if shorted compressor detected, false if otherwise
*/
CTR_Code PCM::GetCompressorFault(bool &status) {
@@ -191,7 +199,7 @@ CTR_Code PCM::GetCompressorFault(bool &status) {
}
/* Get solenoid fault value
*
*
* @Return - True/False - True if shorted solenoid detected, false if otherwise
*/
CTR_Code PCM::GetSolenoidFault(bool &status) {
@@ -203,7 +211,7 @@ CTR_Code PCM::GetSolenoidFault(bool &status) {
// Past Faults
/* Get compressor sticky fault value
*
*
* @Return - True/False - True if solenoid had previously been shorted
* (and sticky fault was not cleared), false if otherwise
*/
@@ -215,7 +223,7 @@ CTR_Code PCM::GetCompressorStickyFault(bool &status) {
}
/* Get solenoid sticky fault value
*
*
* @Return - True/False - True if compressor had previously been shorted
* (and sticky fault was not cleared), false if otherwise
*/
@@ -226,7 +234,7 @@ CTR_Code PCM::GetSolenoidStickyFault(bool &status) { /* fix this */
return CTR_OKAY;
}
/* Get battery voltage
*
*
* @Return - Volts - Voltage across PCM power ports
*/
CTR_Code PCM::GetBatteryVoltage(float &status) {
@@ -236,9 +244,9 @@ CTR_Code PCM::GetBatteryVoltage(float &status) {
return CTR_OKAY;
}
/* Get number of total failed PCM Control Frame
*
*
* @Return - Failed Control Frames - Number of failed control frames (tokenization fails)
*
*
* @WARNING - Return only valid if [SeekDebugFrames] is enabled
* See function SeekDebugFrames
* See function EnableSeekDebugFrames
@@ -252,10 +260,10 @@ CTR_Code PCM::GetNumberOfFailedControlFrames(UINT16 &status) {
return CTR_OKAY;
}
/* Get raw Solenoid Blacklist
*
*
* @Return - BINARY - 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
@@ -268,11 +276,11 @@ CTR_Code PCM::GetSolenoidBlackList(UINT8 &status) {
}
/* Get solenoid Blacklist status
* - Blacklisted solenoids cannot be enabled until PCM is power cycled
*
*
* @Return - True/False - True if Solenoid is blacklisted, false if otherwise
*
*
* @Param - idx - ID of solenoid
*
*
* @WARNING - Return only valid if [SeekStatusFaultFrames] is enabled
* See function SeekStatusFaultFrames
* See function EnableSeekStatusFaultFrames
@@ -313,7 +321,8 @@ void PCM::ReadStatusFrame(void) {
PcmStatus_t frame = {0};
UINT8 size = 0;
INT32 status = 0;
FRC_NetworkCommunication_JaguarCANDriver_receiveMessage(&PCM_settings.statusFrameID, (uint8_t *)&frame, &size, 0 , &status);
UINT32 timeStamp = 0;
FRC_NetworkCommunication_CANSessionMux_receiveMessage(&PCM_settings.statusFrameID, kFullMessageIDMask, (uint8_t *)&frame, &size, &timeStamp, &status);
if (status == 0) {
_timeSinceLastRx = 0;
_PcmStatus = frame;
@@ -326,7 +335,8 @@ void PCM::ReadStatusFaultFrame(void) {
PcmStatusFault_t frame= {0};
UINT8 size = 0;
INT32 status = 0;
FRC_NetworkCommunication_JaguarCANDriver_receiveMessage(&PCM_settings.statusFaultFrameID, (uint8_t *)&frame, &size, 0, &status);
UINT32 timeStamp = 0;
FRC_NetworkCommunication_CANSessionMux_receiveMessage(&PCM_settings.statusFaultFrameID, kFullMessageIDMask, (uint8_t *)&frame, &size, &timeStamp, &status);
if (status == 0) {
_timeSinceLastRx = 0;
_PcmStatusFault = frame;
@@ -339,7 +349,8 @@ void PCM::ReadDebugFrame(void) {
PcmDebug_t frame= {0};
UINT8 size = 0;
INT32 status = 0;
FRC_NetworkCommunication_JaguarCANDriver_receiveMessage(&PCM_settings.debugFrameID, (uint8_t *)&frame, &size, 0, &status);
UINT32 timeStamp = 0;
FRC_NetworkCommunication_CANSessionMux_receiveMessage(&PCM_settings.debugFrameID, kFullMessageIDMask, (uint8_t *)&frame, &size, &timeStamp, &status);
if (status == 0) {
_timeSinceLastRx = 0;
_PcmDebug = frame;
@@ -351,7 +362,7 @@ void * PCM::ThreadFunc()
{
while(_threadIsRunning){
int32_t status = 0;
FRC_NetworkCommunication_JaguarCANDriver_sendMessage(PCM_settings.controlFrameID, (const uint8_t *)&_PcmControl, sizeof(_PcmControl), &status);
FRC_NetworkCommunication_CANSessionMux_sendMessage(PCM_settings.controlFrameID, (const uint8_t *)&_PcmControl, sizeof(_PcmControl), kCANPeriod, &status);
if(status == 0){
/* success */
_timeSinceLastTx = 0;
@@ -473,4 +484,3 @@ extern "C" {
return retval;
}
}

View File

@@ -1,7 +1,7 @@
#ifndef PCM_H_
#define PCM_H_
#include "ctre.h" //BIT Defines + Typedefs
#include <NetworkCommunication/JaguarCANDriver.h> //CAN Comm
#include <NetworkCommunication/CANSessionMux.h> //CAN Comm
#include <pthread.h>
/* encoder/decoders */
typedef struct _PcmStatus_t{
@@ -75,7 +75,7 @@ class PCM
public:
PCM(UINT8 deviceNumber=50);
~PCM();
/* Set PCM solenoid state
* @Return - CTR_Code - Error code (if any) for setting solenoid
* @Param - idx - ID of solenoid (1-8)
@@ -94,7 +94,7 @@ public:
* @Param - clr - Clear / do not clear faults
*/
CTR_Code ClearStickyFaults(bool clr);
/* Get solenoid state
*
* @Return - CTR_Code - Error code (if any)
@@ -172,7 +172,7 @@ public:
* @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
@@ -186,7 +186,7 @@ public:
* 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

View File

@@ -1,7 +1,10 @@
#include "PDP.h"
#include "NetworkCommunication/JaguarCANDriver.h"
#include "NetworkCommunication/CANSessionMux.h" //CAN Comm
#include <string.h> // memset
#include <unistd.h> // usleep
#define kFullMessageIDMask 0x1fffffff
PDP::PDP(UINT8 deviceNumber)
{
memset(&_status1, 0, sizeof(_status1));
@@ -107,7 +110,9 @@ uint64_t PDP::ReadCurrents(uint8_t api)
uint64_t frame = 0;
UINT8 size = 0;
INT32 status = 0;
FRC_NetworkCommunication_JaguarCANDriver_receiveMessage(&PDP_Settings.frameIDs[api], (uint8_t *)&frame, &size, 0 , &status);
UINT32 timeStamp = 0;
FRC_NetworkCommunication_CANSessionMux_receiveMessage(&PDP_Settings.frameIDs[api], kFullMessageIDMask, (uint8_t *)&frame, &size, &timeStamp, &status);
if (status == 0) {
_timeSinceLastRx = 0;
} else {

View File

@@ -1,7 +1,7 @@
#ifndef PDP_H_
#define PDP_H_
#include "ctre.h" //BIT Defines + Typedefs
#include <NetworkCommunication/JaguarCANDriver.h> //CAN Comm
#include <NetworkCommunication/CANSessionMux.h> //CAN Comm
#include <pthread.h>
/* encoder/decoders */
typedef struct _PdpStatus1_t{