fix: decode jt808 registration plate text
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
package jt808
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"lingniu-vehicle-ingest/go/vehicle-gateway/internal/envelope"
|
||||
"golang.org/x/text/encoding/simplifiedchinese"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -318,7 +321,18 @@ func fixedText(data []byte) string {
|
||||
}
|
||||
|
||||
func freeText(data []byte) string {
|
||||
return strings.TrimRight(strings.TrimSpace(string(data)), "\x00")
|
||||
data = bytes.Trim(data, "\x00 ")
|
||||
if len(data) == 0 {
|
||||
return ""
|
||||
}
|
||||
if utf8.Valid(data) {
|
||||
return string(data)
|
||||
}
|
||||
decoded, err := simplifiedchinese.GBK.NewDecoder().Bytes(data)
|
||||
if err == nil && utf8.Valid(decoded) {
|
||||
return string(decoded)
|
||||
}
|
||||
return strings.ToValidUTF8(string(data), "")
|
||||
}
|
||||
|
||||
func parseBCDTime(data []byte) time.Time {
|
||||
|
||||
Reference in New Issue
Block a user