Commit 6fc0bd42 authored by Arnaud Blanchard's avatar Arnaud Blanchard
Browse files

Fix parameters

parent cbafdc1c
# Set the minimum version of cmake required to build this project
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.13)
project(o_gnuplot)
find_package(blc_channel REQUIRED)
find_package(blc_program REQUIRED)
find_package(blc REQUIRED)
add_definitions(${BL_DEFINITIONS} -std=c++14)
include_directories(${BL_INCLUDE_DIRS})
add_executable(o_gnuplot src/o_gnuplot.cpp src/history_graph.cpp src/graph.cpp )
target_link_libraries(o_gnuplot ${BL_LIBRARIES})
target_compile_features(o_gnuplot PRIVATE cxx_std_14)
target_link_libraries(o_gnuplot PRIVATE blc)
......@@ -9,7 +9,7 @@ using namespace std;
void create_graph(FILE *pipef, deque <blc_channel>&inputs, int refresh_period, float ymin, float ymax, float xmin, float xmax, float label_max){
blc_channel *input=nullptr;
char const *gnuplot_format=NULL;
char command[LINE_MAX];
char command[BLC_LINE_MAX];
int i, offset=0, columns_nb=0, rows_nb=0;
size_t element_size;
int ret;
......@@ -59,10 +59,10 @@ void create_graph(FILE *pipef, deque <blc_channel>&inputs, int refresh_period, f
if (inputs.size()>1) EXIT_ON_ERROR("Multiple array of dims > 1 are not managed");
if (surface_option)
{
fprintf(pipef, "set yrange [%f:%f]\n", 0.f, 10.f);
fprintf(pipef, "set yrange [%f:%f]\n", 0.f, static_cast<double>(input->dims[1].length));
fprintf(pipef, "set zrange [%f:%f]\n", ymin, ymax);
fprintf(pipef, "set view 30,190\n");
offset=snprintf(command, LINE_MAX, "splot '-' binary format='%s' array=%dx%d title 'values' with pm3d ", gnuplot_format, columns_nb, rows_nb);
offset=snprintf(command, BLC_LINE_MAX, "splot '-' binary format='%s' array=%dx%d title 'values' with pm3d ", gnuplot_format, columns_nb, rows_nb);
}
else{
if (input->dims[1].length>64) EXIT_ON_ERROR("To many ( '%d' > 64 ) curves to draw", input->dims[1].length );
......@@ -101,6 +101,7 @@ void create_graph(FILE *pipef, deque <blc_channel>&inputs, int refresh_period, f
blc_command_add("M", [](char *argument, void *pipef ) -> void {
fprintf((FILE*)pipef, "\nset yrange [:%s]\n", argument);
}, "real", "max y value", pipef);
BLC_COMMAND_LOOP(refresh_period){
......
......@@ -15,7 +15,7 @@
extern char const *with_option, *style_option, *surface_option;
void create_history_graph(FILE *pipef, std::deque <blc_channel> &inputs, int history_length, int refresh_period, int sampling_period, float min, float max);
void create_graph(FILE *pipef, std::deque <blc_channel> &inputs, int refresh_period, float min, float max, float xmin, float xmax, float label_max);
void create_history_graph(FILE *pipef, std::deque <blc_channel> &inputs, size_t history_length, int refresh_period, int sampling_period, float min, float max);
void create_graph(FILE *pipef, std::deque <blc_channel> &inputs, int refresh_period, float min, float max, float xmin, float xmax, float label_max);
#endif /* history_graph_h */
#include "blc_program.h"
#include "blc_text.h"
#include "graph.h"
#include <pthread.h>
#include <sys/time.h>
......@@ -7,7 +8,9 @@
using namespace std;
typedef struct history:blc_array{
class History:public blc_array{
public:
History(uint32_t type, uint32_t format, vector<size_t> const &lengths);
blc_channel *input;
void init_timer();
int wait_next_k();
......@@ -17,14 +20,17 @@ typedef struct history:blc_array{
int length, sampling_period;
size_t element_size;
unsigned long initial_us;
}type_history;
};
type_history history;
pthread_mutex_t mutex=PTHREAD_MUTEX_INITIALIZER;
int k;
void type_history::init_timer(){
History::History(uint32_t type, uint32_t format, vector<size_t> const &lengths):blc_array(type, format, lengths)
{};
void History::init_timer(){
struct timeval initial_timer;
gettimeofday(&initial_timer, NULL);
......@@ -34,7 +40,7 @@ void type_history::init_timer(){
}
/**This is in order to take into account the absolute time. If an iteration is longer than it should, the next one will be shorter.*/
int type_history::wait_next_k(){
int History::wait_next_k(){
div_t samples_div;
struct timeval timer;
......@@ -49,7 +55,7 @@ int type_history::wait_next_k(){
return div(samples_div.quot, length).rem;
}
template <typename D_t> void history::start_refresh(){
template <typename D_t> void History::start_refresh(){
int i, j, next_k;
D_t *casted_data=(D_t*)data;
D_t *input_data=(D_t*)input->data;
......@@ -81,7 +87,7 @@ template <typename D_t> void history::start_refresh(){
}
static void *refresh_history_cb(void *history_pt){
type_history *history=(type_history*)history_pt;
History *history=(History*)history_pt;
history->init_timer();
......@@ -107,20 +113,21 @@ static void *refresh_history_cb(void *history_pt){
return NULL;
}
void create_history_graph(FILE *pipef, deque <blc_channel> &inputs, int history_length, int refresh_period, int sampling_period, float min, float max){
blc_channel *input=nullptr;
void create_history_graph(FILE *pipef, deque <blc_channel> &inputs, size_t history_length, int refresh_period, int sampling_period, float min, float max){
char const *gnuplot_format=NULL;
char buffer[BLC_LINE_MAX];
string command;
char code;
int i, columns_nb=0;
int i;
size_t columns_nb=0;
pthread_t thread;
if (inputs.size()>1) EXIT_ON_ERROR("Only one channel is managed for history plots");
else input=&inputs.back();
else
{
blc_channel *input=&inputs.back();
switch (input->dims_nb){
case 0:
......@@ -133,6 +140,9 @@ void create_history_graph(FILE *pipef, deque <blc_channel> &inputs, int history_
EXIT_ON_ARRAY_ERROR(input, "Too many dims");
break;
}
History history(input->type, input->format, { columns_nb, history_length});
switch (input->type){
......@@ -178,7 +188,7 @@ void create_history_graph(FILE *pipef, deque <blc_channel> &inputs, int history_
if (min!=max) fprintf(pipef, "set yrange [%f:%f]\n", min, max);
snprintf(buffer, BLC_LINE_MAX, "plot '-' binary format='%s' record=%d using ($0*%f):1 title '%d' with %s", gnuplot_format, history_length, sampling_period/1000000.f, 0, with_option);
snprintf(buffer, BLC_LINE_MAX, "plot '-' binary format='%s' record=%zu using ($0*%f):1 title '%d' with %s", gnuplot_format, history_length, sampling_period/1000000.f, 0, with_option);
command.assign(buffer);
for(i=1; i!=columns_nb; i++){
......@@ -188,11 +198,10 @@ void create_history_graph(FILE *pipef, deque <blc_channel> &inputs, int history_
else if (i==62) code='[';
else if (i==63) code=']';
else EXIT_ON_ERROR("Too many columns. You have '%d' max is 64", columns_nb);
snprintf(buffer, BLC_LINE_MAX, ", '-' binary format='%s' record=%d u ($0*%f):1 t '%c' w %s", gnuplot_format, history_length, sampling_period/1000000.f, code, with_option);
snprintf(buffer, BLC_LINE_MAX, ", '-' binary format='%s' record=%zu u ($0*%f):1 t '%c' w %s", gnuplot_format, history_length, sampling_period/1000000.f, code, with_option);
command.append(buffer);
}
history.init(input->type, input->format, 2, columns_nb, history_length);
history.sampling_period=sampling_period;
history.input=input;
......@@ -209,4 +218,5 @@ void create_history_graph(FILE *pipef, deque <blc_channel> &inputs, int history_
SYSTEM_ERROR_CHECK(fflush(pipef), -1, NULL);
}
SYSTEM_ERROR_CHECK(fclose(pipef), -1, NULL);
}
}
......@@ -31,8 +31,9 @@ void refresh_period_cb(char *argument, void*){
FILE *init_term(char const *title, char const* verbatim){
FILE *pipef;
SYSTEM_ERROR_CHECK(pipef=popen("gnuplot", "w"), NULL, "Calling gnuplot");
SYSTEM_ERROR_CHECK(pipef=popen("gnuplot", "w"), nullptr, "Calling gnuplot");
fprintf(pipef, "set term qt 1 noraise\n"); //Keep focus on the calling terminal
// fprintf(pipef, "set term qt 1 title 'o_gnulot'\n");
fprintf(pipef, "set term qt font \"arial\"\n");
fprintf(pipef, "set datafile nofpe_trap\n"); //Speed up acquisition but crash if there is a problem with the DATA
fprintf(pipef, "set title '%s'\n", title); //axis x en y only
......@@ -56,6 +57,9 @@ int main(int argc, char *argv[]){
int status=0, total_length;
uint32_t type;
int dims_nb;
fprintf(stderr, "start graph %s\n", history_str);
blc_program_set_description("Display the content of the blc_channel depending on its type and format");
blc_program_add_option(&verbatim, 'c', "command", "string", "command directly send to gnuplot", NULL);
......@@ -72,11 +76,15 @@ int main(int argc, char *argv[]){
blc_program_add_option(&refresh_string, 'P', "period", "UI32", "graph refresh period in ms", "100");
blc_program_add_option(&window_string, 'W', "window", "string", "window posistion and size: 'px,py,sx,sy'", nullptr);
blc_program_add_multiple_parameters(&channel_names, "blc_channel", -1, "channel you want to graph");
blc_program_init(&argc, &argv, blc_quit);
fprintf(stderr, "init done graph %s\n", history_str);
blc_command_forward_blc_channels();
fprintf(stderr, "param done graph %s\n", history_str);
for (char *const*channel_name_pt = channel_names; *channel_name_pt!=nullptr; channel_name_pt++){
inputs.emplace_back();
new (&inputs.back()) blc_channel(*channel_name_pt, BLC_CHANNEL_READ);
......@@ -141,6 +149,8 @@ int main(int argc, char *argv[]){
fprintf(pipef, "set term qt 1 position %d,%d size %d,%d\n", px, py, sx, sy);
}
fprintf(stderr, "before graph %s\n", history_str);
if (history_str) create_history_graph(pipef, inputs, strtol(history_str, NULL, 10), sampling_period, strtol(sample_string, NULL, 10)*1000, ymin, ymax);
else create_graph(pipef, inputs, sampling_period, ymin, ymax, xmin, xmax, lmax);
......
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