Skip to content

Dev#12

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

Dev#12
Gcgc4514 wants to merge 4 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

Extend referee data packs and add high-level control helpers for the sentry robot.

New Features:

  • Add launcher data pack fields to expose robot buffs, launcher data, and dart client information.
  • Introduce a dedicated sentry namespace with posture state enumeration and helper methods for configuring bullet exchanges, HP purchases, resurrection, mode switching, and sending sentry decision packets.
  • Define a chassis data pack struct for publishing robot status and power buffer to the chassis module.

Enhancements:

  • Simplify launcher pack population to reuse full robot status and newly available referee fields.
  • Apply minor formatting and signature alignment cleanups in referee communication helpers.

@sourcery-ai

sourcery-ai Bot commented May 8, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors the referee launcher/chassis data packs to carry richer status (buff, launcher, and dart data), introduces a sentry namespace with state enum and helper methods for sentry decision/remote‑purchase packets, and makes minor formatting cleanups to the referee communication helpers, while updating pack publishing to use the new fields.

Sequence diagram for Sentry remote purchase and pack sending

sequenceDiagram
    actor Operator
    participant Referee
    participant Data
    participant SentryDecisionData as SentryData
    participant UART

    Operator->>Referee: SetBulletRemote(bullet_number)
    Referee->>Data: access sentry_dec_data
    Data->>SentryData: get reference
    Referee->>SentryData: remote_buy_bullet_times += 1
    Referee->>SentryData: buy_bullet_num += bullet_number

    Operator->>Referee: SetRevivalRemote(revival)
    Referee->>Data: access sentry_dec_data
    Data->>SentryData: get reference
    Referee->>SentryData: buy_resurrection = revival

    Operator->>Referee: SetSwitchMode(state)
    Referee->>Data: access sentry_dec_data
    Data->>SentryData: get reference
    Referee->>SentryData: current_state = state

    Operator->>Referee: SendSentryPack()
    Referee->>Data: read sentry_dec_data
    Referee->>UART: SendStudentCmd(REF_STDNT_CMD_ID_SENTRY_DECISION, sender_id, receiver_id, sentry_dec_data)
Loading

Class diagram for updated Referee packs and Sentry helpers

classDiagram
    class Referee {
        +LauncherPack lp_
        +ChassisPack cp_
        +SentryPack sp_
        +Data data_
        +LibXR_UART* uart_
        +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, PayloadType payload)
        +LibXR_ErrorCode SendUILayerDelete(uint16_t sender_id, uint16_t receiver_id, UILayerDelete payload)
        +LibXR_ErrorCode SendUIFigure(uint16_t sender_id, uint16_t receiver_id, UIFigure payload)
        +LibXR_ErrorCode SendUIFigure2(uint16_t sender_id, uint16_t receiver_id, UIFigure2 payload)
        +LibXR_ErrorCode SendUIFigure5(uint16_t sender_id, uint16_t receiver_id, UIFigure5 payload)
        +LibXR_ErrorCode SendUIFigure7(uint16_t sender_id, uint16_t receiver_id, UIFigure7 payload)
        +LibXR_ErrorCode SendUICharacter(uint16_t sender_id, uint16_t receiver_id, UICharacter payload)
        +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()
    }

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

    class ChassisPack {
        +RobotStatus rs
        +uint16_t power_buffer
    }

    class SentryPack {
        +RobotStatus rs
        +GameStatus gs
        +SentryDecisionData sentry_dec_data
    }

    class Data {
        +RobotStatus robot_status
        +PowerHeat power_heat
        +RobotBuff robot_buff
        +LauncherData launcher_data
        +DartClient dart_client
        +SentryDecisionData sentry_dec_data
        +bool confirm_resurrection
    }

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

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

    Referee --> LauncherPack : uses
    Referee --> ChassisPack : uses
    Referee --> SentryPack : uses
    Referee --> Data : owns
    Data --> SentryDecisionData : has
    Data --> RobotStatus : has
    Data --> PowerHeat : has
    Data --> RobotBuff : has
    Data --> LauncherData : has
    Data --> DartClient : has
    SentryDecisionData --> State : uses
    LauncherPack --> RobotStatus : has
    LauncherPack --> RobotBuff : has
    LauncherPack --> LauncherData : has
    LauncherPack --> DartClient : has
    ChassisPack --> RobotStatus : has
    SentryPack --> RobotStatus : has
    SentryPack --> GameStatus : has
    SentryPack --> SentryDecisionData : has
Loading

File-Level Changes

Change Details Files
Extend launcher and chassis data packs to carry richer referee data
  • LauncherPack now carries RobotStatus, RobotBuff, LauncherData, and DartClient instead of manually exposing individual heat fields
  • ChassisPack definition is kept but its comment and role are clarified as the chassis module’s packet
  • LauncherPack publish logic is updated to populate the new fields from the internal referee data (robot_status, robot_buff, launcher_data, dart_client)
Referee.hpp
Introduce sentry namespace with state enum and helper APIs for sentry decision / exchange behavior
  • Add Sentry namespace and State enum (ATTACH, DEFEND, GUERRILLA) to represent sentry posture
  • Add SetNeedBullet, SetConfirmRevival, SetBulletRemote, SetHPRemote, SetRevivalRemote, and SetSwitchMode helpers to manipulate sentry_dec_data and confirm_resurrection on the referee data model
  • Add SendSentryPack helper to send sentry_dec_data via SendStudentCmd with command ID 0x0120 and proper sender/receiver IDs
Referee.hpp
Minor cleanups to Referee communication helpers and constructor
  • Remove outdated TODO comment on semaphore-based operation timeout in Referee constructor
  • Normalize indentation/line breaking in SendFrame, SendStudentCmd, various SendUI* helper signatures, and uart_->Read call in FindHeader to improve readability
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 2 issues, and left some high level feedback:

  • The functions inside the new namespace Sentry (e.g., SetNeedBullet, SetConfirmRevival, etc.) use this-> but are not declared as members of any class; if these are intended as Referee methods they should be defined as Referee::Set... outside the class or moved into the class body instead of a free-function namespace.
  • The enum class State in namespace Sentry is missing a terminating semicolon after the closing brace, which will prevent the code from compiling.
  • SetNeedBullet and SetBulletRemote increment buy_bullet_num instead of setting it to the passed value, which conflicts with the naming/documentation that imply they are setters; consider either renaming to reflect additive semantics or assigning instead of incrementing to avoid confusion.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The functions inside the new `namespace Sentry` (e.g., `SetNeedBullet`, `SetConfirmRevival`, etc.) use `this->` but are not declared as members of any class; if these are intended as `Referee` methods they should be defined as `Referee::Set...` outside the class or moved into the class body instead of a free-function namespace.
- The `enum class State` in `namespace Sentry` is missing a terminating semicolon after the closing brace, which will prevent the code from compiling.
- `SetNeedBullet` and `SetBulletRemote` increment `buy_bullet_num` instead of setting it to the passed value, which conflicts with the naming/documentation that imply they are setters; consider either renaming to reflect additive semantics or assigning instead of incrementing to avoid confusion.

## Individual Comments

### Comment 1
<location path="Referee.hpp" line_range="1007-1016" />
<code_context>
+   * @brief 哨兵相关包定义及发包函数封装
+   *
+   */
+  namespace Sentry{
+
+    /**
+     * @brief 哨兵姿态
+     *
+     */
+  enum class State : uint8_t{
+      ATTACH = 0,
+      DEFEND = 1,
+      GUERRILLA = 2,
+    }
+
   /**
</code_context>
<issue_to_address>
**issue (bug_risk):** Declaring a namespace inside the class body is ill-formed C++ and `enum class State` is missing its terminating semicolon.

Since this lives inside `Referee`, you’ll need to either move `namespace Sentry { ... }` out of the class or convert it to a nested type (e.g., `struct Sentry { ... };` or `class Sentry { ... };`) if it should conceptually belong to `Referee`. Don’t forget to add the trailing `;` after `enum class State`’s closing brace.
</issue_to_address>

### Comment 2
<location path="Referee.hpp" line_range="1088-1090" />
<code_context>
+   *
+   * @note 在定时器线程里,按裁判系统带宽要求调用这个函数
+   */
+  void SendSentryPack(){
+    // SendFrame<SentryDecisionData>(, this->data_.sentry_dec_data);
+    SendStudentCmd(0x0120, GetRobotID(), 0x8080, this->data_.sentry_dec_data);
+  }
+  }
</code_context>
<issue_to_address>
**suggestion:** Hard-coded command and receiver IDs reduce readability and are error-prone.

Please align this with the other send helpers by using the `CMDID` enum and named/typed parameters instead of `0x0120` and `0x8080`. This will make the protocol intent clearer and avoid having to hunt for magic numbers if IDs change later.

Suggested implementation:

```
  /**
   * @brief 发送哨兵包
   *
   * @note 在定时器线程里,按裁判系统带宽要求调用这个函数
   */
  void SendSentryPack() {
    SendStudentCmd(CMDID::kSentryDecision, GetRobotID(), kSentryClientID, this->data_.sentry_dec_data);
  }

```

To fully align this with the rest of the codebase, you should also:

1. Ensure the `CMDID` enum defines a value corresponding to the `0x0120` command ID, e.g.:
   - `kSentryDecision = 0x0120,` (or whatever name matches your existing naming style).
2. Define a named constant for the receiver ID (replacing `0x8080`), in the same place other client IDs are defined, e.g.:
   - `constexpr uint16_t kSentryClientID = 0x8080;`
3. Confirm that `SendStudentCmd` is declared to take a `CMDID` (or compatible type) as its first parameter and that other send helpers use the same pattern:
   - `void SendStudentCmd(CMDID cmd_id, RobotID sender, uint16_t receiver, const SentryDecisionData& data);`
4. If your project uses a different naming convention for command IDs or client IDs, rename `kSentryDecision` / `kSentryClientID` to match those conventions.
</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 Outdated
Comment thread Referee.hpp Outdated
Comment on lines +1088 to +1090
void SendSentryPack(){
// SendFrame<SentryDecisionData>(, this->data_.sentry_dec_data);
SendStudentCmd(0x0120, GetRobotID(), 0x8080, this->data_.sentry_dec_data);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Hard-coded command and receiver IDs reduce readability and are error-prone.

Please align this with the other send helpers by using the CMDID enum and named/typed parameters instead of 0x0120 and 0x8080. This will make the protocol intent clearer and avoid having to hunt for magic numbers if IDs change later.

Suggested implementation:

  /**
   * @brief 发送哨兵包
   *
   * @note 在定时器线程里,按裁判系统带宽要求调用这个函数
   */
  void SendSentryPack() {
    SendStudentCmd(CMDID::kSentryDecision, GetRobotID(), kSentryClientID, this->data_.sentry_dec_data);
  }

To fully align this with the rest of the codebase, you should also:

  1. Ensure the CMDID enum defines a value corresponding to the 0x0120 command ID, e.g.:
    • kSentryDecision = 0x0120, (or whatever name matches your existing naming style).
  2. Define a named constant for the receiver ID (replacing 0x8080), in the same place other client IDs are defined, e.g.:
    • constexpr uint16_t kSentryClientID = 0x8080;
  3. Confirm that SendStudentCmd is declared to take a CMDID (or compatible type) as its first parameter and that other send helpers use the same pattern:
    • void SendStudentCmd(CMDID cmd_id, RobotID sender, uint16_t receiver, const SentryDecisionData& data);
  4. If your project uses a different naming convention for command IDs or client IDs, rename kSentryDecision / kSentryClientID to match those conventions.

@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