Mailing List archive

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

[linux-dvb] Re: how to determine signal strength under linux ?



Johannes Stezenbach wrote:
> 
> The attached piece of code does it with the new API.
> -- No attachments (even text) are allowed --
> -- Type: text/plain
> -- File: signalstrength.c

&$§%&§!

---snip-------
/*
 * print signal stength for the current transponder
 */


#define FRONTENDDEVICE "/dev/ost/qpskfe"

#include <stdint.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>


#include <sys/time.h>
#include <linux/ost/frontend.h>


/* signal strength scale values */ 
#define ZERO_DB         1
#define TEN_DB          182


void
print_bar(double val, double min, double max, uint len)
{
  int i;
  uint num;
  if (val <= min)
    num = 0;
  else if (val >= max)
    num = len;
  else
    num = (uint) ((val - min) / (max - min) * len);
  for (i = 0; i <= num; i++)
    putchar('#');
  for (; i < len ; i++)
    putchar(' ');
}

double
get_signal_strength (int fefd, int *raw)
{
  int signalstrength;
  double db, dstep;

  if (ioctl (fefd, FE_READ_SIGNAL_STRENGTH, &signalstrength) == -1)
    {
      perror ("ioctl FE_READ_SIGNAL_STRENGTH failed");
      return -100.0;
    }

  if (raw)
    *raw = signalstrength;

  /* calculate size of one step (1 dB) */
  dstep = (ZERO_DB - TEN_DB) / 10.0;

  db = signalstrength / dstep;
  return db;
}

#if 0
double
get_signal_noise_ratio (int fefd)
{
  int snr;

  if (ioctl (fefd, FE_READ_SNR, &snr) == -1)
    {
      perror ("ioctl FE_READ_SNR failed");
      return -100.0;
    }
  //FIXME: driver scale value is incorrect/unknown
  return (1.0e-6 * snr);
}
#endif

uint
get_sync (int fefd)
{
  struct qpskRegister reg;

  reg.chipId = 0x20; /* decoder */
  reg.address = 0x0e; /* sync */
  if (ioctl (fefd, QPSK_READ_REGISTER, &reg) == -1)
    {
      perror ("ioctl QPSK_READ_REGISTER failed");
      return 0;
    }

  return (uint) reg.value;
}


int main (int argc, char *argv[])
{
  int fefd;
  double strength;
  int raw;

  fefd = open (FRONTENDDEVICE, O_RDWR);
  if (fefd == -1) {
    perror ("opening frontend failed");
    return 1;
  }

  for (;;)
    {
      strength = get_signal_strength(fefd, &raw);
      printf ("0x%02x %03d %7.3f ", get_sync(fefd), raw, strength);
      print_bar(strength, -20.0, 10.0, 60);
      putchar('\n');
      //usleep(250000);
    }

  close (fefd);

  return 0;
}
---snip-------

Regards,
Johannes


--
Info:
To unsubscribe send a mail to listar@linuxtv.org with "unsubscribe linux-dvb" as subject.



Home | Main Index | Thread Index