blueSMIRF Library

A library for communication with Adafruit BlueSmirf Bluetooth Modem.

/media/uploads/pmundt/bluesmirf.jpg

Files at this revision

API Documentation at this revision

Comitter:
pmundt
Date:
Mon Nov 13 11:29:50 2017 +0000
Parent:
3:b5ecc07f54e1
Commit message:
Bug Fix

Changed in this revision

blueSMIRF.cpp Show annotated file Show diff for this revision Revisions of this file
blueSMIRF.h Show annotated file Show diff for this revision Revisions of this file
--- a/blueSMIRF.cpp	Sat Nov 11 12:59:47 2017 +0000
+++ b/blueSMIRF.cpp	Mon Nov 13 11:29:50 2017 +0000
@@ -52,6 +52,16 @@
         return 0; 
 }
 
+int blueSMIRF::factoryDefaults(void){
+    serial.printf("SF,1\n");
+    char response [16] = {0};
+    readResponse(response); //AOK
+    if(strcmp(response, "AOK\r\n") == 0)
+        return 1;
+    else
+        return 0;
+}
+
 int blueSMIRF::setMode(int mode){
     serial.printf("SM,%d\n", mode);
     char response[16] = {0}; //AOK
@@ -62,6 +72,16 @@
         return 0; 
 }
 
+int blueSMIRF::setName(char * name){
+    serial.printf("SN,%s\n", name);
+    char response[16] = {0}; //AOK
+    readResponse(response);
+    if(strcmp(response, "AOK\r\n") == 0)
+        return 1;
+    else
+        return 0; 
+}
+
 int blueSMIRF::setStatusString(char * str){
     serial.printf("SO,%s%\n", str);
     char response[16] = {0}; //AOK
@@ -72,6 +92,16 @@
         return 0;
 }
 
+int blueSMIRF::setPinCode(char * pinCode){
+    serial.printf("SP,%s\n", pinCode);
+    char response[16] = {0}; //AOK
+    readResponse(response);
+    if(strcmp(response, "AOK\r\n") == 0)
+        return 1;
+    else
+        return 0;
+}
+
 int blueSMIRF::setSpecialConf(int value){
     serial.printf("SQ,%d\n", value);
     char response[16] = {0}; //AOK
@@ -82,6 +112,16 @@
         return 0;
 }
 
+int blueSMIRF::setConfTimer(int value){
+    serial.printf("ST,%d\n", value);
+    char response[16] = {0}; //AOK
+    readResponse(response);
+    if(strcmp(response, "AOK\r\n") == 0)
+        return 1;
+    else
+        return 0;
+}
+
 /** GET COMMANDS **************************************************************/
 void blueSMIRF::getBasicSettings(char * response){
      serial.printf("D\n");
@@ -198,8 +238,8 @@
         return 0;
 }
  //------------------------------------------>>>>   
-void blueSMIRF::connectAddressFast(int address){
-    serial.printf("CF,%12X\n", address);
+void blueSMIRF::connectAddressFast(char * address){
+    serial.printf("CF,%s\n", address);
     //No Response
 }
 
@@ -233,13 +273,14 @@
         return 0;
 }
 
-void blueSMIRF::deviceScan(int time, char * response, int classCOD = 0){
+void blueSMIRF::deviceScan(int time, char * response, int classCOD){
     if(classCOD == 0)
         serial.printf("I,%d\n",time);
     else
         serial.printf("I,%d,%d\n",time ,classCOD);
-        
-    wait(time);
+    
+    int delay = time + 10; //Extra 10seconds for BlueSmirf to print all devices
+    wait(delay);
     
     readResponse(response);
 }
@@ -249,27 +290,33 @@
         serial.printf("IN,%d\n",time);
     else
         serial.printf("IN,%d,%d\n",time ,classCOD);
-        
-    wait(time);
+    
+    int delay = time + 10; //Extra 10seconds for BlueSmirf to print all devices
+    wait(delay);
     
     readResponse(response);
 }
     
 void blueSMIRF::deviceScanWithRSSI(char * response){
     serial.printf("IQ\n");
-    wait(7); // Wait 7 seconds
+
+    wait(17); // Wait 7 seconds + Extra 10 seconds for BlueSmirf to print all devices
     readResponse(response);
 }
     
 void blueSMIRF::deviceScanRovingNetwork(int time, char * response){
     serial.printf("IS%d\n",time);
-    wait(time);
+    
+    int delay = time + 10; //Extra 10seconds for BlueSmirf to print all devices
+    wait(delay);
     readResponse(response);
 }
     
 void blueSMIRF::deviceScanCablePair(int time, char * response){
     serial.printf("IR%d\n",time);
-    wait(time);
+    
+    int delay = time + 10; //Extra 10seconds for BlueSmirf to print all devices
+    wait(delay);
     readResponse(response);
 }
     
@@ -323,6 +370,7 @@
 
 int blueSMIRF::reboot(void){
     serial.printf("R,1\n");
+    wait_ms(100);
     char response[16] = {0}; //Reboot!
     readResponse(response);
     if(strcmp(response, "Reboot!\r\n") == 0)
@@ -366,11 +414,18 @@
 }    
 
 void blueSMIRF::readResponse(char* response){
-    wait_ms(50);
+    wait_ms(100);
+    
+    Timer timeOut;
+    timeOut.start();
+    
+    while(!serial.readable() && timeOut.read_ms() < 500);
+    wait_ms(100); //Be sure to receive the response
     int index = 0;
     while(serial.readable()){
         response[index] = serial.getc();
         index++;
+        wait_ms(1);
     }
 }
 
@@ -378,3 +433,7 @@
     while(serial.readable())
         char c = serial.getc();
 }
+
+void blueSMIRF::setBaud(int baud){
+    serial.baud(baud);
+}
--- a/blueSMIRF.h	Sat Nov 11 12:59:47 2017 +0000
+++ b/blueSMIRF.h	Mon Nov 13 11:29:50 2017 +0000
@@ -65,6 +65,13 @@
      */
     int setDeviceClass(int value);
     
+    /** Factory Defaults
+     * @returns
+     *   1 on success
+     *   0 on error
+     */
+    int factoryDefaults(void);
+    
     /** Mode
      * @param mode 0:Slave, 1:Master, 2:Trigger, 3:Auto, 4:DTR, 5:Any 
      * @returns
@@ -73,14 +80,30 @@
      */
     int setMode(int mode);
     
+    /** Mode
+     * @param name of device
+     * @returns
+     *   1 on success
+     *   0 on error
+     */
+    int setName(char * name);
+    
     /** Connect/Disconnect Status String
-     * $param str
+     * @param str
      * @returns
      *   1 on success
      *   0 on error
      */
     int setStatusString(char * str);
     
+    /** Connect/Disconnect Status String
+     * $param str PinCode
+     * @returns
+     *   1 on success
+     *   0 on error
+     */
+    int setPinCode(char * pinCode);
+    
     /** Special Configuration Settings
      *  @param value 0, 4, 8, 16, 128, 256
      * @returns
@@ -89,6 +112,14 @@
      */
     int setSpecialConf(int value);
     
+    /** This command sets the remote configuration timer
+     * @param value
+     * @returns
+     *   1 on success
+     *   0 on error
+     */
+    int setConfTimer(int value);
+    
     /** GET COMMANDS **********************************************************/
     
     /** Get Basic Settings
@@ -192,7 +223,7 @@
     
     /** Connect to Address in Fast Mode
      */
-    void connectAddressFast(int address);
+    void connectAddressFast(char * address);
     
     /** Connect and Immediately Go into Fast Data Mode Using Last Address Found
      */
@@ -225,7 +256,7 @@
      * @param response char array to data to return
      * @param classCOD is the optional COD of the device class for which you are scanning
      */
-    void deviceScan(int time, char * response, int classCOD);
+    void deviceScan(int time, char * response, int classCOD = 0);
     
     /** Device Scan Inquiry, Returns NAMEs
      * @param time is the scan time in seconds
@@ -331,6 +362,10 @@
     /** Flush Serial
      */
     void flushSerial(void);
+
+    /** Set Baud
+     */
+    void setBaud(int baud);
     
 private:
     BufferedSerial serial;