<commit_before>/* mbed Microcontroller Library
 * Copyright (c) 2018 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

#ifndef MBED_EXTENDED_CONNECT_PARAMETERS_H__
#define MBED_EXTENDED_CONNECT_PARAMETERS_H__

#include "ble/BLETypes.h"
#include "mbed_assert.h"

/**
 * @addtogroup ble
 * @{
 * @addtogroup gap
 * @{
 */

class GapExtendedConnectParameters_t {
    static const uint8_t MAX_PARAM_PHYS = 3;
public:
    GapExtendedConnectParameters_t() :
        _filterPolicy(ble::SCAN_POLICY_FILTER_ALL_ADV),
        _ownAddressType(ble::own_address_type_t::PUBLIC)
    {
        for (uint8_t i = 0; i < MAX_PARAM_PHYS; ++i) {
            _scanInterval[i] = 4;
            _scanWindow[i] = 4;
            _minConnectionInterval[i] = 6;
            _maxConnectionInterval[i] = 6;
            _slaveLatency[i] = 0;
            _connectionSupervisionTimeout[i] = 0xC80;
            _minEventLength[i] = 0;
            _maxEventLength[i] = 0xFFFF;
            _enabledPhy[i] = false;
        }
    };

    /* setters */

    GapExtendedConnectParameters_t& setScanParameters(
        uint32_t scanInterval_us,
        uint32_t scanWindow_us,
        ble::phy_t phy = ble::phy_t::LE_1M
    ) {
        uint8_t phy_index = handlePhyToggle(phy, true);

        _scanInterval[phy_index] = scanInterval_us / 625;
        _scanWindow[phy_index] = scanWindow_us / 625;

        ble::clamp(_scanInterval[phy_index], 0x0004, 0xFFFF);
        ble::clamp(_scanWindow[phy_index], 0x0004, 0xFFFF);

        return *this;
    }

    GapExtendedConnectParameters_t& setConnectionParameters(
        uint16_t minConnectionInterval_ms,
        uint16_t maxConnectionInterval_ms,
        uint16_t slaveLatency,
        uint16_t connectionSupervisionTimeout_ms,
        uint32_t _minEventLength_us,
        uint32_t _maxEventLength_us,
        ble::phy_t phy = ble::phy_t::LE_1M
    ) {
        uint8_t phy_index = handlePhyToggle(phy, true);

        _minConnectionInterval[phy_index] = (((uint32_t)minConnectionInterval_ms) * 1000) / 1250;
        _maxConnectionInterval[phy_index] = (((uint32_t)maxConnectionInterval_ms) * 1000) / 1250;
        _slaveLatency[phy_index] = slaveLatency;

        ble::clamp(_minConnectionInterval[phy_index], 0x0006, 0x0C80);
        ble::clamp(_maxConnectionInterval[phy_index], 0x0006, 0x0C80);
        ble::clamp(_slaveLatency[phy_index], 0x0000, 0x01F3);

        /* avoid overlfow */
        uint32_t connectionSupervisionTimeout_10ms = connectionSupervisionTimeout_ms * 10;
        ble::clamp(connectionSupervisionTimeout_10ms, 0x000A, 0x0C80);
        _connectionSupervisionTimeout[phy_index] = connectionSupervisionTimeout_10ms;

        /* avoid overflows and truncation */
        _minEventLength_us = _minEventLength_us / 625;
        _maxEventLength_us = _maxEventLength_us / 625;

        ble::clamp(_minEventLength_us, 0x0000, 0xFFFF);
        ble::clamp(_maxEventLength_us, 0x0000, 0xFFFF);

        _minEventLength[phy_index] = _minEventLength_us;
        _maxEventLength[phy_index] = _maxEventLength_us;

        return *this;
    }

    GapExtendedConnectParameters_t& setScanParamteres(
        ble::own_address_type_t ownAddress
    ) {
        _ownAddressType = ownAddress;

        return *this;
    }

    GapExtendedConnectParameters_t& setScanParamteres(
        ble::scanning_policy_mode_t filterPolicy
    ) {
        _filterPolicy = filterPolicy;

        return *this;
    }<commit_msg>default values and func names<commit_after>/* mbed Microcontroller Library
 * Copyright (c) 2018 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
*/

#ifndef MBED_EXTENDED_CONNECT_PARAMETERS_H__
#define MBED_EXTENDED_CONNECT_PARAMETERS_H__

#include "ble/BLETypes.h"
#include "mbed_assert.h"

/**
 * @addtogroup ble
 * @{
 * @addtogroup gap
 * @{
 */

class GapExtendedConnectParameters_t {
    static const uint8_t MAX_PARAM_PHYS = 3;
public:
    GapExtendedConnectParameters_t() :
        _filterPolicy(ble::SCAN_POLICY_IGNORE_WHITELIST),
        _ownAddressType(ble::own_address_type_t::PUBLIC)
    {
        for (uint8_t i = 0; i < MAX_PARAM_PHYS; ++i) {
            _scanInterval[i] = 4;
            _scanWindow[i] = 4;
            _minConnectionInterval[i] = 6;
            _maxConnectionInterval[i] = 6;
            _slaveLatency[i] = 0;
            _connectionSupervisionTimeout[i] = 0xC80;
            _minEventLength[i] = 0;
            _maxEventLength[i] = 0xFFFF;
            _enabledPhy[i] = false;
        }
    };

    /* setters */

    GapExtendedConnectParameters_t& setScanParameters(
        uint32_t scanInterval_us,
        uint32_t scanWindow_us,
        ble::phy_t phy = ble::phy_t::LE_1M
    ) {
        uint8_t phy_index = handlePhyToggle(phy, true);

        _scanInterval[phy_index] = scanInterval_us / 625;
        _scanWindow[phy_index] = scanWindow_us / 625;

        ble::clamp(_scanInterval[phy_index], 0x0004, 0xFFFF);
        ble::clamp(_scanWindow[phy_index], 0x0004, 0xFFFF);

        return *this;
    }

    GapExtendedConnectParameters_t& setConnectionParameters(
        uint16_t minConnectionInterval_ms,
        uint16_t maxConnectionInterval_ms,
        uint16_t slaveLatency,
        uint16_t connectionSupervisionTimeout_ms,
        ble::phy_t phy = ble::phy_t::LE_1M,
        uint32_t _minEventLength_us = 0,
        uint32_t _maxEventLength_us = 0xFFFF
    ) {
        uint8_t phy_index = handlePhyToggle(phy, true);

        _minConnectionInterval[phy_index] = (((uint32_t)minConnectionInterval_ms) * 1000) / 1250;
        _maxConnectionInterval[phy_index] = (((uint32_t)maxConnectionInterval_ms) * 1000) / 1250;
        _slaveLatency[phy_index] = slaveLatency;

        ble::clamp(_minConnectionInterval[phy_index], 0x0006, 0x0C80);
        ble::clamp(_maxConnectionInterval[phy_index], 0x0006, 0x0C80);
        ble::clamp(_slaveLatency[phy_index], 0x0000, 0x01F3);

        /* avoid overlfow */
        uint32_t connectionSupervisionTimeout_10ms = connectionSupervisionTimeout_ms * 10;
        ble::clamp(connectionSupervisionTimeout_10ms, 0x000A, 0x0C80);
        _connectionSupervisionTimeout[phy_index] = connectionSupervisionTimeout_10ms;

        /* avoid overflows and truncation */
        _minEventLength_us = _minEventLength_us / 625;
        _maxEventLength_us = _maxEventLength_us / 625;

        ble::clamp(_minEventLength_us, 0x0000, 0xFFFF);
        ble::clamp(_maxEventLength_us, 0x0000, 0xFFFF);

        _minEventLength[phy_index] = _minEventLength_us;
        _maxEventLength[phy_index] = _maxEventLength_us;

        return *this;
    }

    GapExtendedConnectParameters_t& setOwnAddressType(
        ble::own_address_type_t ownAddress
    ) {
        _ownAddressType = ownAddress;

        return *this;
    }

    GapExtendedConnectParameters_t& setFilterPolicy(
        ble::scanning_policy_mode_t filterPolicy
    ) {
        _filterPolicy = filterPolicy;

        return *this;
    }
{'fraction_non_alphanumeric': 0.08702232311766932, 'fraction_numerical': 0.036322360953461974, 'mean_word_length': 3.1758820431806214, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3629243', 'n_tokens_mistral': 2760, 'n_tokens_neox': 2499, 'n_words': 510}