fix: throttle jt808 registration touches
This commit is contained in:
@@ -112,11 +112,8 @@ func ParseFrame(raw []byte, receivedAtMS int64, sourceEndpoint string) (envelope
|
||||
}
|
||||
|
||||
phoneBCD := raw[phoneStart:phoneEnd]
|
||||
phone := bcdString(phoneBCD)
|
||||
phoneTrimZero := strings.TrimLeft(phone, "0")
|
||||
if versioned && phoneTrimZero != "" {
|
||||
phone = phoneTrimZero
|
||||
}
|
||||
phoneRaw := bcdString(phoneBCD)
|
||||
phone := normalizePhone(phoneRaw)
|
||||
body := raw[headerLen : headerLen+int(bodySize)]
|
||||
parsed := map[string]any{
|
||||
"header": map[string]any{
|
||||
@@ -127,7 +124,7 @@ func ParseFrame(raw []byte, receivedAtMS int64, sourceEndpoint string) (envelope
|
||||
"body_size": bodySize,
|
||||
"phone_bcd_hex": strings.ToUpper(hex.EncodeToString(phoneBCD)),
|
||||
"phone": phone,
|
||||
"phone_trim_zero": phoneTrimZero,
|
||||
"phone_raw": phoneRaw,
|
||||
"sequence": binary.BigEndian.Uint16(raw[serialStart : serialStart+2]),
|
||||
"subpackage": subpackage,
|
||||
"package_info": packageInfo,
|
||||
@@ -230,6 +227,14 @@ func parseRegistration(body []byte, versioned bool) (map[string]any, error) {
|
||||
return registration, nil
|
||||
}
|
||||
|
||||
func normalizePhone(phone string) string {
|
||||
trimmed := strings.TrimLeft(strings.TrimSpace(phone), "0")
|
||||
if trimmed == "" {
|
||||
return strings.TrimSpace(phone)
|
||||
}
|
||||
return trimmed
|
||||
}
|
||||
|
||||
func parseAuthentication(body []byte, versioned bool) map[string]any {
|
||||
if versioned {
|
||||
if out, ok := parseVersionedAuthentication(body); ok {
|
||||
|
||||
Reference in New Issue
Block a user