mirror of https://github.com/ArduPilot/ardupilot
Global: Adapt Stream class to be used with Ringbuffer
This commit is contained in:
parent
b856d26087
commit
077e03678f
|
@ -8,10 +8,10 @@
|
|||
|
||||
class AP_HAL::Stream : public AP_HAL::Print {
|
||||
public:
|
||||
virtual int16_t available() = 0;
|
||||
virtual uint32_t available() = 0;
|
||||
/* NB txspace was traditionally a member of BetterStream in the
|
||||
* 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():
|
||||
* -1 if nothing available, uint8_t value otherwise. */
|
||||
|
|
|
@ -14,8 +14,8 @@ void UARTDriver::set_blocking_writes(bool blocking) {}
|
|||
bool UARTDriver::tx_pending() { return false; }
|
||||
|
||||
/* Empty implementations of Stream virtual methods */
|
||||
int16_t UARTDriver::available() { return 0; }
|
||||
int16_t UARTDriver::txspace() { return 1; }
|
||||
uint32_t UARTDriver::available() { return 0; }
|
||||
uint32_t UARTDriver::txspace() { return 1; }
|
||||
int16_t UARTDriver::read() { return -1; }
|
||||
|
||||
/* Empty implementations of Print virtual methods */
|
||||
|
|
|
@ -15,9 +15,9 @@ public:
|
|||
bool tx_pending();
|
||||
|
||||
/* Empty implementations of Stream virtual methods */
|
||||
int16_t available();
|
||||
int16_t txspace();
|
||||
int16_t read();
|
||||
uint32_t available() override;
|
||||
uint32_t txspace() override;
|
||||
int16_t read() override;
|
||||
|
||||
/* Empty implementations of Print virtual methods */
|
||||
size_t write(uint8_t c);
|
||||
|
|
|
@ -290,7 +290,7 @@ bool UARTDriver::tx_pending()
|
|||
/*
|
||||
return the number of bytes available to be read
|
||||
*/
|
||||
int16_t UARTDriver::available()
|
||||
uint32_t UARTDriver::available()
|
||||
{
|
||||
if (!_initialised) {
|
||||
return 0;
|
||||
|
@ -302,7 +302,7 @@ int16_t UARTDriver::available()
|
|||
/*
|
||||
how many bytes are available in the output buffer?
|
||||
*/
|
||||
int16_t UARTDriver::txspace()
|
||||
uint32_t UARTDriver::txspace()
|
||||
{
|
||||
if (!_initialised) {
|
||||
return 0;
|
||||
|
|
|
@ -25,9 +25,9 @@ public:
|
|||
bool tx_pending();
|
||||
|
||||
/* Linux implementations of Stream virtual methods */
|
||||
int16_t available();
|
||||
int16_t txspace();
|
||||
int16_t read();
|
||||
uint32_t available() override;
|
||||
uint32_t txspace() override;
|
||||
int16_t read() override;
|
||||
|
||||
/* Linux implementations of Print virtual methods */
|
||||
size_t write(uint8_t c);
|
||||
|
|
|
@ -122,18 +122,18 @@ int16_t NSHShellStream::read()
|
|||
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) {
|
||||
return ret;
|
||||
}
|
||||
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) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -236,7 +236,7 @@ bool PX4UARTDriver::tx_pending() { return false; }
|
|||
/*
|
||||
return number of bytes available to be read from the buffer
|
||||
*/
|
||||
int16_t PX4UARTDriver::available()
|
||||
uint32_t PX4UARTDriver::available()
|
||||
{
|
||||
if (!_initialised) {
|
||||
try_initialise();
|
||||
|
@ -249,7 +249,7 @@ int16_t PX4UARTDriver::available()
|
|||
/*
|
||||
return number of bytes that can be added to the write buffer
|
||||
*/
|
||||
int16_t PX4UARTDriver::txspace()
|
||||
uint32_t PX4UARTDriver::txspace()
|
||||
{
|
||||
if (!_initialised) {
|
||||
try_initialise();
|
||||
|
|
|
@ -16,9 +16,9 @@ public:
|
|||
bool tx_pending();
|
||||
|
||||
/* PX4 implementations of Stream virtual methods */
|
||||
int16_t available();
|
||||
int16_t txspace();
|
||||
int16_t read();
|
||||
uint32_t available() override;
|
||||
uint32_t txspace() override;
|
||||
int16_t read() override;
|
||||
|
||||
/* PX4 implementations of Print virtual methods */
|
||||
size_t write(uint8_t c);
|
||||
|
|
|
@ -8,9 +8,9 @@ class PX4::NSHShellStream : public AP_HAL::Stream {
|
|||
public:
|
||||
size_t write(uint8_t);
|
||||
size_t write(const uint8_t *buffer, size_t size);
|
||||
int16_t read();
|
||||
int16_t available();
|
||||
int16_t txspace();
|
||||
int16_t read() override;
|
||||
uint32_t available() override;
|
||||
uint32_t txspace() override;
|
||||
private:
|
||||
int shell_stdin = -1;
|
||||
int shell_stdout = -1;
|
||||
|
|
|
@ -100,7 +100,7 @@ void UARTDriver::end()
|
|||
{
|
||||
}
|
||||
|
||||
int16_t UARTDriver::available(void)
|
||||
uint32_t UARTDriver::available(void)
|
||||
{
|
||||
_check_connection();
|
||||
|
||||
|
@ -111,9 +111,7 @@ int16_t UARTDriver::available(void)
|
|||
return _readbuffer.available();
|
||||
}
|
||||
|
||||
|
||||
|
||||
int16_t UARTDriver::txspace(void)
|
||||
uint32_t UARTDriver::txspace(void)
|
||||
{
|
||||
_check_connection();
|
||||
if (!_connected) {
|
||||
|
|
|
@ -47,9 +47,9 @@ public:
|
|||
}
|
||||
|
||||
/* Implementations of Stream virtual methods */
|
||||
int16_t available();
|
||||
int16_t txspace();
|
||||
int16_t read();
|
||||
uint32_t available() override;
|
||||
uint32_t txspace() override;
|
||||
int16_t read() override;
|
||||
|
||||
/* Implementations of Print virtual methods */
|
||||
size_t write(uint8_t c);
|
||||
|
|
|
@ -230,7 +230,7 @@ bool VRBRAINUARTDriver::tx_pending() { return false; }
|
|||
/*
|
||||
return number of bytes available to be read from the buffer
|
||||
*/
|
||||
int16_t VRBRAINUARTDriver::available()
|
||||
uint32_t VRBRAINUARTDriver::available()
|
||||
{
|
||||
if (!_initialised) {
|
||||
try_initialise();
|
||||
|
@ -243,7 +243,7 @@ int16_t VRBRAINUARTDriver::available()
|
|||
/*
|
||||
return number of bytes that can be added to the write buffer
|
||||
*/
|
||||
int16_t VRBRAINUARTDriver::txspace()
|
||||
uint32_t VRBRAINUARTDriver::txspace()
|
||||
{
|
||||
if (!_initialised) {
|
||||
try_initialise();
|
||||
|
|
|
@ -16,9 +16,9 @@ public:
|
|||
bool tx_pending();
|
||||
|
||||
/* VRBRAIN implementations of Stream virtual methods */
|
||||
int16_t available();
|
||||
int16_t txspace();
|
||||
int16_t read();
|
||||
uint32_t available() override;
|
||||
uint32_t txspace() override;
|
||||
int16_t read() override;
|
||||
|
||||
/* VRBRAIN implementations of Print virtual methods */
|
||||
size_t write(uint8_t c);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
if (_port->txspace() < (size + 5)) {
|
||||
if (_port->txspace() < (size + 5U)) {
|
||||
return;
|
||||
}
|
||||
uint8_t checksum = 0;
|
||||
|
|
Loading…
Reference in New Issue