[aprssig] KPC 3+ reset script

Lee Bengston lee.bengston at gmail.com
Thu Feb 23 16:29:49 EST 2012


I beat this to death not long ago.  Just change the port and baud rate
settings to match your system.  This is designed to run when my
computer is re-booted, and at boot time it doesn't know what mode the
TCN is in - and it wants it in KISS mode.  I'm using this on a
KPC-9612+, but I think the commands are the same for a KPC-3+.

Regards,
Lee

-------------------

#!/usr/bin/perl
# script to figure out the current TNC mode and put into KISS mode if
it is not there
# Last update February 5, 2012

use strict;
use warnings;

my ($gotcmd, $match, $after, $pattern, $instead, $count, $result, $cmdflag);
my $kiss1 = "INTFACE KISS\r";
my $kiss2 = "RESET\r";
my $mycall = "K5DAT";
use Device::SerialPort;

my $PortObj=Device::SerialPort->new("/dev/ttyUSB0");

$PortObj->baudrate(9600);
$PortObj->parity("none");
$PortObj->databits(8);
$PortObj->stopbits(1);
$PortObj->handshake("rts");
$PortObj->write_settings;

$PortObj->read_char_time(0);
$PortObj->read_const_time(100);

# send some stuff looking for a response
$PortObj->write("junk\r");
$PortObj->read(2047); # read out lots of bytes in case lots of packets
have come in
sleep (1);
$PortObj->write("junk\r\r"); # now send again and look for cmd prompt
# will iterate up to 12 times looking for the command prompt
# in case there's lots more in the buffer to read out
$count = 12; # choice of 12 is somewhat arbitrary and possibly overkill
$cmdflag = 0;
while ($count > 0)  {
  $result = $PortObj->read(255);
  print "Reading Data...\n\n";
  if ($result =~ m/cmd:/)  {
    $cmdflag = 1;
    $count = 0;
  }
  else {
  $count = $count - 1;
  }
}

# print "cmdflag = $cmdflag\n\n";
if ($cmdflag == 1)  {
  print "OK - got the cmd prompt\n\n";
}
else {
# send commands to take TNC out of KISS MODE - at this point we don't
know for sure
# if it in KISS mode or not, but we know we're not getting expected
responses for
# normal command mode, so this will take it out of KISS if it's in that mode.

  print "no command prompt - sending commands to exit\nKISS mode in
case that's the reason\n\n";

  $PortObj->write(chr(192));
  $PortObj->write(chr(255));
  $PortObj->write(chr(192));

#  check again and see if we can get command mode reponses
  $PortObj->write("junk\r");
  sleep(1);
  $PortObj->write("foo\r");
  $count = 20;
  while ($count > 0)  {
    $result = $PortObj->read(255);
    sleep(1);
    print "Reading data after sending commands to exit KISS mode...\n\n";
    print "$result\n\n";
    if ($result =~ m/cmd:/)  {
      $cmdflag = 2;
      $count = 0;
      print "OK, saw expected command prompt\n\n";
    }
    elsif ($result =~ m/BAUD/)  {
    print "TNC found in 'reset' mode\n\n";
    $PortObj->write("*");
    sleep(1);
    $result = $PortObj->read(127);
    print "$result\n\n";
    $PortObj->write("$mycall\r");
    sleep(1);
    $result = $PortObj->read(63);
    print "$result\n\n";
    $cmdflag = 3;
    }
    else {
    $count = $count - 1;
    }
  }
}

if ($cmdflag == 0)  {
  print "Was never able to communicate\n\n";
}

if ($cmdflag > 0)  {
  print "Sending commands to put the TNC in KISS mode\n\n";
# if we have a prompt, go ahead and put the TNC in KISS mode
  $PortObj->write($kiss1);
  sleep(1);
  $result = $PortObj->read(255);
  print "$result\n\n";
  $PortObj->write($kiss2);
  sleep(1);
  $result = $PortObj->read(255);
  print "$result\n\n";
  print "Commands sent to put the TNC in KISS mode;\n\n";
}
$PortObj->close;



On Thu, Feb 23, 2012 at 4:04 PM, John Gorkos <jgorkos at gmail.com> wrote:
> Great perl minds think alike:  I've got the part to get me OUT of kiss down
> pat.  It's the "get me back IN to kiss" that's a bit harder.  I'll grind out
> some Perl-Expect and post it to this thread when it sort of works.  It would
> be much better if Kantronics would FIX THEIR BUGGY FIRMWARE! (I know, shouting
> on the internet doesn't mean that the Kantronics engineering staff will hear me
> and do what we pay them to do, but it's worth a try).
>
> John gorkos
>
>
> On Thursday, February 23, 2012 01:00:39 PM Curt, WE7U wrote:
>> On Thu, 23 Feb 2012, Curt, WE7U wrote:
>> >> to ensure i don't get bit by Kantronics bad programming.  Does anyone
>> >> have a
>> >> TCL or Perl Expect script that will send the KISS escape sequence,
>> >> tickle the
>> >> TNC, send it an INTFACE KISS command, and reset it?
>> >> I'll try to cobble something together, but plagiarism is the highest
>> >> form of
>> >> flattery here...
>> >
>> > There's a "kiss-off" script in the Xastir sources you could start with.
>>
>> Ah, but it ain't much.  Invoked like this:  ./kiss-off.pl >/dev/ttyS1
>>
>> And here are the only real lines of code:
>>
>>      sleep 1;
>>      printf("%c%c%c", 192, 255, 192);
>>      sleep 1;
>>
>> No "expect" used, in fact no two-way communication at all.  Completely
>> open-loop.  Who wrote this piece of crap?  ;-)
>>
>> Even as-is, I found it useful.  For automated rebooting you'll want
>> something more.
>
> _______________________________________________
> aprssig mailing list
> aprssig at tapr.org
> https://www.tapr.org/cgi-bin/mailman/listinfo/aprssig




More information about the aprssig mailing list