Skip to content

Commit

Permalink
Add another page list to hold normal non-carousel pages which FileMon…
Browse files Browse the repository at this point in the history
…itor has just added or updated.

PacketMag now checks this list ahead of carousels and normal pages so that updates are transmitted immediately (with interrupted sequence flag set in header)
The magazine priority is also ignored when it has waiting updated pages so IsReady returns true (equivalent to calling with force)
  • Loading branch information
ZXGuesser committed Aug 10, 2020
1 parent ece7ddd commit c59c2f3
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 21 deletions.
2 changes: 1 addition & 1 deletion carousel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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--);
}
Expand Down
15 changes: 14 additions & 1 deletion filemonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion normalpages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 28 additions & 9 deletions packetmag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,19 @@ PacketMag::PacketMag(uint8_t mag, std::list<TTXPageStream>* 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)
Expand All @@ -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

Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion packetmag.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "carousel.h"
#include "specialpages.h"
#include "normalpages.h"
#include "updatedpages.h"
#include "configure.h"

#define MAXPACKET29TYPES 3
Expand All @@ -28,9 +29,10 @@ class PacketMag : public PacketSource
*/
std::list<TTXPageStream>* 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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion specialpages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions ttxpagestream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ TTXPageStream::TTXPageStream() :
_isCarousel(false),
_isSpecial(false),
_isNormal(false),
_isUpdated(false),
_updateCount(0)
{
//ctor
Expand All @@ -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
Expand Down
11 changes: 4 additions & 7 deletions ttxpagestream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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();

Expand Down Expand Up @@ -143,6 +139,7 @@ class TTXPageStream : public TTXPage
bool _isCarousel;
bool _isSpecial;
bool _isNormal;
bool _isUpdated;

int _updateCount; // update counter for special pages.

Expand Down
61 changes: 61 additions & 0 deletions updatedpages.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
38 changes: 38 additions & 0 deletions updatedpages.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef _UPDATEDPAGES_H
#define _UPDATEDPAGES_H

#include <list>

#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<TTXPageStream*> _UpdatedPagesList;
std::list<TTXPageStream*>::iterator _iter;
TTXPageStream* _page;

};

}

#endif // _UPDATEDPAGES_H

0 comments on commit c59c2f3

Please sign in to comment.