You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.7 KiB
69 lines
2.7 KiB
|
|
#include "config.h"
|
|
#include "client.h"
|
|
#include "nwthread.h"
|
|
#include "modbus.h"
|
|
|
|
extern GtkBuilder *_builder_;
|
|
|
|
void log_addtext (int logtype, std::string text, NWTReqResult *data) {
|
|
char timetext[255];
|
|
std::string str;
|
|
GtkWidget *textview = GTK_WIDGET(gtk_builder_get_object (_builder_, "cli_LogText"));
|
|
GtkTextBuffer *textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
|
|
GtkTextIter start, end;
|
|
GtkTextTag *tag_datetime;
|
|
GtkTextTag *tag_data;
|
|
GtkTextTag *tag_info;
|
|
GtkTextTag *tag_error;
|
|
GtkTextTag *tag_status;
|
|
time_t _tm =time(NULL);
|
|
struct tm * curtime = localtime (&_tm);
|
|
static int _once = 0;
|
|
|
|
if (_once == 0) {
|
|
_once = 1;
|
|
tag_datetime = gtk_text_buffer_create_tag (textbuffer, "LogDateTime",
|
|
"foreground", "blue", "style", PANGO_WEIGHT_BOLD, "family", "Monospace", NULL);
|
|
tag_data = gtk_text_buffer_create_tag (textbuffer, "LogData",
|
|
"foreground", "black", "style", PANGO_WEIGHT_NORMAL, "family", "Monospace", NULL);
|
|
tag_info = gtk_text_buffer_create_tag (textbuffer, "LogInfo",
|
|
"foreground", "black", "style", PANGO_WEIGHT_NORMAL, "family", "Sans", NULL);
|
|
tag_status = gtk_text_buffer_create_tag (textbuffer, "LogStatus",
|
|
"foreground", "black", "style", PANGO_WEIGHT_BOLD, "family", "Sans", NULL);
|
|
tag_error = gtk_text_buffer_create_tag (textbuffer, "LogError",
|
|
"foreground", "red", "style", PANGO_WEIGHT_BOLD, "family", "Sans", NULL);
|
|
}
|
|
strftime (timetext, 255, "%H:%M:%S", curtime);
|
|
|
|
//
|
|
// display data if there are any
|
|
//
|
|
if (data != NULL && data->rawdatalen > 0 && data->rawdata != NULL) {
|
|
str = "";
|
|
for (int i = 0; i < data->rawdatalen; i++) {
|
|
if (i & 16) str += "\n ";
|
|
else if (i & 4 && i > 0) str += " ";
|
|
str += to_hex8(data->rawdata[i]);
|
|
}
|
|
gtk_text_buffer_insert_with_tags_by_name(textbuffer, &start, str.c_str(), -1, "LogData", NULL);
|
|
}
|
|
|
|
//
|
|
// display text
|
|
//
|
|
gtk_text_buffer_get_start_iter(textbuffer, &start);
|
|
if (logtype == LOG_CONNECT) gtk_text_buffer_insert_with_tags_by_name(textbuffer, &start, text.c_str(), -1, "LogStatus", NULL);
|
|
else if (logtype == LOG_CLOSE) gtk_text_buffer_insert_with_tags_by_name(textbuffer, &start, text.c_str(), -1, "LogStatus", NULL);
|
|
else if (logtype == LOG_ERROR) gtk_text_buffer_insert_with_tags_by_name(textbuffer, &start, text.c_str(), -1, "LogError", NULL);
|
|
else gtk_text_buffer_insert_with_tags_by_name(textbuffer, &start, text.c_str(), -1, "LogInfo", NULL);
|
|
|
|
//
|
|
// add date
|
|
//
|
|
str = (std::string)"\n" + (std::string)timetext + (std::string)" ";
|
|
gtk_text_buffer_get_start_iter(textbuffer, &start);
|
|
gtk_text_buffer_insert_with_tags_by_name(textbuffer, &start, str.c_str(), -1, "LogDateTime", NULL);
|
|
};
|
|
|