-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[modules] Generic UART Sensor (#3060)
- Loading branch information
Showing
3 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE module SYSTEM "module.dtd"> | ||
|
||
<module name="generic_uart_sensor" dir="sensors"> | ||
<doc> | ||
<description>Generic UART sesnsor where the data is forwarded tot the GCS</description> | ||
<configure name="GENERIC_UART_PORT" value="UART4" description="select which uart it is connected to"/> | ||
<configure name="GENERIC_UART_BAUD" value="B9600" description="set the baudrate of the uart"/> | ||
<define name="GENERIC_UART_ENDCHAR" value=">" description="ending character for receiving"/> | ||
</doc> | ||
<header> | ||
<file name="generic_uart.h"/> | ||
</header> | ||
<event fun="generic_uart_event()"/> | ||
<makefile> | ||
<!-- Configure default UART port and baudrate --> | ||
<configure name="GENERIC_UART_PORT" default="UART4" case="upper|lower"/> | ||
<configure name="GENERIC_UART_BAUD" default="B9600"/> | ||
|
||
<!-- Enable UART and set baudrate --> | ||
<define name="USE_$(GENERIC_UART_PORT_UPPER)"/> | ||
<define name="USE_$(GENERIC_UART_PORT_UPPER)_TX" value="FALSE"/> | ||
<define name="$(GENERIC_UART_PORT_UPPER)_BAUD" value="$(GENERIC_UART_BAUD)"/> | ||
<define name="GENERIC_UART_PORT" value="$(GENERIC_UART_PORT_LOWER)"/> | ||
|
||
<!-- Sources --> | ||
<file name="generic_uart.c"/> | ||
</makefile> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (C) 2020 Freek van Tienen <freek.v.tienen@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/sensors/generic_uart.c" | ||
* @author F. van Tienen | ||
* Generic UART sensor, forwarding towards the GCS through telemetry | ||
*/ | ||
|
||
#include "modules/sensors/generic_uart.h" | ||
#include "modules/datalink/telemetry.h" | ||
#include "mcu_periph/uart.h" | ||
|
||
/* Default end character */ | ||
#ifndef GENERIC_UART_ENDCHAR | ||
#define GENERIC_UART_ENDCHAR '>' | ||
#endif | ||
|
||
/* Main variables */ | ||
static struct link_device *gen_uart_dev = (&((GENERIC_UART_PORT).device)); ///< UART device for communication | ||
|
||
/* Event function to read UART message and forward to downlink */ | ||
void generic_uart_event(void) { | ||
// Receive buffer | ||
static uint8_t gen_msg_buf[128]; | ||
static uint8_t gen_msg_cnt = 0; | ||
|
||
// Transmit buffer | ||
static uint8_t msg_buf_snd[128]; | ||
static uint8_t msg_cnt_snd = 0; | ||
|
||
// Look for data on serial port and save it in the buffer | ||
while (gen_uart_dev->char_available(gen_uart_dev->periph)) { | ||
gen_msg_buf[gen_msg_cnt++] = gen_uart_dev->get_byte(gen_uart_dev->periph); | ||
|
||
if(gen_msg_buf[gen_msg_cnt-1] == GENERIC_UART_ENDCHAR) | ||
break; | ||
} | ||
|
||
// Forward the message to the GCS | ||
if(gen_msg_buf[gen_msg_cnt-1] == GENERIC_UART_ENDCHAR || gen_msg_cnt > 50) { | ||
msg_cnt_snd = gen_msg_cnt; | ||
for(uint8_t i = 0; i < msg_cnt_snd; ++i) | ||
msg_buf_snd[i] = gen_msg_buf[i]; | ||
|
||
DOWNLINK_SEND_PAYLOAD(DefaultChannel, DefaultDevice, msg_cnt_snd, msg_buf_snd); | ||
|
||
gen_msg_buf[0] = 0; | ||
gen_msg_cnt = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (C) 2020 Freek van Tienen <freek.v.tienen@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/sensors/generic_uart.c" | ||
* @author F. van Tienen | ||
* Generic UART sensor, forwarding towards the GCS through telemetry | ||
*/ | ||
|
||
#ifndef GENERIC_UART_H | ||
#define GENERIC_UART_H | ||
|
||
#include "std.h" | ||
|
||
extern void generic_uart_event(void); | ||
|
||
#endif |