I just set up mythbackend to record with the HD-PVR 1212 from the SA4250HDC cable box. Thanks to Major Idiot's firewire script posted at <a href="http://ubuntuforums.org/showpost.php?p=4453681&postcount=3">http://ubuntuforums.org/showpost.php?p=4453681&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'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'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 <<a href="mailto:mythdev@son.org">mythdev@son.org</a>> <br>
* Copyright 2005 Matt Porter <<a href="mailto:mporter@kernel.crashing.org">mporter@kernel.crashing.org</a>><br> * Portions Copyright 2006 Chris Ingrassia <<a href="mailto:chris@spicecoffee.org">chris@spicecoffee.org</a>> (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 <libavc1394/rom1394.h><br>#include <libavc1394/avc1394.h><br>#include <libraw1394/raw1394.h><br>#include <sys/types.h><br>#include <stdio.h><br>#include <errno.h><br>
#include <stdlib.h><br>#include <string.h><br><br>/* SA42xxHD IDs */<br>#define SA4200HD_VENDOR_ID1 0x000014f8<br>#define SA4200HD_MODEL_ID1 0x00001072<br>#define SA4250HD_VENDOR_ID1 0x00001e6b /* eric's stb */<br>
#define SA4250HD_MODEL_ID1 0x000010cc /* eric's stb */<br><br>/* add additional vendor and model id'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 << 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, "Usage: sa_ch [-v] <channel_num>\n");<br>
fprintf(stderr, " -v : Verbose Mode\n");<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 < 2) <br> usage();<br><br> for(i = 1; i < argc; ++i) {<br> if ((argv[i][0] == '-') && (strlen(argv[i]) > 1)) {<br> switch(argv[i][1]) {<br>
case 'v':<br> verbose = 1;<br> break;<br> default:<br> fprintf(stderr, "WARNING: Unknown option \'%c\', ignoring", 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, "Not Compatible!\n");<br> } else {<br> perror("Couldn't get 1394 handle");<br> fprintf(stderr, "Is ieee1394, driver, and raw1394 loaded? Are /dev/raw1394 permissions set correctly?\n");<br>
}<br> exit(1);<br> } <br><br> if (raw1394_set_port(handle, 0) < 0) {<br> perror("ERROR-- could not set port");<br> raw1394_destroy_handle(handle);<br> exit(1);<br> }<br><br> int nc = raw1394_get_nodecount(handle);<br>
for (i=STARTING_NODE; i < nc; ++i) {<br> if (rom1394_get_directory(handle, i, &dir) < 0) {<br> fprintf(stderr,"ERROR reading config rom directory for node %d\n", i);<br> raw1394_destroy_handle(handle);<br>
exit(1);<br> }<br><br> if (verbose) <br> printf("node %d: vendor_id = 0x%08x model_id = 0x%08x\n", <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) &&<br> (dir.model_id == SA4250HD_MODEL_ID1)) || <br> ((dir.vendor_id == SA4200HD_VENDOR_ID1) &&<br> (dir.model_id == SA4200HD_MODEL_ID1))) { <br>
device = i;<br> break;<br> }<br> }<br> <br> if (device == -1) {<br> fprintf(stderr, "Could not find SA42XXHD on the 1394 bus!\n");<br> fprintf(stderr, "Try running again with -v and check source code for matching Vendor ID and Model ID-\n");<br>
fprintf(stderr, "Add if necessary and recompile.\n"); <br> raw1394_destroy_handle(handle);<br> exit(1);<br> }<br><br> if (verbose)<br> printf("Device acquired on node %d\n", device);<br>
printf("Changing channel %d\n", chn);<br> <br> quadlet_t cmd[3] =<br> {<br> CTL_CMD0 | AVC1394_SA3250_OPERAND_KEY_PRESS,<br> CTL_CMD1 | (chn << 8),<br> CTL_CMD2,<br>
}; <br><br> if (verbose)<br> printf("AV/C Command: cmd0=0x%08x cmd1=0x%08x cmd2=0x%08x\n",<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 << 8),<br> CTL_CMD2,<br> };<br><br> if (verbose)<br> printf("AV/C Command: cmd0=0x%08x cmd1=0x%08x cmd2=0x%08x\n",<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>