LCOV - code coverage report
Current view: top level - SITL - SIM_RF_LeddarOne.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 38 38 100.0 %
Date: 2026-09-09 11:02:08 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :    This program is free software: you can redistribute it and/or modify
       3             :    it under the terms of the GNU General Public License as published by
       4             :    the Free Software Foundation, either version 3 of the License, or
       5             :    (at your option) any later version.
       6             : 
       7             :    This program is distributed in the hope that it will be useful,
       8             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10             :    GNU General Public License for more details.
      11             : 
      12             :    You should have received a copy of the GNU General Public License
      13             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      14             :  */
      15             : /*
      16             :   Simulator for the LeddarOne rangefinder
      17             : */
      18             : 
      19             : #include "SIM_RF_LeddarOne.h"
      20             : 
      21             : #include <GCS_MAVLink/GCS.h>
      22             : #include <stdio.h>
      23             : 
      24             : using namespace SITL;
      25             : 
      26         355 : uint32_t RF_LeddarOne::packet_for_alt(float alt_m, uint8_t *buffer, uint8_t buflen)
      27             : {
      28         355 :     const uint8_t response_size = 25;
      29         355 :     const uint16_t internal_temperature = 1245;
      30         355 :     const uint16_t num_detections = 1;
      31         355 :     const uint16_t first_distance = alt_m * 1000;
      32         355 :     const uint16_t first_amplitude = 37;
      33         355 :     const uint16_t second_distance = alt_m * 1000;
      34         355 :     const uint16_t second_amplitude = 37;
      35         355 :     const uint16_t third_distance = alt_m * 1000;
      36         355 :     const uint16_t third_amplitude = 37;
      37         355 :     const uint32_t now = AP_HAL::millis();
      38             : 
      39         355 :     buffer[0] = 0x01;
      40         355 :     buffer[1] = 0x04; // magic function number! LEDDARONE_MODOBUS_FUNCTION_CODE
      41         355 :     buffer[2] = response_size;
      42         355 :     buffer[3] = (now >> 16) & 0xff;
      43         355 :     buffer[4] = (now >> 24) & 0xff;
      44         355 :     buffer[5] = (now >> 0) & 0xff;
      45         355 :     buffer[6] = (now >> 8) & 0xff;
      46         355 :     buffer[7] = internal_temperature & 0xff;
      47         355 :     buffer[8] = internal_temperature >> 8;
      48         355 :     buffer[9] = num_detections >> 8;
      49         355 :     buffer[10] = num_detections & 0xff;
      50         355 :     buffer[11] = first_distance >> 8;
      51         355 :     buffer[12] = first_distance & 0xff;
      52         355 :     buffer[13] = first_amplitude >> 8;
      53         355 :     buffer[14] = first_amplitude & 0xff;
      54         355 :     buffer[15] = second_distance >> 8;
      55         355 :     buffer[16] = second_distance & 0xff;
      56         355 :     buffer[17] = second_amplitude >> 8;
      57         355 :     buffer[18] = second_amplitude & 0xff;
      58         355 :     buffer[19] = third_distance >> 8;
      59         355 :     buffer[20] = third_distance & 0xff;
      60         355 :     buffer[21] = third_amplitude >> 8;
      61         355 :     buffer[22] = third_amplitude & 0xff;
      62             : 
      63         355 :     const uint16_t crc = calc_crc_modbus(buffer, 23);
      64         355 :     buffer[23] = crc & 0xff;
      65         355 :     buffer[24] = crc >> 8;
      66             : 
      67         355 :     return response_size;
      68             : }

Generated by: LCOV version 1.14