📄 bluetooth.h
字号:
/*
============================================================================================
Name : Bluetooth.h
Author : BluetoothAPI is a initiative of Embedded LAB - http://www.embedded.ufcg.edu.br/
OpenC/SymbianC++ - http://efforts.embedded.ufcg.edu.br/symbiancpp
Version :
Copyright : This file is part of BluetoothAPI.
Bluetooth is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
BluetoothAPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BluetoothAPI. If not, see <http://www.gnu.org/licenses/>.
Description : Bluetooth.h implementation
===========================================================================================
*/
#ifndef BLUETOOTH_H_
#define BLUETOOTH_H_
#include <vector>
using namespace std;
/**
* Struct that contains the necessary data of a bluettoh device
* to connect: Name, Address and Communication port number
*/
struct BTDeviceData
{
char devName[256];
char devAdr[32];
unsigned int RfCommServicePort;
};
/**
* BluetoothAPIListener
* Inteface to listen the BluetoothAPI and notify important chages
*/
class BluetoothAPIListener
{
public:
/**
* Virtual callback to notify the end of the search for devices
* and pass a vector data with the devices on the bluetooth network
* @param discoveredDeviceList, a vetor to be updated with data of devices on the network
*/
virtual void devicesDiscoverFinished( vector<BTDeviceData>& discoveredDeviceList )=0;
/**
* Virtual callback to notify the end of the search for a specific service on the devices found
* and pass a vector data with the devices with that service
* @param discoveredServiceList, a vetor to be updated with data of devices with the desired service
*/
virtual void servicesDiscoverFinished( vector<BTDeviceData>& discoveredServiceList )=0;
/**
* Virtual callback to notify that the device in use achieved to connect as a server
*/
virtual void serverConnected()=0;
/**
* Virtual callback to notify that the device in use disconnected, or was disconnected, as a server
*/
virtual void serverDisconnected()=0;
/**
* Virtual callback to notify that the device in use achieved to connect as a client
*/
virtual void clientConnected()=0;
/**
* Virtual callback to notify that the device in use disconnected, or was disconnected, as a client
*/
virtual void clientDisconnected()=0;
/**
* Virtual callback to notify that the device in use recieved a message and pass this message
* @param message, message received by the device in use
*/
virtual void messageReceived( char* message)=0;
/**
* Virtual callback to notify that the device in use sent a message
*/
virtual void messageSent()=0;
/**
* Virtual callback to notify an error ocurred
* @param err, variable with the value of error occurred
*/
virtual void errorOcurred(int err)=0;
};
//CLASS DECLARATIONS
/**
* BluetoothAPI class.
* Provides an easy use of the bluetooth available resources
*/
class BluetoothAPI
{
public: //public members
/**
* Class constructor
* @param listener, pointer of a user class to be notified when changes occur
* @return a BluetoothAPI pointer
*/
IMPORT_C static BluetoothAPI* create( BluetoothAPIListener *listener );
/**
* This function starts the search for bluetooth devices in the area
*/
IMPORT_C void searchDevices();
/**
* This function starts the search for a specific service on the found devices
* @param BTServiceUUID, short-form identifier of the service to be searched
*/
IMPORT_C void searchServices(unsigned long int BTServiceUUID);
/**
* This function starts the search for a specific service on the found devices
* @param BTServiceUUID1, highest part of identifier of the service to be searched
* @param BTServiceUUID2, second highest part of identifier of the service to be searched
* @param BTServiceUUID3, second lowest part of identifier of the service to be searched
* @param BTServiceUUID4, lowest part of identifier of the service to be searched
*/
IMPORT_C void searchServices(unsigned long int BTServiceUUID1,
unsigned long int BTServiceUUID2, unsigned long int BTServiceUUID3,
unsigned long int BTServiceUUID4);
/**
* This function connects the device to a server of the device passed as parameter
* @param deviceData, data of the device with user wants to connect
*/
IMPORT_C void connectToServer(BTDeviceData deviceData);
/**
* This function starts the server advetising of a specific service
* @param BTServiceUUID, short-form identifier of the service to be advertised
* @param BTServiceName, name of de service advertised
*/
IMPORT_C void startAdvertising(unsigned long int BTServiceUUID,
char* BTServiceName );
/**
* This function starts the server advetising of a specific service
* @param BTServiceUUID1, highest part of identifier of the service to be advertised
* @param BTServiceUUID2, second highest part of identifier of the service to be advertised
* @param BTServiceUUID3, second lowest part of identifier of the service to be advertised
* @param BTServiceUUID4, lowest part of identifier of the service to be advertised
* @param BTServiceName, name of de service advertised
*/
IMPORT_C void startAdvertising(unsigned long int BTServiceUUID1,
unsigned long int BTServiceUUID2, unsigned long int BTServiceUUID3,
unsigned long int BTServiceUUID4, char* BTServiceName );
/**
* This function stops a server connection or the advertising of a service,
* must be called when the application is closed, otherwise the advertising will
* continue with the application closed
*/
IMPORT_C void stopServerAndAdvertising();
/**
* This class closes the connection to the server, if the device in use is the client
*/
IMPORT_C void disconnectAsClient();
/**
* This class gives access to the list of founded devices
* @return a vector with data of the founded devices
*/
IMPORT_C vector<BTDeviceData>& foundDevicesList();
/**
* This class gives access to the list of devices with the searched service
* @return a vector with data of the devices with the searched service
*/
IMPORT_C vector<BTDeviceData>& foundServicesList();
/**
* Class destructor
*/
IMPORT_C virtual ~BluetoothAPI();
/**
* This function sends a message to the device connected with the device in use,
* The first message must be sent by the client, then the client and server must
* alternate in sending messages.
* @param message, message to be sent
*/
IMPORT_C void sendMessage(char* message);
};
#endif /* BLUETOOTH_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -