Dev#12
Conversation
Reviewer's GuideRefactors 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 sendingsequenceDiagram
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)
Class diagram for updated Referee packs and Sentry helpersclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- The functions inside the new
namespace Sentry(e.g.,SetNeedBullet,SetConfirmRevival, etc.) usethis->but are not declared as members of any class; if these are intended asRefereemethods they should be defined asReferee::Set...outside the class or moved into the class body instead of a free-function namespace. - The
enum class Stateinnamespace Sentryis missing a terminating semicolon after the closing brace, which will prevent the code from compiling. SetNeedBulletandSetBulletRemoteincrementbuy_bullet_numinstead 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| void SendSentryPack(){ | ||
| // SendFrame<SentryDecisionData>(, this->data_.sentry_dec_data); | ||
| SendStudentCmd(0x0120, GetRobotID(), 0x8080, this->data_.sentry_dec_data); |
There was a problem hiding this comment.
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:
- Ensure the
CMDIDenum defines a value corresponding to the0x0120command ID, e.g.:kSentryDecision = 0x0120,(or whatever name matches your existing naming style).
- 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;
- Confirm that
SendStudentCmdis declared to take aCMDID(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);
- If your project uses a different naming convention for command IDs or client IDs, rename
kSentryDecision/kSentryClientIDto match those conventions.
加入哨兵命名空间
同步launcher pack
Summary by Sourcery
Extend referee data packs and add high-level control helpers for the sentry robot.
New Features:
Enhancements: