Click here to go to the forum index Click here for the home page
 
Author Message

<  TAP and patch development  ~  Using Puppy with PERL on LinkStation

Page 2 of 3
Goto page Previous  1, 2, 3  Next
birdman
Posted: Mon Feb 08, 2010 2:30 am Reply with quote
Frequent contributor Joined: 13 Dec 2006 Posts: 1765 Location: Hitchin, HERTS Tx: Sandy Heath
R2-D2 wrote:
especially when the only reason you're forced to do this is because Microsoft made the stupid decision to use backslash as the path separator in MS-DOS (and thus Windows).
You only need to use \ on the command line (/ is used to indicate a command line flag). Within code (and, indeed, within Perl) you can happily use /.
The problem here is that you are passing the string to puppy, which is not Windows, and the pathname is being used by the Toppy and its filesystem, which is also not Windows and, as has been shown, is happy to allow a / in a filename.

_________________

Toppy: TF5800PVR/250 - Black, now 1TB WD10EURX
F/W: MS6 Recommended F/W 12/9/2009 -FmVrXp+BmC0CbFsIPsUUuWfZXl,
Loader: C5.14, Hardware: 1.01
TAPs: SecCache (UK) v0.4; EPG2MEI v0.96; FontManager 1.0d; QuickJump 1.71; MhegOnOff(Now1) A3; EIT Sub v0.6; MyStuff 6.6
USB connected: SheevaPlug with Debian wheezy
Sig mostly from MyInfo on 26/10/09
View user's profile Send private message
EMJB
Posted: Tue Feb 09, 2010 9:37 am Reply with quote
Frequent contributor Joined: 08 Jul 2005 Posts: 3637 Location: Maldon Essex
Thanks to the help above, I have now got my program more or less working, and for you to understand my next questions I need to explain what it does. It is a facility to monitor emails on your TV without using a PC etc, and works as follows:

(1) When the Perl application runs it:
Code:
     (a) Looks for, and downloads, any emails on your ISP server, without deleting them so they are still there when you check with your PC etc.
     (b) Checks for spam, ignoring any spam messages.
     (c) Checks for messages it has seen before, ignoring them.
     (d) Produces a text-only version of the email (still a bit buggy - see screen shot below!) and sends it to the Toppy.

(2) When the associated TAP finds an email file, it displays an "alert" thus:



and if the user wishes he/she can view it as follows:



My questions are as follows:

(1) Rather than run the perl program at say ten minute intervals using crontab, is there a practical way of running it continuously and using the "time" function to dictate when to interrogate the mail server, or would this always prevent other applications from running on the LinkStation?

(2) How do I access the return data from puppy from within perl so, for instance, I can tell whether the Toppy is switched on?

(3) Is there a way of making the Linkstation "beep" withi perl, so I can give an audible warning of new emails?

Before anyone asks, in its current form things like email server data, password, directory structure and spam keywords are all hard coded so it is not suitable for general use in its present form.

TIA,

EMJB
View user's profile Send private message
R2-D2
Posted: Tue Feb 09, 2010 12:34 pm Reply with quote
Frequent contributor Joined: 18 Dec 2006 Posts: 12148
Looks like a very worthwhile project!

EMJB wrote:
(1) Rather than run the perl program at say ten minute intervals using crontab, is there a practical way of running it continuously
Use sleep(). It'd probably be reasonable to create a gap of, say, 5-10 minutes between polls of the mail server -- assuming you're just pulling back headers in the initial enquiry.
Quote:
(2) How do I access the return data from puppy from within perl so, for instance, I can tell whether the Toppy is switched on?
system() returns the exit status of the command, which can probably be used to detect errors. Otherwise if you want to try to parse the output you should use the back-tick operator instead.
Quote:
(3) Is there a way of making the Linkstation "beep" withi perl, so I can give an audible warning of new emails?
Usually you'd print "\a" to the console, but what the console is would depend on the context of your program (certainly running via crontab would make that hard!).

_________________
Troubleshooting -- User Manual -- Dark Side of the Matrix: Firmwares and Patches
View user's profile Send private message Visit poster's website
EMJB
Posted: Tue Feb 09, 2010 2:09 pm Reply with quote
Frequent contributor Joined: 08 Jul 2005 Posts: 3637 Location: Maldon Essex
@ R2-D2 -Thanks for answers - gives me staring points to investigate further. The problem I find with starting to use new languages is that the material on the internet is either very simple at the level of "Hello World" programs or assumes considerable knowledge.

R2-D2 wrote:
Looks like a very worthwhile project!
I started this mainly as an experiment to see what could be done rather than to satisfy a current need - I suppose the equivalent of the energetic types who have to climb mountains because they are there! However if there really are a number of people out there who would like such a facility I could change it to read a cfg file with passwords etc. I would also need guinea pigs with slug & ASUS to test the code and get the installation instructions right. Do they come with perl installed as standard?

EMJB
View user's profile Send private message
R2-D2
Posted: Tue Feb 09, 2010 7:56 pm Reply with quote
Frequent contributor Joined: 18 Dec 2006 Posts: 12148
I think perl is a standard option for pretty much every Unix-like installation. It's simple package addition on a Slug/Asus.

_________________
Troubleshooting -- User Manual -- Dark Side of the Matrix: Firmwares and Patches
View user's profile Send private message Visit poster's website
billmars
Posted: Tue Feb 09, 2010 8:49 pm Reply with quote
Frequent contributor Joined: 17 Sep 2005 Posts: 761
ipkg reports:-

perl 5.8.8-23 Practical Extraction and Report Language.

as installed.

I don't think I installed it, so it may well have 'come with the box'!

I also see 'perlconsole' is available. I know nothing of the ins and outs of perl, but from its description, looks as if it might be useful. But I'm probably talking to the converted!

_________________
BM
Firmware
5800 Samsung 1Tb Autostart TAPs: Extend 1.7;TSRCommander 1.5;TF5000 Display 1.53;EPG2MEI 0.95;MyStuff 6.6;QuickJump 1.72;Power Down 0.75;SecCache 0.4;TSSaver 0.4;MHEG Control B2;eit_sub_sng 0.6 Transmitter: Belmont Extras: as2mei (via NSLU2)
View user's profile Send private message TF5800
birdman
Posted: Wed Feb 10, 2010 1:11 am Reply with quote
Frequent contributor Joined: 13 Dec 2006 Posts: 1765 Location: Hitchin, HERTS Tx: Sandy Heath
EMJB wrote:
(2) How do I access the return data from puppy from within perl so, for instance, I can tell whether the Toppy is switched on?
Any test you can do for checking whether it is switched on is not atomic with anything you wish to do based on the result - so it's not worth doing. So what you really want here is to do something and then check whether it succeeded. As noted - you can check the value returned by the system() call. This should be 0 if all went well (although that will depend on puppy) and non-zero on any problems. The exact value you get is the result of the wait() call used to get the result, which is actually a combination of things,. If you really want to be pedantic and get the exact exit code you need something like:
Code:

use POSIX qw( :sys_wait_h );
...
my $sys_res = system(.....);
my $exit_status = WIFEXITED($sys_res)? WEXITSTATUS($sys_res): 999;
(the 999 gets set if it didn't actually exit - e.g. if it ended as a result of a signal being raised)

_________________

Toppy: TF5800PVR/250 - Black, now 1TB WD10EURX
F/W: MS6 Recommended F/W 12/9/2009 -FmVrXp+BmC0CbFsIPsUUuWfZXl,
Loader: C5.14, Hardware: 1.01
TAPs: SecCache (UK) v0.4; EPG2MEI v0.96; FontManager 1.0d; QuickJump 1.71; MhegOnOff(Now1) A3; EIT Sub v0.6; MyStuff 6.6
USB connected: SheevaPlug with Debian wheezy
Sig mostly from MyInfo on 26/10/09
View user's profile Send private message
EMJB
Posted: Fri Feb 26, 2010 11:14 am Reply with quote
Frequent contributor Joined: 08 Jul 2005 Posts: 3637 Location: Maldon Essex
Thanks to help above I now have a TAP and perl application which work adequately for my purposes (if a little rough round the edges), with one very basic problem. That is as follows:

(1) When run from a Telnet session and another application tries to use puppy, a message appears saying "ERROR: Can not scan for devices while another instance of puppy is running", but $sys_res (as in birdman's code) returns 0 so everthing seems OK as far as the subsequent logic is concerned.

(2) I *think* that when run from rcS, the same circumstance causes my application to crash, so I have to reboot the LinkStation (assuming I realise what has happened). Unless I can stop this happening, the whole project is a non-starter as far as I am concerned.

My first idea for a solution was to run a "ps" to see if puppy was already running before attempting to use it. However "puppy" never seems to appear in the "ps" results, but I noticed when inactive "ftpd-topfield" appears once, and when active it appears at least twice. I therefore tried putting a "wait for puppy" loop before each attempt to use puppy as follows:

Code:

sub wait_for_puppy    # Checks to see if puppy in use and waits for other application to release it if necessary
{
   my ($wait_count) = 0;
   while (&is_puppy_running > 0)
   {
      if ($wait_count*5 > 10*60)
      {
         &do_log("Have been waiting for 10 minutes for puppy to be free!");
         &query_save_history_and_log;
         $wait_count = 0;
      }
      sleep(5);
      $wait_count++;
   }
}
   

sub is_puppy_running
{
   my ($running_prog) = "";
   my ($ftpd_count) = 0;
   my (@ps_result) = qx/ps/;
   
   foreach $running_prog (@ps_result)
   {
      if (index($running_prog,"ftpd-topfield") > 0)
      {
         $ftpd_count++;
         if ($ftpd_count > 1) {return(1);}
      }
      if (index($running_prog,"rt2mei") > 0)
      {
         return(1)
      }
   }
   return(0);
}


This seems to work most of the time, but is not entirely reliable in that it reports puppy is not in use when it is in fact being used by ftpd-topfield.

Can anyone please tell me what I am doing wrong?

EMJB
View user's profile Send private message
mhw
Posted: Fri Feb 26, 2010 12:05 pm Reply with quote
Joined: 22 Aug 2005 Posts: 20
Quote:
When run from a Telnet session and another application tries to use puppy, a message appears saying "ERROR: Can not scan for devices while another instance of puppy is running", but $sys_res (as in birdman's code) returns 0 so everthing seems OK as far as the subsequent logic is concerned.


Hmm; the copy of puppy on my Asus seems to return a usable exit status:

Code:
mhw@toppy:~$ puppy -c dir
ERROR: Can not scan for devices while another instance of puppy is running.
mhw@toppy:~$ echo $?
1
mhw@toppy:~$ puppy -c dir
d                    0 Wed Jan  1 00:00:00 2003 DataFiles
d                    0 Wed Jan  1 00:00:00 2003 ProgramFiles
d                    0 Wed Jan  1 00:00:00 2003 MP3
mhw@toppy:~$ echo $?
0
mhw@toppy:~$


The first invocation was while I had an ftpd-topfield session running, the second when it had finished.

_________________
TF5800, IA On, TS On, F/W: MS6 Recommended F/W 12/9/2009 +BmCbCfCtEvEzIPePfPsRtUUuVb
TAPs: EPG2MEI v0.96; TF5000 Display v1.53; EIT Sub v0.6; Font Manager 1.0d; Extend v1.7; MyStuff 6.1; SecCache (UK) v0.4; MyInfo B4.1a;
Sig generated by MyInfo on 11/1/10
View user's profile Send private message
EMJB
Posted: Fri Feb 26, 2010 6:52 pm Reply with quote
Frequent contributor Joined: 08 Jul 2005 Posts: 3637 Location: Maldon Essex
@mhw,

Just used your commands and get the same results, but the behaviour when using birdman's perl code and running your commands seem to be different (most notably with the crash that seems to be associated with this condition when running from rcS rather that in a Telnet session).

EMJB
View user's profile Send private message
birdman
Posted: Sat Feb 27, 2010 2:51 am Reply with quote
Frequent contributor Joined: 13 Dec 2006 Posts: 1765 Location: Hitchin, HERTS Tx: Sandy Heath
    "ERROR: Can not scan for devices while another instance of puppy is running"
    That only crops up in the original puppy code, not the one I changed to use libusb. In the original a lock file (/tmp/puppy) was created and both puppy and ftpd-topfield look for this (since only one process can talk to the Toppy at a time). If it reports this the exit code returned by puppy should be -1.
    ...but is not entirely reliable in that it reports puppy is not in use when it is in fact being used by ftpd-topfield.
    This would happen if you are running my patch ftpd-topfield (which uses libusb, and hence doesn't use a /tmp/puppy lockfile, as the usbfs knows what has been claimed) with an unpatched puppy. With a patched version of both you'd get this:
    Quote:
    birdman@plug:~$ puppy -c dir '\'
    usb_claim_interface returned an error (-16)
    gml4410@plug:~$ echo $?
    1


_________________

Toppy: TF5800PVR/250 - Black, now 1TB WD10EURX
F/W: MS6 Recommended F/W 12/9/2009 -FmVrXp+BmC0CbFsIPsUUuWfZXl,
Loader: C5.14, Hardware: 1.01
TAPs: SecCache (UK) v0.4; EPG2MEI v0.96; FontManager 1.0d; QuickJump 1.71; MhegOnOff(Now1) A3; EIT Sub v0.6; MyStuff 6.6
USB connected: SheevaPlug with Debian wheezy
Sig mostly from MyInfo on 26/10/09
View user's profile Send private message
EMJB
Posted: Sat Feb 27, 2010 4:07 pm Reply with quote
Frequent contributor Joined: 08 Jul 2005 Posts: 3637 Location: Maldon Essex
@birdman

Thanks that gives me soemthing else to think about, but as usual seems to raise further questions in my ignorant mind as follows:

(1) You refer to patched versions of puppy and ftpd-topfield - where do I get these from? I am running puppy 1.11-1 (and ftpd-topfield 0.7.4 I think, downloaded 25 months ago).

(2) Is the problem of crashing when running from rcS as opposed to from a telnet session likely to be cured by your patched versions, or is it fundamental to perl, or more likely to be completely unrelated?

(3) Had a quick look for /tmp/puppy - it was not there after a LinkSation reboot, appeared after using ftpd-topfield, but doesn't seem to get deleted. Is that what you would expect?

TIA,

EMJB
View user's profile Send private message
birdman
Posted: Sat Feb 27, 2010 7:12 pm Reply with quote
Frequent contributor Joined: 13 Dec 2006 Posts: 1765 Location: Hitchin, HERTS Tx: Sandy Heath
EMJB wrote:
(1) You refer to patched versions of puppy and ftpd-topfield - where do I get these from? I am running puppy 1.11-1 (and ftpd-topfield 0.7.4 I think, downloaded 25 months ago).

Look here.
and also wrote:

(2) Is the problem of crashing when running from rcS as opposed to from a telnet session likely to be cured by your patched versions, or is it fundamental to perl,..
It's certainly not fundamental to Perl to crash. Without knowing what this application is, or how it crashes I can't say much else. Also - why do you need to reboot - that implies something has locked up.
and further wrote:
(3) Had a quick look for /tmp/puppy - it was not there after a LinkSation reboot, appeared after using ftpd-topfield, but doesn't seem to get deleted. Is that what you would expect?
Yes - it would be created when needed.

_________________

Toppy: TF5800PVR/250 - Black, now 1TB WD10EURX
F/W: MS6 Recommended F/W 12/9/2009 -FmVrXp+BmC0CbFsIPsUUuWfZXl,
Loader: C5.14, Hardware: 1.01
TAPs: SecCache (UK) v0.4; EPG2MEI v0.96; FontManager 1.0d; QuickJump 1.71; MhegOnOff(Now1) A3; EIT Sub v0.6; MyStuff 6.6
USB connected: SheevaPlug with Debian wheezy
Sig mostly from MyInfo on 26/10/09
View user's profile Send private message
birdman
Posted: Sat Feb 27, 2010 7:26 pm Reply with quote
Frequent contributor Joined: 13 Dec 2006 Posts: 1765 Location: Hitchin, HERTS Tx: Sandy Heath
EMJB wrote:
Can not scan for devices while another instance of puppy is running", but $sys_res (as in birdman's code) returns 0 so everthing seems OK as far as the subsequent logic is concerned.
You mention a crash. If you *really* mean a crash then that code isn't sufficient, as it will only return the code if the program called exit (hence WIFEXITED), which is doesn't do if it crashes from a signal. If all you want to know is "did it finish successfully" then just checking the system() result is 0 is simpler.

_________________

Toppy: TF5800PVR/250 - Black, now 1TB WD10EURX
F/W: MS6 Recommended F/W 12/9/2009 -FmVrXp+BmC0CbFsIPsUUuWfZXl,
Loader: C5.14, Hardware: 1.01
TAPs: SecCache (UK) v0.4; EPG2MEI v0.96; FontManager 1.0d; QuickJump 1.71; MhegOnOff(Now1) A3; EIT Sub v0.6; MyStuff 6.6
USB connected: SheevaPlug with Debian wheezy
Sig mostly from MyInfo on 26/10/09
View user's profile Send private message
birdman
Posted: Sat Feb 27, 2010 7:49 pm Reply with quote
Frequent contributor Joined: 13 Dec 2006 Posts: 1765 Location: Hitchin, HERTS Tx: Sandy Heath
EMJB wrote:
This seems to work most of the time, but is not entirely reliable in that it reports puppy is not in use when it is in fact being used by ftpd-topfield.

Can anyone please tell me what I am doing wrong?EMJB
Well - you are assuming that a check done now will be true in now+1msec. If ftpd-topfield is just about to start up a child process this won't spot it (it doesn't exist when the ps runs) but it will be there an instant later. Hence my comment that you can't do an atomic check, so there is no point trying. You have to just use puppy and find out whether it succeeded.

PS: You've got a lot of () in the perl, which aren't needed. In certain instances this may produce results you don't expect (it puts things into array mode) - although I can't see it making a difference here. Also, it's usual to use a regex when looking for a substring, rather than index(). So something like this:
Code:
# Checks to see if puppy in use and waits for other application to release it if necessary
sub sub wait_for_puppy{
   while(1) {   # For ever
      my $wait_step = 5; 
      my $wait_lc = 120;
      while ($wait_lc--) {
         return if (not is_puppy_running());
         sleep($wait_step);
      }
      do_log("Have been waiting for 10 minutes for puppy to be free!");
      query_save_history_and_log();
   }
}

sub is_puppy_running {
   my $already_seen = 0;

   my @ps_result = qx/ps/;
   foreach (@ps_result) {
      if (/ftpd-topfield/) {
         return 1 if $already_seen;
         $already_seen = 1;
      }
      return 1 if (/rt2mei/);
   }
   return 0;
}

_________________

Toppy: TF5800PVR/250 - Black, now 1TB WD10EURX
F/W: MS6 Recommended F/W 12/9/2009 -FmVrXp+BmC0CbFsIPsUUuWfZXl,
Loader: C5.14, Hardware: 1.01
TAPs: SecCache (UK) v0.4; EPG2MEI v0.96; FontManager 1.0d; QuickJump 1.71; MhegOnOff(Now1) A3; EIT Sub v0.6; MyStuff 6.6
USB connected: SheevaPlug with Debian wheezy
Sig mostly from MyInfo on 26/10/09
View user's profile Send private message

Display posts from previous:  

All times are GMT + 1 Hour
Page 2 of 3
Goto page Previous  1, 2, 3  Next

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum