public void OnNext(ISpiReportTxStatusFrom value) { int key = value.SpiNum; ObserverTxStatusPoco newRemaining = UpdateTXBufferState(key, value.BytesRemaining, 0, 0); LOG.Debug("Device:" + key + " BufferDepth:" + newRemaining); }
/// <summary> /// Sent by IOIO. Tells us how much buffer space is left. /// </summary> /// <param name="value"></param> public void OnNext(II2cReportTxStatusFrom value) { int key = value.I2cNum; ObserverTxStatusPoco newRemaining = UpdateTXBufferState(key, value.BytesRemaining, 0, 0); LOG.Debug("Device:" + key + " remaining after II2cReportTxStatusFrom:" + newRemaining); }
/// <summary> /// received when we are about to send data /// </summary> /// <param name="value"></param> public void OnNext(ITwiMasterSendDataCommand value) { int key = value.TwiDef.TwiNum; // wait until we know there is room on the remote side int bytesBeforeAction = GetTXBufferState(key); while (bytesBeforeAction < value.PayloadSize()) { LOG.Debug("waiting:" + bytesBeforeAction); System.Threading.Thread.Sleep(5); bytesBeforeAction = GetTXBufferState(key); } ObserverTxStatusPoco newRemaining = UpdateTXBufferState( key, -value.PayloadSize(), value.Data.Length, 0); LOG.Debug("Device:" + key + " remaining after ITwiMasterSendDataCommand:" + newRemaining); }
/// <summary> /// sets the passed in bytes to the current number of bytes /// </summary> /// <param name="key">bus unit identifier, uart num, Twi bus num...</param> /// <param name="numBytesRemaining">current buffer size</param> /// <returns>available buffer space. should be same as numBytesRemaining</returns> internal ObserverTxStatusPoco SetTXBufferState(int key, int numBytesRemaining) { // make sure we always have a key with an initial value. Ignore success/fail code // this used to be in a conditional block. TryAdd fails if key exists BufferDepth_.TryAdd(key, new ObserverTxStatusPoco()); // update requires the old value ObserverTxStatusPoco oldRemaining; bool gotValue = BufferDepth_.TryGetValue(key, out oldRemaining); ObserverTxStatusPoco newRemaining = new ObserverTxStatusPoco( numBytesRemaining, oldRemaining.NumSent, oldRemaining.NumReceived); // this could fail if we have multiple threads manipulating the map and oldRemaining has changed // we should RETRY if we fail bool success = BufferDepth_.TryUpdate(key, newRemaining, oldRemaining); if (!success) { LOG.Info("Failed set: " + newRemaining + "->" + oldRemaining); } return(newRemaining); }