Add tune utility

v2beta
F5OEO 2018-03-22 15:46:38 +00:00
rodzic 43021f4501
commit 02d2523951
2 zmienionych plików z 121 dodań i 1 usunięć

Wyświetl plik

@ -1,5 +1,5 @@
#all: ../rpitx ../pissb ../pisstv ../pifsq ../pifm ../piam ../pidcf77
all: ../pisstv ../piopera ../pifsq ../pichirp ../sendiq ../pissb
all: ../pisstv ../piopera ../pifsq ../pichirp ../sendiq ../pissb ../tune
CFLAGS = -Wall -g -O2 -Wno-unused-variable
LDFLAGS = librpitx/src/librpitx.a -lm -lrt -lpthread
@ -31,6 +31,8 @@ LDFLAGS_Pissb = librpitx/src/librpitx.a -lm -lrt -lpthread -lsndfile
../sendiq : sendiq.cpp
$(CC) $(CFLAGS) -o ../sendiq sendiq.cpp $(LDFLAGS)
../tune : tune.cpp
$(CC) $(CFLAGS) -o ../tune tune.cpp $(LDFLAGS)
CFLAGS_Pifm = -Wall -g -O2 -Wno-unused-variable
LDFLAGS_Pifm = librpitx/src/librpitx.a -lm -lrt -lpthread -lsndfile

118
src/tune.cpp 100644
Wyświetl plik

@ -0,0 +1,118 @@
#include <unistd.h>
#include "librpitx/src/librpitx.h"
#include "stdio.h"
#include <cstring>
#include <signal.h>
bool running=true;
#define PROGRAM_VERSION "0.1"
void print_usage(void)
{
fprintf(stderr,\
"\ntune -%s\n\
Usage:\ntune [-f Frequency] [-h] \n\
-f float frequency carrier Hz(50 kHz to 1500 MHz),\n\
-e exit immediately without killing the carrier,\n\
-h help (this help).\n\
\n",\
PROGRAM_VERSION);
} /* end function print_usage */
static void
terminate(int num)
{
running=false;
fprintf(stderr,"Caught signal - Terminating\n");
}
int main(int argc, char* argv[])
{
int a;
int anyargs = 0;
float SetFrequency=434e6;
bool NotKill=false;
while(1)
{
a = getopt(argc, argv, "f:eh");
if(a == -1)
{
if(anyargs) break;
else a='h'; //print usage and exit
}
anyargs = 1;
switch(a)
{
case 'f': // Frequency
SetFrequency = atof(optarg);
break;
case 'e': // SampleRate (Only needeed in IQ mode)
NotKill=true;
break;
case 'h': // help
print_usage();
exit(1);
break;
case -1:
break;
case '?':
if (isprint(optopt) )
{
fprintf(stderr, "tune: unknown option `-%c'.\n", optopt);
}
else
{
fprintf(stderr, "tune: unknown option character `\\x%x'.\n", optopt);
}
print_usage();
exit(1);
break;
default:
print_usage();
exit(1);
break;
}/* end switch a */
}/* end while getopt() */
for (int i = 0; i < 64; i++) {
struct sigaction sa;
std::memset(&sa, 0, sizeof(sa));
sa.sa_handler = terminate;
sigaction(i, &sa, NULL);
}
clkgpio *clk=new clkgpio;
clk->SetAdvancedPllMode(true);
clk->SetCenterFrequency(SetFrequency,10);
clk->SetFrequency(000);
clk->enableclk(4);
if(!NotKill)
{
while(running)
{
sleep(1);
}
clk->disableclk(4);
delete(clk);
}
else
{
//Ugly method : not destroying clk object will not call destructor thus leaving clk running
}
}