Compare commits

...

3 Commits

Author SHA1 Message Date
a3b4ffc76d
rotctl: only support long quit command
gpredict actually sends either q or Q when disconnecting. This is not
actually a supported command according to my reading of the rotctld
documentation. `q`/`Q` for quitting is limited to the interactive
rotctl prompt.

For autoparking, we don't want to quit when gpredict disconnects. Also
in general, we probably don't want to quit when gpredict disconnects.
I still want to have a quit command when using this via netcat or
whatever, so make them a form gpredict probably does not send.
2024-07-18 23:36:09 -07:00
c295c941e9
rotctl: actually quit when receiving the quit message 2024-07-18 23:36:09 -07:00
de487d18c5
rotctl: add autopark functionality
Since gpredict doesn't have a park button or anything, this will just
automatically park the antenna when the gpredict rotator controller
disconnects. This may or may not actually be a good idea. We will see.
2024-07-18 23:36:09 -07:00
2 changed files with 13 additions and 7 deletions

View File

@ -92,6 +92,7 @@ pub fn validate(self: Config, err_writer: anytype) !void {
rotctl: RotControlConfig = .{
.listen_address = "127.0.0.1",
.listen_port = 4533,
.autopark = false,
},
labjack: LabjackConfig = .{
.device = .autodetect,
@ -151,6 +152,7 @@ pub const MinMax = struct {
const RotControlConfig = struct {
listen_address: []const u8,
listen_port: u16,
autopark: bool,
};
const LabjackConfig = struct {

View File

@ -33,17 +33,16 @@ pub fn run(allocator: std.mem.Allocator) !void {
.rotator = try YaesuController.init(allocator),
};
while (true) {
while (interface.running) {
const client = try server.accept();
defer {
log.info("disconnecting client", .{});
interface.rotator.stop();
if (!config.rotctl.autopark)
interface.rotator.stop();
client.stream.close();
}
interface.writer = .{ .unbuffered_writer = client.stream.writer() };
interface.running = true;
defer interface.running = false;
log.info("client connected from {}", .{client.address});
@ -60,7 +59,13 @@ pub fn run(allocator: std.mem.Allocator) !void {
std.mem.trim(u8, fbs.getWritten(), &std.ascii.whitespace),
) catch break;
}
// loop ended due to client disconnect
if (interface.running and config.rotctl.autopark)
interface.rotator.startPark();
}
interface.rotator.control_thread.join();
}
fn write(self: *RotCtl, buf: []const u8) !void {
@ -172,7 +177,6 @@ fn handleHamlibCommand(
if (first.len == 1 or first[0] == '\\') {
switch (first[0]) {
// NOTE: this is not technically supported by rotctld.
'q', 'Q' => try self.quit(first, &tokens),
'S' => try self.stop(first, &tokens),
'K' => try self.park(first, &tokens),
'p' => try self.getPosition(first, &tokens),
@ -243,8 +247,8 @@ const HamlibCommand = struct {
};
const rotctl_commands = [_]HamlibCommand{
.{ .short = 'q', .callback = quit }, // quit
.{ .short = 'Q', .callback = quit }, // quit
.{ .long = "quit", .callback = quit },
.{ .long = "exit", .callback = quit },
.{ .long = "AOS", .callback = blindAck },
.{ .long = "LOS", .callback = blindAck },
.{ .short = 'P', .long = "set_pos", .callback = setPosition }, // azimuth: f64, elevation: f64