📄 main.c
字号:
/*把查询到的结果保存起来*/
/*DEBUG(("Found device = 0x%x\n",(uint16)((CL_DM_INQUIRE_RESULT_T*)message)->dev_class));*/
sppDevInquiryResult(&theSppApp, (CL_DM_INQUIRE_RESULT_T*)message);
}
break;
case sppDevInitialising:
case sppDevReady:
case sppDevConnected:
case sppDevDisconnecting:
default:
unhandledSppState(state, id);
break;
}
break;
case SPP_CONNECT_CFM:
DEBUG(("SPP_CONNECT_CFM result = %d\n",((SPP_CONNECT_CFM_T*)message)->status));
DEBUG(("SPP_CONNECT_CFM sink = 0x%x\n",(uint16)((SPP_CONNECT_CFM_T*)message)->sink));
switch(state)
{
case sppDevConnecting:
case sppDevInquiring:
/* Connect cfm, but must check status as connection may have failed */
if (((SPP_CONNECT_CFM_T*)message)->status == rfcomm_connect_success)
{
/* Connection Success */
DEBUG(("Device connected OK \n"));
/* Connect Uart to Rfcomm */
StreamUartConfigure(VM_UART_RATE_115K2, VM_UART_STOP_ONE,VM_UART_PARITY_NONE);
theSppApp.uart_sink = StreamUartSink();
theSppApp.uart_source=StreamUartSource();
/*找到和slave 对应的sink*/
theSppApp.spp_connect_sink[theSppApp.saved_addr_index]=((SPP_CONNECT_CFM_T*)message)->sink;
theSppApp.saved_addr_index++;
if(theSppApp.saved_addr_index >= slave_num_max)
theSppApp.saved_addr_index = 0;
DEBUG(("SPP_CONNECT_UART sink = 0x%x\n",(uint16)((SPP_CONNECT_CFM_T*)message)->sink));
DEBUG(("SPP_CONNECT_UART spp = 0x%x\n",(uint16)((SPP_CONNECT_CFM_T*)message)->spp));
DEBUG(("slave_index =%d\n",theSppApp.saved_addr_index));
setSppState(sppDevConnected);
/*20070711 del*/
/*MessageSendLater(getAppTask(), SPP_DEV_CONNECT_NEXT_SLAVE, 0, message_connect_confirm);*/
}
else
{
DEBUG(("Connection failed\n"));
/*continue to connect*/
sppDevConnect(&theSppApp);
/*within 10s ,cancel to contect*/
MessageSendLater(getAppTask(), SPP_DEV_CONNECT_CANCEL, 0, 10000);
}
break;
case sppDevInitialising:
case sppDevReady:
case sppDevConnected:
case sppDevDisconnecting:
default:
unhandledSppState(state, id);
break;
}
break;
case SPP_CONNECT_IND:
DEBUG(("SPP_CONNECT_IND\n"));
switch(state)
{
case sppDevReady:
case sppDevInquiring:
/* Received command that a device is trying to connect. Send response. */
sppDevAuthoriseConnectInd(&theSppApp,(SPP_CONNECT_IND_T*)message);
break;
case sppDevConnected:
case sppDevInitialising:
case sppDevConnecting:
case sppDevDisconnecting:
default:
unhandledSppState(state, id);
break;
}
break;
case SPP_DISCONNECT_IND:
DEBUG(("SPP_DISCONNECT_IND\n"));
/* Disconnect message has arrived */
switch(state)
{
case sppDevReady:
case sppDevConnected:
case sppDevDisconnecting:
if (know_far_addr(theSppApp.bd_addr))
{
sppDevConnect(&theSppApp);
}
else
{
/*sppDevInquire(&theSppApp);*/
}
break;
case sppDevInquiring:
case sppDevInitialising:
case sppDevConnecting:
default:
unhandledSppState(state, id);
break;
}
break;
case CL_SM_PIN_CODE_IND:
DEBUG(("CL_SM_PIN_CODE_IND\n"));
sppDevHandlePinCodeRequest((CL_SM_PIN_CODE_IND_T *) message);
break;
case CL_SM_AUTHORISE_IND:
DEBUG(("CL_SM_AUTHORISE_IND\n"));
sppDevAuthoriseResponse((CL_SM_AUTHORISE_IND_T*) message);
break;
case CL_SM_AUTHENTICATE_CFM:
DEBUG(("CL_SM_AUTHENTICATE_CFM\n"));
sppDevSetTrustLevel(&theSppApp, (CL_SM_AUTHENTICATE_CFM_T*)message);
break;
case CL_DM_LINK_POLICY_IND:
DEBUG(("CL_DM_LINK_POLICY_IND\n"));
break;
case CL_DM_LINK_QUALITY_CFM:
/*DEBUG(("CL_DM_LINK_QUALITY_CFM\n")); */
Radio_Strength= (uint8)(((CL_DM_LINK_QUALITY_CFM_T*)message)->link_quality) ;
/*DEBUG(("Radio_Strength = %d\n",Radio_Strength));*/
break;
case SPP_DEV_UPDATE_LED:
/*DEBUG(("SPP_DEV_UPDATE_LED\n")); */
sppDevUpdateLed(&theSppApp,theSppApp.spp_state);
/* When recived a reinqiure command ,chould re inquire
if((UART_COMMAND == 1) && (theSppApp.saved_addr_index < slave_num_max) )
{
UART_COMMAND =0 ;
sppDevInquire(&theSppApp);
}
*/
ConnectionGetLinkQuality ( &theSppApp.Connection_task, theSppApp.spp_connect_sink[0]);
break;
case SPP_DEV_INQUIRE_CANCEL_AND_CONECT:
DEBUG(("SPP_DEV_INQUIRE_CANCEL_AND_CONECT \n"));
ConnectionInquireCancel(getAppTask()); /* Cancel the inquiry */
break;
case SPP_DEV_CONNECT_NEXT_SLAVE:
DEBUG( ("SPP_DEV_CONNECT_NEXT_SLAVE \n") );
sppDevConnect(&theSppApp);
break;
case SPP_DEV_CONNECT_CANCEL:
/*sppDevDisconnect(&theSppApp);*/
break;
case SPP_MESSAGE_MORE_DATA :
DEBUG(("SPP_MESSAGE_MORE_DATA source = 0x%x\n",(uint16)((SPP_MESSAGE_MORE_DATA_T*)message)->source));
DEBUG(("SPP_MESSAGE_MORE_DATA spp = 0x%x\n",(uint16)((SPP_MESSAGE_MORE_DATA_T*)message)->spp));
/* Get the correct slave address*/
get_slave_addr = UART_SearchCorrespondDeviceAddr( ((SPP_MESSAGE_MORE_DATA_T*)message)->spp);
/* Source(from slave) -- > Sink(recived) Get the received Datafream to Uart */
source_bytes_length= SourceSize(((SPP_MESSAGE_MORE_DATA_T*)message)->source);
if(source_bytes_length)/* received more bytes*/
{
char_point = SourceMap( ((SPP_MESSAGE_MORE_DATA_T*)message)->source );
char_point_tmp = char_point;
for(loop = 0;loop<source_bytes_length;loop++)
{
TranBuff_SLAVE[loop] = (*char_point);
char_point++;
}
#ifdef PC_window_view
char_point = char_point_tmp;
UART_Rec_PC(&theSppApp,(uint8 *)char_point,source_bytes_length);
#endif
SourceDrop(((SPP_MESSAGE_MORE_DATA_T*)message)->source, source_bytes_length);
for(loop = 0;loop<Buff_length;loop++)
TranBuff_SLAVE[loop] = 0;
if( get_slave_addr.nap == StoredAddr[0].nap &&
get_slave_addr.uap == StoredAddr[0].uap &&
get_slave_addr.lap == StoredAddr[0].lap
)
{
TranBuff_SLAVE[0] = 'a';
TranBuff_SLAVE[1] = 'b';
data_len = 2;
char_point = TranBuff_SLAVE;
SPP_UART_SEND_SLAVE(&theSppApp,(uint8*)char_point,data_len,theSppApp.spp_connect_sink[0]);
}
else if( get_slave_addr.nap == StoredAddr[1].nap &&
get_slave_addr.uap == StoredAddr[1].uap &&
get_slave_addr.lap == StoredAddr[1].lap)
{
TranBuff_SLAVE[0] = 'h';
TranBuff_SLAVE[1] = 'm';
data_len = 2;
char_point = TranBuff_SLAVE;
SPP_UART_SEND_SLAVE(&theSppApp,(uint8*)char_point,data_len,theSppApp.spp_connect_sink[1]);
}
else if( get_slave_addr.nap == StoredAddr[2].nap &&
get_slave_addr.uap == StoredAddr[2].uap &&
get_slave_addr.lap == StoredAddr[2].lap)
{
}
else if(get_slave_addr.nap == StoredAddr[3].nap &&
get_slave_addr.uap == StoredAddr[3].uap &&
get_slave_addr.lap == StoredAddr[3].lap)
{
}
else if(get_slave_addr.nap == StoredAddr[4].nap &&
get_slave_addr.uap == StoredAddr[4].uap &&
get_slave_addr.lap == StoredAddr[4].lap)
{
}
else if(get_slave_addr.nap == StoredAddr[5].nap &&
get_slave_addr.uap == StoredAddr[5].uap &&
get_slave_addr.lap == StoredAddr[5].lap)
{
}
else if(get_slave_addr.nap == StoredAddr[6].nap &&
get_slave_addr.uap == StoredAddr[6].uap &&
get_slave_addr.lap == StoredAddr[6].lap)
{
}
DEBUG( ("SPP_MESSAGE_MORE_DATA REV_NUMBER = 0x%x\n",source_bytes_length ) );
DEBUG( ("receive_addr nap= 0x%x \n ", get_slave_addr.nap) );
DEBUG(("receive_addr uap= 0x%X \n ", get_slave_addr.uap) );
DEBUG(("receive_addr lap= 0x%lX \n ", get_slave_addr.lap));
}
break;
case SPP_MESSAGE_MORE_SPACE:
DEBUG(("SPP_MESSAGE_MORE_SPACE\n"));
break;
case CL_DM_ACL_OPENED_IND:
/*DEBUG(("CL_DM_ACL_OPENED_IND msssage arrived\n"));*/
break;
case CL_DM_ACL_CLOSED_IND:
/*DEBUG(("CL_DM_ACL_CLOSED_IND msssage arrived\n"));*/
break;
default:
/* An unexpected message has arrived - must handle it */
DEBUG(("main app - msg type not yet handled 0x%x\n", id));
break;
}
}
int main(void)
{
PioState pio_state;
DEBUG(("Main Started...\n"));
{
/* Set up task 1 handler */
theSppApp.Connection_task.handler = app_handler;
theSppApp.HostUart_task.handler = Host_handler;
PioInit(&pio_state);
/* inital the state*/
setSppState(sppDevInitialising);
sppDevLedInit();
Initial_variable();
opp_initTask(&OPPState);
ftp_initTask(&FTPState);
dun_initTask(&DUNstate);
/* Init the Connection Manager */
ConnectionInit(&theSppApp.Connection_task);
/* Init the UART Manager */
MessageSinkTask(StreamUartSink(), &theSppApp.HostUart_task);
/* Start the message scheduler loop */
MessageLoop();
}
/* Will never get here! */
DEBUG(("Main Ended!\n"));
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -