// UNCLASSIFIED /*------------------------------------------------------------------------- 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. -------------------------------------------------------------------------*/ using System; using System.Runtime.InteropServices; namespace FpgaMeasurementInstrumentsLib { /// /// The header for all command messages /// internal class FPGACmdMessageHeader { #region PrivateClassMembers private const int m_HEADER_SIZE = 1; private byte m_headerCmd; #endregion #region PublicFunctions /// /// Copy constructor /// /// The header to copy public FPGACmdMessageHeader(FPGACmdMessageHeader header) { try { m_headerCmd = header.m_headerCmd; } catch (Exception) { throw; } } /// /// Constructor for when receiving data. /// Use this constructor and then parse to populate it /// public FPGACmdMessageHeader() { try { m_headerCmd = 0; } catch (Exception) { throw; } } /// /// Constructor for sending /// /// the type of the message /// The page to read or write to public FPGACmdMessageHeader(FPGACmdMsgIds commandType, FPGACmdMessage.Page page) { try { m_headerCmd = (byte)((byte)commandType | (byte)page); } catch (Exception) { throw; } } /// /// Encode the header into a byte array for sending /// /// The buffer to put the message items public void Format(IntPtr pData) { try { Marshal.StructureToPtr(m_headerCmd, pData, true); } catch (Exception) { throw; } } /// /// getter for the number of bytes in the header /// /// The header length in bytes public uint GetHeaderLength() { try { return m_HEADER_SIZE; } catch (Exception) { throw; } } /// /// getter for the message id /// /// The message id public FPGACmdMsgIds GetMessageId() { byte temp = (byte)(m_headerCmd >> 4); return (FPGACmdMsgIds)temp; } /// /// Takes an array of bytes and populates the header object /// /// The header in byte form public void Parse(IntPtr pData) { try { m_headerCmd = System.Runtime.InteropServices.Marshal.ReadByte(pData, 0); } catch (Exception) { throw; } } /// /// Creates a string version of the header members /// /// A string containning the header data public override string ToString() { string msg = "Header Data:\r\n"; msg += "Command: " + m_headerCmd.ToString("X") + "\r\n"; return msg; } #endregion } }