![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Publication TP CAN
Dependencies: Dashboard_BUS_CAN Programme_BUS_CAN mbed
main.cpp@0:4eee0a42e29b, 2018-06-05 (annotated)
- Committer:
- KEG
- Date:
- Tue Jun 05 16:49:19 2018 +0000
- Revision:
- 0:4eee0a42e29b
Pulication;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KEG | 0:4eee0a42e29b | 1 | #include "Dashboard.h" |
KEG | 0:4eee0a42e29b | 2 | #include "mbed.h" |
KEG | 0:4eee0a42e29b | 3 | |
KEG | 0:4eee0a42e29b | 4 | #define SIG_RX_CAN 0x01 |
KEG | 0:4eee0a42e29b | 5 | #define SIG_AFF 0x01 |
KEG | 0:4eee0a42e29b | 6 | |
KEG | 0:4eee0a42e29b | 7 | DigitalOut led1(LED1); |
KEG | 0:4eee0a42e29b | 8 | DigitalOut led2(LED2); |
KEG | 0:4eee0a42e29b | 9 | DigitalOut led3(LED3); |
KEG | 0:4eee0a42e29b | 10 | |
KEG | 0:4eee0a42e29b | 11 | Thread threadA; |
KEG | 0:4eee0a42e29b | 12 | Thread threadB; |
KEG | 0:4eee0a42e29b | 13 | |
KEG | 0:4eee0a42e29b | 14 | CAN CanPort(p30, p29); |
KEG | 0:4eee0a42e29b | 15 | CANMessage MessageRx; |
KEG | 0:4eee0a42e29b | 16 | Dashboard dshbd(p28, p27); |
KEG | 0:4eee0a42e29b | 17 | |
KEG | 0:4eee0a42e29b | 18 | signed char dataToPrint[8]; |
KEG | 0:4eee0a42e29b | 19 | |
KEG | 0:4eee0a42e29b | 20 | void canReader(void) |
KEG | 0:4eee0a42e29b | 21 | { |
KEG | 0:4eee0a42e29b | 22 | if (CanPort.read(MessageRx)) |
KEG | 0:4eee0a42e29b | 23 | { |
KEG | 0:4eee0a42e29b | 24 | led1 = !led1; |
KEG | 0:4eee0a42e29b | 25 | threadA.signal_set(SIG_RX_CAN); |
KEG | 0:4eee0a42e29b | 26 | } |
KEG | 0:4eee0a42e29b | 27 | } |
KEG | 0:4eee0a42e29b | 28 | |
KEG | 0:4eee0a42e29b | 29 | void readFrame(CANMessage msg){ |
KEG | 0:4eee0a42e29b | 30 | if(msg.id==2){ |
KEG | 0:4eee0a42e29b | 31 | int i=0; |
KEG | 0:4eee0a42e29b | 32 | for(i=0;i<8;i++){ |
KEG | 0:4eee0a42e29b | 33 | dataToPrint[i]=msg.data[i]; |
KEG | 0:4eee0a42e29b | 34 | } |
KEG | 0:4eee0a42e29b | 35 | } |
KEG | 0:4eee0a42e29b | 36 | } |
KEG | 0:4eee0a42e29b | 37 | |
KEG | 0:4eee0a42e29b | 38 | void thA() |
KEG | 0:4eee0a42e29b | 39 | { |
KEG | 0:4eee0a42e29b | 40 | while(true) |
KEG | 0:4eee0a42e29b | 41 | { |
KEG | 0:4eee0a42e29b | 42 | Thread::signal_wait(SIG_RX_CAN); |
KEG | 0:4eee0a42e29b | 43 | readFrame(MessageRx); |
KEG | 0:4eee0a42e29b | 44 | led2 = !led2; |
KEG | 0:4eee0a42e29b | 45 | threadB.signal_set(SIG_AFF); |
KEG | 0:4eee0a42e29b | 46 | //printf("RX FRAME ID = %X\n",MessageRx.id); |
KEG | 0:4eee0a42e29b | 47 | } |
KEG | 0:4eee0a42e29b | 48 | } |
KEG | 0:4eee0a42e29b | 49 | |
KEG | 0:4eee0a42e29b | 50 | void thB() |
KEG | 0:4eee0a42e29b | 51 | { |
KEG | 0:4eee0a42e29b | 52 | //int i=0; |
KEG | 0:4eee0a42e29b | 53 | while(true){ |
KEG | 0:4eee0a42e29b | 54 | Thread::signal_wait(SIG_AFF); |
KEG | 0:4eee0a42e29b | 55 | led3 = !led3; |
KEG | 0:4eee0a42e29b | 56 | dshbd.clear(); |
KEG | 0:4eee0a42e29b | 57 | dshbd.printData(dataToPrint); |
KEG | 0:4eee0a42e29b | 58 | dshbd.changeColor(dataToPrint[0]); |
KEG | 0:4eee0a42e29b | 59 | //wait(5); |
KEG | 0:4eee0a42e29b | 60 | /*i++; |
KEG | 0:4eee0a42e29b | 61 | if(i>7){i=0;}*/ |
KEG | 0:4eee0a42e29b | 62 | //printData(); |
KEG | 0:4eee0a42e29b | 63 | } |
KEG | 0:4eee0a42e29b | 64 | } |
KEG | 0:4eee0a42e29b | 65 | |
KEG | 0:4eee0a42e29b | 66 | int main() |
KEG | 0:4eee0a42e29b | 67 | { |
KEG | 0:4eee0a42e29b | 68 | //Init CAN |
KEG | 0:4eee0a42e29b | 69 | CanPort.frequency(20000); |
KEG | 0:4eee0a42e29b | 70 | //Init LCD |
KEG | 0:4eee0a42e29b | 71 | dshbd.setRGB(0xff, 0xff, 0xff); //set the color |
KEG | 0:4eee0a42e29b | 72 | dshbd.print("Init System !"); |
KEG | 0:4eee0a42e29b | 73 | dshbd.locate(0,1); |
KEG | 0:4eee0a42e29b | 74 | wait(5); |
KEG | 0:4eee0a42e29b | 75 | |
KEG | 0:4eee0a42e29b | 76 | CanPort.attach(canReader,CAN::RxIrq); |
KEG | 0:4eee0a42e29b | 77 | |
KEG | 0:4eee0a42e29b | 78 | threadA.start(thA); |
KEG | 0:4eee0a42e29b | 79 | threadB.start(thB); |
KEG | 0:4eee0a42e29b | 80 | |
KEG | 0:4eee0a42e29b | 81 | while(1) |
KEG | 0:4eee0a42e29b | 82 | { |
KEG | 0:4eee0a42e29b | 83 | |
KEG | 0:4eee0a42e29b | 84 | |
KEG | 0:4eee0a42e29b | 85 | } |
KEG | 0:4eee0a42e29b | 86 | } |
KEG | 0:4eee0a42e29b | 87 |