Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
Revision 39:ddf38df9699e, committed 2015-02-11
- Comitter:
- pspatel321
- Date:
- Wed Feb 11 23:09:57 2015 +0000
- Parent:
- 38:8efacce315ae
- Commit message:
- Updated CAN IDs for datalogging. Changed profile encoding.
Changed in this revision
--- a/DataStructures/Headers/DefaultProfile.h Sat Feb 07 08:54:51 2015 +0000
+++ b/DataStructures/Headers/DefaultProfile.h Wed Feb 11 23:09:57 2015 +0000
@@ -27,9 +27,6 @@
CAN_RX_SIZE, // CAN rx size
SERIAL_BAUD, // Serial port baudrate
TX_SIZE, // Serial tx buffer size
- XBEE_BAUD, // Xbee baudrate
- XBEE_TX_SIZE, // Xbee tx buffer size
- XBEE_RX_SIZE, // Xbee rx buffer size
};
#endif
--- a/DataStructures/Headers/OperatingInfo.h Sat Feb 07 08:54:51 2015 +0000
+++ b/DataStructures/Headers/OperatingInfo.h Wed Feb 11 23:09:57 2015 +0000
@@ -7,8 +7,8 @@
enum OperatingMode {
// MODES
- FAULT=0,
- OKAY=1,
+ OKAY=1<<0,
+ FAULT=1<<1,
};
// Items here will prevent moving from STANDBY to IDLE
@@ -81,15 +81,7 @@
char imd;
char ams;
} latch;
-
- struct MsgCounter { // Telemetry tracking
- unsigned int msgIn;
- unsigned int msgOut;
- float rateOut;
- };
- struct MsgCounter xbee1;
- struct MsgCounter xbee2;
-
+
char switchState;
float internalTemp;
};
--- a/DataStructures/Headers/Profile.h Sat Feb 07 08:54:51 2015 +0000
+++ b/DataStructures/Headers/Profile.h Wed Feb 11 23:09:57 2015 +0000
@@ -61,16 +61,10 @@
unsigned int CANrxSize; // Size of CAN RX buffer
unsigned int SerialBaud; // Serial port baudrate
unsigned int SerialTxSize; // Serial TX buffer size
- unsigned int XbeeBaud; // Serial port baudrate
- unsigned int XbeeTxSize; // Serial TX buffer size
- unsigned int XbeeRxSize; // Serial TX buffer size
CHANGE_FUNC(CANtxSize, 1, 1000)
CHANGE_FUNC(CANrxSize, 1, 1000)
CHANGE_FUNC(SerialBaud, 9600, 921600)
CHANGE_FUNC(SerialTxSize, 1, 10000)
- CHANGE_FUNC(XbeeBaud, 9600, 921600)
- CHANGE_FUNC(XbeeTxSize, 1, 10000)
- CHANGE_FUNC(XbeeRxSize, 1, 10000)
// Load / store / fetch functions
static bool loadProfile(int index); // Load profile from flash into the current RAM object, 0=default, -1=freeze frame
--- a/IOobjects/CAN_RxIDs.h Sat Feb 07 08:54:51 2015 +0000 +++ b/IOobjects/CAN_RxIDs.h Wed Feb 11 23:09:57 2015 +0000 @@ -1,21 +1,20 @@ #ifndef CAN_RXIDS_H #define CAN_RXIDS_H -#define RX_ID_BASE 0x580 // Start at 0x500 for this device +#define RX_ID_BASE 0x580 // Start at 0x500 for this device // Receive Command IDs // NOTE after each command is parsed, a message will return back with the same ID of length 1 with data[0]=1 for success and data[0]=0 for fail -#define RESET_RX_ID RX_ID_BASE + 0x01 // Reset over CAN -#define RESETCLEAR_RX_ID RX_ID_BASE + 0x02 // Clear all errors and then reset, clean slate startup -#define CAPTURE_RX_ID RX_ID_BASE + 0x03 // Artificially capture freeze frame -#define CLEAR_RX_ID RX_ID_BASE + 0x04 // Clear a freeze frame error (0), clear every fault (1) -#define TIME_RX_ID RX_ID_BASE + 0x05 // Change the time (MM DD YY HH MM SS - 6 bytes) -#define PROFILE_RX_ID RX_ID_BASE + 0x06 // Byte[0] = load/write Byte[1] = profile # -#define SOC_RX_ID RX_ID_BASE + 0x07 // Change the current SOC to some float from 0 to 1 -#define AH_RX_ID RX_ID_BASE + 0x08 // Change the current ampHours to some float from 0 to capacity +#define RESET_RX_ID RX_ID_BASE + 0x00 // Reset over CAN +#define RESETCLEAR_RX_ID RX_ID_BASE + 0x01 // Clear all errors and then reset, clean slate startup +#define CLEAR_RX_ID RX_ID_BASE + 0x02 // Clear a freeze frame error (0), clear every fault (1) +#define TIME_RX_ID RX_ID_BASE + 0x03 // Change the time (MM DD YY HH MM SS - 6 bytes) +#define PROFILE_RX_ID RX_ID_BASE + 0x04 // Byte[0] = load/write Byte[1] = profile # -#define FAN_CONTROL_ID RX_ID_BASE + 0x10 -#define PUMP_CONTROL_ID RX_ID_BASE + 0x11 +#define FAN_CONTROL_RX_ID RX_ID_BASE + 0x10 +#define PUMP_CONTROL_RX_ID RX_ID_BASE + 0x11 +#define SOC_RX_ID RX_ID_BASE + 0x12 // Change the current SOC to some float from 0 to 1 +#define AH_RX_ID RX_ID_BASE + 0x13 // Change the current ampHours to some float from 0 to capacity // Profile Data Change Requests #define PROFILE_CHARGECURRENT_RX_ID RX_ID_BASE + 0x20 @@ -28,22 +27,20 @@ #define PROFILE_DCDCSTOPDELAY_RX_ID RX_ID_BASE + 0x27 #define PROFILE_DCDC_TAPS_RX_ID RX_ID_BASE + 0x28 #define PROFILE_IMDSTARTDELAY_RX_ID RX_ID_BASE + 0x29 -#define PROFILE_INTERNALOVERTEMP_RX_ID RX_ID_BASE + 0x2A -#define PROFILE_CANNOACK_RX_ID RX_ID_BASE + 0x2B -#define PROFILE_EXTENDSERIAL_RX_ID RX_ID_BASE + 0x2C -#define PROFILE_CANTXSIZE_RX_ID RX_ID_BASE + 0x2D -#define PROFILE_CANRXSIZE_RX_ID RX_ID_BASE + 0x2E -#define PROFILE_SERIALBAUD_RX_ID RX_ID_BASE + 0x2F -#define PROFILE_SERIALTXSIZE_RX_ID RX_ID_BASE + 0x30 -#define PROFILE_XBEEBAUD_RX_ID RX_ID_BASE + 0x31 -#define PROFILE_XBEETXSIZE_RX_ID RX_ID_BASE + 0x32 -#define PROFILE_XBEERXSIZE_RX_ID RX_ID_BASE + 0x33 +#define PROFILE_AMSSTARTDELAY_RX_ID RX_ID_BASE + 0x2A +#define PROFILE_INTERNALOVERTEMP_RX_ID RX_ID_BASE + 0x2B +#define PROFILE_CANNOACK_RX_ID RX_ID_BASE + 0x2C +#define PROFILE_EXTENDSERIAL_RX_ID RX_ID_BASE + 0x2D +#define PROFILE_CANTXSIZE_RX_ID RX_ID_BASE + 0x2E +#define PROFILE_CANRXSIZE_RX_ID RX_ID_BASE + 0x2F +#define PROFILE_SERIALBAUD_RX_ID RX_ID_BASE + 0x30 +#define PROFILE_SERIALTXSIZE_RX_ID RX_ID_BASE + 0x31 -#define RX_ID_END 0x5FF // End of SYS MGMT receive block +#define RX_ID_END 0x5FF // End of SYS MGMT receive block // Messages from other devices in the car -#define CHARGER_ERR_ID 0x700 // Is the charger connected? -#define AMS_MODE_ID 0x301 // Contains AIRs data -#define GLOBAL_CAR_RESET_RX_ID 0x602 // Reset button from steering wheel +#define CHARGER_ERR_RX_ID 0x700 // Is the charger connected? +#define AMS_MODE_RX_ID 0x301 // Contains AIRs data +#define GLOBAL_CAR_RESET_RX_ID 0x602 // Reset button from steering wheel -#endif \ No newline at end of file +#endif
--- a/IOobjects/CAN_TxIDs.h Sat Feb 07 08:54:51 2015 +0000 +++ b/IOobjects/CAN_TxIDs.h Wed Feb 11 23:09:57 2015 +0000 @@ -1,45 +1,39 @@ #ifndef CAN_TXIDS_H #define CAN_TXIDS_H -#define BASE_ID 0x500 // Start at 0x500 for this device +#define TX_ID_BASE 0x500 // Start at 0x500 for this device // Transmit IDs - System Mgmt Specific // Operating diagnostics -#define SYS_ERROR_ID BASE_ID + 0x00 // Error frame - critical errors that require shutdown -#define SYS_MODE_ID BASE_ID + 0x01 // Operating mode -#define SYS_FLAGS_ID BASE_ID + 0x02 // Signals -#define SYS_PROFILE_ID BASE_ID + 0x03 // Profile being used -#define SYS_TIME_ID BASE_ID + 0x04 // SysTime and startup time -#define SYS_XBEE1_MSG_ID BASE_ID + 0x05 // Message in/out counter for xbee1 -#define SYS_XBEE1_RATE_ID BASE_ID + 0x06 // Message in/out counter for xbee1 -#define SYS_XBEE2_MSG_ID BASE_ID + 0x07 // Message in/out counter for xbee2 -#define SYS_XBEE2_RATE_ID BASE_ID + 0x08 // Message in/out counter for xbee2 -#define SYS_TEMP_ID BASE_ID + 0x09 // Internal temperature of the glv battery chargerFET +#define FAULTCODE_TX_ID TX_ID_BASE + 0x00 // Error frame - critical errors that require shutdown +#define MODE_TX_ID TX_ID_BASE + 0x01 // Operating mode +#define SIGNALS_TX_ID TX_ID_BASE + 0x02 // Signals +#define PROFILE_TX_ID TX_ID_BASE + 0x03 // Profile being used +#define TIME_TX_ID TX_ID_BASE + 0x04 // SysTime and startup time // GLV Battery -#define SYS_GLV_CURRENT_ID BASE_ID + 0x10 // GLV battery current -#define SYS_GLV_CAPACITY_ID BASE_ID + 0x11 // GLV battery capacity setting -#define SYS_GLV_AH_ID BASE_ID + 0x12 // GLV battery amphours -#define SYS_GLV_SOC_ID BASE_ID + 0x13 // GLV battery SOC -#define SYS_GLV_ERROR_ID BASE_ID + 0x14 // GLV battery error byte +#define TEMP_TX_ID TX_ID_BASE + 0x10 // Internal temperature of the glv battery chargerFET +#define GLV_CURRENT_TX_ID TX_ID_BASE + 0x11 // GLV battery current +#define GLV_CAPACITY_TX_ID TX_ID_BASE + 0x12 // GLV battery capacity setting +#define GLV_AH_TX_ID TX_ID_BASE + 0x13 // GLV battery amphours +#define GLV_SOC_TX_ID TX_ID_BASE + 0x14 // GLV battery SOC +#define GLV_ERROR_TX_ID TX_ID_BASE + 0x15 // GLV battery error byte // DC-DC Converter -#define SYS_DCDC_CURRENT_ID BASE_ID + 0x20 // DC-DC current -#define SYS_DCDC_STATUS_ID BASE_ID + 0x21 // DC-DC status byte - -// PWM Channels -#define SYS_PWM_FAN_ID BASE_ID + 0x30 // FAN1 actual pwm -#define SYS_PWM_PUMP_ID BASE_ID + 0x31 // PUMP1 actual pwm +#define DCDC_CURRENT_TX_ID TX_ID_BASE + 0x20 // DC-DC current +#define DCDC_STATUS_TX_ID TX_ID_BASE + 0x21 // DC-DC status byte +#define PWM_FAN_TX_ID TX_ID_BASE + 0x22 // FAN1 actual pwm +#define PWM_PUMP_TX_ID TX_ID_BASE + 0x23 // PUMP1 actual pwm // IMD -#define SYS_IMD_STATUS_ID BASE_ID + 0x40 // IMD status byte -#define SYS_IMD_RESIST_ID BASE_ID + 0x41 // IMD resistance measurement +#define IMD_STATUS_TX_ID TX_ID_BASE + 0x30 // IMD status byte +#define IMD_RESIST_TX_ID TX_ID_BASE + 0x31 // IMD resistance measurement // Latch Supervisor states -#define SYS_IMD_LATCH_ID BASE_ID + 0x50 // IMD Latch circuit error byte -#define SYS_AMS_LATCH_ID BASE_ID + 0x51 // AMS Latch circuit error byte +#define IMD_LATCH_TX_ID TX_ID_BASE + 0x40 // IMD Latch circuit error byte +#define AMS_LATCH_TX_ID TX_ID_BASE + 0x41 // AMS Latch circuit error byte // Shutdown Switches -#define SYS_SWITCHES_ID BASE_ID + 0x60 // Shutdown Switch State +#define SWITCHES_TX_ID TX_ID_BASE + 0x50 // Shutdown Switch State -#endif \ No newline at end of file +#endif
--- a/IOobjects/IOobjects.cpp Sat Feb 07 08:54:51 2015 +0000
+++ b/IOobjects/IOobjects.cpp Wed Feb 11 23:09:57 2015 +0000
@@ -21,9 +21,9 @@
IMD imd(P1_26); // IMD PWM sense channel to read status and resistance (IMD PWM PIN)
LatchMonitor AMSlatch(P0_18, P0_22); // Supervisor for AMS hardware latch/reset circuit (OK PIN, FAULT PIN, STARTUP DELAY (ms))
LatchMonitor IMDlatch(P0_17, P0_21); // Supervisor for IMD hardware latch/reset circuit (OK PIN, FAULT PIN, STARTUP DELAY (ms))
-MODSERIAL pc(USBTX, USBRX, 1, RX_SIZE); // Serial to computer for diagnostics, 3kB output buffer, 256 byte input buffer
DC_DC dcdc(p18, p20, p26, p25, p24, p23, 0.01, 5, 1);// DC-DC converter & high-current load control (CONTROL PIN, CURRENT SENSE PIN, FAN1 PIN, FAN2 PIN, PUMP1 PIN, PUMP2 PIN, PWM PERIOD (sec), FULL-SCALE SLEW (sec))
Temperature internalTmp(&NXFT15XH103_TABLE, p15); // Temperature conversion look-up table for internal temperature on the GLV bat charger FET (TABLE PTR, PIN)
-XbeeManager xbeeRelay(p9, p10, p13, p14, XBEE_BAUD, 1, 1);
-//XbeeRelay xbee;
+//XbeeManager xbeeRelay(p9, p10, p13, p14, XBEE_BAUD, 1, 1);
+MODSERIAL pc(USBTX, USBRX, 1, RX_SIZE); // Software buffered serial
+XbeeRelay xbee;
DigitalOut extras[] = {(p16), (p17)}; // Unused analog pins driven low
--- a/IOobjects/IOobjects.h Sat Feb 07 08:54:51 2015 +0000 +++ b/IOobjects/IOobjects.h Wed Feb 11 23:09:57 2015 +0000 @@ -15,9 +15,9 @@ #include "PollSwitch.h" #include "Temperature.h" #include "Watchdog.h" -#include "XbeeManager.h" +//#include "XbeeManager.h" #include "DataStructures.h" -//#include "XbeeRelay.h" +#include "XbeeRelay.h" extern CANBuffer can; extern CoulombCounter glvBat; @@ -29,7 +29,7 @@ extern PollSwitch switches; extern Temperature internalTmp; extern Watchdog wdt; -//extern XbeeRelay xbee; -extern XbeeManager xbeeRelay; +extern XbeeRelay xbee; +//extern XbeeManager xbeeRelay; #endif
--- a/Libs/IMD/IMD.h Sat Feb 07 08:54:51 2015 +0000
+++ b/Libs/IMD/IMD.h Wed Feb 11 23:09:57 2015 +0000
@@ -6,13 +6,13 @@
#include "mbed.h"
enum IMDstatus {
- OFF = 0,
- NORMAL = 1,
- UNDERVOLT = 2,
- SPEEDSTART = 3,
- ERROR = 4,
- GROUNDERR = 5,
- INVALID = 6,
+ OFF = 1<<0,
+ NORMAL = 1<<1,
+ UNDERVOLT = 1<<2,
+ SPEEDSTART = 1<<3,
+ ERROR = 1<<4,
+ GROUNDERR = 1<<5,
+ INVALID = 1<<6,
};
class IMD{
--- a/Libs/LatchMonitor/LatchMonitor.cpp Sat Feb 07 08:54:51 2015 +0000
+++ b/Libs/LatchMonitor/LatchMonitor.cpp Wed Feb 11 23:09:57 2015 +0000
@@ -3,17 +3,16 @@
LatchMonitor::LatchMonitor(PinName _ok, PinName _fault) : okPin(_ok, PullDown), faultPin(_fault, PullDown)
{
started = false;
- lastStat = 0;
startDelay = 0;
}
+
void LatchMonitor::setup(float* _startDelay)
{
startDelay = _startDelay;
}
+
void LatchMonitor::delayStart()
{
- lastStat = 0;
- update();
if (startDelay == 0) return; // Not setup yet
// Power-on reset detected
@@ -39,9 +38,8 @@
if (started) {
ret |= !okPin << 2; // Mirror the ok pin when started only
if (!okPin && !faultPin) { // If started && okFault but not caught in hardware
- ret |= HARD_FAULT;
+ //ret |= HARD_FAULT;
}
}
- lastStat = ret;
return ret;
}
--- a/Libs/LatchMonitor/LatchMonitor.h Sat Feb 07 08:54:51 2015 +0000
+++ b/Libs/LatchMonitor/LatchMonitor.h Wed Feb 11 23:09:57 2015 +0000
@@ -21,7 +21,6 @@
char update();
private:
- char lastStat;
float* startDelay;
Timeout startup;
void startupDelay();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Libs/xbeeRelay.lib Wed Feb 11 23:09:57 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/Penn-Electric-Racing/code/xbeeRelay/#d98bea800a7b
--- a/Libs/xbeeRelay/PERMessage.cpp Sat Feb 07 08:54:51 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-#include "PERMessage.h"
-
-PERMessage::PERMessage() {
-
-}
-
-PERMessage::PERMessage(char contentID, char deviceID, bool rtr, char length, unsigned char* data) {
- dataArray[0] = contentID;
- dataArray[1] = ((deviceID & 0x7) << 5) | (rtr << 4) | (length & 0xF);
- for (int i = 0; i < (length & 0xF); i++) {
- dataArray[i+2] = data[i];
- }
-}
-
-char PERMessage::getContentID() {
- return dataArray[0];
-}
-
-char PERMessage::getDeviceID() {
- return (dataArray[1] >> 5) & 0x7;
-}
-
-bool PERMessage::getRTR() {
- return dataArray[1] & 0x1F;
-}
-
-char PERMessage::getLength() {
- return dataArray[1] & 0xF;
-}
-
-void PERMessage::getDataArray(char* buffer) {
- for (int i = 0; i < getLength() + 2; i++) {
- buffer[i] = dataArray[i];
- }
-}
-bool PERMessage::setContentID(char contentID) {
- dataArray[0] = contentID;
- return true;
-}
-
-bool PERMessage::setDeviceID(char deviceID) {
- dataArray[1] = dataArray[1] | (deviceID & 0x7) << 5;
- return true;
-}
-
-bool PERMessage::setRTR(bool RTR) {
- dataArray[1] = dataArray[1] | RTR << 4;
- return true;
-}
-
-bool PERMessage::setLength(char length) {
- dataArray[1] = dataArray[1] | length & 0xF;
- return true;
-}
--- a/Libs/xbeeRelay/PERMessage.h Sat Feb 07 08:54:51 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,26 +0,0 @@
-#ifndef PERMESSAGE
-#define PERMESSAGE
-
-class PERMessage {
-
-public:
- PERMessage ();
- PERMessage (char /* content */, char /* device ID */, bool /* rtr */, char /* length */, unsigned char* /* data[] */);
- char getContentID();
- char getDeviceID();
- bool getRTR();
- char getLength();
- void getDataArray(char* /*buffer*/);
-
-
- bool setContentID(char /*contentID*/);
- bool setDeviceID(char /*deviceID*/);
- bool setRTR(bool /*RTR*/);
- bool setLength(char /* Length*/);
-
-
-private:
- char dataArray[10];
-};
-
-#endif
\ No newline at end of file
--- a/Libs/xbeeRelay/XbeeRelay.cpp Sat Feb 07 08:54:51 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-#include "XbeeRelay.h"
-#include "mbed.h"
-//#include "MODDMA.h"
-//#include "MODSERIAL.h"
-#include "PERMessage.h"
-
-#define MOTORCONID 0x181
-#define PCMIDLOW 0x200
-#define PCMIDHIGH 0x2FF
-
-#define MOTORCONSERIALID 0x3
-#define PCMSERIALID 0x2
-
-#define DMA_CHANNEL_XBEE_1 0
-#define DMA_CHANNEL_XBEE_2 1
-
-XbeeRelay::XbeeRelay() : Xbee_e1(p9,p10), Xbee_e2(p13,p14), counter(0) {
- Xbee_e1.baud(250000);
- Xbee_e2.baud(250000);
- // Xbee_e1.MODDMA(&dma);
- //Xbee_e2.MODDMA(&dma);
-}
-
-bool XbeeRelay::receive(CANMessage cm) {
- this->cm = cm;
-
- XbeeRelay::parse();
- return true;//XbeeRelay::send();
-}
-
-void XbeeRelay::parseMotorCon () {
- unsigned char *dataPtr = cm.data;
- PERMessage pm(*dataPtr, MOTORCONSERIALID, false, cm.len - 1, (dataPtr+1));
- this->pm = pm;
-}
-
-void XbeeRelay::parseNormal () {
- unsigned char *dataPtr = cm.data;
- PERMessage pm(cm.id & 0xFF, (cm.id & 0x700) >> 8, false, cm.len, dataPtr);
- this->pm = pm;
-}
-
-void XbeeRelay::parse () {
- if (cm.id == MOTORCONID) {
- parseMotorCon();
- } else {
- parseNormal();
- }
-}
-
-bool XbeeRelay::send () {
- char dataarr[pm.getLength() + 2];
- pm.getDataArray(dataarr);
-
- /* if (!dma.Enabled(DMA_CHANNEL_XBEE_1)) {
- // Xbee_e1.dmaSend(dataarr, sizeof(dataarr), DMA_CHANNEL_XBEE_1);
- return true;
- } else if (!dma.Enabled(DMA_CHANNEL_XBEE_2)) {
- // Xbee_e2.dmaSend(dataarr, sizeof(dataarr), DMA_CHANNEL_XBEE_2);
- return true;
- }
- */
- return false;
-}
\ No newline at end of file
--- a/Libs/xbeeRelay/XbeeRelay.h Sat Feb 07 08:54:51 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,33 +0,0 @@
-#ifndef XBEERELAY
-
-#define XBEERELAY
-
-#include "mbed.h"
-//#include "MODDMA.h"
-#include "MODSERIAL.h"
-#include "PERMessage.h"
-
-
-class XbeeRelay {
-
-public:
- XbeeRelay ();
- // returns TRUE on successful send, FALSE otherwise
- bool receive(CANMessage /* cm */);
-
-
-private:
- void parse(void /* cm */);
- void parseMotorCon(void);
- void parseNormal(void /* deviceID */);
- bool send(void /*pm*/);
- char dataLength (char /*contentID*/);
- MODSERIAL Xbee_e1;
- MODSERIAL Xbee_e2;
- unsigned int counter;
- //MODDMA dma;
- CANMessage cm;
- PERMessage pm;
-};
-
-#endif
\ No newline at end of file
--- a/inCommands/inCommands.cpp Sat Feb 07 08:54:51 2015 +0000
+++ b/inCommands/inCommands.cpp Wed Feb 11 23:09:57 2015 +0000
@@ -177,9 +177,6 @@
CHANGE_VAR("CANrxSize", CANrxSize)
CHANGE_VAR("SerialBaud", SerialBaud)
CHANGE_VAR("SerialTx", SerialTxSize)
- CHANGE_VAR("XbeeBaud", XbeeBaud)
- CHANGE_VAR("XbeeTxSize", XbeeTxSize)
- CHANGE_VAR("XbeeRxSize", XbeeRxSize)
CHANGE_VAR("CANack", CANnoAck)
if (!parsed) return -1;
@@ -191,9 +188,6 @@
CMP(1, "CANrxSize") return can.rxSize(param->CANrxSize)?1:-1;
CMP(1, "SerialBaud") pc.baud(param->SerialBaud);
CMP(1, "SerialTx") return (pc.txBufferSetSize(param->SerialTxSize) == 0)?1:-1;
- CMP(1, "XbeeBaud") xbeeRelay.baud(param->XbeeBaud);
- CMP(1, "XbeeTxSize") return (xbeeRelay.txSize(param->XbeeTxSize))?1:-1;
- CMP(1, "XbeeRxSize") return (xbeeRelay.rxSize(param->XbeeRxSize))?1:-1;
return 1;
}
@@ -357,6 +351,8 @@
} else {
if (!can.rxRead(msg)) return false;
}
+ xbee.receive(msg);
+
// Redirect global car reset
if (msg.id == GLOBAL_CAR_RESET_RX_ID) msg.id = RESETCLEAR_RX_ID;
@@ -369,8 +365,8 @@
}
CAN_FAIL
-
- // Clear non-volatile fault flags, then reset microcontroller
+
+ // Clear non-volatile fault flags, then reset microcontroller
case (RESETCLEAR_RX_ID):
if (msg.len == 0) { // Length must = 0
FreezeFrame::clearError();
@@ -378,30 +374,13 @@
CAN_SUCCESS
}
CAN_FAIL
-
- // Artificially capture a freeze frame
- case (CAPTURE_RX_ID):
- if (msg.len == 0) { // Length must = 0
- if (!FreezeFrame::getError()) { // Only allow capture if freeze frame from the last error was read
- if (FreezeFrame::writeFrame()) { // Capture the RAM contents to flash
- CAN_SUCCESS
- }
- }
- }
- CAN_FAIL
-
- // Clear fault conditions
+
+ // Clear fault conditions
case (CLEAR_RX_ID):
- if (msg.len == 1) { // One data byte
- if (msg.data[0] == 0) { // Clear only freeze frame error if = 0
- FreezeFrame::clearError(); // Clear non-volatile freeze frame marker
- CAN_SUCCESS
- }
- if (msg.data[0] == 1) { // Clear everything if = 1
- runTime::clearFaults();
- op->faultCode = 0;
- CAN_SUCCESS
- }
+ if (msg.len == 0) { // No data byte
+ runTime::clearFaults();
+ op->faultCode = 0;
+ CAN_SUCCESS
}
CAN_FAIL
@@ -427,9 +406,15 @@
// RAM and flash profile manipulations
case (PROFILE_RX_ID):
if (msg.len == 2*sizeof(char)) { // 2 command bytes
+ int index=-2;
+ for (int i = 0; i < NUM_STORED_PROFILES+1; i++) { // Get the profile number
+ if (msg.data[1] == (1<<i)) index=i;
+ }
+ if (msg.data[1] == 1<<6) index=-1; // Special case for Freeze
+ if (index == -2) { // Not matched to anything, fail
+ CAN_FAIL
+ }
if (msg.data[0] == 0) { // Load profile from a flash location to RAM
- int index = msg.data[1]; // Second byte contains profile index
- if (msg.data[1] == 0xff) index = -1; // If freeze (special case)
if (Profile::loadProfile(index)) { // Attempt to load (copy flash to RAM)
op->profileIndex = Profile::usingProfile(); // Change the currently loaded profile marker
op->profileModded = false; // Mark it as a fresh, unmodified profile
@@ -437,8 +422,6 @@
}
}
if (msg.data[0] == 1) { // Write profile to flash from RAM
- int index = msg.data[1]; // Get which slot to write to from message
- if (msg.data[1] == 0xff) index = -1; // If freeze (special case)
bool s = Profile::saveProfile(index); // Write profile to flash slot
if (s) {
op->profileIndex = Profile::usingProfile(); // Change the currently loaded profile marker
@@ -449,30 +432,30 @@
}
CAN_FAIL
- case FAN_CONTROL_ID:
+ case FAN_CONTROL_RX_ID:
if (msg.len != 2*sizeof(float)) return false;
REFRESH_TIMEOUT(FANS)
op->dcdc.request.fan1 = *((float*)((void*)(&msg.data[0])));
op->dcdc.request.fan2 = *((float*)((void*)(&msg.data[4])));
return true;
- case PUMP_CONTROL_ID:
+ case PUMP_CONTROL_RX_ID:
if (msg.len != 2*sizeof(float)) return false;
REFRESH_TIMEOUT(PUMPS)
op->dcdc.request.pump1 = *((float*)((void*)(&msg.data[0])));
op->dcdc.request.pump2 = *((float*)((void*)(&msg.data[4])));
return true;
- case AMS_MODE_ID:
+ case AMS_MODE_RX_ID:
if (msg.len != sizeof(char)) return false;
REFRESH_TIMEOUT(AIRS_CLOSED)
- if (msg.data[0] & 1<<2) { // AIRs closed?
+ if (msg.data[0] & 1<<3) { // AIRs closed?
op->signals |= AIRS_CLOSED;
} else {
op->signals &= ~AIRS_CLOSED;
}
return true;
- case CHARGER_ERR_ID:
+ case CHARGER_ERR_RX_ID:
REFRESH_TIMEOUT(CHARGER_DET)
op->signals |= CHARGER_DET;
return true;
@@ -491,6 +474,7 @@
CAN_CHANGE(dcdcStopDelay, PROFILE_DCDCSTOPDELAY_RX_ID )
CAN_CHANGE(dcdc_taps, PROFILE_DCDC_TAPS_RX_ID )
CAN_CHANGE(imdStartDelay, PROFILE_IMDSTARTDELAY_RX_ID )
+ CAN_CHANGE(amsStartDelay, PROFILE_AMSSTARTDELAY_RX_ID )
CAN_CHANGE(internalOverTemp, PROFILE_INTERNALOVERTEMP_RX_ID )
CAN_CHANGE(CANnoAck, PROFILE_CANNOACK_RX_ID )
CAN_CHANGE(extendedSerial, PROFILE_EXTENDSERIAL_RX_ID )
@@ -498,9 +482,6 @@
CAN_CHANGE(CANrxSize, PROFILE_CANRXSIZE_RX_ID )
CAN_CHANGE(SerialBaud, PROFILE_SERIALBAUD_RX_ID )
CAN_CHANGE(SerialTxSize, PROFILE_SERIALTXSIZE_RX_ID )
- CAN_CHANGE(XbeeBaud, PROFILE_XBEEBAUD_RX_ID )
- CAN_CHANGE(XbeeTxSize, PROFILE_XBEETXSIZE_RX_ID )
- CAN_CHANGE(XbeeRxSize, PROFILE_XBEERXSIZE_RX_ID )
if (!parsed) return false;
@@ -511,13 +492,11 @@
if (msg.id == PROFILE_CANRXSIZE_RX_ID ) return can.rxSize(param->CANrxSize)?1:-1;
if (msg.id == PROFILE_SERIALBAUD_RX_ID ) pc.baud(param->SerialBaud);
if (msg.id == PROFILE_SERIALTXSIZE_RX_ID ) return (pc.txBufferSetSize(param->SerialTxSize) == 0)?1:-1;
- if (msg.id == PROFILE_XBEEBAUD_RX_ID ) xbeeRelay.baud(param->XbeeBaud);
- if (msg.id == PROFILE_XBEETXSIZE_RX_ID ) return (xbeeRelay.txSize(param->XbeeTxSize))?1:-1;
- if (msg.id == PROFILE_XBEERXSIZE_RX_ID ) return (xbeeRelay.rxSize(param->XbeeRxSize))?1:-1;
return true;
}
// Check for incoming messages from the xbees, relay them to the CAN function and send them out on the bus
+/*
bool receiveMsgXbee()
{
CANMessage msg;
@@ -526,14 +505,13 @@
serviceCAN(&msg); // Send it into the local serviceCAN routine
return true;
} else return false;
-}
-
+}*/
void inCommands::thread_getInputs(void const* args)
{
while(1) {
serviceCAN(0);
- receiveMsgXbee();
+ //receiveMsgXbee();
int ret = serviceSerial();
if (ret == -1) tempData.parseGoodChar = 'x';
--- a/main.cpp Sat Feb 07 08:54:51 2015 +0000
+++ b/main.cpp Wed Feb 11 23:09:57 2015 +0000
@@ -8,8 +8,8 @@
tempData.wdtThreadId = Thread::gettid();
wdt.kick(WDT_TIME);
while(1) {
- Thread::wait(100);
- //Thread::signal_wait(0x1F);
+ //Thread::wait(100);
+ Thread::signal_wait(0x1F);
wdt.kick();
}
}
@@ -64,9 +64,9 @@
can.rxSize(param->CANrxSize);
pc.baud(param->SerialBaud);
pc.txBufferSetSize(param->SerialTxSize);
- xbeeRelay.baud(param->XbeeBaud);
- xbeeRelay.txSize(param->XbeeTxSize);
- xbeeRelay.rxSize(param->XbeeRxSize);
+ //xbeeRelay.baud(param->XbeeBaud);
+ //xbeeRelay.txSize(param->XbeeTxSize);
+ //xbeeRelay.rxSize(param->XbeeRxSize);
// INITIAL SETUP, LINK PROFILE VARIABLES
glvBat.changeCapacity(param->nominalCapacity);
--- a/outDiagnostics/outDiagnostics.cpp Sat Feb 07 08:54:51 2015 +0000
+++ b/outDiagnostics/outDiagnostics.cpp Wed Feb 11 23:09:57 2015 +0000
@@ -122,9 +122,6 @@
ADD_SPRINTF_LINE
snprintf(temp, max_charsPerLine, "CANtxSize: %4d %sCANrxSize: %4d %sSerialBaud: %6d%sSerialTx: %5d", dashParam->CANtxSize,barSpace, dashParam->CANrxSize,barSpace, dashParam->SerialBaud,barSpace, dashParam->SerialTxSize);
ADD_SPRINTF_LINE
- snprintf(temp, max_charsPerLine, "XbeeBaud: %6d %sXbeeTxSize: %4d%sXbeeRxSize: %4d %s CANack: %5s", dashParam->XbeeBaud, barSpace, dashParam->XbeeTxSize,barSpace, dashParam->XbeeRxSize,barSpace, dashParam->CANnoAck?"NOACK":"ACK");
- ADD_SPRINTF_LINE
-
BLANK_LINE
}
snprintf(temp, max_charsPerLine, " Operating Info %s", freeze?"(Viewing Freeze of Last Fault) ":"");
@@ -257,8 +254,15 @@
BLANK_LINE
snprintf(temp, max_charsPerLine, " IMD %s", freeze?"(Viewing Freeze of Last Fault) ":"");
TITLE(temp)
- const char IMDstr[7][12] = {"OFF","NORMAL","UNDERVOLT","SPEEDSTART","ERROR","GROUNDFLT","INVALID"};
- sprintf(temp, "Status: %10s Resistance: %7.0fKohm Error: %3s", IMDstr[dashOp->imd.status], dashOp->imd.resistance/1.0e3, dashOp->imd.error?"ERR":"OK");
+ char imdStatN=6;
+ if (dashOp->imd.status & OFF) imdStatN=0;
+ if (dashOp->imd.status & NORMAL) imdStatN=1;
+ if (dashOp->imd.status & UNDERVOLT) imdStatN=2;
+ if (dashOp->imd.status & SPEEDSTART) imdStatN=3;
+ if (dashOp->imd.status & ERROR) imdStatN=4;
+ if (dashOp->imd.status & GROUNDERR) imdStatN=5;
+ const char IMDstr[7][12] = {"OFF","NORMAL","UNDERVOLT","SPEEDSTART","ERROR","GROUNDERR","INVALID"};
+ sprintf(temp, "Status: %10s Resistance: %7.0fKohm Error: %3s", IMDstr[imdStatN], dashOp->imd.resistance/1.0e3, dashOp->imd.error?"ERR":"OK");
ADD_SPRINTF_LINE
BLANK_LINE
@@ -280,14 +284,6 @@
else sprintf(temp, "%s is OPEN.", switchNames[switches-1]);
ADD_SPRINTF_LINE
- BLANK_LINE
- snprintf(temp, max_charsPerLine, " Telemetry %s", freeze?"(Viewing Freeze of Last Fault) ":"");
- TITLE(temp)
- sprintf(temp, "Channel 1 - MsgIn: %5d MsgOut: %5d %5.2f", dashOp->xbee1.msgIn, dashOp->xbee1.msgOut, dashOp->xbee1.rateOut);
- ADD_SPRINTF_LINE
- sprintf(temp, "Channel 2 - MsgIn: %5d MsgOut: %5d %5.2f", dashOp->xbee2.msgIn, dashOp->xbee2.msgOut, dashOp->xbee2.rateOut);
- ADD_SPRINTF_LINE
-
// Erase screen every few counts to remove glitches
static int count = 0;
if (count % 50 == 0 || lastModeExtended != inExtendedMode) {
@@ -334,56 +330,53 @@
// OPERATING DIAGNOSTICS
// Error Frame
- CAN_SINGLE(faultCode, SYS_ERROR_ID)
+ CAN_SINGLE(faultCode, FAULTCODE_TX_ID)
// Mode
- CAN_SINGLE(mode, SYS_MODE_ID)
+ CAN_SINGLE(mode, MODE_TX_ID)
// Flags
- CAN_SINGLE(signals, SYS_FLAGS_ID)
+ CAN_SINGLE(signals, SIGNALS_TX_ID)
// Profile
- char byte = (op->profileIndex != -1) ? op->profileIndex : 1<<6; // Mark the second to last bit of the byte if using Freeze profile (data[0]=64 for freeze, data[0]=0 for default)
- byte |= (op->profileModded) ? 1<<7 : 0; // Mark the last bit of the byte if the profile was modified (OR'd with profile id from above)
- SEND_CAN_SINGLE(byte, SYS_PROFILE_ID);
+ char byte=0;
+ byte = (op->profileIndex != -1)? 1 << op->profileIndex : 1<<6;
+ byte |= (op->profileModded) ? 1<<7 : 0; // Mark the last bit of the byte if the profile was modified (OR'd with profile id from above)
+ SEND_CAN_SINGLE(byte, PROFILE_TX_ID);
// Time
- CAN_PAIR(SysTime, startTime, SYS_TIME_ID)
-
- // Xbee1 Counter
- CAN_PAIR(xbee1.msgIn, xbee1.msgOut, SYS_XBEE1_MSG_ID)
-
- // Xbee2 Counter
- CAN_PAIR(xbee2.msgIn, xbee2.msgOut, SYS_XBEE2_MSG_ID)
+ CAN_PAIR(SysTime, startTime, TIME_TX_ID)
// Internal temperature
- CAN_SINGLE(internalTemp, SYS_TEMP_ID)
+ CAN_SINGLE(internalTemp, TEMP_TX_ID)
// GLV Battery
- CAN_SINGLE(glvBat.current, SYS_GLV_CURRENT_ID)
- CAN_SINGLE(glvBat.capacity, SYS_GLV_CAPACITY_ID)
- CAN_SINGLE(glvBat.Ah, SYS_GLV_AH_ID)
- CAN_SINGLE(glvBat.SOC, SYS_GLV_SOC_ID)
- CAN_SINGLE(glvBat.error, SYS_GLV_ERROR_ID)
+ CAN_SINGLE(glvBat.current, GLV_CURRENT_TX_ID)
+ CAN_SINGLE(glvBat.capacity, GLV_CAPACITY_TX_ID)
+ CAN_SINGLE(glvBat.Ah, GLV_AH_TX_ID)
+ CAN_SINGLE(glvBat.SOC, GLV_SOC_TX_ID)
+ CAN_SINGLE(glvBat.error, GLV_ERROR_TX_ID)
// DC-DC Converter
- CAN_SINGLE(dcdc.current, SYS_DCDC_CURRENT_ID)
- CAN_SINGLE(dcdc.status, SYS_DCDC_STATUS_ID)
+ CAN_SINGLE(dcdc.current, DCDC_CURRENT_TX_ID)
+ CAN_SINGLE(dcdc.status, DCDC_STATUS_TX_ID)
// PWM Channels
- CAN_PAIR(dcdc.actual.fan1, dcdc.actual.fan2, SYS_PWM_FAN_ID)
- CAN_PAIR(dcdc.actual.pump1, dcdc.actual.pump2, SYS_PWM_PUMP_ID)
+ CAN_PAIR(dcdc.actual.fan1, dcdc.actual.fan2, PWM_FAN_TX_ID)
+ CAN_PAIR(dcdc.actual.pump1, dcdc.actual.pump2, PWM_PUMP_TX_ID)
// IMD
- CAN_SINGLE(imd.status, SYS_IMD_STATUS_ID)
- CAN_SINGLE(imd.resistance, SYS_IMD_RESIST_ID)
+ CAN_SINGLE(imd.status, IMD_STATUS_TX_ID)
+ CAN_SINGLE(imd.resistance, IMD_RESIST_TX_ID)
// Latches
- CAN_SINGLE(latch.imd, SYS_IMD_LATCH_ID)
- CAN_SINGLE(latch.ams, SYS_AMS_LATCH_ID)
+ CAN_SINGLE(latch.imd, IMD_LATCH_TX_ID)
+ CAN_SINGLE(latch.ams, AMS_LATCH_TX_ID)
// Shutdown Switches
- CAN_SINGLE(switchState, SYS_SWITCHES_ID)
+ uint16_t tmp=0;
+ if (op->switchState != 0) tmp |= 1 << (op->switchState-1);
+ SEND_CAN_SINGLE(tmp, SWITCHES_TX_ID);
osSignalSet((osThreadId)(tempData.wdtThreadId), 1<<4); // Signal watchdog thread
Thread::wait(CAN_LOOP*1000);
--- a/runTime/runTime.cpp Sat Feb 07 08:54:51 2015 +0000
+++ b/runTime/runTime.cpp Wed Feb 11 23:09:57 2015 +0000
@@ -44,16 +44,16 @@
op->internalTemp = internalTmp.read();
// Telemetry trackers
- op->xbee1.msgIn = xbeeRelay.counterX1in;
- op->xbee1.msgOut = xbeeRelay.counterX1out;
- op->xbee1.msgIn = xbeeRelay.counterX2in;
- op->xbee2.msgOut = xbeeRelay.counterX2out;
- if (counter++ % 10 == 0) { // Do every 1 second
- op->xbee1.rateOut = xbeeRelay.bytesX1out / 1000.0; // Measure data rate in KB/s
- op->xbee2.rateOut = xbeeRelay.bytesX2out / 1000.0;
- xbeeRelay.bytesX1out = 0; // Clear every second
- xbeeRelay.bytesX2out = 0;
- }
+ // op->xbee1.msgIn = xbeeRelay.counterX1in;
+ // op->xbee1.msgOut = xbeeRelay.counterX1out;
+ // op->xbee1.msgIn = xbeeRelay.counterX2in;
+ // op->xbee2.msgOut = xbeeRelay.counterX2out;
+// if (counter++ % 10 == 0) { // Do every 1 second
+// op->xbee1.rateOut = xbeeRelay.bytesX1out / 1000.0; // Measure data rate in KB/s
+// op->xbee2.rateOut = xbeeRelay.bytesX2out / 1000.0;
+// xbeeRelay.bytesX1out = 0; // Clear every second
+ // xbeeRelay.bytesX2out = 0;
+ // }
// CATCH ERRORS
if (op->glvBat.error) op->faultCode |= GLVBAT_FAULT;
@@ -63,7 +63,7 @@
if (op->latch.imd & HARD_FAULT) op->faultCode |= IMD_LATCH;
if (op->imd.error) op->faultCode |= IMD_FAULT;
- if (FreezeFrame::getError()) op->faultCode |= FREEZE_FRAME;
+ if (FreezeFrame::getError()) ;// op->faultCode |= FREEZE_FRAME;
else op->faultCode &= ~FREEZE_FRAME;
// UPDATE MODE
