예제 #1
0
        /// <summary>
        ///    設定時間
        /// </summary>
        /// <param name="buffer">ZBuffer類別</param>
        /// <param name="time">時間設定值</param>
        /// <param name="isReal">是否為即時  true=即時   false=補價</param>
        internal static void SetTime(PacketBuffer buffer, int time, bool isReal)
        {
            ushort usTime = 0;
            byte   bHour = 0, bMinute = 0, bSecond = 0;

            bHour   = (byte)((time / 3600) - 9);
            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);
        }
예제 #2
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];
            }
        }
예제 #3
0
        /// <summary>
        ///   股票即時資訊時間解碼(解碼開盤其他時間 9:00:00 ~ 16:59:59 以外的時間)
        /// </summary>
        /// <param name="buffer">ZBuffer類別</param>
        /// <returns>返回值: DateTime結構</returns>
        internal static DateTime GetOther(PacketBuffer buffer)
        {
            int    hh = 0, mm = 0, ss = 0;
            ushort TimeByte = (ushort)((buffer[0] << 8) + buffer[1]);

            hh = BitConvert.GetValue(TimeByte, 12, 3);
            if (hh == 6 || hh == 7)
            {
                hh += 1;
            }
            else
            {
                hh += 17;
            }

            hh = (hh < 0 || hh > 23) ? 0 : hh;
            mm = BitConvert.GetValue(TimeByte, 6, 6);
            mm = (mm < 0 || mm > 59) ? 0 : mm;
            ss = BitConvert.GetValue(TimeByte, 0, 6);
            ss = (ss < 0 || ss > 59) ? 0 : ss;

            buffer.Position += 2;
            return(__cToday.AddSeconds(hh * 3600 + mm * 60 + ss));
        }