You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.0 KiB
66 lines
1.0 KiB
10 years ago
|
#include <AP_HAL.h>
|
||
|
|
||
|
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <unistd.h>
|
||
|
#include <errno.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
10 years ago
|
#include "TCPServerDevice.h"
|
||
10 years ago
|
|
||
10 years ago
|
TCPServerDevice::TCPServerDevice(const char *ip, uint16_t port):
|
||
10 years ago
|
_ip(ip),
|
||
|
_port(port)
|
||
|
{
|
||
|
}
|
||
|
|
||
10 years ago
|
TCPServerDevice::~TCPServerDevice()
|
||
10 years ago
|
{
|
||
|
|
||
|
}
|
||
|
|
||
10 years ago
|
ssize_t TCPServerDevice::write(const uint8_t *buf, uint16_t n)
|
||
10 years ago
|
{
|
||
|
return listener.send(buf, n);
|
||
|
}
|
||
|
|
||
10 years ago
|
ssize_t TCPServerDevice::read(uint8_t *buf, uint16_t n)
|
||
10 years ago
|
{
|
||
|
return listener.recv(buf, n, 1);
|
||
|
}
|
||
|
|
||
10 years ago
|
bool TCPServerDevice::open()
|
||
10 years ago
|
{
|
||
|
listener.reuseaddress();
|
||
|
|
||
|
if (!listener.connect(_ip, _port)) {
|
||
|
::printf("connect failed on %s port %u - %s\n",
|
||
|
_ip,
|
||
|
_port,
|
||
|
strerror(errno));
|
||
|
::exit(1);
|
||
|
}
|
||
|
|
||
|
listener.set_blocking(false);
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
10 years ago
|
bool TCPServerDevice::close()
|
||
10 years ago
|
{
|
||
|
return true;
|
||
|
}
|
||
|
|
||
10 years ago
|
void TCPServerDevice::set_blocking(bool blocking)
|
||
10 years ago
|
{
|
||
|
listener.set_blocking(blocking);
|
||
|
}
|
||
|
|
||
10 years ago
|
void TCPServerDevice::set_speed(uint32_t speed)
|
||
10 years ago
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
#endif
|