Skip to content

Commit

Permalink
Adding magazine subclass
Browse files Browse the repository at this point in the history
Packet handling for magazine started.
  • Loading branch information
peterkvt80 committed Aug 12, 2017
1 parent 2068d1f commit 8c84481
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 14 deletions.
69 changes: 69 additions & 0 deletions packetmag.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/** Implements a packet source for magazines
*/

#include "packetmag.h"

using namespace vbit;

// @todo Initialise the magazine data
PacketMag::PacketMag(uint8_t mag, std::list<TTXPageStream>* pageSet, ttx::Configure *configure, uint8_t priority) :
_pageSet(pageSet),
_configure(configure),
_page(NULL),
_magNumber(mag),
_priority(priority),
_priorityCount(priority)
{
//ctor
if (_pageSet->size()>0)
{
//std::cerr << "[Mag::Mag] enters. page size=" << _pageSet->size() << std::endl;
_it=_pageSet->begin();
//_it->DebugDump();
_page=&*_it;
}
_carousel=new vbit::Carousel();
}

PacketMag::~PacketMag()
{
//dtor
delete _carousel;
}

// @todo Invent a packet sequencer similar to mag.cpp which this will replace
Packet* PacketMag::GetPacket()
{
static vbit::Packet* filler=new Packet(8,25," "); // filler


// If there is no page, we should send a filler
if (_pageSet->size()<1)
{
return filler;
}

// If we send a header we go into a wait state
ClearEvent(EVENT_FIELD); // @todo Only when we send the header
return filler; // Dummy return for now
}

/** Is there a packet ready to go?
* If the ready flag is set
* and the priority count allows a packet to go out
*/
bool PacketMag::IsReady()
{
// This happens unless we have just sent out a header
if (GetEvent(EVENT_FIELD))
{
// If we send a header we want to wait for this to get set GetEvent(EVENT_FIELD)
_priorityCount--;
if (_priorityCount==0)
{
_priorityCount=_priority;
return true;
}
}
return false;
};
45 changes: 45 additions & 0 deletions packetmag.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#ifndef PACKETMAG_H
#define PACKETMAG_H
#include <list>
#include <PacketSource.h>
#include "ttxpagestream.h"
#include "carousel.h"
#include "configure.h"

namespace vbit
{


class PacketMag : public PacketSource
{
public:
/** Default constructor */
PacketMag(uint8_t mag, std::list<TTXPageStream>* pageSet, ttx::Configure *configure, uint8_t priority);
/** Default destructor */
virtual ~PacketMag();

/** Get the next packet
* @return The next packet OR if IsReady() would return false then a filler packet
*/
Packet* GetPacket() override;

bool IsReady();


protected:

private:
std::list<TTXPageStream>* _pageSet; //!< Member variable "_pageSet"
ttx::Configure* _configure;
TTXPageStream* _page; //!< The current page being output
int _magNumber; //!< The number of this magazine. (where 0 is mag 8)
uint8_t _priority; //!< Priority of transmission where 1 is highest

std::list<TTXPageStream>::iterator _it;
Carousel* _carousel;
uint8_t _priorityCount; // Controls transmission priority
};

}

#endif // PACKETMAG_H
25 changes: 15 additions & 10 deletions packetsource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,35 @@

using namespace vbit;

PacketSource::PacketSource()
PacketSource::PacketSource() :
_readyFlag(false)
{
//ctor
// This could be in the initializer list BUT does not work in Visual C++
for (int i=0;i<EVENT_NUMBER_ITEMS;i++)
{
_eventList[i]=false;
}

}

PacketSource::~PacketSource()
{
//dtor
//dtor. Probably nothing to do here
}


/** Need to override this function in a child class
* The implementation here is useless so don't call it. In fact I should remove it to avoid confusion.
*/
Packet* PacketSource::GetPacket()
{
Packet* pkt=new Packet(8,25," ");
// Do your stuff
return pkt;
}

bool PacketSource::IsReady()
{
return false; // @todo This will probably just return a member bool
}

void PacketSource::SetEvent(Event event)
{
//@todo Use event to clear the event flags which may have been set by the packet source being in wait.
// An event is recorded by setting the corresponding flag
// GetPacket() will clear any event flags when it needs to wait.
_eventList[event]=true;
}
14 changes: 10 additions & 4 deletions packetsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#ifndef _PACKETSOURCE_H_
#define _PACKETSOURCE_H_

#include "packet.h"
#include <packet.h>

namespace vbit{

Expand All @@ -70,7 +70,8 @@ enum Event
EVENT_P830_FORMAT_2_LABEL_2,
EVENT_P830_FORMAT_2_LABEL_3,
EVENT_SUBTITLE,
EVENT_DATABROADCAST
EVENT_DATABROADCAST,
EVENT_NUMBER_ITEMS
} ;


Expand All @@ -88,13 +89,18 @@ class PacketSource
virtual Packet* GetPacket()=0;

/** Is there a packet ready to go? */
virtual bool IsReady(); // Don't need to Pure this. Just report a member bool
virtual bool IsReady(){return _readyFlag;};

/** Report that an event happened */
virtual void SetEvent(Event event); // Don't need to Pure this. All packet sources can use the same code
void SetEvent(Event event); // All packet sources can use the same code
void ClearEvent(Event event){_eventList[event]=false;}; // All packet sources can use the same code
bool GetEvent(Event event){return _eventList[event];};

protected:
bool _readyFlag;

private:
bool _eventList[EVENT_NUMBER_ITEMS];
};

} // vbit namespace
Expand Down

0 comments on commit 8c84481

Please sign in to comment.