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/sgEncodeInstall.c
Views: 1799
1
/**
2
* @copyright Copyright (c) 2021 Sagetech, Inc. All rights reserved.
3
*
4
* @file sgEncodeInstall.c
5
* @author Jacob.Garrison
6
*
7
* @date Feb 23, 2021
8
*
9
* This file receives a populated installation message struct and
10
* converts it into a installation message buffer.
11
*/
12
13
#include <ctype.h>
14
#include <string.h>
15
#include <stdbool.h>
16
17
#include "sg.h"
18
#include "sgUtil.h"
19
20
#define SG_PAYLOAD_LEN_INSTALL SG_MSG_LEN_INSTALL - 5 /// the payload length.
21
22
#define PBASE 4 /// the payload offset.
23
#define OFFSET_ICAO 0 /// the icao address offset in the payload.
24
#define OFFSET_REG 3 /// the registration offset in the payload.
25
#define OFFSET_RSVD1 10 /// the first reserved field offset in the payload.
26
#define OFFSET_COM0 12 /// the COM port 0 offset in the payload.
27
#define OFFSET_COM1 13 /// the COM port 1 offset in the payload.
28
#define OFFSET_IP 14 /// the IP address offset in the payload.
29
#define OFFSET_MASK 18 /// the net mask offset in the payload.
30
#define OFFSET_PORT 22 /// the port number offset in the payload.
31
#define OFFSET_GPS 24 /// the GPS integrity offset in the payload.
32
#define OFFSET_EMIT_SET 25 /// the emitter category offset in the payload.
33
#define OFFSET_EMIT_TYPE 26 /// the emitter type offset in the payload.
34
#define OFFSET_SIZE 27 /// the aircraft size offset in the payload.
35
#define OFFSET_SPEED 28 /// the maximum airspeed offset in the payload.
36
#define OFFSET_ENCODER 29 /// the altitude-encoder-offset offset in the payload.
37
#define OFFSET_RSVD2 31 /// the second reserved field offset in the payload.
38
#define OFFSET_CONFIG 33 /// the configuration offset in the payload.
39
#define OFFSET_RSVD3 34 /// the third reserved field offset in the payload.
40
41
#define REG_LEN 7 /// the registration field length.
42
/*
43
* Documented in the header file.
44
*/
45
bool sgEncodeInstall(uint8_t *buffer, sg_install_t *stl, uint8_t msgId)
46
{
47
// populate header
48
buffer[0] = SG_MSG_START_BYTE;
49
buffer[1] = SG_MSG_TYPE_HOST_INSTALL;
50
buffer[2] = msgId;
51
buffer[3] = SG_PAYLOAD_LEN_INSTALL;
52
53
// populate icao address
54
icao2Buf(&buffer[PBASE + OFFSET_ICAO], stl->icao);
55
56
// populate aircraft registration
57
charArray2Buf(&buffer[PBASE + OFFSET_REG], stl->reg, REG_LEN);
58
59
// populate reserved fields
60
uint162Buf(&buffer[PBASE + OFFSET_RSVD1], 0);
61
62
// populate COM port 0, correct enum offset
63
buffer[PBASE + OFFSET_COM0] = stl->com0;
64
65
// populate COM port 1, correct enum offset
66
buffer[PBASE + OFFSET_COM1] = stl->com1;
67
68
// populate IP address
69
uint322Buf(&buffer[PBASE + OFFSET_IP], stl->eth.ipAddress);
70
71
// populate net mask
72
uint322Buf(&buffer[PBASE + OFFSET_MASK], stl->eth.subnetMask);
73
74
// populate port number
75
uint162Buf(&buffer[PBASE + OFFSET_PORT], stl->eth.portNumber);
76
77
// populate gps integrity
78
buffer[PBASE + OFFSET_GPS] = stl->sil << 4 |
79
stl->sda;
80
81
// populate emitter category set and type
82
uint8_t emitSet;
83
uint8_t emitType;
84
if (stl->emitter < SG_EMIT_OFFSET_B) // group A
85
{
86
emitSet = SG_EMIT_GROUP_A;
87
emitType = stl->emitter - SG_EMIT_OFFSET_A;
88
}
89
else if (stl->emitter < SG_EMIT_OFFSET_C) // group B
90
{
91
emitSet = SG_EMIT_GROUP_B;
92
emitType = stl->emitter - SG_EMIT_OFFSET_B;
93
}
94
else if (stl->emitter < SG_EMIT_OFFSET_D) // group C
95
{
96
emitSet = SG_EMIT_GROUP_C;
97
emitType = stl->emitter - SG_EMIT_OFFSET_C;
98
}
99
else // group D
100
{
101
emitSet = SG_EMIT_GROUP_D;
102
emitType = stl->emitter - SG_EMIT_OFFSET_D;
103
}
104
buffer[PBASE + OFFSET_EMIT_SET] = emitSet;
105
buffer[PBASE + OFFSET_EMIT_TYPE] = emitType;
106
107
// populate aircraft size
108
buffer[PBASE + OFFSET_SIZE] = stl->size;
109
110
// populate max airspeed
111
buffer[PBASE + OFFSET_SPEED] = stl->maxSpeed;
112
113
// populate altitude encoder offset
114
uint162Buf(&buffer[PBASE + OFFSET_ENCODER], stl->altOffset);
115
116
// populate reserved fields
117
uint162Buf(&buffer[PBASE + OFFSET_RSVD2], 0);
118
119
// populate install configuration
120
buffer[PBASE + OFFSET_CONFIG] = stl->wowConnected << 7 |
121
stl->heater << 6 |
122
stl->airspeedTrue << 5 |
123
stl->hdgTrueNorth << 4 |
124
stl->altRes100 << 3 |
125
stl->antenna;
126
127
// populate reserved fields
128
uint162Buf(&buffer[PBASE + OFFSET_RSVD3], 0);
129
130
// populate checksum
131
appendChecksum(buffer, SG_MSG_LEN_INSTALL);
132
133
return true;
134
}
135
136