#!/usr/bin/env perl

use strict;
use IO::Socket::INET;

my $n1mm = IO::Socket::INET->new(LocalPort => 12040,
				 Proto => 'udp') or die "Fail!!\n";

my $rotctl = IO::Socket::INET->new(PeerAddr => '193.35.52.163',
				   PeerPort => '4533',
				   Proto => 'tcp') or die "Can't connect to rotctld.\n";

my $command;
my $flags;
while ($n1mm->recv($command, 256, $flags)) {
    print $command . "\n";
    if ($command =~ /\<stop\>/) {
	$rotctl->send('S');
    }
    if ($command =~ /\<goazi\>/) {
	my $az;
	($az) = ($command =~ /\<goazi\>([0-9]+[.,][0-9]+)\<\/goazi\>/);
	$az =~ s/,/\./;
	$rotctl->send("P $az 0.0\n");
    }
}

