@@ -45,7 +45,7 @@ func main_loop() {
45
45
var output_xml_path string
46
46
47
47
myos := runtime .GOOS
48
- fmt .Printf ("Host OS: %s\n " , myos )
48
+ fmt .Printf ("Host OS: %s\r \ n " , myos )
49
49
switch myos {
50
50
case "linux" :
51
51
husarnet_temp_dir = "/var/tmp/husarnet-dds"
@@ -82,121 +82,124 @@ func main_loop() {
82
82
dir := filepath .Dir (output_xml_path )
83
83
err := os .MkdirAll (dir , os .ModePerm )
84
84
if err != nil {
85
- fmt .Printf ("Err: can not create \" %s\" path" , dir )
85
+ fmt .Printf ("Err: can not create \" %s\" path\r \n " , dir )
86
86
os .Exit (1 )
87
87
}
88
88
89
89
ioutil .WriteFile (output_xml_path , []byte (output_xml ), 0644 )
90
90
91
- // Check the RMW_IMPLEMENTATION env
92
- rmw_implementation , ok := os .LookupEnv ("RMW_IMPLEMENTATION" )
93
- if ok {
94
- fmt .Println ("RMW_IMPLEMENTATION:" , rmw_implementation )
95
- } else {
96
- fmt .Println ("RMW_IMPLEMENTATION is not set." )
97
- return
91
+ // =========================================
92
+ // CYCLONE DDS CONFIG
93
+ // =========================================
94
+
95
+ input_xml = string (default_config_cyclonedds_simple )
96
+
97
+ // check if non-default DDS config file exists
98
+ if _ , err := os .Stat (template_path_cyclonedds ); err == nil {
99
+ input_xml_bytes , _ := ioutil .ReadFile (template_path_cyclonedds )
100
+ input_xml = string (input_xml_bytes )
98
101
}
99
102
100
- if rmw_implementation == "rmw_cyclonedds_cpp" {
101
- // default config
102
- input_xml = string (default_config_cyclonedds_simple )
103
+ // prepare XML files with Husarnet hosts
104
+ output_xml = ParseCycloneDDSSimple (input_xml )
105
+
106
+ // defaul output path
107
+ output_xml_path = husarnet_temp_dir + "/husarnet-cyclonedds.xml"
103
108
104
- // check if non-default DDS config file exists
105
- if _ , err := os .Stat (template_path_cyclonedds ); err == nil {
106
- input_xml_bytes , _ := ioutil .ReadFile (template_path_cyclonedds )
107
- input_xml = string (input_xml_bytes )
109
+ // check whether env to set non-default path is set
110
+ cyclonedds_uri , ok := os .LookupEnv ("CYCLONEDDS_URI" )
111
+ if ok {
112
+ fmt .Println ("CYCLONEDDS_URI:" , cyclonedds_uri )
113
+ if strings .Contains (cyclonedds_uri , "husarnet" ) {
114
+ output_xml_path = strings .Split (cyclonedds_uri , "file://" )[1 ]
108
115
}
116
+ }
109
117
110
- // prepare XML files with Husarnet hosts
111
- output_xml = ParseCycloneDDSSimple (input_xml )
118
+ // Create necessary directories
119
+ dir = filepath .Dir (output_xml_path )
120
+ err = os .MkdirAll (dir , os .ModePerm )
121
+ if err != nil {
122
+ fmt .Printf ("Err: can not create \" %s\" path\r \n " , dir )
123
+ os .Exit (1 )
124
+ }
112
125
113
- // defaul output path
114
- output_xml_path = husarnet_temp_dir + "/husarnet-cyclonedds.xml"
126
+ ioutil . WriteFile ( output_xml_path , [] byte ( output_xml ), 0644 )
127
+ fmt . Printf ( "Cyclone DDS config saved here: \" %s \" \r \n " , output_xml_path )
115
128
116
- // check whether env to set non-default path is set
117
- cyclonedds_uri , ok := os .LookupEnv ("CYCLONEDDS_URI" )
118
- if ok {
119
- fmt .Println ("CYCLONEDDS_URI:" , cyclonedds_uri )
120
- if strings .Contains (cyclonedds_uri , "husarnet" ) {
121
- output_xml_path = strings .Split (cyclonedds_uri , "file://" )[1 ]
122
- }
123
- }
129
+ // =========================================
130
+ // FAST DDS CONFIG
131
+ // =========================================
132
+
133
+ // Load the appriopriate XML default config
134
+ ros_discovery_server , is_ds_client := os .LookupEnv ("ROS_DISCOVERY_SERVER" )
135
+ if is_ds_client {
136
+ fmt .Println ("ROS_DISCOVERY_SERVER:" , ros_discovery_server )
137
+ input_xml = string (default_config_fastdds_ds_client )
138
+ } else {
139
+ input_xml = string (default_config_fastdds_simple )
124
140
}
125
141
126
- if rmw_implementation == "rmw_fastrtps_cpp" {
142
+ // check if non-default DDS config file exists
143
+ if _ , err := os .Stat (template_path_fastdds_simple ); err == nil {
144
+ input_xml_bytes , _ := ioutil .ReadFile (template_path_fastdds_simple )
145
+ input_xml = string (input_xml_bytes )
146
+ }
127
147
128
- // Load the appriopriate XML default config
129
- ros_discovery_server , is_ds_client := os .LookupEnv ("ROS_DISCOVERY_SERVER" )
130
- if is_ds_client {
131
- fmt .Println ("ROS_DISCOVERY_SERVER:" , ros_discovery_server )
132
- input_xml = string (default_config_fastdds_ds_client )
133
- } else {
134
- input_xml = string (default_config_fastdds_simple )
135
- }
148
+ // prepare XML files with Husarnet hosts
149
+ if is_ds_client {
150
+ var ds_server_addr string
151
+ var ds_server_port string
136
152
137
- // check if non-default DDS config file exists
138
- if _ , err := os .Stat (template_path_fastdds_simple ); err == nil {
139
- input_xml_bytes , _ := ioutil .ReadFile (template_path_fastdds_simple )
140
- input_xml = string (input_xml_bytes )
141
- }
153
+ // check whether IPv6 address is provided instead of hostname
154
+ ipv6 := strings .Split (ros_discovery_server , ":" )
155
+
156
+ if ipv6 [0 ] == "[fc94" {
157
+ // IPv6 hostname is provided
158
+ parts := strings .Split (ros_discovery_server , "]:" )
142
159
143
- // prepare XML files with Husarnet hosts
144
- if is_ds_client {
145
- var ds_server_addr string
146
- var ds_server_port string
147
-
148
- // check whether IPv6 address is provided instead of hostname
149
- ipv6 := strings .Split (ros_discovery_server , ":" )
150
-
151
- if ipv6 [0 ] == "[fc94" {
152
- // IPv6 hostname is provided
153
- parts := strings .Split (ros_discovery_server , "]:" )
154
-
155
- if len (parts ) == 1 {
156
- fmt .Println ("Error: Invalid string format" )
157
- os .Exit (1 )
158
- }
159
-
160
- ds_server_addr = strings .Trim (parts [0 ], "[" )
161
- ds_server_port = parts [1 ]
162
- output_xml = strings .Replace (input_xml , "$DISCOVERY_SERVER_IPV6" , ds_server_addr , 1 )
163
- } else {
164
- // normal hostname is provided
165
- ds_server_addr = strings .Split (ros_discovery_server , ":" )[0 ]
166
- ds_server_port = strings .Split (ros_discovery_server , ":" )[1 ]
167
- output_xml = strings .Replace (input_xml , "$DISCOVERY_SERVER_IPV6" , GetHostIPv6 (ds_server_addr ), 1 )
160
+ if len (parts ) == 1 {
161
+ fmt .Println ("Error: Invalid string format" )
162
+ os .Exit (1 )
168
163
}
169
164
170
- output_xml = strings .Replace (output_xml , "$DISCOVERY_SERVER_PORT" , ds_server_port , 1 )
171
- output_xml = strings .Replace (output_xml , "$HOST_IPV6" , GetOwnHusarnetIPv6 (), - 1 )
165
+ ds_server_addr = strings .Trim (parts [0 ], "[" )
166
+ ds_server_port = parts [1 ]
167
+ output_xml = strings .Replace (input_xml , "$DISCOVERY_SERVER_IPV6" , ds_server_addr , 1 )
172
168
} else {
173
- output_xml = ParseFastDDSSimple (input_xml )
169
+ // normal hostname is provided
170
+ ds_server_addr = strings .Split (ros_discovery_server , ":" )[0 ]
171
+ ds_server_port = strings .Split (ros_discovery_server , ":" )[1 ]
172
+ output_xml = strings .Replace (input_xml , "$DISCOVERY_SERVER_IPV6" , GetHostIPv6 (ds_server_addr ), 1 )
174
173
}
175
174
176
- // defaul output path
177
- output_xml_path = husarnet_temp_dir + "/husarnet-fastdds.xml"
175
+ output_xml = strings .Replace (output_xml , "$DISCOVERY_SERVER_PORT" , ds_server_port , 1 )
176
+ output_xml = strings .Replace (output_xml , "$HOST_IPV6" , GetOwnHusarnetIPv6 (), - 1 )
177
+ } else {
178
+ output_xml = ParseFastDDSSimple (input_xml )
179
+ }
180
+
181
+ // defaul output path
182
+ output_xml_path = husarnet_temp_dir + "/husarnet-fastdds.xml"
178
183
179
- // check whether env to set non-default path is set
180
- fastrtps_default_profiles_file , ok := os .LookupEnv ("FASTRTPS_DEFAULT_PROFILES_FILE" )
181
- if ok {
182
- fmt .Println ("FASTRTPS_DEFAULT_PROFILES_FILE:" , fastrtps_default_profiles_file )
183
- if strings .Contains (fastrtps_default_profiles_file , "husarnet" ) {
184
- output_xml_path = fastrtps_default_profiles_file
185
- }
184
+ // check whether env to set non-default path is set
185
+ fastrtps_default_profiles_file , ok := os .LookupEnv ("FASTRTPS_DEFAULT_PROFILES_FILE" )
186
+ if ok {
187
+ fmt .Println ("FASTRTPS_DEFAULT_PROFILES_FILE:" , fastrtps_default_profiles_file )
188
+ if strings .Contains (fastrtps_default_profiles_file , "husarnet" ) {
189
+ output_xml_path = fastrtps_default_profiles_file
186
190
}
187
-
188
191
}
189
192
190
193
// Create necessary directories
191
194
dir = filepath .Dir (output_xml_path )
192
195
err = os .MkdirAll (dir , os .ModePerm )
193
196
if err != nil {
194
- fmt .Printf ("Err: can not create \" %s\" path" , dir )
197
+ fmt .Printf ("Err: can not create \" %s\" path\r \n " , dir )
195
198
os .Exit (1 )
196
199
}
197
200
198
201
ioutil .WriteFile (output_xml_path , []byte (output_xml ), 0644 )
199
- fmt .Printf ("DDS config saved here: \" %s\" " , output_xml_path )
202
+ fmt .Printf ("Fast DDS config saved here: \" %s\" \r \n " , output_xml_path )
200
203
} else {
201
204
fmt .Println ("can't reach Husarnet client API" )
202
205
os .Exit (1 )
@@ -296,7 +299,7 @@ func main() {
296
299
envvars := make (map [string ]string )
297
300
298
301
for i , env := range envs {
299
- fmt .Printf ("env[%d]: %s\n " , i , env )
302
+ fmt .Printf ("env[%d]: %s\r \ n " , i , env )
300
303
key := strings .Split (env , "=" )[0 ]
301
304
value := strings .Split (env , "=" )[1 ]
302
305
@@ -340,7 +343,7 @@ func main() {
340
343
341
344
installCommand .Flags ().StringArrayVarP (& envs , "env" , "e" ,
342
345
[]string {
343
- "RMW_IMPLEMENTATION=rmw_fastrtps_cpp " ,
346
+ "CYCLONEDDS_URI=file://" + husarnet_temp_dir + "/cyclonedds.xml " ,
344
347
"FASTRTPS_DEFAULT_PROFILES_FILE=" + husarnet_temp_dir + "/fastdds.xml" },
345
348
"environment variables for the service" )
346
349
0 commit comments