cbt_bt_sig.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:15k
- /*****************************************************************************
- * 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:
- * ---------
- * cbt_bt_sig.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * CBT 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 _CBT_BT_SIG_H_
- #include "cbt_bt_sig.h"
- #endif
- #pragma package(smart_init)
- //=============================================================================
- /////////////////////// General //////////////////////////////////
- //=============================================================================
- bool cbt_sig_bt_init(S_CBT_T *cbt, bool bReset)
- {
- ViStatus status;
- unsigned long num;
- char cmd[BUF], buf[BUF];
- if (NULL == cbt->base)
- {
- status = viOpenDefaultRM(&cbt->RM);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- status = viOpen(cbt->RM, (cbt->ADD+"::0::INSTR").c_str(), VI_NULL, cbt->TMO, &cbt->base);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- status = viSetAttribute(cbt->base, VI_ATTR_TMO_VALUE, cbt->TMO);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- }
- strcpy(cmd, "SYST:REM:ADDR:SEC 21,"BLUETOOTH_Sig"");
- viWrite(cbt->base, cmd, strlen(cmd), &num);
- status = viOpen(cbt->RM, (cbt->ADD+"::21::INSTR").c_str(), VI_NULL, cbt->TMO, &(cbt->s_bt));
- if (status < VI_SUCCESS)
- {
- return false;
- }
- status = viSetAttribute(cbt->s_bt, VI_ATTR_TMO_VALUE, cbt->TMO);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- // port
- strcpy(cmd, "INP:STAT RF2");
- viWrite(cbt->s_bt, cmd, strlen(cmd), &num);
- strcpy(cmd, "OUTP:STAT RF2");
- viWrite(cbt->s_bt, cmd, strlen(cmd), &num);
- // loss
- sprintf(cmd, "SENS:CORR:LOSS:INP2 %f", cbt->loss_bt_i);
- viWrite(cbt->s_bt, cmd, strlen(cmd), &num);
- sprintf(cmd, "SENS:CORR:LOSS:OUTP2 %f", cbt->loss_bt_o);
- viWrite(cbt->s_bt, cmd, strlen(cmd), &num);
- return true;
- }
- //-----------------------------------------------------------------------------
- bool cbt_sig_bt_close(S_CBT_T *cbt)
- {
- ViStatus status;
- if (NULL != cbt->s_bt)
- {
- status = viClose(cbt->s_bt);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- cbt->s_bt = NULL;
- }
- if (NULL != cbt->base)
- {
- status = viClose(cbt->base);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- cbt->base = NULL;
- }
- if (NULL != cbt->RM)
- {
- status = viClose(cbt->RM);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- cbt->RM = NULL;
- }
-
- return true;
- }
- //-----------------------------------------------------------------------------
- bool cbt_sig_bt_config_downlink_power(S_CBT_T *cbt, 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(cbt->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //=============================================================================
- /////////////////////// Connection control ///////////////////////////////
- //=============================================================================
- bool cbt_sig_bt_config_slave_parameter(S_CBT_T *cbt, 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(cbt->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(cbt->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(cbt->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(cbt->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(cbt->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- bool cbt_sig_bt_config_address(S_CBT_T *cbt, 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(cbt->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //--------------------------------------------------------------------------
- bool cbt_sig_bt_config_inquiry(S_CBT_T *cbt, 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(cbt->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(cbt->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //--------------------------------------------------------------------------
- bool cbt_sig_bt_inquiry(S_CBT_T *cbt)
- {
- ViStatus status;
- char cmd[BUF];
- unsigned long num;
- strcpy(cmd, "PROCedure:SIGNalling:ACTion INQuiry");
- status = viWrite(cbt->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //--------------------------------------------------------------------------
- bool cbt_sig_bt_connect_test(S_CBT_T *cbt)
- {
- ViStatus status;
- char cmd[BUF];
- unsigned long num;
- strcpy(cmd, "PROCedure:SIGNalling:ACTion TEST");
- status = viWrite(cbt->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //--------------------------------------------------------------------------
- bool cbt_sig_bt_query_state(S_CBT_T *cbt, 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(cbt->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- status = viRead(cbt->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 cbt_sig_bt_release(S_CBT_T *cbt)
- {
- ViStatus status;
- char cmd[BUF];
- unsigned long num;
- strcpy(cmd, "PROCedure:SIGNalling:ACTion DETach");
- status = viWrite(cbt->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //===========================================================================
- /////////////////////////// MPR measurement ///////////////////////////
- //===========================================================================
- bool cbt_sig_bt_config_mpr(S_CBT_T *cbt, 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(cbt->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(cbt->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(cbt->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(cbt->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(cbt->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //===========================================================================
- /////////////////////////// MOD measurement ///////////////////////////
- //===========================================================================
- bool cbt_sig_bt_config_mod(S_CBT_T *cbt, 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(cbt->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(cbt->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(cbt->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(cbt->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- bool cbt_sig_bt_read_average_freq_error(S_CBT_T *cbt, 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(cbt->s_bt, cmd, strlen(cmd), &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- status = viRead(cbt->s_bt, buf, BUF, &num);
- if (status < VI_SUCCESS)
- {
- return false;
- }
- buf[num-1] = NULL;
- double d_result[CBT_BT_MOD_NUM];
- AnsiString as_result(buf);
- if (as_result.Pos("NAN"))
- {
- return false;
- }
- String_To_Array_double(buf, d_result, CBT_BT_MOD_NUM);
- *freq_err = d_result[CBT_BT_MOD_FREQ_ACCURACY_AVERAGE];
- return true;
- }