当前位置: 首页>>代码示例>>C#>>正文


C# AdHocBaseApp.Packet类代码示例

本文整理汇总了C#中AdHocBaseApp.Packet的典型用法代码示例。如果您正苦于以下问题:C# Packet类的具体用法?C# Packet怎么用?C# Packet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Packet类属于AdHocBaseApp命名空间,在下文中一共展示了Packet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendPacketDirectly

        public override bool SendPacketDirectly(float time, Packet pkg)
        {
            float recv_time = global.processDelay + global.internetDelay;
            pkg.Prev = Id;
            Console.WriteLine("{0:F4} [{1}] {2}{3} sends to {4}{5}", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.NextType, (pkg.Next == -1 ? "all" : pkg.Next.ToString()));

            if (pkg.Next == -1) //Broadcast
                return true;//No such a case.
            else
            {
                Node node = null;
                switch (pkg.NextType)
                {
                    case NodeType.READER:
                        node = global.readers[pkg.Next];
                        break;
                    case NodeType.SERVER:
                        node = global.server;
                        break;
                    default:
                        Debug.Assert(false, "Error Next Type!");
                        break;
                }
                pkg.PrevType = type;
                pkg.Prev = Id;
                Event.AddEvent(
                    new Event(time + recv_time, EventType.RECV,
                        node, pkg));
            }
            return true;
        }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:31,代码来源:Querier.cs

示例2: IOTPhenomemon

 public IOTPhenomemon(IOTPhenomemonType type, int nodeId, double time, Packet pkg)
 {
     this.type = type;
     this.nodeId = nodeId;
     this.start = this.end = time;
     this.pkg = pkg;
 }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:7,代码来源:IOTPhenomemon.cs

示例3: Recv

        public override void Recv(Packet pkg)
        {
            if (pkg.PrevType != NodeType.READER)
            {
                Console.WriteLine("{0:F4} [{1}] {2}{3} drop from {4}{5} due to wrong node type", scheduler.currentTime, pkg.Type, this.type,this.Id, pkg.PrevType, pkg.Prev);
                return;
            }

            Reader node = global.readers[pkg.Prev];
            if (Utility.Distance(this, (MobileNode)node) > Global.getInstance().objectMaxDist)
            {
                Console.WriteLine("{0:F4} [{1}] {2}{3} Drop {4}{5} due to out of space", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.PrevType, pkg.Prev);
                return;
            }

            switch (pkg.Type)
            {
                case PacketType.LOGICAL_PATH_REQUEST:
                    Console.WriteLine("{0:F4} [{1}] {2}{3} recv from {4}{5}", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.PrevType, pkg.Prev);
                    RecvQueryRequest(pkg);
                    break;
                case PacketType.DATA_AVAIL: //Override the link path update
                    Console.WriteLine("{0:F4} [{1}] {2}{3} recv from {4}{5}", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.PrevType, pkg.Prev);
                    UpdateLogicalPath(pkg);
                    break;
                default:
                    base.Recv(pkg);
                    return;
            }
            return;
        }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:31,代码来源:LogicalPathObjectNode.cs

示例4: GetQueryResponseFromServer

        public void GetQueryResponseFromServer(Packet pkg)
        {
            if (pkg.ObjectLogicalPathQueryServerReply == null)
            {
                Console.WriteLine("{0:F4} [{1}] {2}{3} Querying result: Object not found.", scheduler.currentTime, pkg.Type, this.type, this.Id);
                return;
            }
            else
                Console.WriteLine("{0:F4} [{1}] {2}{3} Querying result: Object {4}.", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.ObjectLogicalPathQueryServerReply.ToString());

            ObjectLogicalPathQueryServerReplyField f = pkg.ObjectLogicalPathQueryServerReply;
            if (scheduler.currentTime - f.time > global.maxLocationUpdateInterval * 2)
            {
                Console.WriteLine("{0:F4} [{1}] {2}{3} Query abort: Object {4} move time out.", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.ObjectLogicalPathQueryServerReply.obj);
                return;
            }
            Packet pkg1 = new Packet(this, global.readers[f.reader], PacketType.LOGICAL_PATH_REQUEST);
            pkg1.Next = f.gateway;
            pkg1.NextType = NodeType.READER;
            pkg1.ObjectLogicalPathQueryReqeust = new ObjectLogicalPathQueryRequestField();
            pkg1.ObjectLogicalPathQueryReqeust.gateway = f.gateway;
            pkg1.ObjectLogicalPathQueryReqeust.reader = f.reader;
            pkg1.ObjectLogicalPathQueryReqeust.obj = f.obj;
            SendPacketDirectly(scheduler.currentTime, pkg1);
        }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:25,代码来源:LogicalPathQuerier.cs

示例5: Recv

        public override void Recv(Packet pkg)
        {
            if (pkg.PrevType != NodeType.READER)
            {
                Console.WriteLine("{0:F4} [{1}] {2}{3} drop from {4}{5} due to wrong node type", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.PrevType, pkg.Prev);
                return;
            }

            Reader node = global.readers[pkg.Prev];
            if (Utility.Distance(this, (MobileNode)node) > Global.getInstance().objectMaxDist)
            {
                Console.WriteLine("{0:F4} [{1}] {2}{3} Drop {4}{5} due to out of space", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.PrevType, pkg.Prev);
                return;
            }

            switch (pkg.Type)
            {
                case PacketType.TAG_HEADER:
                    Console.WriteLine("{0:F4} [{1}] {2}{3} recv from {4}{5}", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.PrevType, pkg.Prev);
                    RecvTagHeaderRequest(pkg);
                    break;
                case PacketType.DATA_AVAIL:
                    Console.WriteLine("{0:F4} [{1}] {2}{3} recv from {4}{5}", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.PrevType, pkg.Prev);
                    RecvAuthorization(pkg);
                    break;
                default:
                    base.Recv(pkg);
                    return;
            }
            return;
        }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:31,代码来源:IOTObjectNode.cs

示例6: RecvAuthorization

        public void RecvAuthorization(Packet pkg)
        {
            int key = pkg.Authorization.keys[0];
            if (key != Id)
            {
                Console.WriteLine("Object{0} key not match: {1}.", Id, key);
                return;
            }
            this.lastNearReader = this.global.readers[pkg.Src];
            this.lastNearReaderTime = scheduler.currentTime;

            List<Packet> removeList = new List<Packet>();
            List<Packet> addList = new List<Packet>();
            foreach (Packet p in this.cachePackets)
            {
                if (TrySendData(p) && this.cachePackets.Contains(pkg))
                    removeList.Add(p);
                else if (!this.cachePackets.Contains(pkg))
                    addList.Add(pkg);
            }
            //我们就不测重试失败的例子了
            /*
            foreach (Packet p in addList)
                this.cachePackets.Add(p);
             **/
            foreach (Packet p in removeList)
                this.cachePackets.Remove(p);
        }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:28,代码来源:IOTObjectNode.cs

示例7: GetQueryResponseFromReader

 public void GetQueryResponseFromReader(Packet pkg)
 {
     if (pkg.ObjectLogicalPathQueryReply == null)
         Console.WriteLine("{0:F4} [{1}] {2}{3} Querying result: Object not found.", scheduler.currentTime, pkg.Type, this.type, this.Id);
     else
         Console.WriteLine("{0:F4} [{1}] {2}{3} Querying result: Object {4}, total time:{5}.", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.ObjectLogicalPathQueryReply, scheduler.currentTime - this.queryingTime);
     this.queryingTime = -1;
 }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:8,代码来源:LogicalPathQuerier.cs

示例8: GetQueryResponse

 public void GetQueryResponse(Packet pkg)
 {
     if (pkg.ObjectLocationReply == null)
         Console.WriteLine("{0:F4} [LOCATION_QUERY] {1}{2} Querying result: Object {3} not found.", scheduler.currentTime, this.type, this.Id, pkg.ObjectLocationReply.obj);
     else
         Console.WriteLine("{0:F4} [LOCATION_QUERY] {1}{2} Querying result: Object {3}.", scheduler.currentTime, this.type, this.Id, pkg.ObjectLocationReply.ToString());
     this.queryingTime = -1;
 }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:8,代码来源:Querier.cs

示例9: SendObjectLogicalPath

        public void SendObjectLogicalPath(Packet pkg)
        {
            Node querier = global.queriers[pkg.Src];
            Packet pkg1 = new Packet(this, querier, PacketType.LOCATION_QUERY);
            int obj = pkg.ObjectLocationRequest.obj;
            if (this.objectLogicalPaths.ContainsKey(obj))
                pkg1.ObjectLogicalPathQueryServerReply = new ObjectLogicalPathQueryServerReplyField(obj, this.objectLogicalPaths[obj].G, this.objectLogicalPaths[obj].R, this.objectLogicalPaths[obj].T);
            else
                pkg1.ObjectLogicalPathQueryServerReply = null;

            SendPacketDirectly(scheduler.currentTime, pkg1);
        }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:12,代码来源:LogicalPathServer.cs

示例10: CheckReversePathCache

 public void CheckReversePathCache(Packet pkg)
 {
     int r = pkg.ObjectLogicalPathUpdate.r;
     int o = pkg.ObjectLogicalPathUpdate.obj;
     string key = r + "_" + o;
     int prev = pkg.Prev;
     if (this.reversePathCache.ContainsKey(key))
     {
         this.reversePathCache[key].time = scheduler.currentTime;
     }
     else
     {
         this.reversePathCache.Add(key, new ReversePath(r, prev, scheduler.currentTime));
     }
 }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:15,代码来源:LogicalPathReader.cs

示例11: Recv

 public override void Recv(Packet pkg)
 {
     switch (pkg.Type)
     {
         //Some codes are hided in the base class.
         case PacketType.LOGICAL_PATH_UPDATE:
             UpdateLogicalPath(pkg);
             break;
         case PacketType.LOCATION_QUERY:
             SendObjectLogicalPath(pkg);
             break;
         default:
             base.Recv(pkg);
             return;
     }
 }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:16,代码来源:LogicalPathServer.cs

示例12: UpdateLogicalPath

        public void UpdateLogicalPath(Packet pkg)
        {
            int id = pkg.ObjectLogicalPathUpdate.obj;
            ObjectLogicalPath path = null;
            if (this.objectLogicalPaths.ContainsKey(id))
                path = this.objectLogicalPaths[id];
            else
            {
                path = new ObjectLogicalPath();
                this.objectLogicalPaths.Add(id, path);
            }

            path.O = pkg.ObjectLogicalPathUpdate.obj;
            path.R = pkg.ObjectLogicalPathUpdate.r;
            path.G = pkg.ObjectLogicalPathUpdate.g;
            path.T = pkg.ObjectLogicalPathUpdate.t;
        }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:17,代码来源:LogicalPathServer.cs

示例13: Recv

 public override void Recv(Packet pkg)
 {
     if (pkg.PrevType != NodeType.SERVER )
     {
         System.Console.WriteLine("Server receive error type!");
         return;
     }
     else if (pkg.PrevType == NodeType.SERVER)
     {
         switch (pkg.Type)
         {
             case PacketType.LOCATION_QUERY:
                 Console.WriteLine("{0:F4} [{1}] {2}{3} recv from {4}{5}, total time:{6}", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.PrevType, pkg.Prev, scheduler.currentTime-this.queryingTime);
                 GetQueryResponse(pkg);
                 break;
         }
     }
 }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:18,代码来源:Querier.cs

示例14: RecvQueryRequest

        public void RecvQueryRequest(Packet pkg)
        {
            ObjectLogicalPathQueryRequestField f = pkg.ObjectLogicalPathQueryReqeust;
            Reader gw = global.readers[f.gateway];
            Packet reply = new Packet(this, gw, PacketType.LOGICAL_PATH_REPLY);
            reply.NextType = NodeType.READER;
            reply.Next = pkg.Prev;
            reply.ObjectLogicalPathQueryReply = new ObjectLogicalPathQueryReplyField();
            reply.ObjectLogicalPathQueryReply.gateway = f.gateway;
            reply.ObjectLogicalPathQueryReply.obj = Id;
            reply.ObjectLogicalPathQueryReply.querier = pkg.Src;
            //TODO, x and y should be acquired from landmark reader...
            reply.ObjectLogicalPathQueryReply.shape = new PointShape(this.x, this.y);

            //TODO fill the shape.
            //do some stuf here
            SendPacketDirectly(scheduler.currentTime, reply);
        }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:18,代码来源:LogicalPathObjectNode.cs

示例15: Recv

 public override void Recv(Packet pkg)
 {
     if (pkg.PrevType != NodeType.READER)
     {
         Debug.Assert(false, "Wrong packet src");
     }
     Node node = global.readers[pkg.Prev];
     if (Utility.Distance(this, (MobileNode)node) > Global.getInstance().nodeMaxDist)
     {
         Console.WriteLine("{0:F4} [{1}] {2}{3} Drop from {4}{5} out of space", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.PrevType, pkg.Prev);
         return;
     }
     switch (pkg.Type)
     {
         case PacketType.LANDMARK:
             Console.WriteLine("{0:F4} [{1}] {2}{3} recv from {4}{5}", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.PrevType, pkg.Prev);
             SetCurrentLandmarkLocation(pkg);
             break;
         case PacketType.DATA_AVAIL:
             Console.WriteLine("{0:F4} [{1}] {2}{3} recv from {4}{5}", scheduler.currentTime, pkg.Type, this.type, this.Id, pkg.PrevType, pkg.Prev);
             UpdateLocation(pkg);
             List<Packet> removeList = new List<Packet>();
             foreach (Packet p in this.cachePackets)
             {
                 if (this.cachePackets.Contains(pkg) && TrySendData(p))
                 {
                     this.lastNearReader = this.global.readers[pkg.Src];
                     this.lastNearReaderTime = scheduler.currentTime;
                     removeList.Add(p);
                 }
                 else if (!this.cachePackets.Contains(pkg))
                     this.cachePackets.Add(pkg);
             }
             foreach (Packet p in removeList)
                 this.cachePackets.Remove(p);
             break;
         default:
             break;
     }
     return;
 }
开发者ID:marvelliu,项目名称:IOTResearch,代码行数:41,代码来源:ObjectNode.cs


注:本文中的AdHocBaseApp.Packet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。