refactored GPS bin

This commit is contained in:
Djeeberjr 2023-05-31 18:57:10 +02:00
parent 06b3e37138
commit 779933be32

View File

@ -1,60 +1,15 @@
package bin; package bin;
import kernel.ps.ProcessHandle; import lib.CLIAppBase;
import kernel.ps.Process;
import kernel.gps.INS; import kernel.gps.INS;
import lib.Pos3; import lib.Pos3;
import lib.Vec.Vec3; import lib.Vec.Vec3;
using tink.CoreApi; using tink.CoreApi;
class GPS implements Process { class GPS extends CLIAppBase {
private var handle:ProcessHandle; public function new() {
registerSyncSubcommand("set", (args)->{
public function new() {}
public function run(handle: ProcessHandle):Void {
this.handle = handle;
var subcommand = handle.args[0];
var subcommand_args = handle.args.slice(1);
switch (subcommand) {
case "set":
handle.close(setManuelPos(subcommand_args));
case "status":
handle.close(getGPSStatus());
case "locate":
kernel.gps.GPS.instance.locate().handle((pos)->{
if (pos != null) {
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
handle.close(true);
} else {
handle.writeLine("Position not available");
handle.close(false);
}
});
case "ins":
INS.instance.align().handle(()->{
handle.writeLine("INS aligned");
handle.close(true);
});
default:
handle.writeLine("Unknown subcommand: " + subcommand);
printHelp();
handle.close(false);
}
}
private function printHelp(){
handle.writeLine("GPS commands:");
handle.writeLine("set <x> <y> <z> - set manual position");
handle.writeLine("status - get current position and accuracy");
handle.writeLine("locate - get current position");
handle.writeLine("ins - align INS");
}
private function setManuelPos(args: Array<String>): Bool {
var x: Float = Std.parseFloat(args[0]); var x: Float = Std.parseFloat(args[0]);
var y: Float = Std.parseFloat(args[1]); var y: Float = Std.parseFloat(args[1]);
var z: Float = Std.parseFloat(args[2]); var z: Float = Std.parseFloat(args[2]);
@ -64,10 +19,9 @@ class GPS implements Process {
kernel.gps.GPS.instance.setManualPosition(pos); kernel.gps.GPS.instance.setManualPosition(pos);
return true; return true;
} },"<x> <y> <z>");
private function getGPSStatus(): Bool {
registerSyncSubcommand("status",(args)->{
var pos = kernel.gps.GPS.instance.getPosition(); var pos = kernel.gps.GPS.instance.getPosition();
if (pos != null) { if (pos != null) {
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}'); handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
@ -93,5 +47,24 @@ class GPS implements Process {
} }
return true; return true;
});
registerAsyncSubcommand("locate",(args)->{
return kernel.gps.GPS.instance.locate().map((pos)->{
if (pos != null) {
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
} else {
handle.writeLine("Position not available");
}
return true;
});
});
registerAsyncSubcommand("ins",(args)->{
return INS.instance.align().map((_)->{
handle.writeLine("INS aligned");
return true;
});
});
} }
} }