I just set up mythbackend to record with the HD-PVR 1212 from the SA4250HDC cable box.  Thanks to Major Idiot&#39;s firewire script posted at <a href="http://ubuntuforums.org/showpost.php?p=4453681&amp;postcount=3">http://ubuntuforums.org/showpost.php?p=4453681&amp;postcount=3</a>  I am able to run channel changing over firewire without a problem.  However I ran into an issue when I tried to record a program with the HDPVR using the script.  The recording failed due to the cable box not showing the actual channel until a few seconds after the change and the HD-PVR started to record instantly after the channel was changed by the script.  I&#39;ve seen a few users suggest adding a sleep command of say 5 seconds to a channel changing script, and that is what I would like to do with this script.  How do I add sleep to the following script?<br>
<br>/*<br> * Samo&#39;s SA4250HD firewire channel changer by majoridiot<br> *<br> * requires: libavc1394-dev libraw1394-dev <br> *<br> * compile with: gcc -o sa4250_ch sa4250_ch.c -lrom1394 -lavc1394 -lraw1394<br> *<br> * based on mythtv source code and<br>
 *<br> * sa3250ch - an external channel changer for SA3250HD Tuner <br> * Based off 6200ch.c by Stacey D. Son<br> * <br> * Copyright 2004,2005 by Stacey D. Son &lt;<a href="mailto:mythdev@son.org">mythdev@son.org</a>&gt; <br>
 * Copyright 2005 Matt Porter &lt;<a href="mailto:mporter@kernel.crashing.org">mporter@kernel.crashing.org</a>&gt;<br> * Portions Copyright 2006 Chris Ingrassia &lt;<a href="mailto:chris@spicecoffee.org">chris@spicecoffee.org</a>&gt; (SA4200 and Single-digit command mode)<br>
 * <br> * This program is free software; you can redistribute it and/or modify<br> * it under the terms of the GNU General Public License as published by<br> * the Free Software Foundation; either version 2 of the License, or<br>
 * (at your option) any later version.<br> *<br> * This program is distributed in the hope that it will be useful,<br> * but WITHOUT ANY WARRANTY; without even the implied warranty of<br> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br>
 * GNU General Public License for more details.<br> *<br> * You should have received a copy of the GNU General Public License<br> * along with this program; if not, write to the Free Software Foundation,<br> * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.<br>
 */<br><br>#include &lt;libavc1394/rom1394.h&gt;<br>#include &lt;libavc1394/avc1394.h&gt;<br>#include &lt;libraw1394/raw1394.h&gt;<br>#include &lt;sys/types.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;errno.h&gt;<br>
#include &lt;stdlib.h&gt;<br>#include &lt;string.h&gt;<br><br>/* SA42xxHD IDs */<br>#define SA4200HD_VENDOR_ID1     0x000014f8<br>#define SA4200HD_MODEL_ID1      0x00001072<br>#define SA4250HD_VENDOR_ID1    0x00001e6b  /* eric&#39;s stb */<br>
#define SA4250HD_MODEL_ID1    0x000010cc  /* eric&#39;s stb */<br><br>/* add additional vendor and model id&#39;s here- addition needed to if statement starting @ line 134 below */<br><br>#define AVC1394_SA3250_COMMAND_CHANNEL 0x000007c00   <br>
#define AVC1394_SA3250_OPERAND_KEY_PRESS 0xe7<br>#define AVC1394_SA3250_OPERAND_KEY_RELEASE 0x67 <br><br>#define CTL_CMD0 AVC1394_CTYPE_CONTROL | AVC1394_SUBUNIT_TYPE_PANEL | \<br>        AVC1394_SUBUNIT_ID_0 | AVC1394_SA3250_COMMAND_CHANNEL<br>
#define CTL_CMD1 (0x04 &lt;&lt; 24)<br>#define CTL_CMD2 0xff000000<br><br>/* I changed this from 0 to 1 because cable box is connected on node 1 */<br>#define STARTING_NODE 1<br><br>void usage()<br>{<br>   fprintf(stderr, &quot;Usage: sa_ch [-v] &lt;channel_num&gt;\n&quot;);<br>
   fprintf(stderr, &quot;  -v : Verbose Mode\n&quot;);<br>   exit(1);<br>}<br><br>int main (int argc, char *argv[])<br>{<br>   rom1394_directory dir;<br>   int device = -1;<br>   int single = 0;<br>   int i;<br>   int verbose = 0;<br>
   int dig[3];<br>   int chn = 708;<br><br>   if (argc &lt; 2) <br>      usage();<br><br>  for(i = 1; i &lt; argc; ++i) {<br>      if ((argv[i][0] == &#39;-&#39;) &amp;&amp; (strlen(argv[i]) &gt; 1)) {<br>        switch(argv[i][1]) {<br>
            case &#39;v&#39;:<br>                verbose = 1;<br>                break;<br>            default:<br>                fprintf(stderr, &quot;WARNING: Unknown option \&#39;%c\&#39;, ignoring&quot;, argv[i][1]);<br>
        }<br>      }<br>      else {<br>          chn = atoi(argv[i]);<br>      }<br>  }<br><br>#ifdef RAW1394_V_0_8<br>   raw1394handle_t handle = raw1394_get_handle();<br>#else<br>   raw1394handle_t handle = raw1394_new_handle();<br>
#endif<br><br>   if (!handle) {<br>      if (!errno) {<br>         fprintf(stderr, &quot;Not Compatible!\n&quot;);<br>      } else {<br>         perror(&quot;Couldn&#39;t get 1394 handle&quot;);<br>         fprintf(stderr, &quot;Is ieee1394, driver, and raw1394 loaded?  Are /dev/raw1394 permissions set correctly?\n&quot;);<br>
      }<br>      exit(1);<br>   } <br><br>   if (raw1394_set_port(handle, 0) &lt; 0) {<br>      perror(&quot;ERROR-- could not set port&quot;);<br>      raw1394_destroy_handle(handle);<br>      exit(1);<br>   }<br><br>   int nc = raw1394_get_nodecount(handle);<br>
   for (i=STARTING_NODE; i &lt; nc; ++i) {<br>      if (rom1394_get_directory(handle, i, &amp;dir) &lt; 0) {<br>         fprintf(stderr,&quot;ERROR reading config rom directory for node %d\n&quot;, i);<br>         raw1394_destroy_handle(handle);<br>
         exit(1);<br>      }<br><br>      if (verbose) <br>         printf(&quot;node %d: vendor_id = 0x%08x model_id = 0x%08x\n&quot;, <br>                 i, dir.vendor_id, dir.model_id); <br><br>/* add new vendor and model ids    to if stanza below */<br>
    <br>      if ( ((dir.vendor_id == SA4250HD_VENDOR_ID1) &amp;&amp;<br>            (dir.model_id == SA4250HD_MODEL_ID1))  || <br>      ((dir.vendor_id == SA4200HD_VENDOR_ID1) &amp;&amp;<br>        (dir.model_id == SA4200HD_MODEL_ID1))) { <br>
            device = i;<br>            break;<br>      }<br>   }<br>    <br>   if (device == -1) {<br>        fprintf(stderr, &quot;Could not find SA42XXHD on the 1394 bus!\n&quot;);<br>    fprintf(stderr, &quot;Try running again with -v and check source code for matching Vendor ID and Model ID-\n&quot;);<br>
    fprintf(stderr, &quot;Add if necessary and recompile.\n&quot;); <br>        raw1394_destroy_handle(handle);<br>        exit(1);<br>   }<br><br>   if (verbose)<br>        printf(&quot;Device acquired on node %d\n&quot;, device);<br>
        printf(&quot;Changing channel %d\n&quot;, chn);<br>        <br>    quadlet_t cmd[3] =<br>        {<br>            CTL_CMD0 | AVC1394_SA3250_OPERAND_KEY_PRESS,<br>            CTL_CMD1 | (chn &lt;&lt; 8),<br>            CTL_CMD2,<br>
        };        <br><br>       if (verbose)<br>            printf(&quot;AV/C Command: cmd0=0x%08x cmd1=0x%08x cmd2=0x%08x\n&quot;,<br>                   cmd[0], cmd[1], cmd[2]);<br>       avc1394_transaction_block(handle, device, cmd, 3, 1);       <br>
<br>        quadlet_t cmd2[3] =<br>        {<br>            CTL_CMD0 | AVC1394_SA3250_OPERAND_KEY_RELEASE,<br>            CTL_CMD1 | (chn &lt;&lt; 8),<br>            CTL_CMD2,<br>        };<br><br>       if (verbose)<br>            printf(&quot;AV/C Command: cmd0=0x%08x cmd1=0x%08x cmd2=0x%08x\n&quot;,<br>
                   cmd2[0], cmd2[1], cmd2[2]);<br>       avc1394_transaction_block(handle, device, cmd2, 3, 1);<br><br>   raw1394_destroy_handle(handle);<br>   exit(0);<br>}<br clear="all"><br>-- <br>Eric<br>