()
| 55 | return cmd |
| 56 | |
| 57 | def main(): |
| 58 | parser = argparse.ArgumentParser( |
| 59 | description="Convert GPX file to simctl location start command", |
| 60 | formatter_class=argparse.RawDescriptionHelpFormatter, |
| 61 | epilog=""" |
| 62 | Examples: |
| 63 | python gpx_to_simctl.py test_route.gpx --speed 60 --interval 0.1 |
| 64 | python gpx_to_simctl.py test_route.gpx --speed 80 --distance 10 --clear-first |
| 65 | python gpx_to_simctl.py test_route.gpx --speed 50 --dry-run |
| 66 | """ |
| 67 | ) |
| 68 | |
| 69 | parser.add_argument('gpx_file', help='Input GPX file') |
| 70 | parser.add_argument('--speed', type=float, default=60, |
| 71 | help='Speed in km/h (default: 60)') |
| 72 | parser.add_argument('--interval', type=float, default=0.1, |
| 73 | help='Update interval in seconds (default: 0.1)') |
| 74 | parser.add_argument('--distance', type=float, |
| 75 | help='Update distance in meters (overrides --interval)') |
| 76 | parser.add_argument('--device', default='booted', |
| 77 | help='Target device (default: booted)') |
| 78 | parser.add_argument('--dry-run', action='store_true', |
| 79 | help='Show command without executing (default: execute)') |
| 80 | parser.add_argument('--clear-first', action='store_true', |
| 81 | help='Clear existing location before starting') |
| 82 | |
| 83 | args = parser.parse_args() |
| 84 | |
| 85 | # Validate input file |
| 86 | gpx_file = Path(args.gpx_file) |
| 87 | if not gpx_file.exists(): |
| 88 | print(f"Error: GPX file '{gpx_file}' not found", file=sys.stderr) |
| 89 | return 1 |
| 90 | |
| 91 | try: |
| 92 | # Extract waypoints |
| 93 | points = extract_track_points_from_gpx(gpx_file) |
| 94 | print(f"Extracted {len(points)} waypoints from {gpx_file}") |
| 95 | |
| 96 | if len(points) < 2: |
| 97 | print("Error: Need at least 2 waypoints for location simulation", file=sys.stderr) |
| 98 | return 1 |
| 99 | |
| 100 | # Generate command |
| 101 | cmd = generate_simctl_command( |
| 102 | points, |
| 103 | speed_kmh=args.speed, |
| 104 | interval=args.interval, |
| 105 | distance=args.distance, |
| 106 | device=args.device |
| 107 | ) |
| 108 | |
| 109 | # Show command |
| 110 | print(f"\nGenerated simctl command:") |
| 111 | print(" ".join(cmd)) |
| 112 | |
| 113 | # Calculate simulation info |
| 114 | speed_mps = args.speed / 3.6 |
no test coverage detected