diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ConfigParser.cpp | 18 | ||||
| -rw-r--r-- | src/dabInputPrbs.cpp | 34 | ||||
| -rw-r--r-- | src/utils.cpp | 26 | ||||
| -rw-r--r-- | src/utils.h | 8 | 
4 files changed, 51 insertions, 35 deletions
| diff --git a/src/ConfigParser.cpp b/src/ConfigParser.cpp index 8e5fed1..e68f98f 100644 --- a/src/ConfigParser.cpp +++ b/src/ConfigParser.cpp @@ -112,24 +112,6 @@ static void setup_subchannel_from_ptree(DabSubchannel* subchan,          std::shared_ptr<dabEnsemble> ensemble,          const string& subchanuid); -/* a helper class to parse hexadecimal ids */ -static int hexparse(std::string input) -{ -    int value; -    if (input.find("0x") == 0) { -        value = strtoll(input.c_str() + 2, nullptr, 16); -    } -    else { -        value = strtoll(input.c_str(), nullptr, 10); -    } - -    if (errno == ERANGE) { -        throw runtime_error("hex conversion: value out of range"); -    } - -    return value; -} -  static uint16_t get_announcement_flag_from_ptree(          boost::property_tree::ptree& pt          ) diff --git a/src/dabInputPrbs.cpp b/src/dabInputPrbs.cpp index f34c427..f9a62b5 100644 --- a/src/dabInputPrbs.cpp +++ b/src/dabInputPrbs.cpp @@ -34,30 +34,36 @@  #include <limits.h>  #include <stdlib.h>  #include <errno.h> +#include "utils.h"  using namespace std; +// ETS 300 799 Clause G.2.1 +// Preferred polynomial is G(x) = x^20 + x^17 + 1 +const uint32_t PRBS_DEFAULT_POLY = (1 << 19) | (1 << 16) | 1; +  int DabInputPrbs::open(const string name)  { -    if (name[0] != ':') { -        throw invalid_argument( -                "Invalid PRBS address format. Must be prbs://:polynomial."); +    if (name.empty()) { +        m_prbs.setup(PRBS_DEFAULT_POLY);      } +    else { +        if (name[0] != ':') { +            throw invalid_argument( +                    "Invalid PRBS address format. " +                    "Must be prbs://:polynomial."); +        } -    const string poly_str = name.substr(1); +        const string poly_str = name.substr(1); -    long polynomial = strtol(poly_str.c_str(), (char **)NULL, 10); -    if ((polynomial == LONG_MIN) || (polynomial == LONG_MAX)) { -        stringstream ss; -        ss <<  "Can't convert polynomial number " << poly_str; -        throw invalid_argument(ss.str()); -    } +        long polynomial = hexparse(poly_str); -    if (polynomial == 0) { -        throw invalid_argument("No polynomial given for PRBS input"); -    } +        if (polynomial == 0) { +            throw invalid_argument("No polynomial given for PRBS input"); +        } -    m_prbs.setup(polynomial); +        m_prbs.setup(polynomial); +    }      rewind();      return 0; diff --git a/src/utils.cpp b/src/utils.cpp index 9976e88..f0df772 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -426,3 +426,29 @@ void printEnsemble(const shared_ptr<dabEnsemble> ensemble)      }  } +long hexparse(const std::string& input) +{ +    long value = 0; +    errno = 0; + +    // Do not use strtol's base=0 because +    // we do not want to accept octal. +    if (input.find("0x") == 0) { +        value = strtol(input.c_str() + 2, nullptr, 16); +    } +    else { +        value = strtol(input.c_str(), nullptr, 10); +    } + +    if ((value == LONG_MIN or value == LONG_MAX) and errno == ERANGE) { +        throw out_of_range("hexparse: value out of range"); +    } +    else if (value == 0 and errno != 0) { +        stringstream ss; +        ss << "hexparse: " << strerror(errno); +        throw invalid_argument(ss.str()); +    } + +    return value; +} + diff --git a/src/utils.h b/src/utils.h index f65bba8..94712cd 100644 --- a/src/utils.h +++ b/src/utils.h @@ -26,9 +26,10 @@     You should have received a copy of the GNU General Public License     along with ODR-DabMux.  If not, see <http://www.gnu.org/licenses/>.  */ -#ifndef _UTILS_H -#define _UTILS_H +#pragma once +#include <string> +#include <vector>  #include <cstdio>  #include <memory>  #include "MuxElements.h" @@ -78,5 +79,6 @@ void printEnsemble(const std::shared_ptr<dabEnsemble> ensemble);  /* Print detailed component information */  void printComponent(DabComponent* component); -#endif + +long hexparse(const std::string& input); | 
