Skip to content

Commit cf09754

Browse files
authored
Merge pull request #277 from docsteer/243-feature-request-transmit-view-manually-set-fps-hz
243 Feature Request - Transmit View - Manually Set FPS Hz
2 parents a184e5a + bf67571 commit cf09754

File tree

12 files changed

+318
-117
lines changed

12 files changed

+318
-117
lines changed

src/sacn/ACNShare/tock.cpp

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,102 @@ bool Tock_StartLib()
3838
//Gets a tock representing the current time
3939
tock Tock_GetTock()
4040
{
41-
return tock(timer.elapsed());
41+
return tock(std::chrono::nanoseconds(timer.nsecsElapsed()));
4242
}
4343

4444
//Shuts down the tock layer.
4545
void Tock_StopLib()
4646
{
4747

4848
}
49+
50+
tock::tock():v(0) {}
51+
52+
template <typename Rep, typename Period>
53+
tock::tock(std::chrono::duration<Rep, Period> duration)
54+
{
55+
v = duration;
56+
}
57+
58+
tock::resolution_t tock::Get() const
59+
{
60+
return v;
61+
}
62+
63+
void tock::Set(tock::resolution_t time)
64+
{
65+
v = time;
66+
}
67+
68+
bool operator>(const tock& t1, const tock& t2)
69+
{
70+
return t1.v.count() - t2.v.count() > 0;
71+
}
72+
73+
bool operator>=(const tock& t1, const tock& t2)
74+
{
75+
return t1.v.count() - t2.v.count() >= 0;
76+
}
77+
78+
bool operator==(const tock& t1, const tock& t2)
79+
{
80+
return t1.v.count() - t2.v.count() == 0;
81+
}
82+
83+
bool operator!=(const tock& t1, const tock& t2)
84+
{
85+
return t1.v.count() - t2.v.count() != 0;
86+
}
87+
88+
bool operator<(const tock& t1, const tock& t2)
89+
{
90+
return t2.v.count() - t1.v.count() > 0;
91+
}
92+
93+
bool operator<=(const tock& t1, const tock& t2)
94+
{
95+
return t2.v.count() - t1.v.count() >= 0;
96+
}
97+
98+
ttimer::ttimer():interval(0)
99+
{
100+
Reset();
101+
}
102+
103+
template <typename Rep, typename Period>
104+
ttimer::ttimer(std::chrono::duration<Rep, Period> interval) :
105+
interval(interval)
106+
{
107+
Reset();
108+
}
109+
110+
void ttimer::SetInterval(tock::resolution_t interval)
111+
{
112+
this->interval = interval;
113+
Reset();
114+
}
115+
116+
tock::resolution_t ttimer::GetInterval() const
117+
{
118+
return interval;
119+
}
120+
121+
void ttimer::Reset()
122+
{
123+
tockout.Set(Tock_GetTock().Get() + interval);
124+
}
125+
126+
bool ttimer::Expired() const
127+
{
128+
return (Tock_GetTock().Get()) >= tockout.Get();
129+
}
130+
131+
bool operator==(const ttimer& t1, const ttimer& t2)
132+
{
133+
return ((t1.tockout == t2.tockout) && (t1.interval == t2.interval));
134+
}
135+
136+
bool operator!=(const ttimer& t1, const ttimer& t2)
137+
{
138+
return !(t1 == t2);
139+
}

src/sacn/ACNShare/tock.h

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
2323
Provides a standard definition of a tock and a ttimer.
2424
25-
A tock is the number of milliseconds since a platform-specific date.
25+
A tock is the number of nanoseconds since a platform-specific date.
2626
Tocks are never used directly, rather the difference between two tocks
2727
(latest - previous) are used to determine the passage of time. It is
2828
assumed that tocks always move forward, and that the base date is not
2929
different for any instance of the compiled tock, nor does the base date change.
3030
31-
Tocks are guaranteed to have a millisecond granularity.
31+
Tocks are guaranteed to have a nanosecond granularity.
3232
Tock comparisons correctly handle clock rollover.
3333
3434
A ttimer is a simple abstraction for typical timer usage, which is
@@ -40,6 +40,7 @@
4040
#define _TOCK_H_
4141

4242
#include <QtGlobal>
43+
#include <chrono>
4344

4445
class tock;
4546
class ttimer;
@@ -57,20 +58,26 @@ void Tock_StopLib(); //Shuts down the tock layer.
5758
class tock
5859
{
5960
public:
61+
typedef std::chrono::nanoseconds resolution_t;
62+
6063
//construction and copying
6164
tock();
62-
tock(quint32 ms);
63-
tock(const tock& t);
64-
tock& operator=(const tock& t);
65+
tock(const tock&) = default;
66+
tock(tock&&) = default;
67+
tock& operator=(const tock&) = default;
68+
tock& operator=(tock&&) = default;
69+
70+
template <typename Rep, typename Period>
71+
tock(std::chrono::duration<Rep, Period> duration);
6572

66-
//Returns the number of milliseconds that this tock represents
67-
quint32 Getms();
73+
//Returns the number of nanoseconds that this tock represents
74+
resolution_t Get() const;
6875

69-
//Used sparingly, but sets the number of milliseconds that this tock represents
70-
void Setms(quint32 ms);
76+
//Used sparingly, but sets the number of nanoseconds that this tock represents
77+
void Set(resolution_t time);
7178

7279
protected:
73-
qint32 v; //Signed, so the wraparound calculations will work
80+
resolution_t v;
7481

7582
friend bool operator>(const tock& t1, const tock& t2);
7683
friend bool operator>=(const tock& t1, const tock& t2);
@@ -87,52 +94,28 @@ class ttimer
8794
public:
8895
//construction/setup
8996
ttimer(); //Will immediately time out if timeout isn't set
90-
ttimer(qint32 ms); //The number of milliseconds before the timer will time out
91-
void SetInterval(qint32 ms); //Sets a new timeout interval (in ms) and resets the timer
92-
qint32 GetInterval(); //Returns the current timeout interval (in ms)
97+
ttimer(const ttimer&) = default;
98+
ttimer(ttimer&&) = default;
99+
ttimer& operator=(const ttimer&) = default;
100+
ttimer& operator=(ttimer&&) = default;
101+
template <typename Rep, typename Period>
102+
ttimer(std::chrono::duration<Rep, Period> interval); //The duration before the timer will time out
103+
104+
void SetInterval(tock::resolution_t interval); //Sets a new timeout interval and resets the timer
105+
106+
tock::resolution_t GetInterval() const; //Returns the current timeout interval
93107

94108
void Reset(); //Resets the timer, using the current timeout interval
95-
bool Expired() const; //Returns true if the timer has expired.
96-
//Call Reset() to use this timer again for a new interval.
109+
110+
//Returns true if the timer has expired
111+
//Call Reset() to use this timer again for a new interval.
112+
bool Expired() const;
97113

98114
friend bool operator==(const ttimer& t1, const ttimer& t2);
99115
friend bool operator!=(const ttimer& t1, const ttimer& t2);
100116

101117
protected:
102-
qint32 interval;
118+
tock::resolution_t interval;
103119
tock tockout;
104120
};
105-
106-
107-
//---------------------------------------------------------------------------------
108-
// Implementation
109-
110-
/*ttimer implementation*/
111-
inline ttimer::ttimer():interval(0) {Reset();}
112-
inline ttimer::ttimer(qint32 ms):interval(ms) {Reset();}
113-
inline void ttimer::SetInterval(qint32 ms) {interval = ms; Reset();}
114-
inline qint32 ttimer::GetInterval() {return interval;}
115-
inline void ttimer::Reset() {tockout.Setms(Tock_GetTock().Getms() + interval);}
116-
inline bool ttimer::Expired() const {return Tock_GetTock() > tockout;}
117-
inline bool operator==(const ttimer& t1, const ttimer& t2) { return ((t1.tockout == t2.tockout) && (t1.interval == t2.interval)); }
118-
inline bool operator!=(const ttimer& t1, const ttimer& t2) { return !(t1 == t2); }
119-
120-
/*tock implementation*/
121-
inline tock::tock():v(0) {}
122-
inline tock::tock(quint32 ms):v(ms) {}
123-
inline tock::tock(const tock& t) {v = t.v;}
124-
inline tock& tock::operator=(const tock& t) {v = t.v; return *this;}
125-
126-
inline quint32 tock::Getms() {return v;}
127-
inline void tock::Setms(quint32 ms) {v = ms;}
128-
129-
inline bool operator>(const tock& t1, const tock& t2) {return t1.v - t2.v > 0;}
130-
inline bool operator>=(const tock& t1, const tock& t2) {return t1.v - t2.v >= 0;}
131-
inline bool operator==(const tock& t1, const tock& t2) {return t1.v - t2.v == 0;}
132-
inline bool operator!=(const tock& t1, const tock& t2) {return t1.v - t2.v != 0;}
133-
inline bool operator<(const tock& t1, const tock& t2) {return t2.v - t1.v > 0;}
134-
inline bool operator<=(const tock& t1, const tock& t2) {return t2.v - t1.v >= 0;}
135-
inline quint32 operator-(const tock& t1, const tock& t2) {return t1.v - t2.v;}
136-
137-
138121
#endif /*_TOCK_H*/

src/sacn/e1_11.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define E1_11_H
33

44
namespace E1_11 {
5+
static const unsigned int MIN_REFRESH_RATE_HZ = 1; // E1.11:2008 Table 6
56
static const unsigned int MAX_REFRESH_RATE_HZ = 44; // E1.11:2008 Table 6
67
}
78

src/sacn/sacndiscovery.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ void sACNDiscoveryRX::processPacket(quint8* pbuf, uint buflen)
280280
qDebug() << "DiscoveryRX : New universe - CID" << CID::CIDIntoQString(cid) << ", universe" << universe;
281281
emit newUniverse(CID::CIDIntoQString(cid), universe);
282282
}
283-
m_discoveryList[cid]->Universe[universe].SetInterval(E131_UNIVERSE_DISCOVERY_INTERVAL);
283+
m_discoveryList[cid]->Universe[universe].SetInterval(std::chrono::milliseconds(E131_UNIVERSE_DISCOVERY_INTERVAL));
284284
}
285285
}
286286
else

src/sacn/sacnlistener.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,14 +334,14 @@ void sACNListener::processDatagram(const QByteArray &data, const QHostAddress &d
334334
{
335335
// This is a source which is coming back online, so we need to repeat the steps
336336
// for initial source aquisition
337-
ps->active.SetInterval(E131_NETWORK_DATA_LOSS_TIMEOUT + m_ssHLL);
337+
ps->active.SetInterval(std::chrono::milliseconds(E131_NETWORK_DATA_LOSS_TIMEOUT + m_ssHLL));
338338
ps->lastseq = sequence;
339339
ps->src_cid = source_cid;
340340
ps->src_valid = true;
341341
ps->doing_dmx = (start_code == STARTCODE_DMX);
342342
ps->doing_per_channel = ps->waited_for_dd = false;
343343
newsourcenotify = false;
344-
ps->priority_wait.SetInterval(WAIT_PRIORITY);
344+
ps->priority_wait.SetInterval(std::chrono::milliseconds(WAIT_PRIORITY));
345345
}
346346

347347
if(
@@ -358,10 +358,10 @@ void sACNListener::processDatagram(const QByteArray &data, const QHostAddress &d
358358
//to a value of 1, a receiver shall enter network
359359
//data loss condition. Any property values in
360360
//these packets shall be ignored"
361-
(*it)->active.SetInterval(m_ssHLL); //We factor in the hold last look time here, rather than 0
361+
(*it)->active.SetInterval(std::chrono::milliseconds(m_ssHLL)); //We factor in the hold last look time here, rather than 0
362362

363363
if((*it)->doing_per_channel)
364-
(*it)->priority_wait.SetInterval(m_ssHLL); //We factor in the hold last look time here, rather than 0
364+
(*it)->priority_wait.SetInterval(std::chrono::milliseconds(m_ssHLL)); //We factor in the hold last look time here, rather than 0
365365

366366
validpacket = false;
367367
break;
@@ -372,7 +372,7 @@ void sACNListener::processDatagram(const QByteArray &data, const QHostAddress &d
372372
{
373373
//No matter how valid, we got something -- but we'll tweak the interval for any hll change
374374
(*it)->doing_dmx = true;
375-
(*it)->active.SetInterval(E131_NETWORK_DATA_LOSS_TIMEOUT + m_ssHLL);
375+
(*it)->active.SetInterval(std::chrono::milliseconds(E131_NETWORK_DATA_LOSS_TIMEOUT + m_ssHLL));
376376
}
377377
else if(start_code == STARTCODE_PRIORITY && (*it)->waited_for_dd)
378378
{
@@ -414,14 +414,14 @@ void sACNListener::processDatagram(const QByteArray &data, const QHostAddress &d
414414
{
415415
(*it)->waited_for_dd = true;
416416
(*it)->doing_per_channel = true;
417-
(*it)->priority_wait.SetInterval(E131_NETWORK_DATA_LOSS_TIMEOUT + m_ssHLL);
417+
(*it)->priority_wait.SetInterval(std::chrono::milliseconds(E131_NETWORK_DATA_LOSS_TIMEOUT + m_ssHLL));
418418
newsourcenotify = true;
419419
}
420420
else if((*it)->priority_wait.Expired())
421421
{
422422
(*it)->waited_for_dd = true;
423423
(*it)->doing_per_channel = false;
424-
(*it)->priority_wait.SetInterval(E131_NETWORK_DATA_LOSS_TIMEOUT + m_ssHLL); //In case the source later decides to sent 0xdd packets
424+
(*it)->priority_wait.SetInterval(std::chrono::milliseconds(E131_NETWORK_DATA_LOSS_TIMEOUT + m_ssHLL)); //In case the source later decides to sent 0xdd packets
425425
newsourcenotify = true;
426426
}
427427
else
@@ -448,7 +448,7 @@ void sACNListener::processDatagram(const QByteArray &data, const QHostAddress &d
448448
ps->ip = sender;
449449
ps->universe = universe;
450450
ps->synchronization = synchronization;
451-
ps->active.SetInterval(E131_NETWORK_DATA_LOSS_TIMEOUT + m_ssHLL);
451+
ps->active.SetInterval(std::chrono::milliseconds(E131_NETWORK_DATA_LOSS_TIMEOUT + m_ssHLL));
452452
ps->lastseq = sequence;
453453
ps->src_cid = source_cid;
454454
ps->src_valid = true;
@@ -460,14 +460,14 @@ void sACNListener::processDatagram(const QByteArray &data, const QHostAddress &d
460460
ps->waited_for_dd = true;
461461
ps->doing_per_channel = (start_code == STARTCODE_PRIORITY);
462462
newsourcenotify = true;
463-
ps->priority_wait.SetInterval(E131_NETWORK_DATA_LOSS_TIMEOUT + m_ssHLL);
463+
ps->priority_wait.SetInterval(std::chrono::milliseconds(E131_NETWORK_DATA_LOSS_TIMEOUT + m_ssHLL));
464464
}
465465
else
466466
{
467467
//If we aren't sampling, we want the earlier logic to set the state
468468
ps->doing_per_channel = ps->waited_for_dd = false;
469469
newsourcenotify = false;
470-
ps->priority_wait.SetInterval(WAIT_PRIORITY);
470+
ps->priority_wait.SetInterval(std::chrono::milliseconds(WAIT_PRIORITY));
471471
}
472472

473473
validpacket = newsourcenotify;

0 commit comments

Comments
 (0)