diff --git a/client.go b/client.go index 386ac87..729c0e5 100644 --- a/client.go +++ b/client.go @@ -129,8 +129,8 @@ func (client *Client) Disconnect() error { } // GetSecurityCount 获取指定市场内的证券数目 -func (client *Client) GetSecurityCount(market uint16) (*proto.SecurityCountReply, error) { - obj := proto.NewSecurityCount() +func (client *Client) GetSecurityCount(market uint16) (*proto.GetSecurityCountReply, error) { + obj := proto.NewGetSecurityCount() obj.SetParams(market) err := client.do(obj) if err != nil { @@ -138,3 +138,14 @@ func (client *Client) GetSecurityCount(market uint16) (*proto.SecurityCountReply } return obj.Reply, err } + +// GetSecurityQuotes 获取盘口五档报价 +func (client *Client) GetSecurityQuotes(params []proto.Stock) (*proto.GetSecurityQuotesReply, error) { + obj := proto.NewGetSecurityQuotes() + obj.SetParams(params) + err := client.do(obj) + if err != nil { + return nil, err + } + return obj.Reply, err +} diff --git a/client_test.go b/client_test.go index 7bada05..bde5ee6 100644 --- a/client_test.go +++ b/client_test.go @@ -2,6 +2,7 @@ package gotdx import ( "fmt" + "gotdx/proto" "testing" ) @@ -52,3 +53,19 @@ func Test_tdx_GetSecurityCount(t *testing.T) { _ = api.Disconnect() } + +func Test_tdx_GetSecurityQuotes(t *testing.T) { + api := prepare() + params := []proto.Stock{} + params = append(params, proto.Stock{Market: MarketSh, Code: "002062"}) + params = append(params, proto.Stock{Market: MarketSh, Code: "000001"}) + reply, err := api.GetSecurityQuotes(params) + if err != nil { + fmt.Println(err) + } + + fmt.Println(reply) + + _ = api.Disconnect() + +} diff --git a/constants.go b/constants.go index 0d9fc76..f750c4c 100644 --- a/constants.go +++ b/constants.go @@ -3,8 +3,8 @@ package gotdx import "errors" const ( - MarketSz = 0 // 深圳 - MarketSh = 1 // 上海 + MarketSh = 0 // 上海 + MarketSz = 1 // 深圳 MarketBj = 2 // 北京 ) diff --git a/proto/get_security_count.go b/proto/get_security_count.go index 97b0360..483540f 100644 --- a/proto/get_security_count.go +++ b/proto/get_security_count.go @@ -3,59 +3,49 @@ package proto import ( "bytes" "encoding/binary" + "encoding/hex" ) -// SecurityCount -type SecurityCount struct { +// GetSecurityCount +type GetSecurityCount struct { ReqHeader - content []byte - Reply *SecurityCountReply + content string + Reply *GetSecurityCountReply market uint16 } -type SecurityCountReply struct { +type GetSecurityCountReply struct { Count uint16 } -func NewSecurityCount() *SecurityCount { - obj := &SecurityCount{} - obj.Reply = new(SecurityCountReply) +func NewGetSecurityCount() *GetSecurityCount { + obj := &GetSecurityCount{} obj.Zip = 0x0c obj.SeqID = seqID() obj.PacketType = 0x01 obj.Method = KMSG_SECURITYCOUNT - obj.content = []byte{0x75, 0xc7, 0x33, 0x01} + obj.content = "75c73301" // 未解 return obj } -func (obj *SecurityCount) SetParams(market uint16) { +func (obj *GetSecurityCount) SetParams(market uint16) { obj.market = market } -func (obj *SecurityCount) Serialize() ([]byte, error) { +func (obj *GetSecurityCount) Serialize() ([]byte, error) { obj.PkgLen1 = 2 + uint16(len(obj.content)) + 2 obj.PkgLen2 = 2 + uint16(len(obj.content)) + 2 buf := new(bytes.Buffer) err := binary.Write(buf, binary.LittleEndian, obj.ReqHeader) err = binary.Write(buf, binary.LittleEndian, obj.market) - buf.Write(obj.content) + b, err := hex.DecodeString(obj.content) + buf.Write(b) return buf.Bytes(), err } -/* -0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011f85e34068747470733a2f2f626967352e6e65776f6e652e636f6d2e636e2f7a797968742f7a645f7a737a712e7a6970000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004150503a414c4c0d0a54494d453a303a30312d31353a30352c31353a30362d32333a35390d0a20202020c4facab9d3c3b5c4b0e6b1bebcb4bdabcda3d3c3a3acceaac1cbc4fab5c4d5fdb3a3cab9d3c32cc7ebbea1bfecc9fdd6c1d5d0c9ccd6a4c8af5043b0e6a1a30d0a20202020c8e7b9fbb2bbc4dcd7d4b6afc9fdbcb6a3acc7ebb5bdb9d9cdf868747470733a2f2f7777772e636d736368696e612e636f6d2fcfc2d4d8b0b2d7b0a3acd0bbd0bbc4fab5c4d6a7b3d6a3a100 年月日 年月日 -*/ -func (obj *SecurityCount) UnSerialize(header interface{}, data []byte) error { - //serverInfo := utils.Utf8ToGbk(data[58:]) - //fmt.Println(fmt.Sprintf("服务器:%s;", serverInfo)) - //fmt.Println(hex.EncodeToString(data)) - //obj.Reply.Info = serverInfo - - //var tmp uint16 - //bytesBuffer := bytes.NewBuffer(data) - //err := binary.Write(bytesBuffer, binary.LittleEndian, &tmp) - //binary.LittleEndian.Uint16(data) +func (obj *GetSecurityCount) UnSerialize(header interface{}, data []byte) error { + obj.Reply = new(GetSecurityCountReply) obj.Reply.Count = binary.LittleEndian.Uint16(data[:2]) return nil } diff --git a/proto/get_security_quotes.go b/proto/get_security_quotes.go new file mode 100644 index 0000000..e5b5d6b --- /dev/null +++ b/proto/get_security_quotes.go @@ -0,0 +1,220 @@ +package proto + +import ( + "bytes" + "encoding/binary" + "encoding/hex" + "fmt" + "gotdx/utils" +) + +// GetSecurityQuotes //获取盘口五档报价 +type GetSecurityQuotes struct { + ReqHeader + contentHex string + Reply *GetSecurityQuotesReply + + stocks []Stock +} + +type Stock struct { + Market uint8 + Code string +} + +type GetSecurityQuotesReply struct { + Count uint16 + List []SecurityQuote +} + +type SecurityQuote struct { + Market uint8 // 市场 + Code string // 代码 + Active1 uint16 // 活跃度 + Price float64 // 现价 + LastClose float64 // 昨收 + Open float64 // 开盘 + High float64 // 最高 + Low float64 // 最低 + ServerTime string // 时间 + ReversedBytes0 int // 保留(时间 ServerTime) + ReversedBytes1 int // 保留 + Vol int // 总量 + CurVol int // 现量 + Amount float64 // 总金额 + SVol int // 内盘 + BVol int // 外盘 + ReversedBytes2 int // 保留 + ReversedBytes3 int // 保留 + BidLevels []Level + AskLevels []Level + Bid1 float64 + Ask1 float64 + BidVol1 int + AskVol1 int + Bid2 float64 + Ask2 float64 + BidVol2 int + AskVol2 int + Bid3 float64 + Ask3 float64 + BidVol3 int + AskVol3 int + Bid4 float64 + Ask4 float64 + BidVol4 int + AskVol4 int + Bid5 float64 + Ask5 float64 + BidVol5 int + AskVol5 int + ReversedBytes4 uint16 // 保留 + ReversedBytes5 int // 保留 + ReversedBytes6 int // 保留 + ReversedBytes7 int // 保留 + ReversedBytes8 int // 保留 + Rate float64 // 涨速 + Active2 uint16 // 活跃度 +} + +type Level struct { + Price float64 + Vol int +} + +func NewGetSecurityQuotes() *GetSecurityQuotes { + obj := &GetSecurityQuotes{} + obj.Zip = 0x0c + obj.SeqID = seqID() + obj.PacketType = 0x01 + obj.Method = KMSG_SECURITYQUOTES + obj.contentHex = "0500000000000000" + return obj +} +func (obj *GetSecurityQuotes) SetParams(stocks []Stock) { + obj.stocks = stocks +} + +func (obj *GetSecurityQuotes) Serialize() ([]byte, error) { + obj.PkgLen1 = 2 + uint16(len(obj.stocks)*7) + 10 + obj.PkgLen2 = 2 + uint16(len(obj.stocks)*7) + 10 + + buf := new(bytes.Buffer) + err := binary.Write(buf, binary.LittleEndian, obj.ReqHeader) + b, err := hex.DecodeString(obj.contentHex) + buf.Write(b) + + err = binary.Write(buf, binary.LittleEndian, uint16(len(obj.stocks))) + + for _, stock := range obj.stocks { + //code, _ := hex.DecodeString(stock.Code) + //code := []byte{} + code := make([]byte, 6) + copy(code, stock.Code) + tmp := []byte{stock.Market} + tmp = append(tmp, code...) + buf.Write(tmp) + } + return buf.Bytes(), err +} + +func (obj *GetSecurityQuotes) UnSerialize(header interface{}, data []byte) error { + obj.Reply = new(GetSecurityQuotesReply) + //fmt.Println(hex.EncodeToString(data)) + pos := 0 + + pos += 2 // 跳过两个字节 + binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &obj.Reply.Count) + pos += 2 + for index := uint16(0); index < obj.Reply.Count; index++ { + ele := SecurityQuote{} + binary.Read(bytes.NewBuffer(data[pos:pos+1]), binary.LittleEndian, &ele.Market) + pos += 1 + var code [6]byte + binary.Read(bytes.NewBuffer(data[pos:pos+6]), binary.LittleEndian, &code) + //enc := mahonia.NewDecoder("gbk") + //ele.Code = enc.ConvertString(string(code[:])) + ele.Code = utils.Utf8ToGbk(code[:]) + pos += 6 + binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &ele.Active1) + pos += 2 + + price := getprice(data, &pos) + ele.Price = obj.getPrice(price, 0) + ele.LastClose = obj.getPrice(price, getprice(data, &pos)) + ele.Open = obj.getPrice(price, getprice(data, &pos)) + ele.High = obj.getPrice(price, getprice(data, &pos)) + ele.Low = obj.getPrice(price, getprice(data, &pos)) + + ele.ReversedBytes0 = getprice(data, &pos) + ele.ServerTime = fmt.Sprintf("%d", ele.ReversedBytes0) + ele.ReversedBytes1 = getprice(data, &pos) + + ele.Vol = getprice(data, &pos) + ele.CurVol = getprice(data, &pos) + + var amountraw uint32 + binary.Read(bytes.NewBuffer(data[pos:pos+4]), binary.LittleEndian, &amountraw) + pos += 4 + ele.Amount = getvolume(int(amountraw)) + + ele.SVol = getprice(data, &pos) + ele.BVol = getprice(data, &pos) + + ele.ReversedBytes2 = getprice(data, &pos) + ele.ReversedBytes3 = getprice(data, &pos) + + for i := 0; i < 5; i++ { + bidele := Level{Price: obj.getPrice(getprice(data, &pos), price)} + offerele := Level{Price: obj.getPrice(getprice(data, &pos), price)} + bidele.Vol = getprice(data, &pos) + offerele.Vol = getprice(data, &pos) + ele.BidLevels = append(ele.BidLevels, bidele) + ele.AskLevels = append(ele.AskLevels, offerele) + } + ele.Bid1 = ele.BidLevels[0].Price + ele.Bid2 = ele.BidLevels[1].Price + ele.Bid3 = ele.BidLevels[2].Price + ele.Bid4 = ele.BidLevels[3].Price + ele.Bid5 = ele.BidLevels[4].Price + ele.Ask1 = ele.AskLevels[0].Price + ele.Ask2 = ele.AskLevels[1].Price + ele.Ask3 = ele.AskLevels[2].Price + ele.Ask4 = ele.AskLevels[3].Price + ele.Ask5 = ele.AskLevels[4].Price + + ele.BidVol1 = ele.BidLevels[0].Vol + ele.BidVol2 = ele.BidLevels[1].Vol + ele.BidVol3 = ele.BidLevels[2].Vol + ele.BidVol4 = ele.BidLevels[3].Vol + ele.BidVol5 = ele.BidLevels[4].Vol + + ele.AskVol1 = ele.AskLevels[0].Vol + ele.AskVol2 = ele.AskLevels[1].Vol + ele.AskVol3 = ele.AskLevels[2].Vol + ele.AskVol4 = ele.AskLevels[3].Vol + ele.AskVol5 = ele.AskLevels[4].Vol + + binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &ele.ReversedBytes4) + pos += 2 + ele.ReversedBytes5 = getprice(data, &pos) + ele.ReversedBytes6 = getprice(data, &pos) + ele.ReversedBytes7 = getprice(data, &pos) + ele.ReversedBytes8 = getprice(data, &pos) + + var reversedbytes9 int16 + binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &reversedbytes9) + pos += 2 + ele.Rate = float64(reversedbytes9) / 100.0 + binary.Read(bytes.NewBuffer(data[pos:pos+2]), binary.LittleEndian, &ele.Active2) + pos += 2 + + obj.Reply.List = append(obj.Reply.List, ele) + } + //obj.Reply.Count = binary.LittleEndian.Uint16(data[:2]) + return nil +} + +func (obj *GetSecurityQuotes) getPrice(price int, diff int) float64 { + return float64(price+diff) / 100.0 +} diff --git a/proto/hello1.go b/proto/hello1.go index 094a430..849d30a 100644 --- a/proto/hello1.go +++ b/proto/hello1.go @@ -3,14 +3,15 @@ package proto import ( "bytes" "encoding/binary" + "encoding/hex" "gotdx/utils" ) // Hello1 创建握手消息1 type Hello1 struct { ReqHeader - content []byte - Reply *Hello1Reply + contentHex string + Reply *Hello1Reply } type Hello1Reply struct { Info string @@ -19,22 +20,24 @@ type Hello1Reply struct { func NewHello1() *Hello1 { obj := &Hello1{} - obj.Reply = new(Hello1Reply) obj.Zip = 0x0c obj.SeqID = seqID() obj.PacketType = 0x01 obj.Method = KMSG_CMD1 - obj.content = []byte{0x01} + obj.contentHex = "01" return obj } func (obj *Hello1) Serialize() ([]byte, error) { - obj.PkgLen1 = 2 + uint16(len(obj.content)) - obj.PkgLen2 = 2 + uint16(len(obj.content)) + b, err := hex.DecodeString(obj.contentHex) + + obj.PkgLen1 = 2 + uint16(len(b)) + obj.PkgLen2 = 2 + uint16(len(b)) buf := new(bytes.Buffer) - err := binary.Write(buf, binary.LittleEndian, obj.ReqHeader) - buf.Write(obj.content) + err = binary.Write(buf, binary.LittleEndian, obj.ReqHeader) + + buf.Write(b) return buf.Bytes(), err } @@ -43,9 +46,8 @@ func (obj *Hello1) Serialize() ([]byte, error) { 分 时 秒 日期 */ func (obj *Hello1) UnSerialize(header interface{}, data []byte) error { + obj.Reply = new(Hello1Reply) serverInfo := utils.Utf8ToGbk(data[68:]) - //fmt.Println(fmt.Sprintf("服务器:%s;", serverInfo)) - //fmt.Println(hex.EncodeToString(data)) obj.Reply.Info = serverInfo return nil } diff --git a/proto/hello2.go b/proto/hello2.go index 5e57347..b09e69d 100644 --- a/proto/hello2.go +++ b/proto/hello2.go @@ -3,14 +3,15 @@ package proto import ( "bytes" "encoding/binary" + "encoding/hex" "gotdx/utils" ) // Hello2 创建握手消息2 type Hello2 struct { ReqHeader - content []byte - Reply *Hello2Reply + contentHex string + Reply *Hello2Reply } type Hello2Reply struct { Info string @@ -19,22 +20,23 @@ type Hello2Reply struct { func NewHello2() *Hello2 { obj := &Hello2{} - obj.Reply = new(Hello2Reply) obj.Zip = 0x0c obj.SeqID = seqID() obj.PacketType = 0x01 obj.Method = KMSG_CMD2 - obj.content = []byte{0xd5, 0xd0, 0xc9, 0xcc, 0xd6, 0xa4, 0xa8, 0xaf, 0x00, 0x00, 0x00, 0x8f, 0xc2, 0x25, 0x40, 0x13, 0x00, 0x00, 0xd5, 0x00, 0xc9, 0xcc, 0xbd, 0xf0, 0xd7, 0xea, 0x00, 0x00, 0x00, 0x02} + obj.contentHex = "d5d0c9ccd6a4a8af0000008fc22540130000d500c9ccbdf0d7ea00000002" return obj } func (obj *Hello2) Serialize() ([]byte, error) { - obj.PkgLen1 = 2 + uint16(len(obj.content)) - obj.PkgLen2 = 2 + uint16(len(obj.content)) + b, err := hex.DecodeString(obj.contentHex) + + obj.PkgLen1 = 2 + uint16(len(b)) + obj.PkgLen2 = 2 + uint16(len(b)) buf := new(bytes.Buffer) - err := binary.Write(buf, binary.LittleEndian, obj.ReqHeader) - buf.Write(obj.content) + err = binary.Write(buf, binary.LittleEndian, obj.ReqHeader) + buf.Write(b) return buf.Bytes(), err } @@ -42,8 +44,8 @@ func (obj *Hello2) Serialize() ([]byte, error) { 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011f85e34068747470733a2f2f626967352e6e65776f6e652e636f6d2e636e2f7a797968742f7a645f7a737a712e7a6970000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004150503a414c4c0d0a54494d453a303a30312d31353a30352c31353a30362d32333a35390d0a20202020c4facab9d3c3b5c4b0e6b1bebcb4bdabcda3d3c3a3acceaac1cbc4fab5c4d5fdb3a3cab9d3c32cc7ebbea1bfecc9fdd6c1d5d0c9ccd6a4c8af5043b0e6a1a30d0a20202020c8e7b9fbb2bbc4dcd7d4b6afc9fdbcb6a3acc7ebb5bdb9d9cdf868747470733a2f2f7777772e636d736368696e612e636f6d2fcfc2d4d8b0b2d7b0a3acd0bbd0bbc4fab5c4d6a7b3d6a3a100 年月日 年月日 */ func (obj *Hello2) UnSerialize(header interface{}, data []byte) error { + obj.Reply = new(Hello2Reply) serverInfo := utils.Utf8ToGbk(data[58:]) - //fmt.Println(fmt.Sprintf("服务器:%s;", serverInfo)) //fmt.Println(hex.EncodeToString(data)) obj.Reply.Info = serverInfo return nil diff --git a/proto/proto.go b/proto/proto.go index ae2970a..e835684 100644 --- a/proto/proto.go +++ b/proto/proto.go @@ -1,6 +1,12 @@ package proto -import "sync/atomic" +import ( + "bytes" + "encoding/binary" + "math" + "sync/atomic" + "time" +) const ( MessageHeaderBytes = 0x10 @@ -26,6 +32,35 @@ const ( KMSG_SECURITYQUOTES = 0x053e // 行情信息 KMSG_TRANSACTIONDATA = 0x0fc5 // 分笔成交信息 KMSG_XDXRINFO = 0x000f // 除权除息信息 + + /* + K线种类 + # K 线种类 + # 0 - 5 分钟K 线 + # 1 - 15 分钟K 线 + # 2 - 30 分钟K 线 + # 3 - 1 小时K 线 + # 4 - 日K 线 + # 5 - 周K 线 + # 6 - 月K 线 + # 7 - 1 分钟 + # 8 - 1 分钟K 线 + # 9 - 日K 线 + # 10 - 季K 线 + # 11 - 年K 线 + */ + KLINE_TYPE_5MIN = 0 + KLINE_TYPE_15MIN = 1 + KLINE_TYPE_30MIN = 2 + KLINE_TYPE_1HOUR = 3 + KLINE_TYPE_DAILY = 4 + KLINE_TYPE_WEEKLY = 5 + KLINE_TYPE_MONTHLY = 6 + KLINE_TYPE_EXHQ_1MIN = 7 + KLINE_TYPE_1MIN = 8 + KLINE_TYPE_RI_K = 9 + KLINE_TYPE_3MONTH = 10 + KLINE_TYPE_YEARLY = 11 ) type Msg interface { @@ -63,3 +98,182 @@ func seqID() uint32 { atomic.AddUint32(&_seqId, 1) return _seqId } + +// pytdx : 类似utf-8的编码方式保存有符号数字 +func getprice(b []byte, pos *int) int { + posbype := 6 + bdata := b[*pos] + intdata := int(bdata & 0x3f) + + sign := false + if (bdata & 0x40) > 0 { + sign = true + } + + if (bdata & 0x80) > 0 { + for { + *pos += 1 + bdata = b[*pos] + intdata += (int(bdata&0x7f) << posbype) + + posbype += 7 + + if (bdata & 0x80) <= 0 { + break + } + } + } + *pos += 1 + + if sign { + intdata = -intdata + } + return intdata +} + +func gettime(b []byte, pos *int) (h uint16, m uint16) { + var sec uint16 + binary.Read(bytes.NewBuffer(b[*pos:*pos+2]), binary.LittleEndian, &sec) + h = sec / 60 + m = sec % 60 + (*pos) += 2 + return +} + +func getdatetime(category int, b []byte, pos *int) (year int, month int, day int, hour int, minute int) { + hour = 15 + if category < 4 || category == 7 || category == 8 { + var zipday, tminutes uint16 + binary.Read(bytes.NewBuffer(b[*pos:*pos+2]), binary.LittleEndian, &zipday) + (*pos) += 2 + binary.Read(bytes.NewBuffer(b[*pos:*pos+2]), binary.LittleEndian, &tminutes) + (*pos) += 2 + + year = int((zipday >> 11) + 2004) + month = int((zipday % 2048) / 100) + day = int((zipday % 2048) % 100) + hour = int(tminutes / 60) + minute = int(tminutes % 60) + } else { + var zipday uint32 + binary.Read(bytes.NewBuffer(b[*pos:*pos+4]), binary.LittleEndian, &zipday) + (*pos) += 4 + year = int(zipday / 10000) + month = int((zipday % 10000) / 100) + day = int(zipday % 100) + } + return +} + +func getdatetimenow(category int, lasttime string) (year int, month int, day int, hour int, minute int) { + utime, _ := time.Parse("2006-01-02 15:04:05", lasttime) + switch category { + case KLINE_TYPE_5MIN: + utime = utime.Add(time.Minute * 5) + case KLINE_TYPE_15MIN: + utime = utime.Add(time.Minute * 15) + case KLINE_TYPE_30MIN: + utime = utime.Add(time.Minute * 30) + case KLINE_TYPE_1HOUR: + utime = utime.Add(time.Hour) + case KLINE_TYPE_DAILY: + utime = utime.AddDate(0, 0, 1) + case KLINE_TYPE_WEEKLY: + utime = utime.Add(time.Hour * 24 * 7) + case KLINE_TYPE_MONTHLY: + utime = utime.AddDate(0, 1, 0) + case KLINE_TYPE_EXHQ_1MIN: + utime = utime.Add(time.Minute) + case KLINE_TYPE_1MIN: + utime = utime.Add(time.Minute) + case KLINE_TYPE_RI_K: + utime = utime.AddDate(0, 0, 1) + case KLINE_TYPE_3MONTH: + utime = utime.AddDate(0, 3, 0) + case KLINE_TYPE_YEARLY: + utime = utime.AddDate(1, 0, 0) + } + + if category < 4 || category == 7 || category == 8 { + if (utime.Hour() >= 15 && utime.Minute() > 0) || (utime.Hour() > 15) { + utime = utime.AddDate(0, 0, 1) + utime = utime.Add(time.Minute * 30) + hour = (utime.Hour() + 18) % 24 + } else { + hour = utime.Hour() + } + minute = utime.Minute() + } else { + if utime.Unix() > time.Now().Unix() { + utime = time.Now() + } + hour = utime.Hour() + minute = utime.Minute() + if utime.Hour() > 15 { + hour = 15 + minute = 0 + } + } + year = utime.Year() + month = int(utime.Month()) + day = utime.Day() + return +} + +func getvolume(ivol int) (volume float64) { + logpoint := ivol >> (8 * 3) + //hheax := ivol >> (8 * 3) // [3] + hleax := (ivol >> (8 * 2)) & 0xff // [2] + lheax := (ivol >> 8) & 0xff //[1] + lleax := ivol & 0xff //[0] + + //dbl_1 := 1.0 + //dbl_2 := 2.0 + //dbl_128 := 128.0 + + dwEcx := logpoint*2 - 0x7f + dwEdx := logpoint*2 - 0x86 + dwEsi := logpoint*2 - 0x8e + dwEax := logpoint*2 - 0x96 + tmpEax := dwEcx + if dwEcx < 0 { + tmpEax = -dwEcx + } else { + tmpEax = dwEcx + } + + dbl_xmm6 := 0.0 + dbl_xmm6 = math.Pow(2.0, float64(tmpEax)) + if dwEcx < 0 { + dbl_xmm6 = 1.0 / dbl_xmm6 + } + + dbl_xmm4 := 0.0 + dbl_xmm0 := 0.0 + + if hleax > 0x80 { + tmpdbl_xmm3 := 0.0 + //tmpdbl_xmm1 := 0.0 + dwtmpeax := dwEdx + 1 + tmpdbl_xmm3 = math.Pow(2.0, float64(dwtmpeax)) + dbl_xmm0 = math.Pow(2.0, float64(dwEdx)) * 128.0 + dbl_xmm0 += float64(hleax&0x7f) * tmpdbl_xmm3 + dbl_xmm4 = dbl_xmm0 + } else { + if dwEdx >= 0 { + dbl_xmm0 = math.Pow(2.0, float64(dwEdx)) * float64(hleax) + } else { + dbl_xmm0 = (1 / math.Pow(2.0, float64(dwEdx))) * float64(hleax) + } + dbl_xmm4 = dbl_xmm0 + } + + dbl_xmm3 := math.Pow(2.0, float64(dwEsi)) * float64(lheax) + dbl_xmm1 := math.Pow(2.0, float64(dwEax)) * float64(lleax) + if (hleax & 0x80) > 0 { + dbl_xmm3 *= 2.0 + dbl_xmm1 *= 2.0 + } + volume = dbl_xmm6 + dbl_xmm4 + dbl_xmm3 + dbl_xmm1 + return +}