读书人

蓝牙代码解决方案

发布时间: 2012-04-28 11:49:53 作者: rapoo

蓝牙代码
关于蓝牙代码看不懂望高手指教一二。详细的给出最高分
代码如下:
#include "private.h"
#include "usb_audio.h"
#include "led.h"
#include "inquiry_scan.h"
#include "ps_store.h"
#include "usb_hid.h"
#include "app_manager.h"
#include "a2dp_handler.h"
#include "avrcp_handler.h"
#include "aghfp_handler.h"
#include "sys_handler.h"
#include "cl_handler.h"

#include <panic.h>
#include <pio.h>
#include <pcm.h>
#include <stdlib.h>/* For NULL */
#include <string.h> /* For memcpy */
#include <kalimba_standard_messages.h>
#include <file.h>
#include <kalimba.h>
#include <bdaddr.h>


/* This is the task data associated with the app. */
mvdTaskData *s_the_app = NULL;
mvdTaskData* mvdGetApp (void)
{
return s_the_app;
}


/****************************************************************************
Unhandled state in the message handler.
*/
static void unhandledMessage(MessageId id)
{
DEBUG(("\nUnhandled message 0x%X", (uint16)id));
}

/****************************************************************************
MessageHandler
*/
static void messageHandler(Task task, MessageId id, Message message)
{
/*Sink old_audio_sink = s_the_app->audio_sink; TODO: Remove */

if (id>=MESSAGE_FROM_HOST && id<=MESSAGE_USB_SUSPENDED)
{
mvdHandleSystemMessage(id, message);
}
else if (id>=CL_MESSAGE_BASE && id<CL_MESSAGE_TOP)
{
mvdHandleClMessage(id, message);
}
else if (id>=A2DP_MESSAGE_BASE && id<A2DP_MESSAGE_TOP)
{
mvdHandleA2dpMessage(id, message);
}
else if (id>=AVRCP_MESSAGE_BASE && id<AVRCP_MESSAGE_TOP)
{
mvdHandleAvrcpMessage(id, message);
}
else if (id>=AGHFP_MESSAGE_BASE && id<AGHFP_MESSAGE_TOP)
{
mvdHandleAghfpMessage(id, message);
}
else if (id>=APP_MESSAGE_BASE && id<APP_MESSAGE_TOP)
{
mvdHandleAppMessage(id, message);
}
else
{/* Unrecognised messages */
unhandledMessage(id);
}
}


/****************************************************************************
Extra initialisation for time critical functionality
*/
extern void _init(void);
void _init(void)
{
/* mvdInitUsbAudioTimeCritical();
mvdInitUsbHidTimeCritical();
*/
}


/****************************************************************************
Find the two DSP apps and take note of their file system indexes
*/
static const char kal_sco_enc[] = "mv_kalimba/mv_kalimba.kap";

void mvdKalimbaStart (mvdTaskData *the_app)
{
DEBUG(("\nkalimbaStart"));

/* Find the file in the file system */
the_app->sco_enc_idx = FileFind(FILE_ROOT,kal_sco_enc,sizeof(kal_sco_enc)-1/*don't pass terminator*/);
PanicFalse( the_app->sco_enc_idx != FILE_NONE );

/* Load the codec into Kalimba */
DEBUG_KALIMBA((" kl"));
PanicFalse( KalimbaLoad(the_app->sco_enc_idx) );

/* Plug in the usb ports to kalimba */
DEBUG_KALIMBA((" cua"));
mvdConnectUsbAudio( StreamKalimbaSink(0), StreamKalimbaSource(1) );

/*DEBUG_KALIMBA((" ksmENCODER_SELECT"));
PanicFalse(KalimbaSendMessage(KALIMBA_ENCODER_SELECT, (uint16)EncoderNone, 0, 0, 0));*/

/* Send go message to DSP */
DEBUG_KALIMBA((" ksmGO"));
PanicFalse( KalimbaSendMessage(KALIMBA_MSG_GO, 0, 0, 0, 0) );
}


void mvdKalimbaSelect (mvdTaskData *the_app, mvdEncoderType enc)


{
DEBUG_KALIMBA(("\nmvdKalimbaSelect"));

switch (enc)
{
case EncoderNone:
DEBUG_KALIMBA(("(None)"));
the_app->active_encoder = EncoderNone;
break;

case EncoderSbc:
DEBUG_KALIMBA(("(Sbc)"));
A2dpAudioCodecConfigure(the_app->a2dp, the_app->media_sink);
the_app->active_encoder = EncoderSbc;
break;

case EncoderSco:
DEBUG_KALIMBA(("(Sco)"));
PanicFalse(PcmRateAndRoute(0, PCM_NO_SYNC, 8000, 8000, VM_PCM_INTERNAL_A));
the_app->active_encoder = EncoderSco;
break;

case EncoderWbs:
DEBUG_KALIMBA(("(Wbs=None)"));
the_app->active_encoder = EncoderNone;
break;
}

PanicFalse(KalimbaSendMessage(KALIMBA_ENCODER_SELECT, (uint16)the_app->active_encoder, 0, 0, 0));
}


/****************************************************************************
Entry point
*/
int main(void)
{
/* Set up the application task handler */
s_the_app = (mvdTaskData *)malloc(sizeof(mvdTaskData));
DEBUG(("\nmvdTaskData = 0x%X",(uint16)s_the_app));
PanicNull(s_the_app);
memset(s_the_app, 0, sizeof(mvdTaskData));
s_the_app->task.handler = messageHandler;

#if 0
MessageKalimbaTask(&s_the_app->task);

mvdInitUsbAudio(s_the_app);
mvdInitHid(s_the_app);

/* Setup button's PIO line */
PanicFalse( mvdGetPioConfig(s_the_app) );
MessagePioTask(&s_the_app->task);
#if defined KALIMBA_MESSAGE_DEBUG
PioDebounce(s_the_app->pio_config.mfb | DUT_PIO | USB_IN_TOGGLE_PIO|USB_OUT_TOGGLE_PIO, 3, 3);
PioSetDir(s_the_app->pio_config.mfb | DUT_PIO | USB_IN_TOGGLE_PIO|USB_OUT_TOGGLE_PIO, 0);
#elif defined HID_SEQUENCE_DEBUG
PioDebounce(s_the_app->pio_config.mfb | DUT_PIO | HID_SEQUENCE_PIO, 3, 3);
PioSetDir(s_the_app->pio_config.mfb | DUT_PIO | HID_SEQUENCE_PIO, 0);
#elif defined CALL_SETUP_DEBUG
PioDebounce(s_the_app->pio_config.mfb | DUT_PIO | CALL_INCOMING_PIO | CALL_OUTGOING_PIO | CALL_CANCEL_PIO | CALL_ACTIVE_PIO, 3, 3);
PioSetDir(s_the_app->pio_config.mfb | DUT_PIO | CALL_INCOMING_PIO | CALL_OUTGOING_PIO | CALL_CANCEL_PIO | CALL_ACTIVE_PIO, 0);
#else
PioDebounce(s_the_app->pio_config.mfb | DUT_PIO, 3, 3);
PioSetDir(s_the_app->pio_config.mfb | DUT_PIO, 0);
#endif
/* If the button's PIO line is high at boot time (now), then entry to DFU mode
is being requested. */
s_the_app->pio_state = PioGet();
s_the_app->dfu_requested = ((s_the_app->pio_state & s_the_app->pio_config.mfb) == s_the_app->pio_config.mfb);

/* Get USB HID keycode configuration */
PanicFalse( mvdGetHidConfig(s_the_app) );

s_the_app->audio_streaming_timeout = mvdGetAudioStreamingTimeout();
#endif
/* Start the message scheduler loop and init application */
MessageSend(&s_the_app->task, APP_INIT, 0);


MessageLoop();

/* Never get here! */
return 0;
}


[解决办法]
我是菜鸟,我没有看懂问题
[解决办法]
逻辑上似乎没什么难理解:就是不同的事件做不同的响应。
要彻底理解,应该需要先了解蓝牙的通信协议才行吧。
[解决办法]
路过学习的

读书人网 >C语言

热点推荐