Dashboard firmware for FBR2012
Dependencies: mbed TextLCD PinDetect
Revision 7:78cb2263290a, committed 2013-02-17
- Comitter:
- intrinseca
- Date:
- Sun Feb 17 18:50:09 2013 +0000
- Parent:
- 6:11b2bbbe14b2
- Child:
- 8:e59084742552
- Commit message:
- Move CAN comms to library
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MSCAN.lib Sun Feb 17 18:50:09 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/intrinseca/code/MSCAN/#0abff05153a1
--- a/inc/CANComms.h Wed Oct 17 16:08:51 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,23 +0,0 @@ -#ifndef FBRDASH_CANCOMMS_H -#define FBRDASH_CANCOMMS_H - -#include "mbed.h" -#include "State.h" -#include "Comms.h" - -class CANComms : public Comms -{ - public: - CANComms(State* _values); - virtual void send(char message); - - private: - Ticker* pollTicker; - Ticker* readTicker; - CAN* can; - - void receive(); - void poll(); -}; - -#endif \ No newline at end of file
--- a/inc/Comms.h Wed Oct 17 16:08:51 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -#ifndef FBRDASH_COMMS_H -#define FBRDASH_COMMS_H - -#include "State.h" - -class Comms -{ - public: - Comms(State* _values); - virtual void send(char message) {}; - - protected: - State* values; - - void process_packet(unsigned char id, int length, unsigned char data[]); -}; - -#endif \ No newline at end of file
--- a/inc/MSCANHeader.h Wed Oct 17 16:08:51 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -#ifndef FBRDASH_MSCANHEADER_H -#define FBRDASH_MSCANHEADER_H - -#define MSCAN_CMD 0 //a command to set a variable on the receiving processor to the value in the subsequent data part of the message, or -#define MSCAN_REQ 1 //a request for data, i.e., the value of a specific variable (and where to store the reply) -#define MSCAN_RSP 2 //a push-type message in reply to the destination processor's request for a variable value, the requested values are in the data buffer (&CAN_RB_DSR0) in the received message, -#define MSCAN_XSUB 3 //a message to this processor from device 1 to execute subroutine immediately here (set flag if can execute in main loop), or -#define MSCAN_BURN 4 //a message to burn RAM data table into flash data table. - -#define MSCAN_ID_MS 0 -#define MSCAN_ID_DASH 1 - -#define MSCAN_BLOCK_OUTPC 7 - -class MSCANHeader -{ - public: - MSCANHeader(); - MSCANHeader(char to, char from, char type, char block, short offset); - - void parse(int id); - int build(); - - short var_offset; - char msg_type; - char from_id; - char to_id; - char var_blk; -}; - -#endif \ No newline at end of file
--- a/inc/State.h Wed Oct 17 16:08:51 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -#ifndef FBRDASH_STATE_H -#define FBRDASH_STATE_H - -struct State -{ - unsigned short int rpm; - float throttle_pos; - unsigned char manifold_pres; - unsigned char air_temp; - float coolant_temp; - unsigned char lambda; - unsigned char speed; - unsigned char accel_x; - unsigned char accel_y; - unsigned char gear; - unsigned char oil_temp; - unsigned char warnings; - float voltage; -}; - -#endif \ No newline at end of file
--- a/main.cpp Wed Oct 17 16:08:51 2012 +0000 +++ b/main.cpp Sun Feb 17 18:50:09 2013 +0000 @@ -53,19 +53,22 @@ revs.refresh(car.rpm); if(car.voltage < 12) { - warn[0]=1; + warn[0] = 1; } else { - warn[0]=0; + warn[0] = 0; } - if(car.coolant_temp>110) { - warn[1]=1; + + if(car.coolant_temp > 110) { + warn[1] = 1; } else { - warn[1]=0; + warn[1] = 0; } - if(car.rpm==0 and car.gear!=0) { - warn[2]=1; + + if(car.rpm == 0 and car.gear != 0) + { + warn[2] = 1; } else { - warn[2]=0; + warn[2] = 0; } }
--- a/src/CANComms.cpp Wed Oct 17 16:08:51 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -#include "CANComms.h" -#include "mbed.h" -#include "State.h" - -#include "MSCANHeader.h" - -CANComms::CANComms(State* _values) : Comms(_values) -{ - can = new CAN(p30, p29); - can->frequency(500000); - - pollTicker = new Ticker(); - readTicker = new Ticker(); - - pollTicker->attach(this, &CANComms::poll, 0.05); - readTicker->attach(this, &CANComms::receive, 0.025); -} - -void CANComms::poll() -{ - char i; - - //start 6, 22 - //int ids[] = {0x00189838, 0x00589838}; - - short offsets[] = {6, 22}; - - MSCANHeader header(MSCAN_ID_MS, MSCAN_ID_DASH, MSCAN_REQ, MSCAN_BLOCK_OUTPC, 0); - - for(i = 0; i < 2; i++) - { - header.var_offset = offsets[i]; - CANMessage msg(header.build(), 0, 3, CANData, CANExtended); - - msg.data[0] = i; //Where to put the response - used when communicating between MS's to tell them where they wanted the data put - msg.data[1] = 0; //Offset into the table specified in data[0] - msg.data[2] = 8; //How many bytes of the source table we want - - /*printf("Polling %d\n", i);*/ - - if(can->write(msg)) - { - - } - } -} - -void CANComms::send(char message) -{ - -} - -void CANComms::receive() -{ - float tps; - char block; - - CANMessage msg; - MSCANHeader header; - - while(can->read(msg)) - { - /*printf("CAN Message %08X %d %02X%02X%02X%02X%02X%02X%02X%02X\n", msg.id, msg.len, - msg.data[0], - msg.data[1], - msg.data[2], - msg.data[3], - msg.data[4], - msg.data[5], - msg.data[6], - msg.data[7] - );*/ - - header.parse(msg.id); - - //printf("Processing data, block %d\n", block); - - if(header.var_blk == 0) - { - values->rpm = (msg.data[0] << 8) | msg.data[1]; - } - else - { - values->coolant_temp = (((msg.data[0] << 8) | msg.data[1]) - 320.0) * 0.05555; - values->throttle_pos = ((msg.data[2] << 8) | msg.data[3]) / 10.0; - values->voltage = ((msg.data[4] << 8) | msg.data[5]) / 10.0; - printf("TPS: %f\n", values->throttle_pos); - } - - //printf("Bat: %f\n", battery / 10.0); - } -} \ No newline at end of file
--- a/src/Comms.cpp Wed Oct 17 16:08:51 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -#include "PCComms.h" -#include "mbed.h" -#include "State.h" - -//Process incoming data from Comms interfaces - -//Initialise members -Comms::Comms(State* _values) -{ - values = _values; -} - -//Process an incoming data packet -void Comms::process_packet(unsigned char id, int length, unsigned char data[]) -{ - switch(id) - { - case 100: - values->rpm = data[0] + (data[1] << 8); - values->throttle_pos = data[2]; - values->manifold_pres = data[3]; - values->air_temp = data[4]; - values->coolant_temp = data[5]; - values->lambda = data[6]; - break; - case 200: - values->speed = data[0]; - values->accel_x = data[1]; - values->accel_y = data[2]; - values->gear = data[3]; - values->oil_temp = data[4]; - values->voltage = data[5]; - values->warnings = data[6]; - break; - } -} \ No newline at end of file
--- a/src/LEDS.cpp Wed Oct 17 16:08:51 2012 +0000 +++ b/src/LEDS.cpp Sun Feb 17 18:50:09 2013 +0000 @@ -14,7 +14,6 @@ //Calculate new PWM values void LEDS::refresh(float rpm) { - //Engine running pins[0]=(rpm-1000)/4000; //Change Down
--- a/src/MSCANHeader.cpp Wed Oct 17 16:08:51 2012 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -#include "MSCANHeader.h" - -MSCANHeader::MSCANHeader() -{ - -} - -MSCANHeader::MSCANHeader(char to, char from, char type, char block, short offset) -{ - to_id = to; - from_id = from; - msg_type = type; - var_blk = block; - var_offset = offset; -} - -//MS encodes most of the request params in the message ID. -//Alignment is weird because the ID really includes some non-data bits. MS worked round these, mBed just skips them - -//0-2 3 bits Spare on MSII -//3-6 4 bits Block to get data from. 7 = outpc, all the stuff that MS sends to the PC via serial -//7-10 4 bits To ID - 0 for MS -//11-14 4 bits From ID - Using 3 here for no good reason -//15-17 3 bits Message type. 1 to get data, response has 2 -//18-28 11 bits Offset into the block in bits 3-6. Look in the INI file for Tuner Studio to find these, -// [OutputChannels] section starting line 3036 - -void MSCANHeader::parse(int id) -{ - var_offset = (id & 0x1FFC0000) >> 18; - msg_type = (id & 0x00038000) >> 15; - from_id = (id & 0x00007800) >> 11; - to_id = (id & 0x00000780) >> 7; - var_blk = (id & 0x00000078) >> 3; -} - -int MSCANHeader::build() -{ - int id = 0; - - id |= (var_offset & 0x7FF) << 18; - id |= (msg_type & 0x7) << 15; - id |= (from_id & 0xF) << 11; - id |= (to_id & 0xF) << 7; - id |= (var_blk & 0xF) << 3; - - return id; -} \ No newline at end of file