mirror of
https://github.com/nasa/trick.git
synced 2024-12-20 05:37:55 +00:00
Add VariableServerSession command to have ip_parse interpret python code.
This commit is contained in:
parent
63605da069
commit
2afa2b3e38
@ -1,8 +1,5 @@
|
|||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
PURPOSE: (Represent Websocket variable server connection.)
|
PURPOSE: (Represent Websocket variable server connection.)
|
||||||
LIBRARY DEPENDENCIES:
|
|
||||||
( (../src/VariableServerSession.o))
|
|
||||||
|
|
||||||
|
|
||||||
Messages sent from Client to Server
|
Messages sent from Client to Server
|
||||||
================================
|
================================
|
||||||
@ -17,6 +14,9 @@ LIBRARY DEPENDENCIES:
|
|||||||
{ "cmd" : "var_cycle",
|
{ "cmd" : "var_cycle",
|
||||||
"period" : <int>
|
"period" : <int>
|
||||||
}
|
}
|
||||||
|
{ "cmd" : "python",
|
||||||
|
"pycode" : <str>
|
||||||
|
}
|
||||||
|
|
||||||
Messages sent from Server to Client
|
Messages sent from Server to Client
|
||||||
=================================
|
=================================
|
||||||
|
@ -5,13 +5,16 @@ LIBRARY DEPENDENCIES:
|
|||||||
(VariableServerVariable.o)
|
(VariableServerVariable.o)
|
||||||
)
|
)
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iomanip> // for setprecision
|
#include <iomanip> // for setprecision
|
||||||
#include "trick/memorymanager_c_intf.h"
|
#include "trick/memorymanager_c_intf.h"
|
||||||
|
#include "trick/input_processor_proto.h"
|
||||||
#include "trick/exec_proto.h"
|
#include "trick/exec_proto.h"
|
||||||
#include "../include/VariableServerSession.hh"
|
#include "../include/VariableServerSession.hh"
|
||||||
#include "../include/simpleJSON.hh"
|
#include "../include/simpleJSON.hh"
|
||||||
|
|
||||||
|
|
||||||
// CONSTRUCTOR
|
// CONSTRUCTOR
|
||||||
VariableServerSession::VariableServerSession( struct mg_connection *nc ) : WebSocketSession(nc) {
|
VariableServerSession::VariableServerSession( struct mg_connection *nc ) : WebSocketSession(nc) {
|
||||||
intervalTimeTics = exec_get_time_tic_value(); // Default time interval is one second.
|
intervalTimeTics = exec_get_time_tic_value(); // Default time interval is one second.
|
||||||
@ -58,8 +61,9 @@ int VariableServerSession::handleMessage(std::string client_msg) {
|
|||||||
int status = 0;
|
int status = 0;
|
||||||
std::vector<Member*> members = parseJSON(client_msg.c_str());
|
std::vector<Member*> members = parseJSON(client_msg.c_str());
|
||||||
std::vector<Member*>::iterator it;
|
std::vector<Member*>::iterator it;
|
||||||
const char *cmd;
|
std::string cmd;
|
||||||
const char *var_name;
|
std::string var_name;
|
||||||
|
std::string pycode;
|
||||||
int period;
|
int period;
|
||||||
|
|
||||||
for (it = members.begin(); it != members.end(); it++ ) {
|
for (it = members.begin(); it != members.end(); it++ ) {
|
||||||
@ -69,51 +73,42 @@ int VariableServerSession::handleMessage(std::string client_msg) {
|
|||||||
var_name = (*it)->valText;
|
var_name = (*it)->valText;
|
||||||
} else if (strcmp((*it)->key, "period") == 0) {
|
} else if (strcmp((*it)->key, "period") == 0) {
|
||||||
period = atoi((*it)->valText);
|
period = atoi((*it)->valText);
|
||||||
|
} else if (strcmp((*it)->key, "pycode") == 0) {
|
||||||
|
pycode = (*it)->valText;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd == NULL) {
|
if (cmd.empty()) {
|
||||||
printf ("No \"cmd\" member found in client message.\n");
|
printf ("No \"cmd\" member found in client message.\n");
|
||||||
status = 1;
|
status = 1;
|
||||||
} else if (strcmp(cmd, "var_add") == 0) {
|
} else if (cmd == "var_add") {
|
||||||
addVariable( strdup(var_name) );
|
addVariable( strdup( var_name.c_str()));
|
||||||
} else if ( strcmp(cmd, "var_cycle") == 0 ) {
|
} else if (cmd == "var_cycle") {
|
||||||
setTimeInterval(period);
|
setTimeInterval(period);
|
||||||
} else if ( strcmp(cmd, "var_pause") == 0 ) {
|
} else if (cmd == "var_pause") {
|
||||||
pause();
|
pause();
|
||||||
} else if ( strcmp(cmd, "var_unpause") == 0 ) {
|
} else if (cmd == "var_unpause") {
|
||||||
unpause();
|
unpause();
|
||||||
} else if ( strcmp(cmd, "var_send") == 0 ) {
|
} else if (cmd == "var_send") {
|
||||||
stageVariableValues();
|
stageVariableValues();
|
||||||
sendMessage();
|
sendMessage();
|
||||||
} else if ( strcmp(cmd, "var_clear") == 0 ) {
|
} else if (cmd == "var_clear") {
|
||||||
clear();
|
clear();
|
||||||
} else if ( strcmp(cmd, "var_exit") == 0 ) {
|
} else if (cmd == "var_exit") {
|
||||||
//TODO
|
//TODO
|
||||||
// nc->flags |= MG_F_SEND_AND_CLOSE;
|
// nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||||
|
} else if (cmd == "python") {
|
||||||
|
// Remove carriage-returns from pycode.
|
||||||
|
pycode.erase(std::remove(pycode.begin(), pycode.end(), '\r'), pycode.end());
|
||||||
|
// Call the Trick input processor.
|
||||||
|
ip_parse(pycode.c_str());
|
||||||
} else {
|
} else {
|
||||||
sendErrorMessage("Unknown Command: \"%s\".\n", cmd);
|
sendErrorMessage("Unknown Command: \"%s\".\n", cmd.c_str());
|
||||||
status = 1;
|
status = 1;
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// #include "trick/input_processor_proto.h"
|
|
||||||
// for( ii = 0 , jj = 0 ; ii <= msg_len ; ii++ ) {
|
|
||||||
// if ( incoming_msg[ii] != '\r' ) {
|
|
||||||
// stripped_msg[jj++] = incoming_msg[ii] ;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// ip_parse(stripped_msg); /* returns 0 if no parsing error */
|
|
||||||
|
|
||||||
|
|
||||||
// Remove characters from a string
|
|
||||||
// str.erase(std::remove(str.begin(), str.end(), '\r'), str.end());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void VariableServerSession::setTimeInterval(unsigned int milliseconds) {
|
void VariableServerSession::setTimeInterval(unsigned int milliseconds) {
|
||||||
intervalTimeTics = exec_get_time_tic_value() * milliseconds / 1000;
|
intervalTimeTics = exec_get_time_tic_value() * milliseconds / 1000;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user