Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSDK-9814 Increase packet buffer size to 10 #24

Merged
merged 7 commits into from
Feb 3, 2025
Merged

RSDK-9814 Increase packet buffer size to 10 #24

merged 7 commits into from
Feb 3, 2025

Conversation

oliviamiller
Copy link
Collaborator

When debug was on in the gateway, the line WARNING: not enough space allocated, fetched 2 packet(s), 1 will be left in RX buffer showed occasionally. Increased the buffer to 10 to ensure we don't miss any packets, no longer see the warning when manually testing.

packets := unsafe.Slice((*C.struct_lgw_pkt_rx_s)(unsafe.Pointer(p)), maxRxPkt)
for i := range numPackets {
// received a LORA packet
var payload []byte
Copy link
Collaborator

@randhid randhid Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This produces a []bytes(nil), is this what you want instead of a []bytes{}? both have a length of 0, but one has a nil array.

I think your number of packets check is defensive enough, but just wanted to point this out in case we need to be defensive payload checking and logging for a nil case there as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's handled elsewhere just add a comment about where a nil check for the payload is handled, do we have a test for a nil handlepacket payload?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code right below this should handle this sufficiently, if the packet size is zero we skip calling handlePacket, otherwise we append bytes to the payload so it won't be nil.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we'll never have a packet non-zero size with a nil payload?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the size that is sent in the packet is the payload size, so it should be zero if the payload is nil. So something would have to be wrong with the packet to not match. doesn't hurt to have a nil check just in case, will add.

Copy link
Collaborator

@JohnN193 JohnN193 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just a question on a code change in the diff

g.logger.Errorf("error receiving lora packet")
default:
// convert from c array to go slice
packets := unsafe.Slice((*C.struct_lgw_pkt_rx_s)(unsafe.Pointer(p)), maxRxPkt)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[supernit] do we need the extra variable? wondering if we can just do this

Suggested change
packets := unsafe.Slice((*C.struct_lgw_pkt_rx_s)(unsafe.Pointer(p)), maxRxPkt)
packets := unsafe.Slice((*C.struct_lgw_pkt_rx_s)(unsafe.Pointer(p)), int(C.MAX_RX_PKT))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I can just do that

default:
// convert from c array to go slice
packets := unsafe.Slice((*C.struct_lgw_pkt_rx_s)(unsafe.Pointer(p)), maxRxPkt)
for i := range numPackets {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] so before we didn't need this because we set MAX_RX_PKT = 8.

now that MAX_RX_PKT = 10, we technically need to loop thru the packets?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before we weren't using the MAX_RX_PKT in the C receive function we were doing return lgw_receive(1, packet);, so only one packet was received.

@oliviamiller oliviamiller merged commit b77b66a into main Feb 3, 2025
2 checks passed
@oliviamiller oliviamiller deleted the warn branch February 14, 2025 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants