Makefile 5.28 KB
Newer Older
1
2
PYVER := 3
VENV := .venv
3
INODIR := .ino
4

5
6
INO_OR_ANO := ino
ARDUINO_PATH := #-d ~/Downloads/arduino-1.6.5
7

8
9
10
all: help

help:
11
	@ echo "USAGE: make <command>"
12
	@ echo ""
13
	@ echo "COMMANDS:"
14
	@ echo ""
15
16
	@ echo "  install          --  Install required tools, build and upload firmware, and"
	@ echo "                       deploy logger daemon (background process)"
17
	@ echo ""
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
	@ echo "  uninstall        --  Remove daemon process (if present) and clean this folder"
	@ echo ""
	@ echo "  tail-log         --  Exibits and follow last modified execution log file"
	@ echo "  tail-data        --  Exibits and follow last modified datalog file"
	@ echo ""
	@ echo "  plot-data col=<C>  --  Uses Gnuplot to plot last modified datalog file"
	@ echo ""
	@ echo "  help             --  Shows the full help"

help-full:
	@ echo "USAGE: make <command>"
	@ echo ""
	@ echo "COMMANDS:"	
	@ echo ""	
	@ echo "  install          --  setup & bu & deploy-logger"
	@ echo "  uninstall        --  undeploy-logger & clean-venv & clean-ino"
	@ echo ""	
35
36
37
	@ echo "  apt-install      --  Uses Debian's apt to install required system tools"
	@ echo "  venv             --  Creates a Python local virtual environment at ${VENV}"
	@ echo "  setup            --  apt-install & venv"
38
	@ echo ""
39
	@ echo "  serial         --  Enter IPython session with serial opened"
40
	@ echo "  bu             --  build & upload firmware (with Arturo)"
41
	@ echo "  bus            --  build & upload & serial"
42
	@ echo ""
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
	@ echo "  sync-rtc       --  Synchronizes the board's clock with the system's"
	@ echo ""
	@ echo "  run-logger      --  Starts the logger. Keep log at logger/logs"
	@ echo "  deploy-logger   --  Activate logger daemon. Keep log at logger/logs/"
	@ echo "  undeploy-logger --  Deactivate logger daemon"
	@ echo ""
	@ echo "  tail-log       --  Exibits and follow last modified execution log file"
	@ echo "  tail-data      --  Exibits and follow last modified datalog file"
	@ echo ""
	@ echo "  plot-data col=<C>  --  Uses Gnuplot to plot last modified datalog file"
	@ echo "                         Replace <C> with the column number to plot as y axis"
	@ echo "  clean-venv     --  Remove Python's virtual environment directory"
	@ echo "  clean-ino      --  Remove Ino folder"
	@ echo "  clean-data     --  !!! CAUTION !!! Remove all datalog files"
	@ echo "  clean-logs     --  !!! CAUTION !!! Remove all execution log files"
	@ echo "  clean-all      --  Performs all the above cleans" 
59
60
	@ echo ""

61
62
63
64
install: setup bu deploy-logger

uninstall: undeploy-logger clean-venv clean-ino

65
apt-install:
66
	./tools/apt-install.sh
67

68
ano-install:
69
70
71
	chmod +x tools/arturo-install.sh
	./tools/arturo-install.sh

72
73
74
75
76
77
78
ino-install:
	@ echo "Finding pip2 binary.."
	@PIP2=`dpkg -L python-pip | grep /usr/bin/pip | tail -1`;\
		echo "Got it! PIP2=$$PIP2";\
		sudo $$PIP2 install -v ino

setup: apt-install venv ${INO_OR_ANO}-install
79
	
80
venv:
81
82
83
84
85
86
	@ echo "-------------------------------------------------------"
	virtualenv -v --python='python${PYVER}' ${VENV}
	@ echo "Virtualenv with 'python${PYVER}' interpreter was created at ${VENV}"
	@ echo "-------------------------------------------------------"
	${VENV}/bin/pip install --upgrade pip
	@ echo "-------------------------------------------------------"
Nelso Jost's avatar
Nelso Jost committed
87
	${VENV}/bin/pip install -r logger/requirements.pip
88
89
	@ echo "-------------------------------------------------------"
	@ echo "Virtualenv is ready at ${VENV}!"
90
	@ echo " "~/Downloads/arduino-1.0.1
91
92
93
94
95
96
97
	@ echo "TOTAL SIZE: "
	@ du -sh ${VENV}

clean-venv:
	rm -rf ${VENV}

serial:
98
	${VENV}/bin/ipython -i logger/init_serial.py
99

100
bu:
101
	rm -rf ${INODIR}
102
103
104
	mkdir -p ${INODIR}
	mkdir -p ${INODIR}/src/ ${INODIR}/lib/
	cp -rf meteorolog/. ${INODIR}/src/
105
	${INO_OR_ANO} list-models ${ARDUINO_PATH}
106
107
108
109
	@ echo "Getting board model from settings.yaml"
	$(eval MODEL := $(shell cd logger && ../${VENV}/bin/python -c "from app import Meteorologger; print(Meteorologger().CFG['ARDUINO']['BOARD_MODEL'])"))
	@ echo ""
	@ read -p "Type your board model (or hit ENTER to proceed with '${MODEL}'): " MODEL_CONF; \
110
	cd ${INODIR}/ && ${INO_OR_ANO} build ${ARDUINO_PATH} -m $${MODEL_CONF:-${MODEL}} && ${INO_OR_ANO} upload -m $${MODEL_CONF:-${MODEL}} ${ARDUINO_PATH}
111

112
bus: bu serial
113
114
115
116
117
118
119

sync-rtc:
	${VENV}/bin/python${PYVER} run.py --syncrtc
 
run-logger:
	${VENV}/bin/python logger/run.py

120
deploy-logger: undeploy-logger
121
122
123
124
125
126
	mkdir -p logger/logs
	sudo ${VENV}/bin/python${PYVER} logger/deploy.py

undeploy-logger:
	sudo ${VENV}/bin/python${PYVER} logger/deploy.py -u

Nelso Jost's avatar
Nelso Jost committed
127
tail-log:
labfis's avatar
labfis committed
128
	$(eval TMP := $(shell ls -t -I "pid*|stdout*" logger/logs | head -n 1))
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
	@ echo "Last log file updated: logger/logs/$(TMP)"
	@ echo "File size: `du -h logger/logs/$(TMP) | cut -f1`"
	@ echo ""
	@ tail -F logger/logs/$(TMP)

plot-data:
	@ echo "Quit by closing the window with Q and hitting Ctrl+C here to end the process"
	@ cd tools && gnuplot -persist -e "config='config.plt'; col=${col}" loop.plt

tail-data:
	$(eval TMP := $(shell ls -t -I outgoing* data/ | head -n 1))
	@ echo "Last datalog file updated: data/$(TMP)"
	@ echo "Number of lines/points: `cat data/$(TMP) | wc -l`"
	@ echo "File size: `du -h data/$(TMP) | cut -f1`"
	@ echo ""
	@ head -1 data/$(TMP)
	@ echo ""
	@ tail -F data/$(TMP)

clean-data:
	rm -rfv data/*.csv data/outgoing/*.json

clean-logs:
	rm -rfv logger/logs/*

clean-ino:
	rm -rf ${INODIR}

clean-all: clean-data clean-logs clean-ino clean-venv
	cd logger && sudo py3clean app