LCOV - code coverage report
Current view: top level - AP_PiccoloCAN - AP_PiccoloCAN_Cortex.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 22 0.0 %
Date: 2026-09-09 11:02:08 Functions: 0 5 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             : #include "AP_PiccoloCAN_Cortex.h"
      19             : 
      20             : #if AP_PICCOLOCAN_ENABLED
      21             : 
      22             : // Protocol files for the Cortex controller
      23             : #include <AP_PiccoloCAN/piccolo_protocol/CortexDefines.h>
      24             : #include <AP_PiccoloCAN/piccolo_protocol/CortexPackets.h>
      25             : #include <AP_PiccoloCAN/piccolo_protocol/CortexProtocol.h>
      26             : 
      27             : /**
      28             :  * PiccoloCAN glue logic
      29             :  */
      30             : 
      31             : //! \return the packet data pointer from the packet
      32           0 : uint8_t* getCortexPacketData(void* pkt)
      33             : {
      34           0 :     AP_HAL::CANFrame* frame = (AP_HAL::CANFrame*) pkt;
      35             : 
      36           0 :     return (uint8_t*) frame->data;
      37             : }
      38             : 
      39             : //! \return the packet data pointer from the packet, const
      40           0 : const uint8_t* getCortexPacketDataConst(const void* pkt)
      41             : {
      42           0 :     AP_HAL::CANFrame* frame = (AP_HAL::CANFrame*) pkt;
      43             : 
      44           0 :     return (const uint8_t*) frame->data;
      45             : }
      46             : 
      47             : //! Complete a packet after the data have been encoded
      48           0 : void finishCortexPacket(void* pkt, int size, uint32_t packetID)
      49             : {
      50           0 :     AP_HAL::CANFrame* frame = (AP_HAL::CANFrame*) pkt;
      51             : 
      52           0 :     if (size > AP_HAL::CANFrame::MaxDataLen) {
      53           0 :         size = AP_HAL::CANFrame::MaxDataLen;
      54             :     }
      55             : 
      56           0 :     frame->dlc = size;
      57             : 
      58             :     /* Encode the CAN ID
      59             :      * 0x1Ammddii
      60             :      * - 1A = Battery group ID
      61             :      * - mm = Message ID
      62             :      * - dd = Cortex device type
      63             :      * - ii = Device ID
      64             :      *
      65             :      * Note: The Device type and node ID (lower 16 bits of the frame ID) will be inserted later
      66             :      */
      67             : 
      68           0 :     uint32_t id = (((uint8_t) PiccoloCAN_MessageGroup::BATTERY) << 24) |    // CAN Group ID
      69           0 :                   ((packetID & 0xFF) << 16);                                // Message ID
      70             : 
      71             :     // Extended frame format
      72           0 :     id |= AP_HAL::CANFrame::FlagEFF;
      73             : 
      74           0 :     frame->id = id;
      75           0 : }
      76             : 
      77             : //! \return the size of a packet from the packet header
      78           0 : int getCortexPacketSize(const void* pkt)
      79             : {
      80           0 :     AP_HAL::CANFrame* frame = (AP_HAL::CANFrame*) pkt;
      81             : 
      82           0 :     return (int) frame->dlc;
      83             : }
      84             : 
      85             : //! \return the ID of a packet from the packet header
      86           0 : uint32_t getCortexPacketID(const void* pkt)
      87             : {
      88           0 :     AP_HAL::CANFrame* frame = (AP_HAL::CANFrame*) pkt;
      89             : 
      90             :     // Extract the message ID field from the 29-bit ID
      91           0 :     return (uint32_t) ((frame->id >> 16) & 0xFF);
      92             : }
      93             : 
      94             : #endif // AP_PICCOLOCAN_ENABLED

Generated by: LCOV version 1.14