feat: build vehicle data platform and production pipeline
This commit is contained in:
@@ -124,6 +124,28 @@ func TestAutoResponseEchoesRawVINAndOriginalTime(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAutoResponseRejectsEnforcedInvalidPlatformLogin(t *testing.T) {
|
||||
body := []byte{0x1a, 0x07, 0x02, 0x00, 0x26, 0x0f, 0x00, 0x01}
|
||||
body = append(body, fixedASCII("platform-a", 12)...)
|
||||
body = append(body, fixedASCII("wrong-password", 20)...)
|
||||
body = append(body, 0x01)
|
||||
request := buildFrame(0x05, 0xfe, "12345678901234567", body)
|
||||
env, err := ParseFrame(request, 1782914969584, "127.0.0.1:32960")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
env.AuthenticationEnforced = true
|
||||
env.AuthenticationStatus = "rejected"
|
||||
|
||||
response, ok, err := AutoResponse(request, env)
|
||||
if err != nil || !ok {
|
||||
t.Fatalf("AutoResponse() ok=%v err=%v", ok, err)
|
||||
}
|
||||
if response[3] != responseError {
|
||||
t.Fatalf("response flag = 0x%02x, want 0x%02x", response[3], responseError)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseFrameExtractsRealtimeVehicleMileageAndPosition(t *testing.T) {
|
||||
body := []byte{0x1a, 0x06, 0x1e, 0x16, 0x17, 0x39}
|
||||
body = append(body, 0x01)
|
||||
|
||||
@@ -12,6 +12,7 @@ var ErrResponseFrameTooShort = errors.New("gb32960 response frame too short")
|
||||
|
||||
const (
|
||||
responseSuccess = byte(0x01)
|
||||
responseError = byte(0x02)
|
||||
responseCommand = byte(0xfe)
|
||||
encryptNone = byte(0x01)
|
||||
)
|
||||
@@ -37,7 +38,11 @@ func AutoResponse(raw []byte, env envelope.FrameEnvelope) ([]byte, bool, error)
|
||||
if timestamp := responseTime(raw, command); !timestamp.IsZero() {
|
||||
body = encodeGBTime(timestamp)
|
||||
}
|
||||
return buildResponse(raw[0], command, responseSuccess, raw[4:21], body), true, nil
|
||||
responseFlag := responseSuccess
|
||||
if command == 0x05 && env.AuthenticationEnforced && env.AuthenticationStatus != "accepted" {
|
||||
responseFlag = responseError
|
||||
}
|
||||
return buildResponse(raw[0], command, responseFlag, raw[4:21], body), true, nil
|
||||
}
|
||||
|
||||
func shouldRespond(command byte) bool {
|
||||
|
||||
Reference in New Issue
Block a user