Firmware
microRTPS_client.h
1 /****************************************************************************
2  *
3  * Copyright 2017 Proyectos y Sistemas de Mantenimiento SL (eProsima).
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  ****************************************************************************/
32 
33 #pragma once
34 
35 #include "microRTPS_transport.h"
36 
37 #include <inttypes.h>
38 #include <cstdio>
39 #include <ctime>
40 #include <pthread.h>
41 #include <termios.h>
42 
43 #include <ucdr/microcdr.h>
44 #include <px4_config.h>
45 #include <px4_getopt.h>
46 #include <px4_posix.h>
47 #include <px4_tasks.h>
48 #include <px4_time.h>
49 #include <uORB/uORB.h>
50 
51 #define BUFFER_SIZE 1024
52 #define UPDATE_TIME_MS 0
53 #define LOOPS -1
54 #define SLEEP_MS 1
55 #define BAUDRATE B460800
56 #define BAUDRATE_VAL 460800
57 #ifndef B460800
58 #define B460800 460800
59 #endif
60 #ifndef B921600
61 #define B921600 921600
62 #endif
63 #define DEVICE "/dev/ttyACM0"
64 #define POLL_MS 1
65 #define DEFAULT_RECV_PORT 2019
66 #define DEFAULT_SEND_PORT 2020
67 
68 void *send(void *data);
69 void micrortps_start_topics(struct timespec &begin, int &total_read, uint32_t &received, int &loop);
70 
71 struct baudtype {
72  speed_t code;
73  uint32_t val;
74 };
75 
76 struct options {
77  enum class eTransports {
78  UART,
79  UDP
80  };
81  eTransports transport = options::eTransports::UART;
82  char device[64] = DEVICE;
83  int update_time_ms = UPDATE_TIME_MS;
84  int loops = LOOPS;
85  int sleep_ms = SLEEP_MS;
86  struct baudtype baudrate = {.code = BAUDRATE, .val = BAUDRATE_VAL};
87  int poll_ms = POLL_MS;
88  uint16_t recv_port = DEFAULT_RECV_PORT;
89  uint16_t send_port = DEFAULT_SEND_PORT;
90 };
91 
92 extern struct options _options;
93 extern bool _should_exit_task;
94 extern Transport_node *transport_node;
Definition: microRTPS_transport.h:40
Definition: microRTPS_client.h:76
Configuration flags used in code.
Includes POSIX-like functions for virtual character devices.
Definition: microRTPS_client.h:71
Namespace encapsulating all device framework classes, functions and data.
Definition: CDev.cpp:47
API for the uORB lightweight object broker.
Thread safe version of getopt.