Beispiel #1
0
        public void DateTimeToGPSOriginTime_Invalid_NonUTCDate()
        {
            Action act = () => GPS.DateTimeToGPSOriginTime(DateTime.Now, out _, out _);

            act.Should().Throw <ArgumentException>().WithMessage("Date must be a UTC date time*");
        }
Beispiel #2
0
        public void DateTimeToGPSOriginTime_Invalid_Early()
        {
            Action act = () => GPS.DateTimeToGPSOriginTime(DateTime.SpecifyKind(new DateTime(1950, 1, 1), DateTimeKind.Utc), out _, out _);

            act.Should().Throw <ArgumentException>().WithMessage("Date to be converted to GPS date is before the GPS date origin*");
        }
Beispiel #3
0
        /// <summary>
        /// Process field from datapacket
        /// </summary>
        private bool ProcessField()
        {
            try
            {
                switch (TagName)
                {
                case TagConstants.TIME:
                {
                    // Starts new epoch
                    uint gpsTime;
                    uint gpsWeek;
                    var  utcTime = TagUtils.DateTimeFromUnixTimestampMillis(Convert.ToInt64(TagValue));
                    GPS.DateTimeToGPSOriginTime(utcTime, out gpsWeek, out gpsTime);
                    EpochRec.Time = gpsTime;
                    EpochRec.Week = gpsWeek;
                    break;
                }

                case TagConstants.LEFT_EASTING_BLADE:
                {
                    var leb = Convert.ToDouble(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasLEB & leb == Prev_EpochRec.LEB)
                        {
                            break;
                        }
                    }
                    EpochRec.LEB = leb;
                    break;
                }

                case TagConstants.LEFT_NORTHING_BLADE:
                {
                    var lnb = Convert.ToDouble(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasLNB & lnb == Prev_EpochRec.LNB)
                        {
                            break;
                        }
                    }
                    EpochRec.LNB = lnb;
                    break;
                }

                case TagConstants.LEFT_HEIGHT_BLADE:
                {
                    var lhb = Convert.ToDouble(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasLHB & lhb == Prev_EpochRec.LHB)
                        {
                            break;
                        }
                    }
                    EpochRec.LHB = lhb;
                    break;
                }

                case TagConstants.RIGHT_EASTING_BLADE:
                {
                    var reb = Convert.ToDouble(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasREB & reb == Prev_EpochRec.REB)
                        {
                            break;
                        }
                    }
                    EpochRec.REB = reb;
                    break;
                }

                case TagConstants.RIGHT_NORTHING_BLADE:
                {
                    var rnb = Convert.ToDouble(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasRNB & rnb == Prev_EpochRec.RNB)
                        {
                            break;
                        }
                    }
                    EpochRec.RNB = rnb;
                    break;
                }

                case TagConstants.RIGHT_HEIGHT_BLADE:
                {
                    var rhb = Convert.ToDouble(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasRHB & rhb == Prev_EpochRec.RHB)
                        {
                            break;
                        }
                    }
                    EpochRec.RHB = rhb;
                    break;
                }

                case TagConstants.GPS_MODE:
                {
                    EpochRec.GPM = Convert.ToUInt16(TagValue);
                    break;
                }

                case TagConstants.BLADE_ON_GROUND:
                {
                    ushort val = Convert.ToUInt16(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasBOG & val == Prev_EpochRec.BOG)
                        {
                            break;
                        }
                    }
                    EpochRec.BOG = Convert.ToUInt16(TagValue);
                    break;
                }

                case TagConstants.DESIGN:
                {
                    var design = TagValue;
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasDesign & design == Prev_EpochRec.Design)
                        {
                            break;
                        }
                    }
                    EpochRec.Design = design;
                    break;
                }

                case TagConstants.LATITUDE:
                {
                    var latt = (SeedLat != 0) ? SeedLat : Convert.ToDouble(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasLAT & latt == Prev_EpochRec.LAT)
                        {
                            break;
                        }
                    }
                    EpochRec.LAT = latt;
                    break;
                }

                case TagConstants.LONTITUDE:
                {
                    var lng = (SeedLon != 0) ? SeedLon : Convert.ToDouble(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasLON & lng == Prev_EpochRec.LON)
                        {
                            break;
                        }
                    }
                    EpochRec.LON = lng;
                    break;
                }

                case TagConstants.HEIGHT:
                {
                    var hgt = Convert.ToDouble(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasHGT & hgt == Prev_EpochRec.HGT)
                        {
                            break;
                        }
                    }
                    EpochRec.HGT = hgt;
                    break;
                }

                case TagConstants.MACHINE_ID:
                {
                    EpochRec.MID = TagValue;
                    break;
                }

                case TagConstants.MACHINE_SPEED:
                {
                    var spd = Convert.ToDouble(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasMSD & spd == Prev_EpochRec.MSD)
                        {
                            break;
                        }
                    }
                    EpochRec.MSD = spd;
                    break;
                }

                case TagConstants.MACHINE_TYPE:
                {
                    EpochRec.MTP = TagUtils.ConvertToMachineType(TagValue);
                    break;
                }

                case TagConstants.HEADING:
                {
                    var hdg = Convert.ToDouble(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasHDG & hdg == Prev_EpochRec.HDG)
                        {
                            break;
                        }
                    }
                    EpochRec.HDG = hdg;
                    break;
                }

                case TagConstants.SERIAL:
                {
                    EpochRec.Serial      = TagValue;
                    EpochRec.RadioSerial = TagValue; // Yes assigned two places
                    break;
                }

                case TagConstants.UTM:
                {
                    EpochRec.UTM = Convert.ToByte(TagValue);
                    break;
                }

                case TagConstants.HDR:
                {
                    if (Convert.ToByte(TagValue) == TagConstants.HEADER_RECORD)
                    {
                        EpochRec.HasHeader = true;
                        packetIsHeader     = true;
                    }
                    break;
                }

                case TagConstants.CCV:
                {
                    var ccv = Convert.ToUInt16(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasCCV & ccv == Prev_EpochRec.CCV)
                        {
                            break;
                        }
                    }
                    EpochRec.CCV = ccv;
                    break;
                }

                case TagConstants.MAPPING_MODE:
                {
                    EpochRec.MappingMode = Convert.ToUInt16(TagValue);
                    break;
                }

                case TagConstants.TARGET_CCV:
                {
                    EpochRec.TargetCCV = Convert.ToUInt16(TagValue);
                    break;
                }

                case TagConstants.TEMPERATURE:
                {
                    var tmp = Convert.ToUInt16(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasTemperature & tmp == Prev_EpochRec.Temperature)
                        {
                            break;
                        }
                    }
                    EpochRec.Temperature = tmp;
                    break;
                }

                case TagConstants.COMPACT_SENSOR_TYPE:
                {
                    EpochRec.CST = Convert.ToUInt16(TagValue);
                    break;
                }

                case TagConstants.FLAGS:
                {
                    EpochRec.Flags = Convert.ToUInt16(TagValue);
                    break;
                }

                case TagConstants.DIRECTION:
                {
                    EpochRec.Direction = Convert.ToUInt16(TagValue);
                    break;
                }

                case TagConstants.MDP:
                {
                    var mdp = Convert.ToUInt16(TagValue);
                    if (Prev_EpochRec != null)
                    {
                        if (Prev_EpochRec.HasMDP & mdp == Prev_EpochRec.MDP)
                        {
                            break;
                        }
                    }
                    EpochRec.MDP = mdp;
                    break;
                }

                case TagConstants.TARGET_MDP:
                {
                    EpochRec.TargetMDP = Convert.ToUInt16(TagValue);
                    break;
                }

                case TagConstants.TARGET_PASSCOUNT:
                {
                    EpochRec.TargetPasses = Convert.ToUInt16(TagValue);
                    break;
                }

                case TagConstants.TARGET_THICKNESS:
                {
                    EpochRec.TargetThickness = Convert.ToUInt16(TagValue);
                    break;
                }

                case TagConstants.TEMP_MIN:
                {
                    EpochRec.TempMin = Convert.ToUInt16(TagValue);
                    break;
                }

                case TagConstants.TEMP_MAX:
                {
                    EpochRec.TempMax = Convert.ToUInt16(TagValue);
                    break;
                }


                default:
                    Log.LogWarning($"ProcessField. Unknown TagName:{TagName} Value:{TagValue}");
                    break;
                }
            }
            catch (Exception ex)
            {
                Log.LogError($"Unexpected error in ProcessField. TagName:{TagName}, Value:{TagValue}, Error:{ex.Message.ToString()} Trace:{ex.StackTrace.ToString()}");
                return(false);
            }

            return(true);
        }