From e27f6d02dad6a53fd80806971c4296e408bf22a6 Mon Sep 17 00:00:00 2001 From: Ralf Ramsauer Date: Fri, 14 Jun 2019 20:50:37 +0200 Subject: [PATCH] pydoorlock: autogenerate Protocol.py Signed-off-by: Ralf Ramsauer --- .gitignore | 1 + Makefile | 6 +++++- scripts/gen_protocol.sh | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100755 scripts/gen_protocol.sh diff --git a/.gitignore b/.gitignore index 1ec7748..2c5a975 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ arch/*.xz arch/BKCA.crt gpio-wait +pydoorlock/Protocol.py pydoorlock/__pycache__/ diff --git a/Makefile b/Makefile index c150446..08f59e1 100644 --- a/Makefile +++ b/Makefile @@ -2,13 +2,16 @@ DESTDIR ?= / PREFIX ?= /usr SYSCONFDIR ?= /etc -all: gpio-wait +all: gpio-wait pydoorlock/Protocol.py package: sed -i -r -e "s@(^SYSCONFDIR = ').*('$$)@\1$(SYSCONFDIR)\2@" doorlockd sed -i -r -e "s@(^PREFIX = ').*('$$)@\1$(PREFIX)\2@" doorlockd sed -i -r -e "s@(^__version__ = ').*('$$)@\1$(shell cat VERSION)\2@" doorlockd +pydoorlock/Protocol.py: avr-code/protocol.h + ./scripts/gen_protocol.sh $^ > $@ + gpio-wait: gpio-wait.c install: @@ -29,3 +32,4 @@ install: clean: rm -f gpio-wait rm -rf pydoorlock/__pycache__ + rm -f pydoorlock/Protocol.py diff --git a/scripts/gen_protocol.sh b/scripts/gen_protocol.sh new file mode 100755 index 0000000..1466aac --- /dev/null +++ b/scripts/gen_protocol.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# doorlock-avr, AVR code of Binary Kitchen's doorlock +# +# Copyright (c) Binary Kitchen, 2019 +# +# Authors: +# Ralf Ramsauer +# +# This work is licensed under the terms of the GNU GPL, version 2. See +# the COPYING file in the top-level directory. + +PROTOCOL_H=$1 + +function find_defines() { + header=$1 + prefix=$2 + search="#define\s\+${prefix}\(\S*\)\s\+\(\S*\).*" + replace=" \1\t= b\2" + + grep $prefix $header | sed -e "s/$search/$replace/" +} + +AVR_COMM=$(find_defines $PROTOCOL_H AVR_) + +cat <