Commit d62670c4 authored by Claes Sjofors's avatar Claes Sjofors

Trend snapshot, open bugfix and file location

parent 6b8ae122
...@@ -837,14 +837,14 @@ int XttTCurve::load_data( pwr_tStatus *sts, pwr_tAttrRef *aref) ...@@ -837,14 +837,14 @@ int XttTCurve::load_data( pwr_tStatus *sts, pwr_tAttrRef *aref)
int last_idx; int last_idx;
int size; int size;
char *tb; char *tb;
char *vb[10]; char *vb[XTT_TCURVE_MAX];
int header_size = pwr_AlignLW(sizeof(pwr_sClass_CircBuffHeader)); int header_size = pwr_AlignLW(sizeof(pwr_sClass_CircBuffHeader));
*sts = gdh_GetObjectInfoAttrref( aref, &trend, sizeof(trend)); *sts = gdh_GetObjectInfoAttrref( aref, &trend, sizeof(trend));
if ( EVEN(*sts)) return 0; if ( EVEN(*sts)) return 0;
idx = 0; idx = 0;
for ( int j = 0; j < 10; j++) { for ( int j = 0; j < XTT_TCURVE_MAX; j++) {
if ( cdh_ObjidIsNull( trend.Buffers[j].Objid)) if ( cdh_ObjidIsNull( trend.Buffers[j].Objid))
continue; continue;
...@@ -971,7 +971,12 @@ void XttTCurve::save( char *filename) ...@@ -971,7 +971,12 @@ void XttTCurve::save( char *filename)
{ {
pwr_tFileName fname; pwr_tFileName fname;
strcpy( fname, filename); if ( strchr( filename, '/') == 0)
strcpy( fname, "$pwrp_load/");
else
strcpy( fname, "");
strncat( fname, filename, sizeof(fname));
if ( !( strlen(filename) < 9 && if ( !( strlen(filename) < 9 &&
strcmp( &filename[strlen(filename)-9], ".rtt_trd") == 0)) strcmp( &filename[strlen(filename)-9], ".rtt_trd") == 0))
strncat( fname, ".rtt_trd", sizeof(fname)); strncat( fname, ".rtt_trd", sizeof(fname));
...@@ -998,8 +1003,10 @@ void XttTCurve::open( char *filename) ...@@ -998,8 +1003,10 @@ void XttTCurve::open( char *filename)
{ {
pwr_tFileName fname; pwr_tFileName fname;
pwr_tStatus sts; pwr_tStatus sts;
tcurve_sTc *tcp;
strcpy( fname, filename); strcpy( fname, "$pwrp_load/");
strncat( fname, filename, sizeof(fname));
if ( !( strlen(filename) < 9 && if ( !( strlen(filename) < 9 &&
strcmp( &filename[strlen(filename)-9], ".rtt_trd") == 0)) strcmp( &filename[strlen(filename)-9], ".rtt_trd") == 0))
strncat( fname, ".rtt_trd", sizeof(fname)); strncat( fname, ".rtt_trd", sizeof(fname));
...@@ -1012,23 +1019,42 @@ void XttTCurve::open( char *filename) ...@@ -1012,23 +1019,42 @@ void XttTCurve::open( char *filename)
return; return;
} }
// Free old data
free( tc.tbuf);
for ( int i = 0; i < tc.bufcnt; i++)
free( tc.vbuf[i]);
fp.read( (char *)&aref_cnt, sizeof(aref_cnt)); fp.read( (char *)&aref_cnt, sizeof(aref_cnt));
if ( aref_cnt > XTT_TCURVE_MAX) {
printf( "Read error\n");
return;
}
fp.read( (char *)arefv, aref_cnt * sizeof(arefv[0])); fp.read( (char *)arefv, aref_cnt * sizeof(arefv[0]));
fp.read( (char *)&tc, sizeof(tc)); tcp = (tcurve_sTc *)calloc( 1, sizeof(tcurve_sTc));
tc.tbuf = (char *)calloc( 1, tc.timebuf_bsize); fp.read( (char *)tcp, sizeof(*tcp));
fp.read( tc.tbuf, tc.timebuf_bsize);
for ( int i = 0; i < tc.bufcnt; i++) { if ( tcp->bufcnt > XTT_TCURVE_MAX || tcp->timebuf_bsize > 20000000) {
tc.vbuf[i] = (char *)calloc( 1, tc.buf_bsize[i]); printf( "Read error\n");
fp.read( tc.vbuf[i], tc.buf_bsize[i]); return;
}
for ( int i = 0; i < tcp->bufcnt; i++) {
if ( tcp->buf_bsize[i] > 20000000) {
printf( "Read error\n");
return;
}
}
tcp->tbuf = (char *)calloc( 1, tcp->timebuf_bsize);
fp.read( tcp->tbuf, tcp->timebuf_bsize);
for ( int i = 0; i < tcp->bufcnt; i++) {
tcp->vbuf[i] = (char *)calloc( 1, tcp->buf_bsize[i]);
fp.read( tcp->vbuf[i], tcp->buf_bsize[i]);
} }
fp.close(); fp.close();
// Free old data
free( tc.tbuf);
for ( int i = 0; i < tc.bufcnt; i++)
free( tc.vbuf[i]);
memcpy( &tc, tcp, sizeof(tc));
free( tcp);
pwr_tTime from = pwr_cNTime; pwr_tTime from = pwr_cNTime;
pwr_tTime to = {0xEFFFFFFF, 0}; pwr_tTime to = {0xEFFFFFFF, 0};
get_data( &sts, from, to); get_data( &sts, from, to);
......
...@@ -56,21 +56,21 @@ ...@@ -56,21 +56,21 @@
/*! \addtogroup Xtt */ /*! \addtogroup Xtt */
/*@{*/ /*@{*/
#define XTT_TCURVE_MAX 20 #define XTT_TCURVE_MAX 10
class CoWow; class CoWow;
class CoWowTimer; class CoWowTimer;
typedef struct { typedef struct {
pwr_tAName name[10]; pwr_tAName name[XTT_TCURVE_MAX];
pwr_tAttrRef buf_aref[10]; pwr_tAttrRef buf_aref[XTT_TCURVE_MAX];
pwr_tAttrRef timebuf_aref; pwr_tAttrRef timebuf_aref;
int element_size[10]; int element_size[XTT_TCURVE_MAX];
pwr_eType type[10]; pwr_eType type[XTT_TCURVE_MAX];
int buf_size[10]; int buf_size[XTT_TCURVE_MAX];
int buf_bsize[10]; int buf_bsize[XTT_TCURVE_MAX];
int buf_samples[10]; int buf_samples[XTT_TCURVE_MAX];
char *vbuf[10]; char *vbuf[XTT_TCURVE_MAX];
int bufcnt; int bufcnt;
int timeelement_size; int timeelement_size;
int timebuf_size; int timebuf_size;
......
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