![](/media/cache/group/underwritten_car_negative.png.50x50_q85.png)
System Management code
Dependencies: mbed CANBuffer Watchdog MODSERIAL mbed-rtos xbeeRelay IAP
Fork of SystemManagement by
serviceCAN/serviceCAN.cpp@31:7eaa5e881b56, 2014-11-14 (annotated)
- Committer:
- pspatel321
- Date:
- Fri Nov 14 06:05:59 2014 +0000
- Revision:
- 31:7eaa5e881b56
- Parent:
- 30:91af74a299e1
- Child:
- 33:6bc82b6b62e5
Mostly working. Wrote CAN in/out code. Xbee still needs work. My guess is that MODDMA breaks when used with RTOS.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pspatel321 | 30:91af74a299e1 | 1 | #include "serviceCAN.h" |
pspatel321 | 31:7eaa5e881b56 | 2 | #include "CAN_RxIDs.h" |
pspatel321 | 30:91af74a299e1 | 3 | |
pspatel321 | 30:91af74a299e1 | 4 | |
pspatel321 | 30:91af74a299e1 | 5 | bool canbus::serviceCAN() { |
pspatel321 | 30:91af74a299e1 | 6 | CANMessage msg; |
pspatel321 | 31:7eaa5e881b56 | 7 | if (can.rxRead(msg)) { |
pspatel321 | 31:7eaa5e881b56 | 8 | switch (msg.id) { |
pspatel321 | 31:7eaa5e881b56 | 9 | case FAN_CONTROL_ID: |
pspatel321 | 31:7eaa5e881b56 | 10 | if (msg.len != 2*sizeof(float)) break; |
pspatel321 | 31:7eaa5e881b56 | 11 | memcpy((void*)&CANdata.dcdcFan1Duty, &msg.data[0], sizeof(float)); |
pspatel321 | 31:7eaa5e881b56 | 12 | memcpy((void*)&CANdata.dcdcFan2Duty, &msg.data[4], sizeof(float)); |
pspatel321 | 31:7eaa5e881b56 | 13 | dcdc.setPwm(FAN1, CANdata.dcdcFan1Duty); |
pspatel321 | 31:7eaa5e881b56 | 14 | dcdc.setPwm(FAN2, CANdata.dcdcFan2Duty); |
pspatel321 | 31:7eaa5e881b56 | 15 | break; |
pspatel321 | 31:7eaa5e881b56 | 16 | |
pspatel321 | 31:7eaa5e881b56 | 17 | case PUMP_CONTROL_ID: |
pspatel321 | 31:7eaa5e881b56 | 18 | if (msg.len != 2*sizeof(float)) break; |
pspatel321 | 31:7eaa5e881b56 | 19 | memcpy((void*)&CANdata.dcdcPump1Duty, &msg.data[0], sizeof(float)); |
pspatel321 | 31:7eaa5e881b56 | 20 | memcpy((void*)&CANdata.dcdcPump2Duty, &msg.data[4], sizeof(float)); |
pspatel321 | 31:7eaa5e881b56 | 21 | dcdc.setPwm(PUMP1, CANdata.dcdcPump1Duty); |
pspatel321 | 31:7eaa5e881b56 | 22 | dcdc.setPwm(PUMP2, CANdata.dcdcPump2Duty); |
pspatel321 | 31:7eaa5e881b56 | 23 | break; |
pspatel321 | 31:7eaa5e881b56 | 24 | |
pspatel321 | 31:7eaa5e881b56 | 25 | case DCDC_CONTROL_ID: |
pspatel321 | 31:7eaa5e881b56 | 26 | if (msg.len != sizeof(char)) break; |
pspatel321 | 31:7eaa5e881b56 | 27 | if (msg.data[0] == 1) dcdc.set(1); |
pspatel321 | 31:7eaa5e881b56 | 28 | else dcdc.set(0); |
pspatel321 | 31:7eaa5e881b56 | 29 | break; |
pspatel321 | 31:7eaa5e881b56 | 30 | |
pspatel321 | 31:7eaa5e881b56 | 31 | case AMS_RELAYS_ID: |
pspatel321 | 31:7eaa5e881b56 | 32 | if (msg.len != sizeof(char)) break; |
pspatel321 | 31:7eaa5e881b56 | 33 | if ((msg.data[0] & 0xC0) == 0xC0) { |
pspatel321 | 31:7eaa5e881b56 | 34 | CANdata.airsClosed = true; |
pspatel321 | 31:7eaa5e881b56 | 35 | dcdc.set(1); |
pspatel321 | 31:7eaa5e881b56 | 36 | } else { |
pspatel321 | 31:7eaa5e881b56 | 37 | CANdata.airsClosed = false; |
pspatel321 | 31:7eaa5e881b56 | 38 | dcdc.set(0); |
pspatel321 | 31:7eaa5e881b56 | 39 | } |
pspatel321 | 31:7eaa5e881b56 | 40 | break; |
pspatel321 | 31:7eaa5e881b56 | 41 | |
pspatel321 | 31:7eaa5e881b56 | 42 | case GLVBAT_CLEARSOC_ID: |
pspatel321 | 31:7eaa5e881b56 | 43 | if (msg.len != sizeof(float)) break; |
pspatel321 | 31:7eaa5e881b56 | 44 | glvBat.resetToSOC(*((float*)(&msg.data[0]))); |
pspatel321 | 31:7eaa5e881b56 | 45 | break; |
pspatel321 | 31:7eaa5e881b56 | 46 | |
pspatel321 | 31:7eaa5e881b56 | 47 | case GLVBAT_CLEARAH_ID: |
pspatel321 | 31:7eaa5e881b56 | 48 | if (msg.len != sizeof(float)) break; |
pspatel321 | 31:7eaa5e881b56 | 49 | glvBat.resetToAh(*((float*)(&msg.data[0]))); |
pspatel321 | 31:7eaa5e881b56 | 50 | break; |
pspatel321 | 31:7eaa5e881b56 | 51 | |
pspatel321 | 31:7eaa5e881b56 | 52 | case GLVBAT_SETCAPAC_ID: |
pspatel321 | 31:7eaa5e881b56 | 53 | if (msg.len != sizeof(float)) break; |
pspatel321 | 31:7eaa5e881b56 | 54 | glvBat.changeCapacity(*((float*)(&msg.data[0]))); |
pspatel321 | 31:7eaa5e881b56 | 55 | break; |
pspatel321 | 31:7eaa5e881b56 | 56 | |
pspatel321 | 31:7eaa5e881b56 | 57 | default: |
pspatel321 | 31:7eaa5e881b56 | 58 | break; |
pspatel321 | 31:7eaa5e881b56 | 59 | } |
pspatel321 | 31:7eaa5e881b56 | 60 | xbee.receive(msg); |
pspatel321 | 31:7eaa5e881b56 | 61 | return true; |
pspatel321 | 31:7eaa5e881b56 | 62 | } |
pspatel321 | 30:91af74a299e1 | 63 | return false; |
pspatel321 | 30:91af74a299e1 | 64 | } |