je vais tout casser ?
This commit is contained in:
36
core/Makefile
Normal file
36
core/Makefile
Normal file
@@ -0,0 +1,36 @@
|
||||
#
|
||||
# dd2 monitoring
|
||||
#
|
||||
# build the core functions, use with care
|
||||
#
|
||||
|
||||
|
||||
COPT = -Wall -fpic -g -DDEBUG_LEVEL=0
|
||||
OBJS = lut1024f.o parseconf.o utils.o sysmetrics.o
|
||||
DEPS = Makefile
|
||||
ALIB = libdd2m-core.a
|
||||
# ---------------------------------------------------
|
||||
|
||||
${ALIB}: ${OBJS}
|
||||
ar r $@ $?
|
||||
|
||||
lut1024f.o: lut1024f.c lut1024.h ${DEPS}
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
parseconf.o: parseconf.c config.h ${DEPS}
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
utils.o: utils.c utils.h ${DEPS}
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
sysmetrics.o: sysmetrics.c ${DEPS}
|
||||
gcc $(COPT) -c $<
|
||||
|
||||
# ---------------------------------------------------
|
||||
|
||||
t: t.c ${ALIB} lut1024.h config.h utils.h ${DEPS}
|
||||
gcc -Wall $< ${ALIB} -o $@
|
||||
|
||||
foo.lut1024f: mklut.pl Makefile
|
||||
./mklut.pl quux > $@
|
||||
|
||||
24
core/config.h
Normal file
24
core/config.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* config.h
|
||||
*/
|
||||
|
||||
#define SZ_STRINGS 200
|
||||
|
||||
typedef struct {
|
||||
|
||||
int valid;
|
||||
|
||||
char *input_device;
|
||||
int input_speed;
|
||||
|
||||
char *eyecandy_banner;
|
||||
|
||||
} Configuration;
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
int set_default_config(Configuration *cfg);
|
||||
int parse_config(char *fname, int flags);
|
||||
int show_config(char *title);
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
16
core/dd2-monitor.conf
Normal file
16
core/dd2-monitor.conf
Normal file
@@ -0,0 +1,16 @@
|
||||
#
|
||||
# experimental config file
|
||||
#
|
||||
|
||||
# --------------------------------------------------
|
||||
# serial input from the control cpu
|
||||
|
||||
input_device s /dev/ttyACM0
|
||||
input_speed i 9600
|
||||
|
||||
# --------------------------------------------------
|
||||
# some values for the eyecandy displays
|
||||
|
||||
eyecandy_banner s hacked by tTh
|
||||
|
||||
# --------------------------------------------------
|
||||
17
core/lut1024.h
Normal file
17
core/lut1024.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* LUT 1024 - DEALING WITH DISCRETE VALUES
|
||||
*/
|
||||
|
||||
|
||||
typedef struct {
|
||||
int flags;
|
||||
float vals[1024];
|
||||
} Lut1024f;
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
int slurp_lut1024f(FILE *fp, Lut1024f *where, int notused);
|
||||
int load_lut1024f(char *fname, Lut1024f *where, int notused);
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
70
core/lut1024f.c
Normal file
70
core/lut1024f.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* LUT 1024 -> FLOAT
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lut1024.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
int slurp_lut1024f(FILE *fp, Lut1024f *where, int notused)
|
||||
{
|
||||
int count, foo;
|
||||
|
||||
for(count=0; count<1024; count++) {
|
||||
foo = fscanf(fp, "%f", &where->vals[foo]);
|
||||
if (1 != foo) {
|
||||
fprintf(stderr, "%s: bad read %d\n", __func__, foo);
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
int load_lut1024f(char *fname, Lut1024f *where, int notused)
|
||||
{
|
||||
FILE *fplut;
|
||||
char firstline[100];
|
||||
char label[] = "LUT1024F";
|
||||
int foo;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintg(stderr, ">>> %s ( '%s' %p %d )\n", __func__,
|
||||
fname, where, notused);
|
||||
#endif
|
||||
|
||||
if (NULL==(fplut=fopen(fname, "r"))) {
|
||||
perror(fname);
|
||||
return -2;
|
||||
}
|
||||
|
||||
fprintf(stderr, "%s: getting first line\n", __func__);
|
||||
|
||||
if (NULL==fgets(firstline, 20, fplut)) {
|
||||
fprintf(stderr, "%s: nothing to read from %s\n",
|
||||
__func__, fname);
|
||||
return -3;
|
||||
}
|
||||
|
||||
foo = strncmp(label, firstline, sizeof(label)-1);
|
||||
if (foo) {
|
||||
fprintf(stderr, "%s: bad label [%s]\n", __func__, firstline);
|
||||
exit(5);
|
||||
}
|
||||
|
||||
foo = slurp_lut1024f(fplut, where, 0);
|
||||
|
||||
fclose(fplut);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
10
core/mklut.pl
Executable file
10
core/mklut.pl
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
my $foo;
|
||||
|
||||
print "LUT1024F\n";
|
||||
|
||||
for ($foo=0; $foo<1024; $foo++) {
|
||||
print rand()*3.30, "\n";
|
||||
}
|
||||
0;
|
||||
112
core/parseconf.c
Normal file
112
core/parseconf.c
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* core/parseconf.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
extern int verbosity;
|
||||
extern Configuration config;
|
||||
|
||||
#define CMP(a) (!strcmp(keyptr, a))
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
int parse_config(char *fname, int flags)
|
||||
{
|
||||
FILE *fp;
|
||||
char line[SZ_STRINGS+1],
|
||||
*keyptr, *typeptr, *cptr;
|
||||
int numligne;
|
||||
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, ">>> %s ( '%s' $%x )\n", fname, flags);
|
||||
#endif
|
||||
|
||||
config.valid = 49;
|
||||
|
||||
if (NULL==(fp=fopen(fname, "r"))) {
|
||||
perror(fname);
|
||||
return -2;
|
||||
}
|
||||
|
||||
numligne = 0;
|
||||
|
||||
while (fgets(line, SZ_STRINGS, fp))
|
||||
{
|
||||
numligne++;
|
||||
if ('\0'==line[0]) {
|
||||
fprintf(stderr, "%s : short read line %d\n",
|
||||
fname, numligne);
|
||||
fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* massage the end of line */
|
||||
line[strlen(line)-1] = '\0'; /* kill EOL */
|
||||
if (verbosity) {
|
||||
fprintf(stderr, "%3d :\t%s\n", numligne, line);
|
||||
}
|
||||
|
||||
/* seek for the first token in this line */
|
||||
if (NULL==(keyptr = strtok(line, " \t"))) {
|
||||
/* Got an empty line */
|
||||
continue;
|
||||
}
|
||||
/* skip comments */
|
||||
if ('#'==*keyptr) continue;
|
||||
/* seek for the type field */
|
||||
if (NULL==(typeptr = strtok(NULL, " \t"))) {
|
||||
/* we can(t get a type flag ? wtf ? */
|
||||
fprintf(stderr, "ERROR line %d : no type\n", numligne);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(verbosity)
|
||||
fprintf(stderr, "[%s] type %s\n", keyptr, typeptr);
|
||||
|
||||
if CMP("abort") {
|
||||
fprintf(stderr, "abort in config file\n");
|
||||
}
|
||||
|
||||
if (CMP("input_device")) {
|
||||
config.input_device = strdup(strtok(NULL, " \t"));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (CMP("input_speed")) {
|
||||
config.input_speed = atoi(strtok(NULL, " \t"));
|
||||
#if DEBUG_LEVEL
|
||||
fprintf(stderr, "input speed = %d\n", config.input_speed);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (CMP("eyecandy_banner")) {
|
||||
config.eyecandy_banner = strdup(strtok(NULL, " \t"));
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
int show_config(char *title)
|
||||
{
|
||||
|
||||
if (verbosity) {
|
||||
printf("********** %s **********\n", title);
|
||||
}
|
||||
|
||||
printf("valid : %d\n", config.valid);
|
||||
printf("input device : %s\n", config.input_device);
|
||||
printf("input speed : %d\n", config.input_speed);
|
||||
|
||||
puts("");
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
38
core/sysmetrics.c
Normal file
38
core/sysmetrics.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* core/sysmetrics.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "sysmetrics.h"
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------- */
|
||||
|
||||
int get_loadavg(float *where)
|
||||
{
|
||||
FILE *fp;
|
||||
float loads[3];
|
||||
int foo;
|
||||
|
||||
if ( ! (fp=fopen("/proc/loadavg", "r")) ) {
|
||||
perror("read loadavg");
|
||||
return -1;
|
||||
}
|
||||
|
||||
foo = fscanf(fp, "%f %f %f", loads, loads+1, loads+2);
|
||||
if (3 != foo) fprintf(stderr, "%s : read %d vals\n", __func__, foo);
|
||||
|
||||
memcpy(where, loads, 3 * sizeof(float));
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- */
|
||||
4
core/sysmetrics.h
Normal file
4
core/sysmetrics.h
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
|
||||
int get_loadavg(float *where);
|
||||
|
||||
73
core/t.c
Normal file
73
core/t.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* main de test des core functions
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "lut1024.h"
|
||||
#include "config.h"
|
||||
#include "sysmetrics.h"
|
||||
|
||||
int verbosity;
|
||||
|
||||
Configuration config;
|
||||
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
int essai_sysmetrics(int k)
|
||||
{
|
||||
float fvalues3[3];
|
||||
int foo;
|
||||
|
||||
foo = get_loadavg(fvalues3);
|
||||
if (foo) {
|
||||
fprintf(stderr, "err get load avg %d\n", foo);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("load avg %f %f %f\n", fvalues3[0], fvalues3[1], fvalues3[2]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int foo, opt;
|
||||
char *conffile = "dd2-monitor.conf";
|
||||
|
||||
fprintf(stderr, "+\n+ DD2 MONITOR\n+\n");
|
||||
|
||||
/* set some default values */
|
||||
verbosity = 0;
|
||||
|
||||
|
||||
while ((opt = getopt(argc, argv, "v")) != -1) {
|
||||
switch (opt) {
|
||||
case 'v': verbosity++; break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "%s : uh ?", argv[0]);
|
||||
exit(1);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
foo = parse_config(conffile, 0);
|
||||
fprintf(stderr, "parse_config(%s) -> %d\n\n", conffile, foo);
|
||||
show_config("foo");
|
||||
|
||||
essai_sysmetrics(0);
|
||||
/*
|
||||
foo = load_lut1024f("foo.lut1024f", NULL, 1);
|
||||
fprintf(stderr, "chargement de la lut --> %d\n\n", foo);
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
63
core/utils.c
Normal file
63
core/utils.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* core/utils.c
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
extern int verbosity;
|
||||
|
||||
/* --------------------------------------------------------------- */
|
||||
/* maybe not a really goof initialisation... */
|
||||
int seed_my_rand(int foo)
|
||||
{
|
||||
long v1, v2;
|
||||
|
||||
v1 = getpid(); v2 = time(NULL);
|
||||
return v1 ^ v2;
|
||||
}
|
||||
/* --------------------------------------------------------------- */
|
||||
int random1000(int type)
|
||||
{
|
||||
int value, foo;
|
||||
|
||||
#if DEBUG_LEVEL > 1
|
||||
fprintf(stderr, ">>> %s(%d)\n", __func__, type);
|
||||
#endif
|
||||
|
||||
switch (type) {
|
||||
case 0:
|
||||
value = rand() % 1000;
|
||||
break;
|
||||
case 1:
|
||||
value = (rand()%1000 + rand()%1000) / 2;
|
||||
break;
|
||||
case 4:
|
||||
value = 0;
|
||||
for (foo=0; foo<4; foo++)
|
||||
value += rand() % 1000;
|
||||
value /= 4;
|
||||
break;
|
||||
default:
|
||||
value = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
/* --------------------------------------------------------------- */
|
||||
double dtime(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
int foo;
|
||||
|
||||
foo = gettimeofday(&tv, NULL);
|
||||
if (foo) fprintf(stderr, "got %d in %s\n", foo, __func__);
|
||||
|
||||
return (double)tv.tv_sec + (double)tv.tv_usec / 1e6;
|
||||
}
|
||||
/* --------------------------------------------------------------- */
|
||||
8
core/utils.h
Normal file
8
core/utils.h
Normal file
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* core/utils.h
|
||||
*/
|
||||
|
||||
int seed_my_rand(int foo);
|
||||
int random1000(int type);
|
||||
|
||||
double dtime(void);
|
||||
7
core/wtf.txt
Normal file
7
core/wtf.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
|
||||
Il est temps de se reprendre en main
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user