Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A simple comman line signal strength meter for dvb



Below is the code for a simple signal strength meter that you can run in an
xterm
You need to tune in some station first, for example with gVideo or VDR.
Then exit these apps.


Put this file in a directory parallel to the dvb tree
(like you did with VTR) this cause it uses teh header dvb.h.
Then compile with
gcc sdb.c
This will generate a.out
run:
./a.out

I will perhaps make a distribution later.
Kill with ctrl C
Explanation is in the code below.

Nice to point teh disk, signal strengs is displayed like this:
Panteltje signal_strength meter-0.1

Opened /dev/video0
***********************************10.1 dB 


Remember this is just a quick hack, and I extracted it from some other
stuff I am writing.


// FIXME: these should be defined in ../DVB/driver/dvb.h!!!
typedef unsigned int __u32;
typedef unsigned short __u16;
typedef unsigned char __u8;

#include "../DVB/driver/dvb.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>


main(int argc, char **argv)
{
int a, i, f, r;
struct video_capability cap;
char temp[1024];

iopl(3);

#define VIDEODEV "/dev/video"

fprintf(stdout, "\nPanteltje signal_strength meter-0.1\n\n");

for(i = 0; i < 10; i++)
        {
        sprintf(temp, "%s%d", VIDEODEV, i);
        if(access(temp, F_OK | R_OK | W_OK) != 0)
                {
//                fprintf(stdout, "main(): could not access device %s\n", temp);
//                perror("access");
                exit(1);
                }

        f = open(temp, O_RDWR);
        if(f < 0) 
                {
                }

        r = ioctl(f, VIDIOCGCAP, &cap);

        if(r == 0 && (cap.type & VID_TYPE_DVB) )
                {
                fprintf(stdout, "Opened %s\n", temp);

                print_signal_strength(f);

                /* close video device */
                close(f);
                }/* end if f OK */
        else
                {
                }
        }/* end for i */

exit(0);
}/* end function main */


int print_signal_strength(int videoDev)
{
int a, c, i;
int top;
struct frontend front;
double dstep, deebee;

/* this how many stars maximum in display */
#define MAX_SCALE        50

/*
the agc value is now in front.agc (16 bits integer),
the stronger the signal, the more the agc (automatic gain control)
drops.

65280 = 0dB no signal          0 % scale
19000 = 10 dB
        0 = ?? dB                        100 % scale
*/

/* if 19000 = 10dB and 65280 = 0dB then 1 dB = */
dstep = (65280.0 - 19000.0) / 10.0;
        
/* prevent devide by zero later on */
if(front.agc == 65535) front.agc = 1;

while(1)
        {
//        c = getc(stdin);
//        ungetc(c, stdin);

//        if(c == 27) return 1; // ESCAPE exits

        ioctl(videoDev, VIDIOCGFRONTEND, &front);  

        top = 65535 - front.agc;
        top = top * (MAX_SCALE / 65536.0);

        // scale is linear due to agc log
        deebee =  (65535 - front.agc) / dstep ;  

        for(i = 0; i < MAX_SCALE; i++)
                {
                if(i < top) fprintf(stdout, "*");
                else if(i == top) fprintf(stdout, "%2.1f dB", deebee);
                else fprintf(stdout, " ");
                }
        fprintf(stdout, "\r");

        }/* end while display signal strength loop */

return 1;
}/* end function print signal_strength */




Home | Main Index | Thread Index