⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hf_demo_app.c

📁 BlueTooth Host Software HandFree相关的lib/app/demo源码
💻 C
📖 第 1 页 / 共 5 页
字号:
                            }
                            else
                            {
                                printf("Unhandled AT cmd in the Service Level Connection upstart sequence\n");
                            }

                            if(instData->conInstData[myPrim->connectionType].atResultCounter > 0)
                            {
                                if(instData->conInstData[myPrim->connectionType].threeWayCallingSupported)
                                {
                                    appSendChld();
                                    instData->conInstData[myPrim->connectionType].atState = sequence5;
                                }
                                else if(instData->conInstData[myPrim->connectionType].supportedFeatures & HF_SUPPORT_REMOTE_VOLUME_CONTROL)
                                {
                                    appSendVgs(instData->conInstData[myPrim->connectionType].speakerGain);
                                    instData->conInstData[myPrim->connectionType].atState = sequence6;
                                }
                                else
                                {
                                    printf("...Neither remote volume nor 3-way-call supported, finished AT startup sequence...\n");
                                    instData->conInstData[myPrim->connectionType].atState = serviceLevelConn;
                                }
                            
                                instData->conInstData[myPrim->connectionType].atResultCounter = 0;
                            }
                                printf("Unhandled AT cmd in the Service Level Connection start-up sequence\n");
                            break;
                        }
                
                    case sequence5:
                        {
                            if (result == CHLD_TOKEN)
                            {
                                printf("CHLD_TOKEN\n");
                                instData->conInstData[myPrim->connectionType].atResultCounter++;
                            }
                            else if (result == OK_TOKEN)
                            {
                                printf("OK_TOKEN\n");
                                instData->conInstData[myPrim->connectionType].atResultCounter++;
                            }
                            else
                            {
                                printf("Unhandled AT cmd in the Service Level Connection upstart sequence\n");
                                instData->conInstData[myPrim->connectionType].atResultCounter = 2;
                            }
                    
                            if (instData->conInstData[myPrim->connectionType].atResultCounter > 0)
                            {
                                if(instData->conInstData[myPrim->connectionType].supportedFeatures & HF_SUPPORT_REMOTE_VOLUME_CONTROL)
                                {
                                    appSendVgs(instData->conInstData[myPrim->connectionType].speakerGain);
                                    instData->conInstData[myPrim->connectionType].atState = sequence6;
                                }
                                else
                            {
                                    printf("...Remove volume not supported, finished AT startup sequence\n");
                                    instData->conInstData[myPrim->connectionType].atState = serviceLevelConn;
                                }

                                instData->conInstData[myPrim->connectionType].atResultCounter = 0;

                            }
                            break;
                        }

                    case sequence6:
                        {
                            if (result == OK_TOKEN)
                            {
                                printf("OK_TOKEN\n");
                            }
                            else
                            {
                                printf("Unhandled AT cmd in the Service Level Connection upstart sequence\n");
                            }

                            if(instData->conInstData[myPrim->connectionType].supportedFeatures & HF_SUPPORT_REMOTE_VOLUME_CONTROL)
                            {
                                appSendVgm(instData->conInstData[myPrim->connectionType].micGain);
                                instData->conInstData[myPrim->connectionType].atState = sequence7;
                            }
                            else
                            {
                                printf("...Remove volume not supported, finished AT startup sequence\n");
                                instData->conInstData[myPrim->connectionType].atState = serviceLevelConn;
                                printf("AT sequence for Service Level Connection finished\n");
                            }
                            instData->conInstData[myPrim->connectionType].atResultCounter = 0;
                            break;
                        }

                    case sequence7:
                        {
                            if (result == OK_TOKEN)
                            {
                                printf("OK_TOKEN\n");
                            }
                            else
                            {
                                printf("Unhandled AT cmd in the Service Level Connection upstart sequence\n");
                            }

                            printf("...Finished AT startup sequence\n");
                            instData->conInstData[myPrim->connectionType].atState = serviceLevelConn;
                            break;
                        }
                
                    default:
                        {
							int i;
                            for (i=0; i<myPrim->payloadLength; i++)
                            {
                                switch (myPrim->payload[i])
                                {
                                    case '\r':
                                        {
                                            printf("\\r");
                                            break;
                                        }
                                    case '\n':
                                        {
                                            printf("\\n");
                                            break;
                                        }
                                    default:
                                        {
                                            printf("%c", myPrim->payload[i]);
                                            break;
                                        }
                                }
                            }
                            printf("\n");
                            break;
                        }
                }
#else

                /* We are _not_ in ADVANCED_HF mode, so check if the
                 * startup-sequence is running such that the
                 * mic/speaker gains can be sent through */
                if(instData->conInstData[myPrim->connectionType].startup == STARTUP_MIC)
                {
                    instData->conInstData[myPrim->connectionType].startup = STARTUP_DONE;
                    HfSpeakerGainReqSend(instData->conInstData[myPrim->connectionType].speakerGain,
                                     myPrim->connectionType);
                    
                }
#endif
                pfree(myPrim->payload);
                break;
            }
        
        default:
            {
                printf("####### default in hf prim handler 0x%04x,\n", *primType);
                /*  unexpected primitive received   */
            }
            
    }
}

/**************************************************************************************************
 *
 *   an Cm event is received.
 *
 **************************************************************************************************/
void handleCmPrim(DemoInstdata_t * instData)
{
    commonPrim_t    *primType;
    
    primType = (commonPrim_t *) instData->recvMsgP;
    switch (*primType)
    {
        
        default:
            {
                printf("####### default in CmPrim handler %x,\n",*primType);
                /*  unexpected primitive received   */
            }
    }   /*  end switch(primType)    */
}


/*************************  SC PRIMITIVES   ***************************/

/**************************************************************************************************
 *
 *   handler function for the passkey indication primitive. This function will simply return a response
 *   signal to sc. We do not check the address as we can handle only one.
 *
 **************************************************************************************************/
void handleScPasskeyInd(DemoInstdata_t * instData)
{
    SC_PASSKEY_IND_T        *prim;
    prim = (SC_PASSKEY_IND_T *) instData->recvMsgP;

#ifndef INCLUDE_SC_HANDLER
    instData->state = pairing;
    
    instData->bondingDevAddr = prim->deviceAddr;
    instData->passkeyLength  = 0;
    printf("\nPlease insert passkey for address %04X:%02X:%06X: ", prim->deviceAddr.nap,
           prim->deviceAddr.uap,
           prim->deviceAddr.lap);
#else
    ScPasskeyResSend(TRUE, &prim->deviceAddr, 1, "1", TRUE, TRUE);
#endif
}

/**************************************************************************************************
 *
 *   handler function for the bond indication primitive. Upon successful bonding a connection towards
 *   the headset is initiated for the audio connection.
 *   A connect confirmation is expected in return.
 *
 **************************************************************************************************/
void handleScBondCfm(DemoInstdata_t * instData)
{
    SC_BOND_CFM_T       *incomingPrim;
    incomingPrim    = (SC_BOND_CFM_T *) instData->recvMsgP;
    
    instData->state = idle;
    playIntro(instData);
    if (incomingPrim->result == SUCCESS )
    {
        printf("Bonding completed!!\n");
    }
    else
    {
        printf("Bonding failed\n");
    }

}

/**************************************************************************************************
 *
 *   handler function for the bond indication primitive.
 *
 **************************************************************************************************/
void handleScBondInd(DemoInstdata_t * instData)
{
    SC_BOND_IND_T       *incomingPrim;
    incomingPrim    = (SC_BOND_IND_T *)instData->recvMsgP;
    
    printf("\nBonding with device: %04X:%02X:%06X Completed\n", incomingPrim->deviceAddr.nap,incomingPrim->deviceAddr.uap,
           incomingPrim->deviceAddr.lap);
    instData->bondingDevAddr.lap = incomingPrim->deviceAddr.lap;
    instData->bondingDevAddr.uap = incomingPrim->deviceAddr.uap;
    instData->bondingDevAddr.nap = incomingPrim->deviceAddr.nap;
    instData->state         = idle; 
}

/**************************************************************************************************
 *
 *   handler function for the authorise indication primitive. 
 *   Authorise is sent when no pairing has be completed and an incoming connection is to be setup.
 *
 **************************************************************************************************/
void handleScAuthoriseInd(DemoInstdata_t * instData)
{
    SC_AUTHORISE_IND_T      *prim;
    prim = (SC_AUTHORISE_IND_T *) instData->recvMsgP;
    
    printf("Authorise ind received\n");
    ScAuthoriseResSend( TRUE, &(prim->deviceAddr) );
    printf("Accepting connection request from %s (%04X:%02X:%06X)\n", prim->deviceName, prim->deviceAddr.nap, prim->deviceAddr.uap, prim->deviceAddr.lap);
}

/**************************************************************************************************
 *
 *   function to handle all sc-primitives.
 *
 **************************************************************************************************/
void handleScPrim(DemoInstdata_t * instData)
{
    commonPrim_t    *primType;
    primType = (commonPrim_t *) instData->recvMsgP;
    switch (*primType)
    {
        /*  the SC must have the passkey to use for the pairing procedure   */
        case SC_PASSKEY_IND:
            {
                handleScPasskeyInd(instData);
                break;
            }
            /*  Bonding completed. Result is indicated. If failed then exit */
        case SC_BOND_CFM:
            {
                handleScBondCfm(instData);
                break;
            }
        case SC_BOND_IND:
            {
                handleScBondInd(instData);
                break;
            }
        case SC_AUTHORISE_IND:
            {
                handleScAuthoriseInd(instData);
                break;
            }
        default:
            {
                printf("####### default in scPrim handler %x,\n",*primType);
            
                /*  unexpected primitive received   */
            }
    }
}


/**************************************************************************************************
 *
 *   a keyboard event is received.
 *   first check for selection of a found device during inquiry if state is inquiry. If not start
 *   proper action as selected.
 *
 **************************************************************************************************/
void handleKeybPrim(DemoInstdata_t * instData)
{
    BchsKeyPress_t *key;
    key = (BchsKeyPress_t*)instData->recvMsgP;

    if (key->key == ESCAPE_KEY)
    {
        printf("\nUser exit...\n");
#ifdef ENABLE_SHUTDOWN
        sched_stop();
#else
        exit(0);
#endif
        return;
    }
    else if(key->key==' ')
    {
        playIntro(instData);
        return;
    }
    
    if (instData->state == pairing)
    {
        passkeyHandler(instData);
        return;
    }
    
    if (instData->state == dialing)
    {
        ph

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -