Skip to content

Instantly share code, notes, and snippets.

@karuna
Created July 5, 2015 10:37
Show Gist options
  • Save karuna/a773b6f9234f660026f2 to your computer and use it in GitHub Desktop.
Save karuna/a773b6f9234f660026f2 to your computer and use it in GitHub Desktop.
wave radio for indonesia
#include <math.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/ioctl.h>
#include <machine/speaker.h>
#define SPEAKER "/dev/speaker"
static struct tm *ptmOurs;
static time_t ttOurs;
static struct timeval tvOurs;
static struct timezone tzOurs;
static struct timespec tsAsked, tsRemaining;
static int iFrequencies[2][60]={2000,
1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,
1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,
1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,
1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,
1000,1000,1000,1000,1000,1000,1000,1000,1000,1000,
1000,1000,1000,1000,1000,1000,500,500,500,
2000,
700,700,700,700,700,700,700,700,700,700,
700,700,700,700,700,700,700,700,700,700,
700,700,700,700,700,700,700,700,700,700,
700,700,700,700,700,700,700,700,700,700,
700,700,700,700,700,700,700,700,700,700,
700,700,700,700,700,700,500,500,500};
static int iDurations[2][60]={50,
5,5,5,5,5,5,5,5,50,5,
5,5,5,5,5,5,5,5,50,5,
5,5,5,5,5,5,5,5,50,5,
5,5,5,5,5,5,5,5,50,5,
5,5,5,5,5,5,5,5,50,5,
5,5,5,5,5,5,20,20,20,
50,
5,5,5,5,5,5,5,5,50,5,
5,5,5,5,5,5,5,5,50,5,
5,5,5,5,5,5,5,5,50,5,
5,5,5,5,5,5,5,5,50,5,
5,5,5,5,5,5,5,5,50,5,
5,5,5,5,5,5,20,20,20};
int main(int iArgc, char *pszArgv[])
{
int iSec, iMin;
long double ldLastElapsed, ldTOD, ldLastTOD, ldElapsed;
long lSleepInt;
tone_t toneOurs;
int fSpeaker;
if ((fSpeaker=open(SPEAKER,O_WRONLY,0))==-1)
{
printf("Speaker open failed; make sure %s is configured and writable .\n",SPEAKER);
}
while (1==1)
{
gettimeofday(&tvOurs,&tzOurs);
ttOurs=time(NULL);
ptmOurs=gmtime(&ttOurs);
printf("%04d/%02d/%02d %02d:%02d:%02d\n",ptmOurs->tm_year+1900,ptmOurs->tm_mon,
ptmOurs->tm_mday,ptmOurs->tm_hour,ptmOurs->tm_min,ptmOurs->tm_sec);
iSec=ptmOurs->tm_sec;
iMin=ptmOurs->tm_min;
toneOurs.frequency=iFrequencies[iMin&1][iSec];
toneOurs.duration=iDurations[iMin%1][iSec];
if (fSpeaker!=-1)
{
ioctl(fSpeaker,SPKRTONE,&toneOurs);
}
gettimeofday(&tvOurs,&tzOurs);
ttOurs=time(NULL);
ptmOurs=gmtime(&ttOurs);
lSleepInt=1000000000-(tvOurs.tv_usec*1000);
tsAsked.tv_sec=0;
tsAsked.tv_nsec=lSleepInt;
nanosleep(&tsAsked,&tsRemaining);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment