Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1918 - 1
/*****************************************************************************
2
 *   Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de                  *
3
 *   Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net                  *
4
 *   Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
5
 *   Copyright (C) 2011 Harald Bongartz                                      *
6
 *                                                                           *
7
 *   This program is free software; you can redistribute it and/or modify    *
8
 *   it under the terms of the GNU General Public License as published by    *
9
 *   the Free Software Foundation; either version 2 of the License.          *
10
 *                                                                           *
11
 *   This program is distributed in the hope that it will be useful,         *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
14
 *   GNU General Public License for more details.                            *
15
 *                                                                           *
16
 *   You should have received a copy of the GNU General Public License       *
17
 *   along with this program; if not, write to the                           *
18
 *   Free Software Foundation, Inc.,                                         *
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
20
 *                                                                           *
21
 *                                                                           *
22
 *   Credits to:                                                             *
23
 *   Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN  *
24
 *                          http://www.mikrokopter.de                        *
25
 *   Gregor "killagreg" Stobrawa for his version of the MK code              *
26
 *   Thomas Kaiser "thkais" for the original project. See                    *
27
 *                          http://www.ft-fanpage.de/mikrokopter/            *
28
 *                          http://forum.mikrokopter.de/topic-4061-1.html    *
29
 *   Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
30
 *                          http://www.mylifesucks.de/oss/c-osd/             *
31
 *   Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
32
 *****************************************************************************/
33
 
34
 
35
#ifndef _BLUETOOTH_H_
36
#define _BLUETOOTH_H_
37
 
38
#include <avr/io.h>
39
//#include <common.h>
40
 
41
 
42
#define SQUIRREL
43
#define NUTS_LIST 16
44
#define EXTENSIONS_LIST 16
45
#define RXD_BUFFER_SIZE         150
46
//void InitBT(void);
47
 
48
extern char bt_rx_buffer[RXD_BUFFER_SIZE];
49
extern volatile uint8_t bt_rx_len;
50
extern volatile uint8_t bt_rx_ready;
51
extern uint8_t rx_GPS;
52
//extern static char start = '$';
53
//extern static char end = '\n';
54
extern char data_decode[RXD_BUFFER_SIZE];
55
extern volatile uint16_t rx_timeout;
56
extern uint8_t bt_rxerror;
57
 
58
extern uint8_t BT_New_Baudrate;              //Merkzelle für zu setzende Baudrate
59
 
60
typedef struct _device_info device_info;
61
 
62
// device info struct, holds mac , class and extensions + values of a device
63
struct _device_info
64
{
65
    char DevName[20];
66
    char mac[14];
67
 
68
//    uint8_t class;
69
//    uint8_t extension_types[EXTENSIONS_LIST];
70
//    uint16_t values_cache[EXTENSIONS_LIST];
71
};
72
extern uint8_t bt_devicecount;
73
extern device_info device_list[NUTS_LIST];
74
extern char localID[15];
75
#define valid(num) (num < NUTS_LIST && (device_list[num].mac[0] != 0 || device_list[num].mac[1] != 0 || device_list[num].mac[2] != 0 || device_list[num].mac[3] != 0 || device_list[num].mac[4] != 0 || device_list[num].mac[5] != 0 || device_list[num].mac[6] != 0 || device_list[num].mac[7] != 0 || device_list[num].mac[8] != 0 || device_list[num].mac[9] != 0 || device_list[num].mac[10] != 0 || device_list[num].mac[11] != 0))
76
 
77
extern volatile uint8_t bt_receiveNMEA(void);
78
 
79
extern void bt_start(void); // EchoAnswervariable setzen
80
void bt_set_EchoAnswer (uint8_t onoff);
81
 
82
extern uint8_t bt_getID (void);
83
 
84
//extern static communication_mode_t update_comm_mode(uint16_t timeout_ms);
85
 
86
// Bluetooth mode ENUM
87
typedef enum
88
{
89
    BLUETOOTH_MASTER, // < Master Mode (to create outgoinng connections).
90
    BLUETOOTH_SLAVE   // < Slave Mode (to wait for incoming connections).
91
} bt_mode_t;
92
 
93
// set baudrate bluetooth
94
// @return true = ok
95
//         false = error
96
//extern uint16_t bt_setbaud (uint8_t baudrate);
97
uint16_t bt_setbaud(uint8_t baudrate);
98
 
99
// init bluetooth driver
100
// @return always true
101
//
102
//extern uint16_t bt_init (void (*upate_percentage) (uint16_t));
103
extern uint16_t bt_init (void);
104
 
105
// Set the Bluetooth mode
106
// @param mode bt_mode_t Bluetooth Mode ENUM (BLUETOOTH_MASTER or BLUETOOTH_SLAVE)
107
// @return true if mode change was succesful, false if not
108
//
109
extern uint8_t bt_set_mode (const bt_mode_t mode);
110
 
111
// recieve data over bluetooth
112
// @param data pointer to memory for data storage
113
// @param length value of length after call holds the actual recived data length
114
// @param timeout_ms timeout in ms after the recive function aborts and returns with false
115
// @return false if recived length > length parameter or it timeouted, true otherwise
116
//
117
extern uint16_t bt_receive (void * data, uint8_t length, uint16_t timeout_ms);
118
 
119
// send data over bluetooth
120
// @param data pointer to the data to send
121
// @param length length of the data to be send
122
// @return true if sendingn was successful, false otherwise
123
//
124
extern uint16_t bt_send (void * data, const uint8_t length);
125
 
126
// squirrelt only functions
127
#ifdef SQUIRREL
128
 
129
// open bluetoot connection (only one at a time possible)
130
// @param address connection is opened to this device mac address
131
// @return true if connection was established, false otherwise
132
//
133
extern uint16_t bt_connect (const char *address);
134
 
135
// closes bluetooth connection
136
// @return false if failed, true otherwise
137
//
138
extern uint16_t bt_disconnect (void);
139
 
140
// discover bluetooth devices
141
// @param result in a 2 dimensional array first index are devicecs (max 8) second is mac address string
142
// @param update_callback to inform of progress (in % from 0 to 100)
143
// @return true if successful, false if error occured
144
//
145
extern uint16_t bt_discover (char result[8][12]);
146
//extern uint16_t bt_discover (char result[8][12], void (*update_callback)(const uint16_t progress));
147
 
148
extern void bt_downlink_init(void);        // Auf Master stellen für Devicesuche und GPS Empfang
149
 
150
extern void bt_searchDevice(void);              //Bluetoothgeräte suchen
151
 
152
#endif  // SQUIRREL
153
 
154
 
155
#endif
156