using System; using System.IO; using Microsoft.VisualStudio.TestTools.UnitTesting; using CPF; using CPF.FileTransfer; using CPF.PosixClient; using System.Text; using Microsoft.SPOT; using System.Threading; namespace CPFUnitTests { [TestClass] public class UnitTestIridiumRUDICS { /// /// Test zmodem send using the bluetooth serial port, but plug it into a linux tty login. /// if no login is provided, the attempt should fail gracefully. /// [TestMethod] public void TestIridiumDD_BidirectionalTransfer() { Init(); int resp = 0; IridiumPosixSession session = new IridiumPosixSession(); session.Username = "rawa"; session.Password = "New0rleans"; session.LoginPrompt = "TODO"; session.PasswordPrompt = "TODO"; session.CommandPrompt = "$ "; //Connect IModem.SelectBearerServiceType(IModem.CallSpeed.BPS9600V110); Thread.Sleep(1000); // enough time for the cbst message to come in CPF.Program.processStructQ(); byte[] baRUDICSnumber = Encoding.UTF8.GetBytes("T00881600005170"); Debug.Print("Dialing"); resp = session.Connect(baRUDICSnumber); if (resp < 0) goto done; goto done; //Login resp = session.Login(); if (resp < 0) goto done; //Delete File if its there already session.SendCommand("rm graph.pdf\r"); //Send File resp = session.ZModemSendTransaction("\\SD\\graph.pdf"); if (resp < 0) goto done; //Receive File //Delete Local File try { if (File.Exists("\\SD\\manifest.txt")) File.Delete("\\SD\\manifest.txt"); } catch { goto done; } resp = session.CheckForPrompt(); if (resp < 0) goto done; resp = session.ZModemReceiveTransaction("~/manifest.txt", "\\SD\\"); if (resp < 0) goto done; //Logout // resp = session.Logout(); done: //Shut down the session. session.Disconnect(); // Hang up the call bool bRUDICSThreadRunning = true; bool bEscapeReceived = false; int iAttempts = 0; while (bRUDICSThreadRunning && iAttempts < 10) { CPF.Program.processStructQ(); if (!bEscapeReceived) resp = IModem.waitForResponse(IModem.commands.escapeSeq); else resp = IModem.waitForResponse(IModem.commands.ath0); if (resp == 0) { Thread.Sleep(100); continue; } else if (resp == 1) { Debug.Print("Response from IModem"); bRUDICSThreadRunning = false; if (!bEscapeReceived) bEscapeReceived = true; else bRUDICSThreadRunning = false; } else { Debug.Print("No Reponse from IModem"); bEscapeReceived = true; //this will automatically alternate which messsage is sent. Sometimes the connection is dropp and the +++ doesn't return an OK iAttempts++; } } if (iAttempts == 10) Assert.Fail(); } static bool runonce = false; public void Init() { if (!runonce) { runonce = true; Debug.Print("Initializing Iridium Modem"); IModem.init(); } } } }