EdgeBotix / HC05

Dependencies:   CRC16

Dependents:   eBot_Firmware_V1

Fork of SWSPI by Dave Van Wagner

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HC05.cpp Source File

HC05.cpp

00001 #include "HC05.h"
00002 #include <stdarg.h> 
00003 
00004 HC05::HC05(PinName tx_pin, PinName rx_pin, PinName en_pin):
00005     MODSERIAL(tx_pin, rx_pin),
00006     on_switch(en_pin)
00007 {
00008     //wait_ms(5000);  //mark
00009     on_switch = 0;
00010 }
00011 void HC05::start(){
00012     on_switch = 1;
00013 }
00014 int HC05::printfCRC ( const char * format, ... ){
00015          
00016     va_list argptr; /* Set up the variable argument list here */
00017     va_start(argptr, format);
00018     int ret = sprintf(buffer,format, argptr); 
00019     va_end(argptr);  /* Signify end of processing of variable arguments */   
00020     
00021     int i = 0;
00022     while(i < BUFFER_SIZE && buffer[i]){    
00023         putc(buffer[i]);
00024         i++;
00025     }    
00026     unsigned short checksum = calculateCRC16(buffer,i);
00027 
00028     //printf(" %d %d ", checksum >> 8, checksum & 0xFF);   
00029 
00030     for( int j = 0; j < 4; j++)        
00031         putc( ( checksum >> ( 4* (3-j) ) ) & 0x0F);
00032         
00033     //putc(checksum & 0xFF);
00034     putc('\r');
00035     putc('\n');
00036 
00037     return ret;
00038     }
00039     
00040 void HC05::printBufferCRC(){
00041     int i = 0;
00042     while(i < BUFFER_SIZE && buffer[i]){    
00043         putc(buffer[i]);
00044         i++;
00045     }    
00046     unsigned short checksum = calculateCRC16(buffer,i);
00047 
00048     //printf(" %d %d ", checksum >> 8, checksum & 0xFF);   
00049 
00050     for( int j = 0; j < 4; j++)        
00051         putc( ( checksum >> ( 4* (3-j) ) ) & 0x0F);
00052         
00053     //putc(checksum & 0xFF);
00054     putc('\r');
00055     putc('\n');    
00056     }
00057 //void HCO5::stop(){
00058 //    on_switch = 0;
00059 //}