home *** CD-ROM | disk | FTP | other *** search
- //////////////////////////////////
- // Program name : Fmradio.c //
- // //
- // Purpose : To allow users //
- // to control RadioTrack or //
- // SoundTrack using command //
- // line options. //
- //////////////////////////////////
-
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include <dos.h>
- #include "radio.h"
-
- #define NoDataBit 16
- #define NoControlBit 8
- #define CtrlDataMute 0x00
- #define CtrlDataSB 0x00
- #define CtrlDataRadio 0x00
- #define MaxRatio 4748
- #define MinRatio 3948
- #define TimeBase 0x00
- #define RefFreq 0x04
- #define Fmin 0x01
-
-
- void SetDefault(int,float *),ShowUsage(void),
- Send(unsigned int,unsigned int),DecVolCtrl(void),IncVolCtrl(void);
- int Mute=0;
- unsigned int Addr[1];
-
- void main(int argc,char *argv[])
- {
- FILE *CfgFilePtr;
- char *Ptr,*FullFilePath;
- char BkSlash='\\',*CfgFileName="\\RADIOMAN.CFG";
- int Flag=0;
- float Data[30],Freq=88.0;
-
- if(argc > 1) { // Must have more on line arguments
- Ptr = strrchr(argv[0],BkSlash); // Search for last occurrence of backslash
- *Ptr = '\0'; // If found, place end of string to establish path name
- FullFilePath = (char *)malloc(strlen(argv[0])+strlen(CfgFileName)); // Calculate length of full file name and allocate space
- strcpy(FullFilePath,argv[0]); // Copy path name to allocated space
- strcat(FullFilePath,CfgFileName); // Append configuration name to it
- CfgFilePtr = fopen(FullFilePath,"rb"); // Open configuration file
- CfgFilePtr = fopen("radioman.cfg","rb"); // Open configuration file
- RT_InitRadio(0x30c);
- rewind(CfgFilePtr);
- if((atof(argv[1]) >= 1) && (atof(argv[1]) <= 10)) { // See if user is specifying station numbers
- if(CfgFilePtr == NULL) { // If can't open configuration file
- SetDefault(atoi(argv[1]),&Freq); // Set to default Singapore stations
- }
- else {
- fread(Data,sizeof(Data),1,CfgFilePtr); // Read data from file to buffer
- Freq = Data[atoi(argv[1])-1]; // Set to stations read from configuration file
- fclose(CfgFilePtr); // Close file after reading from it
- }
- Flag = 1; // Set flag to indicate that command was successful
- }
- if((atof(argv[1]) >= 88) && (atof(argv[1]) <= 108)) { // If user specifies frequency
- Freq = atof(argv[1]); // Set frequency as specified by user
- Flag = 1; // Set flag to indicate that command was successful
- }
-
- if(strncmp(strupr(argv[1]),"ON",2) == 0) { // If user only wanted to on the radio
- if(CfgFilePtr == NULL) { // If can't open configuration file
- SetDefault(11,&Freq); // Set to default Singapore station
- }
- else {
- fread(Data,sizeof(Data),1,CfgFilePtr); // Read data from file to buffer
- Freq = Data[(int)Data[10]-1]; // Set to last station listened to
- fclose(CfgFilePtr); // Close file after reading from it
- }
- Flag = 1; // Set flag to indicate that command was successful
- }
- if(strncmp(strupr(argv[1]),"OFF",3) == 0) { // If user wants SoundBlaster mode
- RT_MuteAudio(1);
- exit(1);
- }
-
- if(strncmp(strupr(argv[1]),"-",1) == 0){ // If user only wanted to on the radio
- RT_VolCtr(1);
- exit(1);
- }
-
- if(strncmp(strupr(argv[1]),"+",1) == 0){ // If user only wanted to on the radio
- RT_VolCtr(0);
- exit(1);
- }
- if(Flag == 1) { // If command line was good
- RT_TuneStation(Freq,0);
- }
- else {
- ShowUsage(); // If command line was wrong, show user how to do it
- exit(1); // Exit with error code
- }
- }
- else {
- ShowUsage(); // If command line was wrong, show user how to do it
- exit(1); // Exit with error code
- }
- }
-
- // Function : To set Singapore default stations if there is no configuration file
- // Variables: Station is the channel no.
- // Freq is the channel frequency
- // Return : Routine returns channel frequency in Freq
-
- void SetDefault(int Station,float *Freq)
- {
- switch(Station) {
- case 1: *Freq = 88.9; // Set to 88.9 MHz
- break;
- case 2: *Freq = 90.5; // Set to 90.5 MHz
- break;
- case 3: *Freq = 91.3; // Set to 91.3 MHz
- break;
- case 4: *Freq = 92.4; // Set to 92.4 MHz
- break;
- case 5: *Freq = 93.3; // Set to 93.3 MHz
- break;
- case 6: *Freq = 94.2; // Set to 94.2 MHz
- break;
- case 7: *Freq = 95.0; // Set to 95.0 MHz
- break;
- case 8: *Freq = 95.8; // Set to 95.8 MHz
- break;
- case 9: *Freq = 98.7; // Set to 98.7 MHz
- break;
- case 10: *Freq = 100.3; // Set to 100.3 MHz
- break;
- case 11: *Freq = 91.3; // Default station when returning from mute off function
- break; // if configuration file was not found
- }
- }
-
- // Function : To show program usage to user if command was entered wrongly
-
- void ShowUsage(void)
- {
- printf("\nUsage : fmradio [arg 1] \n");
- printf("\n");
- printf("[arg 1] = Any of the following :\n");
- printf(" i. [On] or [Off] to switch on or off fm radio\n");
- printf(" ii. Channel no. [1 - 10]\n");
- printf(" iii. Frequency value [88 - 108] MHz\n");
- printf(" iv. [-] or [+] to decrease or increase volume\n");
- }
-
-
-