WaspBT Class Reference

WaspBT Class. More...

#include <WaspBT.h>

Collaboration diagram for WaspBT:

Collaboration graph
[legend]

Public Member Functions

 WaspBT ()
 class constructor
void ON ()
 It opens the UART and powers the module.
void OFF ()
 It closes the UART and powers off the module.
uint8_t init ()
 It sets some initial parameters such as security parameters, service parameters, public name, auto accept and discoverable.
uint8_t setSecurity (uint8_t mode, char *pin)
 It sets security parameters.
uint8_t setPublicName (char *name)
 It sets the public name.
uint8_t setAutoAccept (uint8_t mode)
 It sets auto accepting incoming connections.
uint8_t setDiscoveryOptions (uint8_t option)
 It sets the discovering options.
uint8_t readData ()
 It waits for incoming data and stores it in the appropriate array.
uint8_t setServiceParameters (char *name, uint8_t channel, char *cod)
 It sets the service parameters.
uint8_t reset ()
 It resets the module.
uint8_t scanNetwork ()
 It scans looking for devices. It stores in 'discovered_devices' struct the devices discovered.
uint8_t discoverDevice (char *mac, char *profile)
 It searchs for a specific device and stores the service name and service channel in the aprropriate variables.
uint8_t createConnection (char *mac, char *channel)
 It creates a connection with other module.
uint8_t getOwnMac ()
 It gets the own MAC address. It stores the mac in 'own_mac' variable.
uint8_t removeTrustedDevice (char *mac)
 It removes the trusted device specified.
uint8_t sendData (char *data)
 It sends data to other module.
uint8_t removeConnection ()
 It removes an active connection.
uint8_t createStreamConnection ()
 It creates a transparent communication between two devices.

Data Fields

int flag
 Variable : status flag, used to see if there was an error while communicating with the module.
char bt_pin [16]
 Variable : current pin.
uint8_t auto_accept
 Variable : specifies if incoming connections are accepted automatically or not.
uint8_t active_connection
 Variable : specifies if there is an active connection or not.
Device discovered_devices [BT_MAX_DEVICES]
 Variable : stores the discovered devices.
uint8_t devices_found
 Variable : stores the number of discovered devices.
char device_service_name [17]
 Variable : stores the service name that a module is using. It is filled when the function 'searchDevice' is called.
char device_service_channel [2]
 Variable : stores the service channel that a module is using. It is filled when the function 'searchDevice' is called.
char connection_mtu [3]
 Variable : stores the maximum MTU can be used in an active connection.
char own_mac [12]
 Variable : stores the MAC of the device.
char data_received [BT_MAX_DATA]
 Variable : stores the received data.

Private Member Functions

uint16_t waitForData (uint8_t *data, char *expectedAnswer)
 It looks for a pattern in 'data'.
uint8_t parse_data ()
 It waits for response from the module and executes the proper function.
uint8_t parse_data (char *answer)
 It waits for response from the module and executes the proper function.
uint8_t pin_request (uint8_t *data, uint8_t pin_en)
 It answers to the PIN request.
uint8_t accept_connection (uint8_t *data)
 It accepts incoming connection.
uint8_t data_request (uint8_t *data)
 It stores incoming data.
void ending_connection (uint8_t *data)
 It changes the value of 'active_connection' variable.
void parse_brothers (uint8_t *data, uint16_t number_of_data)
 It stores the discovered devices in the appropriate array.
void parse_device (uint8_t *data)
 It stores the discovered device parameters.
void get_MTU (uint8_t *data)
 It stores the MTU of the active connection.
void printData (char *data)
 It sends the data through the UART.

Private Attributes

uint16_t i
 Variable : integer used as counter.
char received [100]
 Variable : array for storing the data received from the module.
uint8_t first
 Variable : integer to reset the BT module before setting security.

Detailed Description

WaspBT Class.

WaspBT Class defines all the variables and functions used for managing the Bluetooth Board

Definition at line 150 of file WaspBT.h.


Constructor & Destructor Documentation

WaspBT::WaspBT (  ) 

class constructor

It initializes some variables

Parameters:
void 
Returns:
void

Definition at line 354 of file WaspBT.cpp.

References active_connection, auto_accept, BT_AUTO_ACC, bt_pin, BT_PIN, devices_found, and i.

00355 {
00356         i=0;
00357         while(BT_PIN[i]!='\0'){
00358                 bt_pin[i]=BT_PIN[i];
00359                 i++;
00360         }
00361         
00362         auto_accept=BT_AUTO_ACC;
00363         
00364         active_connection=0;
00365         
00366         devices_found=0;
00367 }


Member Function Documentation

uint16_t WaspBT::waitForData ( uint8_t *  data,
char *  expectedAnswer 
) [private]

It looks for a pattern in 'data'.

Parameters:
char* data : data where the 'expectedAnswer' has to be found
char* expectedAnswer : string expected to be answered by the module
Returns:
'0' if pattern is not found, pattern position otherwise

Definition at line 31 of file WaspBT.cpp.

References first, i, and received.

Referenced by data_request(), parse_data(), and parse_device().

00032 {
00033         uint16_t i=0;
00034         for (i = 0; i < 100; i++) received[i] = ' ';
00035 
00036         int theLength = 0;
00037         int it=0;
00038         bool theSame=false;
00039         
00040         uint8_t first=1;
00041         uint8_t match=0;
00042         i=0;
00043     
00044         while( expectedAnswer[theLength]!='\0' ) theLength++;
00045         
00046         while( !match && data[i]!='\0' )
00047         {
00048                 if( first )
00049                 {
00050                         for(it=0;it<theLength;it++)
00051                         {
00052                                 received[it]=data[i];
00053                                 i++;
00054                         }
00055                         first=0;
00056                 }
00057                 it=0;
00058                 theSame=true;
00059                 for(it=0; it<theLength ; it++)
00060                 {
00061                         if(received[it]!=expectedAnswer[it]){
00062                                 theSame= false;
00063                                 break;
00064                         }
00065                 }
00066                 if( theSame ) match=1;
00067                 else
00068                 {
00069                         for(it=0; it<theLength-1 ; it++)
00070                         {
00071                                 received[it]=received[it+1];
00072                         }
00073                         received[it]=data[i];
00074                         i++;
00075                 }
00076         }
00077         
00078         if( !match ) i=0;
00079         return i;
00080 }

Here is the caller graph for this function:

uint8_t WaspBT::parse_data (  )  [private]

It waits for response from the module and executes the proper function.

Parameters:
char* data : data where the 'expectedAnswer' has to be found
char* expectedAnswer : string expected to be answered by the module
Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 83 of file WaspBT.cpp.

Referenced by accept_connection(), createConnection(), createStreamConnection(), discoverDevice(), getOwnMac(), ON(), pin_request(), readData(), removeConnection(), removeTrustedDevice(), reset(), scanNetwork(), sendData(), setAutoAccept(), setDiscoveryOptions(), setPublicName(), setSecurity(), and setServiceParameters().

00084 {
00085         parse_data("");
00086 }

Here is the caller graph for this function:

uint8_t WaspBT::parse_data ( char *  answer  )  [private]

It waits for response from the module and executes the proper function.

Parameters:
char* answer : string expected to be answered by the module
Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 90 of file WaspBT.cpp.

References accept_connection(), auto_accept, BT_MANUAL_ACC, data_request(), ending_connection(), get_MTU(), i, MAX_PARSE, millis(), parse_brothers(), parse_device(), pin_request(), printNewline(), serialAvailable(), serialRead(), and waitForData().

00091 {
00092         bool withAnswer = false;
00093         bool match = false;
00094         uint8_t pin_en = 0;
00095         uint8_t lengthAnswer = 0;
00096         long previous=millis();
00097         long previous2=millis();
00098         int16_t interval=50;
00099         int16_t intervalMAX=40000;
00100         uint16_t MAX_BT_DATA=450;
00101         uint8_t* memory = (uint8_t*) calloc(MAX_PARSE,sizeof(uint8_t));
00102         if( memory==NULL ) return -1;
00103         
00104         // Checking if we are waiting for a specific answer
00105         i=0;
00106         while(answer[i]!='\0') i++;
00107         lengthAnswer=i;
00108         if( lengthAnswer ) withAnswer = true;
00109         
00110         if( !(strcmp(answer,"+RDDSCNF=0")) ) interval=30000;
00111         if( !(strcmp(answer,"+RSDSCNF=0")) ){
00112                  interval=10000;
00113                  pin_en=1;
00114         }
00115         if( !(strcmp(answer,"ROK")) ) interval=5000;
00116         if( !(strcmp(answer,"+RCCRCNF")) ){
00117                 interval=10000; 
00118                 pin_en=2;
00119         }
00120 
00121         // Read data from BT meanwhile data is available
00122         i=0;
00123         previous2=millis();
00124         previous=millis();
00125         while( ((millis()-previous)<interval) && ((millis()-previous2)<intervalMAX) && i<MAX_BT_DATA && !match)
00126         {
00127                 if(serialAvailable(0))
00128                 {
00129                         memory[i]=serialRead(0);
00130                         i++;
00131                         previous=millis();
00132                 }
00133                 if( withAnswer ){
00134                         if( waitForData(memory,answer) ) match=true;
00135                 }               
00136                 if( millis()-previous < 0 ) previous=millis();
00137                 if( millis()-previous2 < 0 ) previous2=millis();
00138         }
00139         printNewline(1);
00140                 
00141         // If we are here, the answer has not been found or there wasn't any answer to find
00142         if( waitForData(memory,"+RPCI") ){
00143                 if(!pin_request(memory,pin_en)) match = true;
00144         }
00145         if( waitForData(memory,"+RCOI") && (auto_accept==BT_MANUAL_ACC) ) accept_connection(memory);
00146         if( waitForData(memory,"+RDAI") ){
00147                  if(!data_request(memory)) match = true;
00148         }
00149         if( waitForData(memory,"+RDII") ) ending_connection(memory);
00150         if( waitForData(memory,"+RDDSCNF=0") ) parse_brothers(memory,i);
00151         if( waitForData(memory,"+RSDSCNF=0") ) parse_device(memory);
00152         if( waitForData(memory,"+RCCRCNF") ) get_MTU(memory);
00153                 
00154         if( match ){
00155                 free(memory);
00156                 memory=NULL;
00157                 return 0;
00158         }
00159         
00160         if( withAnswer )
00161         {
00162                 if( i>0 ){
00163                         free(memory);
00164                         memory=NULL;
00165                         return 1;
00166                 }
00167                 else{
00168                         free(memory);
00169                         memory=NULL;
00170                         return 2;
00171                 }
00172         }
00173         else
00174         {
00175                 if( i>0 ){
00176                         free(memory);
00177                         memory=NULL;
00178                         return 3;
00179                 }
00180                 else{
00181                         free(memory);
00182                         memory=NULL;
00183                         return 4;
00184                 }
00185         }
00186         
00187 }

Here is the call graph for this function:

uint8_t WaspBT::pin_request ( uint8_t *  data,
uint8_t  pin_en 
) [private]

It answers to the PIN request.

Parameters:
uint8_t* data : data that has been answered by the module
uint8_t pin_en : specifies if pin is requested
Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 190 of file WaspBT.cpp.

References BT_AT_PIN_REQUEST, bt_pin, i, parse_data(), and printData().

Referenced by parse_data().

00191 {
00192         char command[50];
00193         uint8_t length=0;
00194                 
00195         i=0;
00196         while(bt_pin[i]!='\0') i++;
00197         length=i;       
00198         
00199         if(length<10) sprintf(command,"%s0%d,%s",BT_AT_PIN_REQUEST,length,bt_pin);
00200         else if(length>=10) sprintf(command,"%s%d,%s",BT_AT_PIN_REQUEST,length,bt_pin);
00201         
00202         printData(command);
00203         
00204         if(pin_en==1) return parse_data("+RSDSCNF=0");
00205         if(pin_en==2) return parse_data("+RCCRCNF");
00206         else if(!pin_en) return parse_data("+RSLE");
00207 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspBT::accept_connection ( uint8_t *  data  )  [private]

It accepts incoming connection.

Parameters:
uint8_t* data : data that has been answered by the module
Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 210 of file WaspBT.cpp.

References BT_AT_ACCEPT_CONN, parse_data(), and printData().

Referenced by parse_data().

00211 {
00212         char command[50];       
00213         
00214         sprintf(command,"%s1",BT_AT_ACCEPT_CONN);
00215         
00216         printData(command);
00217         
00218         return parse_data("OK");
00219 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspBT::data_request ( uint8_t *  data  )  [private]

It stores incoming data.

Parameters:
uint8_t* data : data that has been answered by the module
Returns:
'0'

Definition at line 222 of file WaspBT.cpp.

References BT_MAX_DATA, data_received, i, init(), printNewline(), and waitForData().

Referenced by parse_data().

00223 {
00224         uint16_t i=0;
00225         uint16_t j=0;
00226         uint8_t k=0;
00227         uint16_t init=0;
00228         
00229         j=waitForData(data,"+RDAI");
00230         
00231         while(data[j]!=',') j++;
00232         j++;
00233         
00234         while(data[j]!='\r' && i<BT_MAX_DATA){
00235                 data_received[i]=data[j];
00236                 i++;
00237                 j++;
00238         }
00239         printNewline(1);
00240         if(i<BT_MAX_DATA) data_received[i]='\0';
00241         else data_received[BT_MAX_DATA-1]='\0';
00242         
00243         return 0;
00244 }

Here is the call graph for this function:

Here is the caller graph for this function:

void WaspBT::ending_connection ( uint8_t *  data  )  [private]

It changes the value of 'active_connection' variable.

Parameters:
uint8_t* data : data that has been answered by the module

Definition at line 247 of file WaspBT.cpp.

References active_connection.

Referenced by parse_data().

00248 {
00249         active_connection=0;
00250 }

Here is the caller graph for this function:

void WaspBT::parse_brothers ( uint8_t *  data,
uint16_t  number_of_data 
) [private]

It stores the discovered devices in the appropriate array.

Parameters:
uint8_t* data : data that has been answered by the module
uint16_t number_of_data : number of discovered devices

Definition at line 253 of file WaspBT.cpp.

References BT_MAX_DEVICES, Device::CoD, devices_found, discovered_devices, i, Device::mac_address, and Device::name.

Referenced by parse_data().

00254 {
00255         uint8_t i=0;
00256         uint16_t j=0;
00257         uint8_t k=0;
00258         uint8_t end_line=0;
00259         
00260         i=0;
00261         while(i<number_of_data){
00262                 if(data[i]=='\n') end_line++;
00263                 i++;
00264         }
00265 
00266         devices_found=end_line-1;
00267         if(devices_found>BT_MAX_DEVICES) devices_found=BT_MAX_DEVICES;
00268         
00269         i=0;
00270         while( i<(end_line-1) && i<BT_MAX_DEVICES )
00271         {
00272                 while(data[j]!='=' && j<number_of_data) j++;
00273                 j++;
00274                 for(k=0;k<12;k++)
00275                 {
00276                         discovered_devices[i].mac_address[k]=data[j];
00277                         j++;
00278                 }
00279                 j++;
00280                 k=0;
00281                 while(data[j]!=',' && k<18)
00282                 {
00283                         discovered_devices[i].name[k]=data[j];
00284                         j++;
00285                         k++;
00286                 }
00287                 discovered_devices[i].name[k]='\0';
00288                 while(data[j]!=',' && j<number_of_data) j++;
00289                 j++;
00290                 k=0;
00291                 while(data[j]!='\r' && k<6)
00292                 {
00293                         discovered_devices[i].CoD[k]=data[j];
00294                         j++;
00295                         k++;
00296                 }
00297                 discovered_devices[i].CoD[k]='\0';
00298                 i++;
00299                 k=0;
00300         }
00301 }

Here is the caller graph for this function:

void WaspBT::parse_device ( uint8_t *  data  )  [private]

It stores the discovered device parameters.

Parameters:
uint8_t* data : data that has been answered by the module

Definition at line 304 of file WaspBT.cpp.

References device_service_channel, device_service_name, and waitForData().

Referenced by parse_data().

00305 {
00306         uint16_t j=0;
00307         uint8_t k=0;
00308                 
00309         if( waitForData(data,"+RSDSRES=") ){
00310                 while(data[j]!='=') j++;
00311                 j++;
00312                 while(data[j]!=',' && k<16)
00313                 {
00314                         device_service_name[k]=data[j];
00315                         j++;
00316                         k++;
00317                 }
00318                 j++;
00319                 device_service_name[k]='\0';
00320                 device_service_channel[0]=data[j];
00321                 device_service_channel[1]=data[j+1];
00322         }
00323 }

Here is the call graph for this function:

Here is the caller graph for this function:

void WaspBT::get_MTU ( uint8_t *  data  )  [private]

It stores the MTU of the active connection.

Parameters:
uint8_t* data : data that has been answered by the module

Definition at line 326 of file WaspBT.cpp.

References connection_mtu, i, serialFlush(), and serialRead().

Referenced by parse_data().

00327 {
00328         uint8_t i=0;
00329         uint16_t j=0;
00330         uint8_t k=0;
00331         
00332         while(data[j]!='=') j++;
00333         j++;
00334         
00335         connection_mtu[0]=serialRead(0);
00336         connection_mtu[1]=serialRead(0);
00337         connection_mtu[2]=serialRead(0);        
00338         serialFlush(1);
00339 }

Here is the call graph for this function:

Here is the caller graph for this function:

void WaspBT::printData ( char *  data  )  [private]

It sends the data through the UART.

Parameters:
uint8_t* data : data to be sent

Definition at line 342 of file WaspBT.cpp.

References printByte(), and printString().

Referenced by accept_connection(), createConnection(), createStreamConnection(), discoverDevice(), getOwnMac(), pin_request(), removeConnection(), removeTrustedDevice(), reset(), scanNetwork(), sendData(), setAutoAccept(), setDiscoveryOptions(), setPublicName(), setSecurity(), and setServiceParameters().

00343 {
00344         uint8_t uart=0;
00345         
00346         printString(data,uart);
00347         printByte('\r',uart);
00348         printByte('\n',uart);
00349 }

Here is the call graph for this function:

Here is the caller graph for this function:

void WaspBT::ON ( void   ) 

It opens the UART and powers the module.

Definition at line 371 of file WaspBT.cpp.

References beginSerial(), BT_ERROR_ON, digitalWrite(), flag, HIGH, OUTPUT, parse_data(), pinMode(), XBEE_PW, and XBEE_RATE.

00372 {
00373         uint8_t answer=0;
00374         
00375         beginSerial(XBEE_RATE, 0);
00376         pinMode(XBEE_PW,OUTPUT);
00377         digitalWrite(XBEE_PW,HIGH);
00378         
00379         // Waiting for the answer 'ROK'
00380         answer=parse_data("ROK");
00381         
00382         if(answer) flag |= BT_ERROR_ON;
00383 }

Here is the call graph for this function:

void WaspBT::OFF (  ) 

It closes the UART and powers off the module.

Definition at line 386 of file WaspBT.cpp.

References closeSerial(), digitalWrite(), LOW, OUTPUT, pinMode(), and XBEE_PW.

00387 {
00388         closeSerial(0);
00389         pinMode(XBEE_PW,OUTPUT);
00390         digitalWrite(XBEE_PW,LOW);
00391 }

Here is the call graph for this function:

uint8_t WaspBT::init (  ) 

It sets some initial parameters such as security parameters, service parameters, public name, auto accept and discoverable.

Returns:
'0' when the functions are right, '>0' otherwise

Definition at line 395 of file WaspBT.cpp.

References BT_AUTO_ACC, BT_DISCOVERABLE, bt_pin, BT_PUBLIC_NAME, BT_SECURITY_PREDEFINED, BT_SERVICE_CHANNEL, BT_SERVICE_COD, BT_SERVICE_NAME, first, setAutoAccept(), setDiscoveryOptions(), setPublicName(), setSecurity(), and setServiceParameters().

Referenced by data_request().

00396 {
00397         uint8_t error = 0;
00398         
00399         first=1;
00400         
00401         if(setSecurity(BT_SECURITY_PREDEFINED,bt_pin)) error++;
00402                 
00403         if(setServiceParameters(BT_SERVICE_NAME,BT_SERVICE_CHANNEL,BT_SERVICE_COD)) error++;
00404         
00405         if(setPublicName(BT_PUBLIC_NAME)) error++;
00406         
00407         if(setAutoAccept(BT_AUTO_ACC)) error++;
00408         
00409         if(setDiscoveryOptions(BT_DISCOVERABLE)) error++;
00410                 
00411         return error;
00412 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspBT::setSecurity ( uint8_t  mode,
char *  pin 
)

It sets security parameters.

Parameters:
uint8_t mode : security mode (BT_SECURITY_1, BT_SECURITY_NONE, BT_SECURITY_3)
char* pin : the pin to stablish
Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 416 of file WaspBT.cpp.

References BT_AT_SECURITY, BT_ERROR_SECURITY, bt_pin, first, flag, i, parse_data(), printData(), and reset().

Referenced by init().

00417 {
00418         char command[50];
00419         uint8_t length=0;
00420         uint8_t error=0;
00421         
00422         i=0;
00423         while(pin[i]!='\0'){
00424                 bt_pin[i]=pin[i];
00425                 i++;
00426         }
00427         length=i;       
00428         
00429         if(!first) reset();
00430         
00431         if(length<10) sprintf(command,"%s%d,1,1,0%d,%s",BT_AT_SECURITY,mode,length,pin);
00432         else if(length>=10) sprintf(command,"%s%d,1,1,%d,%s",BT_AT_SECURITY,mode,length,pin);
00433         
00434         printData(command);
00435         
00436         first=0;
00437         
00438         error=parse_data("OK");
00439         if(error) flag |= BT_ERROR_SECURITY;
00440         return error;
00441 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspBT::setPublicName ( char *  name  ) 

It sets the public name.

Parameters:
char* name : the public name to stablish
Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 445 of file WaspBT.cpp.

References BT_AT_PUBLIC_NAME, BT_ERROR_NAME, flag, i, parse_data(), and printData().

Referenced by init().

00446 {       
00447         char command[50];
00448         uint8_t length=0;
00449         uint8_t error=0;
00450         
00451         i=0;
00452         while(name[i]!='\0') i++;
00453         length=i;
00454         
00455         if(length<10) sprintf(command,"%s0%d,%s",BT_AT_PUBLIC_NAME,length,name);
00456         else if(length>=10) sprintf(command,"%s%d,%s",BT_AT_PUBLIC_NAME,length,name);
00457         
00458         printData(command);
00459         
00460         error=parse_data("OK");
00461         if(error) flag |= BT_ERROR_NAME;
00462         return error;
00463 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspBT::setAutoAccept ( uint8_t  mode  ) 

It sets auto accepting incoming connections.

Parameters:
uint8_t mode : BT_AUTO_ACC or BT_MANUAL_ACC
Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 467 of file WaspBT.cpp.

References auto_accept, BT_AT_AUTO_ACCEPT, BT_ERROR_ACCEPT, flag, parse_data(), and printData().

Referenced by init().

00468 {
00469         char command[50];
00470         uint8_t error=0;
00471         
00472         auto_accept=mode;       
00473 
00474         sprintf(command,"%s%d",BT_AT_AUTO_ACCEPT,mode);
00475         
00476         printData(command);
00477                 
00478         error=parse_data("OK");
00479         if(error) flag |= BT_ERROR_ACCEPT;
00480         return error;
00481 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspBT::setDiscoveryOptions ( uint8_t  option  ) 

It sets the discovering options.

Parameters:
uint8_t option : the discovering options (BT_NO_DISC, BT_INQ_EN, BT_PAGE_EN, BT_DISCOVERABLE)
Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 485 of file WaspBT.cpp.

References BT_AT_DISCOV_OPT, BT_ERROR_DISC_OPT, flag, parse_data(), and printData().

Referenced by init().

00486 {
00487         char command[50];
00488         uint8_t length=0;
00489         uint8_t error=0;
00490 
00491         sprintf(command,"%s%d",BT_AT_DISCOV_OPT,option);
00492         
00493         printData(command);
00494         
00495         error=parse_data("OK");
00496         if(error) flag |= BT_ERROR_DISC_OPT;
00497         return error;
00498 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspBT::readData (  ) 

It waits for incoming data and stores it in the appropriate array.

Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 501 of file WaspBT.cpp.

References parse_data().

00502 {
00503         return parse_data();
00504 }

Here is the call graph for this function:

uint8_t WaspBT::setServiceParameters ( char *  name,
uint8_t  channel,
char *  cod 
)

It sets the service parameters.

Parameters:
char* name : the service name
uint8_t channel : the service channel
char* cod: Class of Device
Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 507 of file WaspBT.cpp.

References BT_AT_SERVICE_PAR, BT_ERROR_SERVICE, flag, i, parse_data(), and printData().

Referenced by init().

00508 {
00509         char command[50];
00510         uint8_t length=0;
00511         uint8_t error=0;
00512         
00513         i=0;
00514         while(name[i]!='\0') i++;
00515         length=i;       
00516         
00517         if(length<10 && channel<10) sprintf(command,"%s1101,0%d,%s,0%d,%s",BT_AT_SERVICE_PAR,length,name,channel,cod);
00518         else if(length>=10 && channel<10) sprintf(command,"%s1101,%d,%s,0%d,%s",BT_AT_SERVICE_PAR,length,name,channel,cod);
00519         else if(length<10 && channel>=10) sprintf(command,"%s1101,0%d,%s,%d,%s",BT_AT_SERVICE_PAR,length,name,channel,cod);
00520         else if(length>=10 && channel>=10) sprintf(command,"%s1101,%d,%s,%d,%s",BT_AT_SERVICE_PAR,length,name,channel,cod);
00521                 
00522         printData(command);
00523         
00524         error=parse_data("OK");
00525         if(error) flag |= BT_ERROR_SERVICE;
00526         return error;
00527 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspBT::reset (  ) 

It resets the module.

Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 531 of file WaspBT.cpp.

References BT_AT_RESET, BT_ERROR_RESET, flag, parse_data(), and printData().

Referenced by setSecurity().

00532 {       
00533         uint8_t error=0;
00534         
00535         printData(BT_AT_RESET);
00536         
00537         error=parse_data("ROK");
00538         if(error) flag |= BT_ERROR_RESET;
00539         return error;
00540 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspBT::scanNetwork (  ) 

It scans looking for devices. It stores in 'discovered_devices' struct the devices discovered.

Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 544 of file WaspBT.cpp.

References BT_AT_DISCOVER, BT_ERROR_SCAN, flag, parse_data(), and printData().

00545 {       
00546         char command[50];
00547         uint8_t error=0;
00548         
00549         sprintf(command,"%s%d",BT_AT_DISCOVER,0);
00550         
00551         printData(command);
00552         
00553         if(parse_data("OK")) return 1;
00554 
00555         error=parse_data("+RDDSCNF=0");
00556         if(error) flag |= BT_ERROR_SCAN;
00557         return error;
00558 }

Here is the call graph for this function:

uint8_t WaspBT::discoverDevice ( char *  mac,
char *  profile 
)

It searchs for a specific device and stores the service name and service channel in the aprropriate variables.

Parameters:
char* mac : the MAC of the device to find
char* profile : the profile (SPP='1101')
Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 561 of file WaspBT.cpp.

References BT_AT_DISCOVER_DEV, BT_ERROR_DISC, flag, parse_data(), and printData().

00562 {
00563         char command[50];
00564         uint8_t error=0;
00565         
00566         sprintf(command,"%s%s,%s",BT_AT_DISCOVER_DEV,mac,profile);
00567         
00568         printData(command);
00569         
00570         if(parse_data("OK")) return 1;
00571 
00572         error=parse_data("+RSDSCNF=0");
00573         if(error) flag |= BT_ERROR_DISC;
00574         return error;
00575 }

Here is the call graph for this function:

uint8_t WaspBT::createConnection ( char *  mac,
char *  channel 
)

It creates a connection with other module.

Parameters:
char* mac : the MAC of the device to connect to
char* channel : the channel where the device is operating
Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 578 of file WaspBT.cpp.

References active_connection, BT_AT_CONNECT, BT_ERROR_CONNECTING, flag, parse_data(), and printData().

00579 {
00580         char command[50];
00581         uint8_t error=0;
00582         
00583         sprintf(command,"%s%s,%s",BT_AT_CONNECT,mac,channel);
00584         
00585         printData(command);
00586         
00587         if(parse_data("OK")){
00588                 flag |= BT_ERROR_CONNECTING; 
00589                 return 1;
00590         }
00591 
00592         error=parse_data("+RCCRCNF");
00593         if(error) flag |= BT_ERROR_CONNECTING;
00594         else active_connection=1;
00595         
00596         return error;
00597 }

Here is the call graph for this function:

uint8_t WaspBT::getOwnMac (  ) 

It gets the own MAC address. It stores the mac in 'own_mac' variable.

Returns:
'0' on success, '1' if error

Definition at line 600 of file WaspBT.cpp.

References BT_AT_OWN_MAC, BT_ERROR_MAC, flag, i, own_mac, parse_data(), printData(), serialFlush(), and serialRead().

Referenced by removeConnection().

00601 {       
00602         printData(BT_AT_OWN_MAC);
00603         
00604         if(!parse_data("+RRBDRES")){
00605                 i=0;
00606                 while(i<12){
00607                         own_mac[i]=serialRead(0);
00608                         i++;
00609                 }
00610                 serialFlush(1);
00611                 return 0;
00612         }
00613         flag |= BT_ERROR_MAC;
00614         return 1;
00615 }

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t WaspBT::removeTrustedDevice ( char *  mac  ) 

It removes the trusted device specified.

Parameters:
char* mac : the MAC of the device to remove
Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 618 of file WaspBT.cpp.

References BT_AT_DELETE_TD, BT_ERROR_REMOVING_TD, flag, parse_data(), and printData().

00619 {
00620         char command[50];
00621         uint8_t error=0;
00622         
00623         sprintf(command,"%s%s",BT_AT_DELETE_TD,mac);
00624         
00625         printData(command);
00626         
00627         error=parse_data("OK");
00628         if(error) flag |= BT_ERROR_REMOVING_TD;
00629         return error;
00630 }

Here is the call graph for this function:

uint8_t WaspBT::sendData ( char *  data  ) 

It sends data to other module.

Parameters:
char* data : the data to send
Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 633 of file WaspBT.cpp.

References BT_AT_SEND_DATA, BT_ERROR_SENDING_DATA, delay(), flag, i, parse_data(), and printData().

00634 {
00635         uint16_t length=0;
00636         uint8_t error=0;
00637         
00638         i=0;
00639         while(data[i]!='\0') i++;
00640         length=i;       
00641         
00642         char command[20+length];
00643 
00644         if(length<10) sprintf(command,"%s00%d,%s",BT_AT_SEND_DATA,length,data);
00645         else if(length<100 && length>10) sprintf(command,"%s0%d,%s",BT_AT_SEND_DATA,length,data);
00646         else sprintf(command,"%s%d,%s",BT_AT_SEND_DATA,length,data);
00647                 
00648         printData(command);
00649         
00650         error=parse_data("OK");
00651         delay(300);
00652         if(error) flag |= BT_ERROR_SENDING_DATA;
00653         return error;
00654 }

Here is the call graph for this function:

uint8_t WaspBT::removeConnection (  ) 

It removes an active connection.

Returns:
'0' on success, '1' if error

Definition at line 657 of file WaspBT.cpp.

References BT_AT_DISCONNECT, BT_ERROR_REMOVING_CONNECTION, flag, getOwnMac(), parse_data(), and printData().

00658 {       
00659         printData(BT_AT_DISCONNECT);
00660         
00661         if(!parse_data("OK"))
00662         {
00663                 getOwnMac();
00664                 return 0;
00665         }
00666         flag |= BT_ERROR_REMOVING_CONNECTION;
00667         return 1;
00668 }

Here is the call graph for this function:

uint8_t WaspBT::createStreamConnection (  ) 

It creates a transparent communication between two devices.

Returns:
'0' on match with answer, '1' on mismatch with answer, '2' no char received with answer, '3' no error without answer, '4' no char received without answer

Definition at line 670 of file WaspBT.cpp.

References BT_AT_STREAM_CONN, BT_ERROR_STREAM, flag, parse_data(), and printData().

00671 {
00672         uint8_t error=0;
00673 
00674         printData(BT_AT_STREAM_CONN);
00675         
00676         error=parse_data("OK");
00677         if(error) flag |= BT_ERROR_STREAM;
00678         return error;
00679 }       

Here is the call graph for this function:


Field Documentation

uint16_t WaspBT::i [private]

char WaspBT::received[100] [private]

Variable : array for storing the data received from the module.

Definition at line 162 of file WaspBT.h.

Referenced by waitForData().

uint8_t WaspBT::first [private]

Variable : integer to reset the BT module before setting security.

Definition at line 167 of file WaspBT.h.

Referenced by init(), setSecurity(), and waitForData().

Variable : status flag, used to see if there was an error while communicating with the module.

Possible values are : BT_ERROR_ON,

Definition at line 253 of file WaspBT.h.

Referenced by createConnection(), createStreamConnection(), discoverDevice(), getOwnMac(), ON(), removeConnection(), removeTrustedDevice(), reset(), scanNetwork(), sendData(), setAutoAccept(), setDiscoveryOptions(), setPublicName(), setSecurity(), and setServiceParameters().

char WaspBT::bt_pin[16]

Variable : current pin.

Definition at line 387 of file WaspBT.h.

Referenced by init(), pin_request(), setSecurity(), and WaspBT().

Variable : specifies if incoming connections are accepted automatically or not.

Definition at line 392 of file WaspBT.h.

Referenced by parse_data(), setAutoAccept(), and WaspBT().

Variable : specifies if there is an active connection or not.

Definition at line 397 of file WaspBT.h.

Referenced by createConnection(), ending_connection(), and WaspBT().

Variable : stores the discovered devices.

Definition at line 402 of file WaspBT.h.

Referenced by parse_brothers().

Variable : stores the number of discovered devices.

Definition at line 407 of file WaspBT.h.

Referenced by parse_brothers(), and WaspBT().

Variable : stores the service name that a module is using. It is filled when the function 'searchDevice' is called.

Definition at line 412 of file WaspBT.h.

Referenced by parse_device().

Variable : stores the service channel that a module is using. It is filled when the function 'searchDevice' is called.

Definition at line 417 of file WaspBT.h.

Referenced by parse_device().

Variable : stores the maximum MTU can be used in an active connection.

Definition at line 422 of file WaspBT.h.

Referenced by get_MTU().

char WaspBT::own_mac[12]

Variable : stores the MAC of the device.

Definition at line 427 of file WaspBT.h.

Referenced by getOwnMac().

char WaspBT::data_received[BT_MAX_DATA]

Variable : stores the received data.

Definition at line 432 of file WaspBT.h.

Referenced by data_request().


The documentation for this class was generated from the following files:

Generated on Tue Jul 20 09:31:01 2010 for WaspmoteAPI by  doxygen 1.5.6