aboutsummaryrefslogtreecommitdiffstats
path: root/src/fig0_11.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-04-27 01:39:20 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-04-27 01:39:20 +0200
commit0616c12772c4995d0a22b803127af156a37a3a7d (patch)
tree0561c72fa58cc71209edc196e4706b850b000868 /src/fig0_11.cpp
parent36d70772c7ba15bf1d769f7ec54ba129377f4617 (diff)
downloadetisnoop-0616c12772c4995d0a22b803127af156a37a3a7d.tar.gz
etisnoop-0616c12772c4995d0a22b803127af156a37a3a7d.tar.bz2
etisnoop-0616c12772c4995d0a22b803127af156a37a3a7d.zip
Refactor FIG0/X message generation
Diffstat (limited to 'src/fig0_11.cpp')
-rw-r--r--src/fig0_11.cpp99
1 files changed, 49 insertions, 50 deletions
diff --git a/src/fig0_11.cpp b/src/fig0_11.cpp
index d26795f..f019fa3 100644
--- a/src/fig0_11.cpp
+++ b/src/fig0_11.cpp
@@ -1,6 +1,6 @@
/*
Copyright (C) 2014 CSP Innovazione nelle ICT s.c.a r.l. (http://www.csp.it/)
- Copyright (C) 2016 Matthias P. Braendli (http://www.opendigitalradio.org)
+ Copyright (C) 2017 Matthias P. Braendli (http://www.opendigitalradio.org)
Copyright (C) 2015 Data Path
This program is free software: you can redistribute it and/or modify
@@ -49,15 +49,14 @@ bool fig0_11_is_complete(int region_id)
// FIG 0/11 Region definition
// ETSI EN 300 401 8.1.16.1
-bool fig0_11(fig0_common_t& fig0, const display_settings_t &disp)
+fig_result_t fig0_11(fig0_common_t& fig0, const display_settings_t &disp)
{
Lat_Lng gps_pos = {0, 0};
int16_t Latitude_coarse, Longitude_coarse;
uint16_t Region_Id, Extent_Latitude, Extent_Longitude, key;
uint8_t i = 1, j, k, GATy, Rfu, Length_TII_list, Rfa, MainId, Length_SubId_list, SubId;
int8_t bit_pos;
- char desc[256];
- char tmpbuf[256];
+ fig_result_t r;
bool GE_flag;
uint8_t* f = fig0.f;
uint8_t Mode_Identity = get_mode_identity();
@@ -74,58 +73,54 @@ bool fig0_11(fig0_common_t& fig0, const display_settings_t &disp)
i += 2;
if (GATy == 0) {
// TII list
- sprintf(desc, "GATy=%d Geographical area defined by a TII list, G/E flag=%d %s coverage area, RegionId=0x%X, database key=0x%X",
- GATy, GE_flag, GE_flag?"Global":"Ensemble", Region_Id, key);
+ r.msgs.push_back(strprintf("GATy=%d", GATy));
+ r.msgs.emplace_back("Geographical area defined by a TII list");
+ r.msgs.push_back(strprintf("G/E flag=%d %s coverage area",
+ GE_flag, GE_flag ? "Global" : "Ensemble"));
+ r.msgs.push_back(strprintf("RegionId=0x%X", Region_Id));
+ r.msgs.push_back(strprintf("database key=0x%X", key));
+
if (i < fig0.figlen) {
Rfu = f[i] >> 5;
if (Rfu != 0) {
- sprintf(tmpbuf, ", Rfu=%d invalid value", Rfu);
- strcat(desc, tmpbuf);
+ r.errors.push_back(strprintf("Rfu=%d invalid value", Rfu));
}
Length_TII_list = f[i] & 0x1F;
- sprintf(tmpbuf, ", Length of TII list=%d", Length_TII_list);
- strcat(desc, tmpbuf);
+ r.msgs.push_back(strprintf(", Length of TII list=%d", Length_TII_list));
if (Length_TII_list == 0) {
- strcat(desc, ", CEI");
+ r.msgs.emplace_back("CEI");
}
- printbuf(desc, disp+1, NULL, 0);
i++;
- for(j = 0;(i < (fig0.figlen - 1)) && (j < Length_TII_list); j++) {
+ for (j = 0; (i < (fig0.figlen - 1)) && (j < Length_TII_list); j++) {
// iterate over Transmitter group
Rfa = f[i] >> 7;
MainId = f[i] & 0x7F;
if (Rfa != 0) {
- sprintf(desc, "Rfa=%d invalid value, MainId=0x%X",
- Rfa, MainId);
+ r.errors.push_back(strprintf("Rfa=%d invalid value, MainId=0x%X", Rfa, MainId));
}
else {
- sprintf(desc, "MainId=0x%X", MainId);
+ r.msgs.emplace_back(1, strprintf("MainId=0x%X", MainId));
}
// check MainId value
if ((Mode_Identity == 1) || (Mode_Identity == 2) || (Mode_Identity == 4)) {
if (MainId > 69) {
// The coding range shall be 0 to 69 for transmission modes I, II and IV
- sprintf(tmpbuf, " invalid value for transmission mode %d", Mode_Identity);
- strcat(desc, tmpbuf);
+ r.errors.push_back(strprintf("invalid value for transmission mode %d", Mode_Identity));
}
}
else if (Mode_Identity == 3) {
if (MainId > 5) {
// The coding range shall be 0 to 5 for transmission modes I, II and IV
- sprintf(tmpbuf, " invalid value for transmission mode %d", Mode_Identity);
- strcat(desc, tmpbuf);
+ r.errors.push_back(strprintf("invalid value for transmission mode %d", Mode_Identity));
}
}
Rfa = f[i+1] >> 5;
if (Rfa != 0) {
- sprintf(tmpbuf, ", Rfa=%d invalid value", Rfa);
- strcat(desc, tmpbuf);
+ r.errors.push_back(strprintf("Rfa=%d invalid value", Rfa));
}
Length_SubId_list = f[i+1] & 0x1F;
- sprintf(tmpbuf, ", Length of SubId=%d", Length_SubId_list);
- strcat(desc, tmpbuf);
- printbuf(desc, disp+2, NULL, 0);
+ r.msgs.emplace_back(1, strprintf("Length of SubId=%d", Length_SubId_list));
i += 2;
bit_pos = 3;
@@ -134,12 +129,11 @@ bool fig0_11(fig0_common_t& fig0, const display_settings_t &disp)
// iterate SubId
if (bit_pos >= 0) {
SubId |= (f[i] >> bit_pos) & 0x1F;
- sprintf(desc, "SubId=0x%X", SubId);
+ r.msgs.emplace_back(2, strprintf("SubId=0x%X", SubId));
// check SubId value
if ((SubId == 0) || (SubId > 23)) {
- strcat(desc, " invalid value");
+ r.errors.push_back(strprintf("Invalid SubId=0x%X", SubId));
}
- printbuf(desc, disp+3, NULL, 0);
bit_pos -= 5;
SubId = 0;
}
@@ -154,56 +148,61 @@ bool fig0_11(fig0_common_t& fig0, const display_settings_t &disp)
i++;
}
if (k < Length_SubId_list) {
- sprintf(desc, "%d SubId missing, fig length too short !", (Length_SubId_list - k));
- printbuf(desc, disp+3, NULL, 0);
- fprintf(stderr, "WARNING: FIG 0/%d length %d too short !\n", fig0.ext(), fig0.figlen);
+ r.errors.push_back(strprintf("%d SubId missing, fig length too short !", Length_SubId_list - k));
}
}
if (j < Length_TII_list) {
- sprintf(desc, "%d Transmitter group missing, fig length too short !", (Length_TII_list - j));
- printbuf(desc, disp+2, NULL, 0);
- fprintf(stderr, "WARNING: FIG 0/%d length %d too short !\n", fig0.ext(), fig0.figlen);
+ r.errors.push_back(strprintf("%d Transmitter group missing, fig length too short !", Length_TII_list - j));
}
}
}
else if (GATy == 1) {
// Coordinates
- sprintf(desc, "GATy=%d Geographical area defined as a spherical rectangle by the geographical co-ordinates of one corner and its latitude and longitude extents, G/E flag=%d %s coverage area, RegionId=0x%X, database key=0x%X",
- GATy, GE_flag, GE_flag?"Global":"Ensemble", Region_Id, key);
+ r.msgs.push_back(strprintf("GATy=%d", GATy));
+ r.msgs.emplace_back("Geographical area defined as a spherical rectangle "
+ "by the geographical co-ordinates of one corner and its latitude and "
+ "longitude extents");
+ r.msgs.push_back(strprintf("G/E flag=%d %s coverage area",
+ GE_flag, GE_flag ? "Global" : "Ensemble"));
+ r.msgs.push_back(strprintf("RegionId=0x%X", Region_Id));
+ r.msgs.push_back(strprintf("database key=0x%X", key));
+
if (i < (fig0.figlen - 6)) {
Latitude_coarse = ((int16_t)f[i] << 8) | ((uint16_t)f[i+1]);
Longitude_coarse = ((int16_t)f[i+2] << 8) | ((uint16_t)f[i+3]);
gps_pos.latitude = ((double)Latitude_coarse) * 90 / 32768;
gps_pos.longitude = ((double)Latitude_coarse) * 180 / 32768;
- sprintf(tmpbuf, ", Lat Lng coarse=0x%X 0x%X => %f, %f",
- Latitude_coarse, Longitude_coarse, gps_pos.latitude, gps_pos.longitude);
- strcat(desc, tmpbuf);
+ r.msgs.push_back(strprintf("Lat Lng coarse=0x%X 0x%X => %f, %f",
+ Latitude_coarse, Longitude_coarse, gps_pos.latitude, gps_pos.longitude));
Extent_Latitude = ((uint16_t)f[i+4] << 4) | ((uint16_t)(f[i+5] >> 4));
Extent_Longitude = ((uint16_t)(f[i+5] & 0x0F) << 8) | ((uint16_t)f[i+6]);
gps_pos.latitude += ((double)Extent_Latitude) * 90 / 32768;
gps_pos.longitude += ((double)Extent_Longitude) * 180 / 32768;
- sprintf(tmpbuf, ", Extent Lat Lng=0x%X 0x%X => %f, %f",
- Extent_Latitude, Extent_Longitude, gps_pos.latitude, gps_pos.longitude);
- strcat(desc, tmpbuf);
+ r.msgs.push_back(strprintf("Extent Lat Lng=0x%X 0x%X => %f, %f",
+ Extent_Latitude, Extent_Longitude, gps_pos.latitude, gps_pos.longitude));
}
else {
- sprintf(tmpbuf, ", Coordinates missing, fig length too short !");
- strcat(desc, tmpbuf);
- fprintf(stderr, "WARNING: FIG 0/%d length %d too short !\n", fig0.ext(), fig0.figlen);
+ r.errors.push_back("Coordinates missing, fig length too short !");
}
- printbuf(desc, disp+1, NULL, 0);
i += 7;
}
else {
// Rfu
- sprintf(desc, "GATy=%d reserved for future use of the geographical, G/E flag=%d %s coverage area, RegionId=0x%X, database key=0x%X, stop Region definition iteration %d/%d",
- GATy, GE_flag, GE_flag?"Global":"Ensemble", Region_Id, key, i, fig0.figlen);
- printbuf(desc, disp+1, NULL, 0);
+ r.msgs.push_back(strprintf("GATy=%d", GATy));
+ r.msgs.emplace_back("reserved for future use of the geographical");
+ r.msgs.push_back(strprintf("G/E flag=%d %s coverage area",
+ GE_flag, GE_flag ? "Global" : "Ensemble"));
+ r.msgs.push_back(strprintf("RegionId=0x%X", Region_Id));
+ r.msgs.push_back(strprintf("database key=0x%X", key));
+ r.msgs.push_back(strprintf("stop Region definition iteration %d/%d",
+ i, fig0.figlen));
// stop Region definition iteration
i = fig0.figlen;
+ r.errors.push_back("Stopping iteration because Rfu encountered");
}
}
- return complete;
+ r.complete = complete;
+ return r;
}