Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port from 1.13_fc_only to main [1/4] #703

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ROMFS/px4fmu_common/init.d/airframes/4420_ssrc_arwing
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ param set-default PWM_AUX_FUNC4 101
param set-default PWM_MAIN_REV 2
param set-default PWM_AUX_REV 2

# Enable airspeed sensor
param set-default SENS_EN_SDP3X 1

# Airspeed parameters
sdp3x start -X -f 400
param set-default ASPD_DO_CHECKS 15
param set-default FW_AIRSPD_MAX 22.0
param set-default FW_AIRSPD_MIN 14.0
Expand Down
1 change: 0 additions & 1 deletion ROMFS/px4fmu_common/init.d/airframes/4421_ssrc_skywalker
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ param set-default PWM_MAIN_FUNC2 202
param set-default PWM_MAIN_FUNC4 101

# Airspeed parameters
ms4525do start -X -f 500
param set-default SENS_EN_MS4525DO 1
param set-default ASPD_DO_CHECKS 15
param set-default FW_AIRSPD_MAX 25.0
Expand Down
4 changes: 2 additions & 2 deletions ROMFS/px4fmu_common/init.d/airframes/4430_ssrc_strivermini
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ param set-default PWM_AUX_FUNC5 205
param set-default PWM_AUX_FUNC6 105

# Start airspeed sensor driver
ms4525do start -X -f 500
sdp3x start -X -f 500
param set-default SENS_EN_MS4525DO 1
param set-default SENS_EN_SDP3X 1

# Airspeed parameters
param set-default ASPD_DO_CHECKS 7
Expand Down
2 changes: 1 addition & 1 deletion boards/ssrc/saluki-pi
2 changes: 1 addition & 1 deletion boards/ssrc/saluki-v2
2 changes: 1 addition & 1 deletion boards/ssrc/saluki-v3
2 changes: 1 addition & 1 deletion src/drivers/differential_pressure/ms4525do/MS4525DO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include <uORB/PublicationMulti.hpp>
#include <uORB/topics/differential_pressure.h>

static constexpr uint32_t I2C_SPEED = 100 * 1000; // 100 kHz I2C serial interface
static constexpr uint32_t I2C_SPEED = 400 * 1000; // 400 kHz I2C serial interface
static constexpr uint8_t I2C_ADDRESS_DEFAULT = 0x28;

/* Register address */
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/differential_pressure/sdp3x/SDP3X.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#define I2C_ADDRESS_2_SDP3X 0x22
#define I2C_ADDRESS_3_SDP3X 0x23

static constexpr uint32_t I2C_SPEED = 100 * 1000; // 100 kHz I2C serial interface
static constexpr uint32_t I2C_SPEED = 400 * 1000; // 400 kHz I2C serial interface

#define SDP3X_SCALE_TEMPERATURE 200.0f
#define SDP3X_RESET_ADDR 0x00
Expand Down
41 changes: 41 additions & 0 deletions src/systemcmds/telem_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
############################################################################
#
# Copyright (c) 2024 Technology Innoavation Institute. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name PX4 nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################

px4_add_module(
MODULE systemcmds__telem_test
MAIN telem_test
COMPILE_FLAGS
SRCS
telem_test.cpp
DEPENDS
)
12 changes: 12 additions & 0 deletions src/systemcmds/telem_test/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
menuconfig SYSTEMCMDS_TELEM_TEST
bool "telem_test"
default n
---help---
Enable support for telemetry uart test

menuconfig USER_TELEM_TEST
bool "telemetry uart test running as userspace module"
default y
depends on BOARD_PROTECTED && SYSTEMCMDS_TELEM_TEST
---help---
Put telemetry uart test in userspace memory
208 changes: 208 additions & 0 deletions src/systemcmds/telem_test/telem_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/****************************************************************************
*
* Copyright (c) 2024 Technology Innovation Institute. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/

#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>

#include <px4_platform_common/px4_config.h>
#include <px4_platform_common/module.h>
#include <drivers/drv_hrt.h>

static void usage(const char *reason)
{
if (reason != nullptr) {
printf("%s\n\n", reason);
}

PRINT_MODULE_DESCRIPTION("Telemetry UART test tool");

PRINT_MODULE_USAGE_NAME("telem_test", "command");
PRINT_MODULE_USAGE_COMMAND_DESCR("flush", "Flush UART");
PRINT_MODULE_USAGE_ARG("<dev>", "Uart device", false);
PRINT_MODULE_USAGE_COMMAND_DESCR("loopback", "Loopback test between uarts");
PRINT_MODULE_USAGE_ARG("<dev1>", "First UART device", false);
PRINT_MODULE_USAGE_ARG("<dev2>", "Second UART device", false);
PRINT_MODULE_USAGE_COMMAND_DESCR("send", "Send string to UART");
PRINT_MODULE_USAGE_ARG("<dev>", "Uart device", false);
PRINT_MODULE_USAGE_COMMAND_DESCR("recv", "Receive string from UART");
PRINT_MODULE_USAGE_ARG("<dev>", "UART device", false);
}

static int test_recv(int uart_recv, char *recv_buf, size_t buf_len)
{
if (read(uart_recv, recv_buf, buf_len) < 0) {
printf("ERROR read: %d\n", errno);
return 1;
}

return 0;
}

static int test_send(int uart_send, const char *send_buf)
{
if (write(uart_send, send_buf, strlen(send_buf)) < 0) {
printf("ERROR write: %d\n", errno);
return 1;
}

px4_usleep(200000);

return 0;
}

static int loopback(int uart_send, int uart_recv, const char *send_buf)
{
char recv_buf[15] = {0};

if (test_send(uart_send, send_buf)) {
return 1;
}

if (test_recv(uart_recv, recv_buf, sizeof(recv_buf) - 1)) {
return 1;
}

if (strncmp(send_buf, recv_buf, strlen(send_buf)) != 0) {
printf("ERROR: send != recv\n");
printf(" send '%s'\n", send_buf);
printf(" recv '%s'\n", recv_buf);
return 1;
}

return 0;
}

static int test_loopback(int uart1, int uart2)
{
const char *send_str1 = "send_uart_1";
const char *send_str2 = "send_uart_2";

printf("send: first -> second\n");

if (loopback(uart1, uart2, send_str1)) {
return 1;
}

printf("send: second -> first\n");

if (loopback(uart2, uart1, send_str2)) {
return 1;
}

return 0;
}

extern "C" __EXPORT int telem_test_main(int argc, char *argv[])
{
int res = 1;

if (argc < 3) {
usage(nullptr);
return 1;
}

const char *test_type = argv[1];
const char *uart1_dev = argv[2];
const char *uart2_dev = NULL;

if (argc > 3) {
uart2_dev = argv[3];
}

printf("test type: %s\n", test_type);

int uart1 = open(uart1_dev, O_RDWR | O_NONBLOCK | O_NOCTTY);

if (uart1 < 0) {
printf("ERROR: %s open\n", uart1_dev);
return 1;
}

if (strcmp(test_type, "loopback") == 0) {
printf("first uart: %s\n", uart1_dev);

if (!uart2_dev) {
usage("ERROR: second uart not specified");
close(uart1);
return 1;
}

int uart2 = open(uart2_dev, O_RDWR | O_NONBLOCK | O_NOCTTY);

if (uart2 < 0) {
printf("ERROR: %s open\n", uart2_dev);
close(uart1);
return 1;
}

printf("second uart: %s\n", uart2_dev);

res = test_loopback(uart1, uart2);

close(uart2);

} else if (strcmp(test_type, "flush") == 0) {
printf("flush uart: %s\n", uart1_dev);

res = tcflush(uart1, TCIOFLUSH);

if (res < 0) {
printf("ERROR tcflush: %d\n", errno);
}

} else if (strcmp(test_type, "send") == 0) {
printf("uart: %s\n", uart1_dev);

const char *send_str = "send_uart";
res = test_send(uart1, send_str);

printf("sent: '%s'\n", send_str);

} else if (strcmp(test_type, "recv") == 0) {
printf("uart: %s\n", uart1_dev);

char recv_buf[20] = {0};
res = test_recv(uart1, recv_buf, sizeof(recv_buf) - 1);

printf("recv: '%s'\n", recv_buf);

} else {
usage("ERROR: test type not supported");
}

close(uart1);
return res;
}
Loading