Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ win-mingw/bin/fake_qmake.exe
win-mingw/bin/rlsvgcat.exe
language_bindings/lua/pvslua/pvslua
language_bindings/lua/pvslua/pvapplua
/.cproject
/.project
/.settings/
1 change: 1 addition & 0 deletions .settings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/language.settings.xml
6 changes: 5 additions & 1 deletion rllib/lib/rldefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ The header that is included in every file of rllib.
#define BIT30 256*256*256*64
#define BIT31 256*256*256*128

#define RLCRLF "\r\n"
#define RLCRLF "\r\n"

#if __cplusplus >= 201103
#define RLCPP11
#endif

#endif
7 changes: 4 additions & 3 deletions rllib/lib/rleibnetip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ static void *eib_reader(void *arg) // thread
THREAD_PARAM *p = (THREAD_PARAM *) arg;
rlEIBnetIP *eib = (rlEIBnetIP *) p->user;
rlEIBnetIP::PDU pdu;
rlTime now, last, diff;
rlTime now, last;
double diff;
int ret, len;
int recseq = 0;
int expected_recseq = 0;
Expand Down Expand Up @@ -136,7 +137,7 @@ static void *eib_reader(void *arg) // thread
}
}
diff = now - last;
if(eib->isConnected() && eib->channelid != -1 && diff.second > 50)
if(eib->isConnected() && eib->channelid != -1 && diff > 50)
{ // send heartbeat
if(eib->debug) ::printf("send heartbeat\n");
pdu.headersize = EIB_HEADERSIZE;
Expand Down Expand Up @@ -789,7 +790,7 @@ int rlEIBnetIP::getText(const char *name, char *text, int maxlen)

int rlEIBnetIP::setText(const char *name, const char *text)
{
if(name == NULL || text == NULL) return rlEIBnetIP::EIBERROR;
if(name == NULL || text == NULL) return rlEIBnetIP::EIBERROR;
char buf[16];
int length = strlen(text);
unsigned int a1,a2,a3,daddr;
Expand Down
69 changes: 55 additions & 14 deletions rllib/lib/rlhistorylogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "rlcutil.h"
#include <string.h>

#define MAXBUF 256*256

rlHistoryLogger::rlHistoryLogger(const char *csvName, int maxHoursPerFile, int maxLinesInMemory)
{
int val;
Expand All @@ -26,13 +28,7 @@ rlHistoryLogger::rlHistoryLogger(const char *csvName, int maxHoursPerFile, int m
max_hours_per_file = maxHoursPerFile;
if(max_hours_per_file <= 0) max_hours_per_file = 1;
val = max_hours_per_file;
time_diff.hour = val % 24;
val = val / 24;
time_diff.day = val % 31; // we are on the save side if we assume a month with 31 days
val = val / 31;
time_diff.month = val % 12;
val = val / 12;
time_diff.year = val;
time_diff = val * 3600;
max_lines_in_memory = maxLinesInMemory;
if(max_lines_in_memory <= 0) max_lines_in_memory = 1;
current_file = -1;
Expand Down Expand Up @@ -151,29 +147,74 @@ int rlHistoryLogger::openFile()
{
// find oldest file and open it for writing
int i_oldest = 0;
rlTime t,t_oldest;
int i_youngest = 0;
int file_count = 0;
rlTime t, t_oldest, t_youngest;
t_oldest.getLocalTime(); // this must be newer that any file time
for(int i=0; i<10; i++)
{
sprintf(csv_file_name,"%s%d.csv",csv_name,i);
if(t.getFileModificationTime(csv_file_name) == 0)
{
if(t < t_oldest) i_oldest = i;
if(t < t_oldest)
{
i_oldest = i;
t_oldest = t;
}
if (t > t_youngest)
{
i_youngest = i;
t_youngest = t;
}
++file_count;
}
else // create missing file
{
FILE* f = fopen(csv_file_name, "w");
if (f)
fclose(f);
}
}
current_file = i_oldest;
sprintf(csv_file_name,"%s%d.csv",csv_name,i_oldest);
fout = fopen(csv_file_name,"w");

if ((t_youngest + time_diff) > time) // file is in our time slot, append; this reduces data loss in case of frequent restarts
{
current_file = i_youngest;
sprintf(csv_file_name, "%s%d.csv", csv_name, current_file);

// "a+" does not work reliable,
// under Windows is the order of creation of read- and write-pointer unpredictable,
// they are not independent and the file IO layer has problems after
// system crashes or UID changes,
// this leads to unexplored problems, which prevent successful data write operations
fout = fopen(csv_file_name, "r");
auto buf = new char[MAXBUF];
if (fgets(buf, MAXBUF-1, fout) != NULL)
file_start_time.setTimeFromString(buf);
else
file_start_time = t_youngest;
delete[] buf;
fclose(fout);
fout = fopen(csv_file_name, "a");
}
else
{
// oldest file is old enough for truncation
current_file = i_oldest;
sprintf(csv_file_name, "%s%d.csv", csv_name, current_file);
fout = fopen(csv_file_name,"w");
file_start_time.getLocalTime();
}
}
else
{
// open next file for writing
current_file++;
if(current_file >= 10) current_file = 0;
if(current_file >= 10)
current_file = 0;
sprintf(csv_file_name,"%s%d.csv",csv_name,current_file);
fout = fopen(csv_file_name,"w");
file_start_time.getLocalTime();
}
file_start_time.getLocalTime();
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion rllib/lib/rlhistorylogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class rlHistoryLogger
int pushLineToFile(const char *line);
int openFile();
rlHistoryLogLine *first_line,*current_line;
rlTime time,file_start_time,time_diff;
rlTime time,file_start_time;
time_t time_diff;
FILE *fout;
int max_hours_per_file, max_lines_in_memory, current_file;
char *csv_name, *csv_file_name;
Expand Down
Loading