Commit Graph

129 Commits

Author SHA1 Message Date
Leandro Pereira e3b676ba89 AP_HAL: Add method to peek non-contiguous parts of a ByteBuffer
Modify ByteBuffer class to have a `peekiovec()` method, that takes in a
`struct IoVec` array (similar to `struct iovec` from POSIX), and a
number of bytes, and returns the number of elements from this array
that have been filled out.  It is either 0 (buffer is empty), 1
(there's enough contiguous bytes to read that amount) or 2 (ring buffer
is wrapping around).

This enables using scatter-gather I/O (i.e. writev()), removing calls
to memcpy().  That's one call when no wrap-around is happening, and
two calls if it is.

Also, rewrite `ByteBuffer::peekbytes()` to use `peekiovec()`, so that
some of the checks performed by the former are not replicated in the
latter.
2016-07-08 13:10:16 -03:00
Andrew Tridgell 595d5c0002 AP_HAL: added set_size() to RingBuffer API 2016-05-23 23:41:02 +10:00
Lucas De Marchi cf11776150 AP_HAL: fix signed and unsigned comparison warning
../../libraries/AP_HAL/examples/Printf/Printf.cpp:63:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (ret != strlen(float_tests[i].result)) {
                 ^
...

ardupilot/modules/gtest/include/gtest/gtest.h:1448:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (expected == actual) {
                ^
And similar ones.
2016-05-04 08:58:37 -03:00
Ricardo de Almeida Gonzaga 5bd034a5a8 Global: start using cmath instead of math.h 2016-04-05 21:06:19 -07:00
Lucas De Marchi 57f8db5672 AP_HAL: sparse-endian: conditionally include byteswap header
This is not present in qurt.
2016-03-23 17:50:38 -03:00
Lucas De Marchi c5dc54dac7 AP_HAL: utility: import sparse-endian header 2016-03-23 17:50:38 -03:00
Andrew Tridgell 2120913ac2 AP_HAL: added ObjectArray template
this is a ring buffer that supports indexing for efficient handling of
queue peeking and manipulation
2016-02-24 09:18:06 +11:00
Tom Pittenger 9718ee23d1 AP_HAL: fix peekbytes casting 2016-02-24 09:18:06 +11:00
Andrew Tridgell 1df2512935 AP_HAL: added update() method for object ringbuffer
to support updating objects for GCS work Tom is doing
2016-02-23 16:34:06 +11:00
Tom Pittenger 1d528d552f AP_HAL: rename RingBuffer.force() to RingBuffer.push_force() 2016-02-21 22:13:27 -08:00
Andrew Tridgell 4ff396dfa8 AP_HAL: added force() and peek() method for object ringbuffers 2016-02-22 12:34:32 +11:00
Lucas De Marchi dbf2aedf1e AP_HAL: replace header guard with pragma once 2016-02-18 14:52:34 -02:00
Lucas De Marchi 10abec277d AP_HAL: functor: use std::remove_reference 2016-02-16 19:49:09 -02:00
Lucas De Marchi 2e60e1b1f2 AP_HAL: utility: Add OwnPtr implementation
This is very similar to std::unique_ptr, but doesn't require including
the <memory> header which pulls lots of c++ headers and cause problems
with nuttx headers. It's header-only. It contains an explanation on what
it solves, how to use and unit tests.
2016-02-16 19:49:08 -02:00
Andrew Tridgell dafc9b4c6b AP_HAL: allow getopt_cpp on QURT
avoid using stderr
2015-12-29 19:10:46 +11:00
Lucas De Marchi 97022a4161 AP_HAL: RingBuffer: fix macro expansion
Fix warning that reveals a real bug:

In file included from libraries/AP_HAL_Linux/UARTDriver.cpp:25:0:
libraries/AP_HAL_Linux/UARTDriver.cpp: In member function 'virtual bool Linux::UARTDriver::tx_pending()':
libraries/AP_HAL/utility/RingBuffer.h:21:35: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
 #define BUF_EMPTY(buf) buf##_head == buf##_tail
                                   ^
libraries/AP_HAL_Linux/UARTDriver.cpp:355:13: note: in expansion of macro 'BUF_EMPTY'
     return !BUF_EMPTY(_writebuf);

The problem is when there's a ! operator: without the parenthesis we would actually be doing

    return !_write_buf_head == _write_buf_tail

which is not what we want.
2015-12-28 21:50:27 -02:00
Andrew Tridgell c90d7dd86e AP_HAL: fixed vprintf segfault 2015-12-28 08:44:40 +11:00
Lucas De Marchi 520b0384fd AP_HAL: remove unused in_progmem flag to print_vprintf 2015-12-27 15:58:12 -02:00
Lucas De Marchi 8e0c125f56 AP_HAL: print_vprintf: follow coding style
- Use 4 spaces to indent
 - Add braces to control statements
 - Don't use tabs
2015-12-27 15:58:12 -02:00
Lucas De Marchi c35730058a AP_HAL: print_vprintf: stop using Progmem.h
Remove the unused support to data from progmem, including the unused %S
format specifier.
2015-12-27 15:58:12 -02:00
Lucas De Marchi 29ed01189d AP_HAL: ftoa_engine: replace tabs with spaces 2015-12-27 15:58:12 -02:00
Lucas De Marchi e751d632e6 AP_HAL: ftoa_engine: stop using Progmem.h 2015-12-27 15:58:12 -02:00
Andrew Tridgell 7c431b40f2 AP_HAL: enable HAL_QURT 2015-12-27 16:21:25 +11:00
Andrew Tridgell cfd54c5683 AP_HAL: moved dsm implementation into AP_HAL/utility 2015-12-27 16:12:27 +11:00
Andrew Tridgell ec6a679482 AP_HAL: added ByteBuffer and ObjectBuffer in RingBuffer
much better API than old macros
2015-12-20 07:33:54 +11:00
Lucas De Marchi d19c5035b6 Global: Rename printf format attribute
As commented in 8218140 ("AP_Common: add scanf format macro"), "FORMAT"
was a bad name for this macro since there's also the scanf. Rename to
FMT_PRINTF to follow the scanf name.
2015-12-01 07:22:12 +11:00
Lucas De Marchi 5244559010 Minimize AP_Progmem.h includes
Most of AP_Progmem is already gone so we can stop including it in most
of the places. The only places that need it are the ones using
pgm_read_*() APIs.

In some cases the header needed to be added in the .cpp since it was
removed from the .h to reduce scope. In those cases the headers were
also reordered.
2015-10-30 14:35:32 +09:00
Lucas De Marchi a65c98485c AP_HAL: UARTDriver: remove _P() variants
They aren't used anymore so remove.
2015-10-30 14:35:31 +09:00
Lucas De Marchi 1b07dabeb7 Replace prog_char and prog_char_t with char
prog_char and prog_char_t are now the same as char on supported
platforms. So, just change all places that use them and prefer char
instead.

AVR-specific places were not changed.
2015-10-30 14:35:30 +09:00
Lucas De Marchi 2556fc8dbe BetterStream: use common macro for printf formatting
Since this needs an additional header, also put them in correct order.
2015-10-30 14:35:26 +09:00
Lucas De Marchi 831d8acca5 Remove use of PROGMEM
Now variables don't have to be declared with PROGMEM anymore, so remove
them. This was automated with:

    git grep -l -z PROGMEM | xargs -0 sed -i 's/ PROGMEM / /g'
    git grep -l -z PROGMEM | xargs -0 sed -i 's/PROGMEM//g'

The 2 commands were done so we don't leave behind spurious spaces.

AVR-specific places were not changed.
2015-10-30 14:35:16 +09:00
Lucas De Marchi 0aa117f65d Replace use of strnlen_P() with strnlen() 2015-10-30 14:35:13 +09:00
Lucas De Marchi 2c38e31c93 Remove use of PSTR
The PSTR is already define as a NOP for all supported platforms. It's
only needed for AVR so here we remove all the uses throughout the
codebase.

This was automated with a simple python script so it also converts
places which spans to multiple lines, removing the matching parentheses.

AVR-specific places were not changed.
2015-10-30 14:35:04 +09:00
Lucas De Marchi ca17b6155e AP_HAL: standardize inclusion of libaries headers
Do the missing header changes due to changing the code before the pr
getting accepted.
2015-08-18 17:12:51 +10:00
Gustavo Jose de Sousa 0456eccca8 AP_HAL: standardize inclusion of libaries headers
This commit changes the way libraries headers are included in source files:

 - If the header is in the same directory the source belongs to, so the
 notation '#include ""' is used with the path relative to the directory
 containing the source.

 - If the header is outside the directory containing the source, then we use
 the notation '#include <>' with the path relative to libraries folder.

Some of the advantages of such approach:

 - Only one search path for libraries headers.

 - OSs like Windows may have a better lookup time.
2015-08-11 16:28:43 +10:00
Andrew Tridgell eca0940bc7 AP_HAL: allow for broadcast packets on UDP IPv4 2015-07-29 16:46:33 +10:00
Andrew Tridgell 3e4b0b9869 AP_HAL: added pollout() function to socket API 2015-07-29 14:19:46 +10:00
Andrew Tridgell 596ecde70d AP_HAL: added listen and accept APIs to socket API 2015-07-29 09:07:41 +10:00
Andrew Tridgell b07f7e873f AP_HAL: added pollin() interface for Socket API 2015-07-29 08:58:02 +10:00
Andrew Tridgell 5067359ed7 AP_HAL: fixed socket destructor 2015-07-29 08:39:16 +10:00
Staroselskii Georgii 1a588263e4 AP_HAL: added destructor for Socket 2015-07-29 08:34:43 +10:00
Staroselskii Georgii 4411c1fed4 AP_HAL: improved constness of Socket API 2015-07-29 08:24:24 +10:00
Andrew Tridgell 4dd47ead0e AP_HAL: removed old fastdelegate code 2015-06-01 15:18:30 +10:00
Andrew Tridgell ac3fc2f373 AP_HAL: fixed build warnings 2015-05-30 22:51:09 +10:00
Andrew Tridgell 4705be97bf AP_HAL: support %lld and %llu in internal printf
useful for log messages with 64 bit timestamps
2015-05-27 11:54:17 +10:00
Lucas De Marchi 83efb9280b AP_HAL: use variadic templates in FastDelegate
Now that we are using C++11 we can use variadic templates to simplify
the FastDelegate classes. It also simplifies moving away from the
FastDelegate implementation.
2015-05-26 13:46:51 +10:00
Lucas De Marchi a1e1503e1a AP_HAL: Add Functor implementation
This is a Functor implementation that should cover the use cases we have
for FastDelegate. In contrary to the latter, it can be constructed at
compile time so the compiler can safely put it in a read-only section
which covers the cases in which we are not using it.
2015-05-26 13:46:49 +10:00
Andrew Tridgell 9336914598 AP_HAL: added sendto socket method 2015-05-22 16:07:44 +10:00
Andrew Tridgell be587beedc AP_HAL: disable nagle on sockets for faster local operation 2015-05-21 07:48:45 +10:00
Andrew Tridgell 414f4125de AP_HAL: use FD_CLOEXEC to prevent sockets being inherited in SITL 2015-05-11 08:05:51 +10:00
Andrew Tridgell 692fc18698 AP_HAL: protect Socket.h from double include 2015-05-10 21:02:04 +10:00
Tom Pittenger 4b6d0d8e24 AP_HAL: replace fabs() with fabsf() 2015-05-09 09:57:26 +10:00
Andrew Tridgell 2369e06815 AP_HAL: fixed SITL build on windows 2015-05-06 09:07:03 +10:00
Andrew Tridgell 08b9ed3342 AP_HAL: added socket handling class 2015-05-05 21:34:19 +10:00
Andrew Tridgell 35d22b9d57 AP_HAL: added getopt_cpp class
a simple port of getopt_long to C++
2015-05-05 09:45:58 +10:00
Grant Morphett 525787078f AP_HAL: Changes to fix the warnings in rover sitl build.
We are starting the process of resolving all the warnings in the
ardupilot builds of all vehicles and platforms.
2015-02-11 18:16:45 +11:00
Andrew Tridgell 6fb00f4fc3 AP_HAL: create a common utility/RingBuffer.h header 2015-01-07 08:41:14 +11:00
Andrew Tridgell 74227cd7f0 AP_HAL: prevent some FastDelegate warnings 2014-05-08 11:11:03 +10:00
Andrew Tridgell efe1e01700 AP_HAL: require a buffer write() function in all ports
this makes a sufficient performance difference that it is worth it
2013-10-03 12:21:07 +10:00
Andrew Tridgell f2de4bb7b0 AP_HAL: implement AP_HAL::MemberProc via FastDelegate.h
this provides a more portable way to encapsulate member functions in
variables
2013-09-30 20:51:13 +10:00
Andrew Tridgell 0e9aef7e52 AP_HAL: changed base defines for print()
this avoids a conflict with wirish from libmaple
2013-09-23 18:10:21 +10:00
Andrew Tridgell 928e06f52c AP_HAL: use fabs() in print
fixes build on Arduino
2013-09-22 13:18:40 +10:00
Andrew Tridgell 0d662c52b3 AP_HAL: fixed length return from snprintf 2013-09-21 15:45:05 +10:00
Andrew Tridgell 60122f9877 AP_HAL: moved printf implementation from AP_HAL_AVR to AP_HAL
this gives a common printf implementation on all boards, which
simplifies testing, and also simplifies porting to new boards
2013-09-21 13:28:46 +10:00
Andrew Tridgell 97b7130bb9 libraries: update license header to GPLv3
we switched to GPLv3 a long time ago, but neglected to update the
per-file license headers
2013-08-30 13:01:39 +10:00
Tobias d3ea88e8c7 AP_HAL: resolved -Woverloaded-virtual warning
the function:
virtual size_t AP_HAL::Print::write(const uint8_t *buffer, size_t size);

was hidden in all derived classes by their
virtual size_t write(uint8_t) = 0; implementations.

To solve this, a non-virtual write(const uint8_t *, size_t) that calls a
virtual write_implementation was added.

This isn't necessary atm, because the derived classes don't call
write(const uint8_t *, size_t), BUT this decreases the apm2-quad Program
size by 40 bytes :D and removes warnings.
2013-07-08 12:17:34 +10:00
Andrew Tridgell 76092eb590 AP_HAL: remove unused peek() interface from UART drivers
this is a bit tricky to implement on some platforms, and is unused
anyway
2013-01-16 14:43:18 +11:00
James Bielman 4fa7bb1486 Add AVR compatibility header for missing math.h definitions.
- Define float versions of math functions to the double versions
  on AVR (eg. #define sinf sin).
- These macros appear to be missing in older versions of avr-libs.
- Include AP_Math.h rather than math.h to get these definitions.
2013-01-16 13:52:17 +11:00
James Bielman 5631f865b2 Update floating point calculations to use floats instead of doubles.
- Allows use of hardware floating point on the Cortex-M4.
- Added "f" suffix to floating point literals.
- Call floating point versions of stdlib math functions.
2013-01-16 13:52:01 +11:00
Andrew Tridgell ba1a6eb073 AP_HAL: fixed SITL build 2013-01-02 14:48:15 +11:00
Pat Hickey 7681fef988 AP_HAL: BetterStream gets vprintf and vprintf_P methods 2012-12-20 14:53:22 +11:00
Pat Hickey 243590bb73 AP_HAL: UARTDriver & Stream uses only sized int types
Signed-off-by: Pat Hickey <pat@galois.com>
2012-12-20 14:51:33 +11:00
Pat Hickey 3bca50f422 AP_HAL: BetterStream removes printf attribute from _printf_P 2012-12-20 14:51:33 +11:00
Pat Hickey a399851ca2 AP_HAL: Depend on AP_Progmem rather than AP_Common to provide pstr 2012-12-20 14:51:28 +11:00
Andrew Tridgell 87e300b119 AP_HAL: added double print functions
this copes with the fact that the compiler doesn't really know that
float and double are the same things
2012-12-20 14:51:27 +11:00
Pat Hickey 36154559fc AP_HAL: change txspace from a BetterStream method to a Stream method. 2012-12-20 14:51:24 +11:00
Pat Hickey 8eb9b39a44 AP_HAL_AVR move library classes to their own AP_HAL_AVR namespace 2012-12-20 14:51:19 +11:00
Pat Hickey afd1f36400 AP_HAL: add BetterStream, Stream, and Print interfaces
* BetterStream Means AP_HAL depends on AP_Common, for now, in order to have
  the AVR specific pgm_char_t defined.
  I'll need to factor that out in the future but for now it can stay
2012-12-20 14:51:19 +11:00
Pat Hickey 29a425c0dd AP_HAL: import utility Print, Stream, and BetterStream headers 2012-12-20 14:51:18 +11:00