[mythtv-users] Channel Changer Script error

the Dragon King Dragon.King at SoftHome.net
Sat Mar 5 16:47:45 UTC 2005


Hello!

I ran a myth box for ~20 months; did a couple of upgrades, some went 
very well, some went harder.  When 0.17 came out, I decided to bite the 
bullet, and reinstall the box and go from RH9 to FC3.  Numerous rpm/apt 
difficulties led to this decision (I'd unwisely 'forced' some things, 
and the upgrade to 0.17 went very poorly).

Anyway, I have a DirecTV receiver (circa Q1 2000), and hacked a found 
script to work with my box (needed to do some slight bit fiddling to get 
it to work).  I saved that script, since I knew it was fiddled, and knew 
it worked.  I've not changed the Serial->DirecTV-low-speed-data cable.

Well, everything has gone well (ok, not great, but the excellent guide 
of  Jarod, et el let me work through them all (I was one of the lucky 
ones snagged by the NVidia GF4 MX 440 bug (permanent logo display), so I 
got a MX 5200 card),.

However, my problem is this:  I cannot get the channel changer script to 
work!  And the urls' I kept from the effort 20 months ago have dried up 
on me.   Worse, I don't know enough about the issue to give google a 
question to give me an answer.

Here's the script: Note: I'm not a PERL guy, so I can do only simple 
things myself in the language, like find the line where the error occurs 
via printfs:
--------------------------------changechannel-------------------------------------------

#!/usr/bin/perl

# This is only the necessary parts of the original script (found in the 
link bellow) necessary to change the channels in the box.
# dss_control:  Remote control of a Sony DSS unit via the serial port
# By Josh Wilmes (http://www.hitchhiker.org/dss)
# Based on info from http://www.isd.net/mevenmo/audiovideo.html
#
# I take no responsibility for any damage this script might cause.
# Feel free to modify and redistribute this as you see fit, but please 
retain
# the comments above.

# Modified 12-05-02 by Jason Richmond (jason at jgrichmond.com) to control 
RCA DirecTV reciever.
#Usage:
#      RCA.pl <channel number>
#Notes:
# Com port is set to COM 2 (cua1)
# Just make this file executable (chmod 755) and call it.


$|=1;
use POSIX qw(:termios_h);
use FileHandle;

$verbose=1;

%pkt_decode=("0xF0" => "START PKT",
            "0xF1" => "ERR 1",
            "0xF2" => "GOT EXTENDED",
            "0xF4" => "END PKT",
            "0xF5" => "ERR 2",
            "0xFB" => "PROMPT");

%terminal=("0xF1" => -1,
          "0xF4" => 1,
          "0xF5" => -1);


%cmds=("on" => \&on,
      "off" => \&off,
      "get_channel" => \&get_channel,
      "text" => \&text,
      "scroll" => \&scroll,
      "hide" => \&hide,
      "show" => \&show,
      "get_signal" => \&get_signal,
      "channel" => \&change_channel,
      "key" => \&key,
      "verbose" => \&toggle_verbose
      );

# done
%keymap=(right => "0xa8",
           left => "0xa9",
           up => "0xa6",
         down => "0xa7",
     favorite => "0x9e",
       select => "0xc3",
         exit => "0xf9",
            9 => "0xc6",
            8 => "0xc7",
            7 => "0xc8",
            6 => "0xc9",
            5 => "0xca",
            4 => "0xcb",
            3 => "0xcc",
            2 => "0xcd",
            1 => "0xce",
            0 => "0xcf",
        ch_up => "0xd2",
        ch_dn => "0xd3",
        power => "0xd5",
         jump => "0xac",
        guide => "0xe5",
         menu => "0xf7");
printf( "Here\n");
my $serial=init_serial("/dev/cua0","9600");
printf( "There\n");
#@ARGV = split //, join '', @ARGV;
foreach (@ARGV) {
 printf($_);
 change_channel($_);
}

exit(0);

sub change_channel {
   my ($channel)=@_;

   $_=sprintf("%4.4x",$channel);
   ($n1,$n2)=/(..)(..)/;

   simple_command("0x46",$n1,$n2,"0x0");
}


sub simple_command {
   if (defined(dss_command(@_))) {
        return(1);
   } else {
        return(undef);
   }
}
##looks right
sub dss_command {
   sendbytes("0xFA", at _);
   return get_reply();
}

sub sendbytes {
   (@send)=@_;
   foreach (@send) { s/^0x//g; $_=hex($_); }
   print " SEND: " if ($verbose);
   foreach $num (@send) {
       $str=pack('C',$num);
       printf("0x%X [%s] ", $num, $str) if ($verbose);
     syswrite($serial,$str,length($str));
   }
   print "\n" if ($verbose);
}

sub get_reply {
   my $starttime=time();
   my ($last,$ok, at ret);

   print "  RECV: " if ($verbose);

   while (1) {
      $ret=sysread($serial,$buf,1);
      $str=sprintf("0x%2.2X", ord($buf));

      # busy wait bad!
      die ("Error ($str)\n") if (time() - $starttime > 8);
      next if $str eq "0x00";

      if ($pkt_decode{$str}) {
          print $str if ($verbose);
          print "[$pkt_decode{$str}] " if ($verbose);
      } else {
          $_=$str; s/^0x//g; $_=hex($_);
          printf("$str(%3.3s) ",$_) if ($verbose);
          push (@ret,$_);
      }

      $ok=1 if ($terminal{$str} > 0);
      last if ($terminal{$str});
      last if ($last eq "0xFB" && $str eq "0xFB");
      $last=$str;
  }
  print "\n\n" if ($verbose);

  return @ret if ($ok);
  return undef;
}

sub init_serial {
printf("step1\n");
   my($port,$baud)=@_;
   my($termios,$cflag,$lflag,$iflag,$oflag);
   my($voice);

my $serial=new FileHandle("+>$port") || die "Could not open $port: $!\n";

   $termios = POSIX::Termios->new();
printf("step2\n");
   $termios->getattr($serial->fileno()) || die "getattr: $!\n";
printf("step3\n");
   $cflag= 0 | CS8 | HUPCL | CREAD | CLOCAL;
   $lflag= 0;
   $iflag= 0 | IGNBRK | IGNPAR | IXON | IXOFF;
   $oflag= 0;

   $termios->setcflag($cflag);
   $termios->setlflag($lflag);
   $termios->setiflag($iflag);
   $termios->setoflag($oflag);
   $termios->setattr($serial->fileno(),TCSANOW) || die "setattr: $!\n";
   eval qq[
     \$termios->setospeed(POSIX::B$baud) || die "setospeed: \$!\n";
     \$termios->setispeed(POSIX::B$baud) || die "setispeed: \$!\n";
   ];

   die $@ if $@;

   $termios->setattr($serial->fileno(),TCSANOW) || die "setattr: $!\n";

   # This gets rid of all the special characters..
   $termios->getattr($serial->fileno()) || die "getattr: $!\n";
   for (0..NCCS) {
        if ($_ == NCCS) { last; }

        # Dont mess up XON/XOFF..
        if ($_ == VSTART || $_ == VSTOP) { next; }

        $termios->setcc($_,0);
   }
   $termios->setattr($serial->fileno(),TCSANOW) || die "setattr: $!\n";

   return $serial;
}
----------------------------------------------end 
script-------------------------------------------
When I execute the script, I see:
Here
step1
step2
getattr: Inappropriate ioctl for device

So I know the line that's not working:
                $termios->getattr($serial->fileno()) || die "getattr: $!\n";

So.  What has changed since RH9 that makes the above getattr command 
illegal in FC3?  Or have I got to set /dev/cua0 to something?  Here's an 
ls -l of /dev/cua0:
       -rwxrwxrwx  1 root root 0 Mar  5 10:31 /dev/cua0

I know the receiver is working since: mplayer /dev/video0 does show a 
program. (pictures *and* sound! w00t!)

Any help would be more'n appreciated, let me tell you.  :-)  I think 
everything else is ok (learned LVM, set it up with expanded drives); 
 mythsetup ran  anyway... *grin*  And I saved my DB, and previous 
recordings.  I think this is hopefully the last issue, and there seems 
little help, lestways, I don't know enough to ask Google the right 
question...

Thanks in advance!

Carl



More information about the mythtv-users mailing list