From 8ea5c5bf03335f0c95a292f400699ba98e6cf821 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 7 Aug 2015 13:53:43 +0200 Subject: Add FIG0/8 and 0/9 --- src/DabMultiplexer.cpp | 2 +- src/fig/FIG.h | 1 + src/fig/FIG0.cpp | 125 ++++++++++++++++++++++++++++++++++++++++++++++++ src/fig/FIG0.h | 39 +++++++++++++++ src/fig/FIGCarousel.cpp | 3 +- src/fig/FIGCarousel.h | 2 +- 6 files changed, 169 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/DabMultiplexer.cpp b/src/DabMultiplexer.cpp index 3dbe325..ff431b0 100644 --- a/src/DabMultiplexer.cpp +++ b/src/DabMultiplexer.cpp @@ -633,7 +633,7 @@ void DabMultiplexer::mux_frame(std::vector >& outpu // FIB 0 Insertion bool new_fig_carousel = m_pt.get("general.new_fig_carousel", false); if (new_fig_carousel) { - fig_carousel.set_currentFrame(currentFrame); + fig_carousel.update(currentFrame, date); figSize += fig_carousel.carousel(0, &etiFrame[index], 30, currentFrame % 4); index += figSize; } 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 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::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 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 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); -- cgit v1.2.3