mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-31 05:21:35 +08:00
increase priority of sPort_telemetry to 200
This commit is contained in:
committed by
Lorenz Meier
parent
bb565f5d6a
commit
ff690dda80
@@ -112,14 +112,12 @@ void sPort_init()
|
|||||||
static void sPort_send_start(int uart)
|
static void sPort_send_start(int uart)
|
||||||
{
|
{
|
||||||
static const uint8_t c = 0x10;
|
static const uint8_t c = 0x10;
|
||||||
write(uart, &c, sizeof(c));
|
write(uart, &c, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_crc(uint16_t *crc)
|
static void update_crc(uint16_t *crc, uint8_t b)
|
||||||
{
|
{
|
||||||
*crc += 0x10;
|
*crc += b;
|
||||||
*crc += *crc >> 8;
|
|
||||||
*crc &= 0xFF;
|
|
||||||
*crc += *crc >> 8;
|
*crc += *crc >> 8;
|
||||||
*crc &= 0xFF;
|
*crc &= 0xFF;
|
||||||
}
|
}
|
||||||
@@ -152,27 +150,30 @@ static void sPort_send_byte(int uart, uint8_t value)
|
|||||||
*/
|
*/
|
||||||
void sPort_send_data(int uart, uint16_t id, uint32_t data)
|
void sPort_send_data(int uart, uint16_t id, uint32_t data)
|
||||||
{
|
{
|
||||||
union {
|
union {
|
||||||
uint16_t word;
|
uint32_t word;
|
||||||
uint8_t byte[2];
|
uint8_t byte[4];
|
||||||
} wbuf;
|
} buf;
|
||||||
|
|
||||||
uint16_t crc = 0;
|
uint16_t crc = 0;
|
||||||
sPort_send_start(uart);
|
sPort_send_start(uart);
|
||||||
|
// write(uart, 0x10, 1);
|
||||||
|
|
||||||
wbuf.word = id;
|
buf.word = id;
|
||||||
|
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
update_crc(&crc);
|
update_crc(&crc, buf.byte[i]);
|
||||||
sPort_send_byte(uart, wbuf.byte[i]); /* LSB first */
|
sPort_send_byte(uart, buf.byte[i]); /* LSB first */
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *bbuf = (uint8_t *)data;
|
buf.word = data;
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
update_crc(&crc);
|
update_crc(&crc, buf.byte[i]);
|
||||||
sPort_send_byte(uart, bbuf[i]); /* LSB first */
|
sPort_send_byte(uart, buf.byte[i]); /* LSB first */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sPort_send_byte(uart, crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef xxxx
|
#ifdef xxxx
|
||||||
|
|||||||
@@ -49,11 +49,13 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <poll.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <systemlib/err.h>
|
#include <systemlib/err.h>
|
||||||
#include <systemlib/systemlib.h>
|
#include <systemlib/systemlib.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <drivers/drv_hrt.h>
|
||||||
|
|
||||||
#include "sPort_data.h"
|
#include "sPort_data.h"
|
||||||
|
|
||||||
@@ -76,23 +78,13 @@ __EXPORT int sPort_telemetry_main(int argc, char *argv[]);
|
|||||||
static int sPort_open_uart(const char *uart_name, struct termios *uart_config_original)
|
static int sPort_open_uart(const char *uart_name, struct termios *uart_config_original)
|
||||||
{
|
{
|
||||||
/* Open UART */
|
/* Open UART */
|
||||||
const int uart = open(uart_name, O_RDWR | O_NOCTTY);
|
const int uart = open(uart_name, O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||||
|
// const int uart = open(uart_name, O_RDWR | O_NOCTTY);
|
||||||
|
|
||||||
if (uart < 0) {
|
if (uart < 0) {
|
||||||
err(1, "Error opening port: %s", uart_name);
|
err(1, "Error opening port: %s", uart_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make sure uart FD is blocking */
|
|
||||||
int flags = fcntl(uart, F_GETFL);
|
|
||||||
if (flags < 0) {
|
|
||||||
err(1, "Error getting FD flags: %s", uart_name);
|
|
||||||
}
|
|
||||||
flags &= ~O_NONBLOCK;
|
|
||||||
flags = fcntl(uart, F_SETFL, flags);
|
|
||||||
if (flags < 0) {
|
|
||||||
err(1, "Error setting FD flags: %s", uart_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Back up the original UART configuration to restore it after exit */
|
/* Back up the original UART configuration to restore it after exit */
|
||||||
int termios_state;
|
int termios_state;
|
||||||
|
|
||||||
@@ -175,33 +167,37 @@ static int sPort_telemetry_thread_main(int argc, char *argv[])
|
|||||||
err(1, "could not open %s", device_name);
|
err(1, "could not open %s", device_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* poll descriptor */
|
||||||
|
struct pollfd fds[1];
|
||||||
|
fds[0].fd = uart;
|
||||||
|
fds[0].events = POLLIN;
|
||||||
|
|
||||||
/* Subscribe to topics */
|
/* Subscribe to topics */
|
||||||
sPort_init();
|
sPort_init();
|
||||||
|
|
||||||
thread_running = true;
|
thread_running = true;
|
||||||
|
|
||||||
/* Main thread loop */
|
/* Main thread loop */
|
||||||
char sbuf[2];
|
char sbuf[20];
|
||||||
uint8_t fiftyfive = 0x55;
|
|
||||||
|
|
||||||
while (!thread_should_exit) {
|
while (!thread_should_exit) {
|
||||||
|
|
||||||
/* wait for poll frame starting with value 0x7E */
|
/* wait for poll frame starting with value 0x7E */
|
||||||
int newBytes = read(uart, &sbuf[0], 1);
|
int status = poll(fds, sizeof(fds) / sizeof(fds[0]), -1);
|
||||||
// warnx("%x, %x \n", sbuf[0], sbuf[1]);
|
if (status < 1) continue;
|
||||||
|
|
||||||
|
// read 2 bytes
|
||||||
|
int newBytes = read(uart, &sbuf[0], 2);
|
||||||
if (newBytes < 1 || sbuf[0] != 0x7E) continue;
|
if (newBytes < 1 || sbuf[0] != 0x7E) continue;
|
||||||
|
|
||||||
/* read the ID byte */
|
/* device ID 4 */
|
||||||
sbuf[1] = read(uart, &sbuf[0], 1);
|
static uint8_t counter = 0;
|
||||||
|
if (sbuf[1] == 0xe4) {
|
||||||
// sPort_send_data(uart, id, 7);
|
/* send data for A2 */
|
||||||
|
sPort_send_data(uart, 0xf103, counter++);
|
||||||
/*** test ***/
|
/* read it back */
|
||||||
/* write single byte */
|
read(uart, &sbuf[0], sizeof(sbuf));
|
||||||
write(uart, &fiftyfive, 1);
|
}
|
||||||
/* read it back */
|
|
||||||
read(uart, &sbuf[0], 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset the UART flags to original state */
|
/* Reset the UART flags to original state */
|
||||||
@@ -233,7 +229,7 @@ int sPort_telemetry_main(int argc, char *argv[])
|
|||||||
thread_should_exit = false;
|
thread_should_exit = false;
|
||||||
sPort_task = px4_task_spawn_cmd("sPort_telemetry",
|
sPort_task = px4_task_spawn_cmd("sPort_telemetry",
|
||||||
SCHED_DEFAULT,
|
SCHED_DEFAULT,
|
||||||
SCHED_PRIORITY_DEFAULT,
|
200,
|
||||||
2000,
|
2000,
|
||||||
sPort_telemetry_thread_main,
|
sPort_telemetry_thread_main,
|
||||||
(char *const *)argv);
|
(char *const *)argv);
|
||||||
|
|||||||
Reference in New Issue
Block a user