public FileResult GetRawCsvFile(string packetId)
        {
            var packet = PacketRepository.GetByPacketId(packetId);
            var theImpactArray = packet.ToMessage();

            var results = new List<PacketViewModel>();
            var packetVM = new PacketViewModel
            {
                PacketId = packet.PacketId,
                Seq = packet.Seq,
                MessageType = theImpactArray.MessageType.ToString(),
                RawData = packet.RawPacket,
            };

            results.Add(packetVM);
            byte[] csvFile = results.ToCsvFile();

            return File(csvFile, "application/CSV", "rawdata_" + packetId + ".csv");
        }
        public FileResult GetImpactCsvFile(string packetId)
        {
            var packet = PacketRepository.GetByPacketId(packetId);
            var theImpactArray = packet.ToMessage() as ImpactAlert1ArrayMessage;

            var theMsgs = (from m in theImpactArray.ToSingleMessages() select (ImpactAlert1Message)m).ToList();
            var theFirst = theMsgs.FirstOrDefault() as ImpactAlert1Message;

            int theKey = theFirst.ImpactUniqueID + theFirst.NumberOfDataPointInArray;

            var packets = PacketRepository.GetPacketIdAfterByHeaderTime(packetId, new TimeSpan(0, 0, 10));
            packets = packets.OrderByDescending(p => p.HeaderTime).ToList();

            List<ImpactAlert1Message> results = new List<ImpactAlert1Message>();

            packets.ForEach(p =>
            {
                var impactArray = p.ToMessage() as ImpactAlert1ArrayMessage;
                var msgs = (from m in impactArray.ToSingleMessages() select (ImpactAlert1Message)m).ToList();
                var first = msgs.FirstOrDefault() as ImpactAlert1Message;
                if (first != null)
                {
                    int key = first.ImpactUniqueID + first.NumberOfDataPointInArray;
                    if (key == theKey)
                    {
                        results.AddRange(msgs);
                    }
                }
            });

            results = results.OrderBy(m => m.Index).ToList();

            double delTime = 1d / 800;
            List<double> times = new List<double>();
            List<double> ax = new List<double>();
            List<double> ay = new List<double>();
            List<double> az = new List<double>();

            for (int i = 0; i < results.Count; i++)
            {
                times.Add(delTime * i);

                ax.Add(results[i].ValueOfXAxisAcceleration);
                ay.Add(results[i].ValueOfYAxisAcceleration);
                az.Add(results[i].ValueOfZAxisAcceleration);
            }

            byte[] csvFile = results.ToCsvFile();

            return File(csvFile, "application/CSV", "imppact_" + packetId + ".csv");
        }