Skip to content

fix: separate ADC source offsets from buffer destinations (fixes #303) - #322

Open
abdulhamid999 wants to merge 1 commit into
fossasia:mainfrom
abdulhamid999:fix/adc-buffer-source-offsets-303
Open

abdulhamid999 wants to merge 1 commit into
fossasia:mainfrom
abdulhamid999:fix/adc-buffer-source-offsets-303

Conversation

@abdulhamid999

@abdulhamid999 abdulhamid999 commented Nov 20, 2026 •

Copy link
Copy Markdown

Fixes #303.

Problem

ADCBufferMixin.fill_buffer() previously used the device buffer destination index (idx = starting_position) to slice the input Python data list (data[idx : idx + samps]). When starting_position > 0, the first input values were skipped and if starting_position >= len(data), zero values were sent while the hardware command still declared the full sample count, causing the firmware to block waiting for payload words that were never sent.

Solution

Decouple the Python data array source offset from the hardware destination position:

  • Maintain offset starting at 0 to slice data[offset : offset + samps].
  • Transmit starting_position + offset as the destination index in each buffer fill command.
  • Preserve chunk size boundaries (128 samples), acknowledgments, and caller data.

Testing

Added hardware-independent regression tests in tests/test_buffer_fill.py covering:

  • Nonzero destination positions (0, 1, 10, 200) across sample sizes (3, 128, 129, 260) asserting exact command sequence and payload words.
  • Preserving existing zero-destination command structure.
  • Early exit on empty data without issuing commands.

Summary by Sourcery

Ensure ADC buffer destination offsets are independent from input data offsets while preserving existing command behavior.

Bug Fixes:

  • Correct ADC buffer filling so nonzero hardware destination positions no longer skip input samples or send incomplete payloads.

Tests:

  • Add hardware-independent regression coverage for destination offsets, chunk boundaries, command sequences, data preservation, and empty inputs.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed buffer writes so input samples are sent in the correct chunks and written at the requested starting position.
    • Empty input no longer sends device commands.

@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Separate the input-data offset from the hardware destination index so nonzero starting positions still send every sample.

  • pslab/instrument/buffer.py L72, L78-86

Tests

Add regression tests for chunked writes at nonzero destinations, the zero-destination command sequence, and empty input.

  • tests/test_buffer_fill.py L1-59

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

fill_buffer now tracks the input data offset separately from the destination position. Tests cover chunked writes, default-position writes, unchanged input, and empty input.

Changes: ADC buffer writes

Layer / File(s) Summary
Separate input and destination offsets
pslab/instrument/buffer.py, tests/test_buffer_fill.py
fill_buffer selects each chunk using its input offset and writes it at starting_position + offset. Tests check chunk contents and command sequence across positions and sample counts, verify the input list remains unchanged, and confirm empty input sends no commands.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: bessman

Merge Risk: Minimal · up to 64715

The change fixes ADC buffer writes so every input sample is sent at the requested device destination, and it adds hardware-independent tests. No remaining merge risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the actual change: the fill_buffer fix separates the ADC source offset (offset into the input data) from the device buffer destination (starting_position + offset). The raw summary con…
Linked Issues check Passed [#303] The reviewed head of pslab/instrument/buffer.py meets the coding objective. fill_buffer() now starts a Python-side offset at 0 and slices data[offset : offset + samps]. Each command sends start…
Out of Scope Changes check Passed The PR changes the fill_buffer() offset logic in pslab/instrument/buffer.py and adds tests in tests/test_buffer_fill.py for that same method. The source change is the fix that issue #303 requests. The…
Full details: Title check

Explanation

The title names the actual change: the fill_buffer fix separates the ADC source offset (offset into the input data) from the device buffer destination (starting_position + offset). The raw summary confirms that data slicing now uses a separate offset, and the linked issue #303 and PR objectives describe the same behavior change. The title is specific and matches the main change. The 'fix:' prefix and issue reference are conventional and do not reduce relevance.

Full details: Linked Issues check

Explanation

[#303] The reviewed head of pslab/instrument/buffer.py meets the coding objective. fill_buffer() now starts a Python-side offset at 0 and slices data[offset : offset + samps]. Each command sends starting_position + offset as the destination and samps as the count. The payload therefore matches the declared count for every chunk, including short final chunks. Chunks stay at most 128 samples, and get_ack() still runs after each chunk. The input list is not modified. Under the issue example, fill_buffer([7, 8, 9], starting_position=10) now sends destination 10, count 3, and values 7, 8, 9. No firmware or protocol change is needed, and none is made. The PR also adds regression tests in tests/test_buffer_fill.py. I did not read that test file because the diff tool was unavailable, so test coverage is taken from the PR description and AI summary only. The source change alone establishes compliance.

Full details: Out of Scope Changes check

Explanation

The PR changes the fill_buffer() offset logic in pslab/instrument/buffer.py and adds tests in tests/test_buffer_fill.py for that same method. The source change is the fix that issue #303 requests. The AI summary lists no other source or public API changes. The whole-PR diff tool was unavailable, so I could not read the full diff to confirm there are no other edited files. The summary and PR description list only these two files, and both relate to #303. No unrelated change was found.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e95965a1-abb7-4b00-9302-5c4f5cd6a23f
Commits

Reviewing files that changed from the base of the PR and between 08de0d0 and 6471593.

Files selected for processing: 2

  • pslab/instrument/buffer.py
  • tests/test_buffer_fill.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026

Copy link
Copy Markdown

Linked issues

Checked at commit 6471593

#303 ADC buffer writes skip input values at nonzero destinations · 2 of 2 met

# Requirement Status Notes
1 Write every input value starting at the requested destination, using a separate input-data offset. ✅ Met The source slice uses offset, while each command sends starting_position + offset as the destination.
2 Preserve chunk boundaries, acknowledgments, and the caller's input list. ✅ Met The 128-sample chunking and per-chunk acknowledgment remain; the method only reads slices of data.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
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.

ADC buffer writes skip input values at nonzero destinations

1 participant