diff --git a/ping.go b/ping.go new file mode 100644 index 0000000..fd644aa --- /dev/null +++ b/ping.go @@ -0,0 +1,19 @@ +package mapache + +// Ping is a type to represent a ping between the vehicle and the server. +// Note that only the uplink latency is saved on the server. The vehicle does receive pongs, +// so it may choose to record the round trip time if it desires. +type Ping struct { + // VehicleID is the unique identifier for the vehicle that sent the ping. + VehicleID string `json:"vehicle_id" gorm:"primaryKey"` + // Ping is the unix millis when the vehicle sent the ping. + Ping int `json:"ping" gorm:"primaryKey"` + // Pong is the unix millis when the vehicle received the ping. + Pong int `json:"pong"` + // Latency is the latency of the ping in milliseconds. + Latency int `json:"latency"` +} + +func (Ping) TableName() string { + return "ping" +} diff --git a/signal_test.go b/signal_test.go index 15d4172..1c5b5ea 100644 --- a/signal_test.go +++ b/signal_test.go @@ -1,138 +1,5 @@ package mapache -// import ( -// "reflect" -// "testing" -// ) +import "testing" -// func TestSignal_Decode(t *testing.T) { -// t.Run("Test Big Endian Unsigned", func(t *testing.T) { -// f := Signal{ -// Bytes: []byte{0x00, 0x01}, -// Sign: Unsigned, -// Endian: BigEndian, -// } -// if f.Decode().RawValue != 1 { -// t.Error("Expected 1, got", f.Decode().RawValue) -// } -// }) -// t.Run("Test Big Endian Signed", func(t *testing.T) { -// f := Signal{ -// Bytes: []byte{0x00, 0x01}, -// Sign: Signed, -// Endian: BigEndian, -// } -// if f.Decode().RawValue != 1 { -// t.Error("Expected 1, got", f.Decode().RawValue) -// } -// }) -// t.Run("Test Little Endian Unsigned", func(t *testing.T) { -// f := Signal{ -// Bytes: []byte{0x00, 0x01}, -// Sign: Unsigned, -// Endian: LittleEndian, -// } -// if f.Decode().RawValue != 256 { -// t.Error("Expected 256, got", f.Decode().RawValue) -// } -// }) -// t.Run("Test Little Endian Signed", func(t *testing.T) { -// f := Signal{ -// Bytes: []byte{0x00, 0x01}, -// Sign: Signed, -// Endian: LittleEndian, -// } -// if f.Decode().RawValue != 256 { -// t.Error("Expected 256, got", f.Decode().RawValue) -// } -// }) -// t.Run("Test Other", func(t *testing.T) { -// f := Signal{ -// Bytes: []byte{0x00, 0x01}, -// Sign: -1, -// Endian: -1, -// } -// if f.Decode().RawValue != 0 { -// t.Error("Expected 0, got", f.Decode().RawValue) -// } -// }) -// } - -// func TestSignal_Encode(t *testing.T) { -// t.Run("Test Big Endian Unsigned", func(t *testing.T) { -// f := Signal{ -// Sign: Unsigned, -// Endian: BigEndian, -// RawValue: 1, -// Size: 2, -// } -// b, err := f.Encode() -// if err != nil { -// t.Error("Expected nil, got", err) -// } -// expected := []byte{0x00, 0x01} -// if !reflect.DeepEqual(b.Bytes, expected) { -// t.Error("Expected", expected, "got", b.Bytes) -// } -// }) -// t.Run("Test Big Endian Signed", func(t *testing.T) { -// f := Signal{ -// Sign: Signed, -// Endian: BigEndian, -// RawValue: 1, -// Size: 2, -// } -// b, err := f.Encode() -// if err != nil { -// t.Error("Expected nil, got", err) -// } -// expected := []byte{0x00, 0x01} -// if !reflect.DeepEqual(b.Bytes, expected) { -// t.Error("Expected", expected, "got", b.Bytes) -// } -// }) -// t.Run("Test Little Endian Unsigned", func(t *testing.T) { -// f := Signal{ -// Sign: Unsigned, -// Endian: LittleEndian, -// RawValue: 1, -// Size: 2, -// } -// b, err := f.Encode() -// if err != nil { -// t.Error("Expected nil, got", err) -// } -// expected := []byte{0x01, 0x00} -// if !reflect.DeepEqual(b.Bytes, expected) { -// t.Error("Expected", expected, "got", b.Bytes) -// } -// }) -// t.Run("Test Little Endian Signed", func(t *testing.T) { -// f := Signal{ -// Sign: Signed, -// Endian: LittleEndian, -// RawValue: 1, -// Size: 2, -// } -// b, err := f.Encode() -// if err != nil { -// t.Error("Expected nil, got", err) -// } -// expected := []byte{0x01, 0x00} -// if !reflect.DeepEqual(b.Bytes, expected) { -// t.Error("Expected", expected, "got", b.Bytes) -// } -// }) -// t.Run("Test Other", func(t *testing.T) { -// f := Signal{ -// Sign: -1, -// Endian: -1, -// RawValue: 1, -// Size: 2, -// } -// _, err := f.Encode() -// if err == nil { -// t.Error("Expected err, got nil") -// } -// }) -// } +func TestSignal_TableName(t *testing.T) {}