l2cap-cmd/l2cap-cmd.c

Date:
2005/04/11
Author:
Ole Reinhard

Jan Beutel <j.beutel@ieee.org>

Example application to show the use of the Bluetooth L2CAP layer.

00001 /*
00002  * Copyright (C) 2000-2005 by ETH Zurich
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY ETH ZURICH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ETH ZURICH
00021  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.btnode.ethz.ch/
00031  *
00032  * $Id: l2cap-cmd.c,v 1.8 2006/03/27 14:14:04 kevmarti Exp $
00033  * 
00034  */
00035 
00076 #include <stdio.h>
00077 #include <string.h>
00078 #include <io.h>
00079 #include <stdlib.h>
00080 #include <dev/usart.h>
00081 #include <dev/usartavr.h>
00082 #include <sys/thread.h>
00083 #include <bt/bt_hci_cmds.h>
00084 #include <bt/bt_l2cap.h>
00085 #include <terminal/btn-terminal.h>
00086 #include <terminal/btn-cmds.h>
00087 #include <terminal/bt-cmds.h>
00088 #include <terminal/nut-cmds.h>
00089 #include <terminal/l2cap-cmds.h>
00090 #include <led/btn-led.h>
00091 #include <hardware/btn-hardware.h>
00092 
00093 #define BT_L2CAP_HCI_PACKET_TYPE         (BT_HCI_PACKET_TYPE_DM1 | BT_HCI_PACKET_TYPE_DH1 | \
00094                                           BT_HCI_PACKET_TYPE_DM3 | BT_HCI_PACKET_TYPE_DH3)
00095 
00096 /*
00097 #define BT_L2CAP_HCI_PACKET_TYPE        (BT_HCI_PACKET_TYPE_DM1 | BT_HCI_PACKET_TYPE_DH1 |\
00098                                          BT_HCI_PACKET_TYPE_DM3 | BT_HCI_PACKET_TYPE_DH3 |\
00099                                          BT_HCI_PACKET_TYPE_DM5 | BT_HCI_PACKET_TYPE_DH5)
00100 
00101 */
00102 
00103 FILE *uart_terminal;
00104 struct btstack* stack;
00105 struct bt_l2cap_stack* l2cap_stack;
00106 
00110 void init_term(void) {
00111     u_long baud = 57600;
00112     
00113     // initialize UART 1
00114     NutRegisterDevice(&APP_UART, 0, 0);
00115     uart_terminal = fopen(APP_UART.dev_name, "r+");
00116     _ioctl(_fileno(uart_terminal), UART_SETSPEED, &baud);
00117     btn_terminal_init(uart_terminal, "[bt-cmd@btnode]$");
00118 }
00119 
00125 int main(void)
00126 {
00127     //long retval;
00128     btn_hardware_init();
00129     // btnode init
00130     btn_led_init(1);
00131     init_term();
00132     btn_hardware_bt_on();
00133     
00134     // Register DebugDevice (there comes the output if DEBUG was enabled
00135     // during the compilation of the stack)
00136     //NutRegisterDevice( &devDebug1, 0, 0);
00137     freopen(APP_UART.dev_name, "w", stdout);
00138     DEBUGT("bt-cmd started...\n");
00139     
00140     // Start the stack and let the initialization begin
00141     stack = bt_hci_init(&BT_UART);
00142     
00143     bt_hci_write_local_cod(stack, BT_HCI_SYNC, 200);
00144     
00145     // init l2cap
00146     l2cap_stack =
00147         bt_l2cap_init(stack, 8, 8, BT_L2CAP_HCI_PACKET_TYPE);
00148 
00149     // terminal init
00150     bt_cmds_init(stack);
00151     l2cap_cmds_init(l2cap_stack, 1, BT_L2CAP_MIN_MTU, BT_L2CAP_MTU_DEFAULT);
00152     
00153     bt_cmds_register_cmds();
00154     btn_cmds_register_cmds();
00155     nut_cmds_register_cmds();
00156     l2cap_cmds_register_cmds();
00157     
00158     //register_cmds();
00159     DEBUGT("cmds registered\n");
00160     btn_terminal_run(BTN_TERMINAL_NOFORK, 0);
00161     return 0;
00162 }

Generated on Wed Apr 29 11:12:28 2009 for BTnut System Software by doxygen 1.5.1
!!! Dieses Dokument stammt aus dem ETH Web-Archiv und wird nicht mehr gepflegt !!!
!!! This document is stored in the ETH Web archive and is no longer maintained !!!