From a12c44df560f5db343e4d37a5d0f318375acc917 Mon Sep 17 00:00:00 2001 From: ZXGuesser Date: Sun, 15 Sep 2019 22:46:04 +0100 Subject: [PATCH] use _isSpecial and _isCarousel flags only for managing removal of pointers from special and carousel lists. Make carousel time a minimum duration and reset timeout on next magazine cycle *unless* interrupted sequence flag is set, in which case output the subpage on strict timings --- carousel.cpp | 29 ++++++----- filemonitor.cpp | 126 +++++++++++++---------------------------------- normalpages.cpp | 4 +- packetmag.cpp | 13 +++-- pagelist.cpp | 20 +++++--- specialpages.cpp | 8 +++ 6 files changed, 83 insertions(+), 117 deletions(-) diff --git a/carousel.cpp b/carousel.cpp index 043a2ed..60bb84e 100644 --- a/carousel.cpp +++ b/carousel.cpp @@ -46,21 +46,26 @@ TTXPageStream* Carousel::nextCarousel() _carouselList.remove(p); return nullptr; } - - if (p->Expired()) + else if ((!(p->IsCarousel())) || (p->Special())) { - // We found a carousel that is ready to step - p->StepNextSubpage(); - p->SetTransitionTime(p->GetCarouselPage()->GetCycleTime()); - break; + std::cerr << "[Carousel::nextCarousel] no longer a carousel " << std::hex << p->GetPageNumber() << std::endl; + _carouselList.remove(p); + p->SetCarouselFlag(false); + return nullptr; + } + else + { + if (p->Expired()) + { + // We found a carousel that is ready to step + if (p->GetCarouselPage()->GetPageStatus() & PAGESTATUS_C9_INTERRUPTED) + { + // carousel should go out now out of sequence + return p; + } + } } p=nullptr; } -#if 0 - char c; - std::cin >> c; - if (c=='x') - exit(3); -#endif return p; } diff --git a/filemonitor.cpp b/filemonitor.cpp index cd4dca4..d8007b0 100644 --- a/filemonitor.cpp +++ b/filemonitor.cpp @@ -118,96 +118,30 @@ void FileMonitor::run() q->GetPageCount(); // renumber the subpages int mag=(q->GetPageNumber() >> 16) & 0x7; - if (q->GetSpecialFlag()) + if ((!(q->GetSpecialFlag())) && (q->Special())) { - // Page was 'special' - q->SetSpecialFlag(q->Special()); - q->SetCarouselFlag(q->IsCarousel()); - if (!(q->Special())) - { - // Page is longer 'special' - // TODO: remove from SpecialPages list - _pageList->GetMagazines()[mag]->GetSpecialPages()->deletePage(q); - - if (q->IsCarousel()) - { - // Page is a 'carousel', add to Carousel list - _pageList->GetMagazines()[mag]->GetCarousel()->addPage(q); - std::cerr << "[FileMonitor::run] page was special, is now a carousel " << std::hex << q->GetPageNumber() << std::endl; - } - else - { - // Page is 'normal', add to NormalPages list - _pageList->GetMagazines()[mag]->GetNormalPages()->addPage(q); - std::cerr << "[FileMonitor::run] page was special, is now normal " << std::hex << q->GetPageNumber() << std::endl; - _pageList->GetMagazines()[mag]->GetNormalPages()->sortPages(); // TODO: add pages in correct place in list - } - } - else - { - // no change - //std::cerr << "[FileMonitor::run] page remains special " << std::hex << q->GetPageNumber() << std::endl; - } + // page was not 'special' but now is, add to SpecialPages list + q->SetSpecialFlag(true); + _pageList->GetMagazines()[mag]->GetSpecialPages()->addPage(q); + std::cerr << "[FileMonitor::run] page was normal, is now special " << std::hex << q->GetPageNumber() << std::endl; + // page will be removed from NormalPages list by the service thread + // page will be removed from Carousel list by the service thread } - else if (q->GetCarouselFlag()) + else if ((q->GetSpecialFlag()) && (!(q->Special()))) { - // Page was 'carousel' - q->SetSpecialFlag(q->Special()); - q->SetCarouselFlag(q->IsCarousel()); - if (!(q->IsCarousel()) || q->Special()) - { - // Page is no longer a 'carousel' - // TODO: remove from Carousel list - _pageList->GetMagazines()[mag]->GetCarousel()->deletePage(q); - - if (q->Special()) - { - // Page is 'special', add to SpecialPages list - _pageList->GetMagazines()[mag]->GetSpecialPages()->addPage(q); - std::cerr << "[FileMonitor::run] page was carousel, is now special " << std::hex << q->GetPageNumber() << std::endl; - } - else - { - // Page is 'normal', add to NormalPages list - _pageList->GetMagazines()[mag]->GetNormalPages()->addPage(q); - std::cerr << "[FileMonitor::run] page was carousel, is now normal " << std::hex << q->GetPageNumber() << std::endl; - _pageList->GetMagazines()[mag]->GetNormalPages()->sortPages(); // TODO: add pages in correct place in list - } - } - else - { - // no change - //std::cerr << "[FileMonitor::run] page remains a carousel " << std::hex << q->GetPageNumber() << std::endl; - } + // page was 'special' but now isn't, add to NormalPages list + _pageList->GetMagazines()[mag]->GetNormalPages()->addPage(q); + std::cerr << "[FileMonitor::run] page was special, is now normal " << std::hex << q->GetPageNumber() << std::endl; + _pageList->GetMagazines()[mag]->GetNormalPages()->sortPages(); // TODO: add pages in correct place in list } - else + + if ((!(q->Special())) && (!(q->GetCarouselFlag())) && q->IsCarousel()) { - // Page was 'normal' - q->SetSpecialFlag(q->Special()); - q->SetCarouselFlag(q->IsCarousel()); - if (q->Special() || q->IsCarousel()) - { - // Page is no longer 'normal' - // page will be removed from NormalPages list by the service thread - - if (q->Special()) - { - // Page is 'special', add to SpecialPages list - _pageList->GetMagazines()[mag]->GetSpecialPages()->addPage(q); - std::cerr << "[FileMonitor::run] page was normal, is now special " << std::hex << q->GetPageNumber() << std::endl; - } - else if (q->IsCarousel()) - { - // Page is a 'carousel', add to Carousel list - _pageList->GetMagazines()[mag]->GetCarousel()->addPage(q); - std::cerr << "[FileMonitor::run] page was normal, is now a carousel " << std::hex << q->GetPageNumber() << std::endl; - } - } - else - { - // no change - //std::cerr << "[FileMonitor::run] page remains normal " << std::hex << q->GetPageNumber() << std::endl; - } + // 'normal' page was not 'carousel' but now is, add to Carousel list + q->SetCarouselFlag(true); + q->StepNextSubpage(); // ensure we're pointing at a subpage + _pageList->GetMagazines()[mag]->GetCarousel()->addPage(q); + std::cerr << "[FileMonitor::run] page is now a carousel " << std::hex << q->GetPageNumber() << std::endl; } if (_pageList->CheckForPacket29(q)) @@ -237,23 +171,29 @@ void FileMonitor::run() if (q->Special()) { // Page is 'special' - q->SetSpecialFlag(q->Special()); + q->SetSpecialFlag(true); + q->SetCarouselFlag(false); _pageList->GetMagazines()[mag]->GetSpecialPages()->addPage(q); //std::cerr << "[FileMonitor::run] new page is special " << std::hex << q->GetPageNumber() << std::endl; } - else if (q->IsCarousel()) - { - // Page is a 'carousel' - q->SetCarouselFlag(q->IsCarousel()); - _pageList->GetMagazines()[mag]->GetCarousel()->addPage(q); - //std::cerr << "[FileMonitor::run] new page is a carousel " << std::hex << q->GetPageNumber() << std::endl; - } else { // Page is 'normal' + q->SetSpecialFlag(false); _pageList->GetMagazines()[mag]->GetNormalPages()->addPage(q); //std::cerr << "[FileMonitor::run] new page is normal " << std::hex << q->GetPageNumber() << std::endl; _pageList->GetMagazines()[mag]->GetNormalPages()->sortPages(); + + if (q->IsCarousel()) + { + // Page is also a 'carousel' + q->SetCarouselFlag(true); + q->StepNextSubpage(); // ensure we're pointing at a subpage + _pageList->GetMagazines()[mag]->GetCarousel()->addPage(q); + //std::cerr << "[FileMonitor::run] new page is a carousel " << std::hex << q->GetPageNumber() << std::endl; + } + else + q->SetCarouselFlag(false); } if (_pageList->CheckForPacket29(q)) diff --git a/normalpages.cpp b/normalpages.cpp index 7981474..5b6e1d0 100644 --- a/normalpages.cpp +++ b/normalpages.cpp @@ -50,9 +50,9 @@ TTXPageStream* NormalPages::NextPage() goto loop; // jump back to try for the next page } - if (_page->GetSpecialFlag() || _page->GetSpecialFlag()) + if (_page->Special()) { - std::cerr << "[NormalPages::NextPage] " << _page->GetSourcePage() << " became Special" << std::endl; + std::cerr << "[NormalPages::NextPage] page became Special" << std::hex << _page->GetPageNumber() << std::endl; _iter = _NormalPagesList.erase(_iter); _page = *_iter; goto loop; // jump back to try for the next page diff --git a/packetmag.cpp b/packetmag.cpp index 61d39b4..6379a51 100644 --- a/packetmag.cpp +++ b/packetmag.cpp @@ -126,6 +126,7 @@ Packet* PacketMag::GetPacket(Packet* p) /* rules for the subcode are really complicated. The S1 nibble should be the sub page number, S2 is a counter that increments when the page is updated, S3 and S4 hold the last row number */ } else { // got to the end of the special pages + ClearEvent(EVENT_SPECIAL_PAGES); return nullptr; } } @@ -151,7 +152,13 @@ Packet* PacketMag::GetPacket(Packet* p) _thisRow=0; - if (_page->GetCarouselFlag()){ + if (_page->IsCarousel()){ + if (_page->Expired()) + { + // cycle if timer has expired + _page->StepNextSubpage(); + _page->SetTransitionTime(_page->GetCarouselPage()->GetCycleTime()); + } thisSubcode=_page->GetCarouselPage()->GetSubCode(); _status=_page->GetCarouselPage()->GetPageStatus(); _region=_page->GetCarouselPage()->GetRegion(); @@ -195,7 +202,7 @@ Packet* PacketMag::GetPacket(Packet* p) //p->Parity(13); // don't apply parity here it will screw up the template. parity for the header is done by tx() later assert(p!=NULL); - if (_page->GetCarouselFlag()){ + if (_page->IsCarousel()){ links=_page->GetCarouselPage()->GetLinkSet(); } else { links=_page->GetLinkSet(); @@ -332,7 +339,7 @@ Packet* PacketMag::GetPacket(Packet* p) //std::cerr << "TRACE-F " << std::endl; // std::cerr << "PACKETSTATE_FASTEXT enters" << std::endl; p->SetMRAG(_magNumber,27); - if (_page->GetCarouselFlag()){ + if (_page->IsCarousel()){ links=_page->GetCarouselPage()->GetLinkSet(); } else { links=_page->GetLinkSet(); diff --git a/pagelist.cpp b/pagelist.cpp index aac4d34..e5f9aec 100644 --- a/pagelist.cpp +++ b/pagelist.cpp @@ -407,22 +407,28 @@ void PageList::PopulatePageTypeLists() { TTXPageStream* ptr; ptr=&(*p); - if (ptr->Special() && !(ptr->GetSpecialFlag())) + if (ptr->Special()) { // Page is 'special' ptr->SetSpecialFlag(true); + ptr->SetCarouselFlag(false); _mag[mag]->GetSpecialPages()->addPage(ptr); } - else if (ptr->IsCarousel() && !(ptr->GetCarouselFlag())) - { - // Page is a 'carousel' - ptr->SetCarouselFlag(ptr->IsCarousel()); - _mag[mag]->GetCarousel()->addPage(ptr); - } else { // Page is 'normal' + ptr->SetSpecialFlag(false); _mag[mag]->GetNormalPages()->addPage(ptr); + + if (ptr->IsCarousel()) + { + // Page is also 'carousel' + ptr->SetCarouselFlag(true); + _mag[mag]->GetCarousel()->addPage(ptr); + ptr->StepNextSubpage(); + } + else + ptr->SetCarouselFlag(false); } } diff --git a/specialpages.cpp b/specialpages.cpp index 2ca2e01..f35534b 100644 --- a/specialpages.cpp +++ b/specialpages.cpp @@ -65,6 +65,14 @@ TTXPageStream* SpecialPages::NextPage() ResetIter(); return nullptr; } + else if (!(_page->Special())) + { + std::cerr << "[SpecialPages::NextPage()] no longer special " << std::hex << _page->GetPageNumber() << std::endl; + _specialPagesList.remove(_page); + _page->SetSpecialFlag(false); + ResetIter(); + return nullptr; + } } return _page;