diff --git a/packetmag.cpp b/packetmag.cpp index 241c864..262346f 100644 --- a/packetmag.cpp +++ b/packetmag.cpp @@ -26,7 +26,7 @@ PacketMag::PacketMag(uint8_t mag, std::list* pageSet, ttx::Config _cycleDuration(-1) { //ctor - _lastCycle = {0,0}; + _lastCycleTimestamp = {0,0}; for (int i=0;iInstance(); MasterClock::timeStruct t = mc->GetMasterClock(); - if (_lastCycle.seconds){ // wait for real timestamps - int diffSeconds = difftime(t.seconds, _lastCycle.seconds); // truncates double to int - _cycleDuration = ((diffSeconds * 50) - _lastCycle.fields) + t.fields; + if (_lastCycleTimestamp.seconds){ // wait for real timestamps + int diffSeconds = difftime(t.seconds, _lastCycleTimestamp.seconds); // truncates double to int + _cycleDuration = ((diffSeconds * 50) - _lastCycleTimestamp.fields) + t.fields; _debug->SetMagCycleDuration(_magNumber, _cycleDuration); } - _lastCycle = t; // update timestamp + _lastCycleTimestamp = t; // update timestamp // couldn't get a page to send so sent a time filling header p->Header(_magNumber,0xFF,0x0000,0x8010,_headerTemplate); @@ -435,6 +435,8 @@ bool PacketMag::IsReady(bool force) ClearEvent(EVENT_FIELD); if (_waitingForField > 0) { + // _waitingForField is set to 2 when the last packet was a header but field event is not yet cleared + // on the next IsReady we clear the event and decrement it ready to wait for the next field event. _waitingForField--; } } diff --git a/packetmag.h b/packetmag.h index 90ea100..d4cc2e2 100644 --- a/packetmag.h +++ b/packetmag.h @@ -51,6 +51,7 @@ namespace vbit bool GetCustomHeaderFlag() { return _hasCustomHeader; }; void DeleteCustomHeader(); + void InvalidateCycleTimestamp() { _lastCycleTimestamp = {0,0}; }; // reset cycle duration calculation int GetCycleDuration() { return _cycleDuration; }; protected: @@ -92,7 +93,7 @@ namespace vbit bool _specialPagesFlipFlop; // toggle to alternate between special pages and normal pages int _waitingForField; - MasterClock::timeStruct _lastCycle; + MasterClock::timeStruct _lastCycleTimestamp; int _cycleDuration; // magazine cycle time in fields }; } diff --git a/service.cpp b/service.cpp index a41c858..4b0c6a9 100644 --- a/service.cpp +++ b/service.cpp @@ -12,11 +12,11 @@ Service::Service(Configure *configure, vbit::Debug *debug, PageList *pageList, P _packetServer(packetServer), _fieldCounter(49) // roll over immediately { - vbit::PacketMag **magList=_pageList->GetMagazines(); + _magList=_pageList->GetMagazines(); // Register all the packet sources for (uint8_t mag=0;mag<8;mag++) { - vbit::PacketMag* m=magList[mag]; + vbit::PacketMag* m=_magList[mag]; m->SetPriority(_configure->GetMagazinePriority(mag)); // set the mags to the desired priorities _register(m); // use the PacketMags created in pageList rather than duplicating them } @@ -190,6 +190,9 @@ void Service::_updateEvents() masterClock.seconds = now; _debug->Log(Debug::LogLevels::logWARN,"[Service::_updateEvents] Resynchronising master clock"); + + for (int i=0;i<8;i++) + _magList[i]->InvalidateCycleTimestamp(); // reset magazine cycle duration calculations } if (masterClock.seconds%15==0) // TODO: how often do we want to trigger sending special packets? diff --git a/service.h b/service.h index 748e21f..baa3d47 100644 --- a/service.h +++ b/service.h @@ -57,6 +57,7 @@ namespace ttx Configure* _configure; /// Member reference to the configuration settings vbit::Debug* _debug; PageList* _pageList; /// Member reference to the pages list + vbit::PacketMag** _magList; PacketServer* _packetServer; // Member variables for event management