Exemplo n.º 1
0
        private MeasMsg AddCellDepths(NMEAProprietarySentence nmeaSentence, MeasMsg measMsg)
        {
            bool      cannotCompute = false;
            const int blankingIndex = 4;
            const int cellSizeIndex = 5;
            double    blanking      = 0;
            double    cellSize      = 0;

            if (!measMsg.GetNumericDoubleObsValueByName(nameDictionary["I"][blankingIndex], out blanking))
            {
                cannotCompute = true;
            }
            else if (!measMsg.GetNumericDoubleObsValueByName(nameDictionary["I"][cellSizeIndex], out cellSize))
            {
                cannotCompute = true;
            }

            for (int i = 0; i < CellDepthVariables.Count; i++)
            {
                string dataValue = "///";
                if (!cannotCompute)
                {
                    double depth = blanking + (i + 1) * cellSize;
                    dataValue = depth.ToString();
                }
                measMsg.AddMeas(CellDepthVariables[i], dataValue.ToString());
            }

            return(measMsg);
        }
Exemplo n.º 2
0
        public MeasMsg Parse(string message)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(message))
                {
                    return(null);
                }

                //   Debug.WriteLine("Parsing AWAC message:" + message);

                int dollarIndex = message.IndexOf("$");
                if (dollarIndex == -1)
                {
                    return(null);
                }

                int crLfIndex = message.IndexOf("/r/n");
                if (crLfIndex == -1)
                {
                    message = message + Environment.NewLine;
                }

                if (nameDictionary.Count == 0)
                {
                    InitDictionary();
                }

                int index = message.IndexOf("$PN");
                if (index == -1)
                {
                    return(null);
                }
                if (index > 0)
                {
                    message = message.Substring(index);
                }



                NMEAProprietarySentence nmeaSentence = (NMEAParser.Parse(message)) as NMEAProprietarySentence;
                return(ParseMsg(nmeaSentence));
            }
            catch (Exception ex)
            {
                ExceptionHandler.HandleException(ex, "Error while parsing NMEA message." + message);
                return(null);
            }
        }
Exemplo n.º 3
0
        private MeasMsg ParseMsg(NMEAProprietarySentence nmeaSentence)
        {
            MeasMsg result = new MeasMsg();

            result.Time = DateTimeEx.Now;
            var s = nmeaSentence.SentenceIDString.ToUpperInvariant();

            if (!nameDictionary.ContainsKey(s))
            {
                return(null);
            }

            if (s == "C")
            {
                return(ParseCellVelocityData(nmeaSentence, result));
            }


            int len = nmeaSentence.parameters.Length;

            for (int i = 0; i < len; i++)
            {
                string dataValue = string.Empty;
                if (null != nmeaSentence.parameters[i])
                {
                    dataValue = nmeaSentence.parameters[i].ToString();
                }

                result.AddMeas(nameDictionary[s][i], dataValue);
            }

            if (s == "I")
            {
                return(AddCellDepths(nmeaSentence, result));
            }

            return(result);
        }
Exemplo n.º 4
0
        private MeasMsg ParseCellVelocityData(NMEAProprietarySentence nmeaSentence, MeasMsg measMsg)
        {
            const int cellIdIndex = 2;
            const int speedIndex  = 6;
            const int dirIndex    = 7;
            int       cell;
            string    cellId = nmeaSentence.parameters[cellIdIndex].ToString();

            if (!int.TryParse(cellId, out cell))
            {
                SimpleFileWriter.WriteLineToEventFile(DirectoryName.EventLog, StringManager.GetString("Unable to parse Nortec AWAC NMEA message cell id. Received cellId was:") + cellId);
                return(measMsg);
            }

            int index = cell - 1;

            // Ignore any message from cells which do not have variables defined
            if (-1 < index && index < CellSpeedVariables.Count)
            {
                var dataValue = nmeaSentence.parameters[speedIndex].ToString();
                measMsg.AddMeas(CellSpeedVariables[index], dataValue);
            }

            if (-1 < index && index < CellDirectionVariables.Count)
            {
                var dataValue = nmeaSentence.parameters[dirIndex].ToString();
                measMsg.AddMeas(CellDirectionVariables[index], dataValue);
            }

            if (measMsg.Count == 0)
            {
                return(null);
            }


            return(measMsg);
        }