Example #1
0
        public override List <DataFile> Parse(byte[] fileBytes)
        {
            Dictionary <string, ConfigElement> datFileParams = Config.Instance.datFileParams.ToDictionary(d => d.name);

            List <DataFile> results    = new List <DataFile>();
            List <byte[]>   dataChunks = Split(fileBytes);

            for (int j = 0; j < dataChunks.Count; j++)
            {
                var dataChunk = dataChunks[j];
                int position  = 0;
                var result    = new DataFile();
                // 3 bytes
                byte[] buffer = new byte[3] {
                    dataChunk[position++], dataChunk[position++], dataChunk[position++]
                };
                result.Data.Add("Три байта 0xEE", new DataElement {
                    OriginalValue = (buffer[0], buffer[1], buffer[2]), DataParams = datFileParams["Три байта 0xEE"]
                });
Example #2
0
        private List <DataFile> ToDataFile(List <BinFile> data)
        {
            Dictionary <int, ConfigElement> binFileParams = Config.Instance.binFileParams.ToDictionary(d => d.number);

            var result = new List <DataFile>();
            var dates  = data.GroupBy(d => d.Date).ToArray();

            bool first = true;

            foreach (var date in dates)
            {
                List <BinFile> elementsOfDate = date.ToList();
                var            resultElement  = new DataFile();
                resultElement.Data.Add("Время в “UNIX” формате", new DataElement {
                    OriginalValue = date.Key, DisplayValue = DateTimeOffset.FromUnixTimeMilliseconds(date.Key).AddHours(3).ToString("dd.MM.yyyy HH:mm:ss")
                });

                for (int j = 0; j < elementsOfDate.Count; j++)
                {
                    var element = elementsOfDate[j];

                    string displayValue;
                    switch (element.Uid)
                    {
                    case 21:
                    case 22:
                        displayValue = ParseCoordinate((int)element.Value);
                        break;

                    case 29:
                    case 15:
                    case 16:
                    case 102:
                    case 151:
                        displayValue = (element.Value * 0.1).ToString();
                        break;

                    case 30:
                        displayValue = (element.Value * 0.01).ToString();
                        break;

                    default:
                        displayValue = element.Value.ToString();
                        break;
                    }

                    var dataElement = new DataElement
                    {
                        ChartValue   = element.Value,
                        DisplayValue = displayValue,
                        Display      = true,
                        DataParams   = binFileParams[element.Uid]
                    };
                    resultElement.Data.Add(dataElement.DataParams.name, dataElement);
                }

                if (!first && result.Last().Data.Count > resultElement.Data.Count)
                {
                    var keys = result.Last().Data.Keys;
                    foreach (var key in keys)
                    {
                        if (!resultElement.Data.ContainsKey(key))
                        {
                            resultElement.Data.Add(key, result.Last().Data[key]);
                        }
                    }
                }

                result.Add(resultElement);

                first = false;
            }

            return(result);
        }