Example #1
0
 public static VelodyneNmeaPacket Parse(String nmeaStr)
 {
     try
     {
         String[] tsnmeas = nmeaStr.Split(','); // hhmmss.ss
         if (tsnmeas.Length > 0)
         {
             String             dateStr   = default(DateTime).ToString("yyyy-MM-dd ") + tsnmeas[1].Substring(0, 2) + ":" + tsnmeas[1].Substring(2, 2) + ":" + tsnmeas[1].Substring(4, 2);
             DateTime           time_nmea = DateTime.ParseExact(dateStr, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
             VelodyneNmeaPacket packet    = new VelodyneNmeaPacket(time_nmea);
             packet.LatDeg     = Convert.ToInt32(tsnmeas[3].Substring(0, 2));
             packet.LatMin     = Convert.ToDouble(tsnmeas[3].Substring(2, 6));
             packet.LonDeg     = Convert.ToInt32(tsnmeas[5].Substring(0, 3));
             packet.LonMin     = Convert.ToDouble(tsnmeas[5].Substring(3, 6));
             packet.NmeaString = nmeaStr;
             return(packet);
         }
         else
         {
             //throw new Exception("NMEA seems empty: " + nmeaStr);
             return(null);
         }
     }
     catch (Exception)
     {
         //throw new Exception("Couldn't parse NMEA data! NMEA message: " + nmeaStr + " Excaption: " + ex.Message);
         return(null);
     }
 }
Example #2
0
 public IndexData(DateTime packetTimeStamp, DateTime internalTimeStamp, long position, String nmea)
 {
     this.PacketTimeStamp   = packetTimeStamp;
     this.Nmea              = VelodyneNmeaPacket.Parse(nmea);
     this.InternalTimeStamp = internalTimeStamp;
     this.Position          = position;
 }
Example #3
0
        public static VelodyneNmeaPacket ReadRecordNMEA(byte[] packet)
        {
            int    i  = 42 + 198;
            double ts = BitConverter.ToUInt32(new byte[] { packet[i], packet[i + 1], packet[i + 2], packet[i + 3] }, 0) / 1000000.00;

            i = i + 8;
            byte[] nmeaMessageArray = new byte[75];
            for (int j = 0; j < 75; j++)
            {
                nmeaMessageArray[j] = packet[i + j];
            }

            String             nmeaStr    = System.Text.Encoding.ASCII.GetString(nmeaMessageArray);
            VelodyneNmeaPacket nmeaPacket = VelodyneNmeaPacket.Parse(nmeaStr);

            return(nmeaPacket);
        }
Example #4
0
        public void Convert(CancellationToken cancellationToken = default(CancellationToken))
        {
            FileInfo     fi        = new FileInfo(PcapFile);
            long         fileSize  = fi.Length;
            BinaryWriter idxWriter = new BinaryWriter(File.Open(GetDefaultIndexFile(PcapFile), FileMode.Create));

            OfflinePacketDevice selectedDevice = new OfflinePacketDevice(PcapFile);
            PacketCommunicator  communicator   =
                selectedDevice.Open(65536,                                  // portion of the packet to capture
                                                                            // 65536 guarantees that the whole packet will be captured on all the link layers
                                    PacketDeviceOpenAttributes.Promiscuous, // promiscuous mode
                                    1000);                                  // read timeout


            using (BinaryWriter pointWriter = new BinaryWriter(File.Open(GetDefaultPointFile(PcapFile), FileMode.Create)))
            {
                Packet             packet;
                bool               isEof    = false;
                VelodyneNmeaPacket lastNmea = null;
                long               sumBytes = 0;
                long               indexId  = 0;

                while (!isEof)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        idxWriter.Close();
                        cancellationToken.ThrowIfCancellationRequested();
                    }

                    PacketCommunicatorReceiveResult result = communicator.ReceivePacket(out packet);
                    switch (result)
                    {
                    case PacketCommunicatorReceiveResult.Timeout:

                    case PacketCommunicatorReceiveResult.Ok:

                        sumBytes += packet.Length;

                        if (packet.Length == 554)
                        {
                            lastNmea = PacketInterpreter.ReadRecordNMEA(packet.Buffer);
                            indexId++;
                        }
                        else
                        {
                            pointWriter.Write(packet.Timestamp.Ticks);
                            pointWriter.Write(packet.Buffer);

                            if (lastNmea != null)
                            {
                                int      l                  = packet.Length - 6; // this is the end of the pack!
                                double   internal_time      = BitConverter.ToUInt32(new byte[] { packet[l], packet[l + 1], packet[l + 2], packet[l + 3] }, 0) / 1000000.00;
                                DateTime utcPacketTimestamp = packet.Timestamp.ToUniversalTime();
                                DateTime time               = (new DateTime(utcPacketTimestamp.Year, utcPacketTimestamp.Month, utcPacketTimestamp.Day, utcPacketTimestamp.Hour, 0, 0)).AddSeconds(internal_time);

                                idxWriter.Write(time.Ticks);
                                idxWriter.Write(packet.Timestamp.Ticks);
                                idxWriter.Write(pointWriter.BaseStream.Position);
                                byte[] nmea_byte = Encoding.ASCII.GetBytes(lastNmea.NmeaString.PadRight(NMEA_LENGTH, ' '));
                                idxWriter.Write(nmea_byte);

                                if (indexId % 100 == 0)
                                {
                                    ProgressReportEventArgs args = new ProgressReportEventArgs((((double)sumBytes / (double)fileSize) * 100.0), sumBytes, utcPacketTimestamp);
                                    OnReportProgress(args);
                                }

                                lastNmea = null;
                            }
                        }
                        break;

                    case PacketCommunicatorReceiveResult.Eof:
                        isEof = true;
                        break;

                    default:
                        throw new InvalidOperationException("The result " + result + " should never be reached here");
                    }
                }
            }

            idxWriter.Close();
        }