migrated the apps to processes
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
package bin;
|
||||
|
||||
import kernel.ps.ProcessHandle;
|
||||
import kernel.ps.Process;
|
||||
import kernel.gps.INS;
|
||||
import lib.Pos3;
|
||||
import lib.Vec.Vec3;
|
||||
import lib.cli.TermHandle;
|
||||
import lib.cli.CLIApp;
|
||||
|
||||
using tink.CoreApi;
|
||||
|
||||
class GPS extends CLIApp {
|
||||
private var handle:TermHandle;
|
||||
class GPS implements Process {
|
||||
private var handle:ProcessHandle;
|
||||
|
||||
public function new() {}
|
||||
|
||||
public function invoke(handle: TermHandle):Future<Bool> {
|
||||
public function run(handle: ProcessHandle):Void {
|
||||
this.handle = handle;
|
||||
|
||||
var subcommand = handle.args[0];
|
||||
@@ -21,30 +21,37 @@ class GPS extends CLIApp {
|
||||
|
||||
switch (subcommand) {
|
||||
case "set":
|
||||
return Future.sync(setManuelPos(subcommand_args));
|
||||
handle.close(setManuelPos(subcommand_args));
|
||||
case "status":
|
||||
return Future.sync(getGPSStatus());
|
||||
handle.close(getGPSStatus());
|
||||
case "locate":
|
||||
kernel.gps.GPS.instance.locate();
|
||||
return Future.sync(true);
|
||||
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":
|
||||
return INS.instance.align().isSuccess();
|
||||
INS.instance.align().handle(()->{
|
||||
handle.writeLine("INS aligned");
|
||||
handle.close(true);
|
||||
});
|
||||
default:
|
||||
handle.writeLn("Unknown subcommand: " + subcommand);
|
||||
handle.writeLine("Unknown subcommand: " + subcommand);
|
||||
printHelp();
|
||||
return Future.sync(false);
|
||||
|
||||
handle.close(false);
|
||||
}
|
||||
|
||||
return Future.sync(true);
|
||||
}
|
||||
|
||||
private function printHelp(){
|
||||
handle.writeLn("GPS commands:");
|
||||
handle.writeLn("set <x> <y> <z> - set manual position");
|
||||
handle.writeLn("status - get current position and accuracy");
|
||||
handle.writeLn("locate - get current position");
|
||||
handle.writeLn("ins - align INS");
|
||||
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 {
|
||||
@@ -63,26 +70,26 @@ class GPS extends CLIApp {
|
||||
|
||||
var pos = kernel.gps.GPS.instance.getPosition();
|
||||
if (pos != null) {
|
||||
handle.writeLn('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
||||
handle.writeLine('Position x:${pos.x} y:${pos.y} z:${pos.z}');
|
||||
} else {
|
||||
handle.writeLn("Position not available");
|
||||
handle.writeLine("Position not available");
|
||||
return true;
|
||||
}
|
||||
|
||||
var acc = kernel.gps.GPS.instance.getAccuracy();
|
||||
if (acc == 1){
|
||||
handle.writeLn("Accuracy: Low");
|
||||
handle.writeLine("Accuracy: Low");
|
||||
} else if (acc == 2){
|
||||
handle.writeLn("Accuracy: Medium");
|
||||
handle.writeLine("Accuracy: Medium");
|
||||
} else if (acc == 3){
|
||||
handle.writeLn("Accuracy: High");
|
||||
handle.writeLine("Accuracy: High");
|
||||
}
|
||||
|
||||
var ins = INS.instance.getHeading();
|
||||
if (ins != null) {
|
||||
handle.writeLn('INS heading: ${ins.x} y:${ins.y} z:${ins.z}');
|
||||
handle.writeLine('INS heading: ${ins.x} y:${ins.y} z:${ins.z}');
|
||||
} else {
|
||||
handle.writeLn("INS heading not available");
|
||||
handle.writeLine("INS heading not available");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user