cmu200_bt_sig.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:16k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * cmu200_bt_sig.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * CMU 200 BT signalling function source
- *
- * Author:
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- #pragma hdrstop
- #ifndef _FT_UTILS_H_
- #include "ft_utils.h"
- #endif
- #ifndef _CMU200_BT_SIG_H_
- #include "cmu200_bt_sig.h"
- #endif
- #pragma package(smart_init)
- //=============================================================================
- /////////////////////// General //////////////////////////////////
- //=============================================================================
- bool cmu_sig_bt_init(CMU_VAR *cmu, bool bReset)
- {
- ViStatus status;
- unsigned long num;
- char cmd[BUF], buf[BUF];
- if (NULL == cmu->base)
- {
- status = viOpenDefaultRM(&cmu->RM);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- status = viOpen(cmu->RM, (cmu->ADD+"::0::INSTR").c_str(), VI_NULL, cmu->TMO, &(*cmu).base);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- status = viSetAttribute(cmu->base, VI_ATTR_TMO_VALUE, cmu->TMO);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- }
- strcpy(cmd, "SYST:REM:ADDR:SEC 21,"BLUETOOTH_Sig"");
- viWrite(cmu->base, cmd, strlen(cmd), &num);
- status = viOpen(cmu->RM, (cmu->ADD+"::21::INSTR").c_str(), VI_NULL, cmu->TMO, &(cmu->s_bt));
- if (status < VI_SUCCESS)
- {
- return false;
- }
- status = viSetAttribute(cmu->s_bt, VI_ATTR_TMO_VALUE, cmu->TMO);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- // port
- strcpy(cmd, "INP:STAT RF2");
- viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- strcpy(cmd, "OUTP:STAT RF2");
- viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- // loss
- sprintf(cmd, "SENS:CORR:LOSS:INP2 %f", cmu->loss_bt_i);
- viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- sprintf(cmd, "SENS:CORR:LOSS:OUTP2 %f", cmu->loss_bt_o);
- viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- return true;
- }
- //-----------------------------------------------------------------------------
- bool cmu_sig_bt_close(CMU_VAR *cmu)
- {
- ViStatus status;
- if (NULL != cmu->s_bt)
- {
- status = viClose(cmu->s_bt);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- cmu->s_bt = NULL;
- }
- if (NULL != cmu->base)
- {
- status = viClose(cmu->base);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- cmu->base = NULL;
- }
- if (NULL != cmu->RM)
- {
- status = viClose(cmu->RM);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- cmu->RM = NULL;
- }
-
- return true;
- }
- //-----------------------------------------------------------------------------
- bool cmu_sig_bt_config_downlink_power(CMU_VAR *cmu, double d_dn_power)
- {
- ViStatus status;
- char cmd[BUF];
- unsigned long num;
- char str[256];
- sprintf(str, "%f", d_dn_power);
- AnsiString as_power(str);
- AnsiString as_cmd = "CONFigure:MSIGnal:TXLevel " + as_power;
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //=============================================================================
- /////////////////////// Connection control ///////////////////////////////
- //=============================================================================
- bool cmu_sig_bt_config_slave_parameter(CMU_VAR *cmu, unsigned short ch)
- {
- ViStatus status;
- char cmd[BUF];
- unsigned long num;
- // TX test
- AnsiString as_cmd = "CONFigure:SSIGnal:TMODe:TMTYpe TXT";
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- // non hopping
- as_cmd = "CONFigure:SSIGnal:TMODe:HSCHeme RXTX";
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- // RX/TX channel
- as_cmd = "CONFigure:SSIGnal:TMODe:FREQuency:UNIT CH";
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- as_cmd = "CONFigure:SSIGnal:TMODe:TXTests:FREQuency " + IntToStr(ch);
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- // packet type
- as_cmd = "CONFigure:SSIGnal:TMODe:TXTests:PATType P11";
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- bool cmu_sig_bt_config_address(CMU_VAR *cmu, AnsiString as_bd_addr)
- {
- ViStatus status;
- char cmd[BUF];
- unsigned long num;
- AnsiString as_cmd = "CONFigure:MSIGnal:PAGing:TARGet "" + as_bd_addr + """;
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //--------------------------------------------------------------------------
- bool cmu_sig_bt_config_inquiry(CMU_VAR *cmu, S_BTT_INQUIRY s_inquiry)
- {
- ViStatus status;
- char cmd[BUF];
- unsigned long num;
- // timeout
- AnsiString as_cmd = "CONFigure:MSIGnal:INQuiry:ILENgth " + IntToStr(s_inquiry.i_timeout);
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- // number of response
- as_cmd = "CONFigure:MSIGnal:INQuiry:NOResponses " + IntToStr(s_inquiry.i_response_num);
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //--------------------------------------------------------------------------
- bool cmu_sig_bt_inquiry(CMU_VAR *cmu)
- {
- ViStatus status;
- char cmd[BUF];
- unsigned long num;
- strcpy(cmd, "PROCedure:SIGNalling:ACTion INQuiry");
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //--------------------------------------------------------------------------
- bool cmu_sig_bt_connect_test(CMU_VAR *cmu)
- {
- ViStatus status;
- char cmd[BUF];
- unsigned long num;
- strcpy(cmd, "PROCedure:SIGNalling:ACTion TEST");
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //--------------------------------------------------------------------------
- bool cmu_sig_bt_query_state(CMU_VAR *cmu, E_BTT_STATE_T* e_state)
- {
- ViStatus status;
- char cmd[BUF];
- char buf[BUF];
- unsigned long num;
- AnsiString as_cmd = "SIGNalling:XSTate?";
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- status = viRead(cmu->s_bt, buf, BUF, &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- buf[num-1] = NULL;
- AnsiString as(buf);
- as = as.UpperCase();
- if (as.AnsiPos("SBY"))
- {
- *e_state = BTT_STATUS_STANDBY;
- }
- else if (as.AnsiPos("INQ"))
- {
- *e_state = BTT_STATUS_INQUIRY;
- }
- else if (as.AnsiPos("PAG"))
- {
- *e_state = BTT_STATUS_PAGING;
- }
- else if (as.AnsiPos("CONN"))
- {
- *e_state = BTT_STATUS_CONNECTED;
- }
- else if (as.AnsiPos("TEST"))
- {
- *e_state = BTT_STATUS_TEST;
- }
- else if (as.AnsiPos("HOLD"))
- {
- *e_state = BTT_STATUS_HOLD;
- }
- else if (as.AnsiPos("SNIF"))
- {
- *e_state = BTT_STATUS_SNIF;
- }
- else if (as.AnsiPos("PARK"))
- {
- *e_state = BTT_STATUS_PARK;
- }
- else if (as.AnsiPos("AUD"))
- {
- *e_state = BTT_STATUS_AUDIO;
- }
- else if (as.AnsiPos("DET"))
- {
- *e_state = BTT_STATUS_DETACH;
- }
- return true;
- }
- //--------------------------------------------------------------------------
- bool cmu_sig_bt_release(CMU_VAR *cmu)
- {
- ViStatus status;
- char cmd[BUF];
- unsigned long num;
- strcpy(cmd, "PROCedure:SIGNalling:ACTion DETach");
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //===========================================================================
- /////////////////////////// MPR measurement ///////////////////////////
- //===========================================================================
- bool cmu_sig_bt_config_mpr(CMU_VAR *cmu, S_BTT_POWER bt_mpr)
- {
- ViStatus status;
- char cmd[BUF];
- unsigned long num;
- AnsiString as_cmd = "CONFigure:POWer:MPR:CONTrol:STATistics " + IntToStr(bt_mpr.i_burst_num);
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- as_cmd = "CONFigure:POWer:MPR:CONTrol:REPetition SINGleshot,SONerror,NONE";
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- // channel
- as_cmd = "CONFigure:POWer:MPR:MMODe SINGle";
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- as_cmd = "CONFigure:POWer:MPR:MFRequency:UNIT CH";
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- as_cmd = "CONFigure:POWer:MPR:MFRequency " + IntToStr(bt_mpr.i_channel);
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //===========================================================================
- /////////////////////////// MOD measurement ///////////////////////////
- //===========================================================================
- bool cmu_sig_bt_config_mod(CMU_VAR *cmu, S_BTT_MOD bt_mod)
- {
- ViStatus status;
- char cmd[BUF];
- unsigned long num;
- AnsiString as_cmd = "CONFigure:MODulation:DEViation:CONTrol SCALar, " + IntToStr(bt_mod.i_burst_num) +
- ", SINGleshot, SONerror, NONE";
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- // channel
- as_cmd = "CONFigure:MODulation:DEViation:MMODe SINGle";
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- as_cmd = "CONFigure:MODulation:DEViation:MFRequency:UNIT CH";
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- as_cmd = "CONFigure:MODulation:DEViation:MFRequency " + IntToStr(bt_mod.i_channel);
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- bool cmu_sig_bt_read_average_freq_error(CMU_VAR *cmu, double* freq_err)
- {
- ViStatus status;
- char cmd[BUF];
- char buf[BUF];
- unsigned long num;
- AnsiString as_cmd = "READ:MOD:DEV:EXT?";
- strcpy(cmd, as_cmd.c_str());
- status = viWrite(cmu->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- status = viRead(cmu->s_bt, buf, BUF, &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- buf[num-1] = NULL;
- AnsiString temp_total;
- AnsiString temp_value;
- AnsiString value[CMU200_BT_MOD_NUM];
- int i_num;
- AnsiString temp(buf);
- if (temp.Pos("NAN"))
- {
- return false;
- }
- #if 0
- for (int i=0;i<CMU200_BT_MOD_NUM;i++)
- {
- temp_value=temp.SubString(1, temp.Pos(",")-1);
- i_num= temp.AnsiPos(",");
- value[i]=temp_value;
- temp_total=temp.SubString(i_num+1, temp.Length());
- temp=temp_total;
- }
- *freq_err = atof(value[CMU200_BT_MOD_FREQ_ACCURACY_AVERAGE].c_str());
- #endif
- double d_array[CMU200_BT_MOD_NUM];
- String_To_Array_double(temp.c_str(), d_array, CMU200_BT_MOD_NUM);
- *freq_err = d_array[CMU200_BT_MOD_FREQ_ACCURACY_AVERAGE];
- return true;
- }