📄 main.c
字号:
/********************************************************************************
* Copyright (c) 2001, Windigo Systems
*
* All rights reserved.
*
* File name:
*
* SPP_master.c
*
* Summary:
*
* piconet
*
* Original version:
*
* 1.0
*
* Original Author:
*
* forrestyu
*
* Date:
*
* 2007-06-04
*
微微网(Piconet)
流程结构
2007-5-29:
修改led 指示 ,用7个led来指示状态
2007-5-30:
将spp* spp0,spp* spp1 ……….. ? spp*[stpred_size]
flag_init ? srored_index
修改查询状态?
多机串口数据通讯完成
通讯的?
通讯格式蚣
查
2007-06-04
查询的状态:
1,先查询 ,在规定的时间内取消查询,
2,MCU 通讯时 ,主动请求的数据,包含查询取消
3,查询的最大个数为12个 ,连接上把地址存起来
4, 在没有查询到任何有效的地址后,查询存储为空,连接不到任何地址
5,每一个BT 只连接一次 ,如果没有连接成功,则不再连接
6,连接上以后 ,需要将sink source 一一对应起来
7,查询到以后保存地址,连接时连接已经查询到的地址
8,对于断了的设备,如何重新去连接(SPP_DISCONNECT_IND)消息
9, 对于有别的slave要有连接 请求,则要?
*********************************************************************************/
#include "spp_dev_private.h"
#include "spp_dev_init.h"
#include "spp_dev_inquire.h"
#include "spp_dev_auth.h"
#include "spp_dev_store.h"
#include "spp_dev_connect.h"
#include "spp_dev_led.h"
#include <connection.h>
#include <panic.h>
#include <stdio.h>
#include <stream.h>
#include <pio.h>
#include <string.h>
#include <spp.h>
#include <source.h>
#include <ps.h>
#include <bdaddr.h>
#include <sink.h>
#include "spp_uart.h"
#include "opps.h"
#include "ftps.h"
#include <message.h>
#include <vm.h>
#include <stdlib.h>
#include <connection.h>
#include "ObexServer.h"
#define PC_window_view
typedef struct
{
TaskData PIO_task;
}PioState;
static sppTaskData theSppApp;
tOPPState OPPState;
tFTPState FTPState;
static tDUNstate DUNstate;
/*************************************************************************
NAME
unhandledSppState
DESCRIPTION
This function is called when a message arrives and the Spp app is
in an unexpected state.
RETURNS
*/
static void unhandledSppState(sppDevState state, MessageId id)
{
DEBUG(("UNHANDLED SPP current state %d message id 0x%x\n", state, id));
}
/***Added by linda begin ***/
/***************************************************************************
*/
void Setfirmware(void)
{
uint16 firmwarename[3] = {FIRMWARE_NAME,FIRMWARE_DATE, FIRMWARE_YEAR};
/* Disable SDP security */
ConnectionSmSetSdpSecurityIn(TRUE);
/* we write the firmware version here */
(void )PsStore (PSFIRMWARE, &firmwarename, sizeof(firmwarename));
}
/***Added by linda begin ***/
/*************************************************************************
NAME
setSppState
DESCRIPTION
Set the SPP State to the specified state
RETURNS
*/
void setSppState(const sppDevState state)
{
DEBUG(("SPP State - C=%d N=%d\n",theSppApp.spp_state, state));
theSppApp.spp_state = state;
sppDevUpdateLed(&theSppApp,state);
}
/*************************************************************************
NAME
sppAppTask
DESCRIPTION
Returns the spp app's main task.
RETURNS
Task
*/
Task getAppTask(void)
{
return &theSppApp.Connection_task;
}
/***********************************************************************
** the key function ,buttom key is used
**
**
************************************************************************/
static void pioHandler(Task task, MessageId id, Message data)
{
const MessagePioChanged *m = (const MessagePioChanged *)data;
switch(id)
{
case MESSAGE_PIO_CHANGED:
if (m->state == BUTTON_RESET)
{
DEBUG(("Button pressed\n"));
switch(theSppApp.spp_state)
{
case sppDevInitialising:
return;
break;
case sppDevReady:
sppDevInquire(&theSppApp);
break;
case sppDevInquiring:
case sppDevConnecting:
DEBUG(("Cancel Inquiry\n"));
ConnectionInquireCancel(getAppTask());
break;
case sppDevConnected:
DEBUG(("Disconnect\n"));
SppDisconnect(theSppApp.spp[0]);
break;
case sppDevDisconnecting:
break;
}
clear_far_addr(&theSppApp.bd_addr);
memset(StoredAddr, 0, sizeof(StoredAddr));
DEBUG(("End of Pio handler\n"));
}
default:
break;
}
}
static void PioInit(PioState* state)
{
state->PIO_task.handler = pioHandler;
MessagePioTask(&state->PIO_task);
PioDebounce(BUTTON_RESET, 1, 0);
}
static void Initial_variable(void)
{
theSppApp.saved_addr_index = 0;
}
static void Host_handler(Task task, MessageId id, Message message)
{
task = task;
message = message;
if ( id == MESSAGE_MORE_DATA )
{
DEBUG(("HOST_MESSAGE_MORE_DATA\n"));
/*(void) MessageCancelAll(task , MESSAGE_MORE_DATA);*/
UART_SEND_MCU(&theSppApp);
}
}
/* Task handler function */
static void app_handler(Task task, MessageId id, Message message)
{
sppDevState state = theSppApp.spp_state;
static slave_num stored_index;/* for inquire use*/
uint16 source_bytes_length;
bdaddr get_slave_addr;
uint8 loop;
uint8 TranBuff_SLAVE[Buff_length];
const uint8 *char_point;
const uint8 *char_point_tmp;
uint16 data_len;
uint8 Radio_Strength;
switch(id)
{
case CL_INIT_CFM:
DEBUG(("CL_INIT_CFM :- "));
if(((CL_INIT_CFM_T*)message)->status == success)
{
DEBUG(("success\n"));
ConnectionSmSetSdpSecurityIn(TRUE);
sppDevInit();
/* Start the OPP Server */
OppsInit(&OPPState.OppTask, 1);
/* Start the FTP Server */
FtpsInit(&FTPState.FtpTask, 1);
DunInit(&DUNstate.task, dunlibDCE,( 1<<1), ( 1<<2), ( 1<<3), ( 1<<4), 255 );
/* Make Server discoverable */
ConnectionWriteScanEnable(hci_scan_enable_inq_and_page);
stored_index=0;
}
else
{
Panic();
}
break;
case SPP_INIT_CFM:
DEBUG(("SPP_INIT_CFM =%d \n",((SPP_INIT_CFM_T *) message)->status ));
switch(state)
{
case sppDevInitialising:
/* Check for spp_init_success. What do we do if it failed? */
if (((SPP_INIT_CFM_T *) message)->status == spp_init_success)
{
DEBUG( ("spp_init_success slave_number = %d \n",stored_index) );
DEBUG( ( "spp_init_success SPP = 0x%x \n", (uint16)((SPP_INIT_CFM_T *) message)->spp) );
theSppApp.spp[stored_index] = ((SPP_INIT_CFM_T *) message)->spp;
stored_index++;
if(stored_index<slave_dundec)
sppDevInit();
/*else if(stored_index==slave_dundec)
SppInit(getAppTask(),dunDCE, 255);*/
else /*if(stored_index==slave_num_max)*/
{
sppDevInquire(&theSppApp);
}
}
break;
case sppDevInquiring:
break;
case sppDevReady:
case sppDevConnecting:
case sppDevConnected:
case sppDevDisconnecting:
default:
/*DEBUG( ("the SPP_INIT_CFM state = %d \n",state) );*/
unhandledSppState(state, id);
break;
}
break;
case CL_DM_INQUIRE_RESULT:
DEBUG(("CL_DM_INQUIRE_RESULT STATUS= %d\n",((CL_DM_INQUIRE_RESULT_T*)message)->status));
switch(state)
{
case sppDevInquiring:
case sppDevConnecting:
if (((CL_DM_INQUIRE_RESULT_T*)message)->status == inquiry_status_ready)
{
DEBUG(("Inquiry complete\n"));
sppDevConnect(&theSppApp);
}
else
{
DEBUG(("Found device\n"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -