classdef helperBluetoothID
%helperBluetoothID Bluetooth identifiers and their names assigned by the
%Bluetooth Special Interest Group (SIG)
%   BLEIDENTIFIERS = helperBluetoothID creates an object having Bluetooth
%   identifiers and their names assigned by Bluetooth SIG.
%
%   helperBluetoothID properties:
%
%   BluetoothNameValues   - List of Bluetooth identifier names given by
%                           Bluetooth SIG
%
%   See also helperBLEGATTClient, helperBLEGATTServer.

%   Copyright 2018 The MathWorks, Inc.
    
properties(Constant)
    %BluetoothNameValues List of Bluetooth identifiers
    %   BluetoothNameValues is a cell array. Each element represents a
    %   Bluetooth identifier assigned by Bluetooth SIG. Currently this
    %   array contains Bluetooth identifiers corresponding to heart rate
    %   profile, more identifiers can be added to this list to support
    %   other profiles.
    BluetoothNameValues = {'Primary service', 'Characteristic', ...
        'Client characteristic configuration descriptor', ...
        'Heart rate', 'Heart rate measurement', 'Body sensor location'}
end

methods(Static)
    function types = getAttributeTypes()
        types = helperBluetoothID.BluetoothNameValues;
    end

    function types = getCharacteristicTypes()
        types = helperBluetoothID.BluetoothNameValues(4:end);
    end

    function types = getCharacteristicDescriptorTypes()
        types = helperBluetoothID.BluetoothNameValues(3);
    end

    function bluetoothName = getBluetoothName(bluetoothID)
        bluetoothName = '';
        if isrow(bluetoothID)
            ble.internal.validateHex(bluetoothID, 4, 'bluetoothID');
            bluetoothIdentifier = bluetoothID;
        else
            validateattributes(bluetoothID, {'char'}, {'ncols', 2, 'nrows', 2}, ...
                '', 'bluetoothID');
            bluetoothIdentifier = [bluetoothID(2, :) bluetoothID(1, :)];
        end
        switch bluetoothIdentifier
            case '2800'
                bluetoothName = 'Primary service';
            case '2803'
                bluetoothName = 'Characteristic';
            case '2902'
                bluetoothName = 'Client characteristic configuration descriptor';
            case '180D'
                bluetoothName = 'Heart rate';
            case '2A37'
                bluetoothName = 'Heart rate measurement';
            case '2A38'
                bluetoothName = 'Body sensor location';
        end
    end

    function bluetoothID = getBluetoothID(bluetoothName)
        bluetoothID = '';
        validatestring(bluetoothName, helperBluetoothID.BluetoothNameValues, ...
            '', 'bluetoothName', 1);
        switch bluetoothName
            case 'Primary service'
                bluetoothID = '2800';
            case 'Characteristic'
                bluetoothID = '2803';
            case 'Client characteristic configuration descriptor'
                bluetoothID = '2902';
            case 'Heart rate'
                bluetoothID = '180D';
            case 'Heart rate measurement'
                bluetoothID = '2A37';
            case 'Body sensor location'
                bluetoothID = '2A38';
        end
    end
end
end

