Commit 46f294df authored by Claes Sjofors's avatar Claes Sjofors Committed by Claes Sjöfors

Xtt logging in python format

parent 09c0dfc6
......@@ -102,8 +102,8 @@ static int logccm_getd_func(void* filectx, ccm_sArg* arg_list, int arg_count,
XttLogging::XttLogging()
: xnav(0), index(0), active(0), intern(0), stop_logg(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_type(xtt_LoggType_Cont), logg_priority(0), logg_format(xtt_eLoggFormat_Std),
condition_ptr(0), logg_time(200), logg_file(0), line_size(10000), parameter_count(0),
print_shortname(0), buffer_size(100), wanted_buffer_size(100),
buffer_count(0), buffer_ptr(0), cond_ccm_ctx(0)
{
......@@ -144,7 +144,7 @@ XttLogging::~XttLogging()
**************************************************************************/
int XttLogging::logging_set(float a_logg_time, char* filename, char* parameter,
char* condition, int a_logg_type, int insert, int a_buffer_size, int stop,
char* condition, int a_logg_type, int a_logg_format, int insert, int a_buffer_size, int stop,
int priority, int create, int a_line_size, int shortname)
{
int i, sts;
......@@ -238,6 +238,9 @@ int XttLogging::logging_set(float a_logg_time, char* filename, char* parameter,
if (a_logg_type != 0)
logg_type = a_logg_type;
if (a_logg_format >= 0)
logg_format = (xtt_eLoggFormat)a_logg_format;
if (priority < -1 || priority > 32) {
message('E', "Priority out of range");
return XNAV__HOLDCOMMAND;
......@@ -420,6 +423,33 @@ int XttLogging::show_entry(char* buff, int* buff_cnt)
return XNAV__SUCCESS;
}
/*************************************************************************
*
* Name: rtt_logging_analyse()
*
* Type int
*
* Type Parameter IOGF Description
*
* Description:
* Analyse an entry.
*
**************************************************************************/
int XttLogging::analyse()
{
pwr_tCmd cmd;
if (logg_format != xtt_eLoggFormat_Py) {
message('E', "File format has to be \"Py\"");
return XNAV__HOLDCOMMAND;
}
sprintf( cmd, "sev_analyse.py -f %s &", logg_filename);
system(cmd);
return 1;
}
/*************************************************************************
*
* Name: rtt_logging_store_entry()
......@@ -438,6 +468,7 @@ int XttLogging::store(char* filename)
int i;
pwr_tFileName filename_str;
FILE* outfile;
char msg[120];
int found_parameter;
found_parameter = 0;
......@@ -478,6 +509,11 @@ int XttLogging::store(char* filename)
else if (logg_type == xtt_LoggType_Cont)
fprintf(outfile, "logging set/entry=current/type=cont\n");
if (logg_format == xtt_eLoggFormat_Std)
fprintf(outfile, "logging set/entry=current/format=std\n");
else if (logg_format == xtt_eLoggFormat_Py)
fprintf(outfile, "logging set/entry=current/format=py\n");
for (i = 0; i < RTT_LOGG_MAXPAR; i++) {
if (parameterstr[i][0] != 0)
fprintf(outfile, "logging set/entry=current/parameter=\"%s\"\n",
......@@ -508,7 +544,6 @@ int XttLogging::store(char* filename)
dcli_fgetname(outfile, filename_str, filename_str);
fclose(outfile);
char msg[sizeof(filename_str) + 8 + 1];
sprintf(msg, "%s created", filename_str);
message('I', msg);
return XNAV__SUCCESS;
......@@ -620,9 +655,7 @@ int XttLogging::start()
if (logg_filename[0] != 0) {
logg_file = fopen(logg_filename, "w");
if (logg_file == 0) {
char tmp[280];
snprintf(tmp, sizeof(tmp), "Unable to open file \"%s\"", logg_filename);
message('E', tmp);
message('E', "Unable to open file");
return XNAV__HOLDCOMMAND;
}
} else {
......@@ -815,8 +848,15 @@ static void* xtt_logproc(void* arg)
switch (logg->logg_type) {
case xtt_LoggType_Cont:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
if (logg->logg_file)
fprintf(logg->logg_file, "\"%s\"", time_str);
char_cnt += fprintf(logg->logg_file, "Time");
break;
default:
if (logg->logg_file)
char_cnt += fprintf(logg->logg_file, "\"%s\"", time_str);
}
/* Find a unique shortname for each parameter */
for (i = 0; i < RTT_LOGG_MAXPAR; i++) {
if (logg->print_shortname) {
......@@ -857,6 +897,11 @@ static void* xtt_logproc(void* arg)
for (i = 0; i < RTT_LOGG_MAXPAR; i++) {
if (logg->parameterstr[i][0] != 0) {
if (logg->logg_file) {
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += fprintf(logg->logg_file, ",%s", logg->shortname[i]);
break;
default:
char_cnt += fprintf(logg->logg_file, " %s", logg->shortname[i]);
if (char_cnt + 120 > logg->line_size) {
fprintf(logg->logg_file, "\n");
......@@ -865,6 +910,7 @@ static void* xtt_logproc(void* arg)
}
}
}
}
if (logg->logg_file) {
fprintf(logg->logg_file, "\n");
char_cnt = 0;
......@@ -930,51 +976,136 @@ static void* xtt_logproc(void* arg)
if (first_scan)
time_float = 0.;
/* Print time and the value of the parameter on the file */
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
time_AtoAscii(&time, time_eFormat_NumDateAndTime, time_str, sizeof(time_str));
char_cnt += logg->log_print("%s", time_str);
break;
default:
char_cnt += logg->log_print("%12.4f", time_float);
}
for (i = 0; i < RTT_LOGG_MAXPAR; i++) {
if (logg->parameterstr[i][0] != 0) {
value_ptr = logg->parameter_ptr[i];
switch (logg->parameter_type[i]) {
case pwr_eType_Float32:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%f", *(pwr_tFloat32*)value_ptr);
break;
default:
char_cnt += logg->log_print(" %f", *(pwr_tFloat32*)value_ptr);
}
break;
case pwr_eType_Float64:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%f", *(pwr_tFloat64*)value_ptr);
break;
default:
char_cnt += logg->log_print(" %f", *(pwr_tFloat64*)value_ptr);
}
break;
case pwr_eType_UInt8:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%d", *(pwr_tUInt8*)value_ptr);
break;
default:
char_cnt += logg->log_print(" %d", *(pwr_tUInt8*)value_ptr);
}
break;
case pwr_eType_Boolean:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%d", *(pwr_tBoolean*)value_ptr);
break;
default:
char_cnt += logg->log_print(" %d", *(pwr_tBoolean*)value_ptr);
}
break;
case pwr_eType_Char:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%c", *(pwr_tChar*)value_ptr);
break;
default:
char_cnt += logg->log_print(" %c", *(pwr_tChar*)value_ptr);
}
break;
case pwr_eType_Int8:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%d", *(pwr_tInt8*)value_ptr);
break;
default:
char_cnt += logg->log_print(" %d", *(pwr_tInt8*)value_ptr);
}
break;
case pwr_eType_Int16:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%d", *(pwr_tInt16*)value_ptr);
break;
default:
char_cnt += logg->log_print(" %d", *(pwr_tInt16*)value_ptr);
}
break;
case pwr_eType_UInt16:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%d", *(pwr_tUInt16*)value_ptr);
break;
default:
char_cnt += logg->log_print(" %d", *(pwr_tUInt16*)value_ptr);
}
break;
case pwr_eType_Int32:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%d", *(pwr_tInt32*)value_ptr);
break;
default:
char_cnt += logg->log_print(" %d", *(pwr_tInt32*)value_ptr);
}
break;
case pwr_eType_UInt32:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%d", *(pwr_tUInt32*)value_ptr);
break;
default:
char_cnt += logg->log_print(" %d", *(pwr_tUInt32*)value_ptr);
}
break;
case pwr_eType_Int64:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%lld", *(pwr_tInt64*)value_ptr);
break;
default:
char_cnt += logg->log_print(" %lld", *(pwr_tInt64*)value_ptr);
}
break;
case pwr_eType_UInt64:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%llu", *(pwr_tUInt64*)value_ptr);
break;
default:
char_cnt += logg->log_print(" %llu", *(pwr_tUInt64*)value_ptr);
}
break;
case pwr_eType_String:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%s", value_ptr);
break;
default:
char_cnt += logg->log_print(" %s", value_ptr);
}
break;
case pwr_eType_Objid:
objid = *(pwr_tObjid*)value_ptr;
......@@ -986,7 +1117,13 @@ static void* xtt_logproc(void* arg)
objid, hiername, sizeof(hiername), cdh_mNName);
if (EVEN(sts))
strcpy(hiername, "** Unknown objid");
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%s", hiername);
break;
default:
char_cnt += logg->log_print(" %s", hiername);
}
break;
case pwr_eType_AttrRef:
attrref = (pwr_sAttrRef*)value_ptr;
......@@ -994,31 +1131,60 @@ static void* xtt_logproc(void* arg)
attrref, hiername, sizeof(hiername), cdh_mNName);
if (EVEN(sts))
strcpy(hiername, "** Unknown attrref");
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%s", hiername);
break;
default:
char_cnt += logg->log_print(" %s", hiername);
}
break;
case pwr_eType_Time:
sts = time_AtoAscii((pwr_tTime*)value_ptr, time_eFormat_DateAndTime,
timstr, sizeof(timstr));
if (EVEN(sts))
strcpy(timstr, "Undefined time");
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%s", timstr);
break;
default:
char_cnt += logg->log_print(" %s", timstr);
}
break;
case pwr_eType_DeltaTime:
sts = time_DtoAscii(
(pwr_tDeltaTime*)value_ptr, 1, timstr, sizeof(timstr));
if (EVEN(sts))
strcpy(timstr, "Undefined time");
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%s", timstr);
break;
default:
char_cnt += logg->log_print(" %s", timstr);
}
break;
default:
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
char_cnt += logg->log_print(",%s", "Type error");
break;
default:
char_cnt += logg->log_print(" %s", "Type error");
}
}
if (char_cnt + 10 > logg->line_size) {
switch (logg->logg_format) {
case xtt_eLoggFormat_Py:
break;
default:
logg->log_print("\n");
char_cnt = 0;
}
}
}
}
logg->log_print("\n");
char_cnt = 0;
......
......@@ -49,6 +49,10 @@
#define RTT_LOGG_LINE_DEFSIZE 512
typedef enum { xtt_LoggType_Cont = 1, xtt_LoggType_Mod = 2 } xtt_LoggType;
typedef enum {
xtt_eLoggFormat_Std,
xtt_eLoggFormat_Py
} xtt_eLoggFormat;
class XttLogging {
public:
......@@ -62,6 +66,7 @@ public:
int stop_logg;
int logg_type;
int logg_priority;
xtt_eLoggFormat logg_format;
pwr_tAName parameterstr[RTT_LOGG_MAXPAR];
pwr_tAName shortname[RTT_LOGG_MAXPAR];
char* parameter_ptr[RTT_LOGG_MAXPAR];
......@@ -88,10 +93,11 @@ public:
void init(int logg_index, void* logg_xnav);
int logging_set(float logg_time, char* filename, char* parameterstr,
char* conditionstr, int logg_type, int insert, int buffer_size, int stop,
char* conditionstr, int logg_type, int logg_format, int insert, int buffer_size, int stop,
int priority, int create, int line_size, int shortname);
int show();
int show_entry(char* buff, int* buff_cnt);
int analyse();
int store(char* filename);
int start();
int stop();
......
......@@ -3211,6 +3211,10 @@ int XNav::show_logging(int index)
new ItemCommand(brow, Lng::translate("Show curve"), 0, NULL,
flow_eDest_IntoLast, command, 0, brow->pixmap_action);
sprintf(command, "logging analyse/entry=current");
new ItemCommand(brow, Lng::translate("Analyse"), 0, NULL,
flow_eDest_IntoLast, command, 0, brow->pixmap_action);
new ItemLocal(brow, Lng::translate("Scantime (ms)"), "logg_Time",
pwr_eType_Float32, sizeof(logg[0].logg_time), 0, 100000, 0,
(void*)&logg[index].logg_time, NULL, flow_eDest_IntoLast);
......@@ -3220,6 +3224,9 @@ int XNav::show_logging(int index)
new ItemLocal(brow, Lng::translate("Type"), "logg_Type", pwr_eType_Int32,
sizeof(logg[0].logg_type), 0, 0, 0, (void*)&logg[index].logg_type, NULL,
flow_eDest_IntoLast);
new ItemLocal(brow, Lng::translate("Format"), "logg_Format", pwr_eType_Int32,
sizeof(logg[0].logg_type), 0, 0, 0, (void*)&logg[index].logg_format, NULL,
flow_eDest_IntoLast);
new ItemLocal(brow, Lng::translate("BufferSize"), "logg_BufferSize",
pwr_eType_Int32, sizeof(logg[0].wanted_buffer_size), 0, 0, 0,
(void*)&logg[index].wanted_buffer_size, NULL, flow_eDest_IntoLast);
......
......@@ -285,7 +285,7 @@ dcli_tCmdTable xnav_command_table[] = {
} },
{ "TEST", &xnav_test_func, { "dcli_arg1", "dcli_arg2", "" } },
{ "LOGGING", &xnav_logging_func,
{ "dcli_arg1", "dcli_arg2", "/FILE", "/TIME", "/ENTRY", "/TYPE",
{ "dcli_arg1", "dcli_arg2", "/FILE", "/TIME", "/ENTRY", "/TYPE", "/FORMAT",
"/PARAMETER", "/CONDITION", "/INSERT", "/BUFFER_SIZE", "/PRIORITY",
"/STOP", "/NOSTOP", "/CREATE", "/ALL", "/LINE_SIZE", "/SHORTNAME",
"/NOSHORTNAME", "" } },
......@@ -6636,6 +6636,7 @@ static int xnav_logging_func(void* client_data, void* client_flag)
int buffer_size;
int nr;
int logg_type = 0;
int logg_format = -1;
int insert;
int create;
int shortname;
......@@ -6717,6 +6718,14 @@ static int xnav_logging_func(void* client_data, void* client_flag)
} else
logg_type = 0;
if (ODD(dcli_get_qualifier("/FORMAT", str, sizeof(str)))) {
if (str_NoCaseStrncmp(str, "STD", strlen(str)) == 0)
logg_format = xtt_eLoggFormat_Std;
else if (str_NoCaseStrncmp(str, "PY", strlen(str)) == 0)
logg_format = xtt_eLoggFormat_Py;
} else
logg_format = -1;
if (ODD(dcli_get_qualifier(
"/PRIORITY", priority_str, sizeof(priority_str)))) {
/* convert to integer */
......@@ -6758,7 +6767,7 @@ static int xnav_logging_func(void* client_data, void* client_flag)
}
sts = xnav->logg[entry - 1].logging_set(logg_time, file_ptr, parameter_ptr,
condition_ptr, logg_type, insert, buffer_size, stop, priority, create,
condition_ptr, logg_type, logg_format, insert, buffer_size, stop, priority, create,
line_size, shortname);
return sts;
}
......@@ -6889,6 +6898,40 @@ static int xnav_logging_func(void* client_data, void* client_flag)
sts = xnav->logg[entry - 1].show();
return sts;
} else if (str_NoCaseStrncmp(arg1_str, "ANALYSE", strlen(arg1_str)) == 0) {
/* Command is "LOGGING ANALYSE" */
char entry_str[80];
int entry;
int nr;
if (ODD(dcli_get_qualifier("/ENTRY", entry_str, sizeof(entry_str)))) {
if (!str_NoCaseStrcmp(entry_str, "CURRENT")) {
if (xnav->current_logging_index == -1) {
xnav->message('E', "No current logging entry");
return XNAV__HOLDCOMMAND;
}
entry = xnav->current_logging_index + 1;
} else {
/* convert to integer */
nr = sscanf(entry_str, "%d", &entry);
if (nr != 1) {
xnav->message('E', "Entry syntax error");
return XNAV__HOLDCOMMAND;
}
}
} else {
xnav->message('E', "Enter entry");
return XNAV__HOLDCOMMAND;
}
if (entry > XNAV_LOGG_MAX || entry < 1) {
xnav->message('E', "Entry out of range");
return XNAV__HOLDCOMMAND;
}
sts = xnav->logg[entry - 1].analyse();
return sts;
} else if (str_NoCaseStrncmp(arg1_str, "STORE", strlen(arg1_str)) == 0) {
/* Command is "LOGGING STORE" */
......
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