Skip to content

Commit

Permalink
Merge pull request #61 from christopher-s-hall/open-avb-next
Browse files Browse the repository at this point in the history
fix and use Timestamp version field
  • Loading branch information
andrew-elder committed Jul 11, 2014
2 parents 65093fd + e7af407 commit 8791a56
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions daemons/gptp/common/ieee1588.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,21 @@ class ClockIdentity {
void set(LinkLayerAddress * address);
};

#define INVALID_TIMESTAMP_VERSION 0xFF
#define MAX_NANOSECONDS 1000000000
#define MAX_TIMESTAMP_STRLEN 28

class Timestamp {
private:
char output_string[MAX_TIMESTAMP_STRLEN];
public:
Timestamp(uint32_t ns, uint32_t s_l, uint16_t s_m) {
Timestamp
(uint32_t ns, uint32_t s_l, uint16_t s_m,
uint8_t ver = INVALID_TIMESTAMP_VERSION) {
nanoseconds = ns;
seconds_ls = s_l;
seconds_ms = s_m;
_version = ver;
}
Timestamp() {
output_string[0] = '\0';
Expand All @@ -153,6 +157,7 @@ class Timestamp {
uint32_t nanoseconds;
uint32_t seconds_ls;
uint16_t seconds_ms;
uint8_t version;
bool carry;

nanoseconds = this->nanoseconds;
Expand All @@ -172,12 +177,15 @@ class Timestamp {
seconds_ms += carry ? 1 : 0;
carry = seconds_ms < this->seconds_ms ? true : false;

return Timestamp( nanoseconds, seconds_ls, seconds_ms );
version = this->_version == o._version ? this->_version :
INVALID_TIMESTAMP_VERSION;
return Timestamp( nanoseconds, seconds_ls, seconds_ms, version );
}
Timestamp operator-( const Timestamp& o ) {
uint32_t nanoseconds;
uint32_t seconds_ls;
uint16_t seconds_ms;
uint8_t version;
bool carry, borrow_this;
unsigned borrow_total = 0;

Expand Down Expand Up @@ -209,7 +217,9 @@ class Timestamp {
(seconds_ms - borrow_total) - o.seconds_ms;
borrow_total = borrow_this ? borrow_total + 1 : 0;

return Timestamp( nanoseconds, seconds_ls, seconds_ms );
version = this->_version == o._version ? this->_version :
INVALID_TIMESTAMP_VERSION;
return Timestamp( nanoseconds, seconds_ls, seconds_ms, version );
}
void set64( uint64_t value ) {
nanoseconds = value % 1000000000;
Expand Down

0 comments on commit 8791a56

Please sign in to comment.