Dashboard firmware for FBR2012
Dependencies: mbed TextLCD PinDetect
src/PCComms.cpp@1:b3907b8d9f65, 2012-06-25 (annotated)
- Committer:
- intrinseca
- Date:
- Mon Jun 25 21:01:02 2012 +0000
- Revision:
- 1:b3907b8d9f65
Prototype before adding full CAN comms
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
intrinseca | 1:b3907b8d9f65 | 1 | #include "PCComms.h" |
intrinseca | 1:b3907b8d9f65 | 2 | #include "mbed.h" |
intrinseca | 1:b3907b8d9f65 | 3 | #include "State.h" |
intrinseca | 1:b3907b8d9f65 | 4 | |
intrinseca | 1:b3907b8d9f65 | 5 | #define BUFFER_LENGTH 10 |
intrinseca | 1:b3907b8d9f65 | 6 | |
intrinseca | 1:b3907b8d9f65 | 7 | PCComms::PCComms(State* _values) : Comms(_values) |
intrinseca | 1:b3907b8d9f65 | 8 | { |
intrinseca | 1:b3907b8d9f65 | 9 | pc = new Serial(USBTX, USBRX); |
intrinseca | 1:b3907b8d9f65 | 10 | |
intrinseca | 1:b3907b8d9f65 | 11 | pc->attach(this, &PCComms::receive, Serial::RxIrq); |
intrinseca | 1:b3907b8d9f65 | 12 | } |
intrinseca | 1:b3907b8d9f65 | 13 | |
intrinseca | 1:b3907b8d9f65 | 14 | void PCComms::send(char message) |
intrinseca | 1:b3907b8d9f65 | 15 | { |
intrinseca | 1:b3907b8d9f65 | 16 | pc->putc(message); |
intrinseca | 1:b3907b8d9f65 | 17 | } |
intrinseca | 1:b3907b8d9f65 | 18 | |
intrinseca | 1:b3907b8d9f65 | 19 | void PCComms::receive() |
intrinseca | 1:b3907b8d9f65 | 20 | { |
intrinseca | 1:b3907b8d9f65 | 21 | unsigned char packet_id; |
intrinseca | 1:b3907b8d9f65 | 22 | unsigned char data_length; |
intrinseca | 1:b3907b8d9f65 | 23 | |
intrinseca | 1:b3907b8d9f65 | 24 | unsigned char buffer[BUFFER_LENGTH]; |
intrinseca | 1:b3907b8d9f65 | 25 | |
intrinseca | 1:b3907b8d9f65 | 26 | int i; |
intrinseca | 1:b3907b8d9f65 | 27 | |
intrinseca | 1:b3907b8d9f65 | 28 | if(pc->readable()) |
intrinseca | 1:b3907b8d9f65 | 29 | { |
intrinseca | 1:b3907b8d9f65 | 30 | if(pc->getc() == 0xFF && pc->getc() == 0xFF) //Handshake(ish) |
intrinseca | 1:b3907b8d9f65 | 31 | { |
intrinseca | 1:b3907b8d9f65 | 32 | packet_id = pc->getc(); |
intrinseca | 1:b3907b8d9f65 | 33 | data_length = pc->getc(); |
intrinseca | 1:b3907b8d9f65 | 34 | |
intrinseca | 1:b3907b8d9f65 | 35 | for(i = 0; i < data_length && i < BUFFER_LENGTH; i++) |
intrinseca | 1:b3907b8d9f65 | 36 | { |
intrinseca | 1:b3907b8d9f65 | 37 | buffer[i] = pc->getc(); |
intrinseca | 1:b3907b8d9f65 | 38 | } |
intrinseca | 1:b3907b8d9f65 | 39 | |
intrinseca | 1:b3907b8d9f65 | 40 | process_packet(packet_id, data_length, buffer); |
intrinseca | 1:b3907b8d9f65 | 41 | } |
intrinseca | 1:b3907b8d9f65 | 42 | } |
intrinseca | 1:b3907b8d9f65 | 43 | } |