00001 #ifndef _SRCPACKET_H__
00002 #define _SRCPACKET_H__
00003
00004
00005 #include <sys/types.h>
00006
00007 #include <cstddef>
00008
00009 #include <awds/BasePacket.h>
00010 #include <awds/NodeId.h>
00011 #include <awds/toArray.h>
00012
00013 namespace awds {
00014
00025 class SrcPacket {
00026
00027 public:
00028 static const size_t OffsetSrc = 1;
00029 static const size_t OffsetSeq = OffsetSrc + NodeId::size;
00030 static const size_t SrcPacketEnd = OffsetSeq + 2;
00031
00032 BasePacket& packet;
00033
00038 SrcPacket(BasePacket& packet) :packet(packet) {
00039 }
00040
00043 void setSrc(const NodeId& id) {
00044 id.toArray(&packet.buffer[OffsetSrc]);
00045 }
00046
00053 void getSrc(NodeId& id) const {
00054 id.fromArray(&packet.buffer[OffsetSrc]);
00055 }
00056
00059 NodeId getSrc() const {
00060 NodeId ret;
00061 getSrc(ret);
00062 return ret;
00063 }
00064
00067 void setSeq(u_int16_t num) {
00068 toArray<u_int16_t>(num,&packet.buffer[OffsetSeq]);
00069 }
00070
00073 u_int16_t getSeq() const {
00074 return fromArray<u_int16_t>(&packet.buffer[OffsetSeq]);
00075 }
00076
00077
00080 void setControlBit(int bit, bool v = true) {
00081 assert(bit >= 2 && bit <= 7);
00082 packet.buffer[0] = (packet.buffer[0] & ~('\1' << bit)) | (!!v << bit);
00083 }
00084
00087 bool getControlBit(int bit) const {
00088 assert(bit >= 2 && bit <= 7);
00089 return !!(packet.buffer[0] & ('\1' << bit));
00090 }
00091
00094 void setTraceFlag(bool v = true) {
00095 setControlBit(7,v);
00096 }
00097
00100 bool getTraceFlag() const {
00101 return getControlBit(7);
00102 }
00103
00104
00105 };
00106
00107 }
00108
00109 #endif //SRCPACKET_H__
00110
00111
00112
00113
00114
00115
00116