Esempio n. 1
0
        static void Main(string[] args)
        {
            PackagePSP pack = new PackagePSP(new PackagePSPStructure(StartBit.ZERO, 32, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12));
            Random     r    = new Random();

            bool ret = false;

            using (FileStream fs = File.OpenWrite("test3.bvr"))
            {
                uint time = 0;
                for (int i = 0; i < 10000; i++)
                {
                    time++;
                    pack.Item[0].Value = time / 1000;
                    pack.Item[1].Value = time % 1000;

                    //pack.Item[2].Value = (uint)i;

                    if (i > 100)
                    {
                        if (i % 100 == 0)
                        {
                            ret = !ret;
                        }
                        if (ret)
                        {
                            pack.Item[2].Value = 100;
                        }
                        else
                        {
                            pack.Item[2].Value = 3000;
                        }
                    }
                    else
                    {
                        pack.Item[2].Value = (uint)i;
                    }

                    //for (int k = 0; k < 1; k++)
                    //{
                    //    pack.Item[k + 2].Value = (uint)r.Next(4095);
                    //    if (k>4)
                    //    {
                    //        pack.Item[k + 2].Value = (uint)(100 * k);
                    //    }
                    //}

                    var p = PSP.Encode(pack);

                    fs.Write(p, 0, p.Length);
                }
            }
            Console.WriteLine("OK");
            Console.ReadKey();
        }
Esempio n. 2
0
        private async Task <MPoints> BlockDecreaseAsync(int position, int blockSize)
        {
            return(await Task.Run(() =>
            {
                using (FileStream fs = File.OpenRead(fileName))
                {
                    //StreamDecoding sd = new StreamDecoding(fs);

                    MPoints mPointsOut = new MPoints(2);
                    MPoints mPointsBlock;

                    //Создание блока из потока
                    //mPointsBlock = sd.DecodingBlock(blockSize, position);
                    //StreamControl sc = new StreamControl();
                    //sc.SeleсtStream(fs);
                    //var s = sc.ReadStream(blockSize, position);
                    PackagePSP package = new PackagePSP(new PackagePSPStructure(StartBit.ZERO, 32, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12));

                    List <MPoint> mPoints = new List <MPoint>();
                    while (true)
                    {
                        // if (PSP.Decode(s, ref package) == true) break;
                        MPoint mPoint = new MPoint();
                        DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                        dateTime = dateTime.AddSeconds(package.Item[0].Value);
                        dateTime = dateTime.AddMilliseconds(package.Item[1].Value);
                        mPoint.X = dateTime;
                        for (int i = 0; i < mPoint.Y.Length; i++)
                        {
                            mPoint.Y[i] = (int)package.Item[i + 2].Value;
                        }
                        ;
                        mPoints.Add(mPoint);
                    }
                    //Debug.Print(mPoints.Count.ToString());
                    if (mPoints.Count == 0)
                    {
                        return null;
                    }

                    MPoints points = new MPoints(mPoints.Count);
                    for (int i = 0; i < mPoints.Count; i++)
                    {
                        points[i] = mPoints[i];
                    }



                    //Выборка первой и последней даты в блоке
                    mPointsOut.X[0] = points.X.First();
                    mPointsOut.X[1] = points.X.Last();

                    //Выборка минимальных и максимальных Y значений
                    for (int g = 0; g < mPointsOut.Y.Length; g++)
                    {
                        mPointsOut.Y[g].Value[0] = points.Y[g].Value.Min();
                        mPointsOut.Y[g].Value[1] = points.Y[g].Value.Max();
                    }
                    return mPointsOut;
                }
            }
                                  ));
        }