/// <summary> /// Checks if the given <paramref name="packet"/> /// can be used as the <see cref="CurrentPacket"/>. /// </summary> /// <param name="packet">Packet to check.</param> /// <returns>True if the <paramref name="packet"/> can /// be used, false if not.</returns> private bool CanAcceptPacket(Packet packet) { if (CurrentPacket == null) { return(packet.Cargo <= MaxPacketSize); } else if (UpgradeContainer.ContainsUpdateOfType <CombinePacketUpgrade>()) { return(packet.Cargo + CurrentPacket.Cargo <= MaxPacketSize); } else { return(false); } }
/// <summary> /// Receives data from input ports /// and sends data to output ports. /// </summary> public void Update() { if (CurrentPowerState == PowerState.Off) { return; } foreach (var port in _ports) { if (port.CurrentIOMode == IOMode.Input) { if (port.ReceiveBuffer != null) { if (CanAcceptPacket((Packet)port.ReceiveBuffer)) { if (UpgradeContainer.ContainsUpdateOfType <CombinePacketUpgrade>()) { CurrentPacket = CurrentPacket.Combine((Packet)port.CollectReceivedData()); } else { CurrentPacket = (Packet)port.CollectReceivedData(); } } } } else if (port.CurrentIOMode == IOMode.Output) { if (CurrentPacket != null) { if (port.Send(CurrentPacket)) { CurrentPacket = null; } } } } }