summaryrefslogtreecommitdiffstats
path: root/src/dabInputPrbs.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-10-30 11:31:56 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-10-30 11:31:56 +0100
commitf21352094c0949b643721ee5387fefae0cdab507 (patch)
treebae2813b66308d1478f1537fbd5acb9ec1af34b5 /src/dabInputPrbs.cpp
parentb073c0eb1e5bf676a24f225779cc31d3c9f21fd4 (diff)
downloaddabmux-f21352094c0949b643721ee5387fefae0cdab507.tar.gz
dabmux-f21352094c0949b643721ee5387fefae0cdab507.tar.bz2
dabmux-f21352094c0949b643721ee5387fefae0cdab507.zip
Move hexparse to utils and add default PRBS poly
Diffstat (limited to 'src/dabInputPrbs.cpp')
-rw-r--r--src/dabInputPrbs.cpp34
1 files changed, 20 insertions, 14 deletions
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;