/* * Copyright 2009 Free Software Foundation, Inc. * * This software is distributed under multiple licenses; see the COPYING file in the main directory for licensing information for this specific distribuion. * * This use of this software may be subject to additional restrictions. * See the LEGAL file in the main directory for details. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include "PowerManager.h" #include #include #include #include #include extern TransceiverManager gTRX; using namespace GSM; void PowerManager::increasePower() { int maxAtten = gConfig.getNum("GSM.Radio.PowerManager.MaxAttenDB"); int minAtten = gConfig.getNum("GSM.Radio.PowerManager.MinAttenDB"); if (mAtten==minAtten) { LOG(DEBUG) << "power already at maximum"; return; } mAtten--; // raise power by reducing attenuation if (mAttenmaxAtten) mAtten=maxAtten; LOG(INFO) << "power increased to -" << mAtten << " dB"; mRadio->setPower(mAtten); } void PowerManager::reducePower() { int maxAtten = gConfig.getNum("GSM.Radio.PowerManager.MaxAttenDB"); int minAtten = gConfig.getNum("GSM.Radio.PowerManager.MinAttenDB"); if (mAtten==maxAtten) { LOG(DEBUG) << "power already at minimum"; return; } mAtten++; // reduce power be increasing attenuation if (mAttenmaxAtten) mAtten=maxAtten; LOG(INFO) << "power decreased to -" << mAtten << " dB"; mRadio->setPower(mAtten); } // internal method, does the control step void PowerManager::internalControlStep() { unsigned target = gConfig.getNum("GSM.Radio.PowerManager.TargetT3122"); LOG(DEBUG) << "Avg T3122 " << mAveragedT3122 << ", target " << target; // Adapt the power. if (mAveragedT3122 > target) reducePower(); else increasePower(); } void PowerManager::sampleT3122() { // Tweak it down a little just in case there's no activity. mSamples[mNextSampleIndex] = gBTS.shrinkT3122(); unsigned numSamples = gConfig.getNum("GSM.Radio.PowerManager.NumSamples"); mNextSampleIndex = (mNextSampleIndex + 1) % numSamples; long sum = 0; for (unsigned i=0; iserviceLoop(); return NULL; } void PowerManager::start() { mRadio = gTRX.ARFCN(0); mRadio->setPower(mAtten); mThread.start((void*(*)(void*))PowerManagerServiceLoopAdapter,this); } // vim: ts=4 sw=4