Commit 964a98e5 authored by Claes Sjofors's avatar Claes Sjofors

Xtt loggning, conditional logging with expression added

parent ee80c893
...@@ -1142,9 +1142,20 @@ to file. At fast time critical sequences, you can increase the buffer size to av ...@@ -1142,9 +1142,20 @@ to file. At fast time critical sequences, you can increase the buffer size to av
interruption when the buffer i written to file. interruption when the buffer i written to file.
<h2>Conditional logging <h2>Conditional logging
In 'ConditionParameter' a digital attribute controlling the logging can be specified. The In 'Condition' a digital attribute controlling the logging can be specified. The
logging is only performed when the ConditionParameter is true. logging is only performed when the ConditionParameter is true.
It is also possible to insert an expression into 'Condition'. The expression starts with
'expr' followed by the condition enclosed with parenthesis. In the expression, attribute values
can be fetched with the GetA function for analog attributes, GetD function for digital
attributes and GetI function for integer attribute.
<b>Expression example
expr( GetD("H1-H2-Dv1.ActualValue") && GetA("H1-H2-Av2.ActualValue") > 2.5)
The logging is performed when the Dv 'H1-H2-Dv1' is true and the Av 'H1-H2-Av2' is
larger than 2.5.
<h2>Store <h2>Store
The logging configuration is stored with the 'Store' button, and can be restored later The logging configuration is stored with the 'Store' button, and can be restored later
with the 'Restore' button. with the 'Restore' button.
......
...@@ -1129,9 +1129,19 @@ snabba tidskritiska f ...@@ -1129,9 +1129,19 @@ snabba tidskritiska f
att störningar som kan uppstå när bufferten skrivs på fil. att störningar som kan uppstå när bufferten skrivs på fil.
<h2>Villkorlig loggning <h2>Villkorlig loggning
I 'ConditionParameter' kan man ange ett digitalt attribut som styr loggningen. Loggning I 'Condition kan man ange ett digitalt attribut som styr loggningen. Loggning
sker enbart om ConditionParameter är sann. sker enbart om ConditionParameter är sann.
Man kan även ange ett uttryck i 'Condition. Uttrycket startar med 'expr' följt av
villkoret omgivet av parenteser. I villkoret kan man hämta upp attribut-värden med
GetA funktionen för analoga attribut, GetD funktionen för digitala attribut och GetI
funktionen för heltals attribut.
<b>Exempel
expr( GetD("H1-H2-Dv1.ActualValue") && GetA("H1-H2-Av2.ActualValue") > 2.5)
Loggningen utförs när Dv'n 'H1-H2-Dv1' är 1 och Av'n 'H1-H2-Av2' är större en 2.5.
<h2>Lagra <h2>Lagra
Logg konfigureringen kan sparas med 'Store' knappen, för att återskapas vid ett senare Logg konfigureringen kan sparas med 'Store' knappen, för att återskapas vid ett senare
tillfälle med 'Restore' knappen. tillfälle med 'Restore' knappen.
......
This diff is collapsed.
...@@ -251,13 +251,24 @@ int ccm_ref_external_var( ...@@ -251,13 +251,24 @@ int ccm_ref_external_var(
int ccm_singleline_init( int ccm_singleline_init(
ccm_tSingleLineCtx *ctx, ccm_tSingleLineCtx *ctx,
char *line, char *line,
int (* errormessage_func) ( char *, int, void *) int (* errormessage_func) ( char *, int, void *),
void *client_data
); );
int ccm_singleline_exec( int ccm_singleline_exec(
ccm_tSingleLineCtx ctx ccm_tSingleLineCtx ctx
); );
int ccm_singleline_exec_int(
ccm_tSingleLineCtx ctx,
ccm_tInt *result
);
int ccm_singleline_exec_float(
ccm_tSingleLineCtx ctx,
ccm_tFloat *result
);
void ccm_singleline_free( void ccm_singleline_free(
ccm_tSingleLineCtx ctx ccm_tSingleLineCtx ctx
); );
......
...@@ -509,6 +509,7 @@ void Lng::set( char *language) ...@@ -509,6 +509,7 @@ void Lng::set( char *language)
if ( EVEN(sts)) return; if ( EVEN(sts)) return;
} }
setlocale( LC_ALL, lang_to_locale( l)); setlocale( LC_ALL, lang_to_locale( l));
setlocale( LC_NUMERIC, "POSIX");
} }
pwr_tStatus Lng::set( lng_eLanguage language) pwr_tStatus Lng::set( lng_eLanguage language)
...@@ -528,6 +529,7 @@ pwr_tStatus Lng::set( lng_eLanguage language) ...@@ -528,6 +529,7 @@ pwr_tStatus Lng::set( lng_eLanguage language)
} }
setlocale( LC_ALL, lang_to_locale( lang)); setlocale( LC_ALL, lang_to_locale( lang));
setlocale( LC_NUMERIC, "POSIX");
return 1; return 1;
} }
......
...@@ -557,8 +557,6 @@ int main( int argc, char *argv[]) ...@@ -557,8 +557,6 @@ int main( int argc, char *argv[])
{ {
int sts; int sts;
setlocale( LC_TIME, "en_US");
new XttGtk( argc, argv, &sts); new XttGtk( argc, argv, &sts);
exit(sts); exit(sts);
} }
...@@ -596,6 +594,9 @@ XttGtk::XttGtk( int argc, char *argv[], int *return_sts) : ...@@ -596,6 +594,9 @@ XttGtk::XttGtk( int argc, char *argv[], int *return_sts) :
gtk_init( &argc, &argv); gtk_init( &argc, &argv);
setlocale( LC_TIME, "en_US");
setlocale( LC_NUMERIC, "POSIX");
syi_NodeName( &sts, nodename, sizeof(nodename)); syi_NodeName( &sts, nodename, sizeof(nodename));
if ( ODD(sts)) if ( ODD(sts))
strcat( title, nodename); strcat( title, nodename);
......
...@@ -1138,8 +1138,8 @@ int GeCurve::read_file( char *filename) ...@@ -1138,8 +1138,8 @@ int GeCurve::read_file( char *filename)
cd->x_reverse = 0; cd->x_reverse = 0;
cd->cols = nr - 1; cd->cols = nr - 1;
cd->rows[0] = rows;
for ( i = 0; i < nr; i++) { for ( i = 0; i < nr; i++) {
cd->rows[i] = rows;
if ( i == 0) { if ( i == 0) {
strcpy( cd->x_name, item_str[i]); strcpy( cd->x_name, item_str[i]);
cd->x_data[i] = (double *) malloc( rows * sizeof( double)); cd->x_data[i] = (double *) malloc( rows * sizeof( double));
......
...@@ -66,7 +66,7 @@ XttSevHistGtk::XttSevHistGtk( void *parent_ctx, ...@@ -66,7 +66,7 @@ XttSevHistGtk::XttSevHistGtk( void *parent_ctx,
*sts = XNAV__SUCCESS; *sts = XNAV__SUCCESS;
curve = new GeCurveGtk( this, parent_widget, title, NULL, gcd, 0); curve = new GeCurveGtk( this, parent_widget, title, NULL, gcd, 1);
curve->close_cb = sevhist_close_cb; curve->close_cb = sevhist_close_cb;
curve->help_cb = sevhist_help_cb; curve->help_cb = sevhist_help_cb;
curve->higher_res_cb = sevhist_higher_res_cb; curve->higher_res_cb = sevhist_higher_res_cb;
......
...@@ -53,6 +53,7 @@ ...@@ -53,6 +53,7 @@
#include "pwr_baseclasses.h" #include "pwr_baseclasses.h"
#include "co_cdh.h" #include "co_cdh.h"
#include "co_time.h" #include "co_time.h"
#include "co_ccm_msg.h"
#include "rt_gdh.h" #include "rt_gdh.h"
#include "rt_gdh_msg.h" #include "rt_gdh_msg.h"
#include "co_dcli.h" #include "co_dcli.h"
...@@ -73,15 +74,63 @@ ...@@ -73,15 +74,63 @@
#endif #endif
static void *xtt_logproc( void *arg); static void *xtt_logproc( void *arg);
static int log_ccm_registred = 0;
static int log_errormessage_func( char *msg, int severity, void *data)
{
((XttLogging *)data)->message( severity, msg);
printf( "Condition error: %s\n", msg);
return 1;
}
static int logccm_geta_func(
void *filectx,
ccm_sArg *arg_list,
int arg_count,
int *return_decl,
ccm_tFloat *return_float,
ccm_tInt *return_int,
char *return_string)
{
int sts;
if ( arg_count != 1 || arg_list->value_decl != CCM_DECL_STRING)
return CCM__ARGMISM;
sts = gdh_GetObjectInfo( arg_list->value_string, return_float, sizeof(*return_float));
if ( EVEN(sts)) return sts;
*return_decl = CCM_DECL_FLOAT;
return 1;
}
static int logccm_getd_func(
void *filectx,
ccm_sArg *arg_list,
int arg_count,
int *return_decl,
ccm_tFloat *return_float,
ccm_tInt *return_int,
char *return_string)
{
int sts;
if ( arg_count != 1 || arg_list->value_decl != CCM_DECL_STRING)
return CCM__ARGMISM;
sts = gdh_GetObjectInfo( arg_list->value_string, return_int, sizeof(*return_int));
if ( EVEN(sts)) return sts;
*return_decl = CCM_DECL_INT;
return 1;
}
XttLogging::XttLogging() : XttLogging::XttLogging() :
xnav(0), index(0), active(0), intern(0), stop_logg(0), xnav(0), index(0), active(0), intern(0), stop_logg(0),
logg_type(xtt_LoggType_Cont), logg_priority(0), condition_ptr(0), logg_type(xtt_LoggType_Cont), logg_priority(0), condition_ptr(0),
logg_time(200), logg_file(0), line_size(10000), parameter_count(0), logg_time(200), logg_file(0), line_size(10000), parameter_count(0),
print_shortname(0), buffer_size(100), wanted_buffer_size(100), print_shortname(0), buffer_size(100), wanted_buffer_size(100),
buffer_count(0), buffer_ptr(0) buffer_count(0), buffer_ptr(0), cond_ccm_ctx(0)
{ {
for ( int i = 0; i < RTT_LOGG_MAXPAR; i++) { for ( int i = 0; i < RTT_LOGG_MAXPAR; i++) {
parameterstr[i][0] = 0; parameterstr[i][0] = 0;
...@@ -215,17 +264,19 @@ int XttLogging::logging_set( ...@@ -215,17 +264,19 @@ int XttLogging::logging_set(
parameter_size[ par_index] = asize/aelem; parameter_size[ par_index] = asize/aelem;
} }
if ( condition != NULL) if ( condition != NULL) {
{ if ( cdh_NoCaseStrncmp( condition, "EXPR(", 5) == 0)
/* Check that parameter exists */ strcpy ( conditionstr, condition);
else {
/* Attribute, Check that parameter exists */
sts = gdh_GetObjectInfo ( condition, &buffer, sizeof(buffer)); sts = gdh_GetObjectInfo ( condition, &buffer, sizeof(buffer));
if (EVEN(sts)) if (EVEN(sts)) {
{
message('E',"Condition doesn't exist"); message('E',"Condition doesn't exist");
return XNAV__HOLDCOMMAND; return XNAV__HOLDCOMMAND;
} }
strcpy ( conditionstr, condition); strcpy ( conditionstr, condition);
} }
}
if ( a_logg_time != 0) if ( a_logg_time != 0)
logg_time = a_logg_time; logg_time = a_logg_time;
...@@ -499,10 +550,24 @@ int XttLogging::store( ...@@ -499,10 +550,24 @@ int XttLogging::store(
fprintf( outfile, "logging set/entry=current/parameter=\"%s\"\n", fprintf( outfile, "logging set/entry=current/parameter=\"%s\"\n",
parameterstr[i]); parameterstr[i]);
} }
if ( conditionstr[0] != 0) if ( conditionstr[0] != 0) {
fprintf( outfile, "logging set/entry=current/condition=\"%s\"\n", pwr_tCmd cond;
conditionstr); char *s, *t;
// Replace " with \"
for ( s = conditionstr, t = cond; *s; s++) {
if ( *s == '"') {
*t = '\\';
t++;
}
*t = *s;
t++;
}
*t = 0;
fprintf( outfile, "logging set/entry=current/condition=\"%s\"\n",
cond);
}
if ( intern ) if ( intern )
fprintf( outfile, "logging set/entry=current/stop\n"); fprintf( outfile, "logging set/entry=current/stop\n");
else else
...@@ -579,21 +644,50 @@ int XttLogging::start() ...@@ -579,21 +644,50 @@ int XttLogging::start()
} }
/* Get the condition */ /* Get the condition */
if ( conditionstr[0] != 0) if ( conditionstr[0] != 0) {
{ if ( cdh_NoCaseStrncmp( conditionstr, "EXPR(", 5) == 0) {
sts = gdh_RefObjectInfo( pwr_tCmd expr;
conditionstr,
strncpy( expr, &conditionstr[5], sizeof(expr));
char *s = strrchr( expr, ')');
if ( !s) {
message('E', "Condition expression syntax error");
return XNAV__HOLDCOMMAND;
}
*s = 0;
if ( !log_ccm_registred) {
sts = ccm_register_function( "GetA", logccm_geta_func);
if ( EVEN(sts)) return sts;
sts = ccm_register_function( "GetD", logccm_getd_func);
if ( EVEN(sts)) return sts;
sts = ccm_register_function( "GetI", logccm_getd_func);
if ( EVEN(sts)) return sts;
log_ccm_registred = 1;
}
sts = ccm_singleline_init( &cond_ccm_ctx, expr, log_errormessage_func, this);
if ( EVEN(sts)) {
message('E', "Condition expression syntax error");
return XNAV__HOLDCOMMAND;
}
condition_ptr = 0;
}
else {
sts = gdh_RefObjectInfo( conditionstr,
(pwr_tAddress *) &condition_ptr, (pwr_tAddress *) &condition_ptr,
&(condition_subid), 1); &(condition_subid), 1);
if ( EVEN(sts)) if ( EVEN(sts)) {
{ condition_ptr = 0;
message('E', "Condition parameter not found"); message('E', "Condition parameter not found");
return XNAV__HOLDCOMMAND; return XNAV__HOLDCOMMAND;
} }
cond_ccm_ctx = 0;
} }
else }
{ else {
condition_ptr = 0; condition_ptr = 0;
cond_ccm_ctx = 0;
} }
/* Open the file */ /* Open the file */
...@@ -706,8 +800,14 @@ int XttLogging::entry_stop() ...@@ -706,8 +800,14 @@ int XttLogging::entry_stop()
sts = gdh_UnrefObjectInfo ( parameter_subid[i]); sts = gdh_UnrefObjectInfo ( parameter_subid[i]);
} }
} }
if ( condition_ptr != 0) if ( condition_ptr != 0) {
sts = gdh_UnrefObjectInfo ( condition_subid); sts = gdh_UnrefObjectInfo ( condition_subid);
condition_ptr = 0;
}
if ( cond_ccm_ctx != 0) {
ccm_singleline_free( cond_ccm_ctx);
cond_ccm_ctx = 0;
}
return XNAV__SUCCESS; return XNAV__SUCCESS;
} }
...@@ -783,6 +883,7 @@ static void *xtt_logproc( void *arg) ...@@ -783,6 +883,7 @@ static void *xtt_logproc( void *arg)
char timstr[64]; char timstr[64];
char parname[40]; char parname[40];
char *s; char *s;
ccm_tInt cond;
pwr_tTime nextime; pwr_tTime nextime;
pwr_tTime restime; pwr_tTime restime;
pwr_tDeltaTime deltatime; pwr_tDeltaTime deltatime;
...@@ -908,12 +1009,20 @@ static void *xtt_logproc( void *arg) ...@@ -908,12 +1009,20 @@ static void *xtt_logproc( void *arg)
time_Aadd( &restime, &nextime, &deltatime); time_Aadd( &restime, &nextime, &deltatime);
nextime = restime; nextime = restime;
if ( logg->condition_ptr != 0) if ( logg->condition_ptr || logg->cond_ccm_ctx) {
{
if ( logg->active && !logg->stop_logg) if ( logg->active && !logg->stop_logg) {
{ if ( logg->condition_ptr)
if ( !*(logg->condition_ptr)) cond = *logg->condition_ptr;
{ else {
sts = ccm_singleline_exec_int( logg->cond_ccm_ctx, &cond);
if ( EVEN(sts)) {
logg->message(' ', XNav::get_message(sts));
cond = 0;
}
}
if ( !cond) {
/* Don't log, wait until next scan */ /* Don't log, wait until next scan */
#ifdef OS_VMS #ifdef OS_VMS
time_PwrToVms( &nextime, &vmstime); time_PwrToVms( &nextime, &vmstime);
......
...@@ -22,6 +22,10 @@ ...@@ -22,6 +22,10 @@
/* xtt_logging.h -- Logging in xtt */ /* xtt_logging.h -- Logging in xtt */
#ifndef co_ccm_h
#include "co_ccm.h"
#endif
#ifndef rt_gdh_h #ifndef rt_gdh_h
#include "rt_gdh.h" #include "rt_gdh.h"
#endif #endif
...@@ -80,6 +84,7 @@ class XttLogging { ...@@ -80,6 +84,7 @@ class XttLogging {
int wanted_buffer_size; int wanted_buffer_size;
int buffer_count; int buffer_count;
char *buffer_ptr; char *buffer_ptr;
ccm_tSingleLineCtx cond_ccm_ctx;
void init( int logg_index, void *logg_xnav); void init( int logg_index, void *logg_xnav);
int logging_set( int logging_set(
......
...@@ -2890,15 +2890,15 @@ int XNav::show_logging( int index) ...@@ -2890,15 +2890,15 @@ int XNav::show_logging( int index)
new ItemLocal( brow, Lng::translate("ShortName"), "logg_ShortName", new ItemLocal( brow, Lng::translate("ShortName"), "logg_ShortName",
pwr_eType_Boolean, sizeof( logg[0].print_shortname), 0, 0, 0, pwr_eType_Boolean, sizeof( logg[0].print_shortname), 0, 0, 0,
(void *) &logg[index].print_shortname, NULL, flow_eDest_IntoLast); (void *) &logg[index].print_shortname, NULL, flow_eDest_IntoLast);
new ItemLocal( brow, Lng::translate("Condition"), "logg_CondPar",
pwr_eType_String, sizeof( logg[0].conditionstr), 0, 0, 0,
(void *) logg[index].conditionstr, NULL, flow_eDest_IntoLast);
for ( int i = 0; i < RTT_LOGG_MAXPAR; i++) { for ( int i = 0; i < RTT_LOGG_MAXPAR; i++) {
sprintf( text, "%s%d", Lng::translate("Parameter"), i); sprintf( text, "%s%d", Lng::translate("Parameter"), i);
new ItemLocal( brow, text, text, new ItemLocal( brow, text, text,
pwr_eType_String, sizeof( logg[0].parameterstr[0]), 0, 0, 0, pwr_eType_String, sizeof( logg[0].parameterstr[0]), 0, 0, 0,
(void *) logg[index].parameterstr[i], NULL, flow_eDest_IntoLast); (void *) logg[index].parameterstr[i], NULL, flow_eDest_IntoLast);
} }
new ItemLocal( brow, Lng::translate("ConditionParameter"), "logg_CondPar",
pwr_eType_String, sizeof( logg[0].conditionstr), 0, 0, 0,
(void *) logg[index].conditionstr, NULL, flow_eDest_IntoLast);
brow_ResetNodraw( brow->ctx); brow_ResetNodraw( brow->ctx);
brow_Redraw( brow->ctx, 0); brow_Redraw( brow->ctx, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment