LCOV - code coverage report
Current view: top level - AP_ADSB/sagetech-sdk - sgEncodeTargetReq.c (source / functions) Hit Total Coverage
Test: lcov.info Lines: 19 19 100.0 %
Date: 2026-09-09 11:02:08 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /**
       2             :  * @copyright Copyright (c) 2021 Sagetech, Inc. All rights reserved.
       3             :  *
       4             :  * @file   sgEncodeTargetReq.c
       5             :  * @author Jacob.Garrison
       6             :  *
       7             :  * @date Feb 19, 2021
       8             :  *
       9             :  * This file receives a populated target request struct and
      10             :  * converts it into a target request message buffer.
      11             :  */
      12             : 
      13             : #include <stdbool.h>
      14             : #include <stdlib.h>
      15             : 
      16             : #include "sg.h"
      17             : #include "sgUtil.h"
      18             : 
      19             : #define SG_PAYLOAD_LEN_TARGETREQ SG_MSG_LEN_TARGETREQ - 5 /// the payload length.
      20             : 
      21             : #define PBASE 4 /// the payload offset.
      22             : 
      23             : #define OFFSET_REQ_TYPE 0    /// the adsb reporting type and transmit port offset
      24             : #define OFFSET_MAX_TARGETS 1 /// the maximum number of targets offset
      25             : #define OFFSET_ICAO 3        /// the requested target icao offset
      26             : #define OFFSET_REPORTS 6     /// the requested report type offset
      27             : /*
      28             :  * Documented in the header file.
      29             :  */
      30           2 : bool sgEncodeTargetReq(uint8_t *buffer, sg_targetreq_t *tgt, uint8_t msgId)
      31             : {
      32             : 
      33             :     // populate header
      34           2 :     buffer[0] = SG_MSG_START_BYTE;
      35           2 :     buffer[1] = SG_MSG_TYPE_HOST_TARGETREQ;
      36           2 :     buffer[2] = msgId;
      37           2 :     buffer[3] = SG_PAYLOAD_LEN_TARGETREQ;
      38             : 
      39             :     // populate Request Type
      40           2 :     buffer[PBASE + OFFSET_REQ_TYPE] = tgt->transmitPort << 6 |
      41           2 :                                       tgt->reqType;
      42             : 
      43             :     // populate Max Targets
      44           2 :     uint162Buf(&buffer[PBASE + OFFSET_MAX_TARGETS], tgt->maxTargets);
      45             : 
      46             :     // populate Requested ICAO
      47           2 :     icao2Buf(&buffer[PBASE + OFFSET_ICAO], tgt->icao);
      48             : 
      49             :     // populated Requested Reports
      50           2 :     buffer[PBASE + OFFSET_REPORTS] = tgt->ownship << 7 |
      51           2 :                                      tgt->commA << 6 |
      52           2 :                                      tgt->military << 5 |
      53           2 :                                      tgt->tisb << 4 |
      54           2 :                                      tgt->airRefVel << 3 |
      55           2 :                                      tgt->targetState << 2 |
      56           2 :                                      tgt->modeStatus << 1 |
      57           2 :                                      tgt->stateVector;
      58             : 
      59             :     // populate checksum
      60           2 :     appendChecksum(buffer, SG_MSG_LEN_TARGETREQ);
      61             : 
      62           2 :     return true;
      63             : }

Generated by: LCOV version 1.14