@@ -41,6 +41,67 @@ immutable Subscription{T <: SubscriptionOptions}
41
41
end
42
42
unsafe_convert (:: Type{Ptr{Void}} , sub:: Subscription ) = sub. csubscription
43
43
44
+ # Troubleshooting adapted from:
45
+ # https://github.com/RobotLocomotion/drake/blob/f72bb3f465f69f25459a7a65c57b45c795b5e31d/drake/matlab/util/setup_loopback_multicast.sh
46
+ # https://github.com/RobotLocomotion/drake/blob/f72bb3f465f69f25459a7a65c57b45c795b5e31d/drake/matlab/util/check_multicast_is_loopback.sh
47
+ function troubleshoot ()
48
+ lo = loopback_interface ()
49
+ if check_loopback_multicast (lo)
50
+ check_multicast_routing (lo)
51
+ end
52
+ error (" Failed to create LCM instance." )
53
+ end
54
+
55
+ loopback_interface () = chomp (readstring (pipeline (` ifconfig` , ` grep -m 1 -i loopback` , ` cut -d : -f1` )))
56
+
57
+ function loopback_multicast_setup_advice (lo:: String )
58
+ @static if is_apple ()
59
+ """ Consider running:
60
+ route add -net 224.0.0.0 -netmask 240.0.0.0 -interface $lo """
61
+ elseif is_linux ()
62
+ """ Consider running:
63
+ ifconfig $lo multicast
64
+ route add -net 224.0.0.0 netmask 240.0.0.0 dev lo"""
65
+ else
66
+ " OS-specific instructions not available."
67
+ end
68
+ end
69
+
70
+ function check_loopback_multicast (lo:: String )
71
+ pass = if parse (readstring (pipeline (` ifconfig $lo ` , ` grep -c -i multicast` ))) != 0
72
+ msg = """ Loopback interface $lo is not set to multicast.
73
+ The most probable cause for this is that you are not connected to the internet.
74
+ $(loopback_multicast_setup_advice (lo)) """
75
+ warn (msg)
76
+ false
77
+ else
78
+ true
79
+ end
80
+ pass
81
+ end
82
+
83
+ function check_multicast_routing (lo:: String )
84
+ routing_correct = @static if is_apple ()
85
+ chomp (readstring (pipeline (` route get 224.0.0.0 -netmask 240.0.0.0` , ` grep -m 1 -i interface` , ` cut -f2 -d :` , ` tr -d ' '` ))) == lo
86
+ elseif is_linux ()
87
+ chomp (readstring (pipeline (` ip route get 224.0.0.0` , ` grep -m 1 -i dev` , ` sed 's/.*dev\s *//g'` , ` cut -d ' ' -f1` ))) == lo
88
+ else
89
+ error ()
90
+ end
91
+ pass = if ! routing_correct
92
+ msg = """
93
+ Route to multicast channel does not run through the loopback interface.
94
+ The most probable cause for this is that you are not connected to the internet.
95
+ $(loopback_multicast_setup_advice (lo))
96
+ """
97
+ warn (msg)
98
+ false
99
+ else
100
+ true
101
+ end
102
+ pass
103
+ end
104
+
44
105
type LCM
45
106
pointer:: Ptr{Void}
46
107
provider:: String
@@ -49,6 +110,9 @@ type LCM
49
110
50
111
LCM (provider= " " ) = begin
51
112
pointer = ccall ((:lcm_create , liblcm), Ptr{Void}, (Ptr{UInt8},), provider)
113
+ if pointer == C_NULL
114
+ troubleshoot ()
115
+ end
52
116
filedescriptor = RawFD (ccall ((:lcm_get_fileno , liblcm), Cint, (Ptr{Void},), pointer))
53
117
lcm = new (pointer, provider, filedescriptor, Subscription[])
54
118
finalizer (lcm, close)
0 commit comments