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/sgEncodeFlightId.c
Views: 1799
1
/**
2
* @copyright Copyright (c) 2021 Sagetech, Inc. All rights reserved.
3
*
4
* @file sgEncodeFlightId.c
5
* @author Jacob.Garrison
6
*
7
* @date Feb 25, 2021
8
*
9
*/
10
11
#include <ctype.h>
12
#include <stdbool.h>
13
#include <stdlib.h>
14
15
#include "sg.h"
16
#include "sgUtil.h"
17
18
#define SG_PAYLOAD_LEN_FLIGHT SG_MSG_LEN_FLIGHT - 5 /// the payload length.
19
20
#define PBASE 4 /// the payload offset.
21
#define OFFSET_ID 0 /// the flight id offset in the payload.
22
#define OFFSET_RSVD 8 /// the reserved field offset in the payload.
23
24
#define ID_LEN 8 /// the length of the flight identification field.
25
26
/*
27
* Documented in the header file.
28
*/
29
bool sgEncodeFlightId(uint8_t *buffer, sg_flightid_t *id, uint8_t msgId)
30
{
31
// populate header
32
buffer[0] = SG_MSG_START_BYTE;
33
buffer[1] = SG_MSG_TYPE_HOST_FLIGHT;
34
buffer[2] = msgId;
35
buffer[3] = SG_PAYLOAD_LEN_FLIGHT;
36
37
// populate flight identification
38
charArray2Buf(&buffer[PBASE + OFFSET_ID], id->flightId, ID_LEN);
39
40
// populate reserved field
41
uint322Buf(&buffer[PBASE + OFFSET_RSVD], 0);
42
43
// populate checksum
44
appendChecksum(buffer, SG_MSG_LEN_FLIGHT);
45
46
return true;
47
}
48
49