Skip to content

Commit

Permalink
Add new function.
Browse files Browse the repository at this point in the history
  • Loading branch information
GuraMumei committed Apr 16, 2024
1 parent 2d0da61 commit 7210d7a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
8 changes: 4 additions & 4 deletions rm_referee/src/referee_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,16 +293,16 @@ void RefereeBase::updateEnemyHeroState(const rm_msgs::GameRobotHp& game_robot_hp
if (base_.robot_id_ < 100 && base_.robot_id_ != RED_SENTRY)
{
if (game_robot_hp_data.blue_1_robot_hp > 0)
data = L"敌英雄存活:" + std::to_wstring(game_robot_hp_data.blue_1_robot_hp);
data = L"敌方英雄存活:" + std::to_wstring(game_robot_hp_data.blue_1_robot_hp);
else
data = L"敌英雄死亡";
data = L"敌方英雄死亡";
}
else if (base_.robot_id_ >= 100 && base_.robot_id_ != BLUE_SENTRY)
{
if (game_robot_hp_data.red_1_robot_hp > 0)
data = L"敌英雄存活:" + std::to_wstring(game_robot_hp_data.red_1_robot_hp);
data = L"敌方英雄存活:" + std::to_wstring(game_robot_hp_data.red_1_robot_hp);
else
data = L"敌英雄死亡";
data = L"敌方英雄死亡";
}
else
return;
Expand Down
31 changes: 13 additions & 18 deletions rm_referee/src/ui/ui_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,33 +230,28 @@ void UiBase::sendMapSentryData(const rm_referee::MapSentryData& data)

void UiBase::sendCustomInfoData(std::wstring data)
{
uint8_t tx_data[sizeof(rm_referee::CustomInfo)] = { 0 };
auto custom_info = (rm_referee::CustomInfo*)tx_data;
int data_len;
rm_referee::CustomInfo tx_data;
data_len = static_cast<int>(sizeof(rm_referee::CustomInfo));

tx_data.sender_id = base_.robot_id_;
tx_data.receiver_id = base_.client_id_;

uint16_t characters[15];
for (int i = 0; i < 15; i++)
{
if (i < static_cast<int>(data.size()))
characters[i] = static_cast<uint16_t>(data[i]);
else
characters[i] = static_cast<uint16_t>(L' ');
}
for (int i = 0; i < 15; i++)
{
custom_info->user_data[2 * i] = characters[i] & 0xFF;
custom_info->user_data[2 * i + 1] = (characters[i] >> 8) & 0xFF;
}
custom_info->sender_id = base_.robot_id_;
custom_info->receiver_id = base_.client_id_;
pack(tx_buffer_, tx_data, rm_referee::RefereeCmdId::CUSTOM_INFO_CMD, sizeof(rm_referee::CustomInfo));
tx_len_ =
k_header_length_ + k_cmd_id_length_ + static_cast<int>(sizeof(rm_referee::ClientMapReceiveData) + k_tail_length_);

try
{
base_.serial_.write(tx_buffer_, tx_len_);
}
catch (serial::PortNotOpenedException& e)
{
tx_data.user_data[2 * i] = characters[i] & 0xFF;
tx_data.user_data[2 * i + 1] = (characters[i] >> 8) & 0xFF;
}
clearTxBuffer();
pack(tx_buffer_, reinterpret_cast<uint8_t*>(&tx_data), rm_referee::RefereeCmdId::CUSTOM_INFO_CMD, data_len);
sendSerial(ros::Time::now(), data_len);
}

void UiBase::sendRadarInteractiveData(const rm_referee::ClientMapReceiveData& data)
Expand Down

0 comments on commit 7210d7a

Please sign in to comment.