public bool SetSpectraCyberIFGain(double ifGain)
        {
            if (ifGain < 10.0 || ifGain > 25.75)
            {
                logger.Info(Utilities.GetTimeStamp() + ": [AbstractSpectraCyberController] ERROR: invalid IF Gain value: " + ifGain);
                return(false);
            }

            double adjustedGain = (ifGain - 10.0) / 0.25;

            string Command = "!A" + IntToHexString(Convert.ToInt32(adjustedGain));

            SpectraCyberRequest Request = new SpectraCyberRequest(
                SpectraCyberCommandTypeEnum.CHANGE_SETTING,
                Command,
                false,
                4
                );

            SpectraCyberResponse Response = new SpectraCyberResponse();

            SendCommand(Request, ref Response);

            configVals.IFGain = ifGain;

            return(Response.RequestSuccessful);
        }
        private bool SetSomeOffsetVoltage(double offset, char identifier)
        {
            if ((offset < 0.0) || (offset > 4.095))
            {
                logger.Info(Utilities.GetTimeStamp() + ": [AbstractSpectraCyberController] ERROR: input voltage outside of range [0, 4.095]");
                return(false);
            }

            configVals.offsetVoltage = offset;

            int    Magnitude = (int)(offset * 1000);
            string Command   = "!" + identifier + IntToHexString(Magnitude);

            SpectraCyberRequest Request = new SpectraCyberRequest(
                SpectraCyberCommandTypeEnum.CHANGE_SETTING,
                Command,
                false,
                4
                );

            SpectraCyberResponse Response = new SpectraCyberResponse();

            SendCommand(Request, ref Response);

            return(Response.RequestSuccessful);
        }
        private bool SetSomeIntegrationTime(SpectraCyberIntegrationTimeEnum time, char identifier)
        {
            string Command = "!" + identifier + "00" + SpectraCyberIntegrationTimeEnumHelper.GetValue(time);

            SpectraCyberRequest Request = new SpectraCyberRequest(
                SpectraCyberCommandTypeEnum.CHANGE_SETTING,
                Command,
                false,
                4
                );

            SpectraCyberResponse Response = new SpectraCyberResponse();

            SendCommand(Request, ref Response);

            return(Response.RequestSuccessful);
        }
        public void TestCommunication()
        {
            SpectraCyberRequest Request = new SpectraCyberRequest(
                SpectraCyberCommandTypeEnum.RESET,
                "!R000",
                true,
                4
                );

            SpectraCyberResponse Response = new SpectraCyberResponse();

            SendCommand(Request, ref Response);

            string ResponseData = Response.SerialIdentifier + Response.DecimalData.ToString("X3");

            logger.Info(Utilities.GetTimeStamp() + ": [AbstractSpectraCyberController] Attempted RESET with command \"!R000\", heard back: " + ResponseData);
        }
        public bool SetSpectraCyberDCGain(int dcgain, string identifier)
        {
            string Command = "!" + identifier + IntToHexString(dcgain);

            SpectraCyberRequest Request = new SpectraCyberRequest(
                SpectraCyberCommandTypeEnum.CHANGE_SETTING,
                Command,
                false,
                4
                );

            SpectraCyberResponse Response = new SpectraCyberResponse();

            SendCommand(Request, ref Response);

            return(Response.RequestSuccessful);
        }
Ejemplo n.º 6
0
        // Submit a command and return a response
        protected override void SendCommand(SpectraCyberRequest request, ref SpectraCyberResponse response)
        {
            // Here is where the request would be sent through serial if this were a physical device

            // Assume it is successfully sent
            response.RequestSuccessful = true;

            // Give the simulated SpectraCyber some time to process the command
            Thread.Sleep(AbstractSpectraCyberConstants.WAIT_TIME_MS);

            // Check for any significant cases
            switch (request.CommandType)
            {
            // Termination, safely end communication
            case SpectraCyberCommandTypeEnum.TERMINATE:
                BringDown();
                break;

                //
                // Do nothing by default
                //
            }

            // If the request expects a reply back, capture the data and attach it to the response
            if (request.WaitForReply)
            {
                // Reponse's data is valid
                response.Valid = true;

                // Set the SerialIdentifier, assuming the correct type of response is heard back
                response.SerialIdentifier = request.ResponseIdentifier;

                // Generate random data
                // TODO: may need to update to more accurately match the data seen from the real spectra cyber, or use a CSV file (issue #409)
                int minIntensityScaled = (int)(AbstractSpectraCyberConstants.SIMULATED_RF_INTENSITY_MINIMUM / AbstractSpectraCyberConstants.SIMULATED_RF_INTENSITY_DISCRETIZATION);
                int maxIntensityScaled = (int)(AbstractSpectraCyberConstants.SIMULATED_RF_INTENSITY_MAXIMUM / AbstractSpectraCyberConstants.SIMULATED_RF_INTENSITY_DISCRETIZATION);
                response.DecimalData = random.Next(minIntensityScaled, maxIntensityScaled + 1);

                // Set the time captured to be as close to the (simulated) read as possible
                response.DateTimeCaptured = DateTime.UtcNow;
            }

            // Do nothing to purge a simulated buffer
        }
        public bool SetFrequency(double frequency)
        {
            string Command = "!F" + IntToHexString(Convert.ToInt32(frequency));

            SpectraCyberRequest Request = new SpectraCyberRequest(
                SpectraCyberCommandTypeEnum.CHANGE_SETTING,
                Command,
                false,
                4
                );

            SpectraCyberResponse Response = new SpectraCyberResponse();

            SendCommand(Request, ref Response);

            configVals.frequency = frequency;
            configVals.bandscan  = -1 * (configVals.frequency / 2);

            return(Response.RequestSuccessful);
        }
 protected abstract void SendCommand(SpectraCyberRequest request, ref SpectraCyberResponse response);
 public AbstractSpectraCyber()
 {
     CurrentModeType            = SpectraCyberModeTypeEnum.UNKNOWN;
     CurrentSpectraCyberRequest = SpectraCyberRequest.GetNewEmpty();
 }
Ejemplo n.º 10
0
 protected override void SendCommand(SpectraCyberRequest request, ref SpectraCyberResponse response)
 {
     // pass
 }
Ejemplo n.º 11
0
 public AbstractSpectraCyber()
 {
     CurrentModeType            = SpectraCyberModeTypeEnum.UNKNOWN;
     CurrentSpectraCyberRequest = SpectraCyberRequest.GetNewEmpty();
     ActiveAppointmentID        = -1;
 }
Ejemplo n.º 12
0
        // Submit a command and return a response
        protected override void SendCommand(SpectraCyberRequest request, ref SpectraCyberResponse response)
        {
            // If the request is empty, don't process
            if (request.IsEmpty())
            {
                return;
            }

            try
            {
                // Attempt to write the command to the serial port
                ((SpectraCyber)SpectraCyber).SerialPort.Write(request.CommandString);
            }
            catch (Exception)
            {
                // Something went wrong, return the response
                SerialCommsFailed = true;
                return;
            }

            // Command was successfully sent through serial communication
            response.RequestSuccessful = true;

            // Give the SpectraCyber some time to process the command
            Thread.Sleep(AbstractSpectraCyberConstants.WAIT_TIME_MS);

            // Check for any significant cases
            switch (request.CommandType)
            {
                // Termination, safely end communication
                case SpectraCyberCommandTypeEnum.TERMINATE:
                    BringDown();
                    break;

                // TODO: implement this case further probably
                case SpectraCyberCommandTypeEnum.SCAN_STOP:
                    break;

                // Purge the serial buffer
                case SpectraCyberCommandTypeEnum.DATA_DISCARD:
                    ((SpectraCyber)SpectraCyber).SerialPort.DiscardInBuffer();
                    break;

                //
                // Do nothing by default
                //
            }

            // If the request expects a reply back, capture the data and attach it to the response
            if (request.WaitForReply)
            {
                // Reponse's data is valid (assuming no exceptions are thrown)
                response.Valid = true;

                try
                {
                    // Create a character array in which to store the buffered characters
                    string hexString;

                    // Read a number of characters in the buffer
                    char[] charInBuffer = new char[AbstractSpectraCyberConstants.BUFFER_SIZE];

                    int length = -1;
                    try
                    {
                        length = ((SpectraCyber)SpectraCyber).SerialPort.Read(charInBuffer, 0, request.CharsToRead);
                    }
                    catch (Exception)
                    {
                        // Something went wrong, return the response
                        SerialCommsFailed = true;
                        return;
                    }

                    // Set the time captured to be as close to the read as possible, in case it's valid
                    response.DateTimeCaptured = DateTime.UtcNow;

                    // Clip the string to the exact number of bytes read
                    if (AbstractSpectraCyberConstants.CLIP_BUFFER_RESPONSE && (length != AbstractSpectraCyberConstants.BUFFER_SIZE))
                    {
                        char[] actual = new char[length];

                        for (int i = 0; i < length; i++)
                        {
                            actual[i] = charInBuffer[i];
                        }

                        hexString = new string(actual);
                    }

                    // Leave the string how it is, with the possibility of trailing chararacters being "0"
                    else
                    {
                        hexString = new string(charInBuffer);
                    }

                    // Set the SerialIdentifier, as heard (but not necessarily expected)
                    response.SerialIdentifier = hexString[0];

                    // Check to see that replyString's first character is what was expected
                    if (response.SerialIdentifier != request.ResponseIdentifier)
                    {
                        throw new Exception();
                    }

                    // Convert the hex string into an int
                    response.DecimalData = HexStringToInt(hexString.Substring(1));
                }
                catch (Exception e)
                {
                    // Something went wrong, the response isn't valid
                    logger.Info("[SpectraCyberController] Failed to receive a response: " + e.ToString());
                    response.Valid = false;
                }
            }

            // Clear the input buffer
            ((SpectraCyber)SpectraCyber).SerialPort.DiscardInBuffer();
        }