Skip to content

Dev#13

Closed
Gcgc4514 wants to merge 5 commits into
QDU-Robomaster:devfrom
Gcgc4514:dev
Closed

Dev#13
Gcgc4514 wants to merge 5 commits into
QDU-Robomaster:devfrom
Gcgc4514:dev

Conversation

@Gcgc4514

@Gcgc4514 Gcgc4514 commented May 8, 2026

Copy link
Copy Markdown
Collaborator

哨兵包定义及launcher pack

Summary by Sourcery

Define and expose new data packs and control interfaces for the sentry, chassis, and launcher subsystems in the referee module, and hook them into existing publish/send flows.

New Features:

  • Extend LauncherPack to include robot buffs, launcher data, and dart client information for downstream modules.
  • Introduce ChassisPack for chassis-level status and power buffer data consumption.
  • Add SentryPack state management, including sentry posture enumeration and remote control methods for bullets, HP, and resurrection, plus a helper to send sentry decision commands.

Enhancements:

  • Simplify access to RobotStatus and GameStatus in SentryPack by using fully-qualified Referee types.
  • Adjust launcher pack publishing to populate the new fields from referee data.
  • Apply minor formatting and memory-handling cleanups in referee frame sending and user data parsing.

@Gcgc4514 Gcgc4514 self-assigned this May 8, 2026
@sourcery-ai

sourcery-ai Bot commented May 8, 2026

Copy link
Copy Markdown

Reviewer's Guide

Extends the referee interface to provide structured data packs for launcher, chassis, and sentry modules (including new sentry decision helpers), and performs minor refactors around data copying, UART read handling, and send helper formatting.

Sequence diagram for SendSentryPack and referee transmission

sequenceDiagram
  actor SentryModule
  participant Referee
  participant UART

  SentryModule->>Referee: SetNeedBullet(need_bullet)
  SentryModule->>Referee: SetConfirmRevival(revival)
  SentryModule->>Referee: SetBulletRemote(bullet_number)
  SentryModule->>Referee: SetHPRemote()
  SentryModule->>Referee: SetRevivalRemote(revival)
  SentryModule->>Referee: SetSwitchMode(state)

  SentryModule->>Referee: SendSentryPack()
  Referee->>Referee: Prepare sentry_dec_data
  Referee->>Referee: SendStudentCmd(REF_STDNT_CMD_ID_SENTRY_CMD, GetRobotID(), 0x8080, sentry_dec_data)
  Referee->>Referee: SendFrame(cmd_id, payload, PAYLOAD_LEN)
  Referee->>UART: Write(frame_bytes)
  UART-->>Referee: LibXR_ErrorCode OK
  Referee-->>SentryModule: transmission result
Loading

Class diagram for updated Referee packs and sentry helpers

classDiagram
  class Referee {
    +LauncherPack lp_
    +ChassisPack cp_
    +SentryPack sp_
    +Data data_
    +Topic launcherpack_topic_
    +Topic chassispack_topic_
    +Topic sentrypack_topic_
    +void SetNeedBullet(uint8_t need_bullet)
    +void SetConfirmRevival(bool revival)
    +void SetBulletRemote(uint8_t bullet_number)
    +void SetHPRemote()
    +void SetRevivalRemote(bool revival)
    +void SetSwitchMode(State state)
    +void SendSentryPack()
    +LibXR_ErrorCode SendFrame(CommandID cmd_id, const void* payload, uint16_t PAYLOAD_LEN)
    +LibXR_ErrorCode SendStudentCmd(CMDID data_cmd_id, uint16_t sender_id, uint16_t receiver_id, const PayloadType& payload)
  }

  class LauncherPack {
    +RobotStatus rs
    +RobotBuff rb
    +LauncherData ld
    +DartClient dc
  }

  class ChassisPack {
    +RobotStatus rs
    +uint16_t power_buffer
  }

  class SentryPack {
    +RobotStatus rs
    +GameStatus gs
  }

  class State {
    <<enumeration>>
    ATTACH
    DEFEND
    GUERRILLA
  }

  class Data {
    +RobotStatus robot_status
    +RobotBuff robot_buff
    +LauncherData launcher_data
    +DartClient dart_client
    +PowerHeat power_heat
    +GameStatus game_status
    +SentryDecisionData sentry_dec_data
    +RobotInteractionData robot_ineraction_data
  }

  class SentryDecisionData {
    +uint8_t buy_bullet_num
    +bool confirm_resurrection
    +uint8_t remote_buy_bullet_times
    +uint8_t romote_buy_hp_times
    +bool buy_resurrection
    +uint32_t current_state
  }

  class RobotStatus
  class RobotBuff
  class LauncherData
  class DartClient
  class GameStatus
  class PowerHeat {
    +uint16_t chassis_pwr_buff
    +uint16_t launcher_id1_17_heat
  }
  class RobotInteractionData {
    +uint8_t user_data
  }
  class Topic {
    +void Publish(T payload)
  }
  class CommandID
  class CMDID
  class LibXR_ErrorCode

  Referee --> LauncherPack : uses
  Referee --> ChassisPack : uses
  Referee --> SentryPack : uses
  Referee --> Data : aggregates
  Referee --> State : uses
  Referee --> SentryDecisionData : modifies
  Data --> RobotStatus
  Data --> RobotBuff
  Data --> LauncherData
  Data --> DartClient
  Data --> PowerHeat
  Data --> GameStatus
  Data --> SentryDecisionData
  Data --> RobotInteractionData
  Referee --> Topic : publishes packs
Loading

File-Level Changes

Change Details Files
Redefine LauncherPack and how launcher-related referee data is populated and published.
  • Replace LauncherPack fields to bundle RobotStatus, RobotBuff, LauncherData, and DartClient into a single packed struct
  • Update periodic data publishing to fill LauncherPack from robot_status, robot_buff, launcher_data, and dart_client instead of manually mapping individual heat fields
Referee.hpp
Introduce a dedicated ChassisPack and SentryPack API plus a new sentry State enum and decision/control helper methods.
  • Add packed ChassisPack struct carrying RobotStatus and power_buffer for chassis consumers
  • Adjust SentryPack to explicitly use Referee::RobotStatus and Referee::GameStatus
  • Define a State enum class representing sentry posture/mode (ATTACH, DEFEND, GUERRILLA)
  • Add setter methods for sentry decision data (bullet exchange, HP exchange, resurrection confirmation/remote buy, and mode switching)
  • Add SendSentryPack helper to send sentry_dec_data via student command with the proper command ID and robot ID
Referee.hpp
Small refactors to communication helpers and data handling for clarity and consistency.
  • Remove an outdated TODO comment from semaphore-based operation initialization
  • Tidy function signatures and indentation for SendFrame, SendStudentCmd, and UI send wrappers to improve readability
  • Simplify UART header search condition by collapsing a multi-line comparison
  • Replace LibXR::Memory::FastSet on robot_interaction_data.user_data with memset while retaining FastCopy for payload copy
Referee.hpp

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

@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 found 1 issue, and left some high level feedback:

  • The setter methods for bullet quantities (SetNeedBullet, SetBulletRemote) use += semantics even though the comments describe them as setting values; if these APIs are intended to overwrite rather than accumulate, consider switching to assignment to avoid unexpected state growth across calls.
  • When writing the sentinel state in SetSwitchMode, State is cast to uint32_t; if the protocol field is not actually 32-bit or the enum values must match a specific wire format, it would be safer to define State with an explicit underlying type that matches the field and store it directly.
  • You replaced LibXR::Memory::FastSet with memset for robot_ineraction_data.user_data; if the project relies on the abstraction (e.g., for portability or instrumentation), consider keeping FastSet for consistency with the rest of the codebase.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The setter methods for bullet quantities (`SetNeedBullet`, `SetBulletRemote`) use `+=` semantics even though the comments describe them as setting values; if these APIs are intended to overwrite rather than accumulate, consider switching to assignment to avoid unexpected state growth across calls.
- When writing the sentinel state in `SetSwitchMode`, `State` is cast to `uint32_t`; if the protocol field is not actually 32-bit or the enum values must match a specific wire format, it would be safer to define `State` with an explicit underlying type that matches the field and store it directly.
- You replaced `LibXR::Memory::FastSet` with `memset` for `robot_ineraction_data.user_data`; if the project relies on the abstraction (e.g., for portability or instrumentation), consider keeping `FastSet` for consistency with the rest of the codebase.

## Individual Comments

### Comment 1
<location path="Referee.hpp" line_range="1029-1030" />
<code_context>
-    RobotStatus rs;        /* 等级和功率上限 */
-    uint16_t power_buffer; /* 底盘缓冲能量,单位 J */
-  };
+  void SetNeedBullet(uint8_t need_bullet){
+    this->data_.sentry_dec_data.buy_bullet_num += need_bullet;
+  }
+
</code_context>
<issue_to_address>
**question (bug_risk):** Method name/doc suggest setting an absolute value but implementation accumulates, which can be confusing or unintended.

Using `+=` means each call adds to `buy_bullet_num` rather than setting it. If the protocol expects an absolute value per frame, this will lead to over-redemption. If accumulation is correct, please rename the method or update the doc so it’s clearly not a simple setter.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread Referee.hpp
Comment on lines +1029 to +1030
void SetNeedBullet(uint8_t need_bullet){
this->data_.sentry_dec_data.buy_bullet_num += need_bullet;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

question (bug_risk): Method name/doc suggest setting an absolute value but implementation accumulates, which can be confusing or unintended.

Using += means each call adds to buy_bullet_num rather than setting it. If the protocol expects an absolute value per frame, this will lead to over-redemption. If accumulation is correct, please rename the method or update the doc so it’s clearly not a simple setter.

@Gcgc4514 Gcgc4514 closed this May 8, 2026
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.

1 participant