diff --git a/carousel.cpp b/carousel.cpp index 3fa6c4c..7417a73 100644 --- a/carousel.cpp +++ b/carousel.cpp @@ -43,7 +43,7 @@ TTXPageStream* Carousel::nextCarousel() { std::cerr << "[Carousel::nextCarousel] Deleted " << p->GetSourcePage() << std::endl; p->SetCarouselFlag(false); - if (!(p->GetNormalFlag() || p->GetSpecialFlag())) + if (!(p->GetNormalFlag() || p->GetSpecialFlag() || _page->GetUpdatedFlag())) p->SetState(TTXPageStream::GONE); // if we are last mark it gone _carouselList.erase(it--); } diff --git a/filemonitor.cpp b/filemonitor.cpp index 90ab5c2..9a32a92 100644 --- a/filemonitor.cpp +++ b/filemonitor.cpp @@ -168,6 +168,13 @@ int FileMonitor::readDirectory(std::string path){ std::cerr << "[FileMonitor::run] page is now a carousel " << std::hex << q->GetPageNumber() << std::endl; } + if (q->GetNormalFlag() && !(q->GetSpecialFlag()) && !(q->GetCarouselFlag()) && !(q->GetUpdatedFlag())) + { + // add normal, non carousel pages to updatedPages list + _pageList->GetMagazines()[mag]->GetUpdatedPages()->addPage(q); + q->SetUpdatedFlag(true); + } + if (_pageList->CheckForPacket29(q)) { std::cerr << "[FileMonitor::run] found packet 29" << std::endl; @@ -195,9 +202,10 @@ int FileMonitor::readDirectory(std::string path){ if (q->Special()) { // Page is 'special' + q->SetCarouselFlag(false); q->SetSpecialFlag(true); q->SetNormalFlag(false); - q->SetCarouselFlag(false); + q->SetUpdatedFlag(false); _pageList->GetMagazines()[mag]->GetSpecialPages()->addPage(q); //std::cerr << "[FileMonitor::run] new page is special " << std::hex << q->GetPageNumber() << std::endl; } @@ -218,7 +226,12 @@ int FileMonitor::readDirectory(std::string path){ //std::cerr << "[FileMonitor::run] new page is a carousel " << std::hex << q->GetPageNumber() << std::endl; } else + { q->SetCarouselFlag(false); + // add normal, non carousel pages to updatedPages list + _pageList->GetMagazines()[mag]->GetUpdatedPages()->addPage(q); + q->SetUpdatedFlag(true); + } } if (_pageList->CheckForPacket29(q)) diff --git a/normalpages.cpp b/normalpages.cpp index 3065bac..8780f7b 100644 --- a/normalpages.cpp +++ b/normalpages.cpp @@ -55,7 +55,7 @@ TTXPageStream* NormalPages::NextPage() std::cerr << "[NormalPages::NextPage] Deleted " << _page->GetSourcePage() << std::endl; _iter = _NormalPagesList.erase(_iter); _page->SetNormalFlag(false); - if (!(_page->GetSpecialFlag() || _page->GetCarouselFlag())) + if (!(_page->GetSpecialFlag() || _page->GetCarouselFlag() || _page->GetUpdatedFlag())) _page->SetState(TTXPageStream::GONE); // if we are last mark it gone _page = *_iter; goto loop; // jump back to try for the next page diff --git a/packetmag.cpp b/packetmag.cpp index 06f9c6e..0ce2a57 100644 --- a/packetmag.cpp +++ b/packetmag.cpp @@ -26,17 +26,19 @@ PacketMag::PacketMag(uint8_t mag, std::list* pageSet, ttx::Config _packet29[i]=nullptr; } - _normalPages=new vbit::NormalPages(); _carousel=new vbit::Carousel(); _specialPages=new vbit::SpecialPages(); + _normalPages=new vbit::NormalPages(); + _updatedPages=new vbit::UpdatedPages(); } PacketMag::~PacketMag() { //dtor - delete _normalPages; delete _carousel; delete _specialPages; + delete _normalPages; + delete _updatedPages; } Packet* PacketMag::GetPacket(Packet* p) @@ -45,6 +47,7 @@ Packet* PacketMag::GetPacket(Packet* p) int thisPageNum; unsigned int thisSubcode; int* links=NULL; + bool updatedFlag=false; static vbit::Packet* filler=new Packet(8,25," "); // filler @@ -130,14 +133,25 @@ Packet* PacketMag::GetPacket(Packet* p) } else { - _page=_carousel->nextCarousel(); // The next carousel page (if there is one) - if (_page) // Carousel? + _page=_updatedPages->NextPage(); // Get the next updated page (if there is one) + if (_page) { - //_outp("c"); + // updated page + updatedFlag=true; // use our own flag because the pagestream's _isUpdated flag gets cleared by NextPage } - else // No carousel? Take the next normal page + else { - _page=_normalPages->NextPage(); + // no updated pages + _page=_carousel->nextCarousel(); // Get the next carousel page (if there is one) + if (_page) + { + // carousel with hard timings + } + else + { + // no urgent carousels + _page=_normalPages->NextPage(); // Get the next normal page (if there is one) + } } if (_page == nullptr){ @@ -182,6 +196,11 @@ Packet* PacketMag::GetPacket(Packet* p) // Also set the erase flag in output. This will allow left over rows in adaptive transmission to be cleared without leaving the erase flag set causing flickering. _status|=PAGESTATUS_C4_ERASEPAGE; } + + if (updatedFlag){ + // page is updated set interrupted sequence flag and clear UpdatedFlag + _status|=PAGESTATUS_C9_INTERRUPTED; + } } // Assemble the header. (we can simplify this code or leave it for the optimiser) @@ -384,8 +403,8 @@ bool PacketMag::IsReady(bool force) if (_waitingForField == 0) { - _priorityCount--; - if (_priorityCount==0 || force) + _priorityCount--; + if (_priorityCount==0 || force || (_updatedPages->waiting())) // force if there are updated pages waiting { _priorityCount=_priority; result=true; diff --git a/packetmag.h b/packetmag.h index bb7eded..ba97610 100644 --- a/packetmag.h +++ b/packetmag.h @@ -6,6 +6,7 @@ #include "carousel.h" #include "specialpages.h" #include "normalpages.h" +#include "updatedpages.h" #include "configure.h" #define MAXPACKET29TYPES 3 @@ -28,9 +29,10 @@ class PacketMag : public PacketSource */ std::list* Get_pageSet() { return _pageSet; } + Carousel* GetCarousel() { return _carousel; } SpecialPages* GetSpecialPages() { return _specialPages; } NormalPages* GetNormalPages() { return _normalPages; } - Carousel* GetCarousel() { return _carousel; } + UpdatedPages* GetUpdatedPages() { return _updatedPages; } /** Get the next packet * @return The next packet OR if IsReady() would return false then a filler packet @@ -56,6 +58,7 @@ class PacketMag : public PacketSource Carousel* _carousel; SpecialPages* _specialPages; NormalPages* _normalPages; + UpdatedPages* _updatedPages; uint8_t _priorityCount; /// Controls transmission priority PacketState _state; /// State machine to sequence packet types uint8_t _thisRow; // The current line that we are outputting diff --git a/specialpages.cpp b/specialpages.cpp index 2525c5e..d9b94b0 100644 --- a/specialpages.cpp +++ b/specialpages.cpp @@ -64,7 +64,7 @@ TTXPageStream* SpecialPages::NextPage() _page->SetState(TTXPageStream::GONE); _iter = _specialPagesList.erase(_iter); _page->SetSpecialFlag(false); - if (!(_page->GetNormalFlag() || _page->GetCarouselFlag())) + if (!(_page->GetNormalFlag() || _page->GetCarouselFlag() || _page->GetUpdatedFlag())) _page->SetState(TTXPageStream::GONE); // if we are last mark it gone _page = *_iter; goto loop; diff --git a/ttxpagestream.cpp b/ttxpagestream.cpp index f1ae917..5761478 100644 --- a/ttxpagestream.cpp +++ b/ttxpagestream.cpp @@ -7,6 +7,7 @@ TTXPageStream::TTXPageStream() : _isCarousel(false), _isSpecial(false), _isNormal(false), + _isUpdated(false), _updateCount(0) { //ctor @@ -20,6 +21,7 @@ TTXPageStream::TTXPageStream(std::string filename) : _isCarousel(false), _isSpecial(false), _isNormal(false), + _isUpdated(false), _updateCount(0) { struct stat attrib; // create a file attribute structure diff --git a/ttxpagestream.h b/ttxpagestream.h index ffe1d54..28b9e93 100644 --- a/ttxpagestream.h +++ b/ttxpagestream.h @@ -36,14 +36,7 @@ class TTXPageStream : public TTXPage */ TTXPageStream(std::string filename); - /** Access _isCarousel - * \return The current value of _isCarousel - */ bool GetCarouselFlag() { return _isCarousel; } - - /** Set _isCarousel - * \param val New value to set - */ void SetCarouselFlag(bool val) { _isCarousel = val; } bool GetSpecialFlag() { return _isSpecial; } @@ -52,6 +45,9 @@ class TTXPageStream : public TTXPage bool GetNormalFlag() { return _isNormal; } void SetNormalFlag(bool val) { _isNormal = val; } + bool GetUpdatedFlag() { return _isUpdated; } + void SetUpdatedFlag(bool val) { _isUpdated = val; } + int GetUpdateCount() {return _updateCount;} void IncrementUpdateCount(); @@ -143,6 +139,7 @@ class TTXPageStream : public TTXPage bool _isCarousel; bool _isSpecial; bool _isNormal; + bool _isUpdated; int _updateCount; // update counter for special pages. diff --git a/updatedpages.cpp b/updatedpages.cpp new file mode 100644 index 0000000..44cd607 --- /dev/null +++ b/updatedpages.cpp @@ -0,0 +1,61 @@ + +#include "updatedpages.h" + +using namespace vbit; + +UpdatedPages::UpdatedPages() +{ + _iter=_UpdatedPagesList.begin(); + _page=nullptr; +} + +UpdatedPages::~UpdatedPages() +{ + +} + +void UpdatedPages::addPage(TTXPageStream* p) +{ + _UpdatedPagesList.push_front(p); +} + +TTXPageStream* UpdatedPages::NextPage() +{ + if (_page == nullptr) + { + _iter=_UpdatedPagesList.begin(); + _page = *_iter; + } + else + { + ++_iter; + _page = *_iter; + } + +loop: + if (_iter == _UpdatedPagesList.end()) + { + _page = nullptr; + } + + if (_page) + { + /* remove pointers from this list if the pages are marked for deletion */ + if (_page->GetStatusFlag()==TTXPageStream::MARKED && _page->GetUpdatedFlag()) // only remove it once + { + std::cerr << "[UpdatedPages::NextPage] Deleted " << _page->GetSourcePage() << std::endl; + _iter = _UpdatedPagesList.erase(_iter); + _page->SetUpdatedFlag(false); + if (!(_page->GetSpecialFlag() || _page->GetCarouselFlag() || _page->GetNormalFlag())) + _page->SetState(TTXPageStream::GONE); // if we are last mark it gone. + _page = *_iter; + goto loop; // jump back to try for the next page + } + + //std::cerr << "[UpdatedPages::NextPage] got updated page " << std::hex << _page->GetPageNumber() << std::endl; + _iter = _UpdatedPagesList.erase(_iter); // remove page from this list after transmitting it + _page->SetUpdatedFlag(false); + } + + return _page; +} diff --git a/updatedpages.h b/updatedpages.h new file mode 100644 index 0000000..fd1e152 --- /dev/null +++ b/updatedpages.h @@ -0,0 +1,38 @@ +#ifndef _UPDATEDPAGES_H +#define _UPDATEDPAGES_H + +#include + +#include "ttxpagestream.h" + +// list of updated pages + +namespace vbit +{ + +class UpdatedPages +{ + public: + /** Default constructor */ + UpdatedPages(); + /** Default destructor */ + virtual ~UpdatedPages(); + + TTXPageStream* NextPage(); + + void addPage(TTXPageStream* p); + + bool waiting(){ return _UpdatedPagesList.size() > 0; }; + + protected: + + private: + std::list _UpdatedPagesList; + std::list::iterator _iter; + TTXPageStream* _page; + +}; + +} + +#endif // _UPDATEDPAGES_H