45 #include <px4_platform_common/px4_config.h> 46 #include <px4_platform_common/defines.h> 47 #include <px4_platform_common/tasks.h> 52 #include <sys/ioctl.h> 57 #include "../messages.h" 59 #define DEFAULT_UART "/dev/ttyS0"; 65 static const char commandline_usage[] =
"usage: hott_sensors start|status|stop [-d <device>]";
77 static int recv_data(
int uart, uint8_t *buffer,
size_t *size, uint8_t *
id);
78 static int send_poll(
int uart, uint8_t *buffer,
size_t size);
83 for (
size_t i = 0; i < size; i++) {
84 write(uart, &buffer[i],
sizeof(buffer[i]));
93 read(uart, &dummy, size);
99 recv_data(
int uart, uint8_t *buffer,
size_t *size, uint8_t *
id)
108 if (poll(&fds, 1, timeout_ms) > 0) {
110 bool stop_byte_read =
false;
113 read(uart, &buffer[i],
sizeof(buffer[i]));
115 if (stop_byte_read) {
124 stop_byte_read =
true;
144 for (
int i = 0; i < argc && argv[i]; i++) {
145 if (strcmp(argv[i],
"-d") == 0 || strcmp(argv[i],
"--device") == 0) {
147 device = argv[i + 1];
160 errx(1,
"Open fail, exiting.");
185 warnx(
"Unknown sensor ID: %d",
id);
206 if (!strcmp(argv[1],
"start")) {
209 warnx(
"already running");
216 SCHED_PRIORITY_DEFAULT,
219 (argv) ? (
char *
const *)&argv[2] : (
char *
const *)NULL);
223 if (!strcmp(argv[1],
"stop")) {
228 if (!strcmp(argv[1],
"status")) {
233 warnx(
"not started");
static const char daemon_name[]
static int thread_should_exit
Deamon exit flag.
static const char commandline_usage[]
#define DEFAULT_UART
USART1.
#define MAX_MESSAGE_BUFFER_SIZE
static int deamon_task
Handle of deamon task / thread.
Namespace encapsulating all device framework classes, functions and data.
int hott_sensors_thread_main(int argc, char *argv[])
Mainloop of daemon.
static void read(bootloader_app_shared_t *pshared)
void build_gam_request(uint8_t *buffer, size_t *size)
void init_pub_messages(void)
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
static int recv_data(int uart, uint8_t *buffer, size_t *size, uint8_t *id)
#define POST_WRITE_DELAY_IN_USECS
int open_uart(const char *device)
static void write(bootloader_app_shared_t *pshared)
static int thread_running
Deamon status flag.
void publish_gam_message(const uint8_t *buffer)
static int send_poll(int uart, uint8_t *buffer, size_t size)
__EXPORT int hott_sensors_main(int argc, char *argv[])
Deamon management function.