o_textgraph.cpp 1.55 KB
#include "blc_core.h"
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h>
#include <termios.h>
#include <libgen.h> //basename


int fprint_spikes_uchars(blc_mem *mem, FILE *file, const char *title, int width){
    char c;
    int i, j;
    
    fprintf(file, "[%s]\n", title);
    FOR(j, 8){
        FOR(i, mem->size){
            c=((1<<j) & mem->uchars[i])?'.':' ';
            fputc(c, file);
        }
        fputc('\n', file);

    }
    return 9;
}

int main(int argc, char** argv){
    blc_channel channel;
    char const  *period_str;
    char const *channel_name, *filename, *time_str;
    char const *number_str;
    char const *ext;
    FILE *file;
    int number;
    int  period;
    struct timeval timer;
    
    blc_program_set_description("Display a text graph of blc_channel in the terminal");
    blc_program_add_option(&period_str, 'p', "period", "integer", "Period in ms to refresh the graph", "0");
    blc_program_add_parameter(&channel_name, "blc_channel-in", 1, "channel to graph", NULL);
    blc_program_init(&argc, &argv, blc_quit);
    blc_command_forward_blc_channels();

    period=strtol(period_str, NULL,10)*1000;
    
    channel.open(channel_name, BLC_CHANNEL_READ);
    blc_loop_try_add_waiting_semaphore(channel.sem_new_data);
    blc_loop_try_add_posting_semaphore(channel.sem_ack_data);
    
    BLC_COMMAND_LOOP(period){
        //if (blc_loop_iteration!=0);
        blc_eprint_cursor_up(8);
        fprint_spikes_uchars(&channel, stderr, channel_name, 16);
        blc_eprint_cursor_up(8);


    }
    return EXIT_SUCCESS;
}