private void WaitForCommandResponse() { try { mClient.Client.ReceiveTimeout = 10000; // ms timeout int read = mClient.Client.Receive(mHeaderData, 8, SocketFlags.None); if (read > 0) { // Data received, or connection closed int dataLength = BitConverter.ToInt32(mHeaderData, 4); byte[] data = new byte[dataLength]; mClient.Client.Receive(data, dataLength, SocketFlags.None); mCommandResponse = JsonHelper.ToObject <ATCommandResponse>(data); Log("Received command " + mCommandResponse.TestCommand); } else { Log("Received zero bytes from the TestServer."); } } catch (Exception ex) { Log("No data received for CommandResponse: " + ex.Message); } }
private void HandleGetCommand(int dataLength) { byte[] data = ReadBuffer(dataLength); ATCommandRequest request = JsonHelper.ToObject <ATCommandRequest>(data); try { var command = mVMInstance.HandleGetCommand(request); if (command == null) { // no need to respond } else { var item = command.Item1; ATCommandResponse response = new ATCommandResponse() { TestSuiteID = item.TestSuiteID, TestJobID = item.TestJobID, TestCommandID = item.TestCommandID, TestCommand = item.TestCommandString, TimeoutMinutes = item.TimeoutMinutes, TestPackageDirectory = item.TestPackageDirectory, TestSuiteDirectory = item.TestSuiteDirectory, Version = item.Version, LicenseKey = item.LicenseKey, DownloadLink = item.DownloadLink, Snapshot = command.Item2, MaxExecutionOrder = command.Item1.MaxExecutionOrder, ExecutionOrder = command.Item1.ExecutionOrder, UserName = command.Item1.UserName, RunCount = command.Item1.RunCount }; data = JsonHelper.ToByteStream <ATCommandResponse>(response); SendData(AutomationTestMessageID.GetCommandResponse, data); } } catch (Exception ex) { Log("Exception: " + ex); } }
// This method cleans up the TestPackage directory after a test is done private void Cleanup() { mCommandResponse = null; mCommandResult = true; mCommandResultString = string.Empty; SafeExecute(() => { File.Delete(Path.Combine(mTargetDirectory, Definitions.mStdOut)); }); SafeExecute(() => { File.Delete(Path.Combine(mTargetDirectory, Definitions.mErrLog)); }); // Remove dump files if (Directory.Exists(mProgramDataDirDirectory)) { string[] dumpFiles = Directory.GetFiles(mProgramDataDirDirectory, "*.dmp"); foreach (var dumpFile in dumpFiles) { Log("Deleting dump file " + dumpFile); SafeExecute(() => { File.Delete(dumpFile); }); } } }
/// <summary> /// Performs a software reset on this XBee device and blocks until the process is /// completed. /// </summary> /// <exception cref="InterfaceNotOpenException">If this device connection is not open.</exception> /// <exception cref="XBeeException">If there is any other XBee related error.</exception> public override void Reset() { // Check connection. if (!ConnectionInterface.IsOpen) { throw new InterfaceNotOpenException(); } logger.InfoFormat(ToString() + "Resetting the remote module ({0})...", XBee64BitAddr); ATCommandResponse response = null; try { response = SendATCommand(new ATCommand("FR")); } catch (IOException e) { throw new XBeeException("Error writing in the communication interface.", e); } catch (Exceptions.TimeoutException e) { // Remote 802.15.4 devices do not respond to the AT command. if (localXBeeDevice.XBeeProtocol == XBeeProtocol.RAW_802_15_4) { return; } else { throw e; } } // Check if AT Command response is valid. CheckATCommandResponseIsValid(response); }