set terminal postscript eps color font "Helvetica" 16
set xlabel "Time"
set xdata time
set timefmt "%s"
#set datafile separator " "
#set boxwidth 0.15
set style fill pattern 1
set style data lines
set key top left Left #width -3

set output "plot-battery.eps"
set ylabel "Battery level"

plot [:] [0:] \
'data' using 1:($9/4096 * 1.5) title "Battery level"


set output "plot-energy.eps"
set ylabel "Energy (mJ)"

plot 'data' using 1:\
((0.0545 * $13 + 1.8 * $14 + 20.0 * $15 + 17.7 * $16 + 4.6 * $17) / 4096) \
title "Red LED" with filledcurves x1, \
'data' using 1:\
((0.0545 * $13 + 1.8 * $14 + 20.0 * $15 + 17.7 * $16) / 4096) \
title "Radio TX" with filledcurves x1, \
'data' using 1:\
((0.0545 * $13 + 1.8 * $14 + 20.0 * $15) / 4096) \
title "Radio listen" with filledcurves x1, \
'data' using 1:\
((0.0545 * $13 + 1.8 * $14) / 4096) \
title "CPU active" with filledcurves x1, \
'data' using 1:\
((0.0545 * $13) / 4096) \
title "CPU LPM" with filledcurves x1


set output "plot-temperature.eps"
set ylabel "Temperature (degrees Celcius)"

plot [:] [-10:30] \
'data' using 1:(-39.60 + 0.01*$7) title "Temperature"


set output "plot-humidity.eps"
set ylabel "Humidity"

plot [:] [0:100] \
'data' using 1:(-4 + 0.0405*$8 - 2.8e-6*($8*$8)) title "Humidity"


set output "plot-sensors.eps"
set ylabel "Sensed value"

plot [:] [-10:200] \
'data' using 1:(0.625 * 1000000 * 0.5 * $5/4096 / 100000 * 1000) title "Light 1", \
'data' using 1:(0.769 * 100000 * 2.5 * $6/4096 / 100000 * 1000) title "Light 2", \
'data' using 1:(-39.60 + 0.01*$7) title "Temperature", \
'data' using 1:(-4 + 0.0405*$8 - 2.8e-6*($8*$8)) title "Humidity"


set output "plot-light.eps"
set ylabel "Light"

plot [:] [0:] \
'data' using 1:(0.625 * 1000000 * 0.5 * $5/4096 / 100000 * 1000) title "Light 1", \
'data' using 1:(0.769 * 100000 * 2.5 * $6/4096 / 100000 * 1000) title "Light 2"


set output "plot-ll-errors.eps"
set ylabel "Errors per packet"

plot [:] [0:1] \
'data' using 1:($31 / $33) title "contentiondrop per tx", \
'data' using 1:($32 / $33) title "sendingdrop per tx", \
'data' using 1:($27 / $34) title "toolong per rx",\
'data' using 1:($28 / $34)title "tooshort per rx",\
'data' using 1:($29 / $34) title "badsynch per rx",\
'data' using 1:($30 / $34) title "badcrc per rx"

set output "plot-parent.eps"
set ylabel "Node ID"

plot [:] [0:100] \
'data' using 1:10 title "Best parent" with points

set output "plot-rtmetric.eps"
set ylabel "Routing metric"

plot [:] [0:] \
'data' using 1:(($11 + $12) / 16) title "Routing metric" with steps, \
'data' using 1:(($11) / 16) title "ETX to best neighbor" with steps, \
'data' using 1:(($12) / 16) title "Rtmetric for best neighbor" with steps, \
'lost' using 1:($2 * 0.5) title "Lost packet" with points

set output "plot-rtx-stats.eps"
set ylabel "Ratio"

plot \
'data' using 1:($20 / $18) title "reliabletx per tx",\
'data' using 1:($21 / $19) title "reliablerx per rx",\
'data' using 1:($22 / $20) title "rexmit per rtx",\
'data' using 1:($23 / $21) title "acktx per rrx",\
'data' using 1:($24 / $21) title "noacktx per rrx",\
'data' using 1:($25 / $20) title "timedout per rtx",\
'data' using 1:($26 / $20) title "badackrx per rtx"

set output "plot-seqno.eps"
set ylabel "Sequence number"

plot [:] [0:256] \
'data' using 1:3 title "Sequence number" with steps, \
'lost' using 1:($2 * 128) title "Lost" with points, \
'dup' using 1:($2 * 64) title "Duplicate" with points, \
'parent' using 1:2 title "Best parent" with points


set output "plot-hops.eps"
set ylabel "Hops"

plot [:] [-1:5] \
'data' using 1:4 title "Hops" with steps
