protected override void _UpdateState(Command[] outputStates) { Stopwatch stopWatch = Stopwatch.StartNew(); var channelValues = outputStates.ToChannelValuesAsBytes(); this._eventCnt++; foreach (var uE in this._universeTable) { if (uE.Active) { if (this._eventRepeatCount > 0) { if (uE.EventRepeatCount-- > 0) { if (E131Packet.CompareSlots(uE.PhyBuffer, channelValues, uE.Start, uE.Size)) { continue; } } } E131Packet.CopySeqNumSlots(uE.PhyBuffer, channelValues, uE.Start, uE.Size, this._seqNum++); uE.Socket.SendTo(uE.PhyBuffer, uE.DestIpEndPoint); uE.EventRepeatCount = this._eventRepeatCount; uE.PktCount++; uE.SlotCount += uE.Size; } } stopWatch.Stop(); this._totalTicks += stopWatch.ElapsedTicks; }
public override void UpdateState(int chainIndex, ICommand[] outputStates) { _updateStateStopWatch.Start(); //Make sure the setup form is closed & the plugin has started if (isSetupOpen || !running) { return; } if (_data.Universes == null || _data.Universes.Count == 0) { return; } if (channelValues == null || channelValues.Length != outputStates.Length) { channelValues = new byte[outputStates.Length]; } for (int index = 0; index < outputStates.Length; index++) { if (outputStates[index] is _8BitCommand command) { channelValues[index] = command.CommandValue; } else { // State reset channelValues[index] = 0; } } _eventCnt++; foreach (var uE in _data.Universes) { //Not sure why phybuf can be null, but the plugin will crash after being reconfigured otherwise. if (uE.PhyBuffer == null) { continue; } //Check if the universe is active and inside a valid channel range if (!uE.Active || uE.Start >= OutputCount || !running) { continue; } //Check the universe size boundary. int universeSize; if ((uE.Start + uE.Size) > OutputCount) { universeSize = OutputCount - uE.Start; } else { universeSize = uE.Size; } // Reduce duplicate packets... // -the data. counts are the targets // -the uE. counts are how many have happened // do we want to suppress this one? compare to last frame sent bool sendit = true; bool issame = _data.EventRepeatCount > 0 && E131Packet.CompareSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize); if (issame) { // we allow the first event repeat count dups if (_data.EventRepeatCount > 0 && ++uE.EventRepeatCount >= _data.EventRepeatCount) { sendit = false; // we want to suppress, but should we force it anyway? if (_data.EventSuppressCount > 0 && ++uE.EventSuppressCount >= _data.EventSuppressCount) { sendit = true; uE.EventSuppressCount = 0; } } } else { // it's different so will go... clear counters // hopefully this happens within the 7.7 months it will take them to overflow :-) uE.EventRepeatCount = 0; uE.EventSuppressCount = 0; } if (sendit) { //SeqNumbers are per universe so that they can run independently E131Packet.CopySeqNumSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize, uE.seqNum++); uE.Socket.SendTo(uE.PhyBuffer, uE.DestIpEndPoint); uE.PktCount++; uE.SlotCount += uE.Size; } } _updateStateStopWatch.Stop(); this._totalTicks += _updateStateStopWatch.ElapsedTicks; }
public void UpdateState(int chainIndex, byte[] channelValues) { Stopwatch stopWatch = Stopwatch.StartNew(); //Make sure the setup form is closed & the plugin has started if (isSetupOpen && hasStarted) { return; } DateTime lastUpdate; if (channelValues.Where(w => w == 0).Count() == channelValues.Length) { if (outputStateDictionary.TryGetValue(chainIndex, out lastUpdate)) { return; } else { outputStateDictionary[chainIndex] = DateTime.Now; } } else { outputStateDictionary.TryRemove(chainIndex, out lastUpdate); } int universeSize = 0; this._eventCnt++; if (_data.Universes == null || _data.Universes.Count == 0) { return; } foreach (var uE in _data.Universes) { //Check if the universe is active and inside a valid channel range if (uE.Active && (uE.Start + 1) <= OutputCount) { //Check the universe size boundary. if ((uE.Start + 1 + uE.Size) > OutputCount) { universeSize = OutputCount - uE.Start - 1; } else { universeSize = uE.Size; } //Reduce duplicate packets //SeqNumbers are per universe so that they can run independently if (_data.EventRepeatCount > 0) { if (uE.EventRepeatCount-- > 0) { if (E131Packet.CompareSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize)) { continue; } } } //Not sure why this is needed, but the plugin will crash after being reconfigured otherwise. if (uE.PhyBuffer != null) { E131Packet.CopySeqNumSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize, uE.seqNum++); uE.Socket.SendTo(uE.PhyBuffer, uE.DestIpEndPoint); uE.EventRepeatCount = _data.EventRepeatCount; uE.PktCount++; uE.SlotCount += uE.Size; } } } stopWatch.Stop(); this._totalTicks += stopWatch.ElapsedTicks; }
public void UpdateState(int chainIndex, byte[] channelValues) { Stopwatch stopWatch = Stopwatch.StartNew(); //Make sure the setup form is closed & the plugin has started if (isSetupOpen && hasStarted) { return; } DateTime lastUpdate; // no longer used, but I'm leaving it just in case we need it later... /* * if (channelValues.Where(w => w == 0).Count() == channelValues.Length) * { * if (outputStateDictionary.TryGetValue(chainIndex, out lastUpdate)) * { * if( DateTime.Now - lastUpdate < TimeSpan.FromSeconds(1)) * return; * } * outputStateDictionary[chainIndex] = DateTime.Now; * } * else * { * outputStateDictionary.TryRemove(chainIndex, out lastUpdate); * } */ int universeSize = 0; this._eventCnt++; if (_data.Universes == null || _data.Universes.Count == 0) { return; } foreach (var uE in _data.Universes) { //Not sure why phybuf can be null, but the plugin will crash after being reconfigured otherwise. if (uE.PhyBuffer == null) { continue; } //Check if the universe is active and inside a valid channel range if (!uE.Active || uE.Start >= OutputCount) { continue; } //Check the universe size boundary. if ((uE.Start + uE.Size) > OutputCount) { universeSize = OutputCount - uE.Start; } else { universeSize = uE.Size; } // Reduce duplicate packets... // -the data. counts are the targets // -the uE. counts are how many have happened // do we want to suppress this one? compare to last frame sent bool sendit = true; bool issame = E131Packet.CompareSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize); if (issame) { // we allow the first event repeat count dups if (_data.EventRepeatCount > 0 && ++uE.EventRepeatCount >= _data.EventRepeatCount) { sendit = false; // we want to suppress, but should we force it anyway? if (_data.EventSuppressCount > 0 && ++uE.EventSuppressCount >= _data.EventSuppressCount) { sendit = true; uE.EventSuppressCount = 0; } } } else { // it's different so will go... clear counters // hopefully this happens within the 7.7 months it will take them to overflow :-) uE.EventRepeatCount = 0; uE.EventSuppressCount = 0; } if (sendit) { //SeqNumbers are per universe so that they can run independently E131Packet.CopySeqNumSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize, uE.seqNum++); uE.Socket.SendTo(uE.PhyBuffer, uE.DestIpEndPoint); uE.PktCount++; uE.SlotCount += uE.Size; } } stopWatch.Stop(); this._totalTicks += stopWatch.ElapsedTicks; }
public override void UpdateState(int chainIndex, ICommand[] outputStates) { Stopwatch stopWatch = Stopwatch.StartNew(); //Make sure the setup form is closed & the plugin has started if (isSetupOpen && hasStarted) { return; } var channelValues = outputStates.ToChannelValuesAsBytes(); int universeSize = 0; this._eventCnt++; if (_universeTable == null) { return; } foreach (var uE in this._universeTable) { //Check if the universe is active and inside a valid channel range if (uE.Active && (uE.Start + 1) <= OutputCount) { //Check the universe size boundary. if ((uE.Start + 1 + uE.Size) > OutputCount) { universeSize = OutputCount - uE.Start - 1; } else { universeSize = uE.Size; } //Reduce duplicate packets //SeqNumbers are per universe so that they can run independently if (this._eventRepeatCount > 0) { if (uE.EventRepeatCount-- > 0) { if (E131Packet.CompareSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize)) { continue; } } } //Not sure why this is needed, but the plugin will crash after being reconfigured otherwise. if (uE.PhyBuffer != null) { E131Packet.CopySeqNumSlots(uE.PhyBuffer, channelValues, uE.Start, universeSize, uE.seqNum++); uE.Socket.SendTo(uE.PhyBuffer, uE.DestIpEndPoint); uE.EventRepeatCount = this._eventRepeatCount; uE.PktCount++; uE.SlotCount += uE.Size; } } } stopWatch.Stop(); this._totalTicks += stopWatch.ElapsedTicks; }