LCOV - code coverage report
Current view: top level - SITL - SIM_RF_NoopLoop.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 24 24 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             :   Base class for simulator for the NoopLoop TOFSense-F/P Serial RangeFinders
      17             : */
      18             : 
      19             : #include "SIM_RF_NoopLoop.h"
      20             : 
      21             : using namespace SITL;
      22             : 
      23         355 : uint32_t RF_Nooploop::packet_for_alt(float alt_m, uint8_t *buffer, uint8_t buflen)
      24             : {
      25             :     // the NoopLoop driver considers a value of zero invalid and won't
      26             :     // consider it a reading, so you end up with no readings at all
      27             :     // from the driver.  Fudge it here:
      28         355 :     uint16_t alt_cm = alt_m * 100;
      29         355 :     if (alt_cm == 0) {
      30         258 :         alt_cm = 1;
      31             :     }
      32             : 
      33         355 :     int32_t alt_scaled = 2560*alt_cm;
      34         355 :     buffer[0] = 0x57;
      35         355 :     buffer[1] = 0x00;
      36         355 :     buffer[2] = 0xff;
      37         355 :     buffer[3] = 0x00;
      38         355 :     buffer[4] = 0x9e;
      39         355 :     buffer[5] = 0x8f;
      40         355 :     buffer[6] = 0x00;
      41         355 :     buffer[7] = 0x00;
      42         355 :     buffer[8] = alt_scaled >> 8 & 0xff;
      43         355 :     buffer[9] = alt_scaled >> 16 & 0xff;
      44         355 :     buffer[10] = alt_scaled >> 24 & 0xff;
      45         355 :     buffer[11] = 0x00;
      46         355 :     buffer[12] = 0x03;
      47         355 :     buffer[13] = 0x00;
      48         355 :     buffer[14] = 0x06;
      49             : 
      50             :     // calculate checksum:
      51         355 :     buffer[15] = 0;
      52        5680 :     for (uint8_t i=0; i<15; i++) {
      53        5325 :         buffer[15] += buffer[i];
      54             :     }
      55         355 :     return 16;
      56             : }

Generated by: LCOV version 1.14