|
|
@ -9,6 +9,7 @@ import ( |
|
|
|
"encoding/binary" |
|
|
|
"encoding/binary" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
"math" |
|
|
|
//"encoding/hex"
|
|
|
|
//"encoding/hex"
|
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
"sort" |
|
|
|
"sort" |
|
|
@ -17,6 +18,10 @@ import ( |
|
|
|
"../model" |
|
|
|
"../model" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
|
|
|
ALLOWED_TIME_MINUTES = -5 |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type ruptelaTchHeader struct { |
|
|
|
type ruptelaTchHeader struct { |
|
|
|
Length uint16 |
|
|
|
Length uint16 |
|
|
|
IMEI uint64 |
|
|
|
IMEI uint64 |
|
|
@ -219,9 +224,12 @@ func parseData(data []byte, imei uint64, tagOption *opt.Options) (rec DeviceReco |
|
|
|
ioVal := convBinaryToUint16(addOneByteInTwoByte(data[currByte:plusByte]),2,"io1Val") |
|
|
|
ioVal := convBinaryToUint16(addOneByteInTwoByte(data[currByte:plusByte]),2,"io1Val") |
|
|
|
//fmt.Printf("io1Val %d\n",ioVal)
|
|
|
|
//fmt.Printf("io1Val %d\n",ioVal)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
strVal := fmt.Sprintf("%v",int16(ioVal)) |
|
|
|
|
|
|
|
//fmt.Printf("strVal %v\n",strVal)
|
|
|
|
|
|
|
|
|
|
|
|
tagDevice_ := tags_[strconv.Itoa(int(ioID))] |
|
|
|
tagDevice_ := tags_[strconv.Itoa(int(ioID))] |
|
|
|
tagDevice_.TagId = strconv.Itoa(int(ioID)) |
|
|
|
tagDevice_.TagId = strconv.Itoa(int(ioID)) |
|
|
|
tagDevice_.TagVal = strconv.Itoa(int(ioVal)) |
|
|
|
tagDevice_.TagVal = strVal |
|
|
|
if tagDevice_.TagName != ""{ |
|
|
|
if tagDevice_.TagName != ""{ |
|
|
|
//tags_[strconv.Itoa(int(ioID))] = tagDevice_
|
|
|
|
//tags_[strconv.Itoa(int(ioID))] = tagDevice_
|
|
|
|
tags_[tagDevice_.TagName] = tagDevice_ |
|
|
|
tags_[tagDevice_.TagName] = tagDevice_ |
|
|
@ -249,9 +257,13 @@ func parseData(data []byte, imei uint64, tagOption *opt.Options) (rec DeviceReco |
|
|
|
plusByte = currByte + 2 |
|
|
|
plusByte = currByte + 2 |
|
|
|
ioVal := convBinaryToUint16(data[currByte:plusByte],2,"io2Val") |
|
|
|
ioVal := convBinaryToUint16(data[currByte:plusByte],2,"io2Val") |
|
|
|
// fmt.Printf("io2Val %d\n",ioVal)
|
|
|
|
// fmt.Printf("io2Val %d\n",ioVal)
|
|
|
|
|
|
|
|
// fmt.Printf("io2Val INT %d\n",int16(ioVal))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
strVal := fmt.Sprintf("%v",int16(ioVal)) |
|
|
|
|
|
|
|
//fmt.Printf("strVal %v\n",strVal)
|
|
|
|
|
|
|
|
|
|
|
|
tagDevice_ := tags_[strconv.Itoa(int(ioID))] |
|
|
|
tagDevice_ := tags_[strconv.Itoa(int(ioID))] |
|
|
|
tagDevice_.TagVal = strconv.Itoa(int(ioVal)) |
|
|
|
tagDevice_.TagVal = strVal |
|
|
|
if tagDevice_.TagName != ""{ |
|
|
|
if tagDevice_.TagName != ""{ |
|
|
|
tags_[tagDevice_.TagName] = tagDevice_ |
|
|
|
tags_[tagDevice_.TagName] = tagDevice_ |
|
|
|
} |
|
|
|
} |
|
|
@ -277,8 +289,11 @@ func parseData(data []byte, imei uint64, tagOption *opt.Options) (rec DeviceReco |
|
|
|
ioVal := convBinaryToInt32(data[currByte:plusByte],4,"io4Val") |
|
|
|
ioVal := convBinaryToInt32(data[currByte:plusByte],4,"io4Val") |
|
|
|
//fmt.Printf("io4Val %d\n",ioVal)
|
|
|
|
//fmt.Printf("io4Val %d\n",ioVal)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
strVal := fmt.Sprintf("%v",int32(ioVal)) |
|
|
|
|
|
|
|
//fmt.Printf("strVal %v\n",strVal)
|
|
|
|
|
|
|
|
|
|
|
|
tagDevice_ := tags_[strconv.Itoa(int(ioID))] |
|
|
|
tagDevice_ := tags_[strconv.Itoa(int(ioID))] |
|
|
|
tagDevice_.TagVal = strconv.FormatInt(int64(ioVal), 10) |
|
|
|
tagDevice_.TagVal = strVal |
|
|
|
if tagDevice_.TagName != ""{ |
|
|
|
if tagDevice_.TagName != ""{ |
|
|
|
tags_[tagDevice_.TagName] = tagDevice_ |
|
|
|
tags_[tagDevice_.TagName] = tagDevice_ |
|
|
|
} |
|
|
|
} |
|
|
@ -304,8 +319,11 @@ func parseData(data []byte, imei uint64, tagOption *opt.Options) (rec DeviceReco |
|
|
|
ioVal := convBinaryToInt64(data[currByte:plusByte],8,"io8Val") |
|
|
|
ioVal := convBinaryToInt64(data[currByte:plusByte],8,"io8Val") |
|
|
|
//fmt.Printf("io8Val %d\n",ioVal)
|
|
|
|
//fmt.Printf("io8Val %d\n",ioVal)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
strVal := fmt.Sprintf("%v",int64(ioVal)) |
|
|
|
|
|
|
|
//fmt.Printf("strVal %v\n",strVal)
|
|
|
|
|
|
|
|
|
|
|
|
tagDevice_ := tags_[strconv.Itoa(int(ioID))] |
|
|
|
tagDevice_ := tags_[strconv.Itoa(int(ioID))] |
|
|
|
tagDevice_.TagVal = strconv.FormatInt(int64(ioVal), 10) |
|
|
|
tagDevice_.TagVal = strVal |
|
|
|
if tagDevice_.TagName != ""{ |
|
|
|
if tagDevice_.TagName != ""{ |
|
|
|
tags_[tagDevice_.TagName] = tagDevice_ |
|
|
|
tags_[tagDevice_.TagName] = tagDevice_ |
|
|
|
} |
|
|
|
} |
|
|
@ -320,10 +338,18 @@ func parseData(data []byte, imei uint64, tagOption *opt.Options) (rec DeviceReco |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
deviceRecord.TagDevices = tags_ |
|
|
|
deviceRecord.TagDevices = tags_ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tstampToNow := time.Since(deviceRecord.Tstamp) |
|
|
|
|
|
|
|
hCurr := math.Round(tstampToNow.Minutes()*100)/100 |
|
|
|
|
|
|
|
if hCurr >= ALLOWED_TIME_MINUTES { |
|
|
|
deviceRecords = append(deviceRecords, deviceRecord) |
|
|
|
deviceRecords = append(deviceRecords, deviceRecord) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rec.NumRec = uint16(len(deviceRecords)) |
|
|
|
|
|
|
|
|
|
|
|
//sort ascending by date
|
|
|
|
//sort ascending by date
|
|
|
|
sort.Sort(ByTstamp(deviceRecords)) |
|
|
|
sort.Sort(ByTstamp(deviceRecords)) |
|
|
|
|
|
|
|
|
|
|
|