Advertisement
Guest User

Untitled

a guest
Sep 29th, 2010
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <errno.h>
  3. #include <stropts.h>
  4. #include <fcntl.h>
  5.  
  6. #include <si4713.h>
  7. #include <asm/ioctl.h>
  8.  
  9. //warning testing only...
  10. //some missing error handling around ;)
  11.  
  12.  
  13. int main (int argc, char *argv[]) //argc = number of arguments (including program name!), argv = list of strings
  14.  
  15. {
  16.     if (argc < 2) //check if argument for frequenzy is given
  17.         {
  18.             printf("Need frequency argument\n");
  19.  
  20.             return -EINVAL;
  21.         }
  22.  
  23.     int fd = open("/dev/radio0", O_RDWR); //opens "file" /deve/radio with reading and writing flag (O_RDWR)
  24.     perror ("Opening /dev/radio0:");
  25.  
  26.     if (fd < 0) //if opening of file fails:
  27.         {
  28.             close(fd); //close file
  29.  
  30.             return fd;
  31.         }
  32.  
  33.  
  34.     struct si4713_rnl rnl; //define structure rnl as si4713_rnl
  35.     int rval; //variable for noise level
  36.  
  37.  
  38.     sscanf(argv[1], "%d", &rnl.frequency); //writes the string to int convertet frequency argument to rnl.frequenzy (& = no pinter)
  39.     //Missing error handling?
  40.  
  41.  
  42.     rval = ioctl(fd, SI4713_IOC_MEASURE_RNL, &rnl);
  43.     perror ("Optaining noise Level:");
  44.    
  45.     if (rval < 0)
  46.         {
  47.         close(fd);
  48.  
  49.         return rval;
  50.         }
  51.  
  52.  
  53.     printf("received noise level: %d\n", rval);
  54.  
  55.  
  56.  
  57.     close(fd);
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement