Minimale Veränderungen in Btbee; Die Datenübertragung funktioniert nicht hunderprozentig, v.a. wenn mehrere Bytes übertragen werden.

Fork of btbee by Nikolas Goldin

Files at this revision

API Documentation at this revision

Comitter:
friedrich_h
Date:
Tue Jun 28 09:23:51 2016 +0000
Parent:
2:12c38a710982
Commit message:
C++-Code f?r die LNDW 2016;

Changed in this revision

btbee.cpp Show annotated file Show diff for this revision Revisions of this file
btbee.h Show annotated file Show diff for this revision Revisions of this file
diff -r 12c38a710982 -r cf8611463f79 btbee.cpp
--- a/btbee.cpp	Thu May 16 14:01:24 2013 +0000
+++ b/btbee.cpp	Tue Jun 28 09:23:51 2016 +0000
@@ -1,37 +1,37 @@
 #include "btbee.h"
-
+ 
 btbee::btbee(PinName respin, PinName tx, PinName rx) : 
   Serial(tx,  rx) , reset_out(respin) 
 {
   reset_out.write(1);
   baud(DEFAULT_BAUD); 
 }
-
+ 
 btbee::btbee( ) : 
   Serial(p28,p27),  reset_out(p26)
 {
   reset_out.write(1); 
   baud(DEFAULT_BAUD); 
 }
-
+ 
 void btbee::reset(void){
 reset_out.write(0);
 wait(0.01);
 reset_out.write(1);
 }
-
+ 
 void btbee::at_baud(void){
 baud(AT_BAUD);
 }
-
+ 
 void btbee::factory_baud(void){
 baud(FACTORY_BAUD);
 }
-
+ 
 void btbee::default_baud(void){
 baud(DEFAULT_BAUD);
 }
-
+ 
 /* Read from the serial as long as it is readable. 
 *  Params: pointer to char array for the return, 
 *          int containing the length of the char array
@@ -48,4 +48,24 @@
 }
 return 1;
 }
-
+ 
+/* Read from the serial as long as no LF (\n) char has been read.
+*  WARNING: This will block your program if no LF is received. 
+*  Params: pointer to char array for the return, 
+*          int containing the length of the char array
+*          pointer to int for return of chars read 
+*  Return: 1 if ok, 0 if array full but more there to read
+*/
+int btbee::read_line(char * arr, const int len, int * chars_read){
+int pos=0;
+do 
+{
+    while(!readable()){} //wait until readable
+    if (pos==len){return 0;} 
+    arr[pos]=getc(); 
+    pos++;
+    *chars_read = pos;
+}
+while (!(arr[pos-1]=='\n'));
+return 1;
+}
\ No newline at end of file
diff -r 12c38a710982 -r cf8611463f79 btbee.h
--- a/btbee.h	Thu May 16 14:01:24 2013 +0000
+++ b/btbee.h	Tue Jun 28 09:23:51 2016 +0000
@@ -1,10 +1,11 @@
 #include "mbed.h"
 #include "platform.h"
-
+ 
 #define FACTORY_BAUD 9600
 #define DEFAULT_BAUD 115200
 #define AT_BAUD 38400
-
+ 
+// this is a test comment
 class btbee: public Serial{
  public: 
   btbee(PinName respin, PinName tx, PinName rx);
@@ -14,7 +15,9 @@
   void factory_baud(void);
   void default_baud(void);
   int read_all(char*,const int, int*);
-
+  int read_line(char*,const int, int*);
+ 
  protected:
   DigitalOut reset_out;
-};
\ No newline at end of file
+};
+            
\ No newline at end of file