7 #include <netinet/in.h> 8 #include <netinet/tcp.h> 14 #include <sys/socket.h> 16 #include <sys/types.h> 31 using namespace Linux;
38 if (default_console) {
72 ::fprintf(stderr,
"Argument is not valid. Fallback to console.\n" 73 "Launch with --help to see an example.\n");
129 if (
stat(arg, &st) == 0 && S_ISCHR(st.st_mode)) {
131 }
else if (strncmp(arg,
"tcp:", 4) != 0 &&
132 strncmp(arg,
"udp:", 4) != 0 &&
133 strncmp(arg,
"udpin:", 6)) {
137 char *devstr = strdup(arg);
139 if (devstr ==
nullptr) {
143 char *saveptr =
nullptr;
144 char *protocol, *ip, *port, *
flag;
146 protocol = strtok_r(devstr,
":", &saveptr);
147 ip = strtok_r(
nullptr,
":", &saveptr);
148 port = strtok_r(
nullptr,
":", &saveptr);
149 flag = strtok_r(
nullptr,
":", &saveptr);
151 if (ip ==
nullptr || port ==
nullptr) {
170 if (flag !=
nullptr) {
171 _flag = strdup(flag);
176 if (strcmp(protocol,
"udp") == 0 || strcmp(protocol,
"udpin") == 0) {
177 bool bcast = (
_flag && strcmp(
_flag,
"bcast") == 0);
179 if (strcmp(protocol,
"udp") == 0) {
189 bool wait = (
_flag && strcmp(
_flag,
"wait") == 0);
357 uint16_t n = available_bytes;
360 b != MAVLINK_STX_MAVLINK1 && b != MAVLINK_STX) {
366 uint16_t limit = n>256?256:n;
368 for (i=0; i<limit; i++) {
370 if (b == MAVLINK_STX_MAVLINK1 || b == MAVLINK_STX) {
382 (b == MAVLINK_STX_MAVLINK1 || b == MAVLINK_STX)) {
383 uint8_t min_length = (b == MAVLINK_STX_MAVLINK1)?8:12;
386 if (n < min_length) {
394 if (b == MAVLINK_STX) {
397 if (incompat_flags & MAVLINK_IFLAG_SIGNED) {
398 min_length += MAVLINK_SIGNATURE_BLOCK_LEN;
401 if (n < len+min_length) {
404 }
else if (n > len+min_length) {
425 for (
int i = 0; i < n_vec; i++) {
426 ret =
_write_fd(vec[i].data, (uint16_t)vec[i].len);
433 if ((
unsigned)ret != vec[i].len) {
454 uint8_t num_send = 10;
464 for (
int i = 0; i < n_vec; i++) {
465 ret =
_read_fd(vec[i].data, vec[i].len);
476 if ((
unsigned)ret < vec[i].len) {
503 last_receive_us -= transport_time_us;
505 return last_receive_us;
AP_HAL::OwnPtr< SerialDevice > _parseDevicePath(const char *arg)
void set_blocking_writes(bool blocking)
uint32_t available(void) const
virtual void set_blocking(bool blocking)=0
Interface definition for the various Ground Control System.
bool _write_pending_bytes(void)
bool commit(uint32_t len)
virtual ssize_t read(uint8_t *buf, uint16_t n)=0
uint32_t space(void) const
void _allocate_buffers(uint16_t rxS, uint16_t txS)
virtual ssize_t write(const uint8_t *buf, uint16_t n)=0
virtual void delay(uint16_t ms)=0
uint8_t _receive_timestamp_idx
virtual void _timer_tick(void) override
void set_device_path(const char *path)
uint64_t _receive_timestamp[2]
bool set_size(uint32_t size)
uint64_t receive_time_constraint_us(uint16_t nbytes) override
uint32_t peekbytes(uint8_t *data, uint32_t len)
volatile bool _initialised
uint32_t txspace() override
uint32_t available() override
virtual int _write_fd(const uint8_t *buf, uint16_t n)
uint32_t write(const uint8_t *data, uint32_t len)
virtual int _read_fd(uint8_t *buf, uint16_t n)
uint8_t peekiovec(IoVec vec[2], uint32_t len)
int stat(const char *name, struct stat *buf)
Display struct stat, from POSIX stat(0 or fstat(), in ASCII. NOT POSIX.
virtual void set_speed(uint32_t speed)=0
int16_t peek(uint32_t ofs) const
AP_HAL::OwnPtr< SerialDevice > _device
int fprintf(FILE *fp, const char *fmt,...)
fprintf character write function
void uint32_t uint32_t uint32_t flag
void _deallocate_buffers()
uint8_t reserve(IoVec vec[2], uint32_t len)
void panic(const char *errormsg,...) FMT_PRINTF(1
AP_HAL::Scheduler * scheduler
bool read_byte(uint8_t *data)