analysis mode

* changes to data file output - submitted by John Gibbons, N8OBJ
This commit is contained in:
John Gibbons 2020-02-28 14:46:26 -06:00 committed by David Freese
parent ece3e24866
commit e9a2ef2dd0
2 changed files with 204 additions and 28 deletions

View file

@ -6,6 +6,8 @@
//
// This file is part of fldigi.
//
// Modified for data file creation / analysis JC Gibbons N8OBJ 5/14/19
//
// Fldigi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
@ -32,16 +34,17 @@
#include "fftfilt.h"
#include "modem.h"
#define ANAL_SAMPLERATE 8000
#define FILT_LEN 4 //seconds
#define PIPE_LEN 120
#define DSP_CNT 1 //seconds
#define ANAL_BW 4
#define PIPE_LEN 120
#define DSP_CNT 1 //seconds
#define ANAL_BW 4
class anal : public modem {
private:
double phaseacc;
double phaseacc;
fftfilt *bpfilt;
Cmovavg *ffilt;
@ -52,13 +55,14 @@ private:
double prevsymbol;
cmplx prevsmpl;
double fout;
double amp;
long int wf_freq;
double dspcnt;
long int passno;
double fout;
double amp;
long int wf_freq;
double dspcnt;
long int passno;
struct timespec start_time;
struct tm File_Start_Date;
double elapsed;
@ -68,8 +72,10 @@ private:
double nco(double freq);
void writeFile();
void creatfilename();
std::string analysisFilename;
char FileDate [10];
char FileData [12];
public:
anal();
@ -83,6 +89,8 @@ public:
int rx_process(const double *buf, int len);
int tx_process();
std::string analysisFilename;
std::string OpenAnalalysisFile;
};

View file

@ -6,6 +6,12 @@
//
// This file is part of fldigi.
//
// Modified by J C Gibbons / N8OBJ - May 2019
// Added info.txt file option for control of header - Feb 2020
// Added analysis file output modifications
// - Removed relative time from output file, added full ISO date/time stamp
// - Added keeping present days data is the file already exist when program started
//
// Fldigi is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
@ -39,6 +45,10 @@
#include "timeops.h"
#include "debug.h"
// added for file support tasks 2-18-20 JC Gibbons N8OBJ
#include <iostream>
#include <fstream>
using namespace std;
static char msg1[80];
@ -67,6 +77,73 @@ anal::~anal()
delete afilt;
}
// used for checking file exists function
#define F_OK 0
void anal::creatfilename()
{
// Function to find or create the working directory [if not exist yet]
// also creates the filename that should be open for today's date [w and w/o full path]
// Create embedded date YYMMDD for file creation naming
time_t now = time(NULL);
gmtime_r(&now, &File_Start_Date);
// create the embedded filename date image as YYMMDD
strftime((char*)FileDate,sizeof(FileDate),"%y%m%d", &File_Start_Date);
// create the embedded file date image as YYYY-MM-DD
strftime((char*)FileData,sizeof(FileData),"%Y-%m-%d", &File_Start_Date);
// create the home directory path
string HomePath;
HomePath = getenv("HOME");
// create the home directory path to the FLDanalysis filestructure
string FLDdataPath;
FLDdataPath = getenv("HOME");
// append new working path for data storage
FLDdataPath += "/FLDanalysis/";
// check for directory and if not there create it
if (fl_access(FLDdataPath.c_str(),F_OK) == -1)
//directory does not exist, so create it
{
// printf("\n\nDirectory %s does NOT exist - creating it\n", FLDdataPath.c_str() ); // diag line
fl_make_path(FLDdataPath.c_str());
fl_chmod(FLDdataPath.c_str(),0775);
}
// else
// printf("\n\nDirectory %s does exist and will use it\n", FLDdataPath.c_str() ); // diag line
// create the new analysis file name only
OpenAnalalysisFile="analysis";
// embedded date YYMMDD
OpenAnalalysisFile.append(FileDate);
// csv file type extension
OpenAnalalysisFile.append(".csv");
// Full name with path
// Added new file naming and storage by N8OBJ 5-7-19
analysisFilename = HomePath;
analysisFilename += "/FLDanalysis/";
// create new analysis file name w/o path [for display in status line]
analysisFilename.append("analysis");
// embedded date YYMMDD
analysisFilename.append(FileDate);
// csv file type extension
analysisFilename.append(".csv");
// now have full path and filename for today's data file
// in variable analysisFilename
}
void anal::restart()
{
double fhi = ANAL_BW * 1.1 / samplerate;
@ -110,8 +187,7 @@ anal::anal()
ffilt = new Cmovavg(FILT_LEN * samplerate);
afilt = new Cmovavg(FILT_LEN * samplerate);
analysisFilename = TempDir;
analysisFilename.append("analysis.csv");
creatfilename();
cap &= ~CAP_TX;
write_to_csv = false;
@ -136,22 +212,75 @@ cmplx anal::mixer(cmplx in)
void anal::start_csv()
{
FILE *out = fl_fopen(analysisFilename.c_str(), "w");
if (unlikely(!out)) {
LOG_PERROR("fl_fopen");
return;
// create path to info.txt file
string InfoPath;
InfoPath = getenv("HOME");
InfoPath += "/FLDanalysis/info.txt";
creatfilename();
//Open the data file for creation (write) operation
//first check to see if already created (and don't destroy the same days data already gathered)
if (fl_access(analysisFilename.c_str(),F_OK) == 0) {
// file exists! - use it and keep adding to it
// indicate in status line that file write in progress
put_status("Using existing analysis file");
// printf("\n\nUsing existing %s analysis file\n\n", analysisFilename.c_str() ); //diag printout
write_to_csv = true; //say to do writes to file
}
fprintf(out, "Clock,Elapsed Time,Freq Error,RF,|amp|,20log(|amp|)\n");
fclose(out);
put_status("Writing csv file");
else
write_to_csv = true;
// file not there - create it and populate the header info in it
{
FILE *out = fl_fopen(analysisFilename.c_str(), "w"); //create [write] for new data file
if (unlikely(!out)) {
LOG_PERROR("fl_fopen");
return;
}
// file opened - write out header info
put_status("Creating analysis file");
//Check for the existance of info.txt file in the ./FLDanalysis/ directory
string InfoText;
ifstream InfoTextFile( InfoPath.c_str() );
if (InfoTextFile.is_open()) {
// files exists, obtain info in text file
getline (InfoTextFile,InfoText);
InfoTextFile.close();
// since file exists, write out full ISO date as first element of todays header
// along with the contents of info.txt for 1st line of header info
// printf("info.txt exists - writing >%s,%s< into initial header\n",FileData,InfoText.c_str());//diag line
fprintf(out, "%s,%s\n",FileData, InfoText.c_str());
}
// Always write out the normal column header to the new .csv file
fprintf(out, "UTC,Freq,Freq Err,Vpk,dBV(Vpk)\n");
fclose(out);
// printf("Creating analysis file %s \n", analysisFilename.c_str()); //diag output
write_to_csv = true; //say to do writes to file
}
}
void anal::stop_csv()
{
write_to_csv = false;
// clear status line
put_status("");
}
@ -162,22 +291,61 @@ void anal::writeFile()
time_t now = time(NULL);
struct tm tm;
// put check for date rollover here
gmtime_r(&now, &tm);
char DateNow [10];
FILE* out = fl_fopen(analysisFilename.c_str(), "a");
// Create embedded date stamp in the YYMMDD format
strftime((char*)DateNow,sizeof(DateNow),"%y%m%d", &tm);
// printf("Date now is =%s\n",DateNow); //diag printout
// check if date rolled over
if (tm.tm_mday != File_Start_Date.tm_mday)
{
start_csv();
}
FILE *out = fl_fopen(analysisFilename.c_str(), "a");
if (unlikely(!out)) {
LOG_PERROR("fl_fopen");
return;
}
fprintf(out, "%02d:%02d:%02d, %8.3f, %8.3f, %12.3f, %8.3f, %8.2f\n",
tm.tm_hour, tm.tm_min, tm.tm_sec, elapsed,
fout,
(wf->rfcarrier() + (wf->USB() ? 1.0 : -1.0) * (frequency + fout)),
amp,
20.0 * log10( (amp == 0 ? 1e-6 : amp) ) );
// N8OBJ 5-7-19 changed 8.3f to 8.6f (more decimal places on signal strength - show uV level)
// Changed /added new .csv fields
// header is: fprintf(out, "UTC,Freq,Freq Err,Vpk,dBV(Vpk)\n");
// print realltime results to terminal window as well N8OBJ - 7-9-19
// print just the time for UTC --> HH:MM:SS
// diag print
// printf("%02d:%02d:%02d, %13.3f, %6.3f, %8.6f, %6.2f\n",
// tm.tm_hour, tm.tm_min, tm.tm_sec,
// (wf->rfcarrier() + (wf->USB() ? 1.0 : -1.0) * (frequency + fout)), fout,
// amp, 20.0 * log10( (amp == 0 ? 1e-6 : amp) ) );
fprintf(out, "%02d:%02d:%02d, %13.3f, %6.3f, %8.6f, %6.2f\n",
tm.tm_hour, tm.tm_min, tm.tm_sec,
(wf->rfcarrier() + (wf->USB() ? 1.0 : -1.0) * (frequency + fout)), fout,
amp, 20.0 * log10( (amp == 0 ? 1e-6 : amp) ) );
// print date with full date and time for UTC --> YYYY-MM-DD HH:MM:SS
// diag print
// printf("%s %02d:%02d:%02d, %13.3f, %6.3f, %8.6f, %6.2f\n",
// FileData, tm.tm_hour, tm.tm_min, tm.tm_sec,
// (wf->rfcarrier() + (wf->USB() ? 1.0 : -1.0) * (frequency + fout)), fout,
// amp, 20.0 * log10( (amp == 0 ? 1e-6 : amp) ) );
// fprintf(out, "%s %02d:%02d:%02d, %13.3f, %6.3f, %8.6f, %6.2f\n",
// FileData, tm.tm_hour, tm.tm_min, tm.tm_sec,
// (wf->rfcarrier() + (wf->USB() ? 1.0 : -1.0) * (frequency + fout)), fout,
// amp, 20.0 * log10( (amp == 0 ? 1e-6 : amp) ) );
fclose(out);
put_status("Writing csv file");
// indicate in status line the actual file name being written is in progress
char StatusMsg [80];
sprintf( StatusMsg, "Writing analysis file %s", OpenAnalalysisFile.c_str());
put_status(StatusMsg);
}