From dcf8a55ea3d46776f0ba32f28e7e936b92bf6e86 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli (think)" Date: Tue, 28 Aug 2012 16:03:53 +0200 Subject: crc-dabmux: configuration file: added shortlabel support --- src/ParserConfigfile.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 80 insertions(+), 4 deletions(-) (limited to 'src/ParserConfigfile.cpp') diff --git a/src/ParserConfigfile.cpp b/src/ParserConfigfile.cpp index 24b9f22..13fe80d 100644 --- a/src/ParserConfigfile.cpp +++ b/src/ParserConfigfile.cpp @@ -99,6 +99,44 @@ typedef DWORD32 uint32_t; using namespace std; +void set_short_label(dabLabel& label, std::string& slabel, const char* applies_to) +{ + char* end; + const char* lab; + label.flag = strtoul(slabel.c_str(), &end, 0); + if (*end != 0) { + lab = slabel.c_str(); + label.flag = 0; + for (int i = 0; i < 32; ++i) { + if (*lab == label.text[i]) { + label.flag |= 0x8000 >> i; + if (*(++lab) == 0) { + break; + } + } + } + if (*lab != 0) { + stringstream ss; + ss << "Error : " << applies_to << " short label '" << slabel << + "'!\n" << "Not in label '" << label.text << "' !\n"; + throw runtime_error(ss.str()); + } + } + int count = 0; + for (int i = 0; i < 16; ++i) { + if (label.flag & (1 << i)) { + ++count; + } + } + if (count > 8) { + stringstream ss; + ss << applies_to << " '" << slabel << "' short label too long!\n" + "Must be < 8 characters.\n"; + throw runtime_error(ss.str()); + } + +} + void parse_configfile(string configuration_file, vector &outputs, dabEnsemble* ensemble, @@ -158,6 +196,13 @@ void parse_configfile(string configuration_file, label.copy(ensemble->label.text, 16); ensemble->label.flag = 0xff00; + try { + string label = pt_ensemble.get("shortlabel"); + set_short_label(ensemble->label, label, "Ensemble"); + } + catch (ptree_error &e) { } + + /******************** READ SERVICES PARAMETERS *************/ map allservices; @@ -185,6 +230,16 @@ void parse_configfile(string configuration_file, } service->label.flag = 0xe01f; + try { + string label = pt_service.get("shortlabel"); + set_short_label(service->label, label, "Service"); + } + catch (ptree_error &e) { + etiLog.printHeader(TcpLog::WARNING, + "Service with uid %s has no short label.\n", serviceuid.c_str()); + } + + service->id = pt_service.get("id", DEFAULT_SERVICE_ID + ensemble->services.size()); service->pty = pt_service.get("pty", 0); service->language = pt_service.get("language", 0); @@ -219,7 +274,7 @@ void parse_configfile(string configuration_file, } catch (runtime_error &e) { etiLog.printHeader(TcpLog::ERR, - "%s", e.what()); + "%s\n", e.what()); throw e; } @@ -286,6 +341,27 @@ void parse_configfile(string configuration_file, component->subchId = subchannel->id; component->SCIdS = SCIdS_per_service[service]++; + try { + string label = pt_comp.get("label"); + + memset(component->label.text, 0, 16); + label.copy(component->label.text, 16); + component->label.flag = 0xff00; + } + catch (ptree_error &e) { + etiLog.printHeader(TcpLog::WARNING, + "Service with uid %s has no label.\n", componentuid.c_str()); + } + + try { + string label = pt_comp.get("shortlabel"); + set_short_label(component->label, label, "Component"); + } + catch (ptree_error &e) { + etiLog.printHeader(TcpLog::WARNING, + "Component with uid %s has no short label.\n", componentuid.c_str()); + } + ensemble->components.push_back(component); } @@ -628,13 +704,13 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, /* Get protection */ try { - int level = pt.get("protection"); + int level = pt.get("protection") - 1; if (protection->form == 0) { if ((level < 0) || (level > 4)) { stringstream ss; ss << "Subchannel with uid " << subchanuid << - "protection level must be between " + ": protection level must be between " "1 to 5 inclusively (current = " << level << " )"; throw runtime_error(ss.str()); } @@ -643,7 +719,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, if ((level < 0) || (level > 3)) { stringstream ss; ss << "Subchannel with uid " << subchanuid << - "protection level must be between " + ": protection level must be between " "1 to 4 inclusively (current = " << level << " )"; throw runtime_error(ss.str()); } -- cgit v1.2.3