Example #1
0
        /// <summary>
        ///    設定時間(9:00:00 ~ 16:59:59 以外的時間)
        /// </summary>
        /// <param name="buffer">ZBuffer類別</param>
        /// <param name="time">時間設定值</param>
        /// <param name="isReal">是否為即時  true=即時   false=補價</param>
        internal static void SetOther(PacketBuffer buffer, int time, bool isReal)
        {
            ushort usTime = 0;
            byte   bHour = 0, bMinute = 0, bSecond = 0;

            bHour = (byte)(time / 3600);

            if (bHour == 6 || bHour == 7)
            {
                --bHour;
            }
            else
            {
                bHour -= 17;
            }

            time   %= 3600;
            bMinute = (byte)(time / 60);
            bSecond = (byte)(time % 60);

            if (!isReal)
            {
                usTime = BitConvert.SetValue(usTime, 15, 1);
            }

            usTime = BitConvert.SetValue(usTime, 12, bHour);
            usTime = BitConvert.SetValue(usTime, 6, bMinute);
            usTime = BitConvert.SetValue(usTime, 0, bSecond);

            buffer.Data[buffer.Position++] = (byte)((usTime >> 8) & 0xff);
            buffer.Data[buffer.Position++] = (byte)(usTime & 0xff);
        }
Example #2
0
        /// <summary>
        ///     編碼價格資訊函式
        /// </summary>
        /// <param name="Buffer">緩衝區</param>
        /// <param name="Price">價格</param>
        /// <param name="ReferPrice">參考價</param>
        /// <param name="PriceFlag">價格旗標</param>
        /// <param name="BitIndex">起始位元索引(0=最右邊起始位元 依序向左遞增)</param>
        internal static void SetPrice(PacketBuffer Buffer, float Price, float ReferPrice, ref byte PriceFlag, int BitIndex)
        {
            int iValue = 0;

            if (ReferPrice == 0 || System.Math.Abs(Price - ReferPrice) > 255)
            {
                iValue = decimal.ToInt32(new decimal(Price) * 100);
            }
            else
            {
                iValue = decimal.ToInt32((new decimal(Price) * 100) - (new decimal(ReferPrice) * 100));
            }

            int iNegative = (((iValue & 0x80000000) == 0) ? 0x00 : 0x80);

            if (iNegative == 0x80)                 //如果是負數
            {
                iValue = ~iValue;                  //做2的補數(變成正數)
                ++iValue;
            }

            int iInteger = iValue / 100;
            int iDot     = iValue % 100;

            if (iInteger == 0 && iDot > 0)
            {
                Buffer.Data[Buffer.Position++] = (byte)(iDot | iNegative);
                PriceFlag = BitConvert.SetValue(PriceFlag, BitIndex, 0);
            }
            else if (iInteger < 128 && iDot == 0)
            {
                Buffer.Data[Buffer.Position++] = (byte)(iInteger | iNegative);
                PriceFlag = BitConvert.SetValue(PriceFlag, BitIndex, 2);
            }
            else if (iInteger < 256)
            {
                Buffer.Data[Buffer.Position++] = (byte)iInteger;
                Buffer.Data[Buffer.Position++] = (byte)(iDot | iNegative);
                PriceFlag = BitConvert.SetValue(PriceFlag, BitIndex, 3);
            }
            else
            {
                Buffer.Data[Buffer.Position++] = (byte)(iInteger >> 8);
                Buffer.Data[Buffer.Position++] = (byte)(iInteger & 0xff);
                Buffer.Data[Buffer.Position++] = (byte)iDot;
                PriceFlag = BitConvert.SetValue(PriceFlag, BitIndex, 1);
            }
        }
Example #3
0
        /// <summary>
        ///     設定成交量資訊函式
        /// </summary>
        /// <param name="Buffer">封包陣列</param>
        /// <param name="Volumn">成交量</param>
        /// <param name="VolumnFlag">成交量旗標</param>
        /// <param name="BitIndex">起始位元索引(0=最右邊起始位元 依序向左遞增)</param>
        internal static void SetVolumn(PacketBuffer Buffer, uint Volumn, ref byte VolumnFlag, int BitIndex)
        {
            byte[] bTmpData = new byte[4];               //建立一個暫存的陣列

            byte i = 0;

            for (i = 0; i <= 3; i++)
            {
                bTmpData[i] = (byte)(Volumn & 0xff);
                if ((Volumn >>= 8) == 0)
                {
                    break;
                }
            }

            VolumnFlag = BitConvert.SetValue(VolumnFlag, BitIndex, i);

            int iCount = i + 1;

            for (byte j = 0; j < iCount; j++)
            {
                Buffer.Data[Buffer.Position++] = bTmpData[i - j];
            }
        }