BLE shield
Fork of X_NUCLEO_IDB0XA1 by
Embed:
(wiki syntax)
Show/hide line numbers
Utils.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #include "Utils.h" 00018 00019 /**************************************************************************/ 00020 /*! 00021 @brief sets values of EN_HIGH_POWER and PA_LEVEL corresponding to dBMLevel of tx power 00022 00023 @returns value of tx power in dbm actually set 00024 00025 @params[in] dBMLevel 00026 dBMLevel of tx power to be set 00027 00028 @params[in] dBMLevel 00029 dBMLevel of tx power to be set 00030 00031 @endcode 00032 */ 00033 /**************************************************************************/ 00034 double getHighPowerAndPALevelValue(int8_t dBMLevel, int8_t& EN_HIGH_POWER, int8_t& PA_LEVEL) { 00035 double dbm = (double) dBMLevel; 00036 if(dbm<-18.0) { 00037 dbm = -18; 00038 EN_HIGH_POWER = 0; 00039 PA_LEVEL = 0; 00040 } 00041 else if(dbm>8.0) { 00042 dbm = 8; 00043 EN_HIGH_POWER = 1; 00044 PA_LEVEL = 7; 00045 } 00046 00047 // As a policy we are setting tx power level to the higher side 00048 if((dbm>-18.0) && (dbm<=-15)) { 00049 // set tx power to -15dBM 00050 EN_HIGH_POWER = 0; 00051 PA_LEVEL = 0; 00052 } 00053 else if((dbm>-15) && (dbm<=-14.7)) { 00054 // set tx power to -14.7dBM 00055 EN_HIGH_POWER = 0; 00056 PA_LEVEL = 1; 00057 } 00058 else if((dbm>-14.7) && (dbm<=-11.7)) { 00059 // set tx power to -11.7dBM 00060 EN_HIGH_POWER = 1; 00061 PA_LEVEL = 1; 00062 } 00063 else if((dbm>-11.7) && (dbm<=-11.4)) { 00064 // set tx power to -11.4dBM 00065 EN_HIGH_POWER = 0; 00066 PA_LEVEL = 2; 00067 } 00068 else if((dbm>-11.4) && (dbm<=-8.4)) { 00069 // set tx power to -8.4dBM 00070 EN_HIGH_POWER = 1; 00071 PA_LEVEL = 2; 00072 } 00073 else if((dbm>-8.4) && (dbm<=-8.1)) { 00074 // set tx power to -8.1dBM 00075 EN_HIGH_POWER = 0; 00076 PA_LEVEL = 3; 00077 } 00078 else if((dbm>-8.1) && (dbm<=-5.1)) { 00079 // set tx power to -5.1dBM 00080 EN_HIGH_POWER = 1; 00081 PA_LEVEL = 3; 00082 } 00083 else if((dbm>-5.1) && (dbm<=-4.9)) { 00084 // set tx power to -4.9dBM 00085 EN_HIGH_POWER = 0; 00086 PA_LEVEL = 4; 00087 } 00088 else if((dbm>-4.9) && (dbm<=-2.1)) { 00089 // set tx power to -2.1dBM 00090 EN_HIGH_POWER = 1; 00091 PA_LEVEL = 4; 00092 } 00093 else if((dbm>-2.1) && (dbm<=-1.6)) { 00094 // set tx power to -1.6dBM 00095 EN_HIGH_POWER = 0; 00096 PA_LEVEL = 5; 00097 } 00098 else if((dbm>-1.6) && (dbm<=1.4)) { 00099 // set tx power to -1.6dBM 00100 EN_HIGH_POWER = 1; 00101 PA_LEVEL = 5; 00102 } 00103 else if((dbm>1.4) && (dbm<=1.7)) { 00104 // set tx power to 1.7dBM 00105 EN_HIGH_POWER = 0; 00106 PA_LEVEL = 6; 00107 } 00108 else if((dbm>1.7) && (dbm<=4.7)) { 00109 // set tx power to 4.7dBM 00110 EN_HIGH_POWER = 1; 00111 PA_LEVEL = 6; 00112 } 00113 else if((dbm>4.7) && (dbm<=5.0)) { 00114 // set tx power to 5.0dBM 00115 EN_HIGH_POWER = 0; 00116 PA_LEVEL = 7; 00117 } 00118 else if((dbm>5.0) && (dbm<=8)) { 00119 // set tx power to 8.0dBM 00120 EN_HIGH_POWER = 1; 00121 PA_LEVEL = 7; 00122 } 00123 00124 return dbm; 00125 }
Generated on Tue Jul 12 2022 19:27:29 by 1.7.2