rfcomm-cmd/rfcomm-cmd.c

Date:
2005/04/11
Author:
Martin Hinz <btnode@hinz.ch>

Ole Reinhard

Jan Beutel <j.beutel@ieee.org>

Example application to show the use of the Bluetooth stack with RFCOMM and L2CAP layers.

00001 
00002 /*
00003  * Copyright (C) 2000-2004 by ETH Zurich
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. Neither the name of the copyright holders nor the names of
00015  *    contributors may be used to endorse or promote products derived
00016  *    from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY ETH ZURICH AND CONTRIBUTORS
00019  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00021  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ETH ZURICH
00022  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00023  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00024  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00025  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00026  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00027  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00028  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00029  * SUCH DAMAGE.
00030  *
00031  * For additional information see http://www.btnode.ethz.ch/
00032  *
00033  * $Id: rfcomm-cmd.c,v 1.8 2006/03/27 14:49:33 kevmarti Exp $
00034  * 
00035  */
00036 
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 <bt/bt_hci_cmds.h>
00083 #include <bt/bt_l2cap.h>
00084 #include <bt/bt_rfcomm.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 <terminal/rfcomm-cmds.h>
00091 #include <led/btn-led.h>
00092 #include <hardware/btn-hardware.h>
00093 
00094 #include "program_version.h"
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 
00100 /*
00101 #define BT_L2CAP_HCI_PACKET_TYPE        (BT_HCI_PACKET_TYPE_DM1 | BT_HCI_PACKET_TYPE_DH1 |\
00102                                          BT_HCI_PACKET_TYPE_DM3 | BT_HCI_PACKET_TYPE_DH3 |\
00103                                          BT_HCI_PACKET_TYPE_DM5 | BT_HCI_PACKET_TYPE_DH5)
00104 
00105 */
00106 
00107 FILE   *uart_terminal;
00108 struct btstack* stack;
00109 struct bt_l2cap_stack* l2cap_stack;
00110 struct bt_rfcomm_stack* rfcomm_stack;
00111 
00112 
00113 
00115 // * to initialize the terminal
00116 // */
00117 //void init_term(void) {
00118 //    u_long baud = 115200;
00119 //    
00120 //    // initialize UART 1
00121 //    NutRegisterDevice(&APP_UART, 0, 0);
00122 //    freopen(APP_UART.dev_name, "r+", stdout);
00123 //    _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
00124 //}
00125 
00126 
00132 int main(void)
00133 {
00134    // serial baud rate
00135     u_long baud = 57600;
00136 
00137     // hardware init
00138     btn_hardware_init();
00139     btn_led_init(1);
00140     
00141     // init app uart
00142     NutRegisterDevice(&APP_UART, 0, 0);
00143     freopen(APP_UART.dev_name, "r+", stdout);
00144     _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
00145     
00146     // hello world!
00147     printf_P(PSTR("\n# --------------------------------------------"));
00148     printf_P(PSTR("\n# Welcome to BTnut (c) 2005 ETH Zurich\n"));
00149     printf_P(PSTR("# rfcomm-cmd program version: %s\n"), PROGRAM_VERSION);
00150     printf_P(PSTR("# --------------------------------------------"));
00151     printf_P(PSTR("\nbooting bluetooth module... "));
00152 
00153     // bluetooth module on (takes a while)
00154     btn_hardware_bt_on();
00155     
00156     // verbose debug of all hci information
00157     //_bt_hci_debug_uart = 1;
00158        
00159     // Start the stack and let the initialization begin
00160     stack = bt_hci_init(&BT_UART);
00161     bt_hci_write_local_cod(stack, BT_HCI_SYNC, 200);
00162     printf_P(PSTR("ok.\n\r"));
00163 
00164     // give hint
00165     printf_P(PSTR("hit tab twice for a list of commands\n\r"));
00166     
00167     // Register DebugDevice (there comes the output if DEBUG was enabled
00168     // during the compilation of the stack)
00169     //NutRegisterDevice( &devDebug1, 0, 0);
00170     //freopen(APP_UART.dev_name, "w", stdout);
00171     //DEBUGT("rfcomm-cmd started...\n");
00172 
00173     // terminal init
00174     btn_terminal_init(stdout, "[rfcomm-cmd]$");
00175     bt_cmds_init(stack);
00176 
00177     // Start L2CAP and RFCOMM
00178     l2cap_stack = bt_l2cap_init(stack, 8, 8, BT_L2CAP_HCI_PACKET_TYPE);
00179     l2cap_cmds_init(l2cap_stack, 1, BT_L2CAP_MIN_MTU, BT_L2CAP_MTU_DEFAULT);
00180    
00181     rfcomm_stack = bt_rfcomm_init(l2cap_stack, BT_RFCOMM_DEF_MFS, 4, 5);
00182     rfcomm_cmds_init();
00183 
00184     bt_cmds_register_cmds();
00185     btn_cmds_register_cmds();
00186     nut_cmds_register_cmds();
00187     l2cap_cmds_register_cmds();
00188     rfcomm_cmds_register_cmds();
00189 
00190     // terminal mode
00191     btn_terminal_run(BTN_TERMINAL_NOFORK, 0);
00192     return 0;
00193 }

Generated on Wed Apr 29 11:12:28 2009 for BTnut System Software by doxygen 1.5.1