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

📄 main.c

📁 通过蓝牙实现OPP功能。。 比如和NOKIA MOTO的蓝牙手机 对传名片
💻 C
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2004-2006
Part of BlueLab 3.6.2-release

FILE NAME
    main.c
    
DESCRIPTION
	Main source file for an OPP Server application.
	Performs initialisation
*/

#include "opps.h"
#include <message.h>
#include <vm.h>
#include <stdlib.h>
#include <connection.h>

#include "OPPServer.h"


tOPPState OPPState;
tMainState MainState;

#define OBJECT_TRANS_COD ((uint32)1<<20)


static void connect_handler(Task task, MessageId id, Message message)
{
	/* Get task control block */
	tMainState *state = (tMainState*)task;

	state = state;

	switch(id)
	{
	case CL_INIT_CFM:
	{
		CL_INIT_CFM_T *msg = (CL_INIT_CFM_T*)message;
		CON_DEBUG(("CL_INIT_CFM :- "));
		if (msg->status == success)
		{
			GEN_DEBUG(("success\n"));
			ConnectionSmSetSdpSecurityIn(TRUE);

			/* Start the OPP Server */
			OppsInit(&OPPState.OppTask, 1);
			
			/* Get class of device so we can include Object Transfer */
			ConnectionReadClassOfDevice(&state->ConTask);
		}
		else
			GEN_DEBUG(("failure : %d\n", msg->status));

		break;
	}
	case CL_DM_CLASS_OF_DEVICE_CFM:
	{
		CL_DM_CLASS_OF_DEVICE_CFM_T *msg = (CL_DM_CLASS_OF_DEVICE_CFM_T*)message;
		uint32 cod = msg->dev_class;
		CON_DEBUG(("CL_DM_CLASS_OF_DEVICE_CFM\n"));
		CON_DEBUG(("    Before 0x%X%X\n",(uint16)(cod>>16), (uint16)(cod & 0xffff)));
		cod |= OBJECT_TRANS_COD;
		CON_DEBUG(("     After 0x%X%X\n",(uint16)(cod>>16), (uint16)(cod & 0xffff)));
		
		ConnectionWriteClassOfDevice(cod);
	}
	case CL_SM_PIN_CODE_IND:
	{
		CL_SM_PIN_CODE_IND_T *msg = (CL_SM_PIN_CODE_IND_T*)message;
		uint8 pin_code[4] = {'1','2','3','4'};

		CON_DEBUG(("CL_SM_PIN_REQUEST_IND\n"));
		ConnectionSmPinCodeResponse(&msg->bd_addr, 4, &pin_code[0]); 
		break;
	}
	case CL_SM_AUTHORISE_IND:
	{
		CL_SM_AUTHORISE_IND_T *msg = (CL_SM_AUTHORISE_IND_T*)message;

		ConnectionSmAuthoriseResponse(&msg->bd_addr, msg->protocol_id, msg->channel, msg->incoming, TRUE);
		CON_DEBUG(("CL_SM_AUTHORISE_IND\n"));
		break;
	}

	default:
		CON_DEBUG(("Unhandled Message : %d , 0x%0X\n",id,id)); 
		break;
	}
}

int main(void)
{
	/* Set up Connection Manager message handler */
	MainState.ConTask.handler = connect_handler;

	/* Set up FTP Server message handler */
	opp_initTask(&OPPState);

	GEN_DEBUG(("OPP Server App. Started\n"));

	ConnectionInit(&MainState.ConTask);

	/* Start the message scheduler loop */
	MessageLoop();

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

⌨️ 快捷键说明

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