Initial Fork
Dependencies: CRC16
Fork of SWSPI by
Diff: HC05.cpp
- Revision:
- 2:c13831ca234c
- Parent:
- 1:faa9f74488ba
diff -r faa9f74488ba -r c13831ca234c HC05.cpp --- a/HC05.cpp Thu May 08 19:10:52 2014 +0000 +++ b/HC05.cpp Sun Oct 05 12:21:30 2014 +0000 @@ -1,8 +1,59 @@ #include "HC05.h" +#include <stdarg.h> HC05::HC05(PinName tx_pin, PinName rx_pin, PinName en_pin): - Serial(tx_pin, rx_pin), + MODSERIAL(tx_pin, rx_pin), on_switch(en_pin) { + //wait_ms(5000); //mark + on_switch = 0; +} +void HC05::start(){ on_switch = 1; } +int HC05::printfCRC ( const char * format, ... ){ + + va_list argptr; /* Set up the variable argument list here */ + va_start(argptr, format); + int ret = sprintf(buffer,format, argptr); + va_end(argptr); /* Signify end of processing of variable arguments */ + + int i = 0; + while(i < BUFFER_SIZE && buffer[i]){ + putc(buffer[i]); + i++; + } + unsigned short checksum = calculateCRC16(buffer,i); + + //printf(" %d %d ", checksum >> 8, checksum & 0xFF); + + for( int j = 0; j < 4; j++) + putc( ( checksum >> ( 4* (3-j) ) ) & 0x0F); + + //putc(checksum & 0xFF); + putc('\r'); + putc('\n'); + + return ret; + } + +void HC05::printBufferCRC(){ + int i = 0; + while(i < BUFFER_SIZE && buffer[i]){ + putc(buffer[i]); + i++; + } + unsigned short checksum = calculateCRC16(buffer,i); + + //printf(" %d %d ", checksum >> 8, checksum & 0xFF); + + for( int j = 0; j < 4; j++) + putc( ( checksum >> ( 4* (3-j) ) ) & 0x0F); + + //putc(checksum & 0xFF); + putc('\r'); + putc('\n'); + } +//void HCO5::stop(){ +// on_switch = 0; +//} \ No newline at end of file