Skip to content

Commit

Permalink
Support channel map flow message
Browse files Browse the repository at this point in the history
  • Loading branch information
pford committed Oct 23, 2024
1 parent 5562666 commit 9a22d2b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Session/Session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ void Session::OnSetImageChannels(const CARTA::SetImageChannels& message) {
int num_channel(frame->Depth());

// Use animation limits for flow control
int max_frame_rate(15), max_gap(max_frame_rate / 3);
int max_frame_rate(15), max_channel_gap(max_frame_rate / CARTA::InitialAnimationWaitsPerSecond);
std::chrono::microseconds channel_interval(int64_t(1.0e6 / max_frame_rate));

for (int chan = start_channel; chan <= end_channel; ++chan) {
Expand All @@ -780,6 +780,14 @@ void Session::OnSetImageChannels(const CARTA::SetImageChannels& message) {
continue;
}

if (_channel_map_received_channel.find(file_id) != _channel_map_received_channel.end()) {
int received_channel = _channel_map_received_channel[file_id];
while (chan - received_channel > max_channel_gap) {
std::this_thread::sleep_for(channel_interval);
received_channel = _channel_map_received_channel[file_id];
}
}

auto start_time = std::chrono::high_resolution_clock::now();
spdlog::debug("Send channel {} in range {}-{}", chan, start_channel, end_channel);
OnAddRequiredTiles(message.required_tiles(), chan);
Expand Down Expand Up @@ -2580,3 +2588,7 @@ bool Session::IsInChannelMapTiles(int file_id, int tile) {
// Check if tile is in current channel map tiles for file id.
return _channel_map_settings && _channel_map_settings->HasTile(file_id, tile);
}

void Session::HandleChannelMapFlowControlEvt(CARTA::ChannelMapFlowControl& message) {
_channel_map_received_channel[message.file_id()] = message.received_channel();
}
3 changes: 3 additions & 0 deletions src/Session/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class Session {
void ExecuteSetChannelEvt(std::pair<CARTA::SetImageChannels, uint32_t> request) {
OnSetImageChannels(request.first);
}
void HandleChannelMapFlowControlEvt(CARTA::ChannelMapFlowControl& message);

void CancelSetHistRequirements() {
_histogram_context.cancel_group_execution();
}
Expand Down Expand Up @@ -307,6 +309,7 @@ class Session {
std::unordered_map<int, std::mutex> _image_channel_mutexes;
std::unordered_map<int, bool> _image_channel_task_active;
std::unique_ptr<ChannelMapSettings> _channel_map_settings;
std::unordered_map<int, int> _channel_map_received_channel;

// Cube histogram progress: 0.0 to 1.0 (complete)
float _histogram_progress;
Expand Down
8 changes: 8 additions & 0 deletions src/Session/SessionManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,14 @@ void SessionManager::OnMessage(WSType* ws, std::string_view sv_message, uWS::OpC
}
break;
}
case CARTA::EventType::CHANNEL_MAP_FLOW_CONTROL: {
CARTA::ChannelMapFlowControl message;
if (message.ParseFromArray(event_buf, event_length)) {
session->HandleChannelMapFlowControlEvt(message);
message_parsed = true;
}
break;
}
default: {
spdlog::warn("Bad event type {}!", event_type);
break;
Expand Down
7 changes: 7 additions & 0 deletions src/Util/Message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,13 @@ CARTA::ScriptingRequest Message::ScriptingRequest(uint32_t scripting_request_id,
return message;
}

CARTA::ChannelMapFlowControl Message::ChannelMapFlowControl(int32_t file_id, int32_t received_channel) {
CARTA::ChannelMapFlowControl message;
message.set_file_id(file_id);
message.set_received_channel(received_channel);
return message;
}

CARTA::EventType Message::EventType(std::vector<char>& message) {
carta::EventHeader head = *reinterpret_cast<const carta::EventHeader*>(message.data());
return static_cast<CARTA::EventType>(head.type);
Expand Down
2 changes: 2 additions & 0 deletions src/Util/Message.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define CARTA_SRC_UTIL_MESSAGE_H_

#include <carta-protobuf/animation.pb.h>
#include <carta-protobuf/channel_map.pb.h>
#include <carta-protobuf/close_file.pb.h>
#include <carta-protobuf/contour_image.pb.h>
#include <carta-protobuf/defs.pb.h>
Expand Down Expand Up @@ -115,6 +116,7 @@ class Message {
const CARTA::DoublePoint& center, double amp, const CARTA::DoublePoint& fwhm, double pa);
static CARTA::ScriptingRequest ScriptingRequest(uint32_t scripting_request_id, const std::string& target, const std::string& action,
const std::string& parameters, bool async, const std::string& return_path);
static CARTA::ChannelMapFlowControl ChannelMapFlowControl(int32_t file_id, int32_t received_channel);

// Response messages
static CARTA::SpectralProfileData SpectralProfileData(int32_t file_id, int32_t region_id, int32_t stokes, float progress,
Expand Down

0 comments on commit 9a22d2b

Please sign in to comment.