summaryrefslogtreecommitdiffstats
path: root/src/fig
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2015-08-07 13:53:43 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2015-08-07 13:53:43 +0200
commit8ea5c5bf03335f0c95a292f400699ba98e6cf821 (patch)
tree7137862158cce516bdf95e6359bc1ae65145d189 /src/fig
parente601ed83c8acbb0160b0d75ce0dd09852fb10fdf (diff)
downloaddabmux-8ea5c5bf03335f0c95a292f400699ba98e6cf821.tar.gz
dabmux-8ea5c5bf03335f0c95a292f400699ba98e6cf821.tar.bz2
dabmux-8ea5c5bf03335f0c95a292f400699ba98e6cf821.zip
Add FIG0/8 and 0/9
Diffstat (limited to 'src/fig')
-rw-r--r--src/fig/FIG.h1
-rw-r--r--src/fig/FIG0.cpp125
-rw-r--r--src/fig/FIG0.h39
-rw-r--r--src/fig/FIGCarousel.cpp3
-rw-r--r--src/fig/FIGCarousel.h2
5 files changed, 168 insertions, 2 deletions
diff --git a/src/fig/FIG.h b/src/fig/FIG.h
index d2498d0..c1a5ae3 100644
--- a/src/fig/FIG.h
+++ b/src/fig/FIG.h
@@ -41,6 +41,7 @@ class FIGRuntimeInformation {
ensemble(e),
factumAnalyzer(false) {}
+ time_t date;
unsigned long currentFrame;
boost::shared_ptr<dabEnsemble> ensemble;
bool factumAnalyzer;
diff --git a/src/fig/FIG0.cpp b/src/fig/FIG0.cpp
index a080da6..b09771b 100644
--- a/src/fig/FIG0.cpp
+++ b/src/fig/FIG0.cpp
@@ -563,6 +563,130 @@ FillStatus FIG0_8::fill(uint8_t *buf, size_t max_size)
return fs;
}
+//=========== FIG 0/9 ===========
+FIG0_9::FIG0_9(FIGRuntimeInformation *rti) :
+ m_rti(rti) {}
+
+FillStatus FIG0_9::fill(uint8_t *buf, size_t max_size)
+{
+ FillStatus fs;
+ auto ensemble = m_rti->ensemble;
+ size_t remaining = max_size;
+
+ if (remaining < 5) {
+ fs.num_bytes_written = 0;
+ return fs;
+ }
+
+ auto fig0_9 = (FIGtype0_9*)buf;
+ fig0_9->FIGtypeNumber = 0;
+ fig0_9->Length = 4;
+ fig0_9->CN = 0;
+ fig0_9->OE = 0;
+ fig0_9->PD = 0;
+ fig0_9->Extension = 9;
+
+ fig0_9->ext = 0;
+ fig0_9->lto = 0; // Unique LTO for ensemble
+
+ if (ensemble->lto_auto) {
+ time_t now = time(NULL);
+ struct tm* ltime = localtime(&now);
+ time_t now2 = timegm(ltime);
+ ensemble->lto = (now2 - now) / 1800;
+ }
+
+ if (ensemble->lto >= 0) {
+ fig0_9->ensembleLto = ensemble->lto;
+ }
+ else {
+ /* Convert to 1-complement representation */
+ fig0_9->ensembleLto = (-ensemble->lto) | (1<<5);
+ }
+
+ fig0_9->ensembleEcc = ensemble->ecc;
+ fig0_9->tableId = ensemble->international_table;
+ buf += 5;
+ remaining -= 5;
+
+ fs.num_bytes_written = max_size - remaining;
+ return fs;
+}
+
+//=========== FIG 0/10 ===========
+
+FIG0_10::FIG0_10(FIGRuntimeInformation *rti) :
+ m_rti(rti)
+{
+ uint8_t buffer[sizeof(m_watermarkData) / 2];
+ snprintf((char*)buffer, sizeof(buffer),
+ "%s %s, compiled at %s, %s",
+ PACKAGE_NAME, PACKAGE_VERSION, __DATE__, __TIME__);
+
+ memset(m_watermarkData, 0, sizeof(m_watermarkData));
+ m_watermarkData[0] = 0x55; // Sync
+ m_watermarkData[1] = 0x55;
+ m_watermarkSize = 16;
+ for (unsigned i = 0; i < strlen((char*)buffer); ++i) {
+ for (int j = 0; j < 8; ++j) {
+ uint8_t bit = (buffer[m_watermarkPos >> 3] >> (7 - (m_watermarkPos & 0x07))) & 1;
+ m_watermarkData[m_watermarkSize >> 3] |= bit << (7 - (m_watermarkSize & 0x07));
+ ++m_watermarkSize;
+ bit = 1;
+ m_watermarkData[m_watermarkSize >> 3] |= bit << (7 - (m_watermarkSize & 0x07));
+ ++m_watermarkSize;
+ ++m_watermarkPos;
+ }
+ }
+ m_watermarkPos = 0;
+}
+
+FillStatus FIG0_10::fill(uint8_t *buf, size_t max_size)
+{
+ FillStatus fs;
+ auto ensemble = m_rti->ensemble;
+ size_t remaining = max_size;
+
+ if (remaining < 6) {
+ fs.num_bytes_written = 0;
+ return fs;
+ }
+
+ //Time and country identifier
+ auto fig0_10 = (FIGtype0_10 *)buf;
+
+ fig0_10->FIGtypeNumber = 0;
+ fig0_10->Length = 5;
+ fig0_10->CN = 0;
+ fig0_10->OE = 0;
+ fig0_10->PD = 0;
+ fig0_10->Extension = 10;
+ buf += 2;
+
+ tm* timeData;
+ timeData = gmtime(&m_rti->date);
+
+ fig0_10->RFU = 0;
+ fig0_10->setMJD(gregorian2mjd(timeData->tm_year + 1900,
+ timeData->tm_mon + 1,
+ timeData->tm_mday));
+ fig0_10->LSI = 0;
+ fig0_10->ConfInd = (m_watermarkData[m_watermarkPos >> 3] >>
+ (7 - (m_watermarkPos & 0x07))) & 1;
+ if (++m_watermarkPos == m_watermarkSize) {
+ m_watermarkPos = 0;
+ }
+ fig0_10->UTC = 0;
+ fig0_10->setHours(timeData->tm_hour);
+ fig0_10->Minutes = timeData->tm_min;
+ buf += 4;
+ remaining -= 6;
+
+ fs.num_bytes_written = max_size - remaining;
+ fs.complete_fig_transmitted = true;
+ return fs;
+}
+
//=========== FIG 0/13 ===========
FIG0_13::FIG0_13(FIGRuntimeInformation *rti) :
@@ -693,6 +817,7 @@ FillStatus FIG0_13::fill(uint8_t *buf, size_t max_size)
}
}
+ fs.num_bytes_written = max_size - remaining;
return fs;
}
diff --git a/src/fig/FIG0.h b/src/fig/FIG0.h
index 06beb7e..14b658f 100644
--- a/src/fig/FIG0.h
+++ b/src/fig/FIG0.h
@@ -122,6 +122,45 @@ class FIG0_8 : public IFIG
std::vector<DabComponent*>::iterator componentFIG0_8;
};
+// FIG type 0/9
+// The Country, LTO and International table feature defines the local time
+// offset, the International Table and the Extended Country Code (ECC)
+class FIG0_9 : public IFIG
+{
+ public:
+ FIG0_9(FIGRuntimeInformation* rti);
+ virtual FillStatus fill(uint8_t *buf, size_t max_size);
+ virtual FIG_rate repetition_rate(void) { return FIG_rate::B; }
+
+ virtual const int figtype(void) const { return 0; }
+ virtual const int figextension(void) const { return 9; }
+
+ private:
+ FIGRuntimeInformation *m_rti;
+};
+
+
+// FIG type 0/10
+// The date and time feature is used to signal a location-independent timing
+// reference in UTC format.
+class FIG0_10 : public IFIG
+{
+ public:
+ FIG0_10(FIGRuntimeInformation* rti);
+ virtual FillStatus fill(uint8_t *buf, size_t max_size);
+ virtual FIG_rate repetition_rate(void) { return FIG_rate::B; }
+
+ virtual const int figtype(void) const { return 0; }
+ virtual const int figextension(void) const { return 10; }
+
+ private:
+ FIGRuntimeInformation *m_rti;
+
+ uint8_t m_watermarkData[128];
+ size_t m_watermarkSize;
+ size_t m_watermarkPos;
+};
+
// FIG type 0/13
// User Application Information
class FIG0_13 : public IFIG
diff --git a/src/fig/FIGCarousel.cpp b/src/fig/FIGCarousel.cpp
index ce5e7bb..99fb73a 100644
--- a/src/fig/FIGCarousel.cpp
+++ b/src/fig/FIGCarousel.cpp
@@ -80,9 +80,10 @@ FIGCarousel::FIGCarousel(boost::shared_ptr<dabEnsemble> ensemble) :
allocate_fig_to_fib(0, 17, fib0);
}
-void FIGCarousel::set_currentFrame(unsigned long currentFrame)
+void FIGCarousel::update(unsigned long currentFrame, time_t dabTime)
{
m_rti.currentFrame = currentFrame;
+ m_rti.date = dabTime;
}
void FIGCarousel::allocate_fig_to_fib(int figtype, int extension, int fib)
diff --git a/src/fig/FIGCarousel.h b/src/fig/FIGCarousel.h
index e8f3b81..5f90c98 100644
--- a/src/fig/FIGCarousel.h
+++ b/src/fig/FIGCarousel.h
@@ -51,7 +51,7 @@ class FIGCarousel {
public:
FIGCarousel(boost::shared_ptr<dabEnsemble> ensemble);
- void set_currentFrame(unsigned long currentFrame);
+ void update(unsigned long currentFrame, time_t dabTime);
void allocate_fig_to_fib(int figtype, int extension, int fib);