Commit 235be748 authored by Claes Sjöfors's avatar Claes Sjöfors

Xtt sevhist export all, and read exported file

parent c2635224
......@@ -102,6 +102,35 @@ XttSevHistGtk::XttSevHistGtk( void *parent_ctx,
timerid->add( 1000, sevhist_scan, this);
}
XttSevHistGtk::XttSevHistGtk( void *parent_ctx,
GtkWidget *parent_wid,
const char *name,
GtkWidget **w,
char *filename,
int *sts) :
XttSevHist( parent_ctx, name, filename, sts),
parent_widget(parent_wid)
{
char title[250];
strncpy(title, name, sizeof(title));
if ( EVEN(*sts))
// Error from XttSevHist
return;
*sts = XNAV__SUCCESS;
curve = new GeCurveGtk( this, parent_widget, title, NULL, gcd, 1);
curve->close_cb = sevhist_close_cb;
curve->help_cb = sevhist_help_cb;
curve->enable(0);
wow = new CoWowGtk( parent_widget);
timerid = wow->timer_new();
timerid->add( 1000, sevhist_scan, this);
}
XttSevHistGtk::~XttSevHistGtk()
{
timerid->remove();
......
......@@ -57,6 +57,12 @@ class XttSevHistGtk : public XttSevHist {
bool *sevhistobjectv,
sevcli_tCtx xn_scctx,
int *sts);
XttSevHistGtk( void *parent_ctx,
GtkWidget *parent_wid,
const char *name,
GtkWidget **w,
char *filename,
int *sts);
~XttSevHistGtk();
};
......
......@@ -251,11 +251,14 @@ XttTrend *XNavGtk::xtttrend_new( char *name, pwr_tAttrRef *objar, pwr_tAttrRef *
}
XttSevHist *XNavGtk::xttsevhist_new( char *name, pwr_tOid *oidv, pwr_tOName *anamev, pwr_tOName *onamev,
bool *sevhistobjectv, sevcli_tCtx scctx, pwr_tStatus *sts)
bool *sevhistobjectv, sevcli_tCtx scctx, char *filename, pwr_tStatus *sts)
{
GtkWidget *w;
return new XttSevHistGtk( this, parent_wid, name, &w, oidv, anamev, onamev, sevhistobjectv, scctx, sts);
if ( !filename)
return new XttSevHistGtk( this, parent_wid, name, &w, oidv, anamev, onamev, sevhistobjectv, scctx, sts);
else
return new XttSevHistGtk( this, parent_wid, name, &w, filename, sts);
}
XttTCurve *XNavGtk::xtttcurve_new( char *name, pwr_tAttrRef *arefv, pwr_tStatus *sts)
......
......@@ -79,7 +79,7 @@ class XNavGtk : public XNav {
pwr_tStatus *sts);
XttSevHist *xttsevhist_new( char *name, pwr_tOid *oidv, pwr_tOName *anamev,
pwr_tOName *onamev, bool *sevhistobjectv, sevcli_tCtx scctx,
pwr_tStatus *sts);
char *filename, pwr_tStatus *sts);
XttTCurve *xtttcurve_new( char *name, pwr_tAttrRef *arefv, pwr_tStatus *sts);
XttFast *xttfast_new( char *name, pwr_tAttrRef *objar, pwr_tStatus *sts);
XAttOne *xattone_new( pwr_tAttrRef *objar, char *title, unsigned int priv,
......
......@@ -105,6 +105,18 @@ XttSevHist::XttSevHist( void *parent_ctx,
cdh_StrncpyCutOff( title, name, sizeof(title), 1);
}
XttSevHist::XttSevHist( void *parent_ctx,
const char *name,
char *filename,
int *sts) :
xnav(parent_ctx), gcd(0), curve(0), rows(0), vsize(0), timerid(0), close_cb(0), help_cb(0),
get_select_cb(0), first_scan(1), scctx(0), time_low_old(0), time_high_old(0)
{
strncpy( title, filename, sizeof(title));
*sts = read_export( filename);
}
XttSevHist::~XttSevHist()
{
}
......@@ -120,8 +132,12 @@ int XttSevHist::get_data( pwr_tStatus *sts, pwr_tTime from, pwr_tTime to)
void *vbuf;
pwr_tDeltaTime trange;
if ( curve)
curve->set_clock_cursor();
sevcli_get_itemdata( sts, scctx, oidv[0], anamev[0], from, to, 1000, &tbuf, &vbuf,
&rows, &vtype, &vsize);
if ( curve)
curve->reset_cursor();
if ( EVEN(*sts))
return 0;
......@@ -230,8 +246,12 @@ int XttSevHist::get_objectdata( pwr_tStatus *sts, pwr_tTime from, pwr_tTime to)
pwr_tDeltaTime trange;
if ( curve)
curve->set_clock_cursor();
sevcli_get_objectitemdata( sts, scctx, oidv[0], anamev[0], from, to, 1000, &tbuf, &vbuf,
&rows, &histattrbuf, &numAttributes);
if ( curve)
curve->reset_cursor();
if ( EVEN(*sts))
return 0;
......@@ -393,8 +413,12 @@ int XttSevHist::get_multidata( pwr_tStatus *sts, pwr_tTime from, pwr_tTime to)
}
if ( !sevhistobjectv[k]) {
if ( curve)
curve->set_clock_cursor();
sevcli_get_itemdata( sts, scctx, oidv[k], anamev[k], from, to, 1000, &tbuf, &vbuf,
&rows, &vtype, &vsize);
if ( curve)
curve->reset_cursor();
if ( EVEN(*sts))
return 0;
......@@ -864,63 +888,221 @@ int XttSevHist::sevhist_export_cb( void *ctx, pwr_tTime *from, pwr_tTime *to, in
int rrows;
char timestr[40];
FILE *fp;
pwr_tOName oname;
dcli_translate_filename( fname, filename);
if ( idx == -1) {
// Export all attributes
fp = fopen( fname, "w");
if ( !fp)
return SEV__EXPORTFILE;
for ( int j = 0; j < sevhist->oid_cnt; j++) {
sts = gdh_ObjidToName ( sevhist->oidv[j], oname, sizeof(oname),
cdh_mName_volumeStrict);
if ( EVEN(sts)) continue;
fprintf( fp, "# Attribute %s.%s\n", oname, sevhist->anamev[j]);
sevhist->curve->set_clock_cursor();
sevcli_get_itemdata( &sts, sevhist->scctx, sevhist->oidv[j], sevhist->anamev[j], *from, *to,
rows, &tbuf, &vbuf, &rrows, &vtype, &vsize);
sevhist->curve->reset_cursor();
if ( EVEN(sts))
return sts;
if( rrows == 0 )
continue;
fprintf( fp, "# Rows %d\n", rrows);
for ( int i = 0; i < rrows; i++) {
time_AtoAscii( &tbuf[i], time_eFormat_DateAndTime, timestr, sizeof(timestr));
fprintf( fp, "%s, ", timestr);
switch ( vtype) {
case pwr_eType_Int32:
case pwr_eType_Int64:
case pwr_eType_Int16:
case pwr_eType_Int8:
fprintf( fp, "%d", ((pwr_tInt32 *)vbuf)[i]);
break;
case pwr_eType_UInt64:
case pwr_eType_UInt32:
case pwr_eType_UInt16:
case pwr_eType_UInt8:
fprintf( fp, "%u", ((pwr_tUInt32 *)vbuf)[i]);
break;
case pwr_eType_Float32:
fprintf( fp, "%g", ((pwr_tFloat32 *)vbuf)[i]);
break;
case pwr_eType_Float64:
fprintf( fp, "%g", ((pwr_tFloat64 *)vbuf)[i]);
break;
case pwr_eType_Boolean:
fprintf( fp, "%d", ((pwr_tBoolean *)vbuf)[i]);
break;
default:
sts = SEV__CURVETYPE;
}
fprintf( fp, "\n");
}
free( tbuf);
free( vbuf);
}
fclose( fp);
}
else {
sevhist->curve->set_clock_cursor();
sevcli_get_itemdata( &sts, sevhist->scctx, sevhist->oidv[idx], sevhist->anamev[idx], *from, *to,
rows, &tbuf, &vbuf, &rrows, &vtype, &vsize);
sevhist->curve->reset_cursor();
if ( EVEN(sts))
return sts;
if( rrows == 0 ) {
return SEV__NODATATIME;
}
fp = fopen( fname, "w");
if ( !fp)
return SEV__EXPORTFILE;
for ( int i = 0; i < rrows; i++) {
time_AtoAscii( &tbuf[i], time_eFormat_DateAndTime, timestr, sizeof(timestr));
fprintf( fp, "%s, ", timestr);
switch ( vtype) {
case pwr_eType_Int32:
case pwr_eType_Int64:
case pwr_eType_Int16:
case pwr_eType_Int8:
fprintf( fp, "%d", ((pwr_tInt32 *)vbuf)[i]);
break;
case pwr_eType_UInt64:
case pwr_eType_UInt32:
case pwr_eType_UInt16:
case pwr_eType_UInt8:
fprintf( fp, "%u", ((pwr_tUInt32 *)vbuf)[i]);
break;
case pwr_eType_Float32:
fprintf( fp, "%g", ((pwr_tFloat32 *)vbuf)[i]);
break;
case pwr_eType_Float64:
fprintf( fp, "%g", ((pwr_tFloat64 *)vbuf)[i]);
break;
case pwr_eType_Boolean:
fprintf( fp, "%d", ((pwr_tBoolean *)vbuf)[i]);
break;
default:
sts = SEV__CURVETYPE;
}
fprintf( fp, "\n");
}
free( tbuf);
free( vbuf);
fclose( fp);
sevcli_get_itemdata( &sts, sevhist->scctx, sevhist->oidv[idx], sevhist->anamev[idx], *from, *to,
rows, &tbuf, &vbuf, &rrows, &vtype, &vsize);
if ( EVEN(sts))
return sts;
printf( "Exported %d rows to file \"%s\" (%d)\n", rrows, fname, idx);
if( rrows == 0 ) {
return SEV__NODATATIME;
if ( EVEN(sts))
return sts;
}
return SEV__SUCCESS;
}
int XttSevHist::read_export( char *filename)
{
pwr_tFileName fname;
FILE *fp;
char line[200];
int idx = -1;
int rowcnt = 0;
int rows;
char timstr[40];
double y;
char *s;
pwr_tStatus sts;
pwr_tTime t;
fp = fopen( fname, "w");
dcli_translate_filename( fname, filename);
fp = fopen( fname, "r");
if ( !fp)
return SEV__EXPORTFILE;
return 0;
for ( int i = 0; i < rrows; i++) {
time_AtoAscii( &tbuf[i], time_eFormat_DateAndTime, timestr, sizeof(timestr));
fprintf( fp, "%s, ", timestr);
switch ( vtype) {
case pwr_eType_Int32:
case pwr_eType_Int64:
case pwr_eType_Int16:
case pwr_eType_Int8:
fprintf( fp, "%d", ((pwr_tInt32 *)vbuf)[i]);
break;
case pwr_eType_UInt64:
case pwr_eType_UInt32:
case pwr_eType_UInt16:
case pwr_eType_UInt8:
fprintf( fp, "%u", ((pwr_tUInt32 *)vbuf)[i]);
break;
case pwr_eType_Float32:
fprintf( fp, "%g", ((pwr_tFloat32 *)vbuf)[i]);
break;
case pwr_eType_Float64:
fprintf( fp, "%g", ((pwr_tFloat64 *)vbuf)[i]);
break;
case pwr_eType_Boolean:
fprintf( fp, "%d", ((pwr_tBoolean *)vbuf)[i]);
gcd = new GeCurveData( curve_eDataType_DsTrend);
while( 1) {
sts = dcli_read_line( line, sizeof(line), fp);
if ( !sts)
break;
default:
sts = SEV__CURVETYPE;
if ( line[0] == '#') {
if ( strncmp( &line[2], "Attribute", 9) == 0) {
// New attribute
idx++;
strncpy( onamev[idx], &line[12], sizeof(onamev[0]));
s = strchr( onamev[idx], '.');
if ( s) {
*s = 0;
strncpy( anamev[idx], s+1, sizeof(anamev[0]));
}
rowcnt = 0;
gcd->y_axis_type[idx] = curve_eAxis_y;
gcd->x_axis_type[idx] = curve_eAxis_x;
strcpy( gcd->x_format[idx], "%11t");
strcpy( gcd->y_name[idx], onamev[idx]);
strcat( gcd->y_name[idx], ".");
strcat( gcd->y_name[idx], anamev[idx]);
}
else if ( strncmp( &line[2], "Rows", 4) == 0) {
if ( idx < 0)
continue;
sscanf( &line[7], "%d", &rows);
gcd->rows[idx] = rows;
gcd->x_data[idx] = (double *) calloc( 1, 8 * rows);
gcd->y_data[idx] = (double *) calloc( 1, 8 * rows);
}
}
else {
if ( idx < 0)
continue;
strncpy( timstr, line, 23);
timstr[23] = 0;
sscanf( &line[25], "%lf", &y);
if ( rowcnt > gcd->rows[idx])
continue;
time_AsciiToA( timstr, &t);
gcd->x_data[idx][rowcnt] = (double)t.tv_sec + (double)1e-9 * t.tv_nsec;
gcd->y_data[idx][rowcnt] = y;
rowcnt++;
}
fprintf( fp, "\n");
}
free( tbuf);
free( vbuf);
fclose( fp);
if ( idx > 0)
gcd->rows[idx-1] = rowcnt;
gcd->cols = idx + 1;
printf( "Exported %d rows to file \"%s\" (%d)\n", rrows, fname, idx);
fclose(fp);
if ( EVEN(sts))
return sts;
gcd->get_borders();
gcd->get_default_axis();
gcd->select_color( 0);
strcpy( gcd->x_format[0], "%11t");
return SEV__SUCCESS;
if ( curve) {
curve->set_curvedata( gcd); // This will free the old gcd
curve->configure_curves();
curve->configure_axes();
curve->redraw();
}
return 1;
}
void XttSevHist::sevhist_help_cb( void *ctx)
......
......@@ -104,6 +104,10 @@ class XttSevHist {
bool *sevhistobjectv,
sevcli_tCtx xn_scctx,
int *sts);
XttSevHist( void *parent_ctx,
const char *name,
char *filename,
int *sts);
//! Destructor
virtual ~XttSevHist();
......@@ -115,6 +119,7 @@ class XttSevHist {
int get_multidata( pwr_tStatus *sts, pwr_tTime from, pwr_tTime to);
void curve_add( pwr_tOid oid, pwr_tOName aname, pwr_tOName oname,
bool sevhistobject);
int read_export( char *filename);
static void sevhist_close_cb( void *ctx);
static void sevhist_increase_period_cb( void *ctx);
......
......@@ -262,6 +262,31 @@ XttTrend::XttTrend( void *parent_ctx,
gcd->get_default_axis();
gcd->select_color( 0);
// Try to find unit and descripion
for ( i = 0; i < trend_cnt; i++) {
pwr_tAName aname;
char unit[40];
char description[80];
pwr_tStatus lsts;
char *s;
strcpy( aname, object_name[i]);
if ( (s = strrchr( aname, '.')))
*s = 0;
strcat( aname, ".Unit");
lsts = gdh_GetObjectInfo( aname, unit, sizeof(unit));
if ( ODD(lsts))
strncpy( gcd->y_unit[i], unit, sizeof(gcd->y_unit[0]));
strcpy( aname, object_name[i]);
if ( (s = strrchr( aname, '.')))
*s = 0;
strcat( aname, ".Description");
lsts = gdh_GetObjectInfo( aname, description, sizeof(description));
if ( ODD(lsts))
strncpy( gcd->y_description[i], description, sizeof(gcd->y_description[0]));
}
if ( !trend_list) {
// Use axis values from plotgroup object
for ( i = 0; i < trend_cnt; i++) {
......@@ -353,6 +378,31 @@ XttTrend::XttTrend( void *parent_ctx,
}
gcd->x_axis_type[0] = curve_eAxis_x;
// Try to find unit
for ( i = 0; i < trend_cnt; i++) {
pwr_tAName aname;
char unit[40];
char description[80];
pwr_tStatus lsts;
char *s;
strcpy( aname, object_name[i]);
if ( (s = strrchr( aname, '.')))
*s = 0;
strcat( aname, ".Unit");
lsts = gdh_GetObjectInfo( aname, unit, sizeof(unit));
if ( ODD(lsts))
strncpy( gcd->y_unit[i], unit, sizeof(gcd->y_unit[0]));
strcpy( aname, object_name[i]);
if ( (s = strrchr( aname, '.')))
*s = 0;
strcat( aname, ".Description");
lsts = gdh_GetObjectInfo( aname, description, sizeof(description));
if ( ODD(lsts))
strncpy( gcd->y_description[i], description, sizeof(gcd->y_description[0]));
}
for ( i = 0; i < trend_cnt; i++) {
gcd->y_data[i] = (double *) calloc( 1, 8 * max_points);
......
......@@ -350,7 +350,7 @@ class XNav {
pwr_tStatus *sts) {return 0;}
virtual XttSevHist *xttsevhist_new( char *name, pwr_tOid *oidv, pwr_tOName *aname,
pwr_tOName *oname, bool *sevhistobjectv, sevcli_tCtx scctx,
pwr_tStatus *sts) {return 0;}
char *filename, pwr_tStatus *sts) {return 0;}
virtual XttTCurve *xtttcurve_new( char *name, pwr_tAttrRef *arefv, pwr_tStatus *sts) {return 0;}
virtual XttFast *xttfast_new( char *name, pwr_tAttrRef *objar, pwr_tStatus *sts) {return 0;}
virtual XAttOne *xattone_new( pwr_tAttrRef *objar, char *title, unsigned int priv,
......
......@@ -3689,9 +3689,20 @@ static int xnav_open_func( void *client_data,
pwr_tAName aname;
char *s;
bool sevHistObjectFound = false;
pwr_tFileName file_str;
// Command is "OPEN HISTORY"
if ( ODD( dcli_get_qualifier( "/FILE", file_str, sizeof(file_str)))) {
// Open exported history file
hist = xnav->xttsevhist_new( title_str, 0, 0, 0, 0, 0, file_str, &sts);
if ( ODD(sts)) {
hist->help_cb = xnav_sevhist_help_cb;
hist->get_select_cb = xnav_sevhist_get_select_cb;
}
return XNAV__SUCCESS;
}
/* Get the name qualifier */
if ( ODD( dcli_get_qualifier( "dcli_arg2", name_str, sizeof(name_str)))) {
if ( name_str[0] != '/')
......@@ -3930,21 +3941,21 @@ static int xnav_open_func( void *client_data,
}
if ( plotgroup_found) {
hist = xnav->xttsevhist_new( title_str, oidv, anamev, onamev, sevhistobjectv, xnav->scctx, &sts);
hist = xnav->xttsevhist_new( title_str, oidv, anamev, onamev, sevhistobjectv, xnav->scctx, 0, &sts);
if ( ODD(sts)) {
hist->help_cb = xnav_sevhist_help_cb;
hist->get_select_cb = xnav_sevhist_get_select_cb;
}
}
else if( sevHistObjectFound ) {
hist = xnav->xttsevhist_new( title_str, oidv, anamev, onamev, sevhistobjectv, xnav->scctx, &sts);
hist = xnav->xttsevhist_new( title_str, oidv, anamev, onamev, sevhistobjectv, xnav->scctx, 0, &sts);
if ( ODD(sts)) {
hist->help_cb = xnav_sevhist_help_cb;
hist->get_select_cb = xnav_sevhist_get_select_cb;
}
}
else {
hist = xnav->xttsevhist_new( title_str, oidv, anamev, onamev, sevhistobjectv, xnav->scctx, &sts);
hist = xnav->xttsevhist_new( title_str, oidv, anamev, onamev, sevhistobjectv, xnav->scctx, 0, &sts);
if ( ODD(sts)) {
hist->help_cb = xnav_sevhist_help_cb;
hist->get_select_cb = xnav_sevhist_get_select_cb;
......
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