Commit Graph
67 Commits
Author SHA1 Message Date
Thomas Watson 0acec1da17 AP_CANManager: drop problematic log_text method
This functionality was approximately never used when it existed as an
`@SYS` file, and has been a source of dangerous bugs.

Remove it completely to avoid future problems and save the flash.

The parameter must stay to control handling of `LogMessage` from
peripherals, which were always sent to the GCS.
2026-05-18 20:58:47 -05:00
Thomas Watson 9b5f6243bd AP_CANManager: drop CAN log message calls
The infrastructure for these has been continually buggy and rarely used.

Delete calls in preparation for ripping it out entirely.
2026-05-18 20:58:47 -05:00
Thomas Watson 6afd09dd62 AP_CANManager: disable log_text by default
This functionality was approximately never used when it existed as an
`@SYS` file, so compile it out so it does not suddenly appear.

The parameter must stay to control handling of `LogMessage` from
peripherals, which were always sent to the GCS.
2026-05-18 20:58:47 -05:00
bugobliterator 41ba547db8 AP_CANManager: send log_text via GCS instead of buffered log
Replace the in-memory _log_buf with GCS_SEND_TEXT, mapping LogLevel
to MAV_SEVERITY. Drop log_retrieve() and the LOG_BUFFER_SIZE buffer
that backed @SYS/can_log.txt.

Statustexts are mirrored to the onboard log by GCS itself, so no
explicit AP_Logger::Write_Message call is needed here.
2026-05-18 20:58:47 -05:00
Thomas Watson edca856684 AP_CANManager: fix heap corruption when CAN log buffer fills
Once the CAN log buffer gets near to full, the check for remaining space
can pass even though there is insufficient space left in the buffer
for the actual log message after formatting.

The space for the tag is correctly measured, so the `snprintf` will
never perform a short write. However, the `vsnprintf` will. Though it
does not write too much, it pushes `_log_pos` past the end of the buffer
as it returns the amount that would be written, rather than the amount
that actually was written.

In this case, the test on the next call of the function aims to reset
`_log_pos` to the start. Unfortunately, as that variable is unsigned,
the subtraction from `LOG_BUFFER_SIZE` will result in a large positive
number, falsely stating that there is enough space. This will also then
give the `snprintf` and `vsnprintf` a large positive space for them to
write into, so they will write past the end of the buffer and corrupt
the heap and crash the system.

Fix by making the variable and comparison properly signed. This will
give a problem if log messages get into the billions of characters, but
this is unlikely to occur.
2026-05-18 20:58:47 -05:00
Peter Barker 2f82b1c9db AP_CANManager: use normal layout for our enable defines for piccolocan, rename to AP_ namespace 2026-01-11 17:32:48 -06:00
Thomas Watson 51b6796124 AP_CANManager: drop CAN interface alternate mode support
Only "NormalMode" was ever used; the others had rotted or were never
implemented.
2025-11-11 10:58:43 +11:00
Thomas Watson de1dbe974a AP_CANManager: remove CAN filter support from drivers 2025-11-11 10:58:43 +11:00
Thomas Watson d288c658eb AP_CANManager: drop CAN filter support from HAL
Has been unused since the removal of libuavcan.
2025-11-11 10:58:43 +11:00
bugobliterator 0ba6e570d3 AP_CANManager: create a new class for MAVLink CAN 2025-05-06 14:19:12 +10:00
bugobliterator f9a8d9b034 AP_CANManager: use updated frame callback types
also change to IsForwardedFrame from IsMAVCAN
2025-02-05 10:23:46 +11:00
Peter Barker 5e6cbc0c63 AP_CANMananger: fix awful defaulting of AP_CAN_LOGGING_ENABLED 2025-01-07 12:39:42 +11:00
Andrew Tridgell 322b7520de AP_CANManager: fixed critical race in log_text()
the AP_CANManager::log_text() gets called from debug logging in
AP_DroneCAN. It is a method on a common AP_CANManager object which is
shared by multiple AP_DroneCAN threads.

if two threads call the debug log messages at the same time then we
can end up with _log_pos greater than LOG_BUFFER_SIZE (1024) and
overwrite past the end of the buffer

in the crash_dump we have for this case the next piece of memory was
hal.can[0], and the overwrite of the buffer had corrupted the
MessageRam_ structurre in the ChibiOS CAN interface code. That led to
a hardfault on receive of a CAN message

Note that this issue only happens if CAN_LOGLEVEL is set to greater
than zero, and the default is zero. So users can avoid the bug by
checking they have not changed CAN_LOGLEVEL.

Also, this is likely an issue that only happens on startup, as once
the two AP_DroneCAN threads are fully running they have the same
thread priority so can't pre-empt each other. During startup some
messages are sent from the main thread which has a different priority
to the AP_DroneCAN threads, and can thus trigger this issue
2024-12-14 15:41:38 +11:00
Andrew Tridgell c2864b5733 AP_CANManager: support CAN frame logging
this supports logging of all bxCAN and CANFD frames, which helps with
debugging tricky CAN support issues and for the development of new CAN
driver lua scripts
2024-12-11 08:43:56 +11:00
Andrew Tridgell 89c2b48286 AP_CANManager: ensure we only remove our own fwd registrations
keep a record of which bus we have registered a callback for and only
unregister with that bus. This prevents us unregistering a multicast
callback when disconnecting from MAVCAN
2024-09-23 21:01:22 +10:00
Andrew Tridgell b98c7c5296 AP_CANManager: fixed de-registering CAN forwarding
this prevented MissionPlanner MAVCAN UI from working reliably as the
CANManager could think we are registered when we are not
2024-09-23 21:01:22 +10:00
Andrew Tridgell cc930bd49f AP_CANManager: update for new callback API 2024-09-17 10:02:29 +10:00
Peter Barker a0ac6f22df AP_CANManager: use a switch statement to tidy driver allocation 2024-07-25 11:09:07 +10:00
Andrew Tridgell 02456875e7 AP_CANManager: use NEW_NOTHROW for new(std::nothrow) 2024-06-04 09:20:21 +10:00
Peter Barker 9120c1e324 AP_CANManager: correct includes
neither of these headers are used in this file
2024-03-20 18:45:52 +11:00
Peter Barker 5cd18dbc45 AP_CANManager: remove redundant calls to snprintf
these only differ by the constant substring, so pull that out as a variable
2024-03-16 22:45:14 +11:00
Andrew Tridgell d17a1ca7bc AP_CANManager: support CAN_Dn_PROTOCOL2 for an aux 11 bit protocol 2023-11-28 11:38:16 +11:00
Thomas Watson de26095c58 AP_CANManager: use get_HAL_mutable() to install new CAN interfaces
Avoids dubious const_casting.
2023-11-28 08:24:25 +11:00
Mykhailo Kuznietsov 5e9b88cf9f AP_CANManager: Fix some typos
Fixed some typos found in the code.
2023-10-12 18:30:42 +11:00
Peter Barker 3c93fd3c5f AP_CANManager: handle CAN_FORWARD as both command_INT and COMMAND_LONG 2023-09-20 17:50:56 +10:00
Peter Barker ffe46b760e AP_CANManager: allow more libraries to compile with no HAL_GCS_ENABLED 2023-09-05 22:23:51 +10:00
Andrew Tridgell 0a04043c4c AP_CANManager: allow SITL CAN with speedup 2023-08-24 13:06:40 +10:00
Andrew Tridgell b55c1d7193 AP_CANManager: removed native_millis/micros 2023-08-24 13:06:40 +10:00
Peter Barker fea2c8d923 AP_CANManager: move and rename CAN Driver_Type enumeration 2023-04-20 08:53:46 +10:00
Peter Barker b055b67a7f AP_CANManager: remove CANTester 2023-04-18 11:43:58 +10:00
Tom Pittenger 2bbd7d8d91 AP_CANManager: set _driver_type_cache for *all* ifaces 2023-04-17 11:52:52 +10:00
Tom Pittenger eed3cf3255 AP_CANManager: promote KDECAN to a first-class library 2023-04-17 11:52:52 +10:00
Andrew Tridgell 33df480f87 AP_CANManager: rename more variables, types and defines 2023-04-11 10:31:31 +10:00
Andrew Tridgell d59e881301 AP_CANManager: fixed MAVCAN fwding flag
this caused corruption due to multiple frames
2023-04-10 14:46:54 +10:00
Andrew Tridgell dbe91670a9 AP_CANManager: rename AP_UAVCAN to AP_DroneCAN 2023-04-08 07:11:23 +10:00
bugobliterator 44e897cf2d AP_CANManager: setup CANManager for DroneCAN Driver tests 2023-03-29 17:16:39 +11:00
bugobliterator 7e660c2e74 AP_CANManager: replace libuavcan with libcanard based driver 2023-03-29 17:16:39 +11:00
Peter Barker c1c8158687 AP_CANManager: add and use option to compile SLCAN support out of code 2023-03-15 19:08:09 +11:00
Andrew Tridgell 6bff28d5d5 AP_CANManager: check for alloc failure of ObjectBuffer 2023-01-08 15:11:32 +11:00
Andrew Tridgell 34bb5e10cd AP_CANManager: add an output buffer for MAVCAN
this fixes firmware update of peripheral nodes using MAVCAN
2022-11-30 20:06:13 +11:00
Peter Barker 23dd4f54df AP_CANManager: remove GCS.h from library header files 2022-11-16 18:29:07 +11:00
Peter Barker 6cf2136691 AP_CANManager: change namespace of MultiCopter and FixedWing params
this stops the libraries knowing anything about AP_Vehicle
2022-11-09 19:04:37 +11:00
Randy Mackay 533a16287e AP_CANManager: remove ToshibaCAN support 2022-06-10 12:08:05 +09:00
Andrew Tridgell 6320599404 AP_CANManager: support mavcan with CANFD_FRAME 2022-03-11 18:13:54 +11:00
bugobliterator c0188fbf0e AP_CANManager: disable CANTester by default 2022-03-11 18:13:54 +11:00
bugobliterator cb1bc4e613 AP_CANManager: add support for enabling CANFD 2022-03-11 18:13:54 +11:00
Andrew Tridgell 454879e638 AP_CANManager: include hal.h 2022-02-22 12:13:19 +11:00
Andrew Tridgell c94c9d8859 AP_CANManager: added CAN_FRAME filter handling 2022-02-19 18:24:56 +11:00
Andrew Tridgell 6e83633a12 AP_CANManager: moved CAN_FRAME timeout code to CANManager 2022-02-19 18:24:56 +11:00
Andrew Tridgell 0b95272f27 AP_CANManager: support mavcan message forwarding 2022-02-12 16:36:05 +11:00