Bluetooth uuid converter

two functions convert uuid to defined service/characteristic name char *uuidToServiceName(char *raw_data), char *uuidToCharacteristicName(char *raw_data) in : uuid out : service/characteristc name
/*
 * ble_attribute.c
 *
 *  Created on: Feb 25, 2016
 *      Author: 
 */


#define LOG_TAG "GattAttributes"

char *GattServices[][2] =
		{{"00002b30-0000-1000-8000-00805f9b34fb", "Advertising Interval"},
		{"00002b20-0000-1000-8000-00805f9b34fb", "Acceleration/Orientation"},
		{"00002b10-0000-1000-8000-00805f9b34fb", "Temperature"},
		{"00001811-0000-1000-8000-00805f9b34fb", "Alert Notification Service"},
		{"0000180f-0000-1000-8000-00805f9b34fb", "Battery Service"},
		{"00001810-0000-1000-8000-00805f9b34fb", "Blood Pressure"},
		{"00001805-0000-1000-8000-00805f9b34fb", "Current Time Service"},
		{"00001818-0000-1000-8000-00805f9b34fb", "Cycling Power"},
		{"00001816-0000-1000-8000-00805f9b34fb", "Cycling Speed and Cadence"},
		{"0000180a-0000-1000-8000-00805f9b34fb", "Device Information"},
		{"00001800-0000-1000-8000-00805f9b34fb", "Generic Access"},
		{"00001801-0000-1000-8000-00805f9b34fb", "Generic Attribute"},
		{"00001808-0000-1000-8000-00805f9b34fb", "Glucose"},
		{"00001809-0000-1000-8000-00805f9b34fb", "Health Thermometer"},
		{"0000180d-0000-1000-8000-00805f9b34fb", "Heart Rate"},
		{"00001812-0000-1000-8000-00805f9b34fb", "Human Interface Device"},
		{"00001802-0000-1000-8000-00805f9b34fb", "Immediate Alert"},
		{"00001803-0000-1000-8000-00805f9b34fb", "Link Loss"},
		{"00001819-0000-1000-8000-00805f9b34fb", "Location and Navigation"},
		{"00001807-0000-1000-8000-00805f9b34fb", "Next DST Change Service"},
		{"0000180e-0000-1000-8000-00805f9b34fb", "Phone Alert Status Service"},
		{"00001806-0000-1000-8000-00805f9b34fb", "Reference Time Update Service"},
		{"00001814-0000-1000-8000-00805f9b34fb", "Running Speed and Cadence"},
		{"00001813-0000-1000-8000-00805f9b34fb", "Scan Parameters"},
		{"00001804-0000-1000-8000-00805f9b34fb", "Tx Power"},
		{"00001930-0000-1000-8000-00805f9b34fb", "Advertising Interval Service"},
		{"00001910-0000-1000-8000-00805f9b34fb", "Temperature Service"},
		{"00001920-0000-1000-8000-00805f9b34fb", "Acceleration/Orientation Service"}};

char *GattCharacteristics[][2] =
		{{"00002a43-0000-1000-8000-00805f9b34fb","Alert Category ID"},
		{"00002a42-0000-1000-8000-00805f9b34fb","Alert Category ID Bit Mask"},
		{"00002a06-0000-1000-8000-00805f9b34fb","Alert Level"},
		{"00002a44-0000-1000-8000-00805f9b34fb","Alert Notification Control Point"},
		{"00002a3F-0000-1000-8000-00805f9b34fb","Alert Status"},
		{"00002a01-0000-1000-8000-00805f9b34fb","Appearance"},
		{"00002a19-0000-1000-8000-00805f9b34fb","Battery Level"},
		{"00002a49-0000-1000-8000-00805f9b34fb","Blood Pressure Feature"},
		{"00002a35-0000-1000-8000-00805f9b34fb", "Blood Pressure Measurement"},
		{"00002a38-0000-1000-8000-00805f9b34fb", "Body Sensor Location"},
		{"00002a22-0000-1000-8000-00805f9b34fb", "Boot Keyboard Input Report"},
		{"00002a32-0000-1000-8000-00805f9b34fb", "Boot Keyboard Output Report"},
		{"00002a33-0000-1000-8000-00805f9b34fb", "Boot Mouse Input Report"},
		{"00002a5a-0000-1000-8000-00805f9b34fb", "CSC Feature"},
		{"00002a5b-0000-1000-8000-00805f9b34fb", "CSC Measurement"},
		{"00002a2b-0000-1000-8000-00805f9b34fb", "Current Time"},
		{"00002a66-0000-1000-8000-00805f9b34fb", "Cycling Power Control Point"},
		{"00002a65-0000-1000-8000-00805f9b34fb", "Cycling Power Feature"},
		{"00002a63-0000-1000-8000-00805f9b34fb", "Cycling Power Measurement"},
		{"00002a64-0000-1000-8000-00805f9b34fb", "Cycling Power Vector"},
		{"00002a08-0000-1000-8000-00805f9b34fb", "Date Time"},
		{"00002a0a-0000-1000-8000-00805f9b34fb", "Day Date Time"},
		{"00002a09-0000-1000-8000-00805f9b34fb", "Day of Week"},
		{"00002a00-0000-1000-8000-00805f9b34fb", "Device Name"},
		{"00002a0d-0000-1000-8000-00805f9b34fb", "DST Offset"},
		{"00002a0c-0000-1000-8000-00805f9b34fb", "Exact Time 256"},
		{"00002a26-0000-1000-8000-00805f9b34fb", "Firmware Revision String"},
		{"00002a51-0000-1000-8000-00805f9b34fb", "Glucose Feature"},
		{"00002a18-0000-1000-8000-00805f9b34fb", "Glucose Measurement"},
		{"00002a34-0000-1000-8000-00805f9b34fb", "Glucose Measurement Context"},
		{"00002a27-0000-1000-8000-00805f9b34fb", "Hardware Revision String"},
		{"00002a39-0000-1000-8000-00805f9b34fb", "Heart Rate Control Point"},
		{"00002a37-0000-1000-8000-00805f9b34fb", "Heart Rate Measurement"},
		{"00002a4c-0000-1000-8000-00805f9b34fb", "HID Control Point"},
		{"00002a4a-0000-1000-8000-00805f9b34fb", "HID Information"},
		{"00002a2a-0000-1000-8000-00805f9b34fb", "IEEE 11073-20601 Regulatory Certification Data List"},
		{"00002a36-0000-1000-8000-00805f9b34fb", "Intermediate Cuff Pressure"},
		{"00002a1e-0000-1000-8000-00805f9b34fb", "Intermediate Temperature"},
		{"00002a6b-0000-1000-8000-00805f9b34fb", "LN Control Point"},
		{"00002a6a-0000-1000-8000-00805f9b34fb", "LN Feature"},
		{"00002a0f-0000-1000-8000-00805f9b34fb", "Local Time Information"},
		{"00002a67-0000-1000-8000-00805f9b34fb", "Location and Speed"},
		{"00002a29-0000-1000-8000-00805f9b34fb", "Manufacturer Name String"},
		{"00002a21-0000-1000-8000-00805f9b34fb", "Measurement Interval"},
		{"00002a24-0000-1000-8000-00805f9b34fb", "Model Number String"},
		{"00002a68-0000-1000-8000-00805f9b34fb", "Navigation"},
		{"00002a46-0000-1000-8000-00805f9b34fb", "New Alert"},
		{"00002a04-0000-1000-8000-00805f9b34fb", "Peripheral Preferred Connection Parameters"},
		{"00002a02-0000-1000-8000-00805f9b34fb", "Peripheral Privacy Flag"},
		{"00002a50-0000-1000-8000-00805f9b34fb", "PnP ID"},
		{"00002a69-0000-1000-8000-00805f9b34fb", "Position Quality"},
		{"00002a4e-0000-1000-8000-00805f9b34fb", "Protocol Mode"},
		{"00002a03-0000-1000-8000-00805f9b34fb", "Reconnection Address"},
		{"00002a52-0000-1000-8000-00805f9b34fb", "Record Access Control Point"},
		{"00002a14-0000-1000-8000-00805f9b34fb", "Reference Time Information"},
		{"00002a4d-0000-1000-8000-00805f9b34fb", "Report"},
		{"00002a4b-0000-1000-8000-00805f9b34fb", "Report Map"},
		{"00002a40-0000-1000-8000-00805f9b34fb", "Ringer Control Point"},
		{"00002a41-0000-1000-8000-00805f9b34fb", "Ringer Setting"},
		{"00002a54-0000-1000-8000-00805f9b34fb", "RSC Feature"},
		{"00002a53-0000-1000-8000-00805f9b34fb", "RSC Measurement"},
		{"00002a55-0000-1000-8000-00805f9b34fb", "SC Control Point"},
		{"00002a4f-0000-1000-8000-00805f9b34fb", "Scan Interval Window"},
		{"00002a31-0000-1000-8000-00805f9b34fb", "Scan Refresh"},
		{"00002a5d-0000-1000-8000-00805f9b34fb", "Sensor Location"},
		{"00002a25-0000-1000-8000-00805f9b34fb", "Serial Number String"},
		{"00002a05-0000-1000-8000-00805f9b34fb", "Service Changed"},
		{"00002a28-0000-1000-8000-00805f9b34fb", "Software Revision String"},
		{"00002a47-0000-1000-8000-00805f9b34fb", "Supported New Alert Category"},
		{"00002a48-0000-1000-8000-00805f9b34fb", "Supported Unread Alert Category"},
		{"00002a23-0000-1000-8000-00805f9b34fb", "System ID"},
		{"00002a1c-0000-1000-8000-00805f9b34fb", "Temperature Measurement"},
		{"00002a1d-0000-1000-8000-00805f9b34fb", "Temperature Type"},
		{"00002a12-0000-1000-8000-00805f9b34fb", "Time Accuracy"},
		{"00002a13-0000-1000-8000-00805f9b34fb", "Time Source"},
		{"00002a16-0000-1000-8000-00805f9b34fb", "Time Update Control Point"},
		{"00002a17-0000-1000-8000-00805f9b34fb", "Time Update State"},
		{"00002a11-0000-1000-8000-00805f9b34fb", "Time with DST"},
		{"00002a0e-0000-1000-8000-00805f9b34fb", "Time Zone"},
		{"00002a07-0000-1000-8000-00805f9b34fb", "Tx Power Level"},
		{"00002a45-0000-1000-8000-00805f9b34fb", "Unread Alert Status"}};


char *uuidToServiceName(char *raw_data)
{
	bool found = FALSE;
	int begin = 0;
	char *string = NULL;

	do
	{
		if(begin == (sizeof(GattServices) / sizeof(GattServices[0])))
		{
			string = "Unknown Service";
			break;
		}

		if(strcmp(raw_data, GattServices[begin][0]) != 0)
		{
			begin++;
		}
		else
		{
			string = GattServices[begin][1];
			found = TRUE;
		}
	}while(found == FALSE);

	return string;
}


char *uuidToCharacteristicName(char *raw_data)
{
	bool found = FALSE;
	int begin = 0;
	char *string = NULL;

	do
	{
		if(begin == (sizeof(GattCharacteristics) / sizeof(GattCharacteristics[0])))
		{
			string = "Unknown Characteristic";
			break;
		}

		if(strcmp(raw_data, GattCharacteristics[begin][0]) != 0)
		{
			begin++;
		}
		else
		{
			string = GattCharacteristics[begin][1];
			found = TRUE;
		}
	}while(found == FALSE);

	return string;
}

Responses

0 Replies