autoverse-cli 0.12.6__py3-none-any.whl → 0.13.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: autoverse-cli
3
- Version: 0.12.6
3
+ Version: 0.13.0
4
4
  Summary: The Autoverse CLI
5
5
  Author-email: Dan Kamrath <dan.kamrath@autonomalabs.com>
6
6
  License: # End-User License Agreement (EULA) of the Autonoma AutoVerse CLI
@@ -1,15 +1,16 @@
1
1
  avrs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- avrs/app_version.py,sha256=ABDoScc-C0ag7rkv5v2Jb92YXGK84iwyXfg5bLrSmG4,856
2
+ avrs/app_version.py,sha256=ZSZQG_G1Ve_IaZicZow4RXJaElbHnQFTpkWQFgHpj6Y,856
3
3
  avrs/argparse_help.py,sha256=EoEaohGXZXqJvs1dFEzbo9vh47CYdHdSY2Im2Ps2iFo,945
4
- avrs/avrs.py,sha256=Y8rmsJiRjrnJ4U-aUvqyA4ZwFowCIAqOBGe1DED7QYs,3050
4
+ avrs/avrs.py,sha256=LViodKPp_ACSc05lZsCPWhudzuTtIbilelszupneSP0,4543
5
5
  avrs/can_tool.py,sha256=IBoctKobBJ3wCq4ZdtuXuXH4AMEUxazCfYT6YP0Luw8,7161
6
6
  avrs/can_tool_util.py,sha256=G3q21dTGMLc09SDq_RieoW7kSn-kXPkXxPDjavPh4hQ,7710
7
7
  avrs/cfg.py,sha256=kMn08Z4Ms1PAu2-U1QI8weEJeIVEppP4A4_tFfwnjtg,2924
8
- avrs/launcher.py,sha256=Kzrxp6FYCmujiT0Y5dk-sCt8vaY6Z4qKKZk8YUTEuVw,9235
8
+ avrs/launcher.py,sha256=kk1lyHHLgFZ4zsFfa_zV5f1kYbUODT6wEILJ8TZ16rQ,9353
9
9
  avrs/launcher_util.py,sha256=sO3k_z3A-HIQdJVkVXNXUAE_MGFwAYiZUqQBoFwOqew,5325
10
- avrs/race_cloud.py,sha256=kFrAGppfODobdCSXxPLytgSHi_XvHDdVRua5Gn-sFdY,11046
11
- avrs/race_cloud_cfg_util.py,sha256=2_vJW8DLg6--YXUBX_ldzu_PWSewDd1pja1MCsTFPKA,3584
12
- avrs/race_cloud_util.py,sha256=cZ04cmM7Cp8xyb1FDWR5fnL0TFMFua1JLvTXQ1Tm5PY,8608
10
+ avrs/race_cloud.py,sha256=svCuDyfElW5puhKBmM2WLammA3suQEPFdxkqYgOqPpk,13675
11
+ avrs/race_cloud_cfg_util.py,sha256=gcHyUY0m5zc_9zZatKLaSIC_oFGc-6Vs8UlcX5yry9o,5158
12
+ avrs/race_cloud_fwd_api.py,sha256=40eUrCxnMdfIjZGqYiZ9HyUqntEw9wK5dwgkDVcNUBM,1390
13
+ avrs/race_cloud_util.py,sha256=5eBtk9lzRogrV3IiYJA4BwEuhkesIZzRGpWwCxqqo0A,9307
13
14
  avrs/simconfig.py,sha256=UZc4FrxVHUkk2e9IglSpuojXkaL_nPrJW7trbEGgOOo,2907
14
15
  avrs/simconfig_util.py,sha256=1RmnmhK5C4HlCicTQeqn-1ORz3Xrku_QMt1Fqr9XjZs,4839
15
16
  avrs/tests.py,sha256=3JeYBjn0tRqHXERDROfzmYuW1KXeCcKur5Bw-EIegto,153
@@ -36,9 +37,9 @@ avrs/requests/toggle_hud.py,sha256=sV5t5QZc4uvRihPVk8jEKZiQNsyF9tsUwq5b4jjZplc,3
36
37
  avrs/requests/vd.py,sha256=at6oUAGY2h0OxYU6MLOi1gnxyUn6i24vL9DUAj0L880,1600
37
38
  avrs/requests/vehicle_input.py,sha256=R1b1xkRtOBkwyU6OSN4bWVlYsIUroZG0WKbYbc4pEH8,729
38
39
  avrs/requests/vehicle_replay.py,sha256=nCAE21VNyKoeIjjXBGAihgOLO7zYHcu-HWvPZYxdQ2c,11099
39
- autoverse_cli-0.12.6.dist-info/LICENSE,sha256=d4eWXho-u18HkBsX4K21uHX_bBb2UXZSrJdsb7Z_JlM,2647
40
- autoverse_cli-0.12.6.dist-info/METADATA,sha256=5ZKAxuBB9Al1uPeahDHHPq3Ak-i2zkNRevYGBmZpHTs,3342
41
- autoverse_cli-0.12.6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
42
- autoverse_cli-0.12.6.dist-info/entry_points.txt,sha256=Cb9qsUyU5AKkklehCcvtfT0-N3SXbUEqvjze4iEU5kE,40
43
- autoverse_cli-0.12.6.dist-info/top_level.txt,sha256=-AJO2e4MCVej6hY0U84pu5NfMeMW5qaAPSMisDT5rmA,5
44
- autoverse_cli-0.12.6.dist-info/RECORD,,
40
+ autoverse_cli-0.13.0.dist-info/LICENSE,sha256=d4eWXho-u18HkBsX4K21uHX_bBb2UXZSrJdsb7Z_JlM,2647
41
+ autoverse_cli-0.13.0.dist-info/METADATA,sha256=BfcjUahE-gYGu1KOz5TyT37hFMoza8LAUHHp7LEa2Sk,3342
42
+ autoverse_cli-0.13.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
43
+ autoverse_cli-0.13.0.dist-info/entry_points.txt,sha256=Cb9qsUyU5AKkklehCcvtfT0-N3SXbUEqvjze4iEU5kE,40
44
+ autoverse_cli-0.13.0.dist-info/top_level.txt,sha256=-AJO2e4MCVej6hY0U84pu5NfMeMW5qaAPSMisDT5rmA,5
45
+ autoverse_cli-0.13.0.dist-info/RECORD,,
avrs/app_version.py CHANGED
@@ -2,7 +2,7 @@ import http.client
2
2
  import json
3
3
 
4
4
  def get_app_version():
5
- return '0.12.6'
5
+ return '0.13.0'
6
6
 
7
7
  def check_app_is_latest():
8
8
  pass
avrs/avrs.py CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env python3
2
+ import logging
2
3
  import argparse
3
4
  from argparse import RawDescriptionHelpFormatter
4
5
  from argparse import RawTextHelpFormatter
@@ -37,7 +38,45 @@ from avrs.requests.dump_sim_config import *
37
38
  def get_version():
38
39
  return get_app_version()
39
40
 
41
+ def init_logging():
42
+ max_log_size = 1024 * 512
43
+ log_path = os.path.join(get_cfg_dir('avrs'), 'avrs.log')
44
+ verbose_log_path = os.path.join(get_cfg_dir('avrs'), 'avrs_verbose.log')
45
+
46
+ if os.path.exists(verbose_log_path) and os.path.getsize(verbose_log_path) > max_log_size:
47
+ os.remove(verbose_log_path)
48
+ if os.path.exists(log_path) and os.path.getsize(log_path) > max_log_size:
49
+ os.remove(log_path)
50
+
51
+ logging.basicConfig(filename=verbose_log_path,
52
+ filemode='a',
53
+ format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
54
+ datefmt='%H:%M:%S',
55
+ level=logging.DEBUG)
56
+
57
+ # When testing, prevent multiple handler additions to global logging objects
58
+ if 'avrs' in logging.Logger.manager.loggerDict:
59
+ #self.logger = logging.getLogger('alvs')
60
+ del logging.Logger.manager.loggerDict['avrs']
61
+ #return
62
+ logger = logging.getLogger('avrs')
63
+ file_handler = logging.FileHandler(log_path)
64
+ file_handler.setLevel(logging.DEBUG)
65
+ formatter = logging.Formatter('%(asctime)s | %(levelname)s | %(message)s')
66
+ file_handler.setFormatter(formatter)
67
+ console = logging.StreamHandler()
68
+ console.setLevel(logging.DEBUG)
69
+ console.setFormatter(formatter)
70
+ logger.addHandler(file_handler)
71
+ #logger.addHandler(console)
72
+
40
73
  def main():
74
+
75
+ try:
76
+ init_logging()
77
+ except Exception as e:
78
+ print('failed to init logging: {}'.format(e))
79
+
41
80
  parser = argparse.ArgumentParser(
42
81
  prog='avrs',
43
82
  description='Autoverse CLI',
@@ -98,6 +137,5 @@ def main():
98
137
  args = parser.parse_args()
99
138
  args.func(args)
100
139
 
101
-
102
140
  if __name__ == '__main__':
103
141
  main()
avrs/launcher.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import os
2
2
  import stat
3
3
  import json
4
+ import logging
4
5
  import http.client
5
6
  import boto3
6
7
  from avrs.cfg import *
@@ -9,6 +10,7 @@ from avrs.launcher_util import *
9
10
  class AvrsLauncher:
10
11
  def __init__(self, parent_parser, cfg):
11
12
  self.cfg = cfg
13
+ self.logger = logging.getLogger('avrs')
12
14
  provision_parser = parent_parser.add_parser(
13
15
  'launcher',
14
16
  help='launcher operations, such as license registration or updating a sim install\n\n')
@@ -101,6 +103,7 @@ class AvrsLauncher:
101
103
 
102
104
 
103
105
  def get_latest_sim_version(self, args):
106
+ self.logger.info('getting latest sim version')
104
107
  # Validate status of download keys
105
108
  dl_keys_ok, dl_keys_status = has_launcher_download_keys(self.cfg)
106
109
  if not dl_keys_ok:
avrs/race_cloud.py CHANGED
@@ -1,8 +1,10 @@
1
1
  import subprocess
2
2
  import base64
3
+ import logging
3
4
  from avrs.cfg import *
4
5
  from avrs.race_cloud_util import *
5
6
  from avrs.race_cloud_cfg_util import *
7
+ from avrs.race_cloud_fwd_api import *
6
8
  from avrs.util import *
7
9
  from avrs.requests.request import AvrsApiRequest
8
10
  from argparse import RawTextHelpFormatter
@@ -112,12 +114,34 @@ class AvrsRaceCloud(AvrsApiRequest):
112
114
  help='the id of the peer to enable')
113
115
  disable_peer_qos_parser.set_defaults(func=self.disable_peer_qos)
114
116
 
117
+ fwd_server_parser = sps.add_parser(
118
+ 'fwd-api',
119
+ help='forwards incoming external api requests to the simulator api')
120
+ fwd_server_parser.add_argument(
121
+ 'source_port',
122
+ type=int,
123
+ help='the external port to listen to external api requests on')
124
+ fwd_server_parser.add_argument(
125
+ 'target_port',
126
+ type=int,
127
+ help='the local port to forward api requests too')
128
+ fwd_server_parser.add_argument(
129
+ '--background',
130
+ action='store_true',
131
+ help='if true, will run the server in the background')
132
+ fwd_server_parser.set_defaults(func=self.fwd_api)
115
133
 
116
134
  def race_connect(self, args):
135
+ logger = logging.getLogger('avrs')
136
+ logger.info('starting race-cloud connect for team {} to instance {}'.format(
137
+ args.team_name, args.sim_index))
117
138
  print('connecting to race with team name: {}'.format(args.team_name))
118
139
 
119
- # validate / load vehicle config
140
+ # reset local connection first
141
+ logger.info('resetting local connection state prior to connection')
142
+ reset_race_cloud_connection()
120
143
 
144
+ # validate / load vehicle config
121
145
  vcfg_ok, vcfg_data, bsu_vcan, kistler_vcan, badenia_vcan = prepare_vehicle_cfg(args.vehicle_config)
122
146
 
123
147
  if not vcfg_ok:
@@ -190,8 +214,16 @@ class AvrsRaceCloud(AvrsApiRequest):
190
214
 
191
215
  print('connection success with team name {} and slot id {}'.format(args.team_name, sim_slot))
192
216
 
217
+ # if sim slot is not 0, which means domain id is not 0, notify user
218
+ if sim_slot != 0:
219
+ print('your ROS2 interfaces will be available on ROS_DOMAIN_ID {}'.format(sim_slot))
220
+ print('you will need to set the ROS_DOMAIN_ID environment variable prior to echoing or running software')
221
+ print('(eg \"export ROS_DOMAIN_ID={}\")'.format(sim_slot))
222
+
193
223
  # this should only run on sim instances (not dev instances)
194
224
  def rx_connect(self, args):
225
+ logger = logging.getLogger('avrs')
226
+ logger.info('rx race cloud connection for team {} with ip {}'.format(args.team_name, args.ip))
195
227
  ok, msg, slot = try_get_open_slot(args.team_name, args.ip)
196
228
 
197
229
  bsu_vcan = get_auto_vcan_name(slot, 0)
@@ -223,7 +255,9 @@ class AvrsRaceCloud(AvrsApiRequest):
223
255
  return
224
256
 
225
257
  if ok:
258
+ logger.info('enabling qos for slot {} with ip {}'.format(slot, args.ip))
226
259
  enable_peer_qos(slot, args.ip)
260
+ logger.info('connecting vcans for incoming connection')
227
261
  connect_peer_vcan(slot, args.ip, 0)
228
262
  connect_peer_vcan(slot, args.ip, 1)
229
263
  connect_peer_vcan(slot, args.ip, 2)
@@ -243,21 +277,26 @@ class AvrsRaceCloud(AvrsApiRequest):
243
277
  self.remote_sim_ctrl(args)
244
278
 
245
279
  def local_sim_ctrl(self, args):
280
+ logger = logging.getLogger('avrs')
246
281
  if args.action == 'reset-connection':
282
+ logger.info('resetting local race-cloud connection states')
247
283
  print('resetting race cloud connection')
248
284
  print('resetting qos file, removing CAN lock files, stopping all cannelloni instances')
249
285
  reset_race_cloud_connection()
250
286
  if args.clear_autospawns:
251
287
  clear_autospawns()
252
288
  if args.action == 'stop' or args.action == 'restart':
253
- print('stopping sim program on sim instance {}'.format(args.sim_index))
289
+ logger.info('stopping race-cloud simulator program')
290
+ print('stopping sim program on sim instance')
254
291
  bash_kill_process('Autoverse')
255
292
  if args.action == 'start' or args.action == 'restart':
256
- print('starting sim program on sim instance {}'.format(args.sim_index))
293
+ logger.info('starting race-cloud simulator program')
294
+ print('starting sim program on sim instance')
257
295
  exe_path = os.path.join(get_sim_exe_path())
258
296
  start_exe(exe_path)
259
297
 
260
298
  def remote_sim_ctrl(self, args):
299
+ logger = logging.getLogger('avrs')
261
300
 
262
301
  # go ahead and reset local connection as well
263
302
  if args.action == 'reset-connection':
@@ -273,6 +312,8 @@ class AvrsRaceCloud(AvrsApiRequest):
273
312
  'ensure_instance_is_running': False
274
313
  }
275
314
 
315
+ logger.info('sending race-clolud sim-ctrl request: {}'.format(reset_request))
316
+
276
317
  ok, response = call_race_cloud_api(reset_request)
277
318
  #print(response)
278
319
  if not ok:
@@ -298,4 +339,17 @@ class AvrsRaceCloud(AvrsApiRequest):
298
339
 
299
340
  def disable_peer_qos(self, args):
300
341
  print('disabling peer qos for id {}'.format(args.peer_id))
301
- disable_peer_qos(args.peer_id)
342
+ disable_peer_qos(args.peer_id)
343
+
344
+ def fwd_api(self, args):
345
+ # start a server that listens for http on some port and forwards
346
+ # to the simulator on 30313
347
+
348
+ if args.background:
349
+ # call the cli so that it starts the forwarding server in the background
350
+ start_exe('avrs race-cloud fwd-api {} {}'.format(
351
+ args.source_port, args.target_port))
352
+ else:
353
+ handler = ApiForwardHandler(args.target_port)
354
+ server = HTTPServer(('0.0.0.0', args.source_port), handler)
355
+ server.serve_forever()
@@ -1,112 +1,140 @@
1
1
  import os
2
2
  import json
3
3
  import base64
4
+ import logging
4
5
 
5
6
  from avrs.simconfig_util import *
6
7
 
7
8
  def get_payload(cfg_object, payload_name):
8
- for p in cfg_object['payloads']:
9
- if p['typeName'] == payload_name:
10
- return p
11
- return None
9
+ for p in cfg_object['payloads']:
10
+ if p['typeName'] == payload_name:
11
+ return p
12
+ return None
12
13
 
13
14
  def clear_autospawns():
14
- # also need to edit the yas_marina_env.json to have autospawn for this config
15
- sim_path = os.environ.get('AVRS_INSTALL_PATH',
16
- os.path.join(os.environ['HOME'], 'autoverse-linux'))
17
- sim_saved = os.path.join(sim_path, 'Linux', 'Autoverse', 'Saved')
18
- cfg_files = SimConfigFiles(sim_saved)
15
+ # also need to edit the yas_marina_env.json to have autospawn for this config
16
+ sim_path = os.environ.get('AVRS_INSTALL_PATH',
17
+ os.path.join(os.environ['HOME'], 'autoverse-linux'))
18
+ sim_saved = os.path.join(sim_path, 'Linux', 'Autoverse', 'Saved')
19
+ cfg_files = SimConfigFiles(sim_saved)
19
20
 
20
- cfg_ok, msg = cfg_files.validate()
21
- if not cfg_ok:
22
- print(msg)
23
- return
21
+ cfg_ok, msg = cfg_files.validate()
22
+ if not cfg_ok:
23
+ print(msg)
24
+ return
24
25
 
25
- cfg_files.files['yas']['autoSpawnObjects'] = []
26
- cfg_files.files['main']['objectTemplatePaths'] = []
27
- cfg_files.save()
26
+ cfg_files.files['yas']['autoSpawnObjects'] = []
27
+ cfg_files.files['main']['objectTemplatePaths'] = []
28
+ cfg_files.save()
28
29
 
29
30
  def register_received_vehicle(team_name, slot, cfg_data, bsu_vcan, kistler_vcan, badenia_vcan):
30
- cfg_string = base64.b64decode(cfg_data)
31
- cfg_object = json.loads(cfg_string.decode('utf-8'))
32
-
33
- # ensure perception is disabled
34
- eav24 = get_payload(cfg_object, 'Eav24Initializer')
35
- if eav24 is None:
36
- return (False, 'no eav24 payload found')
37
-
38
- eav24['body']['bLidarEnabled'] = False
39
- eav24['body']['bCameraEnabled'] = False
40
- eav24['body']['bRadarEnabled'] = False
41
- eav24['body']['bPublishGroundTruth'] = False
42
- eav24['body']['bPublishInputs'] = False
43
- eav24['body']['bsuCanName'] = bsu_vcan
44
- eav24['body']['kistlerCanName'] = kistler_vcan
45
- eav24['body']['badeniaCanName'] = badenia_vcan
46
-
47
- # do not allow default object name (collision)
48
- if cfg_object['name'] == 'eav24':
49
- cfg_object['name'] = team_name
50
- cfg_object['specName'] = 'eav24_{}'.format(team_name)
51
-
52
- # also need to edit the yas_marina_env.json to have autospawn for this config
53
- sim_path = os.environ.get('AVRS_INSTALL_PATH',
54
- os.path.join(os.environ['HOME'], 'autoverse-linux'))
55
- sim_saved = os.path.join(sim_path, 'Linux', 'Autoverse', 'Saved')
56
- cfg_files = SimConfigFiles(sim_saved)
57
-
58
- cfg_ok, msg = cfg_files.validate()
59
- if not cfg_ok:
60
- print(msg)
61
- return
62
-
63
- start_landmark = 'MvStart{}'.format(slot)
64
-
65
- entry_exists = False
66
- for i in cfg_files.files['yas']['autoSpawnObjects']:
67
- if 'objectSpec' in i and i['objectSpec'] == cfg_object['specName']:
68
- entry_exists = True
69
-
70
- if not entry_exists:
71
- cfg_files.files['yas']['autoSpawnObjects'].append({
72
- 'bShouldSpawn': True,
73
- 'objectType': 'Eav24',
74
- 'objectSpec': cfg_object['specName'],
75
- 'bSpawnAtLandmark': True,
76
- 'spawnLandmarkName': start_landmark
77
- })
78
-
79
- # also need to add the object template to main sim config
80
-
81
- new_cfg_name = 'eav24_{}.json'.format(team_name)
82
- cfg_files.files['main']['objectTemplatePaths'].append(os.path.join('Objects', new_cfg_name))
83
- cfg_files.save()
84
-
85
- target_path = os.path.join(sim_saved, 'Objects', new_cfg_name)
86
- with open(target_path, 'w', encoding='utf-8') as f:
87
- json.dump(cfg_object, f, ensure_ascii=False, indent=4)
31
+ logger = logging.getLogger('avrs')
32
+ logger.info('registering received vehicle in slot {} for team {}'.format(slot, team_name))
33
+
34
+ cfg_string = base64.b64decode(cfg_data)
35
+ cfg_object = json.loads(cfg_string.decode('utf-8'))
36
+
37
+ # ensure perception is disabled
38
+ eav24 = get_payload(cfg_object, 'Eav24Initializer')
39
+ if eav24 is None:
40
+ return (False, 'no eav24 payload found')
41
+
42
+ logger.info('disabling perception for received vehicle config')
43
+ eav24['body']['bLidarEnabled'] = False
44
+ eav24['body']['bCameraEnabled'] = False
45
+ eav24['body']['bRadarEnabled'] = False
46
+ eav24['body']['bPublishGroundTruth'] = False
47
+ eav24['body']['bPublishInputs'] = False
48
+
49
+ logger.info('setting bsu vcan to: {}, kistler to: {}, and badenia to: {}'.format(
50
+ bsu_vcan, kistler_vcan, badenia_vcan))
51
+ eav24['body']['bsuCanName'] = bsu_vcan
52
+ eav24['body']['kistlerCanName'] = kistler_vcan
53
+ eav24['body']['badeniaCanName'] = badenia_vcan
54
+
55
+ ros2 = get_payload(cfg_object, 'Ros2')
56
+ if ros2 is None:
57
+ logger.info('no ros2 payload found. adding with domain id {}'.format(slot))
58
+ # need to add a ros2 payload for domain id
59
+ cfg_object['payloads'].append({
60
+ 'typeName': 'Ros2',
61
+ 'body': {
62
+ 'domainId': slot
63
+ }
64
+ })
65
+ else:
66
+ logger.info('found Ros2 payload OK'.format())
67
+
68
+ # do not allow default object name (collision)
69
+ if cfg_object['name'] == 'eav24':
70
+ logger.info('setting vehicle name from default to team name: {}'.format(team_name))
71
+ cfg_object['name'] = team_name
72
+ cfg_object['specName'] = 'eav24_{}'.format(team_name)
73
+
74
+ # also need to edit the yas_marina_env.json to have autospawn for this config
75
+ sim_path = os.environ.get('AVRS_INSTALL_PATH',
76
+ os.path.join(os.environ['HOME'], 'autoverse-linux'))
77
+ sim_saved = os.path.join(sim_path, 'Linux', 'Autoverse', 'Saved')
78
+ cfg_files = SimConfigFiles(sim_saved)
79
+
80
+ cfg_ok, msg = cfg_files.validate()
81
+ if not cfg_ok:
82
+ print(msg)
83
+ return
84
+
85
+ start_landmark = 'MvStart{}'.format(slot)
86
+
87
+ entry_exists = False
88
+ for i in cfg_files.files['yas']['autoSpawnObjects']:
89
+ if 'objectSpec' in i and i['objectSpec'] == cfg_object['specName']:
90
+ entry_exists = True
91
+ logger.info('config is already in auto spawn list')
92
+
93
+ if not entry_exists:
94
+ logger.info('config is not in auto spawn list. adding')
95
+ cfg_files.files['yas']['autoSpawnObjects'].append({
96
+ 'bShouldSpawn': True,
97
+ 'objectType': 'Eav24',
98
+ 'objectSpec': cfg_object['specName'],
99
+ 'bSpawnAtLandmark': True,
100
+ 'spawnLandmarkName': start_landmark
101
+ })
102
+
103
+ # also need to add the object template to main sim config
104
+
105
+ new_cfg_name = 'eav24_{}.json'.format(team_name)
106
+ cfg_files.files['main']['objectTemplatePaths'].append(os.path.join('Objects', new_cfg_name))
107
+ logger.info('saving config file: {}'.format(new_cfg_name))
108
+ cfg_files.save()
109
+
110
+ target_path = os.path.join(sim_saved, 'Objects', new_cfg_name)
111
+ with open(target_path, 'w', encoding='utf-8') as f:
112
+ json.dump(cfg_object, f, ensure_ascii=False, indent=4)
88
113
 
89
114
  def prepare_vehicle_cfg(cfg_path):
115
+ logger = logging.getLogger('avrs')
116
+ #print('preparing config for transmission: {}'.format(cfg_path))
90
117
 
91
- #print('preparing config for transmission: {}'.format(cfg_path))
118
+ if not os.path.isfile(cfg_path):
119
+ return (False, '{} is not a valid file'.format(cfg_path), None, None, None)
92
120
 
93
- if not os.path.isfile(cfg_path):
94
- return (False, '{} is not a valid file'.format(cfg_path), None, None, None)
121
+ cfg_object = {}
122
+ with open(cfg_path, 'r', encoding='utf-8') as f:
123
+ cfg_object = json.load(f)
95
124
 
96
- cfg_object = {}
97
- with open(cfg_path, 'r', encoding='utf-8') as f:
98
- cfg_object = json.load(f)
99
125
 
126
+ # obtain desired CAN names to start cannelloni
127
+ eav24 = get_payload(cfg_object, 'Eav24Initializer')
128
+ if eav24 is None:
129
+ return (False, 'no eav24 payload found', None, None, None)
100
130
 
101
- # obtain desired CAN names to start cannelloni
102
- eav24 = get_payload(cfg_object, 'Eav24Initializer')
103
- if eav24 is None:
104
- return (False, 'no eav24 payload found', None, None, None)
131
+ bsu_vcan = eav24['body']['bsuCanName']
132
+ kistler_vcan = eav24['body']['kistlerCanName']
133
+ badenia_vcan = eav24['body']['badeniaCanName']
105
134
 
106
- bsu_vcan = eav24['body']['bsuCanName']
107
- kistler_vcan = eav24['body']['kistlerCanName']
108
- badenia_vcan = eav24['body']['badeniaCanName']
135
+ logger.info('detected vcan names from sent config: bsu {}, kistler {}, badenia {}'.format(
136
+ bsu_vcan, kistler_vcan, badenia_vcan))
109
137
 
110
- cfg_data = base64.b64encode(json.dumps(cfg_object).encode('utf-8')).decode('utf-8')
111
- return (True, cfg_data, bsu_vcan, kistler_vcan, badenia_vcan)
138
+ cfg_data = base64.b64encode(json.dumps(cfg_object).encode('utf-8')).decode('utf-8')
139
+ return (True, cfg_data, bsu_vcan, kistler_vcan, badenia_vcan)
112
140
 
@@ -0,0 +1,43 @@
1
+ import argparse
2
+ import json
3
+ import re
4
+ import threading
5
+ import http
6
+ from http import HTTPStatus
7
+ from http.server import BaseHTTPRequestHandler, HTTPServer
8
+
9
+ # https://gist.github.com/dfrankow/f91aefd683ece8e696c26e183d696c29
10
+
11
+ class ApiForwardHandler(BaseHTTPRequestHandler):
12
+ def __init__(self, target_port):
13
+ self.target_port = target_port
14
+
15
+ # allows to be passed to the HTTPServer ctor
16
+ def __call__(self, *args, **kwargs):
17
+ """Handle a request."""
18
+ super().__init__(*args, **kwargs)
19
+
20
+ def do_POST(self):
21
+
22
+ length = int(self.headers.get('content-length'))
23
+ rfile_str = self.rfile.read(length).decode('utf8')
24
+ sim_response = self.get_fwd_response(rfile_str)
25
+ self.wfile.write(data.encode(sim_response))
26
+ self.send_response(HTTPStatus.OK)
27
+ self.end_headers()
28
+
29
+ def get_fwd_response(self, body):
30
+ connection = http.client.HTTPConnection('localhost', self.target_port, timeout=3)
31
+ headers = {
32
+ 'Content-type': 'application/json',
33
+ }
34
+ body = json.dumps(body).encode('utf-8')
35
+ connection.request('POST', '/post', body, headers)
36
+ response = connection.getresponse()
37
+ response_string = ''
38
+ if response.status != 200:
39
+ pass
40
+ else:
41
+ response_string = response.read().decode('utf-8')
42
+ return response_string
43
+
avrs/race_cloud_util.py CHANGED
@@ -1,6 +1,7 @@
1
1
  import os
2
2
  import json
3
3
  import http.client
4
+ import logging
4
5
  from avrs.util import *
5
6
 
6
7
  BASH_KILL_PROCESS_SCRIPT = '''
@@ -92,7 +93,7 @@ CONNECT_PEER_VCAN_SCRIPT = '''
92
93
  if [[ -z $VCAN_NAME ]]; then
93
94
  VCAN_NAME=vcan$PEER_ID
94
95
  fi
95
- echo "connecting peer id $PEER_ID using local port $LOCAL_PORT and remote port $REMOTE_PORT and vcan name $VCAN_NAME"
96
+ echo "connecting peer id $PEER_ID using local port $LOCAL_PORT and remote port $REMOTE_PORT and vcan name $VCAN_NAME" > "$LOG_FILE" 2>&1
96
97
 
97
98
  if [[ -e $LOCK_FILE ]]; then
98
99
  echo "stopping existing cannelloni connection with pid $(cat $LOCK_FILE)"
@@ -101,7 +102,7 @@ CONNECT_PEER_VCAN_SCRIPT = '''
101
102
 
102
103
  # https://stackoverflow.com/questions/29142/getting-ssh-to-execute-a-command-in-the-background-on-target-machine
103
104
  # nohup to avoid SSH issues, send stdout to loni.log, send stderr to stdout, dont expect input, and background with "&"
104
- nohup cannelloni -I $VCAN_NAME -R $PEER_ADDRESS -r $REMOTE_PORT -l $LOCAL_PORT >"$LOG_FILE" 2>&1 < /dev/null &
105
+ nohup cannelloni -I $VCAN_NAME -R $PEER_ADDRESS -r $REMOTE_PORT -l $LOCAL_PORT >>"$LOG_FILE" 2>&1 < /dev/null &
105
106
  echo "$!" > $LOCK_FILE
106
107
  '''
107
108
 
@@ -136,7 +137,7 @@ def get_sim_install_path():
136
137
  def get_sim_exe_path():
137
138
  exe_path = os.environ.get('AVRS_EXE_PATH',
138
139
  os.path.join(os.environ['HOME'], 'autoverse-linux', 'Linux', 'utils', 'run_autoverse.sh'))
139
- return exe_path()
140
+ return exe_path
140
141
 
141
142
  def get_rmw_qos_path():
142
143
  return os.path.join(os.environ['HOME'], '.rmw_qos.xml')
@@ -177,6 +178,7 @@ def get_auto_vcan_name(peer_id, vcan_id):
177
178
  return 'vcan{}_{}'.format(peer_id, vcan_id)
178
179
 
179
180
  def connect_peer_vcan(peer_id, peer_ip, vcan_id, vcan_name=''):
181
+ logger = logging.getLogger('avrs')
180
182
  vcan_id = 0
181
183
  pargs = {
182
184
  'peer_id': peer_id,
@@ -185,6 +187,7 @@ def connect_peer_vcan(peer_id, peer_ip, vcan_id, vcan_name=''):
185
187
  'local_port': 20000 + peer_id * 3 + vcan_id,
186
188
  'vcan_name': vcan_name if vcan_name != '' else get_auto_vcan_name(peer_id, vcan_id)
187
189
  }
190
+ logger.info('connecting vcan with args: {}'.format(pargs))
188
191
  return run_process(['bash', '-c',
189
192
  CONNECT_PEER_VCAN_SCRIPT.format(**pargs)])
190
193
 
@@ -204,8 +207,9 @@ def reset_race_cloud_connection():
204
207
  bash_kill_process('cannelloni')
205
208
 
206
209
  def try_get_open_slot(team_name, ip):
207
-
210
+ logger = logging.getLogger('avrs')
208
211
  slot_file_dir = os.environ['HOME']
212
+ logger.info('finding a slot for team {}'.format(team_name))
209
213
  for i in range(6):
210
214
  slot_file_path = os.path.join(slot_file_dir, '.simslot_{}'.format(i))
211
215
 
@@ -213,15 +217,20 @@ def try_get_open_slot(team_name, ip):
213
217
  with open(slot_file_path, 'r', encoding='utf-8') as f:
214
218
  content = f.read()
215
219
  if content == ip:
220
+ logger.info('slot {} already reserved by team {}'.format(i, team_name))
216
221
  return (True, 'slot {} is already reserved by you'.format(i), i)
217
222
  else:
218
223
  with open(slot_file_path, 'w', encoding='utf-8') as f:
219
224
  f.write(ip)
225
+ logger.info('slot {} successfuly reserved by team {}'.format(i, team_name))
220
226
  return (True, 'reserved slot {}'.format(i), i)
227
+ logger.info('no open slot found for team {}'.format(team_name))
221
228
  return (False, 'no open slots', i)
222
229
 
223
-
224
230
  def call_race_cloud_api(body):
231
+ logger = logging.getLogger('avrs')
232
+ logger.info('calling race-cloud api with body: {}'.format(body))
233
+
225
234
  api_url = 'gitzels0l7.execute-api.us-east-1.amazonaws.com'
226
235
 
227
236
  connection = http.client.HTTPSConnection(api_url)
@@ -238,6 +247,8 @@ def call_race_cloud_api(body):
238
247
 
239
248
  def get_api_script_response(raw):
240
249
  decoded = json.loads(raw)['body']
250
+ logger = logging.getLogger('avrs')
251
+ logger.info('race cloud api response: {}'.format(decoded))
241
252
  if decoded['script_response']['statusCode'] != 200:
242
253
  return (False, 'inner response had bad status code {}'.format(decoded))
243
254
  #print(decoded)