Skip to content
Snippets Groups Projects
Commit 077e0367 authored by Murilo Belluzzo's avatar Murilo Belluzzo Committed by Lucas De Marchi
Browse files

Global: Adapt Stream class to be used with Ringbuffer

parent b856d260
No related branches found
No related tags found
No related merge requests found
Showing with 35 additions and 37 deletions
...@@ -8,10 +8,10 @@ ...@@ -8,10 +8,10 @@
class AP_HAL::Stream : public AP_HAL::Print { class AP_HAL::Stream : public AP_HAL::Print {
public: public:
virtual int16_t available() = 0; virtual uint32_t available() = 0;
/* NB txspace was traditionally a member of BetterStream in the /* NB txspace was traditionally a member of BetterStream in the
* FastSerial library. As far as concerns go, it belongs with available() */ * FastSerial library. As far as concerns go, it belongs with available() */
virtual int16_t txspace() = 0; virtual uint32_t txspace() = 0;
/* return value for read(): /* return value for read():
* -1 if nothing available, uint8_t value otherwise. */ * -1 if nothing available, uint8_t value otherwise. */
......
...@@ -14,8 +14,8 @@ void UARTDriver::set_blocking_writes(bool blocking) {} ...@@ -14,8 +14,8 @@ void UARTDriver::set_blocking_writes(bool blocking) {}
bool UARTDriver::tx_pending() { return false; } bool UARTDriver::tx_pending() { return false; }
/* Empty implementations of Stream virtual methods */ /* Empty implementations of Stream virtual methods */
int16_t UARTDriver::available() { return 0; } uint32_t UARTDriver::available() { return 0; }
int16_t UARTDriver::txspace() { return 1; } uint32_t UARTDriver::txspace() { return 1; }
int16_t UARTDriver::read() { return -1; } int16_t UARTDriver::read() { return -1; }
/* Empty implementations of Print virtual methods */ /* Empty implementations of Print virtual methods */
......
...@@ -15,9 +15,9 @@ public: ...@@ -15,9 +15,9 @@ public:
bool tx_pending(); bool tx_pending();
/* Empty implementations of Stream virtual methods */ /* Empty implementations of Stream virtual methods */
int16_t available(); uint32_t available() override;
int16_t txspace(); uint32_t txspace() override;
int16_t read(); int16_t read() override;
/* Empty implementations of Print virtual methods */ /* Empty implementations of Print virtual methods */
size_t write(uint8_t c); size_t write(uint8_t c);
......
...@@ -290,7 +290,7 @@ bool UARTDriver::tx_pending() ...@@ -290,7 +290,7 @@ bool UARTDriver::tx_pending()
/* /*
return the number of bytes available to be read return the number of bytes available to be read
*/ */
int16_t UARTDriver::available() uint32_t UARTDriver::available()
{ {
if (!_initialised) { if (!_initialised) {
return 0; return 0;
...@@ -302,7 +302,7 @@ int16_t UARTDriver::available() ...@@ -302,7 +302,7 @@ int16_t UARTDriver::available()
/* /*
how many bytes are available in the output buffer? how many bytes are available in the output buffer?
*/ */
int16_t UARTDriver::txspace() uint32_t UARTDriver::txspace()
{ {
if (!_initialised) { if (!_initialised) {
return 0; return 0;
......
...@@ -25,9 +25,9 @@ public: ...@@ -25,9 +25,9 @@ public:
bool tx_pending(); bool tx_pending();
/* Linux implementations of Stream virtual methods */ /* Linux implementations of Stream virtual methods */
int16_t available(); uint32_t available() override;
int16_t txspace(); uint32_t txspace() override;
int16_t read(); int16_t read() override;
/* Linux implementations of Print virtual methods */ /* Linux implementations of Print virtual methods */
size_t write(uint8_t c); size_t write(uint8_t c);
......
...@@ -122,18 +122,18 @@ int16_t NSHShellStream::read() ...@@ -122,18 +122,18 @@ int16_t NSHShellStream::read()
return -1; return -1;
} }
int16_t NSHShellStream::available() uint32_t NSHShellStream::available()
{ {
int ret = 0; uint32_t ret = 0;
if (ioctl(shell_stdin, FIONREAD, (unsigned long)&ret) == OK) { if (ioctl(shell_stdin, FIONREAD, (unsigned long)&ret) == OK) {
return ret; return ret;
} }
return 0; return 0;
} }
int16_t NSHShellStream::txspace() uint32_t NSHShellStream::txspace()
{ {
int ret = 0; uint32_t ret = 0;
if (ioctl(shell_stdout, FIONWRITE, (unsigned long)&ret) == OK) { if (ioctl(shell_stdout, FIONWRITE, (unsigned long)&ret) == OK) {
return ret; return ret;
} }
......
...@@ -236,7 +236,7 @@ bool PX4UARTDriver::tx_pending() { return false; } ...@@ -236,7 +236,7 @@ bool PX4UARTDriver::tx_pending() { return false; }
/* /*
return number of bytes available to be read from the buffer return number of bytes available to be read from the buffer
*/ */
int16_t PX4UARTDriver::available() uint32_t PX4UARTDriver::available()
{ {
if (!_initialised) { if (!_initialised) {
try_initialise(); try_initialise();
...@@ -249,7 +249,7 @@ int16_t PX4UARTDriver::available() ...@@ -249,7 +249,7 @@ int16_t PX4UARTDriver::available()
/* /*
return number of bytes that can be added to the write buffer return number of bytes that can be added to the write buffer
*/ */
int16_t PX4UARTDriver::txspace() uint32_t PX4UARTDriver::txspace()
{ {
if (!_initialised) { if (!_initialised) {
try_initialise(); try_initialise();
......
...@@ -16,9 +16,9 @@ public: ...@@ -16,9 +16,9 @@ public:
bool tx_pending(); bool tx_pending();
/* PX4 implementations of Stream virtual methods */ /* PX4 implementations of Stream virtual methods */
int16_t available(); uint32_t available() override;
int16_t txspace(); uint32_t txspace() override;
int16_t read(); int16_t read() override;
/* PX4 implementations of Print virtual methods */ /* PX4 implementations of Print virtual methods */
size_t write(uint8_t c); size_t write(uint8_t c);
......
...@@ -8,9 +8,9 @@ class PX4::NSHShellStream : public AP_HAL::Stream { ...@@ -8,9 +8,9 @@ class PX4::NSHShellStream : public AP_HAL::Stream {
public: public:
size_t write(uint8_t); size_t write(uint8_t);
size_t write(const uint8_t *buffer, size_t size); size_t write(const uint8_t *buffer, size_t size);
int16_t read(); int16_t read() override;
int16_t available(); uint32_t available() override;
int16_t txspace(); uint32_t txspace() override;
private: private:
int shell_stdin = -1; int shell_stdin = -1;
int shell_stdout = -1; int shell_stdout = -1;
......
...@@ -100,7 +100,7 @@ void UARTDriver::end() ...@@ -100,7 +100,7 @@ void UARTDriver::end()
{ {
} }
int16_t UARTDriver::available(void) uint32_t UARTDriver::available(void)
{ {
_check_connection(); _check_connection();
...@@ -111,9 +111,7 @@ int16_t UARTDriver::available(void) ...@@ -111,9 +111,7 @@ int16_t UARTDriver::available(void)
return _readbuffer.available(); return _readbuffer.available();
} }
uint32_t UARTDriver::txspace(void)
int16_t UARTDriver::txspace(void)
{ {
_check_connection(); _check_connection();
if (!_connected) { if (!_connected) {
......
...@@ -47,9 +47,9 @@ public: ...@@ -47,9 +47,9 @@ public:
} }
/* Implementations of Stream virtual methods */ /* Implementations of Stream virtual methods */
int16_t available(); uint32_t available() override;
int16_t txspace(); uint32_t txspace() override;
int16_t read(); int16_t read() override;
/* Implementations of Print virtual methods */ /* Implementations of Print virtual methods */
size_t write(uint8_t c); size_t write(uint8_t c);
......
...@@ -230,7 +230,7 @@ bool VRBRAINUARTDriver::tx_pending() { return false; } ...@@ -230,7 +230,7 @@ bool VRBRAINUARTDriver::tx_pending() { return false; }
/* /*
return number of bytes available to be read from the buffer return number of bytes available to be read from the buffer
*/ */
int16_t VRBRAINUARTDriver::available() uint32_t VRBRAINUARTDriver::available()
{ {
if (!_initialised) { if (!_initialised) {
try_initialise(); try_initialise();
...@@ -243,7 +243,7 @@ int16_t VRBRAINUARTDriver::available() ...@@ -243,7 +243,7 @@ int16_t VRBRAINUARTDriver::available()
/* /*
return number of bytes that can be added to the write buffer return number of bytes that can be added to the write buffer
*/ */
int16_t VRBRAINUARTDriver::txspace() uint32_t VRBRAINUARTDriver::txspace()
{ {
if (!_initialised) { if (!_initialised) {
try_initialise(); try_initialise();
......
...@@ -16,9 +16,9 @@ public: ...@@ -16,9 +16,9 @@ public:
bool tx_pending(); bool tx_pending();
/* VRBRAIN implementations of Stream virtual methods */ /* VRBRAIN implementations of Stream virtual methods */
int16_t available(); uint32_t available() override;
int16_t txspace(); uint32_t txspace() override;
int16_t read(); int16_t read() override;
/* VRBRAIN implementations of Print virtual methods */ /* VRBRAIN implementations of Print virtual methods */
size_t write(uint8_t c); size_t write(uint8_t c);
......
...@@ -165,7 +165,7 @@ void AP_Mount_Alexmos::write_params() ...@@ -165,7 +165,7 @@ void AP_Mount_Alexmos::write_params()
*/ */
void AP_Mount_Alexmos::send_command(uint8_t cmd, uint8_t* data, uint8_t size) void AP_Mount_Alexmos::send_command(uint8_t cmd, uint8_t* data, uint8_t size)
{ {
if (_port->txspace() < (size + 5)) { if (_port->txspace() < (size + 5U)) {
return; return;
} }
uint8_t checksum = 0; uint8_t checksum = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment