• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WindhoverLabs / yamcs_gdl90 / #38

26 Nov 2024 07:42PM UTC coverage: 0.0%. Remained the same
#38

Pull #3

lorenzo-gomez-windhover
-Upgrade yamcs to 5.9.8
Pull Request #3: Binary Mode

0 of 973 new or added lines in 7 files covered. (0.0%)

20 existing lines in 4 files now uncovered.

0 of 2374 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/com/windhoverlabs/yamcs/gdl90/ForeFlightIDMessage.java
1
/****************************************************************************
2
 *
3
 *   Copyright (c) 2024 Windhover Labs, L.L.C. All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * 1. Redistributions of source code must retain the above copyright
10
 *    notice, this list of conditions and the following disclaimer.
11
 * 2. Redistributions in binary form must reproduce the above copyright
12
 *    notice, this list of conditions and the following disclaimer in
13
 *    the documentation and/or other materials provided with the
14
 *    distribution.
15
 * 3. Neither the name Windhover Labs nor the names of its
16
 *    contributors may be used to endorse or promote products derived
17
 *    from this software without specific prior written permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
 * POSSIBILITY OF SUCH DAMAGE.
31
 *
32
 *****************************************************************************/
33

34
package com.windhoverlabs.yamcs.gdl90;
35

36
import java.io.ByteArrayOutputStream;
37
import java.nio.ByteBuffer;
38

39
/**
40
 * As per the spec:
41
 * https://www.faa.gov/sites/faa.gov/files/air_traffic/technology/adsb/archival/GDL90_Public_ICD_RevA.PDF
42
 * Pg 18
43
 *
44
 * <p>This message is an extension of the GDL90 protocol by ForeFlight
45
 */
46
public class ForeFlightIDMessage {
×
47

48
  byte FlagByte = 0x7E;
×
49
  public static final byte MessageID = 0x65;
50
  public static final byte ForeFlightSubMessageID = 0x00;
UNCOV
51
  private byte Version = 0x01;
×
52

53
  public long DeviceSerialNum;
54
  public String DeviceName;
55
  public String DeviceLongName = "";
×
56

57
  public int CapibilitiesMask;
58

59
  public byte[] toBytes() throws Exception {
60

61
    ByteArrayOutputStream messageStream = new ByteArrayOutputStream();
×
62

63
    messageStream.write(MessageID);
×
64
    messageStream.write(ForeFlightSubMessageID);
×
65

66
    messageStream.write(Version);
×
67

68
    //    for (int i = 0; i < 36; i++) {
69
    //      messageStream.write(0x00);
70
    //    }
71

72
    byte[] DeviceSerialNumBytes = ByteBuffer.allocate(8).putLong(DeviceSerialNum).array();
×
73
    messageStream.write(DeviceSerialNumBytes[7]);
×
74
    messageStream.write(DeviceSerialNumBytes[6]);
×
75
    messageStream.write(DeviceSerialNumBytes[5]);
×
76
    messageStream.write(DeviceSerialNumBytes[4]);
×
77
    messageStream.write(DeviceSerialNumBytes[3]);
×
78
    messageStream.write(DeviceSerialNumBytes[2]);
×
79
    messageStream.write(DeviceSerialNumBytes[1]);
×
80
    messageStream.write(DeviceSerialNumBytes[0]);
×
81

82
    byte[] deviceNameBytes = this.DeviceName.getBytes();
×
83
    if (deviceNameBytes.length > 8) {
×
84
      throw new Exception("DeviceName is greater than 8 characters");
×
85
    }
86

87
    for (byte b : deviceNameBytes) {
×
88
      messageStream.write(b);
×
89
    }
90

91
    int deviceNameBytesRemainder = 8 - deviceNameBytes.length;
×
92

93
    for (int i = 0; i < deviceNameBytesRemainder; i++) {
×
94
      messageStream.write(0x20);
×
95
    }
96

97
    byte[] deviceLongNameBytes = this.DeviceLongName.getBytes();
×
98
    if (deviceLongNameBytes.length > 16) {
×
99
      throw new Exception("DeviceName is greater than 16 characters");
×
100
    }
101

102
    for (byte b : deviceLongNameBytes) {
×
103
      messageStream.write(b);
×
104
    }
105

106
    int deviceNameLongBytesRemainder = 16 - deviceLongNameBytes.length;
×
107

108
    for (int i = 0; i < deviceNameLongBytesRemainder; i++) {
×
109
      messageStream.write(0x20);
×
110
    }
111

112
    //    TODO:Set CapibilitiesMask accordingly
113
    byte[] CapibilitiesMaskBytes = ByteBuffer.allocate(4).putInt(CapibilitiesMask).array();
×
114
    messageStream.write(CapibilitiesMaskBytes[3]);
×
115
    messageStream.write(CapibilitiesMaskBytes[2]);
×
116
    messageStream.write(CapibilitiesMaskBytes[1]);
×
117
    messageStream.write(CapibilitiesMaskBytes[0]);
×
118

119
    byte[] crcData = messageStream.toByteArray();
×
120
    int crc = CrcTable.crcCompute(crcData, 0, crcData.length);
×
121
    //
122
    // Go through message data and escape characters as per the spec
123
    // ....
124
    //
125

126
    byte[] crcBytes = ByteBuffer.allocate(4).putInt(crc).array();
×
127
    messageStream.write(crcBytes[3]);
×
128
    messageStream.write(crcBytes[2]);
×
129

130
    ByteArrayOutputStream messageStreamOut =
×
131
        OwnshipGeoAltitude.escapeBytes(messageStream.toByteArray());
×
132

133
    ByteBuffer bbOut = ByteBuffer.allocate(messageStreamOut.toByteArray().length + 2).put(FlagByte);
×
134

135
    bbOut.put(messageStreamOut.toByteArray());
×
136

137
    bbOut.put(FlagByte);
×
138

139
    byte[] dataOut = bbOut.array();
×
140

141
    messageStream.toByteArray();
×
142

143
    return dataOut;
×
144
  }
145

146
  public static int setNibble(int num, int nibble, int which) {
147
    int shiftNibble = nibble << (4 * which);
×
148
    int shiftMask = 0x0000000F << (4 * which);
×
149
    return (num & ~shiftMask) | shiftNibble;
×
150
  }
151

152
  public int packLatLong(double LatLon) {
153

154
    Double doubleVal = LatLon;
×
155

156
    int valLon = (int) (doubleVal / (180.0 / 8388608.0));
×
157

158
    return valLon;
×
159
  }
160

161
  public int packAltitude(int altFt) {
162
    //          Double doubleVal = altFt;
163
    return (int) ((1000 + altFt) / 25);
×
164
  }
165

166
  public int packDegrees(float heading) {
167
    return Math.round((heading / 10) * 1);
×
168
  }
169
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc