home *** CD-ROM | disk | FTP | other *** search
/ CD/PC Actual 15 / CDACTUAL15.iso / cdactual / drivers / rt_sdk.exe / BC / SAMPLE / FMRADIO.C next >
Encoding:
C/C++ Source or Header  |  1994-05-05  |  5.4 KB  |  155 lines

  1. //////////////////////////////////
  2. //  Program name  : Fmradio.c   //
  3. //                              //
  4. //  Purpose : To allow users    //
  5. //  to control RadioTrack or    //
  6. //  SoundTrack using command    //
  7. //  line options.               //
  8. //////////////////////////////////
  9.  
  10.  
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <math.h>
  14. #include <string.h>
  15. #include <dos.h>
  16. #include "radio.h"
  17.  
  18. #define NoDataBit       16
  19. #define NoControlBit    8
  20. #define CtrlDataMute    0x00
  21. #define CtrlDataSB      0x00
  22. #define CtrlDataRadio   0x00
  23. #define MaxRatio        4748
  24. #define MinRatio        3948
  25. #define TimeBase        0x00
  26. #define RefFreq         0x04
  27. #define Fmin            0x01
  28.  
  29.  
  30. void SetDefault(int,float *),ShowUsage(void),
  31.       Send(unsigned int,unsigned int),DecVolCtrl(void),IncVolCtrl(void);
  32. int Mute=0;
  33. unsigned int Addr[1];
  34.  
  35. void main(int argc,char *argv[])
  36. {
  37.     FILE *CfgFilePtr;
  38.     char *Ptr,*FullFilePath;
  39.     char BkSlash='\\',*CfgFileName="\\RADIOMAN.CFG";
  40.     int Flag=0;
  41.     float Data[30],Freq=88.0;
  42.  
  43.     if(argc > 1) {                      // Must have more on line arguments
  44.         Ptr = strrchr(argv[0],BkSlash);   // Search for last occurrence of backslash
  45.         *Ptr = '\0';                      // If found, place end of string to establish path name
  46.         FullFilePath = (char *)malloc(strlen(argv[0])+strlen(CfgFileName)); // Calculate length of full file name and allocate space
  47.         strcpy(FullFilePath,argv[0]);     // Copy path name to allocated space
  48.         strcat(FullFilePath,CfgFileName); // Append configuration name to it
  49.         CfgFilePtr = fopen(FullFilePath,"rb");   // Open configuration file
  50.         CfgFilePtr = fopen("radioman.cfg","rb");   // Open configuration file
  51.         RT_InitRadio(0x30c);
  52.         rewind(CfgFilePtr);
  53.         if((atof(argv[1]) >= 1) && (atof(argv[1]) <= 10)) {  // See if user is specifying station numbers
  54.             if(CfgFilePtr == NULL) {                    // If can't open configuration file
  55.                 SetDefault(atoi(argv[1]),&Freq);    // Set to default Singapore stations
  56.             }
  57.             else {
  58.                 fread(Data,sizeof(Data),1,CfgFilePtr);   // Read data from file to buffer
  59.                 Freq = Data[atoi(argv[1])-1];   // Set to stations read from configuration file
  60.                 fclose(CfgFilePtr);             // Close file after reading from it
  61.             }
  62.             Flag = 1;    // Set flag to indicate that command was successful
  63.         }
  64.         if((atof(argv[1]) >= 88) && (atof(argv[1]) <= 108)) {  // If user specifies frequency
  65.             Freq = atof(argv[1]);                // Set frequency as specified by user
  66.             Flag = 1;    // Set flag to indicate that command was successful
  67.         }
  68.  
  69.         if(strncmp(strupr(argv[1]),"ON",2) == 0) { // If user only wanted to on the radio
  70.             if(CfgFilePtr == NULL) {           // If can't open configuration file
  71.                 SetDefault(11,&Freq);      // Set to default Singapore station
  72.             }
  73.             else {
  74.                 fread(Data,sizeof(Data),1,CfgFilePtr);   // Read data from file to buffer
  75.                 Freq = Data[(int)Data[10]-1];            // Set to last station listened to
  76.                 fclose(CfgFilePtr);                      // Close file after reading from it
  77.             }
  78.             Flag = 1;   // Set flag to indicate that command was successful
  79.         }
  80.         if(strncmp(strupr(argv[1]),"OFF",3) == 0) { // If user wants SoundBlaster mode
  81.             RT_MuteAudio(1);
  82.             exit(1);
  83.         }
  84.  
  85.         if(strncmp(strupr(argv[1]),"-",1) == 0){  // If user only wanted to on the radio
  86.             RT_VolCtr(1);
  87.             exit(1);
  88.         }
  89.  
  90.         if(strncmp(strupr(argv[1]),"+",1) == 0){  // If user only wanted to on the radio
  91.             RT_VolCtr(0);
  92.             exit(1);
  93.         }
  94.         if(Flag == 1) {              // If command line was good
  95.             RT_TuneStation(Freq,0);
  96.         }
  97.         else {
  98.             ShowUsage();         // If command line was wrong, show user how to do it
  99.             exit(1);             // Exit with error code
  100.         }
  101.     }
  102.     else {
  103.         ShowUsage();         // If command line was wrong, show user how to do it
  104.         exit(1);             // Exit with error code
  105.     }
  106. }
  107.  
  108. //  Function :  To set Singapore default stations if there is no configuration file
  109. //  Variables:  Station is the channel no.
  110. //              Freq is the channel frequency
  111. //  Return   :  Routine returns channel frequency in Freq
  112.  
  113. void SetDefault(int Station,float *Freq)
  114. {
  115.     switch(Station) {
  116.         case 1:         *Freq = 88.9;  // Set to 88.9 MHz
  117.                 break;
  118.         case 2:         *Freq = 90.5;  // Set to 90.5 MHz
  119.                 break;
  120.         case 3:         *Freq = 91.3;  // Set to 91.3 MHz
  121.                 break;
  122.         case 4:         *Freq = 92.4;  // Set to 92.4 MHz
  123.                 break;
  124.         case 5:         *Freq = 93.3;  // Set to 93.3 MHz
  125.                 break;
  126.         case 6:         *Freq = 94.2;  // Set to 94.2 MHz
  127.                 break;
  128.         case 7:         *Freq = 95.0;  // Set to 95.0 MHz
  129.                 break;
  130.         case 8:         *Freq = 95.8;  // Set to 95.8 MHz
  131.                 break;
  132.         case 9:         *Freq = 98.7;  // Set to 98.7 MHz
  133.                 break;
  134.         case 10:        *Freq = 100.3; // Set to 100.3 MHz
  135.                 break;
  136.         case 11:        *Freq = 91.3;  // Default station when returning from mute off function
  137.                 break;         // if configuration file was not found
  138.     }
  139. }
  140.  
  141. // Function  :  To show program usage to user if command was entered wrongly
  142.  
  143. void ShowUsage(void)
  144. {
  145.     printf("\nUsage   :  fmradio  [arg 1] \n");
  146.     printf("\n");
  147.     printf("[arg 1] =  Any of the following :\n");
  148.     printf("           i.   [On] or [Off] to switch on or off fm radio\n");
  149.     printf("           ii.  Channel no. [1 - 10]\n");
  150.     printf("           iii. Frequency value [88 - 108] MHz\n");
  151.     printf("           iv.  [-] or [+] to decrease or increase volume\n");
  152. }
  153.  
  154.  
  155.