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. /// /// private static int utcount; [TestMethod] public void TestIridiumDD_BidirectionalTransfer() { Init(); int resp = 0; bool carrier = false; IridiumPosixSession session = new IridiumPosixSession(); session.Username = "cpfloat"; session.Password = "mbari!@!123"; session.LoginPrompt = "login:"; session.PasswordPrompt = "Password:"; session.CommandPrompt = "$ "; utcount++; //Connect IModem.SelectBearerServiceType(IModem.CallSpeed.BPS9600V110); Thread.Sleep(1000); // enough time for the cbst message to come in CPF.Program.processStructQ(); IModem.sendCSQ(); Thread.Sleep(10000); CPF.Program.processStructQ(); byte[] baRUDICSnumber = Encoding.UTF8.GetBytes("T00881600005391"); //byte[] baRUDICSnumber = Encoding.UTF8.GetBytes("+18317751862"); Debug.Print("Dialing"); resp = session.Connect(baRUDICSnumber); if (resp < 0) goto failed; carrier = true; //Login resp = session.Login(); if (resp == (int)PosixSession.ERROR.NOCARRIER) { carrier = false; goto failed; } //Delete File if its there already //session.SendCommand("rm graph.pdf\r"); //Send a Message to Broadcast StringBuilder utmsg = new StringBuilder("I am UNIT TEST #: "); utmsg.Append(utcount.ToString()); session.Broadcast(utmsg.ToString()); goto done; //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("/home/rawa/manifest.txt", "\\SD\\"); if (resp < 0) goto done; done: //Logout session.Logout(); failed: //Shut down the session. session.Disconnect(); // Hang up the call bool bRUDICSThreadRunning = true; if (!carrier) return; 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.chup); if (resp == 0) { Thread.Sleep(10); 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(); for (int i = 0; i < 6; i++) { Debug.Print("Cleanup: "+i.ToString()); CPF.Program.processStructQ(); Thread.Sleep(1000); } } static bool runonce = false; public void Init() { if (!runonce) { runonce = true; Debug.Print("Initializing Iridium Modem"); IModem.init(); } } } }