Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1720 websocket freeze issue #1724

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions trick_source/web/CivetServer/include/VariableServerSession.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ PURPOSE: (Represent the state of a variable server websocket connection.)
#endif

#include "trick/WebSocketSession.hh"
#include "trick/Executive.hh"
#include "VariableServerVariable.hh"

class VariableServerSession : public WebSocketSession {
Expand All @@ -38,13 +39,15 @@ class VariableServerSession : public WebSocketSession {
int sendSieMessage(void);
int sendUnitsMessage(const char* vname);
REF2* make_error_ref(const char* in_name);
void updateNextTime(long long simTimeTics);
double stageTime;
bool dataStaged;

std::vector<VariableServerVariable*> sessionVariables;
bool cyclicSendEnabled;
long long nextTime;
long long intervalTimeTics;
SIM_MODE mode;
};

WebSocketSession* makeVariableServerSession( struct mg_connection *nc );
Expand Down
21 changes: 19 additions & 2 deletions trick_source/web/CivetServer/src/VariableServerSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ VariableServerSession::VariableServerSession( struct mg_connection *nc ) : WebSo
intervalTimeTics = exec_get_time_tic_value(); // Default time interval is one second.
nextTime = 0;
cyclicSendEnabled = false;
mode = Initialization;
}

// DESTRUCTOR
VariableServerSession::~VariableServerSession() {
clear();
}

void VariableServerSession::updateNextTime(long long simTimeTics) {
nextTime = (simTimeTics - (simTimeTics % intervalTimeTics) + intervalTimeTics);
}

/* Base class virtual function: marshallData
When HTTP_Server::time_homogeneous is set, WebSocketSession::marshallData() is
called from the main sim thread in a "top_of_frame" job, to ensure that all of
Expand All @@ -41,11 +46,23 @@ VariableServerSession::~VariableServerSession() {
(The specified period between messages).
*/
void VariableServerSession::marshallData() {
long long simulation_time_tics = exec_get_time_tics() + exec_get_freeze_time_tics();
long long simulation_time_tics = exec_get_time_tics();
SIM_MODE new_mode = the_exec->get_mode();

if(new_mode == Freeze) {
simulation_time_tics += exec_get_freeze_time_tics();
}

if(new_mode != mode) {
mode = new_mode;
updateNextTime(simulation_time_tics);
}

if ( cyclicSendEnabled && ( simulation_time_tics >= nextTime )) {
stageValues();
nextTime = (simulation_time_tics - (simulation_time_tics % intervalTimeTics) + intervalTimeTics);
updateNextTime(simulation_time_tics);
}

}

/* Base class virtual function: sendMessage
Expand Down
Loading