LCOV - code coverage report
Current view: top level - AP_PiccoloCAN - AP_PiccoloCAN_Device.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 7 0.0 %
Date: 2026-09-09 11:02:08 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /*
       2             :  * This file is free software: you can redistribute it and/or modify it
       3             :  * under the terms of the GNU General Public License as published by the
       4             :  * Free Software Foundation, either version 3 of the License, or
       5             :  * (at your option) any later version.
       6             :  *
       7             :  * This file is distributed in the hope that it will be useful, but
       8             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
       9             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      10             :  * See the GNU General Public License for more details.
      11             :  *
      12             :  * You should have received a copy of the GNU General Public License along
      13             :  * with this program.  If not, see <http://www.gnu.org/licenses/>.
      14             :  *
      15             :  * Author: Oliver Walters / Currawong Engineering Pty Ltd
      16             :  */
      17             : 
      18             : #pragma once
      19             : 
      20             : #include "AP_PiccoloCAN_config.h"
      21             : 
      22             : #if AP_PICCOLOCAN_ENABLED
      23             : 
      24             : #include <stdint.h>
      25             : #include <AP_HAL/AP_HAL.h>
      26             : #include <AP_CANManager/AP_CANManager.h>
      27             : 
      28             : //! Piccolo message groups form part of the CAN ID of each frame
      29             : enum class PiccoloCAN_MessageGroup : uint8_t {
      30             :     SIMULATOR = 0x00,       //!< Simulator messages
      31             :     SENSOR = 0x04,          //!< External sensors
      32             :     ACTUATOR = 0x07,        //!< Actuators (e.g. ESC / servo)
      33             :     ECU_OUT = 0x08,         //!< Messages *from* an ECU
      34             :     ECU_IN = 0x09,          //!< Message *to* an ECU
      35             : 
      36             :     BATTERY = 0x1A,         //!< Battery / generator messages
      37             :     SYSTEM = 0x19,          //!< System messages (e.g. bootloader)
      38             : };
      39             : 
      40             : //! Piccolo device type descriminators
      41             : enum class PiccoloCAN_DeviceType : uint8_t {
      42             :     SERVO = 0x00,
      43             :     ESC = 0x20,
      44             :     CORTEX_LEGACY=0x33,
      45             :     CORTEX_HYBRID=0x34,
      46             :     CORTEX_CHPS = 0x35,
      47             : };
      48             : 
      49             : 
      50             : /*
      51             :  * Generic PiccoloCAN device class implementation
      52             :  */
      53             : 
      54             : class AP_PiccoloCAN_Device
      55             : {
      56             : public:
      57             :     virtual bool handle_can_frame(AP_HAL::CANFrame &frame) = 0;
      58             : 
      59             :     // Determine if this device is "enabled" (default implementation returns false)
      60           0 :     virtual bool is_enabled(void) const { return false; }
      61             : 
      62             :     // Determine if this device has been seen within a specified timeframe
      63           0 :     virtual bool is_connected(uint32_t timeout_us) const {
      64           0 :         uint64_t now = AP_HAL::micros64();
      65             : 
      66           0 :         return now < (last_msg_timestamp + timeout_us);
      67             :     }
      68             : 
      69             :     // Reset the received message timestamp
      70           0 :     void reset_rx_timestamp() {
      71           0 :         last_msg_timestamp = AP_HAL::micros64();
      72           0 :     }
      73             : 
      74             :     //! Timestamp of most recently received CAN message
      75             :     uint64_t last_msg_timestamp = 0;
      76             : };
      77             : 
      78             : #endif // AP_PICCOLOCAN_ENABLED

Generated by: LCOV version 1.14