public void UartTest_LoopbackOut31In32() { //// TODO should use the hardware from the captured connection IResourceManager rManager = new ResourceManager(Hardware.IOIO0003); IOIOConnection ourConn = this.CreateGoodSerialConnection(); this.CreateCaptureLogHandlerSet(); ObserverTxStatusUart bufferObserver = new ObserverTxStatusUart(); this.HandlerObservable_.Subscribe(bufferObserver); // add our own handler so we don't have to grovel aroudn in there IOIOProtocolIncoming fooIn = new IOIOProtocolIncoming(ourConn.GetInputStream(), HandlerObservable_); IOIOProtocolOutgoing fooOut = new IOIOProtocolOutgoing(ourConn.GetOutputStream()); System.Threading.Thread.Sleep(100); // wait for us to get the hardware ids UartConfigureCommand commandCreate = new UartConfigureCommand( new DigitalInputSpec(32), new DigitalOutputSpec(31), 38400, UartParity.NONE, UartStopBits.ONE); commandCreate.Alloc(rManager); commandCreate.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(10); string helloWorld = "Hello World"; byte[] helloWorldBytes = System.Text.Encoding.ASCII.GetBytes(helloWorld); LOG.Debug("Sending Hello World"); UartSendDataCommand commandSend = new UartSendDataCommand(commandCreate.UartDef, helloWorldBytes); commandSend.Alloc(rManager); commandSend.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(50); LOG.Debug("Closing Uart"); UartCloseCommand commandClose = new UartCloseCommand(commandCreate.UartDef); commandClose.Alloc(rManager); commandClose.ExecuteMessage(fooOut); System.Threading.Thread.Sleep(50); // IUartFrom is the parent interface for all messages coming from the UARt Assert.AreEqual(1 + 1 + helloWorldBytes.Count() + 1, this.CapturedSingleQueueAllType_.OfType <IUartFrom>().Count()); Assert.AreEqual(1, this.CapturedSingleQueueAllType_.OfType <IUartOpenFrom>().Count(), "didn't get IUartOpenFrom"); Assert.AreEqual(1, this.CapturedSingleQueueAllType_.OfType <IUartReportTxStatusFrom>().Count(), "didn't get IUartReportTXStatusFrom"); IEnumerable <IUartDataFrom> readValues = this.CapturedSingleQueueAllType_.OfType <IUartDataFrom>(); Assert.AreEqual(helloWorldBytes.Count(), readValues.Count(), "Didn't find the number of expected IUartFrom: " + readValues.Count()); // logging the messages with any other string doesn't show the messages themselves !? LOG.Debug("Captured " + +this.CapturedSingleQueueAllType_.Count()); LOG.Debug(this.CapturedSingleQueueAllType_.GetEnumerator()); Assert.AreEqual(1, this.CapturedSingleQueueAllType_.OfType <IUartCloseFrom>().Count()); // should verify close command in the resource }
public void UartTest_BigBufferOut31In32() { //// TODO should use the hardware from the captured connection IOIOConnection ourConn = this.CreateGoodSerialConnection(false); this.CreateCaptureLogHandlerSet(); // MUST use IOIOImpl to get "send" notifications for buffer management // add our own handler so we don't have to grovel around in there IOIO ourImpl = CreateIOIOImplAndConnect(ourConn, new List <IObserverIOIO>() { this.CapturedConnectionState_, this.CapturedSingleQueueAllType_, this.CapturedLogs_ }); LOG.Debug("Setup Complete"); System.Threading.Thread.Sleep(100); // wait for us to get the hardware ids UartConfigureCommand commandCreate = new UartConfigureCommand( new DigitalInputSpec(32), new DigitalOutputSpec(31), 19200, UartParity.NONE, UartStopBits.ONE); ourImpl.PostMessage(commandCreate); System.Threading.Thread.Sleep(10); // create byte buffer // only 64 can be sent in a single message StringBuilder builder = new StringBuilder(); int numBlock10 = 3; for (int i = 0; i < numBlock10; i++) { builder.Append("0123456789"); } string helloWorld = builder.ToString(); // should overrun the internal buffer to make sure observer flow control is working // buffer is 256 so cnt=4 means get one buffer update : cnt=7 means more than one full buffer char hack = 'A'; int numBufferSend = 10; for (int i = 0; i < numBufferSend; i++) { byte[] helloWorldBytes = System.Text.Encoding.ASCII.GetBytes(helloWorld + hack); LOG.Debug("Sending long string " + i + ":" + helloWorldBytes.Length); UartSendDataCommand commandSend = new UartSendDataCommand(commandCreate.UartDef, helloWorldBytes); ourImpl.PostMessage(commandSend); hack++; System.Threading.Thread.Sleep(50); } // message posts will possibly block if IOIO UART ran out of buffer space // but it may still run before all data sent from IOIO buffers to the UART pins // really node for this since we wait for UART close System.Threading.Thread.Sleep(300); LOG.Debug("Closing Uart"); UartCloseCommand commandClose = new UartCloseCommand(commandCreate.UartDef); ourImpl.PostMessage(commandClose); // either sleep for some time //System.Threading.Thread.Sleep(5000); // or wait until we get the close ack int maxTimeMsec = 5000; while (this.CapturedSingleQueueAllType_.OfType <IUartCloseFrom>().Count() == 0) { Assert.IsTrue(maxTimeMsec > 0, "Did not receive IUartCloseFrom in the expected amount of time"); System.Threading.Thread.Sleep(10); maxTimeMsec -= 10; } Assert.AreEqual(1, this.CapturedSingleQueueAllType_.OfType <IUartOpenFrom>().Count(), "didn't get IUartOpenFrom"); // we should have counted bytes, count is first buffer size + each update at the 130 mark int expectedNumberTxMessages = 1 + ((numBufferSend * numBlock10 * 10) / 130); Assert.AreEqual(expectedNumberTxMessages, this.CapturedSingleQueueAllType_.OfType <IUartReportTxStatusFrom>().Count(), "didn't get IUartReportTXStatusFrom"); int expectedDataPacketsReceived = (numBlock10 * 10 + 1) * numBufferSend; IEnumerable <IUartDataFrom> readValues = this.CapturedSingleQueueAllType_.OfType <IUartDataFrom>(); Assert.AreEqual(expectedDataPacketsReceived, readValues.Count(), "Didn't find the number of expected IUartFrom: " + readValues.Count()); // logging the messages with any other string doesn't show the messages themselves !? LOG.Debug("Captured " + +this.CapturedSingleQueueAllType_.Count()); LOG.Debug(this.CapturedSingleQueueAllType_.GetEnumerator()); Assert.AreEqual(1, this.CapturedSingleQueueAllType_.OfType <IUartCloseFrom>().Count()); // should verify close command in the Resource manager // We get back one packet for each character sent that was looped back + uart open, TX buffer status uart close int expectedNumDataPackets = expectedDataPacketsReceived; Assert.AreEqual(1 + expectedNumberTxMessages + expectedNumDataPackets + 1, this.CapturedSingleQueueAllType_.OfType <IUartFrom>().Count()); }