AskSin++
Peer.h
1 //- -----------------------------------------------------------------------------------------------------------------------
2 // AskSin++
3 // 2016-10-31 papa Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
4 //- -----------------------------------------------------------------------------------------------------------------------
5 
6 #ifndef __PEER_H__
7 #define __PEER_H__
8 
9 #include "HMID.h"
10 #include "Debug.h"
11 
12 namespace as {
13 
14 class Peer : public HMID {
15  uint8_t chan;
16 public:
17  Peer() : chan(0) {}
18  Peer (const HMID& id,uint8_t ch) : HMID(id), chan(ch) {}
19  Peer (uint8_t i1, uint8_t i2, uint8_t i3, uint8_t ch) : HMID(i1,i2,i3), chan(ch) {}
20  Peer (uint8_t* ptr) : HMID(*ptr,*(ptr+1),*(ptr+2)), chan(*(ptr+4)) {}
21  Peer (const Peer& other) : HMID(other) {
22  chan = other.chan;
23  }
24 
25  Peer& operator = (const Peer& other) {
26  *(HMID*)this = (const HMID&)other;
27  chan = other.chan;
28  return *this;
29  }
30  bool operator == (const Peer& other) const {
31  return chan==other.chan && *(HMID*)this == (HMID&)other;
32  }
33 
34  static uint8_t size() { return sizeof(Peer); }
35 
36  uint8_t channel () const {
37  return chan;
38  }
39 
40  bool even () const {
41  return (chan & 0x01) == 0x00;
42  }
43 
44  bool odd () const {
45  return (chan & 0x01) == 0x01;
46  }
47 
48  void dump () {
49  DHEX((uint8_t*)this,sizeof(Peer));
50  }
51 };
52 
53 }
54 
55 #endif
as::Peer
Definition: Peer.h:14
as::HMID
Definition: HMID.h:14