Interface layer for the mbed boards ready for the JAVA library
Dependencies: C12832 LM75B MMA7660 mbed FXOS8700Q
Fork of frdm_serial by
Diff: comms.cpp
- Revision:
- 5:d9f8c2f63323
- Parent:
- 4:39e949908fc5
- Child:
- 6:adf2837c1e7f
--- a/comms.cpp Tue Dec 01 15:00:12 2015 +0000 +++ b/comms.cpp Fri Dec 04 14:42:01 2015 +0000 @@ -1,4 +1,3 @@ - #include "comms.h" DataSerial::DataSerial(PinName tx, PinName rx) : Serial(tx,rx,NULL) {} @@ -30,6 +29,7 @@ } char DataSerial::readChar() { + if(getc()!=1) readFailureMode(); return getc(); } @@ -39,7 +39,20 @@ putc(*(c++)); } +uint8_t DataSerial::readString(char * s) { + char l = getc(); + uint8_t len = (uint8_t)l; + while(l>0) { + *s = getc(); + s++; + l--; + } + return len; +} + void DataSerial::readData(void* data, uint8_t len) { + char readLen = getc(); + if(readLen!=len) readFailureMode(); char* c = (char*)data; while(len>0) { *c = getc(); @@ -50,4 +63,14 @@ void DataSerial::sendSpecialCommand(char char1, char char2) { putc(0); putc(char1); putc(char2); +} + +void DataSerial::readFailureMode() { + DigitalOut lr(PTB22), lg(PTE26), lb(PTB21); + lr=lg=1; lb=0; + for(;;) { + wait_ms(1000); + lb=!lb; + } + } \ No newline at end of file