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/sgEncodeDataReq.c
Views: 1799
1
/**
2
* @copyright Copyright (c) 2021 Sagetech, Inc. All rights reserved.
3
*
4
* @file sgEncodeDataReq.c
5
* @author Jacob.Garrison
6
*
7
* @date Feb 23, 2021
8
*
9
* This file receives a populated data request struct and
10
* converts it into a data 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_DATAREQ SG_MSG_LEN_DATAREQ - 5 /// the payload length.
20
21
#define PBASE 4 /// the payload offset.
22
23
#define OFFSET_REQ_TYPE 0 /// the requested response message type
24
#define OFFSET_RSVD_1 1 /// a reserved field
25
#define OFFSET_RSVD_2 2 /// a reserved field
26
#define OFFSET_RSVD_3 3 /// a reserved field
27
28
/*
29
* Documented in the header file.
30
*/
31
bool sgEncodeDataReq(uint8_t *buffer, sg_datareq_t *data, uint8_t msgId)
32
{
33
// populate header
34
buffer[0] = SG_MSG_START_BYTE;
35
buffer[1] = SG_MSG_TYPE_HOST_DATAREQ;
36
buffer[2] = msgId;
37
buffer[3] = SG_PAYLOAD_LEN_DATAREQ;
38
39
// populate Request Type
40
buffer[PBASE + OFFSET_REQ_TYPE] = data->reqType;
41
42
// populate Reserved fields
43
buffer[PBASE + OFFSET_RSVD_1] = 0;
44
buffer[PBASE + OFFSET_RSVD_2] = 0;
45
buffer[PBASE + OFFSET_RSVD_3] = 0;
46
47
// populate checksum
48
appendChecksum(buffer, SG_MSG_LEN_DATAREQ);
49
50
return true;
51
}
52
53