diff --git a/conf/messages.xml b/conf/messages.xml
index f396474e92..1541b20d7f 100644
--- a/conf/messages.xml
+++ b/conf/messages.xml
@@ -239,6 +239,7 @@
+
@@ -853,7 +854,10 @@
-
+
+
+
+
diff --git a/conf/telemetry/default_rotorcraft_slow.xml b/conf/telemetry/default_rotorcraft_slow.xml
index b1431caa08..317fbc6f57 100644
--- a/conf/telemetry/default_rotorcraft_slow.xml
+++ b/conf/telemetry/default_rotorcraft_slow.xml
@@ -20,6 +20,7 @@
+
diff --git a/sw/airborne/arch/stm32/mcu_periph/spi_arch.c b/sw/airborne/arch/stm32/mcu_periph/spi_arch.c
index 416ab37333..d94ff90c8e 100644
--- a/sw/airborne/arch/stm32/mcu_periph/spi_arch.c
+++ b/sw/airborne/arch/stm32/mcu_periph/spi_arch.c
@@ -1294,7 +1294,10 @@ void dma1_channel2_isr(void) {
// SPI arch slave init
#if USE_SPI2_SLAVE
+
+#ifdef SPI2_SLAVE_NO_NSS
PRINT_CONFIG_MSG("STM32-SPI2 slave: Configured not to use the NSS pin")
+#endif
#ifndef STM32F1
#error "SPI2 slave on STM32 only implemented for STM32F1"
@@ -1331,7 +1334,7 @@ void spi2_slave_arch_init(void) {
spi2.trans_extract_idx = 0;
spi2.status = SPIIdle;
- // Enable SPI1 Periph and gpio clocks
+ // Enable SPI2 Periph and gpio clocks
rcc_periph_clock_enable(RCC_SPI2);
// Configure GPIOs: SCK, MISO and MOSI
diff --git a/sw/airborne/subsystems/datalink/bluegiga.c b/sw/airborne/subsystems/datalink/bluegiga.c
index 857a90ee37..8ece80fb03 100644
--- a/sw/airborne/subsystems/datalink/bluegiga.c
+++ b/sw/airborne/subsystems/datalink/bluegiga.c
@@ -99,6 +99,24 @@ void bluegiga_increment_buf(uint8_t *buf_idx, uint8_t len)
*buf_idx = (*buf_idx + len) % BLUEGIGA_BUFFER_SIZE;
}
+#if PERIODIC_TELEMETRY
+#include "subsystems/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);
+ pprz_msg_send_BLUEGIGA(trans, dev, AC_ID, &rate);
+
+ bluegiga_p.bytes_recvd_since_last = 0;
+ last_ts = now_ts;
+ }
+}
+#endif
+
void bluegiga_init(struct bluegiga_periph *p)
{
#ifdef MODEM_LED
@@ -143,6 +161,8 @@ void bluegiga_init(struct bluegiga_periph *p)
bluegiga_rssi[i] = 127;
}
+ p->bytes_recvd_since_last = 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);
@@ -151,6 +171,10 @@ void bluegiga_init(struct bluegiga_periph *p)
spi_slave_register(&(BLUEGIGA_SPI_DEV), &bluegiga_spi);
coms_status = BLUEGIGA_UNINIT;
+
+#if PERIODIC_TELEMETRY
+ register_periodic_telemetry(DefaultPeriodic, "BLUEGIGA", send_bluegiga);
+#endif
}
/* Add one byte to the end of tx circular buffer */
@@ -246,6 +270,7 @@ void bluegiga_receive(struct spi_transaction *trans)
bluegiga_p.rx_buf[(bluegiga_p.rx_insert_idx + i) % BLUEGIGA_BUFFER_SIZE] = trans->input_buf[i + 4];
}
bluegiga_increment_buf(&bluegiga_p.rx_insert_idx, packet_len);
+ bluegiga_p.bytes_recvd_since_last += packet_len;
coms_status = BLUEGIGA_IDLE;
} else {
coms_status = BLUEGIGA_IDLE;
diff --git a/sw/airborne/subsystems/datalink/bluegiga.h b/sw/airborne/subsystems/datalink/bluegiga.h
index 4be0fd7d4b..021356741d 100644
--- a/sw/airborne/subsystems/datalink/bluegiga.h
+++ b/sw/airborne/subsystems/datalink/bluegiga.h
@@ -59,6 +59,10 @@ struct bluegiga_periph {
uint8_t work_rx[20];
/** Generic device interface */
struct link_device device;
+
+ /* some administrative variable */
+ uint32_t bytes_recvd_since_last;
+
};
// DEVICE passed to all DOWNLINK_SEND functions
diff --git a/sw/airborne/subsystems/datalink/downlink.c b/sw/airborne/subsystems/datalink/downlink.c
index 61a6ecd97e..e171c7cd91 100644
--- a/sw/airborne/subsystems/datalink/downlink.c
+++ b/sw/airborne/subsystems/datalink/downlink.c
@@ -35,28 +35,27 @@ struct downlink downlink;
#include "subsystems/datalink/datalink.h"
#include "mcu_periph/sys_time.h"
+static uint32_t last_down_nb_bytes = 0; // previous number of bytes sent
+static uint32_t last_up_nb_msgs = 0; // previous number of received messages
+static uint32_t last_ts = 0; // timestamp in usec when last message was send
+
static void send_downlink(struct transport_tx *trans, struct link_device *dev)
{
- static uint32_t last_nb_bytes = 0;
- // timestamp in usec when last message was send
- static uint32_t last_ts = 0.;
// current timestamp
uint32_t now_ts = get_sys_time_msec();
// compute downlink byte rate
if (now_ts > last_ts) {
- uint16_t rate = (1000 * ((uint32_t)downlink.nb_bytes - last_nb_bytes)) / (now_ts - last_ts);
- last_ts = now_ts;
- last_nb_bytes = downlink.nb_bytes;
+ uint16_t down_rate = (1000 * ((uint32_t)downlink.nb_bytes - last_down_nb_bytes)) / (now_ts - last_ts);
+ uint16_t up_rate = (1000 * ((uint32_t)datalink_nb_msgs - last_up_nb_msgs)) / (now_ts - last_ts);
-#if defined DATALINK
- uint16_t uplink_nb_msgs = datalink_nb_msgs;
-#else
- uint16_t uplink_nb_msgs = 0;
-#endif
+ last_ts = now_ts;
+ last_down_nb_bytes = downlink.nb_bytes;
+ last_up_nb_msgs = datalink_nb_msgs;
pprz_msg_send_DATALINK_REPORT(trans, dev, AC_ID,
- &datalink_time, &uplink_nb_msgs,
- &downlink.nb_msgs, &rate, &downlink.nb_ovrn);
+ &datalink_time, &datalink_nb_msgs,
+ &downlink.nb_msgs, &down_rate, &up_rate,
+ &downlink.nb_ovrn);
}
}
#endif
diff --git a/sw/tools/bluegiga_usb_dongle/main.c b/sw/tools/bluegiga_usb_dongle/main.c
index bb78398821..a3d47f4d78 100644
--- a/sw/tools/bluegiga_usb_dongle/main.c
+++ b/sw/tools/bluegiga_usb_dongle/main.c
@@ -22,9 +22,10 @@
#include
#include
+#define BUF_SIZE 2048
int sock[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int addr_len, bytes_read, sin_size, bytes_recv;
-unsigned char recv_data[1024], data_buf[8][1024], send_buf[8][1024];
+unsigned char recv_data[BUF_SIZE], data_buf[8][BUF_SIZE], send_buf[8][BUF_SIZE];
struct sockaddr_in send_addr[8], rec_addr[8];
struct hostent *host;
unsigned int send_port , recv_port;
@@ -38,9 +39,9 @@ int last0 = 0, last1 = 0;
int ac_id[8] = { -1, -1, -1, -1, -1, -1, -1, -1};
unsigned int insert_idx[8] = {0, 0, 0, 0, 0, 0, 0, 0},
- extract_idx[8] = {0, 0, 0, 0, 0, 0, 0, 0},
- send_insert_idx[8] = {0, 0, 0, 0, 0, 0, 0, 0},
- send_extract_idx[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+ extract_idx[8] = {0, 0, 0, 0, 0, 0, 0, 0},
+ send_insert_idx[8] = {0, 0, 0, 0, 0, 0, 0, 0},
+ send_extract_idx[8] = {0, 0, 0, 0, 0, 0, 0, 0};
// #define DEBUG
@@ -56,9 +57,9 @@ int connected[] = {0, 0, 0, 0, 0, 0, 0, 0};
int connect_all = 0;
uint8 MAC_ADDR[] = {0x00, 0x00, 0x2d, 0x80, 0x07, 0x00};
-// {0x00, 0x00, 0x1e, 0x80, 0x07, 0x00}; // begining of all dongle adresses
+// {0x00, 0x00, 0x1e, 0x80, 0x07, 0x00}; // beginning of all dongle adresses
-// {0x00,0x00,0x2d,0x80,0x07,0x00}; // begining of all modules adresses
+// {0x00,0x00,0x2d,0x80,0x07,0x00}; // beginning of all modules adresses
enum actions {
action_none,
@@ -135,7 +136,7 @@ void *send_msg()
uint16_t diff = 0;
while (state != state_finish) {
if (action == action_broadcast) {
- diff = (insert_idx[0] - extract_idx[0] + 1024) % 1024;
+ diff = (insert_idx[0] - extract_idx[0] + BUF_SIZE) % BUF_SIZE;
if (diff) {
ble_cmd_gap_end_procedure();
bt_msg_len = diff < 31 ? diff : 31;
@@ -143,7 +144,7 @@ void *send_msg()
ble_cmd_gap_set_adv_data(0, bt_msg_len, &data_buf[0][extract_idx[0]]);
ble_cmd_gap_set_mode(gap_user_data, gap_non_connectable); //gap_set_mode($84, gap_scannable_non_connectable)
- extract_idx[device] = (extract_idx[device] + bt_msg_len) % 1024;
+ extract_idx[device] = (extract_idx[device] + bt_msg_len) % BUF_SIZE;
usleep(1000); // advertisement interval set at 320ms so pause for shorter before turning off
ble_cmd_gap_set_mode(0, 0); // stop advertising
@@ -154,20 +155,20 @@ void *send_msg()
} else {
device = 0;
while (ac_id[device] != -1 && device < 8) {
- diff = (insert_idx[device] - extract_idx[device] + 1024) % 1024;
+ diff = (insert_idx[device] - extract_idx[device] + BUF_SIZE) % BUF_SIZE;
if (diff) {
- bt_msg_len = diff < 27 ? diff : 27;
+ bt_msg_len = diff < 18 ? diff : 18;
//if (bt_msg_len > 18)
// fprintf(stderr,"Long msg: %d, buff size: %d\n", bt_msg_len, diff);
//ble_cmd_attclient_attribute_write(device, drone_handle_measurement, bt_msg_len[device], &data_buf[device][extract_idx[device]]);
ble_cmd_attclient_write_command(device, drone_handle_measurement, bt_msg_len, &data_buf[device][extract_idx[device]]);
- extract_idx[device] = (extract_idx[device] + bt_msg_len) % 1024;
+ extract_idx[device] = (extract_idx[device] + bt_msg_len) % BUF_SIZE;
}
device++;
- usleep(10000); // ~100Hz, max spi speed on lisa
- }
- }
+ } // next device
+ usleep(5000); // ~200Hz, max spi speed on lisa is 400Hz
+ } // repeat
}
pthread_exit(NULL);
}
@@ -294,12 +295,12 @@ void* send_paparazzi_comms()
while (state != state_finish) {
device = 0;
while (ac_id[device] != -1 && device < 8) {
- diff = (send_insert_idx[device] - send_extract_idx[device] + 1024) % 1024;
+ diff = (send_insert_idx[device] - send_extract_idx[device] + BUF_SIZE) % BUF_SIZE;
if (sock[device] && diff) {
// printf("diff % d\n", diff);
sendto(sock[device], &send_buf[device][send_extract_idx[device]], diff, MSG_WAITALL,
(struct sockaddr *)&send_addr[device], sizeof(struct sockaddr));
- send_extract_idx[device] = (send_extract_idx[device] + diff) % 1024;
+ send_extract_idx[device] = (send_extract_idx[device] + diff) % BUF_SIZE;
}
device++;
}
@@ -381,7 +382,7 @@ void ble_evt_gap_scan_response(const struct ble_msg_gap_scan_response_evt_t *msg
free(name);
}
- // automatically connect if reponding device has appropriate mac address hearder
+ // automatically connect if responding device has appropriate mac address header
if (connect_all && cmp_addr(msg->sender.addr, MAC_ADDR) >= 4) {
fprintf(stderr,"Trying to connect to "); print_bdaddr(msg->sender); fprintf(stderr,"\n");
//change_state(state_connecting);
@@ -506,7 +507,7 @@ void ble_evt_attclient_procedure_completed(const struct ble_msg_attclient_proced
// preivous message parsed on device, device now ready for next message
//else if (state == state_listening_measurements) {
- // extract_idx[msg->connection] = (extract_idx[msg->connection] + bt_msg_len[msg->connection]) % 1024;
+ // extract_idx[msg->connection] = (extract_idx[msg->connection] + bt_msg_len[msg->connection]) % BUF_SIZE;
// send_msg(msg->connection, 1);
//}
}
@@ -537,7 +538,7 @@ void ble_evt_attclient_attribute_value(const struct ble_msg_attclient_attribute_
int i = 0;
while(ac_id[i]!=-1 && i < 8){
fprintf(stderr,"Connection %d\nspeed: %dbps message frequency = %dHz\n",i,count[i]*20*8,count[i]);
- fprintf(stderr,"send speed: %dbps buffer size: %d\n",send_count[i],(insert_idx[i] - extract_idx[i])%1024);
+ fprintf(stderr,"send speed: %dbps buffer size: %d\n",send_count[i],(insert_idx[i] - extract_idx[i])%BUF_SIZE);
fprintf(stderr,"extract idx: %d, insert idx: %d\n",extract_idx[i], insert_idx[i]);
send_count[i] = 0;
@@ -553,7 +554,7 @@ void ble_evt_attclient_attribute_value(const struct ble_msg_attclient_attribute_
}
//memcpy(&send_buf[msg->connection][send_insert_idx[msg->connection]], msg->value.data, msg->value.len);
- //send_insert_idx[msg->connection] = (send_insert_idx[msg->connection] + msg->value.len)%1024;
+ //send_insert_idx[msg->connection] = (send_insert_idx[msg->connection] + msg->value.len)%BUF_SIZE;
if (sock[msg->connection])
sendto(sock[msg->connection], msg->value.data, msg->value.len, MSG_DONTWAIT,
(struct sockaddr *)&send_addr[msg->connection], sizeof(struct sockaddr));
@@ -617,29 +618,29 @@ void *recv_paparazzi_comms()
if (state == state_listening_measurements) {
if (action == action_broadcast) {
if (sock[0]) {
- bytes_recv = recvfrom(sock[0], recv_data, 1024, MSG_DONTWAIT, (struct sockaddr *)&rec_addr[0], (socklen_t *)&sin_size);
+ bytes_recv = recvfrom(sock[0], recv_data, BUF_SIZE, MSG_DONTWAIT, (struct sockaddr *)&rec_addr[0], (socklen_t *)&sin_size);
if (bytes_recv > 0) {
send_count[0] += bytes_recv;
// for (i = 0; i 0) {
+ if (bytes_recv > 0) { // TODO: can overtake extract!
send_count[device] += bytes_recv;
// for (i = 0; i