F5OEO-rpitx/src/tune.cpp

145 wiersze
2.8 KiB
C++
Czysty Zwykły widok Historia

2018-03-22 15:46:38 +00:00
#include <unistd.h>
2021-01-13 09:47:38 +00:00
#include <librpitx/librpitx.h>
2018-03-22 15:46:38 +00:00
#include "stdio.h"
#include <cstring>
#include <signal.h>
2018-12-01 00:00:00 +00:00
#include <stdlib.h>
2018-03-22 15:46:38 +00:00
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\
2019-01-08 15:07:50 +00:00
-p set clock ppm instead of ntp adjust\n\
2018-03-22 15:46:38 +00:00
-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;
2019-01-08 15:07:50 +00:00
dbg_setlevel(1);
2018-03-22 15:46:38 +00:00
bool NotKill=false;
bool ppmSet = false;
float ppm = 0.0f;
char * endptr = NULL;
2018-03-22 15:46:38 +00:00
while(1)
{
2019-01-08 15:07:50 +00:00
a = getopt(argc, argv, "f:ehp:");
2018-03-22 15:46:38 +00:00
if(a == -1)
{
if(anyargs) break;
else a='h'; //print usage and exit
}
anyargs = 1;
switch(a)
{
case 'f': // Frequency
SetFrequency = strtof(optarg, &endptr);
if (endptr == optarg || SetFrequency <= 0.0f || SetFrequency == HUGE_VALF) {
fprintf(stderr, "tune: not a valid frequency - '%s'", optarg);
exit(1);
}
2018-03-22 15:46:38 +00:00
break;
2019-01-08 15:07:50 +00:00
case 'e': //End immediately
2018-03-22 15:46:38 +00:00
NotKill=true;
break;
2019-01-08 15:07:50 +00:00
case 'p': //ppm
ppm = strtof(optarg, &endptr);
if (endptr == optarg || ppm <= 0.0f || ppm == HUGE_VALF) {
fprintf(stderr, "tune: not a valid ppm - '%s'", optarg);
exit(1);
}
ppmSet = true;
2019-01-08 15:07:50 +00:00
break;
2018-03-22 15:46:38 +00:00
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);
}
2018-06-14 09:37:51 +00:00
generalgpio gengpio;
gengpio.setpulloff(4);
padgpio pad;
pad.setlevel(7);
2018-03-22 15:46:38 +00:00
clkgpio *clk=new clkgpio;
clk->SetAdvancedPllMode(true);
if(ppmSet) //ppm is set else use ntp
2019-01-08 15:07:50 +00:00
clk->Setppm(ppm);
2018-03-22 15:46:38 +00:00
clk->SetCenterFrequency(SetFrequency,10);
clk->SetFrequency(000);
clk->enableclk(4);
2019-01-08 15:07:50 +00:00
//clk->enableclk(6);//CLK2 : experimental
2018-11-09 17:06:39 +00:00
//clk->enableclk(20);//CLK1 duplicate on GPIO20 for more power ?
2018-03-22 15:46:38 +00:00
if(!NotKill)
{
while(running)
{
sleep(1);
}
clk->disableclk(4);
clk->disableclk(20);
2018-03-22 15:46:38 +00:00
delete(clk);
}
else
{
//Ugly method : not destroying clk object will not call destructor thus leaving clk running
}
}