00001 #ifndef _UNICASTPACKET_H__
00002 #define _UNICASTPACKET_H__
00003
00004
00005 #include <awds/SrcPacket.h>
00006
00007 namespace awds {
00008
00019 class UnicastPacket : public SrcPacket {
00020
00021 public:
00022
00023 static const size_t OffsetUcDest = SrcPacketEnd;
00024 static const size_t OffsetNextHop = OffsetUcDest + NodeId::size;
00025 static const size_t OffsetTTL = OffsetNextHop + NodeId::size;
00026 static const size_t OffsetUcType = OffsetTTL + 1;
00027 static const size_t UnicastPacketEnd = OffsetUcType + 1;
00028
00029
00030 UnicastPacket(BasePacket& p) : SrcPacket(p) {
00031 packet.setType(PacketTypeUnicast);
00032 }
00033
00034 int getTTL() {
00035 return (int)(unsigned)(unsigned char)packet.buffer[OffsetTTL];
00036 }
00037
00038 void setTTL(int ttl) {
00039 packet.buffer[OffsetTTL] = (char)(unsigned char)(ttl % 0x0100);
00040 }
00041
00042 void decrTTL() {
00043 packet.buffer[OffsetTTL]--;
00044 }
00045
00046 void incTTL() {
00047 packet.buffer[OffsetTTL]++;
00048 }
00049
00050 NodeId getUcDest() const {
00051 NodeId ret;
00052 ret.fromArray(&packet.buffer[OffsetUcDest]);
00053 return ret;
00054 }
00055
00056 void setUcDest(const NodeId& id) {
00057 id.toArray(&packet.buffer[OffsetUcDest]);
00058 }
00059
00060 NodeId getNextHop() const {
00061 NodeId ret;
00062 ret.fromArray(&packet.buffer[OffsetNextHop]);
00063 return ret;
00064 }
00065
00066 void setNextHop(const NodeId& id) {
00067 id.toArray(&packet.buffer[OffsetNextHop]);
00068 }
00069
00070
00071 int getUcPacketType() const {
00072 return (int)(unsigned)(unsigned char)packet.buffer[OffsetUcType];
00073 }
00074
00075 void setUcPacketType(int type) {
00076 packet.buffer[OffsetUcType] = static_cast<char>(type % 0x0100);
00077 }
00078
00079 };
00080 }
00081
00082 #endif //UNICASTPACKET_H__
00083
00084
00085
00086
00087
00088