// ******************************************************************************************
// **                                                                                       **
// **      RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION                 **
// **      PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS         **
// **      AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT.DISCLOSURE TO                **
// **      UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO          **
// **      RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS              **
// **      CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS         **
// **      OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON        **
// **      COMPANY.                                                                         **
// **                                                                                       **
// **      THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.               **
// **      GOVERNMENT.                                                                      **
// **                                                                                       **
// **      UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.                                   **
// **                                                                                       **
// **      WARNING: THIS DOCUMENT CONTAINS TECHNICAL DATA AND / OR TECHNOLOGY WHOSE         **
// **      EXPORT OR DISCLOSURE TO NON-U.S.PERSONS, WHEREVER LOCATED, IS RESTRICTED         **
// **      BY THE INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R.SECTION        **
// **      120-130) OR THE EXPORT ADMINISTRATION REGULATIONS(EAR) (15 C.F.R.SECTION         **
// **      730-774). THIS DOCUMENT CANNOT BE EXPORTED(E.G., PROVIDED TO A SUPPLIER          **
// **      OUTSIDE OF THE UNITED STATES) OR DISCLOSED TO A NON-U.S.PERSON, WHEREVER         **
// **      LOCATED, UNTIL A FINAL JURISDICTION AND CLASSIFICATION DETERMINATION HAS         **
// **      BEEN COMPLETED AND APPROVED BY RAYTHEON, AND ANY REQUIRED U.S.GOVERNMENT         **
// **      APPROVALS HAVE BEEN OBTAINED. VIOLATIONS ARE SUBJECT TO SEVERE CRIMINAL          **
// **      PENALTIES.                                                                       **
// **                                                                                       **
// **      CAPITAL EQUIPMENT/SOFTWARE: THIS TECHNICAL DATA WAS DEVELOPED OR ACQUIRED        **
// **      EXCLUSIVELY AT CONTRACTOR EXPENSE AND IS INTENDED FOR USE ON MULTIPLE            **
// **      PROJECTS/PROGRAMS.                                                               **
// **                                                                                       **
// *******************************************************************************************

using System;
using System.Threading;
using System.Threading.Tasks;

namespace Raytheon.Instruments
{
   /// <summary>
   /// An interface to any device that you can write and read to/from
   /// </summary>
   public interface ICommAsync : IInstrument
   {
      /// <summary>
      /// Close the communication interface
      /// </summary>
      void Close( );

      /// <summary>
      /// Open the communication interface
      /// </summary>
      void Open( );

      /// <summary>
      /// Set the timeout on a read
      /// </summary>
      /// <param name="timeout"></param>
      void SetReadTimeout( uint timeout );

      /// <summary>
      /// Reads data from a communication device
      /// </summary>
      /// <param name="dataRead"></param>
      /// <param name="token"></param>
      /// <returns>number of bytes read</returns>
      Task<uint> ReadAsync(byte[] dataRead, CancellationToken token = default(CancellationToken));

      /// <summary>
      /// Reads data from a communication device
      /// </summary>
      /// <param name="token"></param>
      /// <returns></returns>
      Task<string> ReadAsync(CancellationToken token = default(CancellationToken));

      /// <summary>
      /// Writes data to a communication device
      /// </summary>
      /// <param name="data"></param>
      /// <param name="numBytesToWrite"></param>
      /// <returns>the number of bytes written</returns>
      Task<uint> WriteAsync(byte[] dataToSend, uint numBytesToWrite, CancellationToken token = default(CancellationToken));

      /// <summary>
      /// Writes data to a communication device
      /// </summary>
      /// <param name="message"></param>
      /// <returns></returns>
      Task WriteAsync(string message, CancellationToken token = default(CancellationToken));

      /// <summary>
      /// Send command and get response
      /// </summary>
      Task<string> SendCommandGetResponseAsync(string message, CancellationToken token = default(CancellationToken), int timeoutInMs = 5000);

      /// <summary>
      /// Send command and get response
      /// </summary>
      Task<byte[]> SendCommandGetResponseAsync(byte[] data, CancellationToken token = default(CancellationToken), int timeoutInMs = 5000);

      /// <summary>
      /// Keep reading asynchronously
      /// </summary>
      /// <param name="cancellationToken"></param>
      /// <param name="dataReceived"></param>
      /// <returns></returns>
      Task KeepReadingAsync( CancellationToken cancellationToken, Action<string> dataReceived );

      /// <summary>
      /// Keep reading asynchronously
      /// </summary>
      Task KeepReadingAsync(CancellationToken cancellationToken, Action<byte[]> dataReceived);
   }
}
