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

WindhoverLabs / yamcs-cfs / #162

28 Nov 2024 05:03PM UTC coverage: 0.0%. Remained the same
#162

push

lorenzo-gomez-windhover
-Updates for yamcs 5.9.8

0 of 4 new or added lines in 1 file covered. (0.0%)

614 existing lines in 11 files now uncovered.

0 of 6789 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/tctm/UdpTmFrameLink.java
1
package com.windhoverlabs.yamcs.tctm;
2

3
import java.io.IOException;
4
import java.net.DatagramPacket;
5
import java.net.DatagramSocket;
6
import java.net.SocketException;
7
import java.util.Arrays;
8
import org.yamcs.ConfigurationException;
9
import org.yamcs.YConfiguration;
10
import org.yamcs.tctm.ccsds.AbstractTmFrameLink;
11
import org.yamcs.utils.StringConverter;
12

13
/**
14
 * Receives telemetry fames via UDP. One UDP datagram = one TM frame.
15
 *
16
 * <p>This is a TEMPORARY fix. The proper fix is adding the logic of removing the 4 bytes in
17
 * simlink.
18
 *
19
 * @author nm
20
 */
21
public class UdpTmFrameLink extends AbstractTmFrameLink implements Runnable {
×
22
  private DatagramSocket tmSocket;
23
  private int port;
24

25
  DatagramPacket datagram;
26
  String packetPreprocessorClassName;
27
  Object packetPreprocessorArgs;
28
  Thread thread;
29

30
  /**
31
   * Creates a new UDP Frame Data Link
32
   *
33
   * @throws ConfigurationException if port is not defined in the configuration
34
   */
35
  public void init(String instance, String name, YConfiguration config)
36
      throws ConfigurationException {
UNCOV
37
    super.init(instance, name, config);
×
UNCOV
38
    port = config.getInt("port");
×
39
    // TODO:Move this "+ 4" nonsense to configuration
40
    int maxLength = frameHandler.getMaxFrameSize() + 4;
×
UNCOV
41
    datagram = new DatagramPacket(new byte[maxLength], maxLength);
×
42
  }
×
43

44
  @Override
45
  public void doStart() {
UNCOV
46
    if (!isDisabled()) {
×
47
      try {
48
        tmSocket = new DatagramSocket(port);
×
UNCOV
49
        new Thread(this).start();
×
50
      } catch (SocketException e) {
×
51
        notifyFailed(e);
×
52
      }
×
53
    }
54
    notifyStarted();
×
UNCOV
55
  }
×
56

57
  @Override
58
  public void doStop() {
UNCOV
59
    tmSocket.close();
×
UNCOV
60
    notifyStopped();
×
61
  }
×
62

63
  @Override
64
  public void run() {
UNCOV
65
    while (isRunningAndEnabled()) {
×
66
      try {
67
        tmSocket.receive(datagram);
×
68

69
        if (log.isTraceEnabled()) {
×
UNCOV
70
          log.trace(
×
71
              "Received datagram of length {}: {}",
72
              datagram.getLength(),
×
UNCOV
73
              StringConverter.arrayToHexString(
×
74
                  datagram.getData(), datagram.getOffset(), datagram.getLength(), true));
×
75
        }
76

77
        // NOTE: This is a TEMPORARY fix. The proper fix is adding the logic of removing the 4 bytes
78
        // in simlink.
UNCOV
79
        byte[] packet = Arrays.copyOfRange(datagram.getData(), 4, datagram.getLength());
×
UNCOV
80
        handleFrame(timeService.getHresMissionTime(), packet, 0, datagram.getLength() - 4);
×
81

82
      } catch (IOException e) {
×
UNCOV
83
        if (!isRunningAndEnabled()) {
×
84
          break;
×
85
        }
86
        log.warn("exception {} thrown when reading from the UDP socket at port {}", e, port);
×
UNCOV
87
      } catch (Exception e) {
×
88
        log.error("Error processing frame", e);
×
89
      }
×
90
    }
91
  }
×
92

93
  /** returns statistics with the number of datagram received and the number of invalid datagrams */
94
  @Override
95
  public String getDetailedStatus() {
UNCOV
96
    if (isDisabled()) {
×
UNCOV
97
      return "DISABLED";
×
98
    } else {
99
      return String.format(
×
100
          "OK (%s) %nValid datagrams received: %d%nInvalid datagrams received: %d",
101
          port, validFrameCount.get(), invalidFrameCount.get());
×
102
    }
103
  }
104

105
  @Override
106
  protected void doDisable() {
UNCOV
107
    if (tmSocket != null) {
×
UNCOV
108
      tmSocket.close();
×
109
      tmSocket = null;
×
110
    }
111
  }
×
112

113
  @Override
114
  protected void doEnable() throws SocketException {
UNCOV
115
    tmSocket = new DatagramSocket(port);
×
UNCOV
116
    new Thread(this).start();
×
117
  }
×
118

119
  @Override
120
  protected Status connectionStatus() {
UNCOV
121
    return Status.OK;
×
122
  }
123
}
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