Commit 971a769d744581c9d055755966c3467d2f6c9d14

Authored by Arnaud Blanchard
0 parents

Initial basic applications

cmake_minimum_required(VERSION 2.6)
project(bapps)
#subdirs(i_read)
subdirs(i_oscillator)
#subdirs(i_keyboard)
subdirs(f_max)
... ...
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2016)
# Author: Arnaud Blanchard
cmake_minimum_required(VERSION 2.6)
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(${PROJECT_NAME})
find_package(blc_program)
find_package(blc_channel)
add_definitions(${BL_DEFINITIONS})
include_directories(${BL_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${BL_LIBRARIES})
\ No newline at end of file
... ...
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2016)
# Author: Arnaud Blanchard (November 2016)
# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
# 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".
# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
# 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.
# 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,
# 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.
# 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.
# 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.
cd `dirname $0`
echo
echo "Checking `basename $PWD`"
echo "===================="
echo
echo "No check for now"
echo
... ...
#We go in blaar dir
cd `dirname $0`/..
./run.sh i_keyboard --size=2 --type=FL32 --display | ./run.sh f_discretize | ./run.sh f_gnuplot --with=boxes
... ...
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h> //getpid
#include <sys/time.h>
static void discretize_floats(blc_array *output, blc_array const *input, int bins_nb, float max=1.0, float min=0.0){
int i, j, index;
FOR(j, input->total_length) {
index=(input->floats[j]-min)/(max-min)*bins_nb;
if (index>=bins_nb) index=bins_nb-1;
else if (index<0) index=0;
FOR(i, bins_nb){
output->floats[i+j*bins_nb] = (float)(i==index);
}
}
}
int main(int argc, char **argv){
blc_array array;
blc_channel input_channel, output_channel;
char const *output_channel_name, *input_channel_name, *period_str, *bins_nb_str, *display;
float min=0, max=1;
int64_t period;
int iteration, initialized=0, bins_nb;
blc_program_set_description("Discretize an analog signal in bins.");
blc_program_add_option(&display, 'D', "display", NULL, "display a text graph with result", NULL);
blc_program_add_option(&bins_nb_str, 'n', "bins_nb", "integer", "Number of bins where to distribute the discetize", "32");
blc_program_add_option(&period_str, 'p', "period", "integer", "sampling period in ms", "10");
blc_program_add_option(&output_channel_name, 'o', "output", "blc_channel", "name of the output channel", NULL);
blc_program_add_parameter(&input_channel_name, "blc_channel", 1, "Input channel", NULL);
blc_program_init(&argc, &argv, NULL);
if (output_channel_name==NULL) SYSTEM_ERROR_CHECK(asprintf((char**)&output_channel_name, "/%s%d", blc_program_name, getpid()), -1, NULL); //This will not be freed
input_channel.open(input_channel_name, BLC_CHANNEL_READ);
if(input_channel.type!='FL32') EXIT_ON_CHANNEL_ERROR(&input_channel, "Only type FL32 is managed");
period=strtod(period_str, NULL)*1000;
bins_nb=strtod(bins_nb_str, NULL);
if (input_channel.total_length==1) output_channel.create_or_open(output_channel_name, BLC_CHANNEL_WRITE, 'FL32', 'NDEF', 1, bins_nb);
else output_channel.create_or_open(output_channel_name, BLC_CHANNEL_WRITE, 'FL32', 'NDEF', 2, bins_nb, input_channel.total_length);
output_channel.publish();
iteration=0;
BLC_COMMAND_LOOP(period){
discretize_floats(&output_channel, &input_channel, bins_nb, max, min);
}
return EXIT_SUCCESS;
}
... ...
# Set the minimum version of cmake required to build this project
cmake_minimum_required(VERSION 2.6)
# Set the name of the project as the directory basename
project(f_max)
find_package(blc_channel)
find_package(blc_program)
add_definitions(${BL_DEFINITIONS})
include_directories(${BL_INCLUDE_DIRS})
add_executable(f_max f_max.cpp)
target_link_libraries(f_max ${BL_LIBRARIES})
... ...
//
// Created by Arnaud Blanchard on 22/12/15.
// Copyright ETIS 2015. All rights reserved.
//
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h>
#include <math.h>
#define DEFAULT_OUTPUT_NAME ":argmax<pid>"
static float find_float_max(float *floats, int floats_nb, float const *find_arg=NULL){
float max;
int i, imax;
max=floats[0];
imax=0;
for(i=1; i!=floats_nb; i++){
if(floats[i] > max){
max=floats[i];
imax=i;
}
}
if (find_arg) return (imax+0.5f)*(*find_arg);
else return max;
}
static void start_channel_float_loop(blc_channel const *input, blc_channel *output, float const *find_arg=NULL)
{
BLC_COMMAND_LOOP(0){
output->floats[0]=find_float_max(input->floats, input->total_length, find_arg);
}
}
static void start_print_float_loop(blc_channel const *input, float const* find_arg=NULL){
float imax;
BLC_COMMAND_LOOP(0){
imax=find_float_max(input->floats, input->total_length, find_arg);
printf("%f\n", imax);
if( blc_output_terminal) blc_eprint_cursor_up(1);
}
if( blc_output_terminal) blc_eprint_cursor_down(1);
}
int main(int argc, char **argv){
blc_channel input, output;
char const *output_name, *input_name, *find_arg_str;
float *find_arg_gain=NULL;
float arg_gain;
blc_program_set_description("Find the value of argument of the maximal value");
blc_program_add_option(&find_arg_str, 'a', "find_arg", "real", "Return argmax mutiplied by the real instead of max", NULL);
blc_program_add_option(&output_name, 'o', "output", "blc_channel-out", "channel name", DEFAULT_OUTPUT_NAME);
blc_program_add_parameter(&input_name, "blc_channel-in", 1, "channel you want to find max", NULL);
blc_program_init(&argc, &argv, NULL);
input.open(input_name, BLC_CHANNEL_READ);
blc_loop_try_add_waiting_semaphore(input.sem_new_data);
blc_loop_try_add_posting_semaphore(input.sem_ack_data);
if (find_arg_str){
SSCANF(1, find_arg_str, "%f", &arg_gain);
find_arg_gain=&arg_gain;
if(strcmp(output_name, DEFAULT_OUTPUT_NAME)==0) asprintf((char**)&output_name, ":imax%d", getpid());
}
else if(strcmp(output_name, DEFAULT_OUTPUT_NAME)==0) asprintf((char**)&output_name, ":max%d", getpid());
//The output is on terminal
if (strcmp(output_name, "-")==0){
switch (input.type){
case 'FL32':start_print_float_loop(&input, find_arg_gain);
break;
default:EXIT_ON_CHANNEL_ERROR(&input, "Type is not managed. Only 'FL32' is.");
break;
}
}
else
{
output.create_or_open(output_name, BLC_CHANNEL_WRITE, input.type, 'NDEF', 1, 1);
output.publish();
blc_loop_try_add_waiting_semaphore(output.sem_ack_data);
blc_loop_try_add_posting_semaphore(output.sem_new_data);
switch (input.type){
case 'FL32':start_channel_float_loop(&input, &output, find_arg_gain);
break;
default:EXIT_ON_CHANNEL_ERROR(&input, "Type is not managed. Only 'FL32' is.");
break;
}
}
return EXIT_SUCCESS;
}
... ...
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2016)
# Author: Arnaud Blanchard
cmake_minimum_required(VERSION 2.6)
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(${PROJECT_NAME})
find_package(blc_program)
find_package(blc_channel)
add_definitions(${BL_DEFINITIONS})
include_directories(${BL_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME} ${BL_LIBRARIES})
\ No newline at end of file
... ...
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2016)
# Author: Arnaud Blanchard (November 2016)
# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
# 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".
# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
# 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.
# 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,
# 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.
# 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.
# 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.
cd `dirname $0`
echo
echo "Checking `basename $PWD`"
echo "===================="
echo
echo "No check for now"
echo
... ...
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h> //getpid
#include <sys/time.h>
int main(int argc, char **argv){
blc_array array;
blc_channel input_channel, output_channel;
char const *output_channel_name, *input_channel_name, *delay_str, *period_str, *gain_str;
float gain;
int64_t period, delay;
int delay_iterations, iteration, i;
blc_program_set_description("Copy the input signla in the output modifying it (delay, gain, ...)");
blc_program_add_option(&delay_str, 'd', "delay", "integer", "delay applying to the input signal in ms", NULL);
blc_program_add_option(&gain_str, 'g', "gain", "float", "gain to which the signal will be multiply", NULL);
blc_program_add_option(&period_str, 'p', "period", "integer", "sampling period in ms", "10");
blc_program_add_option(&output_channel_name, 'o', "output", "blc_channel", "name of the output channel", NULL);
blc_program_add_parameter(&input_channel_name, "blc_channel", 1, "Input channel", NULL);
blc_program_init(&argc, &argv, NULL);
if (output_channel_name==NULL) SYSTEM_ERROR_CHECK(asprintf((char**)&output_channel_name, "/%s%d", blc_program_name, getpid()), -1, NULL); //This will not be free
input_channel.open(input_channel_name, BLC_CHANNEL_READ);
period=strtod(period_str, NULL)*1000;
if (delay_str){
delay=strtod(delay_str, NULL)*1000;
delay_iterations=delay/period;
if (delay<=period) EXIT_ON_ERROR("Delay (%dms) cannot be shorter than the sampling period (%dms)", delay/1000, period/1000);
//We create a table capable of saving all intermediate iterations
array.init('UIN8', 'NDEF', 2, input_channel.size, delay_iterations);
}
else delay=0;
if (gain_str) {
gain=strtof(gain_str, NULL);
}
else gain=1.0f;
output_channel.create_or_open(output_channel_name, BLC_CHANNEL_WRITE, input_channel.type, input_channel.format, input_channel.dims_nb, input_channel.dims);
output_channel.publish();
iteration=0;
BLC_COMMAND_LOOP(period){
if (delay){
if (gain_str){
switch (input_channel.type){
case 'UIN8':
FOR(i, input_channel.total_length){
array.uchars[array.dims[array.dims_nb-1].step*iteration+i]=CLIP_UCHAR(input_channel.uchars[i]*gain);
}
break;
case 'FL32':
FOR(i, input_channel.total_length){
array.floats[array.dims[array.dims_nb-1].step*iteration+i]=input_channel.floats[i]*gain;
}
break;
default:
EXIT_ON_ARRAY_ERROR(&input_channel, "You can only apply gain on type 'UIN8' or 'FL32'");
break;
}
}else memcpy(array.uchars+array.dims[array.dims_nb-1].step*iteration, input_channel.data, input_channel.size);
iteration++;
if (iteration==delay_iterations) iteration=0;
memcpy(output_channel.data, array.uchars+array.dims[array.dims_nb-1].step*iteration, output_channel.size);
}
else {
if (gain_str){
switch (input_channel.type){
case 'UIN8':
FOR(i, input_channel.total_length){
output_channel.uchars[i]=CLIP_UCHAR(input_channel.uchars[i]*gain);
}
break;
case 'FL32':
FOR(i, input_channel.total_length){
output_channel.floats[i]=input_channel.floats[i]*gain;
}
break;
default:
EXIT_ON_ARRAY_ERROR(&input_channel, "You can only apply gain on type 'UIN8' or 'FL32'");
break;
}
}
else memcpy(output_channel.data, input_channel.data, input_channel.size);
}
}
return EXIT_SUCCESS;
}
... ...
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS
# Author: Arnaud Blanchard (November 2016)
# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
# 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".
# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
# 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.
# 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,
# 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.
# 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.
# 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.
cmake_minimum_required(VERSION 2.6)
project(i_keyboard)
find_package(blc_channel REQUIRED)
find_package(blc_program REQUIRED)
add_definitions(${BL_DEFINITIONS})
include_directories(${BL_INCLUDE_DIRS})
add_executable(i_keyboard src/main.cpp)
target_link_libraries(i_keyboard ${BL_LIBRARIES})
... ...
Repos
0 0.3
1 0.1
4 0.2
5 0.5
8 0.2
Index
0 0.3
1 0.1
2 1.0
3 0.8
4 0.2
5 0.1
Poing
0 0.35
1 0.0
2 1.0
3 0.8
4 1.0
5 0.8
6 0.9
7 0.9
8 0.2
... ...
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2016)
# Author: Arnaud Blanchard (November 2016)
# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
# 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".
# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
# 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.
# 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,
# 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.
# 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.
# 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.
cd `dirname $0`
project=`basename $PWD`
log="/tmp/${project}_test.log"
echo
echo "Checking i_keyboard"
echo "==================="
echo "$project" > $log #We erase previous logs
echo "logs in $log"
../compile.sh . >> $log 2>&1 || { echo "ERROR: Fail compiling"; exit 1; }
echo "Compilation: ok";
echo
#Execution is hard to check as it needs to interact with the terminal
... ...
cd `dirname $0`/..
./run.sh i_keyboard --display
... ...
cd `dirname $0`/..
./run.sh i_keyboard --display | ./run.sh f_gnuplot
... ...
cd `dirname $0`/..
./run.sh i_keyboard --display --toggle | ./run.sh f_gnuplot --with=boxes
... ...
#include "blc_core.h"
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h>
#include <termios.h>
#include <libgen.h> //basename
enum{NORMAL_KEY=0, QUIT_KEY, NEUTRAL_KEY, INDEX_KEY, ARROW_CHANGE_INDEX, WRONG_KEY, DECREMENT_KEY, INCREMENT_KEY, FAST_DECREMENT_KEY, FAST_INCREMENT_KEY};
enum { LEFT_ARROW='D', RIGHT_ARROW='C', UP_ARROW='A', DOWN_ARROW='B'};
blc_channel channel;
blc_mem table;
char *key_list;
char const *display;
int keys_nb;
uchar min, max;
uchar quitting_key, neutral_key;
float neutral_value, max_value, min_value, float_step_size=0.004;
uchar uchar_step_size=1;
//quitting key return -1, neutral return -2;
static int update_index(int *index){
uchar answer[3];
ssize_t ret;
int index_tmp;
SYSTEM_ERROR_CHECK(ret=read(STDIN_FILENO, answer, 3), -1, "Waiting for keyboard input");
if (ret==1)
{
if (answer[0] >= min && answer[0] <= max && ((index_tmp=table.uchars[*answer-min]) != keys_nb)){
*index=index_tmp;
return INDEX_KEY;
}
else if (answer[0]==quitting_key) return QUIT_KEY;
else if (answer[0]==neutral_key) return NEUTRAL_KEY;
else fprintf(stderr, "\nThe key '%c' id '%d' is not possible. The possibilities are in '%s' or '%c' for quitting and '%c' for neutral value.\n", answer[0], answer[0], key_list, quitting_key, neutral_key);
} if (ret==2){
switch (answer[1]){
default:fprintf(stderr, "\nImpossible key of '%ld' bytes. Byte 0 '%c','%d', byte 1, '%c','%d'\n", ret, answer[0], answer[0], answer[1], answer[1]);
break;
}
}
else if (ret==3){
if ((answer[0]==27 && answer[1]=='[') || (answer[0]==239 && answer[1]==156)) {
switch (answer[2]){
case LEFT_ARROW: case 130: *index=MAX(0, *index-1);
return ARROW_CHANGE_INDEX;
break;
case RIGHT_ARROW: case 131: *index=MIN(keys_nb-1, *index+1);
return ARROW_CHANGE_INDEX;
break;
case UP_ARROW:case 128: return INCREMENT_KEY;
break;
case DOWN_ARROW:case 129: return DECREMENT_KEY;
break;
/* case PAGE_UP:case 172: return FAST_INCREMENT_KEY;
break;
case PAGE_DOWN:case 173: return FAST_DECREMENT_KEY;
break;*/
default: fprintf(stderr, "This key does not have effect\n");
break;
}
}
printf("Answer 0 '%c','%d', answer 1, '%c','%d', 2: '%c','%d'\n" , answer[0], answer[0] , answer[1], answer[1], answer[2], answer[2]);
}else fprintf(stderr, "\nImpossible key of '%ld' bytes. Byte 0 '%c','%d', byte 1, '%c','%d'\n", ret, answer[0], answer[0], answer[1], answer[1]);
return WRONG_KEY;
}
/**Return display size*/
static int display_uchar(int index){
char select_char;
int i;
channel.fprint_graph_uchars(stderr, channel.name, 6, 255, 0);
fprintf(stderr, ">");
FOR(i, keys_nb){
if (index==i) select_char='#';
else select_char=' ';
fprintf(stderr, "|%c%c", select_char, key_list[i]);
}
fprintf(stderr, "|\n");
return 7;
}
/**Return display size*/
static int display_float(int index){
char select_char;
int i;
channel.fprint_graph_floats(stderr, channel.name, 6, 1.0, 0);
fprintf(stderr, ">");
FOR(i, keys_nb){
if (index==i) select_char='#';
else select_char=' ';
fprintf(stderr, "|%c%c", select_char, key_list[i]);
}
fprintf(stderr, "|\n");
return 7;
}
static void loop_toggle_uchar(){
int ret=NORMAL_KEY, index=0, graph_height;
if (display) graph_height=display_uchar(index);
while (ret!=QUIT_KEY){
ret=update_index(&index);
switch (ret){
case INCREMENT_KEY:
channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(max_value);
break;
case DECREMENT_KEY: channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(min_value);
break;
case NEUTRAL_KEY:
channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(neutral_value);
break;
case INDEX_KEY:
if (channel.uchars[index] > BLC_NORMED_FLOAT_TO_UCHAR(neutral_value)) channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(min_value);
else channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(max_value);
case ARROW_CHANGE_INDEX:case QUIT_KEY:
break;
default:color_eprintf(BLC_YELLOW, "Unknownd ret '%d'", ret);
}
if (display){
graph_height=display_uchar(index);
blc_eprint_cursor_up(graph_height);
}
}
}
static void loop_uchar(){
int ret=NORMAL_KEY, index=0, graph_height;
if (display) graph_height=display_uchar(index);
while (ret!=QUIT_KEY){
if (display){
blc_eprint_cursor_up(graph_height);
graph_height=display_uchar(index);
}
ret=update_index(&index);
switch (ret){
case INCREMENT_KEY:
channel.uchars[index]=MIN(channel.uchars[index]+uchar_step_size, BLC_NORMED_FLOAT_TO_UCHAR(max_value));
break;
case DECREMENT_KEY: channel.uchars[index]=MAX(channel.uchars[index]-uchar_step_size, BLC_NORMED_FLOAT_TO_UCHAR(min_value));
break;
/* case FAST_INCREMENT_KEY:
channel.uchars[index]=MIN(channel.uchars[index]+10*uchar_step_size, UINT8_MAX);
previous_index=index;
break;
case FAST_DECREMENT_KEY:
channel.uchars[index]=MAX(channel.uchars[index]-10*uchar_step_size, 0);
break;*/
case NEUTRAL_KEY:
channel.uchars[index]=BLC_NORMED_FLOAT_TO_UCHAR(neutral_value);
break;
case INDEX_KEY:case QUIT_KEY:case ARROW_CHANGE_INDEX:
break;
default:EXIT_ON_ERROR("Unknownd ret '%d'", ret);
}
}
}
static void loop_toggle_float(){
int ret=NORMAL_KEY, index=0, graph_height;
if (display) graph_height=display_float(index);
while (ret!=QUIT_KEY){
if (display){
blc_eprint_cursor_up(graph_height);
graph_height=display_float(index);
}
ret=update_index(&index);
switch (ret){
case INCREMENT_KEY:
channel.floats[index]=max_value;
break;
case DECREMENT_KEY: channel.floats[index]=min_value;
break;
case NEUTRAL_KEY:
channel.floats[index]=neutral_value;
break;
case INDEX_KEY:
if (channel.floats[index] > neutral_value) channel.floats[index]=min_value;
else channel.floats[index]=max_value;
case ARROW_CHANGE_INDEX:case QUIT_KEY:
break;
default:color_eprintf(BLC_YELLOW, "Unknownd ret '%d'", ret);
}
}
}
static void loop_float(){
int ret=0, index=0, previous_index=0, graph_height;
if (display) graph_height=display_float(index);
while (ret!=QUIT_KEY){
if (display){
blc_eprint_cursor_up(graph_height);
graph_height=display_float(index);
}
ret=update_index(&index);
switch (ret){
case INCREMENT_KEY: channel.floats[index]=MIN(channel.floats[index]+float_step_size, max_value);
break;
case DECREMENT_KEY: channel.floats[index]=MAX(channel.floats[index]-float_step_size, min_value);
break;
/* case FAST_INCREMENT_KEY: channel.floats[index]+=float_step_size*10;
break;
case FAST_DECREMENT_KEY:channel.floats[index]-=float_step_size*10;
break;*/
case NEUTRAL_KEY:channel.floats[index]=neutral_value;
break;
case INDEX_KEY: case ARROW_CHANGE_INDEX:
previous_index=index;
case QUIT_KEY:break;
default:EXIT_ON_ERROR("Unknownd ret '%d'", ret);
}
}
}
int main(int argc, char** argv){
char *default_output=NULL;
char const *extension;
char const *channel_name, *type_str, *str_quitting_key, *str_neutral_key, *max_str, *min_str, *str_neutral_value, *toggle_mode, *step_size_str, *filename;
char const *key_nb_str;
int i;
char *pos;
uchar answer;
asprintf(&default_output, "/%s%d", basename(argv[0]), getpid()); //This will not be free but it is only allocate once
blc_program_set_description("Get keyboard inputs");
blc_program_add_option(&display, 'd', "display", NULL, "Display a text graph (UIN8 only)", NULL);
blc_program_add_option(&filename, 'f', "file", "filename", "Initialize the values with a tsv file", NULL);
blc_program_add_option((char const**)&key_list, 'k', "key_list", "string", "Define all the keys that can be stroke", "0123456789abcdef");
blc_program_add_option(&min_str, 'm', "min", "real", "Define the normed minimum value", "0.0");
blc_program_add_option(&str_neutral_key, 'n', "neutral_key", "string", "Define the neutral key", "escape");
blc_program_add_option(&channel_name, 'o', "output", "blc_channel", "Define where the result will be put", default_output);
blc_program_add_option(&str_quitting_key, 'q', "quitting_key", "string", "Define the key used to quit", "q");
blc_program_add_option(&key_nb_str, 's', "size", "integer", "Size of key vector", NULL);
blc_program_add_option(&type_str, 't', "type", "UIN8|FL32", "Define the type of the result", "UIN8");
blc_program_add_option(&max_str, 'M', "max", "real", "Define the normed max value", "1.0");
blc_program_add_option(&str_neutral_value, 'N', "neutral_value", "real", "Define the normed neutral value", "0.5");
blc_program_add_option(&step_size_str, 'S', "step", "real", "Set the normed step size", NULL);
blc_program_add_option(&toggle_mode, 'T', "toggle", NULL, "Set in toggle mode", NULL);
blc_program_init(&argc, &argv, blc_set_back_stdin_mode);
if (strlen(str_quitting_key)!=1) EXIT_ON_ERROR("You can only have one quitting key. You propose %s", str_quitting_key);
if (strcmp(str_neutral_key, "escape")==0) neutral_key=27; //Escape
else if (strlen(str_neutral_key)!=1) EXIT_ON_ERROR("You can only have one neutral key. You propose %s", str_neutral_key);
else neutral_key=str_neutral_key[0];
neutral_value=strtof(str_neutral_value, NULL);
max_value=strtof(max_str, NULL);
min_value=strtof(min_str, NULL);
quitting_key=str_quitting_key[0];
if (key_nb_str) {
keys_nb=strtod(key_nb_str, NULL);
key_list=MANY_ALLOCATIONS(keys_nb, char);
FOR(i, keys_nb){
if (i<10) key_list[i]=48+i;
else key_list[i]=97+i-10;
}
}
else keys_nb=strlen(key_list);
if (memchr(key_list, quitting_key, keys_nb)) EXIT_ON_ERROR("The quitting key '%c' is in your key list %*s, you need to select an other one with --quitting_key=...", quitting_key, keys_nb, quitting_key);
if (memchr(key_list, neutral_key, keys_nb)) EXIT_ON_ERROR("The neutral key '%c' is in your key list %*s, you need to select an other one with --neutral_key=...", quitting_key, keys_nb, neutral_key);
channel.create_or_open(channel_name, BLC_CHANNEL_WRITE, STRING_TO_UINT32(type_str), 'NDEF', 1, keys_nb);
if (filename){
extension = blc_get_filename_extension(filename);
if(strcmp(extension, "blc")==0) channel.update_with_blc_file(filename);
else if (strcmp(extension, "tsv")==0) channel.update_with_tsv_file(filename);
else EXIT_ON_ERROR("'%s' is not a possible file type extension", extension);
}
else {
switch (STRING_TO_UINT32(type_str)){
case 'UIN8':
FOR(i, keys_nb) channel.uchars[i]=BLC_NORMED_FLOAT_TO_UCHAR(neutral_value);
break;
case 'FL32':
FOR(i, keys_nb) channel.floats[i]=neutral_value;
break;
default:EXIT_ON_ARRAY_ERROR(&channel, "Type not mnaged");
break;
}
}
if (display){
if ((channel.type!='UIN8') && (channel.type!='FL32')) EXIT_ON_ARRAY_ERROR(&channel, "This type can not be displayed. Only 'UIN8' or 'FL32' can.");
}
blc_set_stdin_non_blocking_mode();
fprintf(stderr, "Waiting for one key in '%s'. Quitting with '%c'\n", key_list, quitting_key);
//We pre calculate the answers
max=min=key_list[0];
FOR(i, keys_nb) {
answer=key_list[i];
if (answer<min) min =answer;
else if (answer>max) max=answer;
}
table.allocate(max-min+1);
FOR(i, table.size){
pos=strchr(key_list, i+min);
if (pos) table.uchars[i]=pos-key_list;
else table.uchars[i]=keys_nb;
}
channel.publish();
switch (channel.type){
case 'UIN8':
if (step_size_str) uchar_step_size=strtod(step_size_str, NULL);
if (toggle_mode) loop_toggle_uchar();
else loop_uchar();
break;
case 'FL32':
if (step_size_str) float_step_size=strtof(step_size_str, NULL);
if (toggle_mode) loop_toggle_float();
else loop_float();
break;
default:
EXIT_ON_ARRAY_ERROR(&channel, "The type is not managed.");
break;
}
return EXIT_SUCCESS;
}
... ...
# Set the minimum version of cmake required to build this project
cmake_minimum_required(VERSION 2.6)
# Set the name of the project as the directory basename
project(i_oscillator)
find_package(blc_channel)
find_package(blc_program)
add_definitions(${BL_DEFINITIONS})
include_directories(${BL_INCLUDE_DIRS})
add_executable(i_oscillator i_oscillator.cpp)
target_link_libraries(i_oscillator ${BL_LIBRARIES})
... ...
//
// Created by Arnaud Blanchard on 22/12/15.
// Copyright ETIS 2015. All rights reserved.
//
#include "blc_core.h"
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h>
#include <math.h>
#define DEFAULT_OUTPUT_NAME ":oscillator<pid>"
int period;
float refresh_rate; //µs;
blc_channel output;
double step;
char const *display;
int display_height;
blc_mem graph_mem;
size_t i=0;
float gain=0;
int columns_nb=64;
int rows_nb=16;
static void info_cb(char const*, void*){
fprintf(stderr, "%d ", output.chars[0]);
}
static void period_cb(char const*argument, void*){
period=strtol(argument, NULL, 10);
step=(double)refresh_rate/(double)period;
}
static void refresh_cb(char const*argument, void*){
refresh_rate=strtol(argument, NULL, 10);
step=(double)refresh_rate/(double)period;
blc_command_loop_period=refresh_rate*1000;
}
static void start_float_loop(float frequency, float min, float max){
int i;
float time_gain, offset, gain;
time_gain=frequency*2*M_PI/(float)output.total_length*refresh_rate/1000;
if (output.sem_ack_data) refresh_rate=0;
gain=(max-min)/2.f; //amplitude sinus = 2
offset=min+gain; //min sinus*gain = -gain
BLC_COMMAND_LOOP(refresh_rate*1000){
FOR(i, output.total_length){
output.floats[i]=sin((blc_loop_iteration*output.total_length+i)*time_gain)*gain+offset;
}
if(display){
blc_fprint_float_graph(stderr, output.floats, output.total_length, "oscillation", columns_nb, rows_nb, 1, 0, "Time", "Intensity");
blc_eprint_cursor_up(rows_nb);
}
}
}
int main(int argc, char **argv){
char const *period_str, *refresh_rate_str, *display_str, *display_height_str, *channel_name, *buffer_length_str, *type_str, *frequency_str;
char const *min_str, *max_str;
float frequency, min, max;
int buffer_length;
uint32_t type;
blc_program_add_option(&channel_name, 'o', "channel", "blc_channel", "channel name", DEFAULT_OUTPUT_NAME);
blc_program_add_option(&display, 'd', "display", NULL, "display value at each iteration", NULL);
blc_program_add_option(&buffer_length_str, 's', "size", "integer", "buffer size (items nb)", "1");
blc_program_add_option(&frequency_str, 'f', "frequency", "float", "frequency in Hz", "1");
blc_program_add_option(&min_str, 'm', "min", "float", "minimum value of oscillation", "0");
blc_program_add_option(&max_str, 'M', "max", "float", "maximum value of oscillation", "1");
blc_program_add_option(&refresh_rate_str, 'r', "refresh", "integer", "refresh rate in ms", "10");
blc_program_add_option(&type_str, 't', "type", "FL32", "type of data", "FL32");
blc_program_init(&argc, &argv, NULL);
// period=strtol(period_str, NULL, 10);
SSCANF(1, refresh_rate_str, "%f", &refresh_rate);
step=(double)refresh_rate/(double)period;
type=STRING_TO_UINT32(type_str);
if (strcmp(DEFAULT_OUTPUT_NAME, channel_name)==0) asprintf((char**)&channel_name, ":oscillator%d",getpid());
SSCANF(1, buffer_length_str, "%d", &buffer_length);
SSCANF(1, frequency_str, "%f", &frequency);
SSCANF(1, min_str, "%f", &min);
SSCANF(1, max_str, "%f", &max);
output.create_or_open(channel_name, BLC_CHANNEL_WRITE, type, 'NDEF', 1, buffer_length);
output.publish();
/*
switch (output.type){
case 'INT8': gain=INT8_MAX;break;
case 'UIN8': gain=UINT8_MAX/2;break;
default:EXIT_ON_CHANNEL_ERROR(&output, "Type not managed");
}
gain *= amp;*/
blc_command_add("i", info_cb, NULL, "display value", NULL);
blc_command_add("p", period_cb, "period(ms)", "signal period", NULL);
blc_command_add("r", refresh_cb, "step(ms)", "time step", NULL);
blc_loop_try_add_waiting_semaphore(output.sem_ack_data);
blc_loop_try_add_posting_semaphore(output.sem_new_data);
start_float_loop(frequency, min, max);
if (display) blc_eprint_cursor_down(rows_nb);
return EXIT_SUCCESS;
}
... ...
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS
# Author: Arnaud Blanchard (November 2016)
# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
# 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".
# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
# 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.
# 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,
# 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.
# 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.
# 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.
cmake_minimum_required(VERSION 2.6)
#The name of the project is the basename of the directory
get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
project(${PROJECT_NAME})
find_package(blc_channel REQUIRED)
find_package(blc_program REQUIRED)
add_definitions(${BL_DEFINTIIONS})
include_directories(${BL_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} i_read.cpp)
target_link_libraries(${PROJECT_NAME} ${BL_LIBRARIES})
... ...
Load a tsv file and put it in a blc_channel.
It between can be done line by line --with=period value in ms separating the time two lines.
... ...
# Copyright ETIS — ENSEA, Université de Cergy-Pontoise, CNRS (2011 - 2016)
# Author: Arnaud Blanchard (November 2016)
# This software is governed by the CeCILL v2.1 license under French law and abiding by the rules of distribution of free software.
# 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".
# As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license,
# 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.
# 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,
# 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.
# 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.
# 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.
cd `dirname $0`
echo
echo "Checking `basename $PWD`"
echo "===================="
echo
echo "No check for now"
echo
... ...
#include "blc_core.h"
#include "blc_channel.h"
#include "blc_program.h"
#include <unistd.h>
#include <termios.h>
#include <libgen.h> //basename
int file_get_lines_number(FILE* file){
int ch, lines_nb;
lines_nb=0;
while(feof(file)==0){
ch = fgetc(file);
if (ch == '\n') lines_nb++;
else if ( ch == EOF ) if (feof(file)==0) EXIT_ON_SYSTEM_ERROR("Reading file");
}
return lines_nb;
}
void array_def_with_tsv_file_first_line(blc_array *array, char const *filename){
char const *ext;
FILE *file;
size_t linecap=0;
char *line;
int length;
char const *pos;
ext=blc_get_filename_extension(filename);
if (strcmp(ext, "tsv")!=0) EXIT_ON_ERROR("'%s' does not .tsv extension but '%s'", filename, ext);
SYSTEM_ERROR_CHECK(file=fopen(filename,"r"), NULL, "opening '%s'", filename);
SYSTEM_ERROR_CHECK(getline(&line, &linecap, file), -1, "Reading '%s'", filename);
pos=line;
length=0;
while(pos){
pos=strchr(pos+1, '\t');
if (pos) length++;
}
array->def_array('FL32', 'NDEF', 1, length);
fclose(file);
}
//We suppose they are float and only one dim
void array_def_with_tsv_file(blc_array *array, char const *filename){
char const *ext;
FILE *file;
size_t linecap=0;
char *line;
int length, lines_nb;
char const *pos;
ext=blc_get_filename_extension(filename);
if (strcmp(ext, "tsv")!=0) EXIT_ON_ERROR("'%s' does not .tsv extension but '%s'", filename, ext);
SYSTEM_ERROR_CHECK(file=fopen(filename,"r"), NULL, "opening '%s'", filename);
SYSTEM_ERROR_CHECK(getline(&line, &linecap, file), -1, "Reading '%s'", filename);
pos=line;
length=0;
while(pos){
pos=strchr(pos+1, '\t');
if (pos)length++;
}
lines_nb=file_get_lines_number(file)+1; //The first line was alreay read
array->def_array('FL32', 'NDEF', 2, length, lines_nb);
fclose(file);
}
int main(int argc, char** argv){
char const *period_str, *text;
char const *channel_name, *filename;
char *line=NULL;
size_t linecap=0;
ssize_t line_size;
blc_channel channel;
FILE *file;
int period;
blc_program_set_description("Read file of 2 dimensions");
blc_program_add_option(&period_str, 'p', "period", "integer", "Period in ms to read line by line", "0");
blc_program_add_option(&channel_name, 'o', "output_channel", "string", "Name of the channel to output the data", NULL);
blc_program_add_option(&text, 't', "text", NULL, "Export the result as text instead of blc_channel", NULL);
blc_program_add_parameter(&filename, "file name", 1, "file to load", NULL);
blc_program_init(&argc, &argv, NULL);
period=strtod(period_str, NULL);
if (text==NULL){
if (channel_name==NULL) if (channel_name==NULL) asprintf((char**)&channel_name, "/%s%d", basename(argv[0]), getpid()); //This will not be free but it is only allocate once
if (period == 0){
array_def_with_tsv_file(&channel, filename);
channel.create_or_open(channel_name, BLC_CHANNEL_WRITE);
channel.update_with_tsv_file(filename);
}
else{
array_def_with_tsv_file_first_line(&channel, filename);
channel.create_or_open(channel_name, BLC_CHANNEL_WRITE);
}
channel.publish();
}
else if (period==0) EXIT_ON_ERROR("You are in text mode and period is 0. Use the POSIX executable 'cat' for the same result");
if (period != 0) {
SYSTEM_ERROR_CHECK(file=fopen(filename, "r"), NULL, "Loading '%s'", filename);
BLC_COMMAND_LOOP(period*1000){
if (text){
line_size=getline(&line, &linecap, file);
if (line_size==-1) EXIT_ON_SYSTEM_ERROR("Reading '%s'", filename);
SYSTEM_SUCCESS_CHECK(write(STDOUT_FILENO, line, line_size), line_size, "Error writing on stdout");
}
else fscan_tsv_floats(file, channel.floats, channel.dims[0].length);
}
}
if (line) {
FREE(line);
linecap=0;
}
return EXIT_SUCCESS;
}
... ...