MAVLinkConnection.java
1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package me.drton.jmavsim;
import me.drton.jmavlib.mavlink.MAVLinkMessage;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* User: ton Date: 13.02.14 Time: 21:50
*/
public class MAVLinkConnection extends WorldObject {
private List<MAVLinkNode> nodes = new ArrayList<MAVLinkNode>();
private Set<Integer> skipMessages = new HashSet<Integer>();
public MAVLinkConnection(World world) {
super(world);
}
public void addNode(MAVLinkNode node) {
nodes.add(node);
node.addConnection(this);
}
public void addSkipMessage(int msgType) {
skipMessages.add(msgType);
}
public void sendMessage(MAVLinkNode sender, MAVLinkMessage msg) {
if (skipMessages.contains(msg.getMsgType())) {
return;
}
for (MAVLinkNode node : nodes) {
if (node != sender) {
node.handleMessage(msg);
}
}
}
@Override
public void update(long t, boolean paused) {
for (MAVLinkNode node : nodes) {
node.update(t, paused);
}
}
}