<commit_before>/*
 * Copyright (C) 2015 Freie Universität Berlin
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License v2.1. See the file LICENSE in the top level
 * directory for more details.
 */

/**
 * @ingroup     drivers_ng_at86rf2xx
 * @{
 *
 * @file
 * @brief       Getter and setter functions for the AT86RF2xx drivers
 *
 * @author      <NAME> <thomas.eichinger@fu-berlin.de>
 * @author      <NAME> <hauke.petersen@fu-berlin.de>
 * @author      <NAME> <<EMAIL>>
 *
 * @}
 */

#include "ng_at86rf2xx.h"
#include "ng_at86rf2xx_internal.h"
#include "ng_at86rf2xx_registers.h"
#include "periph/spi.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

#ifdef MODULE_NG_AT86RF212B
static const uint8_t dbm_to_tx_pow_868[] = {0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18,
                                        0x17, 0x15, 0x14, 0x13, 0x12, 0x11,
                                        0x10, 0x0f, 0x31, 0x30, 0x2f, 0x94,
                                        0x93, 0x91, 0x90, 0x29, 0x49, 0x48,
                                        0x47, 0xad, 0xcd, 0xcc, 0xcb, 0xea,
                                        0xe9, 0xe8, 0xe7, 0xe6, 0xe4, 0x80,
                                        0xa0};
static const uint8_t dbm_to_tx_pow_915[] = {0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x17,
                                        0x16, 0x15, 0x14, 0x13, 0x12, 0x11,
                                        0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b,
                                        0x09, 0x91, 0x08, 0x07, 0x05, 0x27,
                                        0x04, 0x03, 0x02, 0x01, 0x00, 0x86,
                                        0x40, 0x84, 0x83, 0x82, 0x80, 0xc1,
                                        0xc0};
int16_t tx_pow_to_dbm(ng_at86rf2xx_freq_t freq, uint8_t reg) {
    for(int i = 0; i < 38; i++){
        if(freq == NG_AT86RF2XX_FREQ_868MHZ){
            if (dbm_to_tx_pow_868[i] == reg) {
                return i -25;
            }
        } else if (freq == NG_AT86RF2XX_FREQ_915MHZ){
            if (dbm_to_tx_pow_915[i] == reg) {
                return i -25;
            }
        }
    }
    return 0;
}

#elif MODULE_NG_AT86RF233
static const int16_t tx_pow_to_dbm[] = {4, 4, 3, 3, 2, 2, 1,
                                        0, -1, -2, -3, -4, -6, -8, -12, -17};
static const uint8_t dbm_to_tx_pow[] = {0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
                                        0x0e, 0x0d, 0x0d, 0x0d, 0x0c, 0x0c,
                                        0x0b, 0x0b, 0x0a, 0x09, 0x08, 0x07,
                                        0x06, 0x05, 0x03,0x00};
#else
static const int16_t tx_pow_to_dbm[] = {3, 3, 2, 2, 1, 1, 0,
                                        -1, -2, -3, -4, -5, -7, -9, -12, -17};<commit_msg>drivers/ng_at86rf2xx: correct array bounds on tx_pow_to_dbm<commit_after>/*
 * Copyright (C) 2015 Freie Universität Berlin
 *
 * This file is subject to the terms and conditions of the GNU Lesser
 * General Public License v2.1. See the file LICENSE in the top level
 * directory for more details.
 */

/**
 * @ingroup     drivers_ng_at86rf2xx
 * @{
 *
 * @file
 * @brief       Getter and setter functions for the AT86RF2xx drivers
 *
 * @author      <NAME> <thomas.eichinger@fu-berlin.de>
 * @author      <NAME> <hauke.petersen@fu-berlin.de>
 * @author      <NAME> <<EMAIL>>
 *
 * @}
 */

#include "ng_at86rf2xx.h"
#include "ng_at86rf2xx_internal.h"
#include "ng_at86rf2xx_registers.h"
#include "periph/spi.h"

#define ENABLE_DEBUG (0)
#include "debug.h"

#ifdef MODULE_NG_AT86RF212B
/* See: Table 9-15. Recommended Mapping of TX Power, Frequency Band, and
 * PHY_TX_PWR (register 0x05), AT86RF212B data sheet. */
static const uint8_t dbm_to_tx_pow_868[] = {0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18,
                                            0x17, 0x15, 0x14, 0x13, 0x12, 0x11,
                                            0x10, 0x0f, 0x31, 0x30, 0x2f, 0x94,
                                            0x93, 0x91, 0x90, 0x29, 0x49, 0x48,
                                            0x47, 0xad, 0xcd, 0xcc, 0xcb, 0xea,
                                            0xe9, 0xe8, 0xe7, 0xe6, 0xe4, 0x80,
                                            0xa0};
static const uint8_t dbm_to_tx_pow_915[] = {0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x17,
                                            0x16, 0x15, 0x14, 0x13, 0x12, 0x11,
                                            0x10, 0x0f, 0x0e, 0x0d, 0x0c, 0x0b,
                                            0x09, 0x91, 0x08, 0x07, 0x05, 0x27,
                                            0x04, 0x03, 0x02, 0x01, 0x00, 0x86,
                                            0x40, 0x84, 0x83, 0x82, 0x80, 0xc1,
                                            0xc0};
int16_t tx_pow_to_dbm(ng_at86rf2xx_freq_t freq, uint8_t reg) {
    for(int i = 0; i < 37; i++){
        if(freq == NG_AT86RF2XX_FREQ_868MHZ){
            if (dbm_to_tx_pow_868[i] == reg) {
                return i -25;
            }
        } else if (freq == NG_AT86RF2XX_FREQ_915MHZ){
            if (dbm_to_tx_pow_915[i] == reg) {
                return i -25;
            }
        }
    }
    return 0;
}

#elif MODULE_NG_AT86RF233
static const int16_t tx_pow_to_dbm[] = {4, 4, 3, 3, 2, 2, 1,
                                        0, -1, -2, -3, -4, -6, -8, -12, -17};
static const uint8_t dbm_to_tx_pow[] = {0x0f, 0x0f, 0x0f, 0x0e, 0x0e, 0x0e,
                                        0x0e, 0x0d, 0x0d, 0x0d, 0x0c, 0x0c,
                                        0x0b, 0x0b, 0x0a, 0x09, 0x08, 0x07,
                                        0x06, 0x05, 0x03,0x00};
#else
static const int16_t tx_pow_to_dbm[] = {3, 3, 2, 2, 1, 1, 0,
                                        -1, -2, -3, -4, -5, -7, -9, -12, -17};
{'fraction_non_alphanumeric': 0.1105318039624609, 'fraction_numerical': 0.1251303441084463, 'mean_word_length': 1.3673385438091321, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 54, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1999984', 'n_tokens_mistral': 2615, 'n_tokens_neox': 2205, 'n_words': 527}