Skip to content

Commit

Permalink
add console_bridge interface.l
Browse files Browse the repository at this point in the history
rewrited version of kindsenior@71a8e2a
which we need to surpress warning message, see jsk-enshu/robot-programming#437 (comment)
  • Loading branch information
k-okada committed Nov 10, 2023
1 parent 795e764 commit 048de79
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
67 changes: 66 additions & 1 deletion roseus/roseus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include <rospack/rospack.h>
#include <ros/param.h>
#include <ros/callback_queue.h>
#include <console_bridge/console.h>

// for eus.h
#define class eus_class
Expand Down Expand Up @@ -149,7 +150,7 @@ static bool s_bInstalled = false;
#define s_mapTimered s_staticdata.mapTimered
#define s_mapHandle s_staticdata.mapHandle

pointer K_ROSEUS_MD5SUM,K_ROSEUS_DATATYPE,K_ROSEUS_DEFINITION,K_ROSEUS_CONNECTION_HEADER,K_ROSEUS_SERIALIZATION_LENGTH,K_ROSEUS_SERIALIZE,K_ROSEUS_DESERIALIZE,K_ROSEUS_INIT,K_ROSEUS_GET,K_ROSEUS_REQUEST,K_ROSEUS_RESPONSE,K_ROSEUS_GROUPNAME,K_ROSEUS_ONESHOT,K_ROSEUS_LAST_EXPECTED,K_ROSEUS_LAST_REAL,K_ROSEUS_CURRENT_EXPECTED,K_ROSEUS_CURRENT_REAL,K_ROSEUS_LAST_DURATION,K_ROSEUS_SEC,K_ROSEUS_NSEC,QANON,QNOOUT,QREPOVERSION,QROSDEBUG,QROSINFO,QROSWARN,QROSERROR,QROSFATAL;
pointer K_ROSEUS_MD5SUM,K_ROSEUS_DATATYPE,K_ROSEUS_DEFINITION,K_ROSEUS_CONNECTION_HEADER,K_ROSEUS_SERIALIZATION_LENGTH,K_ROSEUS_SERIALIZE,K_ROSEUS_DESERIALIZE,K_ROSEUS_INIT,K_ROSEUS_GET,K_ROSEUS_REQUEST,K_ROSEUS_RESPONSE,K_ROSEUS_GROUPNAME,K_ROSEUS_ONESHOT,K_ROSEUS_LAST_EXPECTED,K_ROSEUS_LAST_REAL,K_ROSEUS_CURRENT_EXPECTED,K_ROSEUS_CURRENT_REAL,K_ROSEUS_LAST_DURATION,K_ROSEUS_SEC,K_ROSEUS_NSEC,QANON,QNOOUT,QREPOVERSION,QROSDEBUG,QROSINFO,QROSWARN,QROSERROR,QROSFATAL,QCONSOLE_BRIDGE_LOG_DEBUG,QCONSOLE_BRIDGE_LOG_INFO,QCONSOLE_BRIDGE_LOG_WARN,QCONSOLE_BRIDGE_LOG_ERROR;
extern pointer LAMCLOSURE;

/***********************************************************
Expand Down Expand Up @@ -831,6 +832,59 @@ pointer ROSEUS_EXIT(register context *ctx,int n,pointer *argv)
else _exit(ckintval(argv[0]));
}

/************************************************************
* rosconsole_bridge
************************************************************/
#define def_console_bridge_formatter(funcname, rosfuncname) \
pointer funcname(register context *ctx,int n,pointer *argv) \
{ pointer *argv2,msg; \
int argc2; \
argc2 = n+1; \
argv2 = (pointer *)malloc(sizeof(pointer)*argc2); \
argv2[0] = NIL; \
for(int i=0;i<n;i++) argv2[i+1]=argv[i] ; \
msg = XFORMAT(ctx, argc2, argv2); \
rosfuncname("%s", msg->c.str.chars); \
free(argv2); \
return (T); \
}

def_console_bridge_formatter(ROSEUS_CONSOLE_BRIDGE_LOGDEBUG, CONSOLE_BRIDGE_logDebug)
def_console_bridge_formatter(ROSEUS_CONSOLE_BRIDGE_LOGINFO, CONSOLE_BRIDGE_logInform)
def_console_bridge_formatter(ROSEUS_CONSOLE_BRIDGE_LOGWARN, CONSOLE_BRIDGE_logWarn)
def_console_bridge_formatter(ROSEUS_CONSOLE_BRIDGE_LOGERROR, CONSOLE_BRIDGE_logError)

pointer ROSEUS_CONSOLE_BRIDGE_SET_LOG_LEVEL(register context *ctx,int n,pointer *argv)
{
ckarg(1);
int log_level = ckintval(argv[0]);
console_bridge::LogLevel level;
switch(log_level){
case 0:
level = console_bridge::CONSOLE_BRIDGE_LOG_DEBUG;
break;
case 1:
level = console_bridge::CONSOLE_BRIDGE_LOG_INFO;
break;
case 2:
level = console_bridge::CONSOLE_BRIDGE_LOG_WARN;
break;
case 3:
level = console_bridge::CONSOLE_BRIDGE_LOG_ERROR;
default:
return (NIL);
}

console_bridge::setLogLevel(level);
return (T);
}

pointer ROSEUS_CONSOLE_BRIDGE_GET_LOG_LEVEL(register context *ctx,int n,pointer *argv)
{
console_bridge::LogLevel level = console_bridge::getLogLevel();
return makeint(level);
}

/************************************************************
* ROSEUS Publisher/Subscriber
************************************************************/
Expand Down Expand Up @@ -2031,6 +2085,17 @@ pointer ___roseus(register context *ctx, int n, pointer *argv, pointer env)
defun(ctx,"ROS-FATAL",argv[0],(pointer (*)())ROSEUS_ROSFATAL, "write mesage to fatal output");
defun(ctx,"EXIT",argv[0],(pointer (*)())ROSEUS_EXIT, "Exit ros clinet");

QCONSOLE_BRIDGE_LOG_DEBUG=defvar(ctx,"*CONSOLE-BRIDGE-LOG-DEBUG*",makeint(0),rospkg);
QCONSOLE_BRIDGE_LOG_INFO=defvar(ctx,"*CONSOLE-BRIDGE-LOG-INFO*",makeint(1),rospkg);
QCONSOLE_BRIDGE_LOG_WARN=defvar(ctx,"*CONSOLE-BRIDGE-LOG-WARN*",makeint(2),rospkg);
QCONSOLE_BRIDGE_LOG_ERROR=defvar(ctx,"*CONSOLE-BRIDGE-LOG-ERROR*",makeint(3),rospkg);
defun(ctx,"CONSOLE-BRIDGE-SET-LOG-LEVEL",argv[0],(pointer (*)())ROSEUS_CONSOLE_BRIDGE_SET_LOG_LEVEL, "set the minimum level of logging data to output to console_bridge");
defun(ctx,"CONSOLE-BRIDGE-GET-LOG-LEVEL",argv[0],(pointer (*)())ROSEUS_CONSOLE_BRIDGE_GET_LOG_LEVEL, "retrieve the current level of console_bridge logging data");
defun(ctx,"CONSOLE-BRIDGE-LOG-DEBUG",argv[0],(pointer (*)())ROSEUS_CONSOLE_BRIDGE_LOGDEBUG, "debug level logging function of console_bridge");
defun(ctx,"CONSOLE-BRIDGE-LOG-INFO",argv[0],(pointer (*)())ROSEUS_CONSOLE_BRIDGE_LOGINFO, "info level logging function of console_bridge");
defun(ctx,"CONSOLE-BRIDGE-LOG-WARN",argv[0],(pointer (*)())ROSEUS_CONSOLE_BRIDGE_LOGWARN, "warn level logging function of console_bridge");
defun(ctx,"CONSOLE-BRIDGE-LOG-ERROR",argv[0],(pointer (*)())ROSEUS_CONSOLE_BRIDGE_LOGDEBUG, "error level logging function of console_bridge");

defun(ctx,"SUBSCRIBE",argv[0],(pointer (*)())ROSEUS_SUBSCRIBE,
"topicname message_type callbackfunc args0 ... argsN &optional (queuesize 1) &key (:groupname groupname)\n\n"
"Subscribe to a topic, version for class member function with bare pointer.\n"
Expand Down
24 changes: 24 additions & 0 deletions roseus/test/test-console-bridge.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env roseus

(require :unittest "lib/llib/unittest.l")
(setq sys::*gc-hook* #'(lambda (a b) (format *error-output* ";; gc ~A ~A~%" a b)))
(init-unit-test)

;;
(deftest test-console-bridge
(dolist (level (list ros::*console-bridge-log-debug*
ros::*console-bridge-log-info*
ros::*console-bridge-log-warn*
ros::*console-bridge-log-error*))
(warning-message 2 "check ~A level~%" level)
(ros::console-bridge-set-log-level level)
(warning-message 2 " current log level ~A~%" (ros::console-bridge-get-log-level))
(ros::console-bridge-log-error "this is ERROR message")
(ros::console-bridge-log-warn "this is WARN message")
(ros::console-bridge-log-info "this is INFO message")
(ros::console-bridge-log-debug "this is DEBUG message")
))

(run-all-tests)

(exit)
3 changes: 3 additions & 0 deletions roseus/test/test-console-bridge.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<launch>
<test test-name="test_console_bridge" pkg="roseus" type="test-console-bridge.l" name="test_console_bridge" />
</launch>

0 comments on commit 048de79

Please sign in to comment.