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