Exemplo n.º 1
0
 // TODO: Double check this once XBeeQueue is implemented
 /// <summary>
 /// Adds a packet to the queue. If the queue is full, the head is removed to make room
 /// </summary>
 /// <param name="packet">The packet to be added</param>
 /// <exception cref="NotImplementedException">Thrown if packet is explicit, since that functionality isn't implemented</exception>
 protected void AddPacketQueue(XBeeAPIPacket packet)
 {
     // Data packets
     if (packet.FrameTypeValue == ApiFrameType.Byte.RECEIVE_PACKET || packet.FrameTypeValue == ApiFrameType.Byte.RX_64 ||
         packet.FrameTypeValue == ApiFrameType.Byte.RX_16)
     {
         // BUG: Race condition in the original python implementation (it has been fixed here). There was
         //      no lock between making room in the queue and adding a new element. If another packet gets
         //      added in between these two operations, the latter will throw an unhandled "XBeeQueueFullException"
         DataXBeeQueue.PutNoWait(packet, true);
     }
     else if (packet.FrameTypeValue == ApiFrameType.Byte.EXPLICIT_RX_INDICATOR)
     {
         ExplicitXBeeQueue.PutNoWait(packet, true);
         if (IsSpecialExplicitPacket((ExplicitRXIndicatorPacket)packet))
         {
             AddPacketQueue(ExplToNoExpl((ExplicitRXIndicatorPacket)packet));
         }
     }
     else if (packet.FrameTypeValue == ApiFrameType.Byte.RX_IPV4)
     {
         IPXBeeQueue.PutNoWait(packet, true);
     }
     else
     {
         XBeeQueue.PutNoWait(packet, true);
     }
 }
Exemplo n.º 2
0
 public PacketListener(SerialPort serialPort, XBeeDevice xbeeDevice, int queueMaxSize = -1)
 {
     foreach (Reader.PacketReceivedHandler handler in xbeeDevice.GetXBeeDeviceCallbacks())
     {
         // Get list of internal callbacks from device, and subscribe them all to PacketReceivedAPI
         PacketReceivedAPI += handler;
     }
     this.xbeeDevice   = xbeeDevice;
     this.comPort      = serialPort;
     this.stop         = true;
     this.queueMaxSize = (queueMaxSize < 0) ? DEFAULT_QUEUE_MAX_SIZE : queueMaxSize;
     XBeeQueue         = new XBeeQueue(this.queueMaxSize);
     DataXBeeQueue     = new XBeeQueue(this.queueMaxSize);
     ExplicitXBeeQueue = new XBeeQueue(this.queueMaxSize);
     IPXBeeQueue       = new XBeeQueue(this.queueMaxSize);
 }