scanEtv.sh 2.87 KB
Newer Older
Kevin Kershaw's avatar
Kevin Kershaw committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
#!/bin/bash
#  File:        scanEtv.sh
#  Author:      Nick Nielsen <n.nielsen@cablelabs.com>
#  Date:        Fri Jan 29 10:14:44 2010
#  Description: Will scan the qam channels to look for ETV signaling

STILLRUNNING=`ps -aef | grep 'comcast-truview' | grep -v 'grep'`

if [ ! -z "$STILLRUNNING" ] ; then
    echo "ERROR: You may not run scanEtv.sh while the tunnel sniffer is running."
    exit -1
fi

# The first EIA channel to look for ETV
START=51

# The last EIA channel to look for ETV
STOP=135

PRINT_DEBUG=0

# Handle Command-line arguments!
until [ -z "$1" ] 
do
    if [ "$1" == "-d" ] ; then
        echo "Printing DEBUG information."
        PRINT_DEBUG=1
    else
        # If a channel is specified, then only scan that particular channel.
        echo "Scanning for EIA channel $1 only."
        START=$1
        STOP=$1
    fi
    shift
done

TEMP=`./miscellaneous/hdhomerun/libhdhomerun/hdhomerun_config discover`
HDHRID=`echo $TEMP | awk '{ print $3 }'`
IP=`echo $TEMP | awk '{ print $6 }'`

if [ -z "$HDHRID" ] ; then
    echo "ERROR: no HDHomeRun device detected."
    exit -1;
fi 

echo "Detected HDHomeRun device ID $HDHRID at $IP"

# The numbers in this for loop are the channels to search.
# Here at CableLabs, EIA channels 2 through 60 are analog (57 MHz through 441 MHz)
# 61 is 447 MHz
# 159 is the highest available EIA channel, at 1005 MHz.  However, the highest 
# channel that the HDHomerun can tune is 135, at 861 MHz.

# In Comcast's Denver feed, the lowest QAM channel that is present is at 
# channel 51 (387 MHz)

for((i=$START;i<=$STOP;i++))
do
    echo -n "."
    ./miscellaneous/hdhomerun/libhdhomerun/hdhomerun_config $HDHRID set /tuner0/channel "auto:$i"
    RET=$?
    if [ $RET != 0 ] ; then
        echo "ERROR $RET occurred setting to channel $i"
        exit $RET;
    fi
    echo -n "."
    sleep 1

    DEBUG=`./miscellaneous/hdhomerun/libhdhomerun/hdhomerun_config $HDHRID get /tuner0/debug`
    echo -n "."
    
    if [ "$PRINT_DEBUG" == "1" ] ; then
        echo "$DEBUG"
    fi
    
    QAMNONE=`echo "$DEBUG" | grep 'lock=none'`
    echo -n "."

    if [ ! -z "$QAMNONE" ] ; then
        echo "   Could not lock onto $i"
    else
        echo "LOCKED at $i"
        echo -n "+"
        STREAMSTRUCTURE=`./miscellaneous/hdhomerun/libhdhomerun/hdhomerun_config $HDHRID streamstructure /tuner0/debug 2>&1`
        echo -n "+"
        
        echo "$STREAMSTRUCTURE" > structure.log
        if [ "$PRINT_DEBUG" == "1" ] ; then
            echo ""
            echo "$STREAMSTRUCTURE"
        fi

        echo -n "+"
        
        PIDS=`echo "$STREAMSTRUCTURE" | egrep 'descriptor 161|descriptor 162' -B 4 | grep pid | awk -F= '{ print $3 }' | awk '{ print $1 }' | sed -e 's/\"//g'`
        echo -n "+"
        #PIDS=`echo $PIDS | sed 's/\n/ /g'`

        if [ ! -z "$PIDS" ] ; then
            echo "Found ETV PIDS for channel $i:" $PIDS
        fi
        echo -n "+"
    fi
done