From 05e9535518d16ae0a61750d0bd8ddf646e7dc2a8 Mon Sep 17 00:00:00 2001 From: "Penn, John M 047828115" Date: Wed, 17 Apr 2019 16:35:29 -0500 Subject: [PATCH 1/9] Add MemoryManager methods to generate JSON for allocation info. #755 --- include/trick/MemoryManager.hh | 3 + .../MemoryManager/MemoryManager_JSON_Intf.cpp | 64 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 trick_source/sim_services/MemoryManager/MemoryManager_JSON_Intf.cpp diff --git a/include/trick/MemoryManager.hh b/include/trick/MemoryManager.hh index 1aead346..36776831 100644 --- a/include/trick/MemoryManager.hh +++ b/include/trick/MemoryManager.hh @@ -658,6 +658,9 @@ namespace Trick { static void emitError( std::string s); static void emitWarning( std::string s); + void write_JSON_alloc_info( std::ostream& s, ALLOC_INFO *alloc_info) ; + void write_JSON_alloc_list( std::ostream& s, int start_ix, int num) ; + private: static int instance_count; /**< -- Number of instances of MemoryManager. Not allowed to exceed 1.*/ diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_JSON_Intf.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_JSON_Intf.cpp new file mode 100644 index 00000000..0bef9fbd --- /dev/null +++ b/trick_source/sim_services/MemoryManager/MemoryManager_JSON_Intf.cpp @@ -0,0 +1,64 @@ +#include +#include "trick/MemoryManager.hh" + +void Trick::MemoryManager::write_JSON_alloc_info(std::ostream& s, ALLOC_INFO *alloc_info) { + s << "{" << std::endl; + if (!alloc_info->name) { + s << "\"name\":null," << std::endl; + } else { + s << "\"name\":\"" << alloc_info->name << "\"," << std::endl; + } + s << "\"start\":\"" << alloc_info->start << "\"," << std::endl; + s << "\"end\":\"" << alloc_info->end << "\"," << std::endl; + s << "\"num\":\"" << alloc_info->num << "\"," << std::endl; + s << "\"size\":\"" << alloc_info->size << "\"," << std::endl; + s << "\"type\":\"" << trickTypeCharString(alloc_info->type, alloc_info->user_type_name) << "\"," << std::endl; + s << "\"stcl\":" ; + if (alloc_info->stcl == TRICK_LOCAL) { + s << "\"TRICK_LOCAL\"," << std::endl; + } + if (alloc_info->stcl == TRICK_EXTERN) { + s << "\"TRICK_EXTERN\"," << std::endl; + } + s << "\"language\":"; + if (alloc_info->language == Language_C ) { + s << "\"Language_C\"," << std::endl; + } + if (alloc_info->language == Language_CPP) { + s << "\"Language_CPP\"," << std::endl; + } + s << "\"index\": [" ; + for (int ii=0; iinum_index; ii++) { + if (ii != 0) { + s << "," ; + } + s << alloc_info->index[ii] ; + } + s << "]}" ; +} + + +void Trick::MemoryManager::write_JSON_alloc_list(std::ostream& s, int chunk_start, int chunk_size) { + + ALLOC_INFO_MAP::iterator pos; + ALLOC_INFO* alloc_info; + + int size = alloc_info_map.size(); + s << "{" << std::endl; + s << "\"alloc_total\":" << size << "," << std::endl; + s << "\"chunk_size\":" << chunk_size << "," << std::endl; + s << "\"chunk_start\":" << chunk_start << "," << std::endl; + s << "\"alloc_list\":[" << std::endl; + pos = alloc_info_map.begin(); + std::advance(pos, chunk_start); + + for (int count = 0; count < chunk_size && pos!=alloc_info_map.end() ; pos++, count++) { + alloc_info = pos->second; + if (count != 0) { + s << "," << std::endl; + } + write_JSON_alloc_info(s, alloc_info); + } + s << "]}" << std::endl; +} + From 0f037e681713aa9faa7c8c0a9e50b9d0cb44fc79 Mon Sep 17 00:00:00 2001 From: "Penn, John M 047828115" Date: Wed, 17 Apr 2019 16:43:12 -0500 Subject: [PATCH 2/9] Update trickTypeCharString() for STLs, so their names can be generated. #755 --- trick_source/sim_services/MemoryManager/trickTypeCharString.c | 1 + 1 file changed, 1 insertion(+) diff --git a/trick_source/sim_services/MemoryManager/trickTypeCharString.c b/trick_source/sim_services/MemoryManager/trickTypeCharString.c index e032d583..9b5da46a 100644 --- a/trick_source/sim_services/MemoryManager/trickTypeCharString.c +++ b/trick_source/sim_services/MemoryManager/trickTypeCharString.c @@ -29,6 +29,7 @@ const char* trickTypeCharString( TRICK_TYPE type, const char* name) { case TRICK_ENUMERATED: type_spec = name; break; case TRICK_STRUCTURED: type_spec = name; break; case TRICK_OPAQUE_TYPE: type_spec = name; break; + case TRICK_STL: type_spec = name; break; default: type_spec = "UNKNOWN_TYPE"; break; } return (type_spec); From b029fae692a0b5d3c64087b474edc88ab01a2238 Mon Sep 17 00:00:00 2001 From: "Penn, John M 047828115" Date: Wed, 17 Apr 2019 17:26:48 -0500 Subject: [PATCH 3/9] Add an experimental mongoose-based embedded web server to SIM_cannon_numeric #756 --- trick_sims/Cannon/SIM_cannon_numeric/S_define | 15 ++ .../Cannon/SIM_cannon_numeric/S_overrides.mk | 7 +- .../www/apps/alloc_info.html | 156 ++++++++++++++++++ .../www/apps/vs_connections.html | 74 +++++++++ .../SIM_cannon_numeric/www/apps/wsexp.html | 41 +++++ .../Cannon/SIM_cannon_numeric/www/index.html | 28 ++++ .../mongoose_httpd/include/http_server.h | 33 ++++ .../models/mongoose_httpd/src/http_server.cpp | 150 +++++++++++++++++ 8 files changed, 502 insertions(+), 2 deletions(-) create mode 100644 trick_sims/Cannon/SIM_cannon_numeric/www/apps/alloc_info.html create mode 100644 trick_sims/Cannon/SIM_cannon_numeric/www/apps/vs_connections.html create mode 100644 trick_sims/Cannon/SIM_cannon_numeric/www/apps/wsexp.html create mode 100644 trick_sims/Cannon/SIM_cannon_numeric/www/index.html create mode 100644 trick_sims/Cannon/models/mongoose_httpd/include/http_server.h create mode 100644 trick_sims/Cannon/models/mongoose_httpd/src/http_server.cpp diff --git a/trick_sims/Cannon/SIM_cannon_numeric/S_define b/trick_sims/Cannon/SIM_cannon_numeric/S_define index e63fd141..54566b93 100644 --- a/trick_sims/Cannon/SIM_cannon_numeric/S_define +++ b/trick_sims/Cannon/SIM_cannon_numeric/S_define @@ -5,11 +5,25 @@ LIBRARY DEPENDENCIES: ( (cannon/gravity/src/cannon_init.c) (cannon/gravity/src/cannon_numeric.c) + (mongoose_httpd/src/http_server.cpp) ) *************************************************************/ #include "sim_objects/default_trick_sys.sm" ##include "cannon/gravity/include/cannon_numeric.h" +##include "mongoose_httpd/include/http_server.h" + +class HttpSimObject : public Trick::SimObject { + + public: + HTTP_Server http_server ; + + HttpSimObject() { + ("default_data") http_default_data( &http_server ) ; + ("initialization") http_init( &http_server ) ; + ("shutdown") http_shutdown( &http_server ) ; + } +} ; class CannonSimObject : public Trick::SimObject { @@ -27,6 +41,7 @@ class CannonSimObject : public Trick::SimObject { // Instantiations CannonSimObject dyn ; +HttpSimObject http ; IntegLoop dyn_integloop (0.01) dyn; diff --git a/trick_sims/Cannon/SIM_cannon_numeric/S_overrides.mk b/trick_sims/Cannon/SIM_cannon_numeric/S_overrides.mk index a2eff6d4..3a3073fb 100644 --- a/trick_sims/Cannon/SIM_cannon_numeric/S_overrides.mk +++ b/trick_sims/Cannon/SIM_cannon_numeric/S_overrides.mk @@ -1,4 +1,7 @@ -TRICK_CFLAGS += -I../models -TRICK_CXXFLAGS += -I../models +TRICK_CFLAGS += -I/usr/include -I../models +TRICK_CXXFLAGS += -I/usr/include -I../models + +TRICK_LDFLAGS += -L/usr/local/lib +TRICK_USER_LINK_LIBS += -lmongoose diff --git a/trick_sims/Cannon/SIM_cannon_numeric/www/apps/alloc_info.html b/trick_sims/Cannon/SIM_cannon_numeric/www/apps/alloc_info.html new file mode 100644 index 00000000..04bfb75c --- /dev/null +++ b/trick_sims/Cannon/SIM_cannon_numeric/www/apps/alloc_info.html @@ -0,0 +1,156 @@ + + + + +Trick Memory Allocations + + + + + +
+
+
+
+ + + + + diff --git a/trick_sims/Cannon/SIM_cannon_numeric/www/apps/vs_connections.html b/trick_sims/Cannon/SIM_cannon_numeric/www/apps/vs_connections.html new file mode 100644 index 00000000..90dd01a5 --- /dev/null +++ b/trick_sims/Cannon/SIM_cannon_numeric/www/apps/vs_connections.html @@ -0,0 +1,74 @@ + + + + Variable Server Connections + + + +
+
+
+
+ + + diff --git a/trick_sims/Cannon/SIM_cannon_numeric/www/apps/wsexp.html b/trick_sims/Cannon/SIM_cannon_numeric/www/apps/wsexp.html new file mode 100644 index 00000000..322b70c2 --- /dev/null +++ b/trick_sims/Cannon/SIM_cannon_numeric/www/apps/wsexp.html @@ -0,0 +1,41 @@ + + + + WS Experiments + + + +
+
+
+
+ + + diff --git a/trick_sims/Cannon/SIM_cannon_numeric/www/index.html b/trick_sims/Cannon/SIM_cannon_numeric/www/index.html new file mode 100644 index 00000000..cdb04443 --- /dev/null +++ b/trick_sims/Cannon/SIM_cannon_numeric/www/index.html @@ -0,0 +1,28 @@ + + + + Trick Simulation Pages + + + +
+

SIM_cannon_numeric

+
+ + + + + + + diff --git a/trick_sims/Cannon/models/mongoose_httpd/include/http_server.h b/trick_sims/Cannon/models/mongoose_httpd/include/http_server.h new file mode 100644 index 00000000..90efbeca --- /dev/null +++ b/trick_sims/Cannon/models/mongoose_httpd/include/http_server.h @@ -0,0 +1,33 @@ +/************************************************************************* +PURPOSE: (Represent the state and initial conditions of an http server) +**************************************************************************/ +#ifndef HTTP_SERVER_H +#define HTTP_SERVER_H + +#include +#include +#include +#include +#include + +typedef struct { + + struct mg_mgr mgr; /* ** mongoose */ + struct mg_connection *nc; /* ** mongoose */ + const char* port; + pthread_t server_thread; /* ** */ + bool shutting_down; + +} HTTP_Server ; + +#ifdef __cplusplus +extern "C" { +#endif + int http_default_data(HTTP_Server * S) ; + int http_init(HTTP_Server * S) ; + int http_shutdown(HTTP_Server * S) ; +#ifdef __cplusplus +} +#endif + +#endif diff --git a/trick_sims/Cannon/models/mongoose_httpd/src/http_server.cpp b/trick_sims/Cannon/models/mongoose_httpd/src/http_server.cpp new file mode 100644 index 00000000..7300cb9b --- /dev/null +++ b/trick_sims/Cannon/models/mongoose_httpd/src/http_server.cpp @@ -0,0 +1,150 @@ +/************************************************************************ +PURPOSE: (Represent the state and initial conditions of an http server) +**************************************************************************/ +#include "../include/http_server.h" +#include + +#include "trick/VariableServer.hh" +extern Trick::VariableServer * the_vs ; +#include "trick/MemoryManager.hh" +extern Trick::MemoryManager* trick_MM; + +static const struct mg_str s_get_method = MG_MK_STR("GET"); +static const struct mg_str s_put_method = MG_MK_STR("PUT"); +static const struct mg_str s_delele_method = MG_MK_STR("DELETE"); + +int getIntegerQueryValue(struct http_message *hm, const char* key, int defaultVal) { + char value_text[100]; + if ( mg_get_http_var(&(hm->query_string), key, value_text, sizeof(value_text)) > 0) { + return atoi(value_text); + } else { + return defaultVal; + } +} + +void handle_vs_connections_call(struct mg_connection *nc, struct http_message *hm) { + /* Send headers */ + mg_printf(nc, "%s", "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"); + std::stringstream ss; + ss << *the_vs << std::endl; + std::string tmp = ss.str(); + mg_printf_http_chunk(nc, "%s", tmp.c_str()); + mg_send_http_chunk(nc, "", 0); +} + +void handle_alloc_info_call(struct mg_connection *nc, struct http_message *hm) { + int start = getIntegerQueryValue(hm, "start", 0); + int count = getIntegerQueryValue(hm, "count", 10); + mg_printf(nc, "%s", "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"); + std::stringstream ss; + trick_MM->write_JSON_alloc_list(ss, start, count); + std::string tmp = ss.str(); + mg_printf_http_chunk(nc, "%s", tmp.c_str()); + mg_send_http_chunk(nc, "", 0); +} + +static int has_prefix(const struct mg_str *uri, const struct mg_str *prefix) { + return uri->len > prefix->len && memcmp(uri->p, prefix->p, prefix->len) == 0; +} + +static int is_equal(const struct mg_str *s1, const struct mg_str *s2) { + return s1->len == s2->len && memcmp(s1->p, s2->p, s2->len) == 0; +} + +static struct mg_serve_http_opts http_server_options; +static const struct mg_str api_prefix = MG_MK_STR("/api/v1"); + +static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { + + http_message *hm = (struct http_message *)ev_data; + + switch(ev) { + case MG_EV_WEBSOCKET_HANDSHAKE_DONE: { + printf("DEBUG: Event MG_EV_WEBSOCKET_HANDSHAKE_DONE.\n"); + const char* s = "Bingo boingo."; + mg_send_websocket_frame(nc, WEBSOCKET_OP_TEXT, s, strlen(s)); + } break; + case MG_EV_WEBSOCKET_FRAME: { + printf("DEBUG: Event MG_EV_WEBSOCKET_FRAME.\n"); + } break; + case MG_EV_CONNECT: { + printf("DEBUG: Event MG_EV_CONNECT.\n"); + } break; + // case MG_EV_RECV: { + // printf("DEBUG: Event MG_EV_RECV.\n"); + // } break; + // case MG_EV_SEND: { + // printf("DEBUG: Event MG_EV_SEND.\n"); + // } break; + case MG_EV_CLOSE: { + printf("DEBUG: Event MG_EV_CLOSE.\n"); + } break; + // case MG_EV_POLL: { + // printf("DEBUG: Event MG_EV_POLL.\n"); + // } break; + case MG_EV_HTTP_REQUEST: { + printf("DEBUG: Event MG_EV_HTTP_REQUEST.\n"); + char * s = strndup(hm->uri.p, hm->uri.len); + printf("DEBUG: URI = \"%s\"\n", s); + free(s); + if (has_prefix(&hm->uri, &api_prefix)) { + struct mg_str key; + key.p = hm->uri.p + api_prefix.len; + key.len = hm->uri.len - api_prefix.len; + + if (is_equal(&hm->method, &s_get_method)) { + printf("DEBUG: HTTP GET method.\n"); + if (mg_vcmp(&key, "/vs_connections") == 0) { + handle_vs_connections_call(nc, hm); + } else if (mg_vcmp(&key, "/alloc_info") == 0) { + handle_alloc_info_call(nc, hm); + } + } else if (is_equal(&hm->method, &s_put_method)) { + printf("DEBUG: HTTP PUT method.\n"); + } else if (is_equal(&hm->method, &s_delele_method)) { + printf("DEBUG: HTTP DELETE method.\n"); + } + } else { + mg_serve_http(nc, (struct http_message *) ev_data, http_server_options); + } + } break; + default: { + } break; + } +} + +void* service_connections (void* arg) { + HTTP_Server *S = (HTTP_Server*)arg; + while(!S->shutting_down) { + mg_mgr_poll(&S->mgr, 1000); + } + return NULL; +} + +int http_default_data(HTTP_Server *S) { + S->port = "8888"; + S->shutting_down = false; + return 0; +} + +int http_init(HTTP_Server *S) { + http_server_options.document_root = "www"; + http_server_options.enable_directory_listing = "yes"; + mg_mgr_init(&S->mgr, NULL); + printf("Starting web server on port %s\n", S->port); + S->nc = mg_bind(&S->mgr, S->port, ev_handler); + if (S->nc == NULL) { + printf("Failed to create listener.\n"); + return 1; + } + mg_set_protocol_http_websocket(S->nc); + pthread_create( &S->server_thread, NULL, service_connections, (void*)S); + return 0; +} + +int http_shutdown(HTTP_Server *S) { + printf("Shutting down web server on port %s\n", S->port); + S->shutting_down = true; + pthread_join(S->server_thread, NULL); + return 0; +} From 38bfdf2a546d4b0317b806e67edd30c276ffc322 Mon Sep 17 00:00:00 2001 From: nmerlene <35947028+nmerlene@users.noreply.github.com> Date: Wed, 24 Apr 2019 15:45:06 -0500 Subject: [PATCH 4/9] Convert string to bytes in variable_server.py for Python 3 * Method socket.sendall() expects bytes to be sent, rather than a string * Python 3 stores text strings as unicode (not ASCII) by default * Therefore, strings must be explicitly converted to bytes for Python 3 compatibility * This works for both Python 2 and Python 3 (tested on Python 2.7, Python 3.6, and Python 3.7) --- share/trick/pymods/trick/variable_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/share/trick/pymods/trick/variable_server.py b/share/trick/pymods/trick/variable_server.py index 37e67071..ee1406a3 100644 --- a/share/trick/pymods/trick/variable_server.py +++ b/share/trick/pymods/trick/variable_server.py @@ -860,7 +860,7 @@ class VariableServer(object): self.Channel.BOTH: [self._synchronous_socket, self._asynchronous_socket] }[channel]: - channel.sendall(command) + channel.sendall(command.encode()) def readline(self, synchronous_channel=True): """ From cebfc174ae43e8b0e0a0709860f83f408277bfad Mon Sep 17 00:00:00 2001 From: "Penn, John M 047828115" Date: Wed, 24 Apr 2019 18:29:50 -0500 Subject: [PATCH 5/9] Don't compile and link HTTP server by default Ref #756 --- trick_sims/Cannon/SIM_cannon_numeric/S_define | 22 ++++--------------- .../Cannon/SIM_cannon_numeric/S_overrides.mk | 7 +++--- .../mongoose_httpd/include/http_server.h | 2 ++ .../models/mongoose_httpd/mongoose_httpd.sm | 21 ++++++++++++++++++ 4 files changed, 30 insertions(+), 22 deletions(-) create mode 100644 trick_sims/Cannon/models/mongoose_httpd/mongoose_httpd.sm diff --git a/trick_sims/Cannon/SIM_cannon_numeric/S_define b/trick_sims/Cannon/SIM_cannon_numeric/S_define index 54566b93..d7852fa7 100644 --- a/trick_sims/Cannon/SIM_cannon_numeric/S_define +++ b/trick_sims/Cannon/SIM_cannon_numeric/S_define @@ -5,26 +5,15 @@ LIBRARY DEPENDENCIES: ( (cannon/gravity/src/cannon_init.c) (cannon/gravity/src/cannon_numeric.c) - (mongoose_httpd/src/http_server.cpp) ) *************************************************************/ #include "sim_objects/default_trick_sys.sm" + +// Uncomment to get a webserver. Also uncomment lines in S_overrise.mk to link in mongoose lib. +// #include "mongoose_httpd/mongoose_httpd.sm" + ##include "cannon/gravity/include/cannon_numeric.h" -##include "mongoose_httpd/include/http_server.h" - -class HttpSimObject : public Trick::SimObject { - - public: - HTTP_Server http_server ; - - HttpSimObject() { - ("default_data") http_default_data( &http_server ) ; - ("initialization") http_init( &http_server ) ; - ("shutdown") http_shutdown( &http_server ) ; - } -} ; - class CannonSimObject : public Trick::SimObject { public: @@ -38,10 +27,7 @@ class CannonSimObject : public Trick::SimObject { ("dynamic_event") cannon_impact( &cannon) ; } } ; - -// Instantiations CannonSimObject dyn ; -HttpSimObject http ; IntegLoop dyn_integloop (0.01) dyn; diff --git a/trick_sims/Cannon/SIM_cannon_numeric/S_overrides.mk b/trick_sims/Cannon/SIM_cannon_numeric/S_overrides.mk index 3a3073fb..0eae513e 100644 --- a/trick_sims/Cannon/SIM_cannon_numeric/S_overrides.mk +++ b/trick_sims/Cannon/SIM_cannon_numeric/S_overrides.mk @@ -1,7 +1,6 @@ - -TRICK_CFLAGS += -I/usr/include -I../models -TRICK_CXXFLAGS += -I/usr/include -I../models +TRICK_CFLAGS += -I../models +TRICK_CXXFLAGS += -I../models +TRICK_SFLAGS += -I../models TRICK_LDFLAGS += -L/usr/local/lib TRICK_USER_LINK_LIBS += -lmongoose - diff --git a/trick_sims/Cannon/models/mongoose_httpd/include/http_server.h b/trick_sims/Cannon/models/mongoose_httpd/include/http_server.h index 90efbeca..06fd3aae 100644 --- a/trick_sims/Cannon/models/mongoose_httpd/include/http_server.h +++ b/trick_sims/Cannon/models/mongoose_httpd/include/http_server.h @@ -1,5 +1,7 @@ /************************************************************************* PURPOSE: (Represent the state and initial conditions of an http server) +LIBRARY DEPENDENCIES: + ( (../src/http_server.cpp)) **************************************************************************/ #ifndef HTTP_SERVER_H #define HTTP_SERVER_H diff --git a/trick_sims/Cannon/models/mongoose_httpd/mongoose_httpd.sm b/trick_sims/Cannon/models/mongoose_httpd/mongoose_httpd.sm new file mode 100644 index 00000000..20ac74c0 --- /dev/null +++ b/trick_sims/Cannon/models/mongoose_httpd/mongoose_httpd.sm @@ -0,0 +1,21 @@ +/************************TRICK HEADER************************* +PURPOSE: + (HTTP Server) +LIBRARY DEPENDENCIES: + ((src/http_server.cpp)) +*************************************************************/ +##include "mongoose_httpd/include/http_server.h" + +class HttpSimObject : public Trick::SimObject { + + public: + HTTP_Server http_server ; + + HttpSimObject() { + ("default_data") http_default_data( &http_server ) ; + ("initialization") http_init( &http_server ) ; + ("shutdown") http_shutdown( &http_server ) ; + } +}; + +HttpSimObject http ; From 7ccdade44155bd71cb895e44d4484c7671727a86 Mon Sep 17 00:00:00 2001 From: "Penn, John M 047828115" Date: Wed, 24 Apr 2019 18:50:08 -0500 Subject: [PATCH 6/9] Fix S_overrides.mk #756 --- trick_sims/Cannon/SIM_cannon_numeric/S_overrides.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trick_sims/Cannon/SIM_cannon_numeric/S_overrides.mk b/trick_sims/Cannon/SIM_cannon_numeric/S_overrides.mk index 0eae513e..20930921 100644 --- a/trick_sims/Cannon/SIM_cannon_numeric/S_overrides.mk +++ b/trick_sims/Cannon/SIM_cannon_numeric/S_overrides.mk @@ -2,5 +2,5 @@ TRICK_CFLAGS += -I../models TRICK_CXXFLAGS += -I../models TRICK_SFLAGS += -I../models -TRICK_LDFLAGS += -L/usr/local/lib -TRICK_USER_LINK_LIBS += -lmongoose +#TRICK_LDFLAGS += -L/usr/local/lib +#TRICK_USER_LINK_LIBS += -lmongoose From d5544a5991147863be2131a6b758a35d21b4dbb4 Mon Sep 17 00:00:00 2001 From: Derek Bankieris Date: Thu, 25 Apr 2019 07:29:58 -0500 Subject: [PATCH 7/9] Correct decimal formatting for ints in TrickView 3032aae added fixed-width to binary formats. Looks like I modified TVInteger's Decimal format instead of Binary. Refs #661 --- trick_source/java/src/trick/tv/TVInteger.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/trick_source/java/src/trick/tv/TVInteger.java b/trick_source/java/src/trick/tv/TVInteger.java index a8966737..3f0fc7c7 100644 --- a/trick_source/java/src/trick/tv/TVInteger.java +++ b/trick_source/java/src/trick/tv/TVInteger.java @@ -22,7 +22,8 @@ public class TVInteger extends VSInteger implements TrickViewFluent Date: Thu, 2 May 2019 08:20:06 -0500 Subject: [PATCH 8/9] Python init code does not work when using SWIG 4.0 #760 Looks like the way modules are loaded changed a little with SWIG 4.0. So I changed the order we include everything in __init__.py. We include all of the c++ python modules first now instead of having them read in from the python code itself. Basically we include the files like this in this order import _m from m import * --- libexec/trick/make_makefile_swig | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libexec/trick/make_makefile_swig b/libexec/trick/make_makefile_swig index a11b13b0..b2c13415 100755 --- a/libexec/trick/make_makefile_swig +++ b/libexec/trick/make_makefile_swig @@ -383,11 +383,16 @@ LINK_LISTS += \$(LD_FILELIST)build/py_link_list foreach $f ( @files_to_process, @ext_lib_files ) { print INITFILE "# $f\n" ; - print INITFILE "from m$md5s{$f} import *\n" ; + print INITFILE "import _m$md5s{$f}\n" ; print INITFILE "combine_cvars(all_cvars, cvar)\n" ; print INITFILE "cvar = None\n\n" ; } + foreach $f ( @files_to_process, @ext_lib_files ) { + print INITFILE "# $f\n" ; + print INITFILE "from m$md5s{$f} import *\n" ; + } + foreach my $mod ( keys %python_modules ) { print INITFILE "import trick.$mod\n" ; } From e6abfd21b875d9eeb1da1579bf4f30ba10a35f92 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Thu, 2 May 2019 16:36:35 -0500 Subject: [PATCH 9/9] Log frame scheduling time if not running real-time. #762 If real-time is off, we exit the rt_monitor function early. The frame scheduled time was calculated after the exit call. Moved the frame scheduled time calcuation before the exit. --- .../RealtimeSync/RealtimeSync.cpp | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/trick_source/sim_services/RealtimeSync/RealtimeSync.cpp b/trick_source/sim_services/RealtimeSync/RealtimeSync.cpp index c2835b56..55ee2279 100644 --- a/trick_source/sim_services/RealtimeSync/RealtimeSync.cpp +++ b/trick_source/sim_services/RealtimeSync/RealtimeSync.cpp @@ -228,9 +228,6 @@ int Trick::RealtimeSync::start_realtime(double in_frame_time , long long ref_tim /* Reset the clock reference time to the desired reference time */ rt_clock->clock_reset(ref_time) ; - /* Set top of frame time for 1st frame (used in frame logging). */ - last_clock_time = rt_clock->clock_time() ; - /* Start the sleep timer hardware */ start_sleep_timer(); @@ -247,6 +244,9 @@ int Trick::RealtimeSync::start_realtime(double in_frame_time , long long ref_tim } + /* Set top of frame time for 1st frame (used in frame logging). */ + last_clock_time = rt_clock->clock_time() ; + return(0) ; } @@ -283,6 +283,12 @@ int Trick::RealtimeSync::rt_monitor(long long sim_time_tics) { long long curr_clock_time ; char buf[512]; + /* calculate the current underrun/overrun */ + curr_clock_time = rt_clock->clock_time() ; + frame_sched_time = curr_clock_time - last_clock_time ; + /* Set the next frame overrun/underrun reference time to the current time */ + last_clock_time = curr_clock_time ; + /* determine if the state of real-time has changed this frame */ if ( ! active ) { if ( enable_flag ) { @@ -303,10 +309,6 @@ int Trick::RealtimeSync::rt_monitor(long long sim_time_tics) { disable_flag = false ; } - /* calculate the current underrun/overrun */ - curr_clock_time = rt_clock->clock_time() ; - frame_overrun_time = 0 ; - frame_sched_time = curr_clock_time - last_clock_time ; frame_overrun_time = curr_clock_time - sim_time_tics ; /* If the wall clock time is greater than the sim time an overrun occurred. */ @@ -363,9 +365,6 @@ int Trick::RealtimeSync::rt_monitor(long long sim_time_tics) { } - /* Set the next frame overrun/underrun reference time to the current time */ - last_clock_time = curr_clock_time ; - return(0) ; } @@ -456,14 +455,14 @@ int Trick::RealtimeSync::unfreeze(long long sim_time_tics, double software_frame /* Adjust the real-time clock reference by the amount of time we were frozen */ rt_clock->adjust_ref_time(freeze_time_tics - sim_time_tics) ; - /* Set top of frame time for 1st frame (used in frame logging). */ - last_clock_time = rt_clock->clock_time() ; - /* Start the sleep timer with the software frame expiration */ sleep_timer->start(software_frame_sec / rt_clock->get_rt_clock_ratio()) ; } + /* Set top of frame time for 1st frame (used in frame logging). */ + last_clock_time = rt_clock->clock_time() ; + return(0) ; }