Пример #1
0
void Bluetooth::init(const char *iname){
	int result;
	this->name = iname;

	if (!EEPROM::instance().read(EEPROM::VAR_LAST_LINK_KEY, 0, &lastLinkKeyIndex, sizeof(lastLinkKeyIndex))){
		lastLinkKeyIndex=0;
	}

	for (int a=0; a<MAX_SUPPORTED_LINK_KEYS; a++){
		//Can't read in one pass because not all link keys are stored. If a non-existing key is tried to read,
		//read will fail and the key will be initialized to 0.
		if (!EEPROM::instance().read(EEPROM::VAR_LINKKEY, a*sizeof(LinkKeyInfo_t), &linkKeyInfo[a], sizeof(LinkKeyInfo_t))){
			memset(&linkKeyInfo[a], 0, sizeof(LinkKeyInfo_t));
		}
	}


	HCI_DRIVER_SET_COMM_INFORMATION(&HCI_DriverInformation, 1, VENDOR_BAUD_RATE, cpHCILL_RTS_CTS);
	HCI_DriverInformation.DriverInformation.COMMDriverInformation.InitializationDelay = 100;

	/* Set up the application callbacks.                                 */
	BTPS_Initialization.MessageOutputCallback = displayCallback;

	/* Initialize the application.                                       */
	if((result = initializeApplication()) > 0){
	//	if (!setClassOfDevice(0x80510)){
			openServer(SPP_PORT_NUMBER_MINIMUM);
	//	}
	}
}
Пример #2
0
static void MainThread(void) {
	unsigned int BluetoothStackID;
	int Result;
	BTPS_Initialization_t BTPS_Initialization;
	HCI_DriverInformation_t HCI_DriverInformation;

	/* Configure the UART Parameters.                                    */
	HCI_DRIVER_SET_COMM_INFORMATION(&HCI_DriverInformation, 1, 115200, cpUART);
	HCI_DriverInformation.DriverInformation.COMMDriverInformation.InitializationDelay =
			100;

	/* Set up the application callbacks.                                 */
	BTPS_Initialization.GetTickCountCallback = GetTickCallback;
	BTPS_Initialization.MessageOutputCallback = DisplayCallback;

	/* Initialize the application.                                       */
	if ((Result = InitializeApplication(&HCI_DriverInformation,
			&BTPS_Initialization)) > 0) {
		/* Save the Bluetooth Stack ID.                                   */
		BluetoothStackID = (unsigned int) Result;

		/* Go ahead an enable HCILL Mode.                                 */
		HCILL_Init();
		HCILL_Configure(BluetoothStackID, HCILL_MODE_INACTIVITY_TIMEOUT,
				HCILL_MODE_RETRANSMIT_TIMEOUT, TRUE);

		/* Call the main application state machine.                       */
		while (1) {
			ApplicationMain();
		}
	}
}