/*******************************************************************************
* TapeStateGen.cc TMS System State Table Generation utility
* T.Barnaby, BEAM Ltd, 2007-03-14
*******************************************************************************
*/
#include <stdio.h>
#include <syslog.h>
#include <unistd.h>
#include <getopt.h>
#include <SigGen.h>
#include <Gen.h>
void usage(){
fprintf(stderr, "tmsStateGen: Version: %s\n", VERSION);
fprintf(stderr, "Usage: tmsstategen [options] <filename>\n");
fprintf(stderr, "Generates a Tms State Table for a particular BEAM type to a file.\n");
fprintf(stderr, " -t <type> - Specifies the signal type (beam1 etc)\n");
fprintf(stderr, " -T - List all signal types supported\n");
fprintf(stderr, " -p - Produce Phase Table ASCII dump file\n");
fprintf(stderr, " -fd <n> - Set pllInitialFrequencyDelay to n ms\n");
fprintf(stderr, " -fref <n> - Set FREF to n Hz\n");
fprintf(stderr, " -name <n> - Set name n\n");
}
static struct option options[] = {
{ "?", 0, NULL, 0 },
{ "h", 0, NULL, 0 },
{ "help", 0, NULL, 0 },
{ "T", 0, NULL, 0 },
{ "t", 1, NULL, 0 },
{ "p", 0, NULL, 0 },
{ "fd", 1, NULL, 0 },
{ "fref", 1, NULL, 0 },
{ "name", 1, NULL, 0 },
{ 0,0,0,0 }
};
int main(int argc, char** argv){
BError err;
Gen* gen = 0;
NameValueList params;
BString s;
BList<Gen*>& genList = genInit();
BIter i;
int c;
int optIndex = 0;
BString fileName = "";
BString typeName = "";
int listTypes = 0;
double fref = 437000;
double sampleRate;
int pllInitialFrequencyDelay = 0;
BString name;
while((c = getopt_long_only(argc, argv, "", options, &optIndex)) == 0){
s = options[optIndex].name;
if(s == "help" || s == "h" || s == "?"){
usage();
return 1;
}
else if(s == "T"){
listTypes = 1;
}
else if(s == "t"){
typeName = optarg;
}
else if(s == "p"){
params.setValue("phaseTableFile", "1");
}
else if(s == "fd"){
pllInitialFrequencyDelay = atoi(optarg);
}
else if(s == "fref"){
fref = atoi(optarg);
}
else if(s == "name"){
name = optarg;
}
}
if(!listTypes && (optind == argc)){
usage();
return 1;
}
sampleRate = 512 * fref;
// sampleRate = 125000000;
params.setValue("sampleRate", sampleRate);
params.setValue("fref", fref);
params.setValue("fileName", argv[optind++]);
params.setValue("useMsbFref", 1);
params.setValue("pllInitialFrequencyDelay", pllInitialFrequencyDelay);
params.setValue("name", name);
printf("SampleRate: %f\n", sampleRate);
printf("FRef: %f\n", fref);
printf("PllInitialFrequencyDelay: %d\n", pllInitialFrequencyDelay);
if(listTypes){
for(genList.start(i); !genList.isEnd(i); genList.next(i)){
printf("%s: %s\n", genList[i]->name().retStr(), genList[i]->info().retStr());
}
return 0;
}
if(typeName == ""){
usage();
return 1;
}
for(genList.start(i); !genList.isEnd(i); genList.next(i)){
if(typeName.toLower() == genList[i]->name().toLower()){
gen = genList[i];
break;
}
}
if(gen == 0){
fprintf(stderr, "Signal type: %s not implemented\n", typeName.retStr());
return 1;
}
printf("Generating TMS State Table for signal: %s\n", gen->info().retStr());
if(err = gen->init(params)){
fprintf(stderr, "Gen Init Error: %s\n", err.getString().retStr());
return 1;
}
if(err = gen->run()){
fprintf(stderr, "Gen Run Error: %s\n", err.getString().retStr());
return 1;
}
return 0;
}