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/toGS.c
Views: 1799
1
/**
2
* @copyright Copyright (c) 2021 Sagetech, Inc. All rights reserved.
3
*
4
* @file toGS.c
5
* @author Jacob.Garrison
6
*
7
* @date Mar 2, 2021
8
*
9
*/
10
11
#include "sgUtil.h"
12
13
/*
14
* Documented in the header file.
15
*/
16
uint8_t toGS(const uint8_t bytes[])
17
{
18
uint8_t code = bytes[0];
19
float gs = 0.0f;
20
21
if (code <= 0x01)
22
{
23
gs = 0.0f;
24
}
25
else if (code <= 0x08)
26
{
27
gs = 1.0f;
28
}
29
else if (code <= 0x0C)
30
{
31
gs = 1.0f + (code - 0x09) * 0.25f;
32
}
33
else if (code <= 0x26)
34
{
35
gs = 2.0f + (code - 0x0D) * 0.5f;
36
}
37
else if (code <= 0x5D)
38
{
39
gs = 15.0f + (code - 0x27) * 1.0f;
40
}
41
else if (code <= 0x6C)
42
{
43
gs = 70.0f + (code - 0x5E) * 2.0f;
44
}
45
else if (code <= 0x7B)
46
{
47
gs = 100.0f + (code - 0x6D) * 5.0f;
48
}
49
else
50
{
51
gs = 176.0f;
52
}
53
54
// first converting to an 16 bit integer is necessary
55
// to keep the floating point conversion from
56
// truncating to 0.
57
return (uint8_t)((int16_t)gs & 0xFF);
58
}
59
60