CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_ADSB/sagetech-sdk/sgEncodeTargetReq.c
Views: 1799
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
bool sgEncodeTargetReq(uint8_t *buffer, sg_targetreq_t *tgt, uint8_t msgId)
31
{
32
33
// populate header
34
buffer[0] = SG_MSG_START_BYTE;
35
buffer[1] = SG_MSG_TYPE_HOST_TARGETREQ;
36
buffer[2] = msgId;
37
buffer[3] = SG_PAYLOAD_LEN_TARGETREQ;
38
39
// populate Request Type
40
buffer[PBASE + OFFSET_REQ_TYPE] = tgt->transmitPort << 6 |
41
tgt->reqType;
42
43
// populate Max Targets
44
uint162Buf(&buffer[PBASE + OFFSET_MAX_TARGETS], tgt->maxTargets);
45
46
// populate Requested ICAO
47
icao2Buf(&buffer[PBASE + OFFSET_ICAO], tgt->icao);
48
49
// populated Requested Reports
50
buffer[PBASE + OFFSET_REPORTS] = tgt->ownship << 7 |
51
tgt->commA << 6 |
52
tgt->military << 5 |
53
tgt->tisb << 4 |
54
tgt->airRefVel << 3 |
55
tgt->targetState << 2 |
56
tgt->modeStatus << 1 |
57
tgt->stateVector;
58
59
// populate checksum
60
appendChecksum(buffer, SG_MSG_LEN_TARGETREQ);
61
62
return true;
63
}
64
65