LCOV - code coverage report
Current view: top level - SITL - SIM_CRSF.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 32 0.0 %
Date: 2026-09-09 11:02:08 Functions: 0 2 0.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 CRSF telemetry
      17             : */
      18             : 
      19             : #include "SIM_config.h"
      20             : 
      21             : #if AP_SIM_CRSF_ENABLED
      22             : 
      23             : #include "SIM_CRSF.h"
      24             : 
      25             : using namespace SITL;
      26             : 
      27             : extern const AP_HAL::HAL& hal;
      28             : 
      29           0 : const char *CRSF::dataid_string(DataID id, ssize_t& len)
      30             : {
      31           0 :     switch (id) {
      32           0 :         case DataID::VTX_FRAME: {
      33             :             static const uint8_t vtx_frame[] = { 0xC8, 0x8, 0xF, 0xCE, 0x30, 0x8, 0x16, 0xE9, 0x0, 0x5F }; // VTX
      34           0 :             len = sizeof(vtx_frame);
      35           0 :             return (const char*)vtx_frame;
      36             :         }
      37             :             break;
      38           0 :         case DataID::VTX_TELEM: {
      39             :             static const uint8_t vtx_frame[] = { 0xC8, 0x7, 0x10, 0xCE, 0xE, 0x16, 0x65, 0x0, 0x1B }; // VTX Telem
      40           0 :             len = sizeof(vtx_frame);
      41           0 :             return (const char*)vtx_frame;
      42             :         }
      43             :             break;
      44           0 :         case DataID::VTX_UNKNOWN: {
      45             :             static const uint8_t vtx_frame[] = { 0xC8, 0x9, 0x8, 0x0, 0x9E, 0x0, 0x0, 0x0, 0x0, 0x0, 0x95}; // Battery 15.8v
      46           0 :             len = sizeof(vtx_frame);
      47           0 :             return (const char*)vtx_frame;
      48             :         }
      49           0 :         default:
      50           0 :             break;
      51             :     }
      52             : 
      53           0 :     return "UNKNOWN";
      54             : }
      55             : 
      56           0 : void CRSF::update()
      57             : {
      58           0 :     const ssize_t n = read_from_autopilot(&_buffer[_buflen], ARRAY_SIZE(_buffer) - _buflen - 1);
      59           0 :     if (n != -1) {
      60           0 :         _buflen += n;
      61             :     }
      62             : 
      63             :     // update every 400ms
      64           0 :     uint32_t now = AP_HAL::millis();
      65           0 :     if (now - _last_update_ms < 400) {
      66           0 :         return;
      67             :     }
      68             : 
      69           0 :     _last_update_ms = now;
      70             : 
      71           0 :     ssize_t len = 0;
      72           0 :     ssize_t index = 0;
      73           0 :     const char* bytes = dataid_string(DataID(_id), len);
      74             : 
      75           0 :     while (len > 0) {
      76           0 :         const ssize_t nwrite = write_to_autopilot(&bytes[index], len);
      77           0 :         len -= nwrite;
      78           0 :         index += nwrite;
      79             :     }
      80             : 
      81           0 :     _id = (_id + 1) % MAX_DATA_FRAMES;
      82             : 
      83           0 :     if (_buflen == 0) {
      84           0 :         return;
      85             :     }
      86             : }
      87             : 
      88             : #endif  // AP_SIM_CRSF_ENABLED

Generated by: LCOV version 1.14