Esempio n. 1
0
        public bool Send(EnOceanPacket packet, IReceiveHandler handler, int retries = 3, int timeout = 1000)
        {
            var rawPacket = packet.BuildPacket();
            var pl        = new PacketListener(handler);

            PacketListeners.Add(pl);
AGAIN:
            // TESTING
            SendFrame(rawPacket);
            pl.waitHandle.WaitOne(timeout);
            if (pl.succeeded)
            {
                PacketListeners.Remove(pl);
                return(true);
            }
            else
            {
                if (retries-- > 0)
                {
                    goto AGAIN;
                }
                PacketListeners.Remove(pl);
                return(false);
                // Packet not what he wanted.. wait for next!
            }
        }
Esempio n. 2
0
 public PacketListener(IReceiveHandler pHandler)
 {
     this.handler = pHandler;
     succeeded    = false;
     packet       = null;
     waitHandle   = new EventWaitHandle(false, EventResetMode.AutoReset);
 }
        public void AssertHandleOrder(IReceiveHandler handler, params Type[] types)
        {
            var currentHandler = (IChainedReceiveHandler)handler;

            foreach (var type in types)
            {
                currentHandler.ShouldBeType(type);
                currentHandler = currentHandler.NextHandler;
            }
        }
Esempio n. 4
0
 public void SendReceiveRequest(byte[] sendData, int receiveCnt, IReceiveHandler receiveHandler)
 {
     if (receiveCnt > 0 && receiveHandler != null)
     {
         lock (lockThis_)
         {
             requests_.Enqueue(new ReceiveRequest(sendData, receiveCnt, receiveHandler));
         }
         evt_.Set(); // thread, wake up
     }
 }
 public PacketListener(IReceiveHandler pHandler)
 {
     this.handler = pHandler;
     succeeded = false;
     packet = null;
     waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
 }
 public bool Send(EnOceanPacket packet, IReceiveHandler handler, int retries = 3, int timeout = 1000)
 {
     var rawPacket = packet.BuildPacket();
     var pl = new PacketListener(handler);
     PacketListeners.Add(pl);
     AGAIN:
     // TESTING
     SendFrame(rawPacket);
     pl.waitHandle.WaitOne(timeout);
     if (pl.succeeded)
     {
         PacketListeners.Remove(pl);
         return true;
     }
     else
     {
         if (retries-- > 0)
             goto AGAIN;
         PacketListeners.Remove(pl);
         return false;
         // Packet not what he wanted.. wait for next!
     }
 }
Esempio n. 7
0
 public ReceiveRequest(byte[] sendData, int cnt, IReceiveHandler h)
 {
     sendData_ = sendData;
     cnt_      = cnt;
     handler_  = h;
 }