Robotran C Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
visu_websocket.h
Go to the documentation of this file.
1 
2 #ifndef VISU_WEBSOCKET_H
3 #define VISU_WEBSOCKET_H
4 
5 #define KEYS_LEN 256
6 #define PORT 9002
7 #define START_VIEWPOINT 0
8 #define FRAMERATE 18.0
9 
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15  #include "user_realtime.h"
16  #include "time_functions.h"
17  #include "realtime_functions.h"
18  #include "realtime_ext.h"
19  #include "realtime.h"
20  #include "json.h"
21 
41  int init_websocket(Realtime_visu *visu, MbsData *mbs_data, int nb_models,
42  int *nb_q, double **q_vec, char **mbs_file, char *mbsz_file,
43  int start_viewpoint, int init_break);
44  void joints_update(Simu_realtime *realtime, int nb_models, int *nb_q, double **q_vec);
45  void process_msg(Simu_realtime *realtime);
46  void update_websocket(Simu_realtime *realtime);
47  void free_websocket(void *visu_class);
48  void update_plot(Simu_realtime *realtime, double tsim);
49 
50 #ifdef __cplusplus
51 }
52 #endif
53 
54 #endif
VisuIn::nb_q
int * nb_q
number of joints for each model
Definition: visu_websocket.cc:178
Realtime_visu::nb_models
int nb_models
number of models to load
Definition: mbs_realtime_struct.h:24
realtime_functions.h
useful functions used by the real-time modules
Simu_realtime::real_simu_speed_factor
double real_simu_speed_factor
real speed factor
Definition: mbs_realtime_struct.h:143
json_mkobject
JsonNode * json_mkobject(void)
Definition: json.c:531
MBS_INFO_FAILURE
#define MBS_INFO_FAILURE
Definition: mbs_define.h:32
MSG_ERR
#define MSG_ERR
Definition: visu_websocket.cc:45
mbs_msg
void mbs_msg(const char *msg,...)
Send a message.
Definition: mbs_message.c:87
visu_in
VisuIn * visu_in
Definition: visu_websocket.cc:190
useful_functions.h
MbsData::tsim
double tsim
The time value.
Definition: mbs_data.h:306
VisuIn::mbs_file
char ** mbs_file
mbs files to load
Definition: visu_websocket.cc:182
update_websocket
void update_websocket(Simu_realtime *realtime)
Definition: visu_websocket.cc:411
VisuIn::start_viewpoint
int start_viewpoint
initial viewpoint
Definition: visu_websocket.cc:176
ws_socket
int ws_socket(struct ws_server *ws_srv)
Main loop for the server.
Definition: ws.c:1940
free_websocket
void free_websocket(void *visu_class)
close the socket connection
Definition: visu_websocket.cc:529
ws_events::onmessage
void(* onmessage)(ws_cli_conn_t *client, const unsigned char *msg, uint64_t msg_size, int type)
On message event, called when a client sends a text or binary message.
Definition: ws.h:266
AutoPlot
User curves to plot auto-update.
Definition: mbs_realtime_struct.h:58
MSG_PRE
#define MSG_PRE
Definition: visu_websocket.cc:46
JsonNode::bool_
bool bool_
Definition: json.h:53
AutoPlot::label_curves
char ** label_curves
tabular with the current curves labels
Definition: mbs_realtime_struct.h:63
mbs_define.h
pause_routine
void pause_routine(Simu_realtime *realtime)
Definition: visu_websocket.cc:380
auto_plot
static AutoPlot * auto_plot
Definition: set_plot.c:5
mbs_splitext
int mbs_splitext(const char *path, char **prefix, char **extension)
Split the path into a pair (root, ext).
Definition: mbs_path.c:460
process_msg
void process_msg(Simu_realtime *realtime)
t_last_plot
static double t_last_plot
update the realtime plot data
Definition: visu_websocket.cc:468
init_websocket
int init_websocket(Realtime_visu *visu, MbsData *mbs_data, int nb_models, int *nb_q, double **q_vec, char **mbs_file, char *mbsz_file, int start_viewpoint, int init_break)
Initialize the communication with the webserver.
Definition: visu_websocket.cc:192
client
static ws_cli_conn_t * client
Definition: visu_websocket.cc:49
VisuIn::q_vec
double ** q_vec
initial joint positions
Definition: visu_websocket.cc:180
VisuIn
input of the 3D window
Definition: visu_websocket.cc:172
onopen
void onopen(ws_cli_conn_t *c)
This function is called whenever a new connection is opened.
Definition: visu_websocket.cc:61
t_last_update
double t_last_update
main update loop for the visualization
Definition: visu_websocket.cc:409
AutoPlot::nb
int nb
current number of curves to plot
Definition: mbs_realtime_struct.h:60
ws_server::thread_loop
int thread_loop
Whether if the ws_socket() should create a new thread and be non-blocking (1) or not (0).
Definition: ws.h:287
realtime_ext.h
Real-time constraints header for external modules.
json_mkarray
JsonNode * json_mkarray(void)
Definition: json.c:526
json_mkstring
JsonNode * json_mkstring(const char *s)
Definition: json.c:514
update_realtime_constraints_break
void update_realtime_constraints_break(Simu_realtime *realtime, int delta_break_u_sec)
update the real-time constraints after a break
Definition: realtime.c:793
KEYS_LEN
#define KEYS_LEN
Definition: visu_websocket.h:5
update_plot
void update_plot(Simu_realtime *realtime, double tsim)
Definition: visu_websocket.cc:470
update_websocket
void update_websocket(Simu_realtime *realtime)
Definition: visu_websocket.cc:411
Realtime_extern::auto_plot
AutoPlot * auto_plot
automatic user plot update structure
Definition: mbs_realtime_struct.h:78
Simu_realtime::ext
Realtime_extern * ext
external variables
Definition: mbs_realtime_struct.h:177
VisuIn::mbsz_path
char * mbsz_path
Definition: visu_websocket.cc:184
AutoPlot::y_curves
double * y_curves
tabular with the current values of the plots to curve
Definition: mbs_realtime_struct.h:65
joints_update
void joints_update(Simu_realtime *realtime, int nb_models, int *nb_q, double **q_vec)
update the joint values for visualization
Definition: visu_websocket.cc:349
JsonNode
Definition: json.h:41
ws_server::port
uint16_t port
Listening port.
Definition: ws.h:282
time_functions.h
functions used to get the time expressed in us (micro seconds)
MbsData::q
double * q
Array with the current values of the generalized coordinates.
Definition: mbs_data.h:285
is_updated
static bool is_updated
Definition: visu_websocket.cc:51
PORT
#define PORT
Definition: visu_websocket.h:6
Realtime_visu::nb_q
int * nb_q
number of joints in the .mbs used for visualization (for each model)
Definition: mbs_realtime_struct.h:36
project_data_size
long project_data_size
Definition: visu_websocket.cc:55
joints_update
void joints_update(Simu_realtime *realtime, int nb_models, int *nb_q, double **q_vec)
update the joint values for visualization
Definition: visu_websocket.cc:349
json_encode
char * json_encode(const JsonNode *node)
Definition: json.c:379
visu_websocket.h
is_connected
static bool is_connected
Definition: visu_websocket.cc:50
mbs_message.h
ws_events::onclose
void(* onclose)(ws_cli_conn_t *client)
On close event, called when a client disconnects.
Definition: ws.h:261
pause_sim
bool pause_sim
Definition: visu_websocket.cc:53
ws_server::evs
struct ws_events evs
Server events.
Definition: ws.h:295
json_find_member
JsonNode * json_find_member(JsonNode *object, const char *name)
Definition: json.c:465
onmessage
void onmessage(ws_cli_conn_t *client, const unsigned char *msg, uint64_t size, int type)
Message events goes here.
Definition: visu_websocket.cc:91
MbsData
Definition: mbs_data.h:247
realtime.h
Real-time constraints main header.
init_websocket
int init_websocket(Realtime_visu *visu, MbsData *mbs_data, int nb_models, int *nb_q, double **q_vec, char **mbs_file, char *mbsz_path, int start_viewpoint, int init_break)
Initialize the communication with the webserver.
Definition: visu_websocket.cc:192
Simu_realtime
real-time structure
Definition: mbs_realtime_struct.h:133
Realtime_visu
Visualization variables and stuctures.
Definition: mbs_realtime_struct.h:22
ws.h
wsServer constants and functions.
Realtime_extern::mbs_data
MbsData * mbs_data
Robotran main structure.
Definition: mbs_realtime_struct.h:80
project_data
static char * project_data
Definition: visu_websocket.cc:54
ws_server::timeout_ms
uint32_t timeout_ms
Ping timeout in milliseconds.
Definition: ws.h:291
json_append_member
void json_append_member(JsonNode *object, const char *key, JsonNode *value)
Definition: json.c:584
Realtime_visu::cur_q
double ** cur_q
current joints positions vector (for each model)
Definition: mbs_realtime_struct.h:47
ws_events::onopen
void(* onopen)(ws_cli_conn_t *client)
On open event, called when a new client connects.
Definition: ws.h:257
Simu_realtime::speed_last_t_usec
int speed_last_t_usec
last real time [us], to compute the simulation speed
Definition: mbs_realtime_struct.h:160
json.h
rt
static Simu_realtime * rt
Definition: visu_websocket.cc:52
free_websocket
void free_websocket(void *visu_class)
close the socket connection
Definition: visu_websocket.cc:529
Simu_realtime::simu_speed_flag
int simu_speed_flag
used to compute the simulation factor
Definition: mbs_realtime_struct.h:139
mbs_path.h
VisuIn::visu
Realtime_visu * visu
pointer to the "visu" structure
Definition: visu_websocket.cc:186
MBS_INFO_SUCCESS
#define MBS_INFO_SUCCESS
Definition: mbs_define.h:30
key_states
static uint8_t key_states[KEYS_LEN]
Definition: visu_websocket.cc:48
FRAMERATE
#define FRAMERATE
Definition: visu_websocket.h:8
json_append_element
void json_append_element(JsonNode *array, JsonNode *element)
Definition: json.c:568
ws_sendframe_bin
int ws_sendframe_bin(ws_cli_conn_t *cli, const char *msg, uint64_t size)
Sends a WebSocket binary frame.
Definition: ws.c:842
ws_sendframe_txt
int ws_sendframe_txt(ws_cli_conn_t *cli, const char *msg)
Sends a WebSocket text frame.
Definition: ws.c:815
user_realtime.h
onclose
void onclose(ws_cli_conn_t *client)
This function is called whenever a connection is closed.
Definition: visu_websocket.cc:77
MBS_INFO_WARNING
#define MBS_INFO_WARNING
Definition: mbs_define.h:31
JsonNode::number_
double number_
Definition: json.h:59
ws_getaddress
char * ws_getaddress(ws_cli_conn_t *client)
Gets the IP address relative to a client connection opened by the server.
Definition: ws.c:475
ws_server
server Web Socket server parameters
Definition: ws.h:273
VisuIn::nb_models
int nb_models
number of models
Definition: visu_websocket.cc:174
ws_server::host
const char * host
Required hostname that the wsServer will bind to.
Definition: ws.h:278
mbs_stricmp
int mbs_stricmp(const char *__s1, const char *__s2)
Compare two char with _stricmp (convert strings to lower case, ignoring case sensitive).
Definition: useful_functions.c:584
json_mknumber
JsonNode * json_mknumber(double n)
Definition: json.c:519
Realtime_extern::visu
Realtime_visu * visu
Java structure.
Definition: mbs_realtime_struct.h:76
json_decode
JsonNode * json_decode(const char *json)
Definition: json.c:361
update_plot
void update_plot(Simu_realtime *realtime, double tsim)
Definition: visu_websocket.cc:470