Compare commits

...

5 Commits

Author SHA1 Message Date
tth f33a0189a5 go go go 2020-10-30 22:39:26 +01:00
tth 9c4595ef4c begining of the Loth project 2020-10-30 22:37:05 +01:00
tth 36f712dc98 asyncburp: boilerplate 2020-10-30 22:21:20 +01:00
tth 18b0fceff4 better error message 2020-10-27 09:42:14 +01:00
tth 11eca2fdc7 adding more bugs... 2020-10-20 10:00:55 +02:00
14 changed files with 685 additions and 8 deletions

2
.gitignore vendored
View File

@ -5,6 +5,7 @@ tarball
osc2cursor
osc-joy
text2osc
showbuttons
doc/*.toc
doc/*.log
@ -20,5 +21,6 @@ tools/udp-dumper
tools/*.o
specific/joy2laser
specific/asyncburp
specific/*.o

6
Loth/Makefile Normal file
View File

@ -0,0 +1,6 @@
# ----------------------------------------------------------
#
#

13
Loth/README.md Normal file
View File

@ -0,0 +1,13 @@
# Loth Hacks for fun and profit
## en shell
Voir `sender.sh`
## en C
## Et ensuite ?
Une petite bière ?

22
Loth/sender.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
R_IP="localhost"
R_PORT="2222"
DEVICE=42
oscpath=$(printf "/loth/truc/%d" $DEVICE)
oscsend $R_IP $R_PORT $oscpath s "==========="
for foo in $(seq 20 7 80)
do
echo " " $foo
message=$(printf "0x%02x" $foo)
oscsend $R_IP $R_PORT $oscpath s "$message"
sleep 1
done

2
MIDI/README.md Normal file
View File

@ -0,0 +1,2 @@
# Musical Instrument Digital Interface

View File

@ -1,4 +1,4 @@
# ----------------------------------------------------
# --------------------------------------------------------------
# umpf...
@ -7,7 +7,7 @@ DEPS = Makefile
all: osc-joy osc2cursor text2osc
# ----------------------------------------------------
# --------------------------------------------------------------
osc2cursor: osc2cursor.c ${DEPS} functions/libpocosc.a
gcc ${OPTS} $< functions/libpocosc.a -llo -lcurses -o $@
@ -18,4 +18,9 @@ osc-joy: osc-joy.c ${DEPS} functions/libpocosc.a
text2osc: text2osc.c ${DEPS} functions/libpocosc.a
gcc ${OPTS} $< functions/libpocosc.a -llo -o $@
# ----------------------------------------------------
# --------------------------------------------------------------
showbuttons: showbuttons.c functions/libpocosc.a ${DEPS}
gcc ${OPTS} $< functions/libpocosc.a -llo -lcurses -o $@
# --------------------------------------------------------------

View File

@ -41,6 +41,17 @@ Une appli ncurses trop choupie :)
Pour faire __beep__ vers Chuck...
# Le reste
## Loth Project
Voir README.md
## Teamlaser
Voir asyncburp.c

48
generators/testkontrol.pl Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/perl -w
my $port = 9001;
my $target = "localhost";
# ----------------------------------------------------------
use Net::OpenSoundControl::Client;
use Data::Dumper qw(Dumper);
use Getopt::Std;
my $client;
my $verbose = 0;
# ----------------------------------------------------------
#
# MAIN
#
getopts('d:v', \%options);
if (defined $options{"d"}) {
# print Dumper $options{"d"};
($target, $port) = split /:/, $options{"d"};
}
$verbose = 1 if (defined $options{"v"});
print "trashing ", $target, " on port ", $port, "\n";
$client = Net::OpenSoundControl::Client->new(
Name => "testkontrol",
Host => $target, Port => $port)
or die "Could not start client: $@\n";
print Dumper $client if $verbose;
my ($foo, $knum, $kval);
for ($foo=0; $foo<128; $foo++) {
$kval = int(128*rand());
$knum = int(128*rand());
print "$knum -> $kval\n" if $verbose;
$client->send(['/kontrol/v', 'i', $knum, 'i', $kval]);
sleep(1);
}
# ----------------------------------------------------------

334
showbuttons.c Normal file
View File

@ -0,0 +1,334 @@
/*
* SHOW BUTTONS
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <errno.h>
#include <getopt.h>
#include <lo/lo.h>
#include "functions/ncursefuncs.h"
/* ----------------------------------------------------------------- */
#define LOCAL_PORT "9002"
#define NB_BUTTONS 24
int verbosity;
typedef struct {
int type;
int value;
char texte[20];
} Event;
#define BUTTONS_EV 1
#define XY_EV 2
#define ID_EV 3
static int count;
static int pipefd[2];
#define EVNT_RD (pipefd[0])
#define EVNT_WR (pipefd[1])
unsigned char buttons[NB_BUTTONS];
short xy_values[2];
/* ----------------------------------------------------------------- */
#define LINE0 8 /* vertical position of the top line */
int draw_buttons(unsigned char *states, int nbre, int unused)
{
int idx, pos_c, pos_l;
char txt[20];
#if DEBUG_LEVEL
fprintf(stderr, "--> %s ( %p %d )\n", __func__, states, nbre);
#endif
for (idx=0; idx<nbre; idx++) {
pos_c = 5 + ((idx % 8) * 9);
pos_l = LINE0 + ((idx / 8) * 5);
sprintf(txt, "%03d", idx);
draw_a_button(stdscr, pos_l, pos_c, txt, states[idx]);
}
return 0;
}
/* ----------------------------------------------------------------- */
int display_a_value(int lig, short value, char letter)
{
char buffer[80], symbol;
int width, seuil, foo;
sprintf(buffer, "%6d [", value);
mvaddstr(lig, 4, buffer);
if (value < 0) symbol = '-';
else symbol = '+';
width = 60;
seuil = (abs((int)value) * width) / 32767;
#if DEBUG_LEVEL > 1
fprintf(stderr, "in %s : value=%6d, seuil=%d\n", __func__, value, seuil);
#endif
for (foo=0; foo<width; foo++) {
if (foo < seuil) mvaddch(lig, foo+12, symbol);
else mvaddch(lig, foo+12, ' ');
}
refresh();
#if DEBUG_LEVEL > 1
sprintf(buffer, "%s : %6d ", __func__, value);
blast_error_message(buffer, 0, 0);
#endif
return 0;
}
/* ----------------------------------------------------------------- */
int display_values(short *vals, int nbre, int ligne)
{
int foo;
char buffer[80];
for (foo=0; foo<nbre; foo ++) {
display_a_value(ligne + foo, vals[foo], '?');
}
return 0;
}
/* ----------------------------------------------------------------- */
int animation(int cycles, int speed)
{
int foo;
short values[2];
#if DEBUG_LEVEL
fprintf(stderr, "entering %s ( %d %d )\n", __func__, cycles, speed);
#endif
for (foo=0; foo<cycles; foo++) {
draw_buttons(buttons, NB_BUTTONS, 0);
display_values(values, 2, 2);
refresh();
usleep(speed*1000);
buttons[rand()%NB_BUTTONS] = rand() & 1;
values[0] += rand() % 320;
values[0] = abs(values[0]);
if (rand()%100 < 10)
values[1] = rand() % 32000;
}
/* may be we can make some cleanup after the show ? */
return 0;
}
/* ----------------------------------------------------------------- */
int do_animation(int cycles, int speed)
{
(void)initcurses();
animation(cycles, speed);
sleep(2);
exit(0);
return 0;
}
/* ----------------------------------------------------------------- */
void error(int num, const char *msg, const char *path)
{
fprintf(stderr, "liblo server error %d in path %s : %s\n", num, path, msg);
exit(1);
}
/* ----------------------------------------------------------------- */
int xy_handler(const char *path, const char *types, lo_arg ** argv,
int argc, void *data, void *user_data)
{
int x, y, foo;
Event evt;
#if DEBUG_LEVEL
fprintf(stderr, "%s : %s %s %d %p\n", __func__,
path, types, argc, user_data);
#endif
x = argv[0]->i; y = argv[1]->i;
/* may be we can bound-check that pair or values ? */
xy_values[0] = x; xy_values[1] = y;
evt.type = XY_EV; evt.value = 0x55;
foo = write(EVNT_WR, &evt, sizeof(Event));
if (sizeof(Event) != foo) {
fprintf(stderr, "%s : fifo error %d\n", __func__, errno);
exit(1);
}
count++;
return 0;
}
/* ----------------------------------------------------------------- */
int id_handler(const char *path, const char *types, lo_arg ** argv,
int argc, void *data, void *user_data)
{
Event evt;
int foo;
evt.type = ID_EV; evt.value = 0x55;
foo = write(EVNT_WR, &evt, sizeof(Event));
if (sizeof(Event) != foo) {
fprintf(stderr, "%s : fifo error %d\n", __func__, errno);
exit(1);
}
return 0;
}
/* ----------------------------------------------------------------- */
int button_handler(const char *path, const char *types, lo_arg ** argv,
int argc, void *data, void *user_data)
{
// char ligne[80];
int button, state, foo;
Event evt;
#if DEBUG_LEVEL
fprintf(stderr, "%s : %s %s %d %p\n", __func__,
path, types, argc, user_data);
#endif
button = argv[0]->i; state = argv[1]->i;
if (button<0 || button>=NB_BUTTONS) {
return 1;
}
((unsigned char *)user_data)[button] = state;
evt.type = BUTTONS_EV; evt.value = 0x55;
foo = write(EVNT_WR, &evt, sizeof(Event));
if (sizeof(Event) != foo) {
fprintf(stderr, "%s : fifo error %d\n", __func__, errno);
exit(1);
}
count++;
return 0;
}
/* ----------------------------------------------------------------- */
static void help(int k)
{
puts("\t * showbuttons " __DATE__ " *");
puts("\t-a\tshow animation");
puts("\t-p\tlocal udp port ("LOCAL_PORT")");
puts("\t-v\tenhance my verbosity");
exit(0);
}
/* ----------------------------------------------------------------- */
int main(int argc, char *argv[])
{
int foo;
lo_server_thread st;
char *local_port = LOCAL_PORT;
int opt;
char ligne[81];
long tdebut;
Event event;
/* parsing command line options */
while ((opt = getopt(argc, argv, "ahp:vE:C:")) != -1) {
switch (opt) {
case 'a': do_animation(200, 20); break;
case 'h': help(0); break;
case 'p': local_port = optarg; break;
case 'v': verbosity++; break;
default: exit(1);
}
}
tdebut = time(NULL);
count = 0;
/*
* setup the inter-thread event synthetizer
*/
foo = pipe(pipefd);
if (foo) {
perror("pipe for event synth");
exit(1);
}
/* set up the pretty screen user interface */
foo = initcurses();
sprintf(ligne, ":%s ", local_port);
foo = draw_main_screen(ligne, 0);
if (foo) {
endwin();
fprintf(stderr, "main screen : err %d\n", foo);
exit(1);
}
/* fireup the OSC liblo engine */
st = lo_server_thread_new(local_port, error);
#if DEBUG_LEVEL
fprintf(stderr, "Address of 'values' = %p\n", buttons);
#endif
lo_server_thread_add_method(st, "/joystick/b", "ii",
button_handler, buttons);
lo_server_thread_add_method(st, "/joystick/xy", "ii",
xy_handler, NULL);
lo_server_thread_start(st);
sprintf(ligne, "process %d on board, captain", getpid());
blast_error_message(ligne, 0, 0);
sleep(1);
for (;;) {
/* wait for un event from liblo threads */
foo = read(EVNT_RD, &event, sizeof(Event));
if (sizeof(Event) != foo) { /* FAILURE */
perror("event fifo read error");
exit(1);
}
#if DEBUG_LEVEL
fprintf(stderr, "event %5d %8d %s\n",
event.type, event.value, event.texte);
#endif
switch (event.type) {
case BUTTONS_EV:
draw_buttons(buttons, NB_BUTTONS, 0);
break;
case XY_EV:
display_values(xy_values, 2, 4);
break;
case ID_EV:
break;
default:
blast_error_message("bad event", 0, 0);
break;
}
}
if (verbosity)
{ fprintf(stderr, "elapsed %ld s.\n", time(NULL)-tdebut); }
return 0;
}
/* ----------------------------------------------------------------- */

View File

@ -2,8 +2,9 @@
OPTS = -Wall -g -DDEBUG_LEVEL=0
all: joy2laser asyncburp
all: joy2laser
# --------------------------------------------
laserblast.o: laserblast.c Makefile
gcc -c ${OPTS} $<
@ -11,4 +12,17 @@ laserblast.o: laserblast.c Makefile
joy2laser: joy2laser.c Makefile laserblast.o
gcc ${OPTS} $< laserblast.o ../functions/libpocosc.a -llo -o $@
# --------------------------------------------
asyncburp.o: asyncburp.c burpmsg.h Makefile
gcc -c ${OPTS} $<
burpmsg.o: burpmsg.c burpmsg.h Makefile
gcc -c ${OPTS} $<
asyncburp: asyncburp.o burpmsg.o
gcc ${OPTS} $< burpmsg.o -llo -o $@
# --------------------------------------------

96
specific/asyncburp.c Normal file
View File

@ -0,0 +1,96 @@
/*
* Joystick to Laser
* async version, with continuous refresh
* post Sonoptic 2020
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <lo/lo.h> /* OSC library */
#include "laserblast.h"
#include "burpmsg.h"
/* ------------------------------------------------------------------- */
#define LOCAL_PORT "9000"
#define REMOTE_HOST "localhost" /* just loling */
#define REMOTE_PORT "9999"
/* ------------------------------------------------------------------- */
int verbosity; /* global variable */
/* ------------------------------------------------------------------- */
static int bloub(void)
{
BurpMsg message;
message.magic = BURP_MAGIC;
display_burp_msg(&message, NULL);
return 0;
}
/* ------------------------------------------------------------------- */
static int help(int krkrkr)
{
puts("HELP ME !");
puts("\t-p NNN\t\tlocal listening port");
puts("\t-R a.b.c.d\tremote host");
puts("\t-P NNN\t\tremote port");
puts("\t-L N\t\tlaser number");
puts("\t-S N\t\tscene number");
puts("\t-v\t\tincrease verbosity");
return 1;
}
/* ------------------------------------------------------------------- */
int main(int argc, char *argv[])
{
char *local_port = LOCAL_PORT;
char *remote_host = REMOTE_HOST;
char *remote_port = REMOTE_PORT;
int lasernumber, scenenumber;
int opt;
fprintf(stderr, "%s compiled %s at %s\n",argv[0], __DATE__, __TIME__);
/* set some default values */
lasernumber = scenenumber = 0;
/* parsing command line options */
while ((opt = getopt(argc, argv, "hp:vL:S:R:P:")) != -1) {
switch (opt) {
case 'h': if (help(0)) exit(1); break;
case 'p': local_port = optarg; break;
case 'R': remote_host = optarg; break;
case 'P': remote_port = optarg; break;
case 'L': lasernumber = atoi(optarg); break;
case 'S': scenenumber = atoi(optarg); break;
case 'v': verbosity++; break;
}
}
if (verbosity) {
fprintf(stderr, "-------------: %s\n", argv[0]);
fprintf(stderr, "pid : %d\n", getpid());
fprintf(stderr, "local port : %s\n", local_port);
fprintf(stderr, "remote : %s %s\n", remote_host, remote_port);
fprintf(stderr, "scn/laser : %d %d\n", scenenumber, lasernumber);
}
bloub();
return 2;
}
/* ------------------------------------------------------------------- */

95
specific/burpmsg.c Normal file
View File

@ -0,0 +1,95 @@
/*
* BURPMSG.C
*/
#include <stdio.h>
#include <stdint.h>
#include <sys/select.h>
#include <unistd.h>
#include "burpmsg.h"
/* ------------------------------------------------------------------- */
int display_burp_msg(BurpMsg *header, void *data)
{
char *txt_type;
if (BURP_MAGIC != header->magic) {
fprintf(stderr, "burpmsg at %p : invalid magic %08X\n",
header, header->magic);
return -1;
}
txt_type = "wtf?"; /* nice default value */
switch(header->msgtype) {
case BURP_RESET:
txt_type = "reset";
break;
case BURP_SETSIZE:
txt_type = "setsize";
break;
case BURP_LASER:
txt_type = "laser";
break;
case BURP_SCENE:
txt_type = "scene";
break;
default:
fprintf(stderr, "burpmsg at %p : invalid msgtype %d\n",
header, header->msgtype);
return -1;
}
fprintf(stderr, "%4d %12s %9d %3d\n",
header->msgtype, txt_type, header->serial, header->szdata);
return 0;
}
/* ------------------------------------------------------------------- */
void la_grande_boucle( int fromfifo )
{
struct timeval tv;
fd_set fds;
int resval, foo;
BurpMsg message;
for(;;) { /* start of infinite loop */
FD_ZERO(&fds);
FD_SET(fromfifo, &fds);
tv.tv_sec = 1;
tv.tv_usec = 0;
resval = select(1, &fds, NULL, NULL, &tv);
if (-1 == resval) {
perror("select()");
/* ABORTING HERE ? */
continue;
}
if (resval) {
/* message available */
foo = read(fromfifo, &message, sizeof(BurpMsg));
if (sizeof(BurpMsg) != foo) {
fprintf(stderr, "err: %d read, %lu expected\n",
foo, sizeof(BurpMsg));
}
display_burp_msg(&message, NULL);
}
else {
/* got a time out */
fprintf(stderr, "TIMEOUT\n");
}
}
/* NOT REACHED */
}
/* ------------------------------------------------------------------- */

30
specific/burpmsg.h Normal file
View File

@ -0,0 +1,30 @@
/*
* BURPMSG.H
*/
/* ------------------------------------------------------------------- */
typedef struct {
uint32_t magic;
uint32_t serial;
uint16_t msgtype;
uint16_t szdata;
} BurpMsg;
#define BURP_MAGIC 0x98769876
/* message type */
#define BURP_RESET 1
#define BURP_SETSIZE 2
#define BURP_LASER 3
#define BURP_SCENE 4
#define BURP_COLOR 5
/* ------------------------------------------------------------------- */
int display_burp_msg(BurpMsg *header, void *data);
/* ------------------------------------------------------------------- */

View File

@ -24,6 +24,9 @@ static int x_scale, y_scale;
extern int verbosity;
/* ------------------------------------------------------------------- */
/*
* - prepare OSC transmission
*/
int blast_init(char *host, char *port, int scene, int laser)
{
#if DEBUG_LEVEL
@ -31,7 +34,6 @@ fprintf(stderr, ">>> %s ( '%s:%p' %d %d )\n", __func__, host, port,
scene, laser);
#endif
/* prepare OSC transmission */
lo_addr = lo_address_new(host, port);
if (verbosity) {
fprintf(stderr, "%s is sending to %s:%s\n", __FILE__, host, port);
@ -118,6 +120,3 @@ return 0;
/* ------------------------------------------------------------------- */
/* ------------------------------------------------------------------- */