diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-03-18 16:02:25 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-03-18 16:02:25 +0100 |
commit | 78a5d1945922e9d4b9932c9d39d61a9f192bcd56 (patch) | |
tree | ce99822cb4b1f143b32ddf3d9b6de83f6b6f4160 /rdsparse/rdsparse.cc | |
parent | 626c6d11cba32fac3bef312c8791df15f5bbf65a (diff) | |
download | mmbtools-aux-78a5d1945922e9d4b9932c9d39d61a9f192bcd56.tar.gz mmbtools-aux-78a5d1945922e9d4b9932c9d39d61a9f192bcd56.tar.bz2 mmbtools-aux-78a5d1945922e9d4b9932c9d39d61a9f192bcd56.zip |
Add rdparse tool in development
Diffstat (limited to 'rdsparse/rdsparse.cc')
-rw-r--r-- | rdsparse/rdsparse.cc | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/rdsparse/rdsparse.cc b/rdsparse/rdsparse.cc new file mode 100644 index 0000000..7d9babd --- /dev/null +++ b/rdsparse/rdsparse.cc @@ -0,0 +1,77 @@ +#include <iostream> +#include <iomanip> +#include <fstream> +#include <vector> +#include <deque> +#include "decoder_impl.h" +#include "parser_impl.h" + +#define PTY_LOCALE 0 + +using namespace std; + +rds::parser_impl parser(true, true, PTY_LOCALE); +rds::decoder_impl decoder(true, true); + +void usage() +{ + std::cerr << "Specify filename" << std::endl; +} + +int main(int argc, char **argv) +{ + if (argc == 1) { + usage(); + return 1; + } + + ifstream in_fd; + in_fd.open(argv[1]); + + string temp; + while (getline(in_fd, temp)) { + stringstream temp_ss(temp); + deque<string> elems; + + string item; + char delim = ' '; + while (getline(temp_ss, item, delim)) { + elems.push_front(item); + } + + vector<int> bytes; + for (auto s : elems) { + int byte = stoul(s, nullptr, 16); + bytes.push_back(byte); + } + + const int skip_head = 7; + const int skip_tail = 6; + + if (bytes[0] == 0xFD) { + int length = bytes[1]; + + vector<int> bits; + + if (length > 0) { +#define HEX(a) std::hex << std::setfill('0') << std::setw(2) << long(a) << std::dec + + for (int i = skip_head; i < length+(skip_head - skip_tail); i++) { + cerr << " " << HEX(bytes[i]); + + for (int ix = 0; ix < 8; ix++) { + bits.push_back(bytes[i] & (1 << ix) ? 1 : 0); + } + } + cerr << " len: " << bits.size() << endl; + + decoder.work(bits.size(), &bits[0]); + } + + } + + } + + return 0; +} + |