Skip to content

Commit

Permalink
rename SequenceID to SequenceNumber; add GetSequenceNumber() (#99)
Browse files Browse the repository at this point in the history
* Add GetSequenceId() to V1Frame and V2Frame

* Refactor SequenceID to SequenceNumber, GetSequenceID to GetSequenceNumber, and other related fields or comments for consistency
  • Loading branch information
ddries authored Apr 13, 2024
1 parent c649c72 commit d6b12ab
Show file tree
Hide file tree
Showing 14 changed files with 176 additions and 161 deletions.
20 changes: 10 additions & 10 deletions endpoint_broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ func TestEndpointBroadcast(t *testing.T) {
evt = <-node.Events()
require.Equal(t, &EventFrame{
Frame: &frame.V2Frame{
SequenceID: byte(i),
SystemID: 11,
ComponentID: 1,
Message: msg,
Checksum: evt.(*EventFrame).Frame.GetChecksum(),
SequenceNumber: byte(i),
SystemID: 11,
ComponentID: 1,
Message: msg,
Checksum: evt.(*EventFrame).Frame.GetChecksum(),
},
Channel: evt.(*EventFrame).Channel,
}, evt)
Expand All @@ -105,11 +105,11 @@ func TestEndpointBroadcast(t *testing.T) {
fr, err := rw.Read()
require.NoError(t, err)
require.Equal(t, &frame.V2Frame{
SequenceID: byte(i),
SystemID: 10,
ComponentID: 1,
Message: msg,
Checksum: fr.GetChecksum(),
SequenceNumber: byte(i),
SystemID: 10,
ComponentID: 1,
Message: msg,
Checksum: fr.GetChecksum(),
}, fr)
}
}
18 changes: 9 additions & 9 deletions endpoint_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func TestEndpointClient(t *testing.T) {
fr, err := rw.Read()
require.NoError(t, err)
require.Equal(t, &frame.V2Frame{
SequenceID: byte(i),
SystemID: 10,
ComponentID: 1,
SequenceNumber: byte(i),
SystemID: 10,
ComponentID: 1,
Message: &MessageHeartbeat{
Type: 1,
Autopilot: 2,
Expand Down Expand Up @@ -114,9 +114,9 @@ func TestEndpointClient(t *testing.T) {
evt = <-node.Events()
require.Equal(t, &EventFrame{
Frame: &frame.V2Frame{
SequenceID: byte(i),
SystemID: 11,
ComponentID: 1,
SequenceNumber: byte(i),
SystemID: 11,
ComponentID: 1,
Message: &MessageHeartbeat{
Type: 6,
Autopilot: 5,
Expand Down Expand Up @@ -164,9 +164,9 @@ func TestEndpointClientIdleTimeout(t *testing.T) {
fr, err := rw.Read()
require.NoError(t, err)
require.Equal(t, &frame.V2Frame{
SequenceID: 0,
SystemID: 10,
ComponentID: 1,
SequenceNumber: 0,
SystemID: 10,
ComponentID: 1,
Message: &MessageHeartbeat{
Type: 1,
Autopilot: 2,
Expand Down
20 changes: 10 additions & 10 deletions endpoint_custom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ func TestEndpointCustom(t *testing.T) {
evt = <-node.Events()
require.Equal(t, &EventFrame{
Frame: &frame.V2Frame{
SequenceID: byte(i),
SystemID: 11,
ComponentID: 1,
Message: msg,
Checksum: evt.(*EventFrame).Frame.GetChecksum(),
SequenceNumber: byte(i),
SystemID: 11,
ComponentID: 1,
Message: msg,
Checksum: evt.(*EventFrame).Frame.GetChecksum(),
},
Channel: evt.(*EventFrame).Channel,
}, evt)
Expand All @@ -129,11 +129,11 @@ func TestEndpointCustom(t *testing.T) {
fr, err := rw.Read()
require.NoError(t, err)
require.Equal(t, &frame.V2Frame{
SequenceID: byte(i),
SystemID: 10,
ComponentID: 1,
Message: msg,
Checksum: fr.GetChecksum(),
SequenceNumber: byte(i),
SystemID: 10,
ComponentID: 1,
Message: msg,
Checksum: fr.GetChecksum(),
}, fr)
}
}
30 changes: 15 additions & 15 deletions endpoint_serial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func TestEndpointSerial(t *testing.T) {
fr, err := rw.Read()
require.NoError(t, err)
require.Equal(t, &frame.V2Frame{
SequenceID: byte(i),
SystemID: 10,
ComponentID: 1,
SequenceNumber: byte(i),
SystemID: 10,
ComponentID: 1,
Message: &MessageHeartbeat{
Type: 6,
Autopilot: 5,
Expand Down Expand Up @@ -99,9 +99,9 @@ func TestEndpointSerial(t *testing.T) {
evt := <-node.Events()
require.Equal(t, &EventFrame{
Frame: &frame.V2Frame{
SequenceID: byte(i),
SystemID: 11,
ComponentID: 1,
SequenceNumber: byte(i),
SystemID: 11,
ComponentID: 1,
Message: &MessageHeartbeat{
Type: 1,
Autopilot: 2,
Expand Down Expand Up @@ -165,9 +165,9 @@ func TestEndpointSerialReconnect(t *testing.T) {
fr, err := rw.Read()
require.NoError(t, err)
require.Equal(t, &frame.V2Frame{
SequenceID: 0,
SystemID: 10,
ComponentID: 1,
SequenceNumber: 0,
SystemID: 10,
ComponentID: 1,
Message: &MessageHeartbeat{
Type: 6,
Autopilot: 5,
Expand Down Expand Up @@ -198,9 +198,9 @@ func TestEndpointSerialReconnect(t *testing.T) {
fr, err := rw.Read()
require.NoError(t, err)
require.Equal(t, &frame.V2Frame{
SequenceID: 0,
SystemID: 10,
ComponentID: 1,
SequenceNumber: 0,
SystemID: 10,
ComponentID: 1,
Message: &MessageHeartbeat{
Type: 7,
Autopilot: 5,
Expand Down Expand Up @@ -241,9 +241,9 @@ func TestEndpointSerialReconnect(t *testing.T) {
evt = <-node.Events()
require.Equal(t, &EventFrame{
Frame: &frame.V2Frame{
SequenceID: 0,
SystemID: 11,
ComponentID: 1,
SequenceNumber: 0,
SystemID: 11,
ComponentID: 1,
Message: &MessageHeartbeat{
Type: 1,
Autopilot: 2,
Expand Down
20 changes: 10 additions & 10 deletions endpoint_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ func TestEndpointServer(t *testing.T) {
evt := <-node.Events()
require.Equal(t, &EventFrame{
Frame: &frame.V2Frame{
SequenceID: byte(i),
SystemID: 11,
ComponentID: 1,
Message: msg,
Checksum: evt.(*EventFrame).Frame.GetChecksum(),
SequenceNumber: byte(i),
SystemID: 11,
ComponentID: 1,
Message: msg,
Checksum: evt.(*EventFrame).Frame.GetChecksum(),
},
Channel: evt.(*EventFrame).Channel,
}, evt)
Expand All @@ -93,11 +93,11 @@ func TestEndpointServer(t *testing.T) {
fr, err := rw.Read()
require.NoError(t, err)
require.Equal(t, &frame.V2Frame{
SequenceID: byte(i),
SystemID: 10,
ComponentID: 1,
Message: msg,
Checksum: fr.GetChecksum(),
SequenceNumber: byte(i),
SystemID: 10,
ComponentID: 1,
Message: msg,
Checksum: fr.GetChecksum(),
}, fr)
}
})
Expand Down
86 changes: 43 additions & 43 deletions node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ func TestNodeWriteAll(t *testing.T) {
if fr, ok := evt.(*EventFrame); ok {
require.Equal(t, &EventFrame{
Frame: &frame.V2Frame{
SequenceID: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: fr.Frame.GetChecksum(),
SequenceNumber: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: fr.Frame.GetChecksum(),
},
Channel: fr.Channel,
}, fr)
Expand All @@ -176,11 +176,11 @@ func TestNodeWriteAll(t *testing.T) {
require.NoError(t, err)
} else {
err := server.WriteFrameAll(&frame.V2Frame{
SequenceID: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: 55967,
SequenceNumber: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: 55967,
})
require.NoError(t, err)
}
Expand Down Expand Up @@ -225,11 +225,11 @@ func TestNodeWriteExcept(t *testing.T) {
if fr, ok := evt.(*EventFrame); ok {
require.Equal(t, &EventFrame{
Frame: &frame.V2Frame{
SequenceID: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: fr.Frame.GetChecksum(),
SequenceNumber: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: fr.Frame.GetChecksum(),
},
Channel: fr.Channel,
}, fr)
Expand Down Expand Up @@ -258,11 +258,11 @@ func TestNodeWriteExcept(t *testing.T) {
require.NoError(t, err)
} else {
err := server.WriteFrameExcept(except, &frame.V2Frame{
SequenceID: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: 55967,
SequenceNumber: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: 55967,
})
require.NoError(t, err)
}
Expand Down Expand Up @@ -306,11 +306,11 @@ func TestNodeWriteTo(t *testing.T) {
if fr, ok := evt.(*EventFrame); ok {
require.Equal(t, &EventFrame{
Frame: &frame.V2Frame{
SequenceID: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: fr.Frame.GetChecksum(),
SequenceNumber: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: fr.Frame.GetChecksum(),
},
Channel: fr.Channel,
}, fr)
Expand Down Expand Up @@ -339,11 +339,11 @@ func TestNodeWriteTo(t *testing.T) {
require.NoError(t, err)
} else {
err := server.WriteFrameTo(except, &frame.V2Frame{
SequenceID: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: 55967,
SequenceNumber: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: 55967,
})
require.NoError(t, err)
}
Expand Down Expand Up @@ -442,7 +442,7 @@ func TestNodeSignature(t *testing.T) {
require.Equal(t, true, ok)
require.Equal(t, &EventFrame{
Frame: &frame.V2Frame{
SequenceID: 0,
SequenceNumber: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Expand Down Expand Up @@ -566,7 +566,7 @@ func TestNodeFixFrame(t *testing.T) {
}, evt)

fra := &frame.V2Frame{
SequenceID: 13,
SequenceNumber: 13,
SystemID: 15,
ComponentID: 11,
Message: testMessage,
Expand All @@ -588,7 +588,7 @@ func TestNodeFixFrame(t *testing.T) {
require.Equal(t, true, ok)
require.Equal(t, &EventFrame{
Frame: &frame.V2Frame{
SequenceID: 13,
SequenceNumber: 13,
SystemID: 15,
ComponentID: 11,
Message: testMessage,
Expand Down Expand Up @@ -656,11 +656,11 @@ func TestNodeWriteSameToMultiple(t *testing.T) {
require.Equal(t, true, ok)

fr := &frame.V2Frame{
SequenceID: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: 55967,
SequenceNumber: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: 55967,
}

err = client1.WriteFrameAll(fr)
Expand All @@ -675,11 +675,11 @@ func TestNodeWriteSameToMultiple(t *testing.T) {
require.Equal(t, true, ok)
require.Equal(t, &EventFrame{
Frame: &frame.V2Frame{
SequenceID: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: 55967,
SequenceNumber: 0,
SystemID: 11,
ComponentID: 1,
Message: testMessage,
Checksum: 55967,
},
Channel: fr.Channel,
}, evt)
Expand Down
3 changes: 3 additions & 0 deletions pkg/frame/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ type Frame interface {
// returns the component id of the author of the frame.
GetComponentID() byte

// returns the sequence number in the frame
GetSequenceNumber() byte

// returns the message wrapped in the frame.
GetMessage() message.Message

Expand Down
Loading

0 comments on commit d6b12ab

Please sign in to comment.