finish CLI tool tdm_ripper
This commit is contained in:
parent
09937203c8
commit
a584cc40de
11
makefile
11
makefile
@ -4,7 +4,7 @@
|
|||||||
EXE = tdmripper
|
EXE = tdmripper
|
||||||
|
|
||||||
# compiler and C++ standard
|
# compiler and C++ standard
|
||||||
CC = g++ -std=c++11
|
CC = g++ -std=c++17
|
||||||
|
|
||||||
# compiler options and optimization flags
|
# compiler options and optimization flags
|
||||||
OPT = -O3 -Wall -Werror -Wunused-variable -Wsign-compare
|
OPT = -O3 -Wall -Werror -Wunused-variable -Wsign-compare
|
||||||
@ -13,9 +13,8 @@ OPT = -O3 -Wall -Werror -Wunused-variable -Wsign-compare
|
|||||||
LIB = pugixml/
|
LIB = pugixml/
|
||||||
|
|
||||||
# determine git version/commit tag
|
# determine git version/commit tag
|
||||||
TAGV := $(shell git describe --tag | head -n1)
|
GTAG := $(shell git tag | head -n1)
|
||||||
COMM := $(shell git rev-parse HEAD | head -c8)
|
GHSH := $(shell git rev-parse HEAD | head -c8)
|
||||||
GITV := $(TAGV)-g$(COMM)
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------------- #
|
# --------------------------------------------------------------------------- #
|
||||||
# CLI tool
|
# CLI tool
|
||||||
@ -26,8 +25,8 @@ $(EXE) : main.o tdm_ripper.o
|
|||||||
# build main.cpp object file and include git version/commit tag
|
# build main.cpp object file and include git version/commit tag
|
||||||
main.o : src/main.cpp
|
main.o : src/main.cpp
|
||||||
@cp $< $<.cpp
|
@cp $< $<.cpp
|
||||||
@sed -i 's/tagfullstring/$(GITV)/g' $<.cpp
|
@sed -i 's/TAGSTRING/$(GTAG)/g' $<.cpp
|
||||||
@sed -i 's/versionstring/$(TAGV)/g' $<.cpp
|
@sed -i 's/HASHSTRING/$(GHSH)/g' $<.cpp
|
||||||
$(CC) -c $(OPT) -I $(LIB) -I lib/ $<.cpp -o $@
|
$(CC) -c $(OPT) -I $(LIB) -I lib/ $<.cpp -o $@
|
||||||
@rm $<.cpp
|
@rm $<.cpp
|
||||||
|
|
||||||
|
290
src/main.cpp
290
src/main.cpp
@ -2,15 +2,18 @@
|
|||||||
|
|
||||||
#include "tdm_ripper.hpp"
|
#include "tdm_ripper.hpp"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
// ------------------------------------------------------------------------- //
|
// ------------------------------------------------------------------------- //
|
||||||
|
|
||||||
const std::string tagfull("tagfullstring");
|
const std::string gittag("TAGSTRING");
|
||||||
const std::string version("versionstring");
|
const std::string githash("HASHSTRING");
|
||||||
|
|
||||||
void show_usage()
|
void show_usage()
|
||||||
{
|
{
|
||||||
std::cout<<"\n"
|
std::cout<<"\n"
|
||||||
<<"tdmripper ["<<tagfull<<"] (Copyright © 2021 Record Evolution GmbH)"
|
<<"tdmripper ["<<gittag<<"-g"<<githash<<"] (Copyright © 2021 Record Evolution GmbH)"
|
||||||
<<"\n\n"
|
<<"\n\n"
|
||||||
<<"Decode TDM/TDX files and dump data as *.csv"
|
<<"Decode TDM/TDX files and dump data as *.csv"
|
||||||
<<"\n\n"
|
<<"\n\n"
|
||||||
@ -19,10 +22,13 @@ void show_usage()
|
|||||||
<<"\n\n"
|
<<"\n\n"
|
||||||
<<"Options:"
|
<<"Options:"
|
||||||
<<"\n\n"
|
<<"\n\n"
|
||||||
<<" -d, --outputdir output directory (must already exist!) for .csv files (default: current working directory)\n"
|
<<" -d, --output (existing!) output directory (default: current working directory)\n"
|
||||||
<<" -s, --csvsep separator character used in .csv files (default is comma ',')\n"
|
<<" -s, --csvsep separator character used in .csv files (default is comma ',')\n"
|
||||||
<<" -h, --help show this help message \n"
|
<<" -p, --prefix name prefix for .csv files (default is none)\n"
|
||||||
<<" -v, --version display version\n"
|
<<" -g, --listgroups list groups in data\n"
|
||||||
|
<<" -c, --listchannels list channels in data\n"
|
||||||
|
<<" -h, --help show this help message \n"
|
||||||
|
<<" -v, --version display version\n"
|
||||||
<<"\n";
|
<<"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,6 +37,9 @@ void show_usage()
|
|||||||
// define type of key-value map object
|
// define type of key-value map object
|
||||||
typedef std::map<std::string,std::string> optkeys;
|
typedef std::map<std::string,std::string> optkeys;
|
||||||
|
|
||||||
|
const std::string argmsg = std::string("both .tdm and .tdx file (and maybe any valid option) must be provided!");
|
||||||
|
const std::string arguse = std::string("see $ tdmripper --help for usage");
|
||||||
|
|
||||||
optkeys parse_args(int argc, char* argv[], bool showargs = false)
|
optkeys parse_args(int argc, char* argv[], bool showargs = false)
|
||||||
{
|
{
|
||||||
if ( showargs )
|
if ( showargs )
|
||||||
@ -42,107 +51,94 @@ optkeys parse_args(int argc, char* argv[], bool showargs = false)
|
|||||||
// declare empty key-value object
|
// declare empty key-value object
|
||||||
optkeys prsdkeys;
|
optkeys prsdkeys;
|
||||||
|
|
||||||
// at least both tdm and tdx file must be provided
|
if ( argc == 2 )
|
||||||
if ( argc > 1 )
|
|
||||||
{
|
{
|
||||||
if ( std::string(argv[1]) == std::string("--help") )
|
if ( std::string(argv[1]) == std::string("--help")
|
||||||
|
|| std::string(argv[1]) == std::string("-h") )
|
||||||
{
|
{
|
||||||
show_usage();
|
show_usage();
|
||||||
}
|
}
|
||||||
else if ( std::string(argv[1]) == std::string("--version") )
|
else if ( std::string(argv[1]) == std::string("--version")
|
||||||
|
|| std::string(argv[1]) == std::string("-v") )
|
||||||
{
|
{
|
||||||
std::cout<<"tdmripper "<<version<<"\n";
|
std::cout<<"tdmripper "<<gittag<<"\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for ( int i = 1; i < argc; i++ )
|
throw std::runtime_error(argmsg + std::string("\n") + arguse);
|
||||||
{
|
}
|
||||||
|
}
|
||||||
|
else if ( argc > 2 ) // && argc%2 == 1 )
|
||||||
|
{
|
||||||
|
// tdm file
|
||||||
|
if ( std::string(argv[argc-2]).find(std::string(".tdm")) != std::string::npos )
|
||||||
|
{
|
||||||
|
prsdkeys.insert(std::pair<std::string,std::string>("tdm",argv[argc-2]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::string tdmerr = std::string(argv[argc-2])
|
||||||
|
+ std::string(" does not look like a .tdm file")
|
||||||
|
+ std::string(", evtl. add file extension *.tdm")
|
||||||
|
+ std::string("\n") + arguse;
|
||||||
|
throw std::runtime_error(tdmerr);
|
||||||
|
}
|
||||||
|
// tdx file
|
||||||
|
if ( std::string(argv[argc-1]).find(std::string(".tdx")) != std::string::npos )
|
||||||
|
{
|
||||||
|
prsdkeys.insert(std::pair<std::string,std::string>("tdx",argv[argc-1]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::string tdxerr = std::string(argv[argc-1])
|
||||||
|
+ std::string(" does not look like a .tdx file")
|
||||||
|
+ std::string(", evtl. add file extension *.tdx")
|
||||||
|
+ std::string("\n") + arguse;
|
||||||
|
throw std::runtime_error(tdxerr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// options (in any order)
|
||||||
|
// for ( int i = 1; i < argc-2; i+=2 )
|
||||||
|
for ( int i = 1; i < argc-2; i++ )
|
||||||
|
{
|
||||||
|
if ( std::string(argv[i]) == std::string("--output")
|
||||||
|
|| std::string(argv[i]) == std::string("-d") )
|
||||||
|
{
|
||||||
|
prsdkeys.insert(std::pair<std::string,std::string>("output",argv[i+1]));
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
else if ( std::string(argv[i]) == std::string("--csvsep")
|
||||||
|
|| std::string(argv[i]) == std::string("-s") )
|
||||||
|
{
|
||||||
|
prsdkeys.insert(std::pair<std::string,std::string>("csvsep",argv[i+1]));
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
else if ( std::string(argv[i]) == std::string("--prefix")
|
||||||
|
|| std::string(argv[i]) == std::string("-p") )
|
||||||
|
{
|
||||||
|
prsdkeys.insert(std::pair<std::string,std::string>("prefix",argv[i+1]));
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
else if ( std::string(argv[i]) == std::string("--listgroups")
|
||||||
|
|| std::string(argv[i]) == std::string("-g") )
|
||||||
|
{
|
||||||
|
prsdkeys.insert(std::pair<std::string,std::string>("listgroups",argv[i+1]));
|
||||||
|
}
|
||||||
|
else if ( std::string(argv[i]) == std::string("--listchannels")
|
||||||
|
|| std::string(argv[i]) == std::string("-c") )
|
||||||
|
{
|
||||||
|
prsdkeys.insert(std::pair<std::string,std::string>("listchannels",argv[i+1]));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::string argerr = std::string("unkown option '") + argv[i] + std::string("'");
|
||||||
|
throw std::runtime_error(argerr + std::string("\n") + arguse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// {
|
|
||||||
// if ( std::string(argv[i]) == std::string("--image") )
|
|
||||||
// {
|
|
||||||
// if ( i+1 == argc || std::string(argv[i+1]).substr(0,2) == std::string("--") )
|
|
||||||
// {
|
|
||||||
// throw std::runtime_error("invalid or missing --image argument");
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// prsdkeys.insert(std::pair<std::string,std::string>("image",argv[i+1]));
|
|
||||||
// }
|
|
||||||
// i++;
|
|
||||||
// }
|
|
||||||
// else if ( std::string(argv[i]) == std::string("--drive") )
|
|
||||||
// {
|
|
||||||
// if ( i+1 == argc || std::string(argv[i+1]).substr(0,2) == std::string("--") )
|
|
||||||
// {
|
|
||||||
// throw std::runtime_error("invalid or missing --drive argument");
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// prsdkeys.insert(std::pair<std::string,std::string>("drive",argv[i+1]));
|
|
||||||
// }
|
|
||||||
// i++;
|
|
||||||
// }
|
|
||||||
// else if ( std::string(argv[i]) == std::string("--config") )
|
|
||||||
// {
|
|
||||||
// if ( i+1 == argc || std::string(argv[i+1]).substr(0,2) == std::string("--") )
|
|
||||||
// {
|
|
||||||
// throw std::runtime_error("invalid or missing --config argument");
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// prsdkeys.insert(std::pair<std::string,std::string>("config",argv[i+1]));
|
|
||||||
// }
|
|
||||||
// i++;
|
|
||||||
// }
|
|
||||||
// else if ( std::string(argv[i]) == std::string("--writeblocksize") )
|
|
||||||
// {
|
|
||||||
// if ( i+1 == argc || std::string(argv[i+1]).substr(0,2) == std::string("--") )
|
|
||||||
// {
|
|
||||||
// throw std::runtime_error("invalid or missing --writeblocksize argument");
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// prsdkeys.insert(std::pair<std::string,std::string>("writeblock",argv[i+1]));
|
|
||||||
// }
|
|
||||||
// i++;
|
|
||||||
// }
|
|
||||||
// else if ( std::string(argv[i]) == std::string("--readblocksize") )
|
|
||||||
// {
|
|
||||||
// if ( i+1 == argc || std::string(argv[i+1]).substr(0,2) == std::string("--") )
|
|
||||||
// {
|
|
||||||
// throw std::runtime_error("invalid or missing --readblocksize argument");
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// prsdkeys.insert(std::pair<std::string,std::string>("readblock",argv[i+1]));
|
|
||||||
// }
|
|
||||||
// i++;
|
|
||||||
// }
|
|
||||||
// else if ( std::string(argv[i]) == std::string("--novalidate") )
|
|
||||||
// {
|
|
||||||
// prsdkeys.insert(std::pair<std::string,std::string>("novalidate","no"));
|
|
||||||
// }
|
|
||||||
// else if ( std::string(argv[i]) == std::string("--listdrives") )
|
|
||||||
// {
|
|
||||||
// prsdkeys.insert(std::pair<std::string,std::string>("listdrives","yes"));
|
|
||||||
// }
|
|
||||||
// else if ( std::string(argv[i]) == std::string("--help") )
|
|
||||||
// {
|
|
||||||
// show_usage();
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// throw std::runtime_error(std::string("invalid argument ") + std::string(argv[i]));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// show_usage();
|
throw std::runtime_error(argmsg + std::string("\n") + arguse);
|
||||||
throw std::runtime_error(".tdm/.tdx files are missing! see $ ./tdmripper --help for usage");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return prsdkeys;
|
return prsdkeys;
|
||||||
@ -155,67 +151,53 @@ int main(int argc, char* argv[])
|
|||||||
// parse CLI arguments
|
// parse CLI arguments
|
||||||
optkeys cfgopts = parse_args(argc,argv);
|
optkeys cfgopts = parse_args(argc,argv);
|
||||||
|
|
||||||
// // path of filename provided ?
|
if ( cfgopts.count("tdm") == 1 && cfgopts.count("tdx") == 1 )
|
||||||
// assert( argc > 1 && "please provide a filename and path" );
|
{
|
||||||
//
|
// set required option values
|
||||||
// std::cout<<"number of CLI-arguments: "<<argc<<"\n";
|
std::string output = cfgopts.count("output") == 1 ? cfgopts.at("output")
|
||||||
// for ( int i = 0; i < argc; i++ ) std::cout<<std::setw(5)<<i<<": "<<argv[i]<<"\n";
|
: std::string("./");
|
||||||
|
std::string csvsep = cfgopts.count("csvsep") == 1 ? cfgopts.at("csvsep")
|
||||||
|
: std::string(",");
|
||||||
|
std::string prefix = cfgopts.count("prefix") == 1 ? cfgopts.at("prefix")
|
||||||
|
: std::string("");
|
||||||
|
bool listgroups = cfgopts.count("listgroups") == 1 ? true : false;
|
||||||
|
bool listchannels = cfgopts.count("listchannels") == 1 ? true : false;
|
||||||
|
|
||||||
// // declare and initialize tdm_ripper
|
// declare and initialize tdm_ripper instance
|
||||||
// assert( argc == 3 );
|
tdm_ripper jack(cfgopts.at("tdm"),cfgopts.at("tdx"));
|
||||||
// tdm_ripper ripper(argv[1],argv[2],false); //,"samples/SineData.tdx",false);
|
|
||||||
//
|
// print list of groups or channels to stdout
|
||||||
// // ripper.list_datatypes();
|
if ( listgroups ) jack.list_groups();
|
||||||
// // ripper.show_structure();
|
if ( listchannels ) jack.list_channels();
|
||||||
//
|
|
||||||
// ripper.print_hash_local("data/hash_table_xml_local.dat");
|
// write all groups/channels to filesystem
|
||||||
// ripper.print_hash_values("data/hash_table_xml_value.dat");
|
if ( !listgroups && !listchannels )
|
||||||
// ripper.print_hash_double("data/hash_table_xml_double.dat");
|
{
|
||||||
// ripper.print_extid("data/channel_ext_id.dat");
|
std::filesystem::path pd = output;
|
||||||
//
|
if ( std::filesystem::is_directory(pd) )
|
||||||
// ripper.list_groups();
|
{
|
||||||
// std::ofstream gout("data/list_of_groups.dat");
|
for ( int i = 0; i < jack.num_channels(); i++ )
|
||||||
// ripper.list_groups(gout);
|
{
|
||||||
// gout.close();
|
// sanitize channel name
|
||||||
//
|
std::regex reg("([^A-Za-z0-9])");
|
||||||
// ripper.list_channels();
|
std::string chname = std::regex_replace(jack.channel_name(i),reg,"");
|
||||||
// std::ofstream fout("data/list_of_channels.dat");
|
|
||||||
// ripper.list_channels(fout);
|
// concat path and construct file name
|
||||||
// fout.close();
|
std::filesystem::path outfile = pd / ( std::string("channel_")
|
||||||
//
|
+ std::to_string(i+1) + std::string("_")
|
||||||
// // long int nsa = 6.3636349745e10; // expected result: 22.07.2016, 19:49:05
|
+ chname + std::string(".csv") );
|
||||||
// // long int nsb = 6.3636350456e10;
|
|
||||||
// // std::string ts = std::to_string(nsa);
|
// write channel to filesystem
|
||||||
// // std::cout<<ripper.unix_timestamp(ts)<<"\n";
|
jack.print_channel(i,outfile.c_str());
|
||||||
//
|
}
|
||||||
// std::cout<<"number of channels "<<ripper.num_channels()<<"\n";
|
}
|
||||||
// std::cout<<"number of groups "<<ripper.num_groups()<<"\n\n";
|
else
|
||||||
//
|
{
|
||||||
// // obtain some specific meta information tags
|
throw std::runtime_error( std::string("directory '") + output
|
||||||
// std::cout<<"\n"<<ripper.get_meta("SMP_Name")<<"\n";
|
+ std::string("' does not exist"));
|
||||||
// std::cout<<ripper.get_meta("SMP_Aufbau_Nr")<<"\n";
|
}
|
||||||
// std::cout<<ripper.get_meta("SMP_Type")<<"\n";
|
}
|
||||||
// std::cout<<ripper.get_meta("Location")<<"\n\n";
|
}
|
||||||
//
|
|
||||||
// // print all meta information
|
|
||||||
// ripper.print_meta("data/meta_info.csv");
|
|
||||||
//
|
|
||||||
// // for ( int i = 0; i < ripper.num_groups(); i++ )
|
|
||||||
// // {
|
|
||||||
// // std::cout<<std::setw(10)<<i+1<<std::setw(10)<<ripper.no_channels(i+1)<<"\n";
|
|
||||||
// // for ( int j = 0; j < ripper.no_channels(i+1); j++ )
|
|
||||||
// // {
|
|
||||||
// // std::cout<<std::setw(10)<<i+1<<std::setw(10)<<j+1<<std::setw(30)<<ripper.channel_name(i+1,j+1)<<"\n";
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
//
|
|
||||||
// // for ( int i = 3; i < 10; i++ )
|
|
||||||
// for ( int i = 0; i < ripper.num_channels(); i++ )
|
|
||||||
// // for ( int i = 11880; i < ripper.num_channels(); i++ )
|
|
||||||
// {
|
|
||||||
// ripper.print_channel(i,("data/channel_"+std::to_string(i+1)+"_"
|
|
||||||
// +ripper.channel_name(i)+".dat").c_str());
|
|
||||||
// }
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user