From 716071727782a92b60ff2e12c7f730dc6d9d3702 Mon Sep 17 00:00:00 2001 From: Kei Okada Date: Fri, 10 Nov 2023 13:04:07 +0900 Subject: [PATCH] add console_bridge interface.l rewrited version of https://github.com/kindsenior/jsk_roseus/commit/71a8e2a3aa461f714c27006d7506c8b9be15b8a5 which we need to surpress warning message, see https://github.com/jsk-enshu/robot-programming/pull/437#issue-1977718998 --- roseus/roseus.cpp | 73 +++++++++++++++++++++++++++- roseus/test/test-console-bridge.l | 24 +++++++++ roseus/test/test-console-bridge.test | 3 ++ 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100755 roseus/test/test-console-bridge.l create mode 100644 roseus/test/test-console-bridge.test diff --git a/roseus/roseus.cpp b/roseus/roseus.cpp index 017869c23..9f8ec56c6 100644 --- a/roseus/roseus.cpp +++ b/roseus/roseus.cpp @@ -74,6 +74,7 @@ #include #include #include +#include // for eus.h #define class eus_class @@ -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; /*********************************************************** @@ -831,6 +832,65 @@ 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;ic.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); +} + +pointer ROSEUS_CONSOLE_BRIDGE_LOG(register context *ctx,int n,pointer *argv) +{ + CONSOLE_BRIDGE_logError("hoge"); + return T; +} + /************************************************************ * ROSEUS Publisher/Subscriber ************************************************************/ @@ -2031,6 +2091,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" diff --git a/roseus/test/test-console-bridge.l b/roseus/test/test-console-bridge.l new file mode 100755 index 000000000..da5f6bb8c --- /dev/null +++ b/roseus/test/test-console-bridge.l @@ -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) diff --git a/roseus/test/test-console-bridge.test b/roseus/test/test-console-bridge.test new file mode 100644 index 000000000..0ddfaf877 --- /dev/null +++ b/roseus/test/test-console-bridge.test @@ -0,0 +1,3 @@ + + +