AP_RCProtocol: disable flow-control and buffered-writes for SRXL2 uart

switched spm_srxl.c to C++ compilation
Correctly set budget for half-duplex writes
Tidy PACKED and other externalities
disable SRXL2 on IOMCU and softserial - SRXL2 is a serial half-duplex protocol-only
fixed buffer overrun in SRXL2 parser
fix bugs in decoder sketch and allow output to SITL
This commit is contained in:
Andy Piper
2020-05-05 09:23:15 +10:00
committed by Andrew Tridgell
parent 44e5171f2b
commit 167e1d12d7
7 changed files with 135 additions and 75 deletions
@@ -13,7 +13,16 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
decode RC input using SITL on command line
* decode RC input using SITL on command line
*
* To use this as an RC protocol decoder for SITL with a real transmitter:
*
* 1. Compile using Linux - SITL has timing that is too variable
* 2. Connect an RX device to an FTDI adapter
* 3. Set the FTDI serial port to 115k baud, 8N1
* 4. Set the FTDI serial BM options to 1ms latency (very important)
* 5. Set the tty using: stty -F <device> raw 115200
* 6. Run this sketch providing the serial device name as an argument. RC values will be automatically written to the SITL RC port
*/
#include <AP_HAL/AP_HAL.h>
@@ -25,8 +34,10 @@ void loop();
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX || CONFIG_HAL_BOARD == HAL_BOARD_SITL
#include <AP_HAL/utility/Socket.h>
#include <AP_RCProtocol/AP_RCProtocol.h>
#include <RC_Channel/RC_Channel.h>
#include <AP_Math/AP_Math.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -62,12 +73,15 @@ private:
#include <RC_Channel/RC_Channels_VarInfo.h>
RC_Channels_RC _rc;
SocketAPM rc_socket{true};
// change this to the device being tested.
const char *devicename = "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A10596TP-if00-port0";
const uint32_t baudrate = 115200;
static int fd;
static uint16_t chan[16];
static uint8_t nchan = 0;
// setup routine
void setup()
@@ -106,30 +120,42 @@ void setup()
}
tcflush(fd, TCIOFLUSH);
rcprot = new AP_RCProtocol();
rcprot = &AP::RC();
#if CONFIG_HAL_BOARD != HAL_BOARD_SITL
rcprot->init();
#endif
// proxy to SITL's rcin port
rc_socket.connect("0.0.0.0", 5501);
}
//Main loop where the action takes place
void loop()
{
uint8_t buf[32];
uint8_t buf[62]; // lowest USB buffer size is 62 user bytes
ssize_t ret = read(fd, buf, sizeof(buf));
if (ret <= 0) {
return;
}
for (uint8_t i=0; i<ret; i++) {
rcprot->process_byte(buf[i], 115200);
if (rcprot->new_input()) {
uint8_t nchan = rcprot->num_channels();
nchan = MIN(rcprot->num_channels(), 16);
rcprot->read(chan, nchan);
printf("%u: ", nchan);
for (uint8_t j=0; j<nchan; j++) {
uint16_t v = rcprot->read(j);
printf("%04u ", v);
// normalize data for SITL
chan[j] = constrain_int16(chan[j], 1100, 1900);
printf("%04u ", chan[j]);
}
printf("\n");
}
}
// SITL expects either 8 or 16 channels, send whether we got data or not
if (nchan <= 8) {
rc_socket.send(chan, 8 * 2);
} else {
rc_socket.send(chan, 16 * 2);
}
}
#else
@@ -139,4 +165,16 @@ void loop() {}
#endif // CONFIG_HAL_BOARD
AP_HAL_MAIN();
AP_HAL::HAL::FunCallbacks callbacks(setup, loop);
extern "C" {
int main(int argc, char* const argv[]);
int main(int argc, char* const argv[]) {
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
if (argc > 1) {
devicename = argv[1];
}
#endif
hal.run(argc, argv, &callbacks);
return 0;
}
}