Commit e551e96129014f54df87551b3fefda1275f64894

Authored by Arnaud Blanchard
1 parent b8149f2e

Add functions to display graph in text mode

  1 +# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS
  2 +# Author: Arnaud Blanchard (November 2016)
  3 +# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
  4 +# You can use, modify and/ or redistribute the software under the terms of the CeCILL v2.1 license as circulated by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
  5 +# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
  6 +# users are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive licensors have only limited liability.
  7 +# In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software,
  8 +# that may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge.
  9 +# Users are therefore encouraged to load and test the software's suitability as regards their requirements in conditions enabling the security of their systems and/or data to be ensured  and, more generally, to use and operate it in the same conditions as regards security.
  10 +# The fact that you are presently reading this means that you have had knowledge of the CeCILL v2.1 license and that you accept its terms.
  11 +
  12 +cmake_minimum_required(VERSION 2.6)
  13 +
  14 +#The name of the project is the basename of the directory
  15 +get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
  16 +project(${PROJECT_NAME})
  17 +
  18 +find_package(blc_channel REQUIRED)
  19 +find_package(blc_program REQUIRED)
  20 +
  21 +add_definitions(${BL_DEFINTIIONS})
  22 +include_directories(${BL_INCLUDE_DIRS})
  23 +add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp)
  24 +target_link_libraries(${PROJECT_NAME} ${BL_LIBRARIES})
  25 +
  26 +
  27 +
  28 +
  1 +#include "blc_core.h"
  2 +#include "blc_channel.h"
  3 +#include "blc_program.h"
  4 +#include <unistd.h>
  5 +#include <termios.h>
  6 +#include <libgen.h> //basename
  7 +
  8 +
  9 +int fprint_spikes_uchars(blc_mem *mem, FILE *file, const char *title, int width){
  10 + char c;
  11 + int i, j;
  12 +
  13 + fprintf(file, "[%s]\n", title);
  14 + FOR(j, 8){
  15 + FOR(i, mem->size){
  16 + c=((1<<j) & mem->uchars[i])?'.':' ';
  17 + fputc(c, file);
  18 + }
  19 + fputc('\n', file);
  20 +
  21 + }
  22 + return 9;
  23 +}
  24 +
  25 +int main(int argc, char** argv){
  26 + blc_channel channel;
  27 + char const *period_str;
  28 + char const *channel_name, *filename, *time_str;
  29 + char const *number_str;
  30 + char const *ext;
  31 + FILE *file;
  32 + int number;
  33 + int period;
  34 + struct timeval timer;
  35 +
  36 + blc_program_set_description("Display a text graph of blc_channel in the terminal");
  37 + blc_program_add_option(&period_str, 'p', "period", "integer", "Period in ms to refresh the graph", "0");
  38 + blc_program_add_parameter(&channel_name, "blc_channel-in", 1, "channel to graph", NULL);
  39 + blc_program_init(&argc, &argv, blc_quit);
  40 + blc_command_forward_blc_channels();
  41 +
  42 + period=strtol(period_str, NULL,10)*1000;
  43 +
  44 + channel.open(channel_name, BLC_CHANNEL_READ);
  45 + blc_loop_try_add_waiting_semaphore(channel.sem_new_data);
  46 + blc_loop_try_add_posting_semaphore(channel.sem_ack_data);
  47 +
  48 + BLC_COMMAND_LOOP(period){
  49 + //if (blc_loop_iteration!=0);
  50 + blc_eprint_cursor_up(8);
  51 + fprint_spikes_uchars(&channel, stderr, channel_name, 16);
  52 + blc_eprint_cursor_up(8);
  53 +
  54 +
  55 + }
  56 + return EXIT_SUCCESS;
  57 +}