106 lines
2.3 KiB
C
106 lines
2.3 KiB
C
/*
|
|
* laserblsat over OSC
|
|
*
|
|
* Sonoptic 2020
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <lo/lo.h> /* OSC library */
|
|
|
|
/* ------------------------------------------------------------------- */
|
|
|
|
#define BUFF_SIZE 8000
|
|
|
|
static char big_buffer[BUFF_SIZE+2];
|
|
static int curpos;
|
|
static int la_scene, le_laser;
|
|
static lo_address lo_addr;
|
|
|
|
extern int verbosity;
|
|
|
|
/* ------------------------------------------------------------------- */
|
|
int blast_init(char *host, char *port, int scene, int laser)
|
|
{
|
|
|
|
/* prepare OSC transmission */
|
|
lo_addr = lo_address_new(host, port);
|
|
if (verbosity) {
|
|
fprintf(stderr, "%s is sending to %s:%s\n", __FILE__, host, port);
|
|
}
|
|
|
|
la_scene = scene, le_laser = laser;
|
|
|
|
/* manage our internals memories */
|
|
big_buffer[0] = '\0'; /* clear buffer */
|
|
curpos = 0; /* index in buffer */
|
|
|
|
return -1;
|
|
}
|
|
/* ------------------------------------------------------------------- */
|
|
int blast_rewind(void)
|
|
{
|
|
|
|
if (verbosity) fprintf(stderr, "Blast rewind\n");
|
|
|
|
big_buffer[0] = '\0'; /* clear buffer */
|
|
curpos = 0; /* index in buffer */
|
|
|
|
strcat(big_buffer, "["); curpos++;
|
|
|
|
return -1;
|
|
}
|
|
/* ------------------------------------------------------------------- */
|
|
int blast_addpoint(float x, float y, long col)
|
|
{
|
|
char buff[100];
|
|
int foo, sz;
|
|
|
|
sz = sprintf(buff, "(%.2f, %.2f, %ld),", x, y, col);
|
|
|
|
if (verbosity)
|
|
fprintf(stderr, "%s --> %s\n", __func__, buff);
|
|
|
|
/* check free space in bigbuffer */
|
|
if ( (curpos+sz) > BUFF_SIZE ) {
|
|
fprintf(stderr, "buffer overflow in %s\n", __func__);
|
|
exit(1);
|
|
}
|
|
|
|
strcat(big_buffer, buff); curpos += sz;
|
|
|
|
return -1;
|
|
}
|
|
/* ------------------------------------------------------------------- */
|
|
int blast_flush(void)
|
|
{
|
|
int foo;
|
|
char buffer[100];
|
|
|
|
/* we have to kill the last ',' in the big buff before send */
|
|
big_buffer[curpos-1] = ']'; big_buffer[curpos] = '\0';
|
|
|
|
if (verbosity)
|
|
fprintf(stderr, "BLAST %s\n", big_buffer);
|
|
|
|
sprintf(buffer, "/pl/%d/%d", la_scene, le_laser);
|
|
|
|
foo = lo_send(lo_addr, buffer, "s", big_buffer);
|
|
if (-1==foo) {
|
|
fprintf(stderr, "%s : error %d\n", __func__, foo);
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
/* ------------------------------------------------------------------- */
|
|
/* ------------------------------------------------------------------- */
|
|
/* ------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|