diff --git a/decoder/src/lib/imbe_decoder.cc b/decoder/src/lib/imbe_decoder.cc index f645393..3e20e17 100644 --- a/decoder/src/lib/imbe_decoder.cc +++ b/decoder/src/lib/imbe_decoder.cc @@ -1,7 +1,6 @@ #include #include -// #include -#include +// #include // #include imbe_decoder_sptr diff --git a/decoder/src/lib/offline_imbe_decoder.cc b/decoder/src/lib/offline_imbe_decoder.cc new file mode 100644 index 0000000..cc25a7d --- /dev/null +++ b/decoder/src/lib/offline_imbe_decoder.cc @@ -0,0 +1,64 @@ +/* -*- C++ -*- */ + +/* + * Copyright 2008 Steve Glass + * + * This file is part of OP25. + * + * OP25 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, or (at your option) + * any later version. + * + * OP25 is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + * License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OP25; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Boston, MA + * 02110-1301, USA. + */ + +#include +#include +#include +#include + +using namespace std; + +offline_imbe_decoder::offline_imbe_decoder() +{ + const char *dev = getenv("IMBE_FILE"); + if(!dev) { + const char *default_filename = "imbe.dat"; + dev = default_filename; + } + d_fp = fopen(dev, "w"); + if(NULL == d_fp) { + perror("fopen(dev, \"w\");"); // a warning, not an error + } +} + +offline_imbe_decoder::~offline_imbe_decoder() +{ + if(d_fp) { + fclose(d_fp); + } +} + +size_t +offline_imbe_decoder::decode(voice_codeword& in_out, audio_output& out) +{ + if(d_fp) { + uint8_t codewords[18]; + extract(in_out, 0, 144, codewords); + if(0 == fwrite(codewords, sizeof(codewords), 1, d_fp)) { + perror("fwrite(d_fp, 1, codewords, sizeof(codewords))"); + fclose(d_fp); + d_fp = NULL; + } + } + return 0; +} diff --git a/decoder/src/lib/offline_imbe_decoder.h b/decoder/src/lib/offline_imbe_decoder.h new file mode 100644 index 0000000..f8ddf49 --- /dev/null +++ b/decoder/src/lib/offline_imbe_decoder.h @@ -0,0 +1,66 @@ +/* -*- C++ -*- */ + +/* + * Copyright 2008 Steve Glass + * + * This file is part of OP25. + * + * OP25 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, or (at your option) + * any later version. + * + * OP25 is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + * License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OP25; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Boston, MA + * 02110-1301, USA. + */ + +#ifndef INCLUDED_OFFLINE_IMBE_DECODER_H +#define INCLUDED_OFFLINE_IMBE_DECODER_H + +#include + +#include + +/** + * offline_imbe_decoder dumps voice codewords to file for offline decoding. + * + */ +class offline_imbe_decoder : public imbe_decoder { +public: + + /** + * offline_imbe_decoder default constructor. + */ + offline_imbe_decoder(); + + /** + * offline_imbe_decoder (virtual) destructor. + */ + virtual ~offline_imbe_decoder(); + + /** + * Dump voice_codeword in_out to file. + * + * \param in_out IMBE codewords and parity. + * \param in Queue of audio samples to which output is written. + * \return The number of samples written to out. + */ + virtual size_t decode(voice_codeword& in_out, audio_output& out); + +private: + + /** + * The output file. + */ + FILE *d_fp; + +}; + +#endif /* INCLUDED_OFFLINE_IMBE_DECODER_H */ diff --git a/decoder/src/lib/value_string.cc b/decoder/src/lib/value_string.cc new file mode 100644 index 0000000..fed7927 --- /dev/null +++ b/decoder/src/lib/value_string.cc @@ -0,0 +1,115 @@ +/* -*- C++ -*- */ + +/* + * Copyright 2008 Steve Glass + * + * This file is part of OP25. + * + * OP25 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, or (at your option) + * any later version. + * + * OP25 is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + * License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OP25; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Boston, MA + * 02110-1301, USA. + */ + +#include +#include +#include + +using namespace std; + +struct value_string { + uint16_t value; + const char *label; +}; + +string +lookup(uint16_t value, const value_string mappings[], size_t mappings_sz) +{ + for(size_t i = 0; i < mappings_sz; ++i) { + if(mappings[i].value == value) { + return mappings[i].label; + } + } + ostringstream os; + os << "Unknown (" << hex << value << ")"; + return os.str(); +} + +const value_string ALGIDS[] = { + /* Type I */ + { 0x00, "ACCORDION 1.3" }, + { 0x01, "BATON (Auto Even)" }, + { 0x02, "FIREFLY Type 1" }, + { 0x03, "MAYFLY Type 1" }, + { 0x04, "SAVILLE" }, + { 0x41, "BATON (Auto Odd)" }, + /* Type III */ + { 0x80, "Unencrypted message" }, + { 0x81, "DES-OFB" }, + { 0x82, "2 key Triple DES" }, + { 0x83, "3 key Triple DES" }, + { 0x84, "AES-256" }, + /* Motorola proprietary */ + { 0x9F, "DES-XL" }, + { 0xA0, "DVI-XL" }, + { 0xA1, "DVP-XL" }, +}; +const size_t ALGIDS_SZ = sizeof(ALGIDS) / sizeof(ALGIDS[0]); + + +const value_string MFIDS[] = { + { 0x00, "Standard MFID (pre-2001)" }, + { 0x01, "Standard MFID (post-2001)" }, + { 0x09, "Aselsan Inc." }, + { 0x10, "Relm / BK Radio" }, + { 0x18, "EADS Public Safety Inc." }, + { 0x20, "Cycomm" }, + { 0x28, "Efratom Time and Frequency Products, Inc" }, + { 0x30, "Com-Net Ericsson" }, + { 0x34, "Etherstack" }, + { 0x38, "Datron" }, + { 0x40, "Icom" }, + { 0x48, "Garmin" }, + { 0x50, "GTE" }, + { 0x55, "IFR Systems" }, + { 0x5A, "INIT Innovations in Transportation, Inc" }, + { 0x60, "GEC-Marconi" }, + { 0x64, "Harris Corp." }, + { 0x68, "Kenwood Communications" }, + { 0x70, "Glenayre Electronics" }, + { 0x74, "Japan Radio Co." }, + { 0x78, "Kokusai" }, + { 0x7C, "Maxon" }, + { 0x80, "Midland" }, + { 0x86, "Daniels Electronics Ltd." }, + { 0x90, "Motorola" }, + { 0xA0, "Thales" }, + { 0xA4, "M/A-COM" }, + { 0xB0, "Raytheon" }, + { 0xC0, "SEA" }, + { 0xC8, "Securicor" }, + { 0xD0, "ADI" }, + { 0xD8, "Tait Electronics" }, + { 0xE0, "Teletec" }, + { 0xF0, "Transcrypt International" }, + { 0xF8, "Vertex Standard" }, + { 0xFC, "Zetron, Inc" }, +}; +const size_t MFIDS_SZ = sizeof(MFIDS) / sizeof(MFIDS[0]); + +const value_string NACS[] = { + { 0x293, "Default NAC" }, + { 0xF7E, "Receiver to open on any NAC" }, + { 0xF7F, "Repeater to receive and retransmit any NAC" }, +}; +const size_t NACS_SZ = sizeof(NACS) / sizeof(NACS[0]); diff --git a/decoder/src/lib/value_string.h b/decoder/src/lib/value_string.h new file mode 100644 index 0000000..e3b5021 --- /dev/null +++ b/decoder/src/lib/value_string.h @@ -0,0 +1,48 @@ +/* -*- C++ -*- */ + +/* + * Copyright 2008 Steve Glass + * + * This file is part of OP25. + * + * OP25 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, or (at your option) + * any later version. + * + * OP25 is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + * License for more details. + * + * You should have received a copy of the GNU General Public License + * along with OP25; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 51 Franklin Street, Boston, MA + * 02110-1301, USA. +*/ + +#ifndef INCLUDED_VALUE_STRING +#define INCLUDED_VALUE_STRING + +#include + +/* + * Look up a value in a value_string array. + * + */ +extern std::string lookup(uint16_t value, const class value_string mappings[], size_t mappings_sz); + +/* + * Look up tables. + */ + +extern const value_string ALGIDS[]; +extern const size_t ALGIDS_SZ; + +extern const value_string MFIDS[]; +extern const size_t MFIDS_SZ; + +extern const value_string NACS[]; +extern const size_t NACS_SZ; + +#endif // INCLUDED_VALUE_STRING