forked from 5152Alotobots/5152_Reefscape
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquest-tools.ps1
More file actions
731 lines (602 loc) · 24 KB
/
quest-tools.ps1
File metadata and controls
731 lines (602 loc) · 24 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
#!/usr/bin/env pwsh
# Quest Development Tools PowerShell Script
$APP_PACKAGE = "com.DerpyCatAviationLLC.QuestNav"
$QUEST_PORT = 5555
# Colors for output
function Write-ColorOutput {
param (
[Parameter(Mandatory=$true)]
[string]$Message,
[Parameter(Mandatory=$true)]
[string]$Color
)
$originalColor = $host.UI.RawUI.ForegroundColor
$host.UI.RawUI.ForegroundColor = $Color
Write-Output $Message
$host.UI.RawUI.ForegroundColor = $originalColor
}
function Print-Help {
Write-ColorOutput "Quest Development Tools" "Yellow"
Write-Output "Usage: .\quest-tools.ps1 [command] [team_number]"
Write-Output ""
Write-Output "Commands:"
Write-Output " connect <team> - Find and connect to Quest on robot network (e.g., 5152)"
Write-Output " status - Check ADB connection status (shows USB and network devices)"
Write-Output " restart - Restart the QuestNav app"
Write-Output " reboot - Reboot the Quest"
Write-Output " enableWifi - Enable wireless debugging (USB connection only)"
Write-Output " kill - Force kill ADB server"
}
function Check-Adb {
try {
$null = Get-Command adb -ErrorAction Stop
return $true
} catch {
Write-ColorOutput "Error: ADB not found. Please install Android platform tools." "Red"
return $false
}
}
function Ensure-Connected {
$job = Start-Job -ScriptBlock { & adb devices }
$completed = Wait-Job -Job $job -Timeout 5
if ($null -eq $completed) {
Write-ColorOutput "ADB command timed out checking connection." "Red"
Stop-Job -Job $job
Remove-Job -Job $job -Force
return $false
}
$devices = Receive-Job -Job $job
Remove-Job -Job $job
if (-not ($devices -match "device$")) {
Write-ColorOutput "Error: No Quest connected. Check with 'status' command first." "Red"
return $false
}
return $true
}
function Force-Kill-Adb {
Write-ColorOutput "Force killing all ADB processes..." "Yellow"
# Try graceful kill first
& adb kill-server > $null
# Find and kill any remaining ADB processes
$processes = Get-Process | Where-Object { $_.Name -eq "adb" }
if ($processes) {
foreach ($process in $processes) {
Write-Output "Killing ADB process with ID $($process.Id)"
Stop-Process -Id $process.Id -Force
}
}
# Give it a moment
Start-Sleep -Seconds 2
# Check if any ADB processes remain
$processes = Get-Process | Where-Object { $_.Name -eq "adb" }
if ($processes) {
Write-ColorOutput "Warning: Some ADB processes could not be killed." "Red"
return $false
} else {
Write-ColorOutput "All ADB processes killed successfully." "Green"
return $true
}
}
function Find-Quest {
param (
[Parameter(Mandatory=$true)]
[string]$Team
)
$subnet1 = "10." + $Team.Substring(0,2)
$subnet2 = $Team.Substring(2,2)
$subnetFull = "$subnet1.$subnet2"
Write-ColorOutput "Scanning network $subnetFull.0/24 for Quest..." "Green"
# Check if nmap is installed
try {
$null = Get-Command nmap -ErrorAction Stop
} catch {
Write-ColorOutput "Error: nmap not found. Please install nmap first." "Red"
return $false
}
# Kill any existing ADB server first
Force-Kill-Adb > $null
# Start ADB server with timeout
$serverJob = Start-Job -ScriptBlock { & adb start-server }
$serverCompleted = Wait-Job -Job $serverJob -Timeout 10
if ($null -eq $serverCompleted) {
Write-ColorOutput "ADB server start timed out." "Red"
Stop-Job -Job $serverJob
Remove-Job -Job $serverJob -Force
Force-Kill-Adb
return $false
}
Receive-Job -Job $serverJob > $null
Remove-Job -Job $serverJob
# Use nmap to quickly scan network, excluding specific addresses
Write-Output "Running quick network scan..."
$scanExclude = "$subnetFull.1,$subnetFull.2"
$scanTarget = "$subnetFull.0/24"
$scan = & nmap -n -sn --exclude $scanExclude $scanTarget | Select-String "Nmap scan report for"
foreach ($line in $scan) {
# Extract IP address - the last word in the line
$ip = $line -replace '.*Nmap scan report for ',''
Write-ColorOutput "Found device at $ip, attempting ADB connection..." "Yellow"
# Try ADB connect with timeout
$connectJob = Start-Job -ScriptBlock {
param($ip, $port)
& adb connect "$ip`:$port"
} -ArgumentList $ip, $QUEST_PORT
$connectCompleted = Wait-Job -Job $connectJob -Timeout 10
if ($null -eq $connectCompleted) {
Write-ColorOutput "Connection attempt timed out, moving to next device..." "Red"
Stop-Job -Job $connectJob
Remove-Job -Job $connectJob -Force
continue
}
Receive-Job -Job $connectJob > $null
Remove-Job -Job $connectJob
# Check if device connected with timeout
$deviceJob = Start-Job -ScriptBlock { & adb devices }
$deviceCompleted = Wait-Job -Job $deviceJob -Timeout 5
if ($null -eq $deviceCompleted) {
Write-ColorOutput "Device check timed out, moving to next device..." "Red"
Stop-Job -Job $deviceJob
Remove-Job -Job $deviceJob -Force
continue
}
$devices = Receive-Job -Job $deviceJob
Remove-Job -Job $deviceJob
if ($devices -match "$ip`:$QUEST_PORT") {
Write-ColorOutput "Successfully connected to Quest!" "Green"
return $true
}
# Disconnect with timeout
$disconnectJob = Start-Job -ScriptBlock {
param($ip, $port)
& adb disconnect "$ip`:$port"
} -ArgumentList $ip, $QUEST_PORT
Wait-Job -Job $disconnectJob -Timeout 5 > $null
Stop-Job -Job $disconnectJob
Remove-Job -Job $disconnectJob -Force
}
Write-ColorOutput "Could not find Quest on network" "Red"
return $false
}
function Restart-App {
Write-Output "Restarting QuestNav..."
# Store connection information with timeout
$deviceJob = Start-Job -ScriptBlock { & adb devices }
$deviceCompleted = Wait-Job -Job $deviceJob -Timeout 5
if ($null -eq $deviceCompleted) {
Write-ColorOutput "Device check timed out." "Red"
Stop-Job -Job $deviceJob
Remove-Job -Job $deviceJob -Force
return $false
}
$devices = Receive-Job -Job $deviceJob
Remove-Job -Job $deviceJob
# Determine connection type (USB or Network)
$isUSB = $false
$isNetwork = $false
$deviceId = $null
$deviceIp = $null
foreach ($line in $devices) {
# Check for USB connection - device ID without port
if ($line -match "^([0-9A-Za-z]+)[^:]*device$") {
$isUSB = $true
$deviceId = $matches[1]
Write-Output "Detected USB-connected device: $deviceId"
break
}
# Check for network connection
elseif ($line -match "([0-9.]+):$QUEST_PORT") {
$isNetwork = $true
$deviceIp = $matches[1]
Write-Output "Detected network-connected device: $deviceIp`:$QUEST_PORT"
break
}
}
if (-not ($isUSB -or $isNetwork)) {
Write-ColorOutput "Error: No connected Quest devices found." "Red"
return $false
}
# Force stop the app with timeout
Write-Output "Stopping QuestNav app..."
$stopJob = Start-Job -ScriptBlock {
param($package)
try {
# Redirect output to avoid PowerShell treating it as an error
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = "adb"
$psi.Arguments = "shell am force-stop $package"
$psi.UseShellExecute = $false
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$process = [System.Diagnostics.Process]::Start($psi)
$stdout = $process.StandardOutput.ReadToEnd()
$stderr = $process.StandardError.ReadToEnd()
$process.WaitForExit()
return @{
ExitCode = $process.ExitCode
StdOut = $stdout
StdErr = $stderr
}
} catch {
return @{
ExitCode = 1
StdOut = ""
StdErr = "Error: $_"
}
}
} -ArgumentList $APP_PACKAGE
$stopCompleted = Wait-Job -Job $stopJob -Timeout 10
if ($null -eq $stopCompleted) {
Write-ColorOutput "App stop command timed out." "Red"
Stop-Job -Job $stopJob
Remove-Job -Job $stopJob -Force
return $false
}
$stopResult = Receive-Job -Job $stopJob
Remove-Job -Job $stopJob
if ($stopResult.ExitCode -ne 0) {
Write-ColorOutput "Error stopping app: $($stopResult.StdErr)" "Red"
}
# Give a moment for the app to stop
Start-Sleep -Seconds 3
# Start the app directly with timeout
Write-Output "Starting QuestNav app..."
$startJob = Start-Job -ScriptBlock {
param($package)
try {
# Redirect output to avoid PowerShell treating it as an error
$psi = New-Object System.Diagnostics.ProcessStartInfo
$psi.FileName = "adb"
$psi.Arguments = "shell monkey -p $package 1"
$psi.UseShellExecute = $false
$psi.RedirectStandardOutput = $true
$psi.RedirectStandardError = $true
$process = [System.Diagnostics.Process]::Start($psi)
$stdout = $process.StandardOutput.ReadToEnd()
$stderr = $process.StandardError.ReadToEnd()
$process.WaitForExit()
# Return a custom object with exit code and output
return @{
ExitCode = $process.ExitCode
StdOut = $stdout
StdErr = $stderr
}
} catch {
return @{
ExitCode = 1
StdOut = ""
StdErr = "Error: $_"
}
}
} -ArgumentList $APP_PACKAGE
$startCompleted = Wait-Job -Job $startJob -Timeout 10
if ($null -eq $startCompleted) {
Write-ColorOutput "App start command timed out." "Red"
Stop-Job -Job $startJob
Remove-Job -Job $startJob -Force
return $false
}
$result = Receive-Job -Job $startJob
Remove-Job -Job $startJob
# Check for real errors, not just the normal monkey output
if ($result.ExitCode -ne 0 -or $result.StdErr -match "Error:") {
Write-ColorOutput "Error starting app: $($result.StdErr)" "Red"
return $false
}
Write-Output "App launch command sent successfully."
if ($result.StdOut -match "args:") {
Write-Output "Note: The 'args' output is normal diagnostic info from the monkey tool, not an error."
}
# Wait a moment for the app to start
Start-Sleep -Seconds 5
# Check device status after restart
$checkJob = Start-Job -ScriptBlock { & adb devices }
$checkCompleted = Wait-Job -Job $checkJob -Timeout 5
if ($null -eq $checkCompleted) {
Write-ColorOutput "Device check timed out." "Red"
Stop-Job -Job $checkJob
Remove-Job -Job $checkJob -Force
return $false
}
$devices = Receive-Job -Job $checkJob
Remove-Job -Job $checkJob
# Check connection based on original connection type
if ($isNetwork) {
# For network connection, check if we need to reconnect
if ($devices -notmatch "$QUEST_PORT") {
Write-Output "Network reset detected, attempting to reconnect..."
$disconnectJob = Start-Job -ScriptBlock { & adb disconnect }
Wait-Job -Job $disconnectJob -Timeout 5 > $null
Stop-Job -Job $disconnectJob
Remove-Job -Job $disconnectJob -Force
Start-Sleep -Seconds 2
# Try to reconnect multiple times with increasing delays
for ($i = 1; $i -le 5; $i++) {
Write-Output "Reconnection attempt $i..."
$reconnectJob = Start-Job -ScriptBlock {
param($ip, $port)
& adb connect "$ip`:$port"
} -ArgumentList $deviceIp, $QUEST_PORT
$reconnectCompleted = Wait-Job -Job $reconnectJob -Timeout 10
if ($null -eq $reconnectCompleted) {
Write-ColorOutput "Reconnection attempt $i timed out." "Red"
Stop-Job -Job $reconnectJob
Remove-Job -Job $reconnectJob -Force
Start-Sleep -Seconds ($i * 2)
continue
}
Receive-Job -Job $reconnectJob > $null
Remove-Job -Job $reconnectJob
# Increasing delay between attempts
Start-Sleep -Seconds ($i * 2)
$checkJob = Start-Job -ScriptBlock { & adb devices }
$checkCompleted = Wait-Job -Job $checkJob -Timeout 5
if ($null -eq $checkCompleted) {
Write-ColorOutput "Device check timed out on attempt $i." "Red"
Stop-Job -Job $checkJob
Remove-Job -Job $checkJob -Force
continue
}
$devices = Receive-Job -Job $checkJob
Remove-Job -Job $checkJob
if ($devices -match "$QUEST_PORT") {
Write-ColorOutput "Successfully reconnected!" "Green"
Write-ColorOutput "App restarted successfully" "Green"
return $true
}
}
Write-ColorOutput "Failed to reconnect. The network interface might need more time to stabilize." "Red"
Write-Output "You can try: .\quest-tools.ps1 connect [team] to reconnect manually."
return $false
}
}
elseif ($isUSB) {
# For USB connection, just check if the device is still connected
if ($devices -notmatch "device$") {
Write-ColorOutput "USB connection lost after restart." "Red"
Write-Output "Check if the Quest is still connected via USB."
return $false
}
}
Write-ColorOutput "App restarted successfully" "Green"
return $true
}
function Check-Device-Status {
Write-ColorOutput "Checking for connected devices..." "Green"
if (-not (Check-Adb)) {
return $false
}
# Make sure ADB server is running
$serverJob = Start-Job -ScriptBlock { & adb start-server }
$serverCompleted = Wait-Job -Job $serverJob -Timeout 10
if ($null -eq $serverCompleted) {
Write-ColorOutput "ADB server start timed out." "Red"
Stop-Job -Job $serverJob
Remove-Job -Job $serverJob -Force
# Try to kill and restart
Write-Output "Attempting to kill and restart ADB server..."
Force-Kill-Adb
$restartJob = Start-Job -ScriptBlock { & adb start-server }
$restartCompleted = Wait-Job -Job $restartJob -Timeout 10
if ($null -eq $restartCompleted) {
Write-ColorOutput "ADB server restart also timed out. Try running 'kill' command." "Red"
Stop-Job -Job $restartJob
Remove-Job -Job $restartJob -Force
return $false
}
Receive-Job -Job $restartJob > $null
Remove-Job -Job $restartJob
} else {
Receive-Job -Job $serverJob > $null
Remove-Job -Job $serverJob
}
# Check for connected devices with timeout
$devicesJob = Start-Job -ScriptBlock { & adb devices }
$devicesCompleted = Wait-Job -Job $devicesJob -Timeout 10
if ($null -eq $devicesCompleted) {
Write-ColorOutput "ADB devices command timed out." "Red"
Stop-Job -Job $devicesJob
Remove-Job -Job $devicesJob -Force
Write-ColorOutput "Try running the 'kill' command and then check status again." "Red"
return $false
}
$devices = Receive-Job -Job $devicesJob
Remove-Job -Job $devicesJob
Write-Output "Connected devices:"
Write-Output $devices
$foundUSB = $false
$foundNetwork = $false
# Check for USB devices and network devices
foreach ($line in $devices) {
if ($line -match "device$" -and $line -notmatch ":") {
Write-ColorOutput "USB device detected." "Green"
$foundUSB = $true
} elseif ($line -match "$QUEST_PORT") {
Write-ColorOutput "Network device detected." "Green"
$foundNetwork = $true
}
}
if (-not ($foundUSB -or $foundNetwork)) {
Write-ColorOutput "No Quest devices found. Make sure the Quest is connected and USB debugging is enabled." "Yellow"
Write-Output "Tips:"
Write-Output " 1. For USB connection: Verify the Quest is connected via USB and USB debugging is enabled"
Write-Output " 2. For network connection: Use 'connect [team]' to establish a network connection"
return $false
}
return $true
}
function Enable-Wireless-Debugging {
Write-ColorOutput "Enabling wireless debugging..." "Green"
if (-not (Check-Adb)) {
return $false
}
# Check for USB connection
$deviceJob = Start-Job -ScriptBlock { & adb devices }
$deviceCompleted = Wait-Job -Job $deviceJob -Timeout 5
if ($null -eq $deviceCompleted) {
Write-ColorOutput "Device check timed out." "Red"
Stop-Job -Job $deviceJob
Remove-Job -Job $deviceJob -Force
return $false
}
$devices = Receive-Job -Job $deviceJob
Remove-Job -Job $deviceJob
$isUSB = $false
$deviceId = $null
foreach ($line in $devices) {
# Check for USB connection - device ID without port
if ($line -match "^([0-9A-Za-z]+)[^:]*device$") {
$isUSB = $true
$deviceId = $matches[1]
break
}
}
if (-not $isUSB) {
Write-ColorOutput "Error: No USB-connected Quest found. Wireless debugging can only be enabled via USB." "Red"
Write-Output "Please connect your Quest via USB first."
return $false
}
# Prompt user to connect Ethernet
Write-ColorOutput "IMPORTANT: Please connect your Quest to Ethernet network now." "Yellow"
Write-Output "This will allow wireless debugging over the robot's network."
Write-Output "Press Enter once the Quest is connected to Ethernet..."
$null = Read-Host
# Wait for Ethernet connection to stabilize
Write-Output "Waiting for Ethernet connection to stabilize..."
Start-Sleep -Seconds 5
# Get device IP address (checking Ethernet interfaces)
Write-Output "Getting device IP address..."
$ipJob = Start-Job -ScriptBlock {
# Try to get ethernet IP address - check multiple possible interfaces
$output = & adb shell "ip addr show | grep 'inet ' | grep '10.51.52'"
return $output
}
$ipCompleted = Wait-Job -Job $ipJob -Timeout 10
if ($null -eq $ipCompleted) {
Write-ColorOutput "IP address command timed out." "Red"
Stop-Job -Job $ipJob
Remove-Job -Job $ipJob -Force
return $false
}
$ipAddressOutput = Receive-Job -Job $ipJob
Remove-Job -Job $ipJob
# Extract IP address from the output
$ipAddress = $null
if ($ipAddressOutput -match "inet\s+(\d+\.\d+\.\d+\.\d+)") {
$ipAddress = $matches[1]
}
if (-not $ipAddress) {
Write-ColorOutput "Error: Could not find an IP address on the 10.51.52.X subnet." "Red"
Write-Output "Output from IP check: $ipAddressOutput"
Write-Output "Please make sure the Quest is connected to the robot's Ethernet network."
# Let's try to list all interfaces to help debugging
Write-Output "Available network interfaces:"
$interfacesJob = Start-Job -ScriptBlock {
& adb shell "ip addr"
}
$interfacesCompleted = Wait-Job -Job $interfacesJob -Timeout 10
if ($null -ne $interfacesCompleted) {
$interfaces = Receive-Job -Job $interfacesJob
Write-Output $interfaces
Remove-Job -Job $interfacesJob
} else {
Write-Output "Could not retrieve network interfaces."
Stop-Job -Job $interfacesJob
Remove-Job -Job $interfacesJob -Force
}
return $false
}
Write-ColorOutput "Device IP address: $ipAddress" "Green"
# Enable TCP/IP mode
Write-Output "Enabling TCP/IP mode on port $QUEST_PORT..."
$tcpipJob = Start-Job -ScriptBlock {
param($port)
& adb tcpip $port
} -ArgumentList $QUEST_PORT
$tcpipCompleted = Wait-Job -Job $tcpipJob -Timeout 10
if ($null -eq $tcpipCompleted) {
Write-ColorOutput "TCP/IP command timed out." "Red"
Stop-Job -Job $tcpipJob
Remove-Job -Job $tcpipJob -Force
return $false
}
$tcpipOutput = Receive-Job -Job $tcpipJob
Remove-Job -Job $tcpipJob
Write-Output $tcpipOutput
# Wait for TCP/IP mode to initialize
Start-Sleep -Seconds 3
Write-ColorOutput "Wireless debugging enabled successfully!" "Green"
Write-Output "You can now disconnect the USB cable and connect wirelessly with:"
Write-Output ".\quest-tools.ps1 connect 5152" # Using the specific team number for this use case
Write-Output ""
Write-Output "Or use ADB directly:"
Write-Output "adb connect $ipAddress`:$QUEST_PORT"
# Attempt immediate connection to the wireless device
Write-Output "Attempting to connect to the Quest wirelessly now..."
Start-Sleep -Seconds 2
$connectJob = Start-Job -ScriptBlock {
param($ip, $port)
& adb connect "$ip`:$port"
} -ArgumentList $ipAddress, $QUEST_PORT
$connectCompleted = Wait-Job -Job $connectJob -Timeout 10
if ($null -eq $connectCompleted) {
Write-ColorOutput "Wireless connection attempt timed out." "Yellow"
Stop-Job -Job $connectJob
Remove-Job -Job $connectJob -Force
} else {
$connectResult = Receive-Job -Job $connectJob
Remove-Job -Job $connectJob
Write-Output $connectResult
if ($connectResult -match "connected") {
Write-ColorOutput "Successfully connected to Quest wirelessly!" "Green"
} else {
Write-ColorOutput "Failed to establish wireless connection. Try connecting manually." "Yellow"
}
}
return $true
}
# Main command handler
$command = $args[0]
$param = $args[1]
switch ($command) {
"connect" {
if ([string]::IsNullOrEmpty($param)) {
Write-ColorOutput "Error: Parameter required (team number)" "Red"
break
}
if (Check-Adb) {
Find-Quest $param
}
}
"restart" {
if (Check-Adb -and (Ensure-Connected)) {
Restart-App
}
}
"reboot" {
if (Check-Adb -and (Ensure-Connected)) {
$rebootJob = Start-Job -ScriptBlock { & adb reboot }
$completed = Wait-Job -Job $rebootJob -Timeout 10
if ($null -eq $completed) {
Write-ColorOutput "Reboot command timed out." "Red"
Stop-Job -Job $rebootJob
Remove-Job -Job $rebootJob -Force
} else {
Receive-Job -Job $rebootJob > $null
Remove-Job -Job $rebootJob
Write-ColorOutput "Reboot command sent successfully." "Green"
}
}
}
"status" {
Check-Device-Status
}
"enableWifi" {
Enable-Wireless-Debugging
}
"kill" {
Force-Kill-Adb
}
default {
Print-Help
}
}