public Contracts.SerialDataResponse ReceiveSerialPortData(int portID, string sessionToken)
        {
            Contracts.SerialDataResponse response = new Contracts.SerialDataResponse();
            response.completionCode = Contracts.CompletionCode.Failure;
            this.portId             = portID;

            Tracer.WriteInfo("Received ReceiveSerialPortConsoleData({0})", this.portId);

            // If there is NOT an already existing serial session (indicated by an invalid sessionToken), return failure with appropriate completion code
            if (CompareAndSwapMetadata(ConfigLoaded.InactiveSerialPortSessionToken, ConfigLoaded.InactiveSerialPortSessionToken) == CompletionCode.Success)
            {
                Tracer.WriteError("ReceiveSerialPortData({0}): Receive failed because of no active session.", portID);
                response.completionCode = Contracts.CompletionCode.NoActiveSerialSession;
                return(response);
            }

            // If this bladeid currently holds the serial session, update the timestamp else return failure
            if (this.CompareAndSwapMetadata(sessionToken, sessionToken, DateTime.Now) != CompletionCode.Success)
            {
                response.completionCode = Contracts.CompletionCode.SerialSessionActive;
                return(response);
            }

            SerialPortConsole currConsole = new SerialPortConsole((byte)portId);
            SerialDataPacket  serialData  = new SerialDataPacket();

            serialData = currConsole.receiveSerialData();
            if (serialData.completionCode != CompletionCode.Success)
            {
                // Common-case: lots of timeouts if device do not have any data to send over serial
                if (serialData.completionCode == CompletionCode.Timeout)
                {
                    Tracer.WriteInfo("ReceiveSerialPortData({0}) Timeout in SerialConsolePort.receiveSerialData()", portId);
                    response.completionCode = Contracts.CompletionCode.Timeout;
                    return(response);
                }
                Tracer.WriteError("ReceiveSerialPortData({0}) Unknown Error in SerialConsolePort.receiveSerialData()", portId);
                return(response);
            }
            response.data           = serialData.data;
            response.completionCode = Contracts.CompletionCode.Success;
            return(response);
        }
Exemple #2
0
        internal static Contracts.SerialDataResponse ReceiveBladeSerialData(int bladeId, string sessionToken)
        {
            Contracts.SerialDataResponse response = new Contracts.SerialDataResponse();
            response.completionCode = Contracts.CompletionCode.Failure;
            Tracer.WriteInfo("BladeSerialSessionMetadata.ReceiveBladeSerialData({0})", bladeId);

            // If there is NOT an already existing Blade serial session (indicated by a invalid bladeId and a invalid sessionToken), return failure with appropriate completion code
            if (CompareAndSwapMetadata(ConfigLoaded.InactiveBladePortId, ConfigLoaded.InactiveBladeSerialSessionToken, ConfigLoaded.InactiveBladePortId, ConfigLoaded.InactiveBladeSerialSessionToken) == CompletionCode.Success)
            {
                Tracer.WriteError("ReceiveBladeSerialData({0}): Receive failed because of no active session.", bladeId);
                response.completionCode = Contracts.CompletionCode.NoActiveSerialSession;
                return(response);
            }

            // If this bladeid do not currently hold the serial session, return failure
            if (BladeSerialSessionMetadata.CompareAndSwapMetadata(bladeId, sessionToken, bladeId, sessionToken) != CompletionCode.Success)
            {
                response.completionCode = Contracts.CompletionCode.SerialSessionActive;
                return(response);
            }

            BladeSerialSession currSession = new BladeSerialSession((byte)bladeId);
            SerialDataPacket   serialData  = new SerialDataPacket();

            serialData = currSession.receiveSerialData();
            if (serialData.completionCode != CompletionCode.Success)
            {
                // Common-case: lots of timeouts if device do not have any data to send over serial
                if (serialData.completionCode == CompletionCode.Timeout)
                {
                    Tracer.WriteInfo("BladeSerialSessionMetadata.ReceiveBladeSerialData({0}) Timeout in BladeSerialSession.receiveSerialData()", bladeId);
                    response.completionCode = Contracts.CompletionCode.Timeout;
                    return(response);
                }
                Tracer.WriteError("BladeSerialSessionMetadata.ReceiveBladeSerialData({0}) Error in BladeSerialSession.receiveSerialData()", bladeId);
                return(response);
            }

            response.data           = serialData.data;
            response.completionCode = Contracts.CompletionCode.Success;
            return(response);
        }
        public Contracts.SerialDataResponse ReceiveSerialPortData(int portID, string sessionToken)
        {
            Contracts.SerialDataResponse response = new Contracts.SerialDataResponse();
            response.completionCode = Contracts.CompletionCode.Failure;
            this.portId = portID;

            Tracer.WriteInfo("Received ReceiveSerialPortConsoleData({0})", this.portId);

            // If there is NOT an already existing serial session (indicated by an invalid sessionToken), return failure with appropriate completion code
            if (CompareAndSwapMetadata(ConfigLoaded.InactiveSerialPortSessionToken, ConfigLoaded.InactiveSerialPortSessionToken) == CompletionCode.Success)
            {
                Tracer.WriteError("ReceiveSerialPortData({0}): Receive failed because of no active session.", portID);
                response.completionCode = Contracts.CompletionCode.NoActiveSerialSession;
                return response;
            }

            // If this bladeid currently holds the serial session, update the timestamp else return failure
            if (this.CompareAndSwapMetadata(sessionToken, sessionToken, DateTime.Now) != CompletionCode.Success)
            {
                response.completionCode = Contracts.CompletionCode.SerialSessionActive;
                return response;
            }

            SerialPortConsole currConsole = new SerialPortConsole((byte)portId);
            SerialDataPacket serialData = new SerialDataPacket();
            serialData = currConsole.receiveSerialData();
            if (serialData.completionCode != CompletionCode.Success)
            {
                // Common-case: lots of timeouts if device do not have any data to send over serial
                if (serialData.completionCode == CompletionCode.Timeout)
                {
                    Tracer.WriteInfo("ReceiveSerialPortData({0}) Timeout in SerialConsolePort.receiveSerialData()", portId);
                    response.completionCode = Contracts.CompletionCode.Timeout;
                    return response;
                }
                Tracer.WriteError("ReceiveSerialPortData({0}) Unknown Error in SerialConsolePort.receiveSerialData()", portId);
                return response;
            }
            response.data = serialData.data;
            response.completionCode = Contracts.CompletionCode.Success;
            return response;
        }
Exemple #4
0
        private SerialDataPacket receiveSerialData(byte id)
        {
            // Initialize return packet
            SerialDataPacket returnPacket = new SerialDataPacket();

            returnPacket.completionCode = CompletionCode.UnspecifiedError;
            returnPacket.data           = null;

            try
            {
                // Call device layer below
                SerialConsolePortReceiveResponse serialResponse =
                    (SerialConsolePortReceiveResponse)this.SendReceive(this.SerialPortConsoleDeviceType, translateSerialPortId(this.PortId),
                                                                       new SerialConsolePortReceiveRequest(), typeof(SerialConsolePortReceiveResponse), (byte)PriorityLevel.User);

                // check for completion code
                if (serialResponse.CompletionCode != 0)
                {
                    returnPacket.completionCode = (CompletionCode)serialResponse.CompletionCode;
                }
                else
                {
                    returnPacket.completionCode = CompletionCode.Success;
                    if (serialResponse.ReceiveData == null)
                    {
                        Tracer.WriteWarning("Data is empty in SerialPortConsole.receiveSerialData");
                    }
                    returnPacket.data = serialResponse.ReceiveData;
                }
            }
            catch (System.Exception ex)
            {
                returnPacket.completionCode = CompletionCode.UnspecifiedError;
                returnPacket.data           = null;
                Tracer.WriteError(this.PortId, DeviceType.SerialPortConsole, ex);
            }

            return(returnPacket);
        }
        internal static Contracts.SerialDataResponse ReceiveBladeSerialData(int bladeId, string sessionToken)
        {
            Contracts.SerialDataResponse response = new Contracts.SerialDataResponse();
            response.completionCode = Contracts.CompletionCode.Failure;
            Tracer.WriteInfo("BladeSerialSessionMetadata.ReceiveBladeSerialData({0})", bladeId);

            // If there is NOT an already existing Blade serial session (indicated by a invalid bladeId and a invalid sessionToken), return failure with appropriate completion code
            if (CompareAndSwapMetadata(ConfigLoaded.InactiveBladePortId, ConfigLoaded.InactiveBladeSerialSessionToken, ConfigLoaded.InactiveBladePortId, ConfigLoaded.InactiveBladeSerialSessionToken) == CompletionCode.Success)
            {
                Tracer.WriteError("ReceiveBladeSerialData({0}): Receive failed because of no active session.", bladeId);
                response.completionCode = Contracts.CompletionCode.NoActiveSerialSession;
                return response;
            }

            // If this bladeid do not currently hold the serial session, return failure
            if (BladeSerialSessionMetadata.CompareAndSwapMetadata(bladeId, sessionToken, bladeId, sessionToken) != CompletionCode.Success)
            {
                response.completionCode = Contracts.CompletionCode.SerialSessionActive;
                return response;
            }

            BladeSerialSession currSession = new BladeSerialSession((byte)bladeId);
            SerialDataPacket serialData = new SerialDataPacket();
            serialData = currSession.receiveSerialData();
            if (serialData.completionCode != CompletionCode.Success)
            {
                // Common-case: lots of timeouts if device do not have any data to send over serial
                if (serialData.completionCode == CompletionCode.Timeout)
                {
                    Tracer.WriteInfo("BladeSerialSessionMetadata.ReceiveBladeSerialData({0}) Timeout in BladeSerialSession.receiveSerialData()", bladeId);
                    response.completionCode = Contracts.CompletionCode.Timeout;
                    return response;
                }
                Tracer.WriteError("BladeSerialSessionMetadata.ReceiveBladeSerialData({0}) Error in BladeSerialSession.receiveSerialData()", bladeId);
                return response;
            }

            response.data = serialData.data;
            response.completionCode = Contracts.CompletionCode.Success;
            return response;
        }
        private SerialDataPacket receiveSerialData(byte id)
        {
            // Initialize return packet 
            SerialDataPacket returnPacket = new SerialDataPacket();
            returnPacket.completionCode = CompletionCode.UnspecifiedError;
            returnPacket.data = null;

            try
            {
                // Call device layer below
                SerialConsolePortReceiveResponse serialResponse =
                    (SerialConsolePortReceiveResponse)this.SendReceive(this.SerialPortConsoleDeviceType, translateSerialPortId(this.PortId),
                    new SerialConsolePortReceiveRequest(), typeof(SerialConsolePortReceiveResponse), (byte)PriorityLevel.User);

                // check for completion code 
                if (serialResponse.CompletionCode != 0)
                {
                    returnPacket.completionCode = (CompletionCode)serialResponse.CompletionCode;
                }
                else
                {
                    returnPacket.completionCode = CompletionCode.Success;
                    if (serialResponse.ReceiveData == null)
                    {
                        Tracer.WriteWarning("Data is empty in SerialPortConsole.receiveSerialData");
                    }
                    returnPacket.data = serialResponse.ReceiveData;
                }
            }
            catch (System.Exception ex)
            {
                returnPacket.completionCode = CompletionCode.UnspecifiedError;
                returnPacket.data = null;
                Tracer.WriteError(ex);
            }

            return returnPacket;
        }