Skip to content

Commit

Permalink
Sort of producing output now.
Browse files Browse the repository at this point in the history
Reworked the service loop to improve the packet sequencing.
Replaced NULL with nullptr as that is the C+11 way to do things.
  • Loading branch information
peterkvt80 committed Aug 21, 2017
1 parent a0db713 commit 974275d
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 49 deletions.
6 changes: 3 additions & 3 deletions carousel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void Carousel::deletePage(TTXPageStream* p)
TTXPageStream* Carousel::nextCarousel()
{
TTXPageStream* p;
//std::cerr << "[nextCarousel] list size = " << _carouselList.size() << std::endl;
std::cerr << "[nextCarousel] list size = " << _carouselList.size() << std::endl;
if (_carouselList.size()==0) return NULL;


Expand All @@ -42,11 +42,11 @@ TTXPageStream* Carousel::nextCarousel()

if (p->Expired())
{
//std::cerr << "[Carousel::nextCarousel] page " << std::hex << p->GetPageNumber() << std::dec << " cycle time=" << p->GetCycleTime() << std::endl;
std::cerr << "[Carousel::nextCarousel] page " << std::hex << p->GetPageNumber() << std::dec << " cycle time=" << p->GetCycleTime() << std::endl;
p->SetTransitionTime(); // We found a carousel that is ready to step
break;
}
p=NULL;
p=nullptr;
}
#if 0
char c;
Expand Down
4 changes: 2 additions & 2 deletions filemonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ FileMonitor::FileMonitor(Configure *configure, PageList *pageList) :
}

FileMonitor::FileMonitor()
: _pageList(NULL)
: _pageList(nullptr)
{
//ctor
}
Expand Down Expand Up @@ -146,6 +146,6 @@ void FileMonitor::run()
ms=5000;
rec.tv_sec = ms / 1000;
rec.tv_nsec=(ms % 1000) *1000000;
nanosleep(&rec,NULL);
nanosleep(&rec,nullptr);
}
} // run
16 changes: 8 additions & 8 deletions mag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Mag::Mag(int mag, std::list<TTXPageStream>* pageSet, ttx::Configure *configure)
_headerFlag(false),
_thisRow(0),
_state(STATE_HEADER),
_lastTxt(NULL)
_lastTxt(0)
{
//ctor
if (_pageSet->size()>0)
Expand Down Expand Up @@ -111,7 +111,7 @@ Packet* Mag::GetPacket(Packet* p)
{
//std::cerr << "[Mag::GetPacket] Delete this carousel" << std::endl;
_carousel->deletePage(_page);
_page=NULL;
_page=nullptr;
// @todo We are not done. This just deletes a pointer to the page. It is still in _pageList
}

Expand Down Expand Up @@ -143,16 +143,16 @@ Packet* Mag::GetPacket(Packet* p)
if (_page->GetStatusFlag()==TTXPageStream::MARKED)
{
_pageSet->remove(*(_it++));
_page=NULL;
_page=nullptr;
return filler;
// Stays in HEADER mode so that we run this again
}
if (_page->IsCarousel() && _page->GetCarouselFlag()) // Don't let registered carousel pages into the main page sequence
{
// todo:
// std::cerr << "Page is a carousel. This can not happen" << std::endl;
_page=NULL;
return NULL;
_page=nullptr;
return nullptr;
}

}
Expand Down Expand Up @@ -283,7 +283,7 @@ Packet* Mag::GetPacket(Packet* p)
_state=STATE_TEXTROW; // Fall through to text rows on normal pages
} else {
// otherwise we end the page here
p=NULL;
p=nullptr;
_state=STATE_HEADER;
_thisRow=0;
break;
Expand All @@ -301,7 +301,7 @@ Packet* Mag::GetPacket(Packet* p)
{
if(_page->GetPageCoding() == CODING_7BIT_TEXT){
// if this is a normal page we've finished
p=NULL;
p=nullptr;
_state=STATE_HEADER;
_thisRow=0;
//_outp("H");
Expand All @@ -317,7 +317,7 @@ Packet* Mag::GetPacket(Packet* p)
if (_lastTxt->IsBlank() && _configure->GetRowAdaptive()) // If the row is empty then skip it
{
// std::cerr << "[Mag::GetPacket] Empty row" << std::hex << _page->GetPageNumber() << std::dec << std::endl;
p=NULL;
p=nullptr;
}
else
{
Expand Down
60 changes: 42 additions & 18 deletions packetmag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ using namespace vbit;
PacketMag::PacketMag(uint8_t mag, std::list<TTXPageStream>* pageSet, ttx::Configure *configure, uint8_t priority) :
_pageSet(pageSet),
_configure(configure),
_page(NULL),
_page(nullptr),
_magNumber(mag),
_priority(priority),
_priorityCount(priority),
_headerFlag(false),
_state(PACKETSTATE_HEADER),
_thisRow(0),
_lastTxt(NULL)
_lastTxt(nullptr)
{
//ctor
if (_pageSet->size()>0)
Expand All @@ -38,6 +38,7 @@ PacketMag::~PacketMag()
// @todo Invent a packet sequencer similar to mag.cpp which this will replace
Packet* PacketMag::GetPacket(Packet* p)
{
std::cerr << "[PacketMag::GetPacket] mag=" << _magNumber << " state=" << _state << std::endl;
int thisPageNum;
unsigned int thisSubcode;
int thisStatus;
Expand All @@ -46,11 +47,16 @@ Packet* PacketMag::GetPacket(Packet* p)
static vbit::Packet* filler=new Packet(8,25," "); // filler

// We should only call GetPacket if IsReady has returned true

/* Nice to have a safety net
* but without the previous value of the force flag this can give a false positive.
if (!IsReady())
{
std::cerr << "[PacketMag::GetPacket] Packet not ready. This must not happen" << std::endl;
exit(0);
}
*/

// If there is no page, we should send a filler
if (_pageSet->size()<1)
Expand All @@ -63,15 +69,15 @@ Packet* PacketMag::GetPacket(Packet* p)
case PACKETSTATE_HEADER: // Start to send out a new page, which may be a simple page or one of a carousel
ClearEvent(EVENT_FIELD); // This will suspend all packets until the next field.

_page=_carousel->nextCarousel(); // The next carousel page
_page=_carousel->nextCarousel(); // The next carousel page (if there is one)

// But before that, do some housekeeping

// Is this page deleted?
if (_page && _page->GetStatusFlag()==TTXPageStream::MARKED)
{
_carousel->deletePage(_page);
_page=NULL;
_page=nullptr;
}

if (_page) // Carousel? Step to the next subpage
Expand All @@ -85,7 +91,7 @@ Packet* PacketMag::GetPacket(Packet* p)
{
if (_it==_pageSet->end())
{
std::cerr << "This can not happen" << std::endl;
std::cerr << "This can not happen (we can't get the next page?)" << std::endl;
exit(0);
}
++_it;
Expand All @@ -100,17 +106,17 @@ Packet* PacketMag::GetPacket(Packet* p)
if (_page->GetStatusFlag()==TTXPageStream::MARKED)
{
_pageSet->remove(*(_it++));
_page=NULL;
_page=nullptr;
return filler;
// Stays in HEADER mode so that we run this again
}
if (_page->IsCarousel() && _page->GetCarouselFlag()) // Don't let registered carousel pages into the main page sequence
{
std::cerr << "This can not happen" << std::endl;
exit(0);
std::cerr << "This can not happen. Carousel found but it isn't a carousel?" << std::endl;
// exit(0); // @todo MUST FIX THIS. Need to find out how we are getting here and stop it doing that!
// Page is a carousel. This can not happen
//_page=NULL;
//return NULL;
_page=nullptr; // clear everything for now so that we keep running @todo THIS IS AN ERROR
return nullptr;
}
}
_thisRow=0;
Expand Down Expand Up @@ -166,16 +172,20 @@ Packet* PacketMag::GetPacket(Packet* p)
// Find the next row that isn't NULL
for (_thisRow++;_thisRow<26;_thisRow++)
{
std::cerr << "*";
_lastTxt=_page->GetTxRow(_thisRow);
if (_lastTxt!=NULL)
break;
}
std::cerr << std::endl;
std::cerr << "[PacketMag::GetPacket] TEXT ROW sending row" << _thisRow << std::endl;

// Didn't find? End of this page.
if (_thisRow>25 || _lastTxt==NULL)
{
if(_page->GetPageCoding() == CODING_7BIT_TEXT){
// if this is a normal page we've finished
p=NULL;
p=nullptr;
_state=PACKETSTATE_HEADER;
_thisRow=0;
//_outp("H");
Expand All @@ -191,7 +201,7 @@ Packet* PacketMag::GetPacket(Packet* p)
if (_lastTxt->IsBlank() && _configure->GetRowAdaptive()) // If the row is empty then skip it
{
// std::cerr << "[Mag::GetPacket] Empty row" << std::hex << _page->GetPageNumber() << std::dec << std::endl;
p=NULL;
p=nullptr;
}
else
{
Expand All @@ -204,11 +214,13 @@ Packet* PacketMag::GetPacket(Packet* p)
}
break;
case PACKETSTATE_FASTEXT:
// std::cerr << "PACKETSTATE_FASTEXT enters" << std::endl;
p->SetMRAG(_magNumber,27);
links=_page->GetLinkSet();
p->Fastext(links,_magNumber);
_lastTxt=_page->GetTxRow(28); // Get _lastTxt ready for packet 28 processing
_state=PACKETSTATE_PACKET28;
// std::cerr << "PACKETSTATE_FASTEXT exits" << std::endl;
break;
default:
_state=PACKETSTATE_HEADER;// For now, do the next page
Expand All @@ -221,19 +233,31 @@ Packet* PacketMag::GetPacket(Packet* p)
/** Is there a packet ready to go?
* If the ready flag is set
* and the priority count allows a packet to go out
* @param force - If true AND if the next packet is being held back due to priority, send the packet anyway
*/
bool PacketMag::IsReady()
bool PacketMag::IsReady(bool force)
{
// This happens unless we have just sent out a header
if (GetEvent(EVENT_FIELD))
bool result=false;
// We can always send something unless
// 1) We have just sent out a header and are waiting on a new field
// 2) There are no pages
if ( ((GetEvent(EVENT_FIELD)) || (_state==PACKETSTATE_HEADER)) && (_pageSet->size()>0))
{
// If we send a header we want to wait for this to get set GetEvent(EVENT_FIELD)
_priorityCount--;
if (_priorityCount==0)
if (_priorityCount==0 || force)
{
_priorityCount=_priority;
return true;
result=true;
}
}
return false;
/*
std::cerr << "[PacketMag::IsReady] exits."
" mag=" << _magNumber <<
" force=" << force <<
" result=" << result <<
" EVENT_FIELD=" << GetEvent(EVENT_FIELD) <<
std::endl;
*/
return result;
};
3 changes: 1 addition & 2 deletions packetmag.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class PacketMag : public PacketSource
*/
Packet* GetPacket(Packet* p) override;

bool IsReady();

bool IsReady(bool force=false);

protected:

Expand Down
7 changes: 5 additions & 2 deletions packetsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ class PacketSource
*/
virtual Packet* GetPacket(Packet* p)=0;

/** Is there a packet ready to go? */
virtual bool IsReady(){return _readyFlag;};
/** Is there a packet ready to go?
* @param force - If true and the next packet's priority is holding it, then allow the packet to go anyway. Default false.
* @return true if there is a packet ready to go.
*/
virtual bool IsReady(bool force=false)=0; // {return _readyFlag;};

/** Report that an event happened */
void SetEvent(Event event); // All packet sources can use the same code
Expand Down
4 changes: 2 additions & 2 deletions pagelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ PageList::PageList(Configure *configure) :
_configure(configure)
{
for (int i=0;i<8;i++)
_mag[i]=NULL;
if (_configure==NULL)
_mag[i]=nullptr;
if (_configure==nullptr)
{
std::cerr << "NULL configuration object" << std::endl;
return;
Expand Down
Loading

0 comments on commit 974275d

Please sign in to comment.