Makefile 3.34 KB
Newer Older
1
PYBIN := python3
2 3
VENVDIR := $(shell pwd)/.venv
VENVPY := ${VENVDIR}/bin/python
4

Nelso Jost's avatar
Nelso Jost committed
5 6 7
INODIR := .ino
BUILDWITH := ino
ARDUINOPATH :=#~/Downloads/arduino-1.6.5
8

Nelso Jost's avatar
Nelso Jost committed
9
.PHONY: help setup firmware serial run deploy undeploy
10

11 12 13
all: help

help:
14
	@ echo "USAGE: make <target>    where <target> can be:"
15
	@ echo ""
16 17 18
	@ echo " setup       Execute once to prepare the required Python virtual environment" 
	@ echo " firmware    Compile and upload the firmware to the Arduino board via serial"
	@ echo " serial      Starts a serial session with Python for board communication"
19
	@ echo ""
20 21 22
	@ echo " run         Execute the logger on the foreground. Hit Ctrl+C to stop it."
	@ echo " deploy      Install logger on the Supervisor daemon tool (exec background)"
	@ echo " undeploy    Undo the 'deploy' command"
23
	@ echo ""
24 25 26
	@ echo " tail-log    Follow updates on the last execution log"
	@ echo " tail-data   Follow updates on the last data log"
	@ echo " plot-data col=x   Uses Gnuplot to plot last data log col number x"
27

28 29 30
dep:
	sudo apt-get install python3 python3-pip python-pip supervisor python-virtualenv

31
apt-install:
32 33
	chmod +x scripts/apt-install.sh
	./scripts/apt-install.sh
34

35
ano-install:
36 37
	chmod +x scripts/ano-install.sh
	./scripts/ano-install.sh
38

39
ino-install:
40 41
	chmod +x scripts/ino-install.sh
	./scripts/ino-install.sh
42

Nelso Jost's avatar
Nelso Jost committed
43
setup: clean-venv create-venv
44
	
Nelso Jost's avatar
Nelso Jost committed
45
create-venv:
46
	@ echo "-------------------------------------------------------"
47 48 49
	virtualenv -v --python='${PYBIN}' ${VENVDIR} --no-site-packages
	${VENVDIR}/bin/pip install --upgrade pip
	${VENVDIR}/bin/pip install -r logger/requirements.pip
50
	@ echo "-------------------------------------------------------"
51 52
	@ echo "Required Python virtual environment installed at "
	@ du -sh ${VENVDIR}
53 54

clean-venv:
55
	rm -rf ${VENVDIR}
56

57 58 59 60 61 62 63 64
check-venv:
	@ command -v ${VENVPY} >/dev/null 2>&1 || \
		{ printf "You need to prepare the required Python virtual environment";\
		  printf "\nfor running this software. Excecute, just once:";\
		  printf "\n\n    $$ make setup\n\nor\n\n    ";\
	   	  printf "$$ make setup PYBIN=<python_binary>\n\nfor specifying a ";\
		  printf "Python binary other than 'python3', like\n'python-3.x' ";\
		  printf "(where x is a number) for instance. \n\n"; exit 1; }
65

Nelso Jost's avatar
Nelso Jost committed
66
firmware: ${BUILDWITH}-install
67
	chmod +x scripts/ino-build.sh
Nelso Jost's avatar
Nelso Jost committed
68
	./scripts/ino-build.sh ${BUILDWITH} ${INODIR} ${ARDUINOPATH}
69

70
serial: 
Nelso Jost's avatar
Nelso Jost committed
71
	${VENVPY} -i scripts/init_serial.py
72
 
73 74
run: check-venv
	${VENVPY} logger/run.py
75

76
deploy:
77
	sudo ${VENVPY} logger/deploy.py
78

79
undeploy:
80
	sudo ${VENVPY} logger/deploy.py -u
81

82
tail-log:
labfis's avatar
labfis committed
83
	$(eval TMP := $(shell ls -t -I "pid*|stdout*" logger/logs | head -n 1))
84 85 86 87 88 89
	@ echo "Last log file updated: logger/logs/$(TMP)"
	@ echo "File size: `du -h logger/logs/$(TMP) | cut -f1`"
	@ echo ""
	@ tail -F logger/logs/$(TMP)

tail-data:
90
	$(eval TMP := $(shell ls -t -I "outgoing.json" data/ | head -n 1))
91 92 93 94 95 96 97 98
	@ 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)

99 100 101 102
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

103
clean-data:
104
	rm -rfv data/*
105 106 107 108 109 110 111 112 113

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