Remove Bluegiga (#3649)
Issues due date / Add labels to issues (push) Has been cancelled
Doxygen / build (push) Has been cancelled

Co-authored-by: Fabien-B <Fabien-B@github.com>
This commit is contained in:
Fabien-B
2026-04-21 23:36:25 +02:00
committed by GitHub
parent 1be5589a2d
commit f4d0575271
34 changed files with 0 additions and 10899 deletions
-1
View File
@@ -166,7 +166,6 @@ sim_static: libpprz
ext:
$(MAKE) -C $(EXT)
$(MAKE) -C $(TOOLS)/bluegiga_usb_dongle
opencv_bebop:
$(MAKE) -C $(EXT) opencv_bebop
@@ -70,16 +70,6 @@
<arg flag="--port" constant="/dev/ttyUSB1"/>
<arg flag="--id" constant="1"/>
</program>
<program name="BluegigaUsbDongleScanner" command="sw/tools/bluegiga_usb_dongle/bluegiga_usb_driver">
<arg flag="/dev/ttyACM2"/>
<arg flag="scan" />
</program>
<program name="BluegigaUsbDongle" command="sw/tools/bluegiga_usb_dongle/bluegiga_usb_driver">
<arg flag="/dev/ttyACM2"/>
<arg flag="00:07:00:2d:d6:bb" />
<arg flag="4242" />
<arg flag="4252" />
</program>
<program name="ADS-B Intruders receiver" command="sw/ground_segment/misc/sbs2ivy">
<arg flag="--ac" constant="@AC_ID"/>
</program>
-53
View File
@@ -1,53 +0,0 @@
<!DOCTYPE module SYSTEM "module.dtd">
<module name="telemetry_bluegiga" dir="datalink" task="datalink">
<doc>
<description>
Telemetry using PPRZ protocol over Bluegiga modules
Bluegiga is a SPI-slave device without Chip select but with a compulsory DRDY
Required:
BLUEGIGA_SPI_DEV: the SPI device which MUST have a SLAVE mode without chipselect
Optional: (defaults to SUPERBITRF DRDY)
BLUEGIGA_DRDY_GPIO
BLUEGIGA_DRDY_GPIO_PIN
</description>
<configure name="BLUEGIGA_SPI_DEV" value="SPIx" description="SPI where the modem is connected to (SPI1, SPI2, etc)"/>
<configure name="MODEM_LED" value="none" description="LED number for modem status, 'none' to disable"/>
<define name="BLUEGIGA_DRDY_GPIO" value="GPIOX" description="GPIO port used for data ready pin"/>
<define name="BLUEGIGA_DRDY_GPIO_PIN" value="GPIOY" description="GPIO pin number used for data ready pin"/>
</doc>
<dep>
<depends>spi_master,datalink_common</depends>
<provides>datalink,telemetry</provides>
</dep>
<header>
<file name="bluegiga_dl.h"/>
</header>
<init fun="bluegiga_dl_init()"/>
<event fun="bluegiga_dl_event()"/>
<makefile target="!sim|nps">
<configure name="BLUEGIGA_SPI_DEV" default="SPI2" case="upper|lower"/>
<configure name="MODEM_LED" default="none"/>
<define name="USE_$(BLUEGIGA_SPI_DEV_UPPER)_SLAVE"/>
<define name="SPI_SLAVE"/>
<define name="BLUEGIGA_SPI_DEV" value="$(BLUEGIGA_SPI_DEV_LOWER)"/>
<define name="MODEM_LED" value="$(MODEM_LED)" cond="ifneq ($(MODEM_LED),none)"/>
<define name="DOWNLINK_DEVICE" value="bluegiga_p"/>
<define name="DOWNLINK_TRANSPORT" value="pprz_bg_tp"/>
<define name="DATALINK" value="BLUEGIGA"/>
<file name="bluegiga_dl.c"/>
<file name="pprz_transport.c" dir="pprzlink/src"/>
<file name="bluegiga.c"/>
<test>
<define name="BLUEGIGA_DRDY_GPIO" value="GPIOA"/>
<define name="BLUEGIGA_DRDY_GPIO_PIN" value="GPIO0"/>
<define name="DOWNLINK_DEVICE" value="bluegiga_p"/>
<define name="BLUEGIGA_SPI_DEV" value="spi2"/>
<define name="SPI_SLAVE"/>
<define name="USE_SPI2_SLAVE"/>
</test>
</makefile>
</module>
@@ -20,7 +20,6 @@
<message name="I2C_ERRORS" period="6.1"/>
<message name="UART_ERRORS" period="4.1"/>
<message name="SUPERBITRF" period="4"/>
<message name="BLUEGIGA" period="4"/>
<message name="ENERGY" period="3.5"/>
<message name="DATALINK_REPORT" period="6.1"/>
<message name="STATE_FILTER_STATUS" period="4.2"/>
-7
View File
@@ -1,7 +0,0 @@
<program command="sw/tools/bluegiga_usb_dongle/bluegiga_usb_driver" name="BluegigaUsbDongle">
<arg flag="/dev/ttyACM2" />
<arg flag="00:07:00:2d:d6:bb" />
<arg flag="4242" />
<arg flag="4252" />
</program>
-5
View File
@@ -1,5 +0,0 @@
<program command="sw/tools/bluegiga_usb_dongle/bluegiga_usb_driver" name="BluegigaUsbDongleScanner">
<arg flag="/dev/ttyACM2" />
<arg flag="scan" />
</program>
-85
View File
@@ -8,68 +8,6 @@
</section>
<section name="sessions">
<session name="Bluegiga">
<program name="BluegigaUsbDongle">
<arg flag="/dev/ttyACM2" constant="all"/>
<arg flag="4242" constant="4252"/>
</program>
<program name="Data Link">
<arg flag="-udp"/>
<arg flag="-udp_port" constant="4242"/>
<arg flag="-udp_uplink_port" constant="4252"/>
</program>
<program name="Server"/>
<program name="Messages"/>
<program name="GCS">
<arg flag="-speech"/>
</program>
<program name="NatNet3">
<arg flag="-ac" constant="1"/>
<arg flag="12"/>
<arg flag="-sm"/>
<arg flag="-f" constant="5"/>
<arg flag="-o"/>
<arg flag="-zf"/>
</program>
<program name="Joystick">
<arg flag="-d" constant="2"/>
<arg flag="-ac" constant="@AIRCRAFT"/>
<arg flag="hobbyking.xml"/>
</program>
</session>
<session name="Bluegiga">
<program name="Data Link">
<arg flag="-udp"/>
<arg flag="-udp_port" constant="4242"/>
<arg flag="-udp_uplink_port" constant="4252"/>
</program>
<program name="Server"/>
<program name="Messages"/>
<program name="GCS">
<arg flag="-speech"/>
</program>
<program name="NatNet3">
<arg flag="-ac" constant="7"/>
<arg flag="114"/>
<arg flag="-sm"/>
<arg flag="-f" constant="5"/>
<arg flag="-o"/>
<arg flag="-zf"/>
</program>
<program name="Joystick">
<arg flag="-d" constant="2"/>
<arg flag="-ac" constant="@AIRCRAFT"/>
<arg flag="hobbyking.xml"/>
</program>
<program name="BluegigaUsbDongle">
<arg flag="/dev/ttyACM2"/>
<arg flag="00:07:80:2d:e0:4b"/>
<arg flag="4242"/>
<arg flag="4252"/>
</program>
</session>
<session name="EKF Full">
<program name="Data Link">
<arg flag="-d" constant="/dev/ttyUSB0"/>
@@ -453,29 +391,6 @@
</program>
<program name="Gazebo"/>
</session>
<session name="helidd">
<program name="BluegigaUsbDongle">
<arg flag="/dev/ttyACM0" constant="00:07:80:2d:d6:d9"/>
<arg flag="4242" constant="4252"/>
</program>
<program name="Data Link">
<arg flag="-udp"/>
<arg flag="-udp_port" constant="4242"/>
<arg flag="-udp_uplink_port" constant="4252"/>
</program>
<program name="Server"/>
<program name="Messages"/>
<program name="GCS">
<arg flag="-speech"/>
</program>
<program name="Joystick">
<arg flag="-d" constant="2"/>
<arg flag="-ac" constant="GeniusDD"/>
<arg flag="hobbyking.xml"/>
</program>
</session>
<session name="Ship">
<program name="Data Link">
<arg flag="-udp"/>
@@ -493,13 +493,6 @@
#define VEL_OPTICFLOW_PMW3901_ID 6
#endif
/*
* IDs of RSSI measurements (message 13)
*/
#ifndef RSSI_BLUEGIGA_ID
#define RSSI_BLUEGIGA_ID 1
#endif
/*
* IDs of ACT_FEEDBACK sensors (message 15)
*/
-368
View File
@@ -1,368 +0,0 @@
/*
* Copyright (C) 2014 Kirk Scheper <kirkscheper@gmail.com>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
/**
* @file modules/datalink/bluegiga.c
* Datalink implementation for the BlueGiga Bluetooth radio chip trough SPI
*/
#include "mcu_periph/sys_time.h"
#include "modules/datalink/bluegiga.h"
#include "mcu_periph/gpio.h"
#include "mcu_periph/spi.h"
#ifdef MODEM_LED
#include "led.h"
#endif
#include "modules/core/abi.h"
// for memset
#include <string.h>
#ifndef BLUEGIGA_SPI_DEV
#error "bluegiga: must define a BLUEGIGA_SPI_DEV"
#endif
// Bluegiga: DRDY defaults to SuperbitRf DRDY
#ifndef BLUEGIGA_DRDY_GPIO
#define BLUEGIGA_DRDY_GPIO SUPERBITRF_DRDY_PORT
#endif
#ifndef BLUEGIGA_DRDY_GPIO_PIN
#define BLUEGIGA_DRDY_GPIO_PIN SUPERBITRF_DRDY_PIN
#endif
#define TxStrengthOfSender(x) (x[1])
#define RssiOfSender(x) (x[2])
#define Pprz_StxOfMsg(x) (x[3])
#define SenderIdOfBGMsg(x) (x[5])
enum BlueGigaStatus coms_status;
struct bluegiga_periph bluegiga_p;
struct spi_transaction bluegiga_spi;
uint8_t broadcast_msg[20];
void bluegiga_load_tx(struct bluegiga_periph *p);
void bluegiga_transmit(struct bluegiga_periph *p, uint8_t data);
void bluegiga_receive(struct spi_transaction *trans);
// Functions for the generic link device device API
static int dev_check_free_space(struct bluegiga_periph *p, long *fd __attribute__((unused)), uint16_t len)
{
// check if there is enough space for message
// NB if BLUEGIGA_BUFFER_SIZE is smaller than 256 then an additional check is needed that len < BLUEGIGA_BUFFER_SIZE
if (len - 1 <= ((p->tx_extract_idx - p->tx_insert_idx - 1 + BLUEGIGA_BUFFER_SIZE) % BLUEGIGA_BUFFER_SIZE)) {
return true;
}
return false;
}
static void dev_put_buffer(struct bluegiga_periph *p, long fd __attribute__((unused)), uint8_t *data, uint16_t len)
{
int i;
for (i = 0; i < len; i++) {
bluegiga_transmit(p, data[i]);
}
}
static void dev_put_byte(struct bluegiga_periph *p, long fd __attribute__((unused)), uint8_t byte)
{
bluegiga_transmit(p, byte);
}
static void dev_send_message(struct bluegiga_periph *p, long fd __attribute__((unused)))
{
p->end_of_msg = p->tx_insert_idx;
}
static int dev_char_available(struct bluegiga_periph *p)
{
return bluegiga_ch_available(p);
}
// note, need to run dev_char_available first
static uint8_t dev_get_byte(struct bluegiga_periph *p)
{
uint8_t ret = p->rx_buf[p->rx_extract_idx];
bluegiga_increment_buf(&p->rx_extract_idx, 1);
return ret;
}
// Functions for the generic spi device API
static void trans_cb(struct spi_transaction *trans)
{
bluegiga_receive(trans);
}
/* check if character available in receive buffer */
bool bluegiga_ch_available(struct bluegiga_periph *p)
{
return (p->rx_extract_idx != p->rx_insert_idx);
}
/* safe increment of circular buffer */
void bluegiga_increment_buf(uint8_t *buf_idx, uint8_t len)
{
*buf_idx = (*buf_idx + len) % BLUEGIGA_BUFFER_SIZE;
}
uint32_t a2a_msgs = 0;
#if PERIODIC_TELEMETRY
#include "modules/datalink/telemetry.h"
uint32_t last_ts = 0;
static void send_bluegiga(struct transport_tx *trans, struct link_device *dev)
{
uint32_t now_ts = get_sys_time_msec();
if (now_ts > last_ts) {
uint32_t rate = 1000 * bluegiga_p.bytes_recvd_since_last / (now_ts - last_ts);
uint32_t a2a_rate = 1000 * a2a_msgs / (now_ts - last_ts);
pprz_msg_send_BLUEGIGA(trans, dev, AC_ID, &rate, &a2a_rate);
a2a_msgs = 0;
bluegiga_p.bytes_recvd_since_last = 0;
last_ts = now_ts;
}
}
#endif
void bluegiga_init(struct bluegiga_periph *p)
{
#ifdef MODEM_LED
LED_INIT(MODEM_LED);
#endif
// configure the SPI bus
bluegiga_spi.input_buf = p->work_rx;
bluegiga_spi.output_buf = p->work_tx;
bluegiga_spi.input_length = BLUEGIGA_SPI_BUF_SIZE;
bluegiga_spi.output_length = BLUEGIGA_SPI_BUF_SIZE;
bluegiga_spi.slave_idx = 0; // Not used for SPI-Slave: always NSS pin
bluegiga_spi.select = SPISelectUnselect;
bluegiga_spi.cpol = SPICpolIdleHigh;
bluegiga_spi.cpha = SPICphaEdge2;
bluegiga_spi.dss = SPIDss8bit;
bluegiga_spi.bitorder = SPIMSBFirst;
bluegiga_spi.cdiv = SPIDiv256;
bluegiga_spi.after_cb = (SPICallback) trans_cb;
// Configure generic link device
p->device.periph = (void *)(p);
p->device.check_free_space = (check_free_space_t) dev_check_free_space;
p->device.put_byte = (put_byte_t) dev_put_byte;
p->device.put_buffer = (put_buffer_t) dev_put_buffer;
p->device.send_message = (send_message_t) dev_send_message;
p->device.char_available = (char_available_t) dev_char_available;
p->device.get_byte = (get_byte_t) dev_get_byte;
// initialize peripheral variables
p->rx_insert_idx = 0;
p->rx_extract_idx = 0;
p->tx_insert_idx = 0;
p->tx_extract_idx = 0;
memset(p->work_rx, 0, bluegiga_spi.input_length);
memset(p->work_tx, 0, bluegiga_spi.output_length);
memset(broadcast_msg, 0, 19);
p->bytes_recvd_since_last = 0;
p->end_of_msg = p->tx_insert_idx;
p->connected = 0;
// set DRDY interrupt pin for spi master triggered on falling edge
gpio_setup_output(BLUEGIGA_DRDY_GPIO, BLUEGIGA_DRDY_GPIO_PIN);
gpio_set(BLUEGIGA_DRDY_GPIO, BLUEGIGA_DRDY_GPIO_PIN);
coms_status = BLUEGIGA_UNINIT;
#if PERIODIC_TELEMETRY
register_periodic_telemetry(DefaultPeriodic, PPRZ_MSG_ID_BLUEGIGA, send_bluegiga);
#endif
// register spi slave read for transaction
spi_slave_register(&(BLUEGIGA_SPI_DEV), &bluegiga_spi);
}
/* Add one byte to the end of tx circular buffer */
void bluegiga_transmit(struct bluegiga_periph *p, uint8_t data)
{
long fd = 0;
if (dev_check_free_space(p, &fd, 1) && coms_status != BLUEGIGA_UNINIT) {
p->tx_buf[p->tx_insert_idx] = data;
bluegiga_increment_buf(&p->tx_insert_idx, 1);
}
}
/* Load waiting data into tx peripheral buffer */
void bluegiga_load_tx(struct bluegiga_periph *p)
{
uint8_t packet_len;
// check data available in buffer to send
packet_len = ((p->end_of_msg - p->tx_extract_idx + BLUEGIGA_BUFFER_SIZE) % BLUEGIGA_BUFFER_SIZE);
if (packet_len > 19) {
packet_len = 19;
}
if (packet_len && coms_status == BLUEGIGA_IDLE) {
uint8_t i;
// attach header with data length of real data in 20 char data string
p->work_tx[0] = packet_len;
// copy data from working buffer to spi output buffer
for (i = 0; i < packet_len; i++) {
p->work_tx[i + 1] = p->tx_buf[(p->tx_extract_idx + i) % BLUEGIGA_BUFFER_SIZE];
}
bluegiga_increment_buf(&p->tx_extract_idx, packet_len);
// clear unused bytes
for (i = packet_len + 1; i < BLUEGIGA_SPI_BUF_SIZE; i++) {
p->work_tx[i] = 0;
}
coms_status = BLUEGIGA_SENDING;
}
}
/* read data from dma if available, set as call back of successful spi exchange
*
* TODO Remove use of bluegiga_p global in following function
*/
void bluegiga_receive(struct spi_transaction *trans)
{
if (trans->status == SPITransSuccess) {
// handle successful msg send
if (coms_status == BLUEGIGA_SENDING) {
// empty transfer buffer
for (uint8_t i = 0; i < trans->output_length; i++) {
trans->output_buf[i] = 0;
}
} else if (coms_status == BLUEGIGA_SENDING_BROADCAST) {
// sending second half of broadcast message
for (uint8_t i = 0; i < broadcast_msg[0]; i++) {
trans->output_buf[i] = broadcast_msg[i];
}
coms_status = BLUEGIGA_SENDING;
return;
}
/*
* >235 data package from broadcast mode
* 0x50 communication lost with ground station
* 0x51 interrupt handled
* <20 data package from connection
*/
uint8_t packet_len = 0;
uint8_t read_offset = 0;
switch (trans->input_buf[0]) {
case 0x50: // communication status changed
bluegiga_p.connected = trans->input_buf[1];
if (bluegiga_p.connected) {
//telemetry_mode_Main = TELEMETRY_PROCESS_Main;
} else {
//telemetry_mode_Main = NB_TELEMETRY_MODES; // send no periodic telemetry
}
coms_status = BLUEGIGA_IDLE;
break;
case 0x51: // Interrupt handled
gpio_set(BLUEGIGA_DRDY_GPIO, BLUEGIGA_DRDY_GPIO_PIN); // Reset interrupt pin
break;
default:
coms_status = BLUEGIGA_IDLE;
// compute length of transmitted message
if (trans->input_buf[0] < trans->input_length) { // normal connection mode
packet_len = trans->input_buf[0];
read_offset = 1;
} else if (trans->input_buf[0] > 0xff - trans->input_length) { // broadcast mode
packet_len = 0xff - trans->input_buf[0];
if (packet_len > 3)
{
#ifdef MODEM_LED
LED_TOGGLE(MODEM_LED);
#endif
int8_t tx_strength = TxStrengthOfSender(trans->input_buf);
int8_t rssi = RssiOfSender(trans->input_buf);
uint8_t ac_id = SenderIdOfBGMsg(trans->input_buf);
if (Pprz_StxOfMsg(trans->input_buf) == PPRZ_STX) {
AbiSendMsgRSSI(RSSI_BLUEGIGA_ID, ac_id, tx_strength, rssi);
}
a2a_msgs++;
}
read_offset = 3;
}
}
// handle incoming datalink message
if (packet_len > 0 && packet_len <= trans->input_length - read_offset) {
//#ifdef MODEM_LED
// LED_TOGGLE(MODEM_LED);
//#endif
// Handle received message
for (uint8_t i = 0; i < packet_len; i++) {
bluegiga_p.rx_buf[(bluegiga_p.rx_insert_idx + i) % BLUEGIGA_BUFFER_SIZE] = trans->input_buf[i + read_offset];
}
bluegiga_increment_buf(&bluegiga_p.rx_insert_idx, packet_len);
bluegiga_p.bytes_recvd_since_last += packet_len;
}
// load next message to be sent into work buffer, needs to be loaded before calling spi_slave_register
bluegiga_load_tx(&bluegiga_p);
// register spi slave read for next transaction
spi_slave_register(&(BLUEGIGA_SPI_DEV), trans);
}
}
/* Send data for broadcast message to the bluegiga module
* maximum size of message is 22 bytes
*/
void bluegiga_broadcast_msg(struct bluegiga_periph *p, char *msg, uint8_t msg_len)
{
if (msg_len == 0 || msg_len > 22) {
return;
}
uint8_t max_length = 20;
p->work_tx[0] = msg_len;
if (msg_len < max_length) {
for (uint8_t i = 0; i < msg_len; i++) {
p->work_tx[i + 1] = msg[i];
}
coms_status = BLUEGIGA_SENDING;
} else {
for (uint8_t i = 0; i < max_length - 1; i++) {
p->work_tx[i + 1] = msg[i];
}
memcpy(broadcast_msg, msg + max_length - 1, msg_len - (max_length - 1));
coms_status = BLUEGIGA_SENDING_BROADCAST;
}
// trigger bluegiga to read direct command
gpio_clear(BLUEGIGA_DRDY_GPIO, BLUEGIGA_DRDY_GPIO_PIN); // set interrupt
}
-85
View File
@@ -1,85 +0,0 @@
/*
* Copyright (C) 2015 Kirk Scheper <kirkscheper@gmail.com>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
/**
* @file modules/datalink/bluegiga.h
* Bluegiga Bluetooth chip I/O
*/
#ifndef BLUEGIGA_DATA_LINK_H
#define BLUEGIGA_DATA_LINK_H
#include "pprzlink/pprzlink_device.h"
#include "pprzlink/pprz_transport.h"
#include "modules/datalink/datalink.h"
/* The different statuses the communication can be in */
enum BlueGigaStatus {
BLUEGIGA_UNINIT, /**< The com isn't initialized */
BLUEGIGA_IDLE, /**< The com is in idle */
BLUEGIGA_SENDING, /**< The com is sending */
BLUEGIGA_SENDING_BROADCAST /**< The com is switched from data link to rssi scanning */
};
#ifndef BLUEGIGA_BUFFER_SIZE
#define BLUEGIGA_BUFFER_SIZE 256 // buffer max value: 256
#elif BLUEGIGA_BUFFER_SIZE < 256
#warning "BLUEGIGA_BUFFER_SIZE may be smaller than possible message length, check modules/datalink/bluegiga.c:dev_check_free_space for more information"
#elif BLUEGIGA_BUFFER_SIZE > 256
#error "BLUEGIGA_BUFFER_SIZE not made for sizes larger than 256, check modules/datalink/bluegiga.c for more information"
#endif
#define BLUEGIGA_SPI_BUF_SIZE 20
struct bluegiga_periph {
/* Receive buffer */
uint8_t rx_buf[BLUEGIGA_BUFFER_SIZE];
uint8_t rx_insert_idx;
uint8_t rx_extract_idx;
/* Transmit buffer */
uint8_t tx_buf[BLUEGIGA_BUFFER_SIZE];
uint8_t tx_insert_idx;
uint8_t tx_extract_idx;
/* transmit and receive buffers */
uint8_t work_tx[BLUEGIGA_SPI_BUF_SIZE];
uint8_t work_rx[BLUEGIGA_SPI_BUF_SIZE];
/** Generic device interface */
struct link_device device;
/* some administrative variables */
uint32_t bytes_recvd_since_last;
uint8_t end_of_msg;
uint8_t connected;
};
// DEVICE passed to all DOWNLINK_SEND functions
extern struct bluegiga_periph bluegiga_p;
extern signed char bluegiga_rssi[]; // values initialized with 127
bool bluegiga_ch_available(struct bluegiga_periph *p);
void bluegiga_increment_buf(uint8_t *buf_idx, uint8_t len);
void bluegiga_init(struct bluegiga_periph *p);
void bluegiga_scan(struct bluegiga_periph *p);
void bluegiga_broadcast_msg(struct bluegiga_periph *p, char *msg, uint8_t msg_len);
#endif /* BLUEGIGA_DATA_LINK_H */
@@ -1,47 +0,0 @@
/*
* Copyright (C) 2016 Gautier Hattenberger <gautier.hattenberger@enac.fr>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
/** \file modules/datalink/bluegiga_dh.c
* \brief Datalink using PPRZ protocol with Bluegiga modules
*/
#include "modules/datalink/bluegiga_dl.h"
#include "modules/datalink/datalink.h"
#include "modules/datalink/bluegiga.h"
#ifndef BLUEGIGA_UPDATE_DL
#define BLUEGIGA_UPDATE_DL TRUE
#endif
struct pprz_transport pprz_bg_tp;
void bluegiga_dl_init(void)
{
pprz_transport_init(&pprz_bg_tp);
bluegiga_init(&bluegiga_p);
}
void bluegiga_dl_event(void)
{
pprz_check_and_parse(&DOWNLINK_DEVICE.device, &pprz_bg_tp, dl_buffer, &dl_msg_available);
DlCheckAndParse(&DOWNLINK_DEVICE.device, &pprz_bg_tp.trans_tx, dl_buffer, &dl_msg_available, BLUEGIGA_UPDATE_DL);
}
@@ -1,42 +0,0 @@
/*
* Copyright (C) 2016 Gautier Hattenberger <gautier.hattenberger@enac.fr>
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
/** \file modules/datalink/bluegiga_dh.h
* \brief Datalink using PPRZ protocol with Bluegiga modules
*/
#ifndef BLUEGIGA_DL_H
#define BLUEGIGA_DL_H
#include "pprzlink/pprz_transport.h"
#include "modules/datalink/bluegiga.h"
/** PPRZ transport structure */
extern struct pprz_transport pprz_bg_tp;
/** Init function */
extern void bluegiga_dl_init(void);
/** Datalink Event */
extern void bluegiga_dl_event(void);
#endif /* BLUEGIGA_DL_H */
-1
View File
@@ -35,7 +35,6 @@
#define XBEE 2
#define SUPERBITRF 3
#define W5100 4
#define BLUEGIGA 5
/** Flag provided to control calls to ::dl_parse_msg. NOT used in this module*/
extern bool dl_msg_available;
-4
View File
@@ -1,4 +0,0 @@
*.d
*.o
*.elf
bluetooth-proximity
-76
View File
@@ -1,76 +0,0 @@
TARGET = bluetooth-proximity
SRCS := $(wildcard *.c)
OBJS := $(SRCS:.c=.o)
DEPS := $(SRCS:.c=.d)
EMBED ?=
ifeq ($(EMBED),)
CC = gcc
MACHINE = $(shell $(CC) -dumpmachine)
# Windows
ifneq (,$(or $(findstring mingw, $(MACHINE)), $(findstring cygwin, $(MACHINE))))
PLATFORM = WIN
LIBS = -lm -lsetupapi
RM = del
# POSIX
else
PLATFORM = POSIX
LIBS = -lm
endif
all: $(TARGET)
%.o: %.c
$(CC) -O3 -Wall -c -fmessage-length=0 -DPLATFORM_$(PLATFORM) -MMD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<" -DPRINT
$(TARGET): $(OBJS)
@echo 'Building target: $@'
$(CC) -o"$(TARGET)" $(OBJS) $(LIBS) $(CFLAG)
@echo 'Finished building target: $@'
clean:
-$(RM) $(OBJS) $(DEPS) $(TARGET)
.PHONY: all clean
else
CROSS_COMPILE ?= arm-linux-gnueabi-
CC := $(CROSS_COMPILE)gcc
CFLAGS := -O3 -Wall -Wextra -Wno-unused-parameter -Wmissing-prototypes
LDFLAGS := -Wl,--no-undefined -Wl,--as-needed
all: $(TARGET)
%.o: %.c
$(CC) -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
$(TARGET): $(OBJS)
@echo 'Building target: $@'
$(CC) -o"$(TARGET).elf" $(OBJS) $(LDFLAGS)
@echo 'Finished building target: $@'
clean:
-$(RM) $(OBJS) $(DEPS) $(TARGET).elf
#include $(PAPARAZZI_SRC)/conf/Makefile.linux
DRONE ?= $(PAPARAZZI_HOME)/sw/tools/parrot/ardrone2.py
SUB_DIR = paparazzi
HOST ?= 192.168.1.1
# Program the device and start it.
upload_program: $(TARGET).elf
#$(Q)$(DRONE) --host=$(HOST) upload_file $(TARGET).elf $(SUB_DIR)
$(Q)$(DRONE) --host=$(HOST) insmod cdc-acm.ko
$(Q)$(DRONE) --host=$(HOST) upload_file_and_run $(TARGET).elf $(SUB_DIR)
$(Q)$(DRONE) --host=$(HOST) status
# --host=$(HOST)
endif
.PHONY: all clean upload_program debug
-37
View File
@@ -1,37 +0,0 @@
STDMA_dongle.md
### Description
This tool allows Bluegiga dongle to communicate using STDMA (Self-organized Time-Division Multiple Access).
Using this, drones with a Bluegiga USB Bluetooth dongle can communicate with eachother and exchange their RSSI (i.e., signal strenth, which is a measure of distance). This has been tested with up to 3 ARDrones.
It was used in: Coppola, M., McGuire, K.N., Scheper, K.Y.W. et al. Auton Robot (2018). https://doi.org/10.1007/s10514-018-9760-3
### Commands functions
make clean && make --> makes it for the computer
EMBED=1 --> this builds it for the drone, rather than for your computer
Once connected to the drone --> make upload_program EMBED=1 HOST=192..........
### Setting up the communication between laptops/drones
Turn on the drones and go to:
cd $PAPARAZZI_HOME/sw/tools/STDMA_dongle
The command
make clean && Make
will build `bluetooth_proximity`. Which is an application that can run on your computer. This is very useful for broadcasting from your computer if you want your computer to simulate the presence of a drone, for instance.
You can run it with
./bluetooth_proximity
If you want the program to actually run on the ARDrones, then you have to build their embedded version and upload it. Note that this must be done every time the drone stops being active (e.g. when you change the battery). It starts running as soon as it is uploaded.
To build and run for the drone:
make clean && make EMBED=1
To upload to the drones, select your **DRONE** type in the Makefile or add the option **DRONE=...** to the command (tested with ARDrone):
make upload_program EMBED=1 HOST=192.168.40.200
Note the last numbers may change depending on the IP address of your drones.
Make sure to check that you are connected to the drones when doing this step!
-41
View File
@@ -1,41 +0,0 @@
#ifndef APITYPES_H_
#define APITYPES_H_
#ifdef __GNUC__
#define PACKSTRUCT( decl ) decl __attribute__((__packed__))
#define ALIGNED __attribute__((aligned(0x4)))
#else //msvc
#define PACKSTRUCT( decl ) __pragma( pack(push, 1) ) decl __pragma( pack(pop) )
#define ALIGNED
#endif
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef signed short int16;
typedef unsigned long uint32;
typedef signed char int8;
typedef struct bd_addr_t {
uint8 addr[6];
} bd_addr;
typedef bd_addr hwaddr;
typedef struct {
uint8 len;
uint8 data[];
} uint8array;
typedef struct {
uint8 len;
int8 data[];
} string;
#endif
Binary file not shown.
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-338
View File
@@ -1,338 +0,0 @@
//
// Bluegigas Bluetooth Smart Demo Application
// Contact: support@bluegiga.com.
//
// This is free software distributed under the terms of the MIT license reproduced below.
//
// Copyright (c) 2012, Bluegiga Technologies
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
//
#include <stdio.h>
#include "uart.h"
#ifdef PLATFORM_WIN
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#include <windows.h>
#include <Setupapi.h>
HANDLE serial_handle;
void uart_list_devices()
{
char name[] = "Bluegiga Bluetooth Low Energy";
BYTE *pbuf = NULL;
DWORD reqSize = 0;
DWORD n = 0;
HDEVINFO hDevInfo;
//guid for ports
static const GUID guid = { 0x4d36e978, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };
char *str;
char tmp[MAX_PATH + 1];
int i;
SP_DEVINFO_DATA DeviceInfoData;
snprintf(tmp, MAX_PATH, "%s (COM%%d)", name);
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
hDevInfo = SetupDiGetClassDevs(&guid, //Retrieve all ports
0L,
NULL,
DIGCF_PRESENT);
if (hDevInfo == INVALID_HANDLE_VALUE) {
return;
}
while (1) {
if (!SetupDiEnumDeviceInfo(
hDevInfo,
n++,
&DeviceInfoData
)) {
SetupDiDestroyDeviceInfoList(hDevInfo);
return;
}
reqSize = 0;
SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, NULL, NULL, 0, &reqSize);
pbuf = (BYTE *)malloc(reqSize > 1 ? reqSize : 1);
if (!SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, NULL, pbuf, reqSize, NULL)) {
free(pbuf);
continue;
}
str = (char *)pbuf;
if (sscanf(str, tmp, &i) == 1) {
printf("%s\n", str);
//emit DeviceFound(str,QString("\\\\.\\COM%1").arg(i));
}
free(pbuf);
}
return;
}
int uart_find_serialport(char *name)
{
BYTE *pbuf = NULL;
DWORD reqSize = 0;
DWORD n = 0;
HDEVINFO hDevInfo;
//guid for ports
static const GUID guid = { 0x4d36e978, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };
char *str;
char tmp[MAX_PATH + 1];
int i;
SP_DEVINFO_DATA DeviceInfoData;
snprintf(tmp, MAX_PATH, "%s (COM%%d)", name);
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
hDevInfo = SetupDiGetClassDevs(&guid, //Retrieve all ports
0L,
NULL,
DIGCF_PRESENT);
if (hDevInfo == INVALID_HANDLE_VALUE) {
return -1;
}
while (1) {
if (!SetupDiEnumDeviceInfo(
hDevInfo,
n++,
&DeviceInfoData
)) {
SetupDiDestroyDeviceInfoList(hDevInfo);
return -1;
}
reqSize = 0;
SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, NULL, NULL, 0, &reqSize);
pbuf = malloc(reqSize > 1 ? reqSize : 1);
if (!SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, NULL, pbuf, reqSize, NULL)) {
free(pbuf);
continue;
}
str = (char *)pbuf;
if (sscanf(str, tmp, &i) == 1) {
free(pbuf);
SetupDiDestroyDeviceInfoList(hDevInfo);
return i;
}
free(pbuf);
}
return -1;
}
int uart_open(char *port)
{
char str[20];
snprintf(str, sizeof(str) - 1, "\\\\.\\%s", port);
serial_handle = CreateFileA(str,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,//FILE_FLAG_OVERLAPPED,
NULL);
if (serial_handle == INVALID_HANDLE_VALUE) {
return -1;
}
return 0;
}
void uart_close()
{
CloseHandle(serial_handle);
}
int uart_tx(int len, unsigned char *data)
{
DWORD r, written;
while (len) {
r = WriteFile(serial_handle,
data,
len,
&written,
NULL
);
if (!r) {
return -1;
}
len -= written;
data += len;
}
return 0;
}
int uart_rx(int len, unsigned char *data, int timeout_ms)
{
int l = len;
DWORD r, rread;
COMMTIMEOUTS timeouts;
timeouts.ReadIntervalTimeout = MAXDWORD;
timeouts.ReadTotalTimeoutMultiplier = 0;
timeouts.ReadTotalTimeoutConstant = timeout_ms;
timeouts.WriteTotalTimeoutMultiplier = 0;
timeouts.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(
serial_handle,
&timeouts
);
while (len) {
r = ReadFile(serial_handle,
data,
len,
&rread,
NULL
);
if (!r) {
l = GetLastError();
if (l == ERROR_SUCCESS) {
return 0;
}
return -1;
} else {
if (rread == 0) {
return 0;
}
}
len -= rread;
data += len;
}
return l;
}
#else
#include <stdio.h>
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
int serial_handle;
void uart_list_devices() {}
int uart_open(char *port)
{
struct termios options;
int i;
serial_handle = open(port, (O_RDWR | O_NOCTTY /*| O_NONBLOCK | O_NDELAY*/));
if (serial_handle < 0) {
return errno;
}
/*
* Get the current options for the port...
*/
tcgetattr(serial_handle, &options);
/*
* Set the baud rates to 115200...
*/
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
//cfsetispeed(&options, B921600);
//cfsetospeed(&options, B921600);
/*
* Enable the receiver and set parameters ...
*/
options.c_cflag &= ~(PARENB | CSTOPB | CSIZE | CRTSCTS | HUPCL);
options.c_cflag |= (CS8 | CLOCAL | CREAD);
options.c_lflag &= ~(ICANON | ISIG | ECHO | ECHOE | ECHOK | ECHONL | ECHOCTL | ECHOPRT | ECHOKE | IEXTEN);
options.c_iflag &= ~(INPCK | IXON | IXOFF | IXANY | ICRNL);
options.c_oflag &= ~(OPOST | ONLCR);
//printf( "size of c_cc = %d\n", sizeof( options.c_cc ) );
for (i = 0; i < sizeof(options.c_cc); i++) {
options.c_cc[i] = _POSIX_VDISABLE;
}
options.c_cc[VTIME] = 0;
options.c_cc[VMIN] = 1;
/*
* Set the new options for the port...
*/
tcsetattr(serial_handle, TCSAFLUSH, &options);
return 0;
}
void uart_close()
{
close(serial_handle);
}
int uart_tx(int len, unsigned char *data)
{
ssize_t written;
while (len) {
written = write(serial_handle, data, len);
if (!written) {
return -1;
}
len -= written;
data += len;
}
return 0;
}
int uart_rx(int len, unsigned char *data, int timeout_ms)
{
int l = len;
ssize_t rread;
struct termios options;
tcgetattr(serial_handle, &options);
options.c_cc[VTIME] = timeout_ms / 100;
options.c_cc[VMIN] = 0;
tcsetattr(serial_handle, TCSANOW, &options);
while (len) {
rread = read(serial_handle, data, len);
if (!rread) {
return 0;
} else if (rread < 0) {
return -1;
}
len -= rread;
data += len;
}
return l;
}
#endif
-10
View File
@@ -1,10 +0,0 @@
#ifndef UART_H
#define UART_H
void uart_list_devices();
int uart_find_serialport(char *name);
int uart_open(char *port);
void uart_close();
int uart_tx(int len, unsigned char *data);
int uart_rx(int len, unsigned char *data, int timeout_ms);
#endif // UART_H
-2
View File
@@ -1,2 +0,0 @@
*.d
bluegiga_usb_driver
-35
View File
@@ -1,35 +0,0 @@
Q=@
CC = gcc
TARGET = bluegiga_usb_driver
MACHINE = $(shell $(CC) -dumpmachine)
# Windows
ifneq (,$(or $(findstring mingw, $(MACHINE)), $(findstring cygwin, $(MACHINE))))
PLATFORM = WIN
LIBS = -lm -lsetupapi
RM = del
# POSIX
else
PLATFORM = POSIX
LIBS = -lm -lpthread
endif
SRCS := $(wildcard *.c)
OBJS := $(SRCS:.c=.o)
DEPS := $(SRCS:.c=.d)
all: $(TARGET)
%.o: %.c
$(Q)$(CC) -O3 -Wall -c -fmessage-length=0 -DPLATFORM_$(PLATFORM) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o"$@" "$<"
$(TARGET): $(OBJS)
@echo 'Building target: $@'
$(Q)$(CC) -o $(TARGET) $(OBJS) $(LIBS)
@echo 'Finished building target: $@'
clean:
-$(RM) $(OBJS) $(DEPS) $(TARGET)
.PHONY: all clean
-74
View File
@@ -1,74 +0,0 @@
// Bluegiga ANSI C BGLib API types header file
// BLE SDK v1.2.1-91
//
// Contact: support@bluegiga.com
//
// This is free software distributed under the terms of the MIT license reproduced below.
//
// Copyright (c) 2013 Bluegiga Technologies
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef APITYPES_H_
#define APITYPES_H_
/* structure packing compability */
#ifndef PACKSTRUCT
#ifdef PACKED
#define PACKSTRUCT(a) a PACKED
#else
/* default packed configuration */
#ifdef __GNUC__
#ifdef _WIN32
#define PACKSTRUCT( decl ) decl __attribute__((__packed__,gcc_struct))
#else
#define PACKSTRUCT( decl ) decl __attribute__((__packed__))
#endif
#define ALIGNED __attribute__((aligned(0x4)))
#else // MSVC
#define PACKSTRUCT( decl ) __pragma( pack(push, 1) ) decl __pragma( pack(pop) )
#define ALIGNED
#endif
#endif
#endif
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef signed short int16;
typedef unsigned long uint32;
typedef signed char int8;
typedef struct bd_addr_t {
uint8 addr[6];
} bd_addr;
typedef bd_addr hwaddr;
typedef struct {
uint8 len;
uint8 data[];
} uint8array;
typedef struct {
uint8 len;
int8 data[];
} string;
#endif
Binary file not shown.
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-333
View File
@@ -1,333 +0,0 @@
// Bluegiga ANSI C BGLib UART interface source file
// BLE SDK v1.3.2-122
//
// http://www.bluegiga.com
//
// This is free software distributed under the terms of the MIT license reproduced below.
//
// Copyright (c) 2015 Bluegiga Technologies
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include <stdio.h>
#include "uart.h"
#ifdef PLATFORM_WIN
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
// Windows implementation of UART access
// see https://msdn.microsoft.com/en-us/library/aa363194(v=vs.85).aspx for reference
#include <windows.h>
#include <setupapi.h>
HANDLE serial_handle;
DCB dcb;
// Windows-only serial port device listing
void uart_list_devices()
{
char name[] = "Bluegiga Bluetooth Low Energy";
BYTE *pbuf = NULL;
DWORD reqSize = 0;
DWORD n = 0;
HDEVINFO hDevInfo;
//guid for ports
static const GUID guid = { 0x4d36e978, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };
char *str;
char tmp[MAX_PATH + 1];
int i;
SP_DEVINFO_DATA DeviceInfoData;
snprintf(tmp, MAX_PATH, "%s (COM%%d)", name);
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
hDevInfo = SetupDiGetClassDevs(&guid, //Retrieve all ports
0L,
NULL, DIGCF_PRESENT);
if (hDevInfo == INVALID_HANDLE_VALUE) {
return;
}
while (1) {
if (!SetupDiEnumDeviceInfo(hDevInfo, n++, &DeviceInfoData)) {
SetupDiDestroyDeviceInfoList(hDevInfo);
return;
}
reqSize = 0;
SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, NULL, NULL, 0, &reqSize);
pbuf = (BYTE *)malloc(reqSize > 1 ? reqSize : 1);
if (!SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, NULL, pbuf, reqSize, NULL)) {
free(pbuf);
continue;
}
str = (char *)pbuf;
if (sscanf(str, tmp, &i) == 1) {
printf("%s\n", str);
//emit DeviceFound(str,QString("\\\\.\\COM%1").arg(i));
}
free(pbuf);
}
return;
}
int uart_find_serialport(char *name)
{
BYTE *pbuf = NULL;
DWORD reqSize = 0;
DWORD n = 0;
HDEVINFO hDevInfo;
// GUID for ports
static const GUID guid = { 0x4d36e978, 0xe325, 0x11ce, { 0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18 } };
char *str;
char tmp[MAX_PATH + 1];
int i;
SP_DEVINFO_DATA DeviceInfoData;
snprintf(tmp, MAX_PATH, "%s (COM%%d)", name);
DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
hDevInfo = SetupDiGetClassDevs(&guid, 0L, NULL, DIGCF_PRESENT);
if (hDevInfo == INVALID_HANDLE_VALUE) {
return -1;
}
while (1) {
if (!SetupDiEnumDeviceInfo(hDevInfo, n++, &DeviceInfoData)) {
SetupDiDestroyDeviceInfoList(hDevInfo);
return -1;
}
reqSize = 0;
SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, NULL, NULL, 0, &reqSize);
pbuf = malloc(reqSize > 1 ? reqSize : 1);
if (!SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DeviceInfoData, SPDRP_FRIENDLYNAME, NULL, pbuf, reqSize, NULL)) {
free(pbuf);
continue;
}
str = (char *)pbuf;
if (sscanf(str, tmp, &i) == 1) {
free(pbuf);
SetupDiDestroyDeviceInfoList(hDevInfo);
return i;
}
free(pbuf);
}
return -1;
}
int uart_open(char *port)
{
char str[20];
snprintf(str, sizeof(str) - 1, "\\\\.\\%s", port);
serial_handle = CreateFileA(str,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0, //FILE_FLAG_OVERLAPPED,
NULL);
if (serial_handle == INVALID_HANDLE_VALUE) {
return -1;
}
memset(&dcb, 0, sizeof(DCB));
dcb.DCBlength = sizeof(DCB);
// 115200 bps, 8 data bits, no parity, and 1 stop bit
dcb.BaudRate = CBR_115200; // baud rate
dcb.ByteSize = 8; // data size, xmit and rcv
dcb.Parity = NOPARITY; // parity bit
dcb.StopBits = ONESTOPBIT; // stop bit
dcb.fOutxCtsFlow = 1; // CTS flow control monitoring
dcb.fRtsControl = 1; // RTS flow control output
if (!SetCommState(serial_handle, &dcb)) {
return -2;
}
return 0;
}
void uart_close()
{
CloseHandle(serial_handle);
}
int uart_tx(int len, unsigned char *data)
{
DWORD r, written;
while (len) {
r = WriteFile(serial_handle, data, len, &written, NULL);
if (!r) {
return -1;
}
len -= written;
data += written;
}
return 0;
}
int uart_rx(int len, unsigned char *data, int timeout_ms)
{
int l = len;
DWORD r, rread;
COMMTIMEOUTS timeouts;
timeouts.ReadIntervalTimeout = MAXDWORD;
timeouts.ReadTotalTimeoutMultiplier = 0;
timeouts.ReadTotalTimeoutConstant = timeout_ms;
timeouts.WriteTotalTimeoutMultiplier = 0;
timeouts.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(serial_handle, &timeouts);
while (len) {
r = ReadFile(serial_handle, data, len, &rread, NULL);
if (!r) {
l = GetLastError();
if (l == ERROR_SUCCESS) {
return 0;
}
return -1;
} else {
if (rread == 0) {
return 0;
}
}
len -= rread;
data += rread;
}
return l;
}
#else // POSIX or Mac OS X
#include <stdio.h>
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
int serial_handle;
void uart_list_devices() {}
int uart_open(char *port)
{
struct termios options;
int i;
//#ifdef PLATFORM_OSX
// serial_handle = open(port, (O_RDWR | O_NOCTTY | O_NDELAY));
//#else
serial_handle = open(port, (O_RDWR | O_NOCTTY /*| O_NDELAY*/));
//#endif
if (serial_handle < 0) {
return errno;
}
/*
* Get the current options for the port...
*/
tcgetattr(serial_handle, &options);
/*
* Set the baud rates to 115200...
*/
cfsetispeed(&options, B115200);
cfsetospeed(&options, B115200);
/*
* Enable the receiver and set parameters ...
*/
options.c_cflag &= ~(PARENB | CSTOPB | CSIZE | CRTSCTS | HUPCL);
options.c_cflag |= (CS8 | CLOCAL | CREAD);
options.c_lflag &= ~(ICANON | ISIG | ECHO | ECHOE | ECHOK | ECHONL | ECHOCTL | ECHOPRT | ECHOKE | IEXTEN);
options.c_iflag &= ~(INPCK | IXON | IXOFF | IXANY | ICRNL);
options.c_oflag &= ~(OPOST | ONLCR);
//printf( "size of c_cc = %d\n", sizeof( options.c_cc ) );
for (i = 0; i < sizeof(options.c_cc); i++) {
options.c_cc[i] = _POSIX_VDISABLE;
}
options.c_cc[VTIME] = 0;
options.c_cc[VMIN] = 1;
/*
* Set the new options for the port...
*/
tcsetattr(serial_handle, TCSAFLUSH, &options);
return 0;
}
void uart_close()
{
close(serial_handle);
}
int uart_tx(int len, unsigned char *data)
{
ssize_t written;
while (len) {
written = write(serial_handle, data, len);
if (written < 1) {
return -1;
}
len -= written;
data += written;
}
return 0;
}
int uart_rx(int len, unsigned char *data, int timeout_ms)
{
int l = len;
ssize_t rread;
struct termios options;
tcgetattr(serial_handle, &options);
options.c_cc[VTIME] = timeout_ms / 100;
options.c_cc[VMIN] = 0;
tcsetattr(serial_handle, TCSANOW, &options);
while (len) {
rread = read(serial_handle, data, len);
if (!rread) {
return 0;
} else if (rread < 0) {
return -1;
}
len -= rread;
data += len;
}
return l;
}
#endif
-38
View File
@@ -1,38 +0,0 @@
// Bluegiga ANSI C BGLib UART interface header file
// BLE SDK v1.3.2-122
//
// http://www.bluegiga.com
//
// This is free software distributed under the terms of the MIT license reproduced below.
//
// Copyright (c) 2015 Bluegiga Technologies
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef UART_H
#define UART_H
void uart_list_devices();
int uart_find_serialport(char *name);
int uart_open(char *port);
void uart_close();
int uart_tx(int len, unsigned char *data);
int uart_rx(int len, unsigned char *data, int timeout_ms);
#endif // UART_H