Skip to content

Commit

Permalink
Add Meteo Plot Profile through gnuplot.
Browse files Browse the repository at this point in the history
  • Loading branch information
flixr committed Jul 24, 2011
1 parent 8b3eb0e commit 035eb83
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -47,6 +47,7 @@
/conf/%gconf.xml
/conf/srtm_data/*
/conf/maps_data/*
/conf/gps/ublox_conf

# /doc/pprz_algebra/
/doc/pprz_algebra/headfile.log
Expand Down Expand Up @@ -99,6 +100,7 @@
/sw/logalizer/plotter
/sw/logalizer/gtk_export.ml
/sw/logalizer/sd2log
/sw/logalizer/plotprofile

# /sw/simulator/
/sw/simulator/gaia
Expand Down
5 changes: 4 additions & 1 deletion sw/logalizer/Makefile
Expand Up @@ -27,7 +27,7 @@ OCAMLC = ocamlc
OCAMLOPT = ocamlopt
INCLUDES= $(shell ocamlfind query -r -i-format xml-light) $(shell ocamlfind query -r -i-format lablgtk2) -I ../lib/ocaml

all: play plotter plot sd2log
all: play plotter plot sd2log plotprofile

play : log_file.cmo play_core.cmo play.cmo
@echo OL $@
Expand Down Expand Up @@ -105,6 +105,9 @@ MORE_CFLAGS = -DHAVE_DLFCN_H=1 -DSTDC_HEADERS=1 -I. -I. -I.. -g -O2 -I/usr/
disp3d: disp3d.c
$(CC) $(MORE_CFLAGS) -g -o $@ $^ $(MORE_FLAGS)

plotprofile: plotprofile.c
gcc -g -O2 -Wall `pkg-config glib-2.0 --cflags` -o $@ $^ `pkg-config glib-2.0 --libs` `pcre-config --libs` -lglibivy

test1: test1.c
$(CC) $(MORE_CFLAGS) -g -o $@ $^ $(MORE_FLAGS) -lglut

Expand Down
138 changes: 138 additions & 0 deletions sw/logalizer/plotprofile.c
@@ -0,0 +1,138 @@

/*
http://users.softlab.ntua.gr/~ttsiod/gnuplotStreaming.html
*/

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
#include <inttypes.h>
#include <sys/time.h>
#include <glib.h>
#include <Ivy/ivy.h>
#include <Ivy/ivyglibloop.h>

#define HEIGHT_SPAN 20000

FILE *Gplt, *Gplh;
int32_t alt = 0;
int32_t temp[HEIGHT_SPAN] = {0};
int32_t humid[HEIGHT_SPAN] = {0};

void on_GPS(IvyClientPtr app, void *user_data, int argc, char *argv[]){
/*
<message name="GPS" id="8">
<field name="mode" type="uint8" unit="byte_mask"/>
<field name="utm_east" type="int32" unit="cm" alt_unit="m"/>
<field name="utm_north" type="int32" unit="cm" alt_unit="m"/>
<field name="course" type="int16" unit="decideg" alt_unit="deg"/>
<field name="alt" type="int32" unit="cm" alt_unit="m"/>
<field name="speed" type="uint16" unit="cm/s" alt_unit="m/s"/>
<field name="climb" type="int16" unit="cm/s" alt_unit="m/s"/>
<field name="week" type="uint16" unit="weeks"></field>
<field name="itow" type="uint32" unit="ms"/>
<field name="utm_zone" type="uint8"/>
<field name="gps_nb_err" type="uint8"/>
</message>
7.73 11 GPS 0 55577549 665183336 0 -4310 0 0 1642 345957748 31 0
*/

int32_t _alt;

_alt = atoi(argv[5]);
alt = _alt / 100;
// if ((_alt/100) < HEIGHT_SPAN) alt = _alt;

// printf("alt %f\n", (float) _alt/100.);
}

void on_TMP_STATUS(IvyClientPtr app, void *user_data, int argc, char *argv[]){
/*
<message name="TMP_STATUS" id="86">
<field name="itemp" type="uint16"/>
<field name="temp" type="float" unit="deg_celsius" format="%.2f"/>
</message>
*/

float _temp;
int i;

_temp = atof(argv[2]);
if (alt < HEIGHT_SPAN) temp[alt] = _temp * 100;

// printf("temp %f\n", _temp);
fprintf(Gplt, "plot '-' w points pt 0 title \"Temp\"\n");
for (i = 0; i < HEIGHT_SPAN; i++){
if (temp[i] != 0) fprintf(Gplt, "%f %d\n", temp[i]/100., i);
}
fprintf(Gplt,"e\n");
}

void on_SHT_STATUS(IvyClientPtr app, void *user_data, int argc, char *argv[]){
/*
<message name="SHT_STATUS" id="89">
<field name="ihumid" type="uint16"/>
<field name="itemp" type="uint16"/>
<field name="humid" type="float" unit="rel_hum" format="%.2f"/>
<field name="temp" type="float" unit="deg_celsius" format="%.2f"/>
</message>
*/

float _humid;
int i;

_humid = atof(argv[3]);
if (alt < HEIGHT_SPAN) humid[alt] = _humid * 100;

// printf("humid %f\n", _humid);
fprintf(Gplh, "plot '-' w points pt 0 title \"Humid\"\n");
for (i = 0; i < HEIGHT_SPAN; i++){
if (humid[i] != 0) fprintf(Gplh, "%f %d\n", humid[i]/100., i);
}
fprintf(Gplh,"e\n");
}

int main( int argc, char* argv[] )
{
double xmint, xmaxt, xminh, xmaxh, ymin, ymax;
GMainLoop *ml;

ml = g_main_loop_new(NULL, FALSE);

IvyInit ("IvyPlotProfile", "IvyPlotProfile READY", NULL, NULL, NULL, NULL);
IvyBindMsg(on_GPS, NULL, "^(\\S*) GPS (\\S*) (\\S*) (\\S*) (\\S*) (\\S*) (\\S*) (\\S*) (\\S*) (\\S*) (\\S*) (\\S*)");
IvyBindMsg(on_TMP_STATUS, NULL, "^(\\S*) TMP_STATUS (\\S*) (\\S*)");
IvyBindMsg(on_SHT_STATUS, NULL, "^(\\S*) SHT_STATUS (\\S*) (\\S*) (\\S*) (\\S*)");
// IvyBindMsg(on_SHT_STATUS, NULL, "^(\\S*) DPICCO_STATUS (\\S*) (\\S*) (\\S*) (\\S*)");
IvyStart("127.255.255.255");

xmint = 5;
xmaxt = 35;
xminh = 0;
xmaxh = 100;
ymin = 500;
ymax = 2300;

Gplt = popen("gnuplot -geometry 300x300 -noraise","w");
setlinebuf(Gplt);
fprintf(Gplt, "set xrange[%f:%f]\n", xmint, xmaxt);
fprintf(Gplt, "set yrange[%f:%f]\n", ymin, ymax);

Gplh = popen("gnuplot -geometry 300x300 -noraise","w");
setlinebuf(Gplh);
fprintf(Gplh, "set xrange[%f:%f]\n", xminh, xmaxh);
fprintf(Gplh, "set yrange[%f:%f]\n", ymin, ymax);

g_main_loop_run(ml);

fclose(Gplt);
fclose(Gplh);
return 0;
}

0 comments on commit 035eb83

Please sign in to comment.