📄 rf_pm.~cpp
字号:
//#include "meta2.h"
#include <IniFiles.hpp>
#include "form_RFTool.h"
#include "rf_pm.h"
#include "man_timer.h"
#include "man_active.h"
#include "man_fdm.h"
//===========================================================================
static CRFPM* rf_pm_ptr;
//===========================================================================
static void REQ_SelectBand( void )
{ rf_pm_ptr->REQ_SelectBand( );
}
static void __stdcall CNF_SelectBand( const unsigned char cnf, const short token, void *usrData )
{
rf_pm_ptr->CNF_SelectBand( cnf, token, NULL);
}
static void REQ_PowerMeasurement( void )
{ rf_pm_ptr->REQ_PowerMeasurement( );
}
static void __stdcall CNF_PowerMeasurement( const RfPm_Cnf *cnf, const short token, void *usrData )
{ rf_pm_ptr->CNF_PowerMeasurement( cnf, token, usrData );
}
static void REQ_TimeOut( void )
{ rf_pm_ptr->REQ_TimeOut();
}
//===========================================================================
CRFPM::CRFPM( void )
{
IsRunning = false;
ConfirmCallback = 0;
RFReq_PM = NULL;
}
//---------------------------------------------------------------------------
CRFPM::~CRFPM()
{
IsRunning = false;
ConfirmCallback = 0;
if( RFReq_PM != NULL)
{
delete RFReq_PM;
RFReq_PM = NULL;
}
}
//---------------------------------------------------------------------------
void CRFPM::REQ_Finish( void )
{
if(!IsRunning) return;
TimerMan->CounterStop();
Confirm( STATE_PM_OK );
IsRunning = false;
}
//---------------------------------------------------------------------------
void CRFPM::REQ_Stop( void )
{
if(!IsRunning) return;
TimerMan->CounterStop();
META_Cancel( RFID_PM );
Confirm( STATE_PM_STOP );
IsRunning = false;
}
//---------------------------------------------------------------------------
void CRFPM::REQ_TimeOut( void )
{
if(!IsRunning) return;
TimerMan->CounterStop();
META_Cancel( RFID_PM );
Confirm( STATE_PM_TIMEOUT );
IsRunning = false;
}
//---------------------------------------------------------------------------
void CRFPM::Confirm( int confirm_state )
{
if(!IsRunning) return;
if(ConfirmCallback==0) return;
ConfirmState = confirm_state;
ActiveMan->SetActiveFunction( ConfirmCallback );
}
//===========================================================================
void CRFPM::REQ_Start( int band, int arfcn, int pm_per_frame, int pm_count, int gain_min, int gain_max, int gain_step )
{
rf_pm_ptr = this;
IsRunning = true;
Band = band;
Arfcn = arfcn;
PMPerFrame = pm_per_frame;
PMCount = pm_count;
GainMin = gain_min;
GainMax = gain_max;
GainStep = gain_step;
if(GainStep==0) GainMax = GainMin-1;
CurPmCount = PMCount;
CurGain = GainMin;
TimerMan->CounterStart( 12000, ::REQ_TimeOut );
ActiveMan->SetActiveFunction( ::REQ_SelectBand );
}
//---------------------------------------------------------------------------
void CRFPM::REQ_SelectBand( void )
{
if(!IsRunning) return;
unsigned char selected_pcs1900;
if(Band==BANDSEL_PCS1900)
selected_pcs1900 =(unsigned char) 1;
else
selected_pcs1900 =(unsigned char) 0;
MetaResult = META_Rf_SelectFrequencyBand1900( selected_pcs1900, ::CNF_SelectBand, &RFID_PM, NULL );
if(MetaResult!=META_SUCCESS)
{ Confirm( STATE_PM_FAIL ); return; }
}
//-------------------------------------
//void CRFPM::CNF_SelectBand( BOOL cnf )
//void CRFPM::CNF_SelectBand(BOOL cnf, short token, void *usrData)
void __stdcall CRFPM::CNF_SelectBand(const unsigned char cnf, const short token, void *usrData)
{
if(!IsRunning) return;
if(cnf==false)
{ Confirm( STATE_PM_FAIL ); return; }
HasMeasured = false;
ActiveMan->SetActiveFunction( ::REQ_PowerMeasurement );
}
//---------------------------------------------------------------------------
void CRFPM::REQ_PowerMeasurement( void )
{
if(!IsRunning) return;
if( HasMeasured )
{ Confirm( STATE_PM_SECTION_OK );
}
if( PMCount==-1 ) /* infinit PM */
{ CurPmCount = 2001;
}
if( CurPmCount==0 )
{ CurGain += GainStep;
if( CurGain>GainMax )
{ REQ_Finish();
return;
}
CurPmCount = PMCount;
}
if( RFReq_PM == NULL)
{
RFReq_PM = new RfPm_Req;
}
RFReq_PM->arfcn = Arfcn;
RFReq_PM->sampleNoPerFrame = PMPerFrame;
RFReq_PM->gain = CurGain;
if( CurPmCount>2000 )
{ RFReq_PM->frames = (int)(1.0*2000/PMPerFrame+0.99);
CurPmCount -= 2000;
}
else
{ RFReq_PM->frames = (int)(1.0*CurPmCount/PMPerFrame+0.99);
CurPmCount = 0;
}
TimerMan->CounterRestart( 12000 );
// modified by Andy Ueng
//MetaResult = META_Rf_PM( RFReq_PM, ::CNF_PowerMeasurement, &RFID_PM );
MetaResult = META_Rf_PM( RFReq_PM, ::CNF_PowerMeasurement, &RFID_PM, NULL );
if(MetaResult!=META_SUCCESS)
{ Confirm( STATE_PM_FAIL ); return; }
}
//-------------------------------------
// modified by Andy Ueng
//void CRFPM::CNF_PowerMeasurement( RfPm_Cnf cnf )
void __stdcall CRFPM::CNF_PowerMeasurement( const RfPm_Cnf *cnf, const short token, void *usrData )
// end of modified
{
if(!IsRunning) return;
HasMeasured = true;
RFCnf_PM = *cnf;
ActiveMan->SetActiveFunction( ::REQ_PowerMeasurement );
}
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -