1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-30 13:41:50 +01:00

pydoorlock: autogenerate Protocol.py

Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
This commit is contained in:
Ralf Ramsauer 2019-06-14 20:50:37 +02:00
parent becb21bbbc
commit e27f6d02da
3 changed files with 41 additions and 1 deletions

1
.gitignore vendored
View File

@ -8,4 +8,5 @@ arch/*.xz
arch/BKCA.crt
gpio-wait
pydoorlock/Protocol.py
pydoorlock/__pycache__/

View File

@ -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

35
scripts/gen_protocol.sh Executable file
View File

@ -0,0 +1,35 @@
#!/bin/bash
#
# doorlock-avr, AVR code of Binary Kitchen's doorlock
#
# Copyright (c) Binary Kitchen, 2019
#
# Authors:
# Ralf Ramsauer <ralf@binary-kitchen.de>
#
# 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 <<END
# This file is autogenerated. If you need to change it, edit
# scripts/gen_protocol.sh instead.
from enum import Enum
class Protocol(Enum):
${AVR_COMM}
END