/// <summary>
        /// only needed when controller is in RC mode, sending constant stream of data for monitoring purposes.
        /// when grabbed, controller is queried via m_queryQueue
        /// </summary>
        /// <param name="monStr"></param>
        /// <param name="timestamp"></param>
        private void interpretMonitoringString(string monStr, long timestamp)
        {
            // Tracer.Trace("MON: " + monStr);

            int j = 0;
            for (int i = 1; i < monStr.Length && j < monitorStringValueNames.GetLength(0) ; i += 2)
            {
                string sHexVal = monStr.Substring(i, 2);
                string valueName = monitorStringValueNames[j];

                RQMeasuredValue measuredValue = new RQMeasuredValue();
                bool mustAdd = false;

                if (m_measuredValues.ContainsKey(valueName))
                {
                    measuredValue = m_measuredValues[valueName];
                }
                else
                {
                    measuredValue = new RQMeasuredValue();
                    mustAdd = true;
                }

                lock (measuredValue)
                {
                    measuredValue.timestamp = timestamp;
                    measuredValue.valueName = valueName;
                    measuredValue.stringValue = sHexVal;
                    measuredValue.intValue = Int32.Parse(sHexVal, NumberStyles.HexNumber);
                    switch (monitorStringValueConverters[j])
                    {
                        default:
                            measuredValue.doubleValue = (double)measuredValue.intValue;
                            break;
                        case 1:
                            measuredValue.doubleValue = RQVoltage.convertToMainVoltage(sHexVal);
                            break;
                        case 2:
                            measuredValue.doubleValue = RQVoltage.convertToInternalVoltage(sHexVal);
                            break;
                        case 3:
                            measuredValue.doubleValue = RQTemperature.convertToCelcius(sHexVal);
                            break;
                        case 4:
                            measuredValue.intValue = RQCompressedHex.convertToInt(sHexVal);
                            measuredValue.doubleValue = (double)measuredValue.intValue;
                            break;
                    }
                }

                if (mustAdd)
                {
                    m_measuredValues.Add(valueName, measuredValue);
                }

                // Tracer.Trace(valueName + "=" + sHexVal + "=" + measuredValue.doubleValue);
                j++;
            }
        }
示例#2
0
        internal override void interpretResponse(long timestamp)
        {
            whenReceivedTicks = timestamp;

            checkResponseSanity();

            long ticksElapsed = 0L;
            StringBuilder strb = null;

            if (doTrace)
            {
                ticksElapsed = timestamp - whenSentTicks;
                strb = new StringBuilder();

                for (int i = 0; i < received.Count; i++)
                {
                    strb.Append(received[i]);
                    strb.Append(" ");
                }

                strb.Append(" <==> ");
            }

            bool goodValue = true;

            for (int i=0; i < received.Count-1; i++)
            {
                try
                {
                    string sHexVal = (string)received[i+1];
                    m_intValues[i] = Int32.Parse(sHexVal, NumberStyles.HexNumber);
                    m_doubleValues[i] = convertValue(sHexVal, i);
                    if (doTrace)
                    {
                        strb.Append("   ");
                        strb.Append(m_valueNames[i]);
                        strb.Append("=");
                        strb.Append(String.Format("{0:F}", m_doubleValues[i]).Replace(".00", ""));
                    }
                }
                catch
                {
                    if (doTrace)
                    {
                        goodValue = false;
                        strb.Append(" ***");
                    }
                }
            }

            if (goodValue)
            {
                OnValueReceived();
            }

            if (doTrace)
            {
                Tracer.Trace("interpretResponse: " + received.Count + "   " + String.Format("{0:F1}", ticksElapsed / 10000.0d) + " ms  " + strb.ToString());
            }

            for (int i = 0; i < m_valueNames.GetLength(0); i++)
            {
                RQMeasuredValue measuredValue;
                bool mustAdd = false;

                if (m_measuredValues.ContainsKey(m_valueNames[i]))
                {
                    measuredValue = (RQMeasuredValue)m_measuredValues[m_valueNames[i]];
                }
                else
                {
                    measuredValue = new RQMeasuredValue();
                    mustAdd = true;
                }

                lock (measuredValue)
                {
                    measuredValue.timestamp = timestamp;
                    measuredValue.valueName = m_valueNames[i];
                    measuredValue.stringValue = (string)received[i + 1];
                    measuredValue.intValue = m_intValues[i];
                    measuredValue.doubleValue = m_doubleValues[i];
                }

                if (mustAdd)
                {
                    m_measuredValues.Add(m_valueNames[i], measuredValue);
                }
            }
        }
示例#3
0
        internal override void interpretResponse(long timestamp)
        {
            whenReceivedTicks = timestamp;

            checkResponseSanity();

            long          ticksElapsed = 0L;
            StringBuilder strb         = null;

            if (doTrace)
            {
                ticksElapsed = timestamp - whenSentTicks;
                strb         = new StringBuilder();

                for (int i = 0; i < received.Count; i++)
                {
                    strb.Append(received[i]);
                    strb.Append(" ");
                }

                strb.Append(" <==> ");
            }

            bool goodValue = true;

            for (int i = 0; i < received.Count - 1; i++)
            {
                try
                {
                    string sHexVal = (string)received[i + 1];
                    m_intValues[i]    = Int32.Parse(sHexVal, NumberStyles.HexNumber);
                    m_doubleValues[i] = convertValue(sHexVal, i);
                    if (doTrace)
                    {
                        strb.Append("   ");
                        strb.Append(m_valueNames[i]);
                        strb.Append("=");
                        strb.Append(String.Format("{0:F}", m_doubleValues[i]).Replace(".00", ""));
                    }
                }
                catch
                {
                    if (doTrace)
                    {
                        goodValue = false;
                        strb.Append(" ***");
                    }
                }
            }

            if (goodValue)
            {
                OnValueReceived();
            }

            if (doTrace)
            {
                Tracer.Trace("interpretResponse: " + received.Count + "   " + String.Format("{0:F1}", ticksElapsed / 10000.0d) + " ms  " + strb.ToString());
            }

            for (int i = 0; i < m_valueNames.GetLength(0); i++)
            {
                RQMeasuredValue measuredValue;
                bool            mustAdd = false;

                if (m_measuredValues.ContainsKey(m_valueNames[i]))
                {
                    measuredValue = (RQMeasuredValue)m_measuredValues[m_valueNames[i]];
                }
                else
                {
                    measuredValue = new RQMeasuredValue();
                    mustAdd       = true;
                }

                lock (measuredValue)
                {
                    measuredValue.timestamp   = timestamp;
                    measuredValue.valueName   = m_valueNames[i];
                    measuredValue.stringValue = (string)received[i + 1];
                    measuredValue.intValue    = m_intValues[i];
                    measuredValue.doubleValue = m_doubleValues[i];
                }

                if (mustAdd)
                {
                    m_measuredValues.Add(m_valueNames[i], measuredValue);
                }
            }
        }
        /// <summary>
        /// only needed when controller is in RC mode, sending constant stream of data for monitoring purposes.
        /// when grabbed, controller is queried via m_queryQueue
        /// </summary>
        /// <param name="monStr"></param>
        /// <param name="timestamp"></param>
        private void interpretMonitoringString(string monStr, long timestamp)
        {
            // Tracer.Trace("MON: " + monStr);

            int j = 0;

            for (int i = 1; i < monStr.Length && j < monitorStringValueNames.GetLength(0); i += 2)
            {
                string sHexVal   = monStr.Substring(i, 2);
                string valueName = monitorStringValueNames[j];

                RQMeasuredValue measuredValue = new RQMeasuredValue();
                bool            mustAdd       = false;

                if (m_measuredValues.ContainsKey(valueName))
                {
                    measuredValue = m_measuredValues[valueName];
                }
                else
                {
                    measuredValue = new RQMeasuredValue();
                    mustAdd       = true;
                }

                lock (measuredValue)
                {
                    measuredValue.timestamp   = timestamp;
                    measuredValue.valueName   = valueName;
                    measuredValue.stringValue = sHexVal;
                    measuredValue.intValue    = Int32.Parse(sHexVal, NumberStyles.HexNumber);
                    switch (monitorStringValueConverters[j])
                    {
                    default:
                        measuredValue.doubleValue = (double)measuredValue.intValue;
                        break;

                    case 1:
                        measuredValue.doubleValue = RQVoltage.convertToMainVoltage(sHexVal);
                        break;

                    case 2:
                        measuredValue.doubleValue = RQVoltage.convertToInternalVoltage(sHexVal);
                        break;

                    case 3:
                        measuredValue.doubleValue = RQTemperature.convertToCelcius(sHexVal);
                        break;

                    case 4:
                        measuredValue.intValue    = RQCompressedHex.convertToInt(sHexVal);
                        measuredValue.doubleValue = (double)measuredValue.intValue;
                        break;
                    }
                }

                if (mustAdd)
                {
                    m_measuredValues.Add(valueName, measuredValue);
                }

                // Tracer.Trace(valueName + "=" + sHexVal + "=" + measuredValue.doubleValue);
                j++;
            }
        }