LCOV - code coverage report
Current view: top level - SITL - SIM_RF_Ainstein_LR_D1.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 26 27 96.3 %
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 Ainstein LR-D1 Serial rangefinder
      17             : */
      18             : 
      19             : #include "SIM_RF_Ainstein_LR_D1.h"
      20             : 
      21             : using namespace SITL;
      22             : 
      23        2171 : uint32_t RF_Ainstein_LR_D1::packet_for_alt(float alt_m, uint8_t *buffer, uint8_t buflen)
      24             : {
      25        2171 :     const uint8_t PACKET_LEN = 32;
      26             : 
      27        2171 :     if (buflen < PACKET_LEN) {
      28           0 :         return 0;
      29             :     }
      30             : 
      31        2171 :     uint8_t malfunction_alert = 0;
      32             : 
      33        2171 :     uint16_t alt_cm = alt_m * 100;
      34             : 
      35        2171 :     uint8_t snr = (alt_cm == 0xFFFF) ? 0 : 100;
      36        2171 :     if (alt_m > 525) {
      37             :         // overheats at 525 metres:
      38         318 :         malfunction_alert |= 1U << 0;
      39             :     }
      40        2171 :     if (alt_m > 500) {
      41             :         // out of range @500m
      42         366 :         snr = 0;
      43             :     }
      44        2171 :     if (alt_m*100 > 65535) {
      45         109 :         malfunction_alert |= 1U << 7;  // AltitudeReading alert
      46             :     }
      47             : 
      48        2171 :     buffer[0] = 0xEB;  // packet header msb
      49        2171 :     buffer[1] = 0x90;  // packet header lsb
      50        2171 :     buffer[2] = 0;  // device_id
      51        2171 :     buffer[3] = 28;  // length
      52        2171 :     buffer[4] = malfunction_alert;
      53        2171 :     buffer[5] = 1;  // object count
      54        2171 :     buffer[6] = HIGHBYTE(alt_cm);
      55        2171 :     buffer[7] = LOWBYTE(alt_cm);
      56        2171 :     buffer[8] = snr;
      57        2171 :     buffer[9] = 0;  // speed high
      58        2171 :     buffer[10] = 0;  // speed low
      59        2171 :     memset(&buffer[11], 0xff, 20); // unused
      60        2171 :     buffer[31] = crc_sum_of_bytes(&buffer[3], PACKET_LEN-4); // minus headerMSB, headerLSB, device_id and checksum
      61             : 
      62        2171 :     return PACKET_LEN;
      63             : }

Generated by: LCOV version 1.14