Skip to content

Commit 2de12f3

Browse files
committed
refactor: processPacket の重複チェック早期化とマジックナンバー解消
- check_counter の重複検査を deserialize() と位置マッチングの前に移動し、 重複パケット時の不要な演算(デシリアライズ・位置マッチング)をスキップするよう改善 - チームループのマジックナンバー 2 を config.h の TEAM_COUNT 定数に置換 - 自明なインラインコメント(skip robot_id byte)を削除
1 parent 229bb34 commit 2de12f3

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/ibis_command_receiver.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,20 @@ void IbisCommandReceiver::processPacket(const QByteArray& data, Robot** robots,
206206
continue;
207207
}
208208

209-
const uint8_t* cmd_data = buf + offset + 1; // skip robot_id byte
209+
const uint8_t* cmd_data = buf + offset + 1;
210+
211+
// Skip duplicate packets (check_counter unchanged)
212+
if (cmd_data[CHECK_COUNTER] == robot_states_[robot_id].last_check_counter) {
213+
continue;
214+
}
215+
210216
IbisCommand cmd = deserialize(cmd_data);
211217

212218
// Auto-detect team: find robot whose position matches vision_global_pos in the packet.
213219
// crane's vision_global_pos is in metres using the same coordinate system as grSim.
214220
Robot* target = nullptr;
215221
constexpr double POSITION_MATCH_THRESHOLD = 0.5; // metres
216-
for (int t = 0; t < 2; ++t) {
222+
for (int t = 0; t < TEAM_COUNT; ++t) {
217223
int idx = (t == 0) ? robot_id : (robotCount + robot_id);
218224
if (idx >= MAX_ROBOT_COUNT * 2 || robots[idx] == nullptr) {
219225
continue;
@@ -232,10 +238,6 @@ void IbisCommandReceiver::processPacket(const QByteArray& data, Robot** robots,
232238
continue;
233239
}
234240

235-
// Skip duplicate packets (check_counter unchanged)
236-
if (cmd.check_counter == robot_states_[robot_id].last_check_counter) {
237-
continue;
238-
}
239241
robot_states_[robot_id].last_check_counter = cmd.check_counter;
240242

241243
applyCommand(robot_id, cmd, target);

0 commit comments

Comments
 (0)