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

5
BUILDDIR := .build
6

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

9 10 11
all: help

help:
12
	@ echo "USAGE: make <target>    where <target> can be:"
13
	@ echo ""
14 15 16
	@ 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"
17
	@ echo ""
18 19 20
	@ 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"
21
	@ echo ""
22 23
	@ echo " tail-log    Follow updates on the last execution log"
	@ echo " tail-data   Follow updates on the last data log"
24
	@ echo " plot col=x  Uses Gnuplot to plot last data log col number x"
25

26 27
install-debian-deps:
	sudo apt-get install -y python3 supervisor curl dialog
28 29

install-pip3:
30 31 32
	wget https://bootstrap.pypa.io/get-pip.py
	sudo python3 get-pip.py
	rm get-pip.py
33

34 35
install-python-deps: install-pip3
	sudo pip3 install -U virtualenv
36

37 38
install-platformio:
	sudo python -c "$$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)"
39

40
setup: install-debian-deps install-python-deps install-platformio venv
41
	
42
venv: clean-venv
43
	@ echo "-------------------------------------------------------"
44 45
	virtualenv -v --python='${PYBIN}' ${VENVDIR} --no-site-packages
	${VENVDIR}/bin/pip install -r logger/requirements.pip
46
	@ echo "-------------------------------------------------------"
47
	@ echo "Required Python virtual environment sucessfully installed at "
48
	@ du -sh ${VENVDIR}
49 50

clean-venv:
51
	rm -rf ${VENVDIR}
52

53 54 55 56 57 58 59 60
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; }
61

62
firmware:
63
	python3 scripts/run_platformio.py
64

65
serial: check-venv
66 67 68 69
	${VENVPY} scripts/init_serial.py --loop

pyserial: check-venv
	${VENVPY} -i scripts/init_serial.py
70 71 72

syncrtc:
	${VENVPY} scripts/init_serial.py --syncrtc
73 74 75

boardhash:
	${VENVPY} scripts/getboardhash.py
76
 
77 78
run: check-venv
	${VENVPY} logger/run.py
79

80 81 82 83
fakerun:
	${VENVPY} logger/run.py --fakedata

deploy: check-venv
84
	sudo ${VENVPY} logger/deploy.py
85

86
undeploy: check-venv
87
	sudo ${VENVPY} logger/deploy.py -u
88

89
tail-log:
labfis's avatar
labfis committed
90
	$(eval TMP := $(shell ls -t -I "pid*|stdout*" logger/logs | head -n 1))
91 92 93 94 95 96
	@ 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:
97
	$(eval TMP := $(shell ls -t -I "outgoing.json" data/ | head -n 1))
98 99 100 101 102 103 104 105
	@ 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)

106
plot:
107 108 109
	@ 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

110
clean-data:
111
	rm -rfv data/*
112 113 114 115 116 117 118

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

clean-ino:
	rm -rf ${INODIR}

119 120 121 122
clean: clean-data clean-logs clean-ino clean-venv
	find . -type f -name "*.py[co]" -delete
	find . -type d -name "__pycache__" -delete	
	rm -rf docs/_build