├── .gitignore ├── manifest-tool.sig ├── modulo-d-amp ├── lcd.c ├── Makefile ├── common.h ├── rc5.h ├── main.h ├── iic.h ├── max9744.c ├── tda7449.h ├── rc5.c ├── max9744.h ├── tda7449.c ├── iic.c ├── main.c └── lcd.h ├── ebus ├── .gitignore ├── hsd-time.h ├── proto-dbgmsg.h ├── hsd-date.c ├── hsd-misc.c ├── hsd-misc.h ├── Makefile ├── protocol.h ├── ebus.h ├── hardware.h ├── README ├── proto-busctl.h ├── onewire.c ├── hsd-time.c ├── doorbell.c ├── i2c.c ├── i2c-lcd.c ├── proto-h61.h ├── testnode.c ├── ebusdump.c └── hardware.c ├── data ├── ex2279-401.bfk ├── ex2279-620.bfk ├── ex2279-160.bfk ├── ex2279-617.bfk ├── ex2279-374.bfk ├── ex2279-402.bfk ├── ex2279-244.bfk ├── ex2279-580.bfk ├── ex2279-516.bfk └── ex2279-479.bfk ├── pp-donation ├── reverse-changeLog ├── check-ustid ├── cp-nnml2maildir ├── epoch2iso.c ├── mv-nnml2maildir ├── findperm.c ├── pp-donation.awk ├── xor.c ├── rot13.c ├── gpg4win-stats ├── ChangeLog ├── b64dec.c ├── encrypt-to-p.c ├── backup-audio ├── rfc822parse.h ├── log.pl ├── bfuck.c ├── mkdiff ├── zb32.c ├── 8bit-in-header.c ├── sks-stats.sh ├── gpgmlrobot ├── webbsh.c ├── hkpstats.c └── undump.c /.gitignore: -------------------------------------------------------------------------------- 1 | /addrutil 2 | -------------------------------------------------------------------------------- /manifest-tool.sig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/wk-misc/master/manifest-tool.sig -------------------------------------------------------------------------------- /modulo-d-amp/lcd.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/wk-misc/master/modulo-d-amp/lcd.c -------------------------------------------------------------------------------- /modulo-d-amp/Makefile: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/wk-misc/master/modulo-d-amp/Makefile -------------------------------------------------------------------------------- /modulo-d-amp/common.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/wk-misc/master/modulo-d-amp/common.h -------------------------------------------------------------------------------- /ebus/.gitignore: -------------------------------------------------------------------------------- 1 | revision.h 2 | housed 3 | housectl 4 | *.hex 5 | *.elf 6 | *.o 7 | 8 | ebusdump 9 | -------------------------------------------------------------------------------- /data/ex2279-401.bfk: -------------------------------------------------------------------------------- 1 | >++++++++++ 2 | [>+++++++++>++++++++> 3 | +++++++><<<<-] 4 | >--->++++>> 5 | <<<< 6 | >.>.>. 7 | -------------------------------------------------------------------------------- /data/ex2279-620.bfk: -------------------------------------------------------------------------------- 1 | ++++++++++[>+>+++>+++++++>++++++++++ 2 | <<<<-]>>>>++.+++++++++++++++.------------------ 3 | .++++++++.<++.>--.++++. 4 | -------------------------------------------------------------------------------- /data/ex2279-160.bfk: -------------------------------------------------------------------------------- 1 | >++++++++++ 2 | [>++++++++++>++++++++++++>+++++++++++> 3 | +++++++++++> ++++++++++++><<<<<<-] 4 | >++>--->>>+> 5 | <<<<<< 6 | >.>.>.>.>. 7 | -------------------------------------------------------------------------------- /data/ex2279-617.bfk: -------------------------------------------------------------------------------- 1 | ++++++++++[>+>+++>+++++++>++++++++++<<<<- 2 | ]>>>>+++++++++++++++++++.------------------.------- 3 | -------.++++++++++++++++++.+++..<--.>---.----. -------------------------------------------------------------------------------- /data/ex2279-374.bfk: -------------------------------------------------------------------------------- 1 | ++++++++++[>+>+++>+++++++>++++++++++ 2 | <<<<-]>>>>+++++++++++++++.----------- 3 | .+.+++++++++++. 4 | <++.>-------------------.+++++++++++++++..--------- 5 | --.+++++++++.+++++. 6 | -------------------------------------------------------------------------------- /data/ex2279-402.bfk: -------------------------------------------------------------------------------- 1 | ++++++++++[>+>+++>+++++++>++++++++++ 2 | <<<<-]>>>>++++++++++++++++++. 3 | -----------------.+++++++++++++.+++++++. 4 | <++++++++++++++++.+++++++++++++++. 5 | >-------.+++++++. 6 | <-------------------------------. 7 | >----.-------..+++++++++++. 8 | -------------------------------------------------------------------------------- /data/ex2279-244.bfk: -------------------------------------------------------------------------------- 1 | ++++++++++[>+>+++>+++++++>++++++++++ 2 | <<<<-]>>>>+++++++++++++++. 3 | ------------------. 4 | +++++++++++++++++++++. 5 | -----------------. 6 | <++++++++++++++.>+++.---. 7 | <-----------------.>+++.+.+++. 8 | --------.++++++++++++++. 9 | -------------.+++++++++. 10 | -------------------------------------------------------------------------------- /data/ex2279-580.bfk: -------------------------------------------------------------------------------- 1 | ++++++++++[>+>+++>+++++++>++++++++++ 2 | <<<<-]>>>>+++++++++++++++++++.------------------. 3 | <+++++++.>----.++++++++++.------.<+++++++.>+++.---. 4 | <+++.>++++++++++.+++.------.--------.<------------- 5 | ---.>++++++++++++++.-------------.----. 6 | +++++++++++++++++++.<------.>-------------.------ 7 | .++++++++.+++++. 8 | -------------------------------------------------------------------------------- /data/ex2279-516.bfk: -------------------------------------------------------------------------------- 1 | ++++++++++[>+>+++>+++++++>++++++++++<<<<- 2 | ]>>>>++++++++.-------.+++++++++++++++.< 3 | +++++++++++++++.>-.<------------------.>-- 4 | 5 | ---------.-------.+++++++++++++.-------.-- 6 | .<+++++++++++++++++.>+++.---.<-------------- 7 | -.>+++++++.-------.--.+++++++++++++++++.--- 8 | --------.++++++.-.<+++++++++++++.>--------- 9 | .++++++++++++++.++.---------.++++++++. 10 | -------------------------------------------------------------------------------- /pp-donation: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Extract donation details from a Paypal notification mail 3 | # 4 | # Due to the problem of passing more than one argument in a shebang 5 | # script, we use this wrapper script to call gawk. gawk is required 6 | # for gensub. 7 | 8 | script=$0.awk 9 | 10 | # We better resort to the C locale to avoid a bug in the -b option 11 | LC_ALL=C 12 | export LC_ALL 13 | 14 | exec gawk -b -f "$script" "$@" 15 | -------------------------------------------------------------------------------- /data/ex2279-479.bfk: -------------------------------------------------------------------------------- 1 | ++++++++++[>+>+++>+++++++>++++++++++ 2 | <<<<-]>>>>++++++++. 3 | -------.+++++++++++++++.<+++++++++++++++.>-. 4 | <--.++++++++++++++.>+++.<++++. 5 | -----------------.>--------------.---. 6 | <+++.>++++++++++.+++.------.--------. 7 | <<++++++++++++++++.>>+++++++++++++.++++. 8 | ------------.----. 9 | +++++++++++++++.<<.>> 10 | -----.-.---------.<--------------. 11 | >++++++++++++++. 12 | <+++.>----------.++++++++++.+. 13 | ---------------.+++++++++.-----.+++++. 14 | -------.<++++++++.>++++++++.<+.>++++. 15 | -------------------------------------------------------------------------------- /reverse-changeLog: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # -*- sh -*- 3 | # Sometimes we find changelogs in chronological order and not 4 | # in the desired reverse chronological order. This script fixes that. 5 | # 6 | # Usage: 7 | # reverse-changelog ChangedLog.fixed 8 | 9 | awk ' 10 | /^[MTWTFS12][a-z0-9]+/ { flush(); i = 0 } 11 | { i++; arr[i] = $0 } 12 | END { flush() } 13 | 14 | 15 | function flush () 16 | { 17 | for (; i > 0; i--) 18 | print arr[i]; 19 | } 20 | ' | tac 21 | -------------------------------------------------------------------------------- /check-ustid: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ourid="DE215605608" 4 | otherid="$1" 5 | # Altes Verfahren 6 | #host="wddx.bff-online.de" 7 | # 8 | #url="/ustid.php?eigene_id=${ourid}&abfrage_id=$otherid" 9 | # 10 | #printf "GET $url HTTP/1.0\r\nHost: $host\r\n\r\n" | nc $host 80 \ 11 | # | sed 's//dev/null| awk -F'>' ' 22 | /ErrorCode/ { print $3 } 24 | found = 0 25 | ' 26 | -------------------------------------------------------------------------------- /cp-nnml2maildir: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | dir="$1" 4 | newdir="$2" 5 | 6 | [ -z $newdir ] && exit 1 7 | 8 | if [ ! -d "$newdir" ]; then 9 | mkdir "$newdir" 10 | chmod g-rx,o-rx "$newdir" 11 | mkdir "$newdir"/tmp "$newdir"/cur "$newdir"/new 12 | chmod g-rx,o-rx "$newdir"/tmp "$newdir"/cur "$newdir"/new 13 | fi 14 | 15 | 16 | ls "$dir" | while read tmp dummy; do 17 | digits=$(echo "$tmp" | sed 's/[^0-9]//g') 18 | oldname="$dir/$tmp" 19 | newname=${newdir}/cur/$(stat -c %Y.${digits}i%i.vigenere:2,S "$oldname") 20 | echo mv "$oldname" '->' "$newname" >&2 21 | mv "$oldname" "$newname" 22 | done 23 | echo mv "$dir/.marks" $newdir/gnus-marks >&2 24 | mv "$dir/.marks" $newdir/gnus-marks 25 | -------------------------------------------------------------------------------- /epoch2iso.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define PGM "epoch2iso" 6 | 7 | 8 | int 9 | main (int argc, char **argv) 10 | { 11 | long value; 12 | struct tm *tp; 13 | time_t atime; 14 | 15 | if (argc != 2) 16 | { 17 | fprintf (stderr, "usage: " PGM " seconds_since_Epoch\n"); 18 | return 1; 19 | } 20 | 21 | value = strtol (argv[1], NULL, 0); 22 | if (value < 0) 23 | { 24 | fprintf (stderr, PGM ": invalid time given\n"); 25 | return 1; 26 | } 27 | 28 | atime = value; 29 | tp = gmtime (&atime); 30 | 31 | printf("%04d-%02d-%02d %02d:%02d:%02d\n", 32 | 1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday, 33 | tp->tm_hour, tp->tm_min, tp->tm_sec); 34 | return 0; 35 | } 36 | 37 | /* 38 | Local Variables: 39 | compile-command: "cc -Wall -o epoch2iso epoch2iso.c" 40 | End: 41 | */ 42 | -------------------------------------------------------------------------------- /mv-nnml2maildir: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | dir="$1" 6 | newdir="$2" 7 | hostname=$(hostname) 8 | 9 | if ! $HOME/w/misc-scripts/readgnusmarks --version >/dev/null 2>&1; then 10 | echo "the readgnusmarks tool is missing" >&2 11 | exit 2 12 | fi 13 | 14 | [ -z $newdir ] && exit 1 15 | 16 | if [ ! -d "$newdir" ]; then 17 | mkdir "$newdir" 18 | chmod 2700 "$newdir" 19 | mkdir "$newdir"/tmp "$newdir"/cur "$newdir"/new 20 | chmod 2700 "$newdir"/tmp "$newdir"/cur "$newdir"/new 21 | fi 22 | 23 | newdir=$(cd "$newdir" && pwd) 24 | 25 | cd $dir 26 | if [ ! -f .marks ]; then 27 | echo ".marks file missing" >&2 28 | exit 1 29 | fi 30 | 31 | script=$(tempfile) 32 | 33 | ls | $HOME/w/misc-scripts/readgnusmarks --verbose .marks "$newdir" >$script 34 | 35 | echo "moving $(cat $script | wc -l) files to $newdir" >&2 36 | sh $script 37 | rm $script 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /ebus/hsd-time.h: -------------------------------------------------------------------------------- 1 | /* hsd-time.c - Time functions for housed and housectl 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | #ifndef HSD_TIME_H 19 | #define HSD_TIME_H 20 | 21 | 22 | #define INVALID_TIME ((uint16_t)(-1)) 23 | 24 | uint16_t timestr_to_ebustime (const char *string, char **endp); 25 | char * ebustime_to_timestr (uint16_t ebustime); 26 | 27 | 28 | #endif /*HSD_TIME_H*/ 29 | -------------------------------------------------------------------------------- /modulo-d-amp/rc5.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | Copyright: (c) 2009 Stange-Distribution Simone Stange, Berlin 3 | Contact: info@obd-shop.com 4 | License: GNU GPL v2 (see License.txt) 5 | Author: Frank Nitzsche classd@beta-x.de 6 | File: rc5.h 7 | Version: 16.02.09 8 | Compiler: AVR-GCC 9 | **************************************************************************/ 10 | 11 | #ifndef RC5_H 12 | #define RC5_H 13 | 14 | #include "common.h" 15 | 16 | /* RC5: 17 | 18 | 14 Bit word: 19 | 20 | | 1 | -C6 | T | A4 | A3 | A2 | A1 | A0 | C5 | C4 | C3 | C2 | C1 | C0 | 21 | | | | \------------------/ \-----------------------/ 22 | | | | Address Command 23 | | | Toggle 24 | | inverted Commandbit 25 | Startbit 26 | 27 | Bit duration = 1.778ms 28 | Word duration = 24.889ms 29 | Word repetition (pressed key) = 113.778ms 30 | 31 | */ 32 | typedef struct{ 33 | U8 Adr; 34 | U8 Cmd; 35 | U8 Tgl; 36 | }RC5_t; 37 | 38 | BOOL getRc5(RC5_t*); 39 | void initRc5(void); 40 | 41 | #endif//RC5_H 42 | -------------------------------------------------------------------------------- /ebus/proto-dbgmsg.h: -------------------------------------------------------------------------------- 1 | /* proto-dbgmsg.h - Definition of the debug message protocol. 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | #ifndef PROTO_DBGMSG_H 19 | #define PROTO_DBGMSG_H 20 | 21 | /* Description of the Debug Message protocol. 22 | 23 | This protocol is used to send debug strings to the bus. 24 | 25 | byte 0 - protocol PROTOCOL_EBUS_DBGMSG 26 | byte 1 - sender node-id high 27 | byte 2 - sender node-id low 28 | byte 3...15 - string 29 | 30 | */ 31 | 32 | #include "protocol.h" 33 | 34 | 35 | #endif /*PROTO_DBGMSG_H*/ 36 | -------------------------------------------------------------------------------- /findperm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | void * 7 | xmalloc (size_t n) 8 | { 9 | void *p = malloc (n); 10 | if (!p) 11 | abort(); 12 | return p; 13 | } 14 | 15 | char * 16 | strlwr (char *s) 17 | { 18 | char *p; 19 | for(p=s; *p; p++ ) 20 | *p = tolower(*(unsigned char *)p); 21 | return s; 22 | } 23 | 24 | 25 | int 26 | main (int argc, char**argv) 27 | { 28 | const unsigned char *s; 29 | char line [1024]; 30 | char *target; 31 | char *flags1, *flags2; 32 | size_t targetlen; 33 | 34 | if (argc != 2) 35 | return 1; 36 | 37 | targetlen = strlen (argv[1]); 38 | target = xmalloc (targetlen+1); 39 | strcpy (target, argv[1]); 40 | strlwr (target); 41 | flags1 = xmalloc (256); 42 | flags2 = xmalloc (256); 43 | memset (flags1, 0, 256); 44 | for (s=target; *s; s++) 45 | flags1[*s]++; 46 | 47 | while ( fgets (line, sizeof line , stdin) ) 48 | { 49 | if (!*line || strlen (line) != targetlen + 1) 50 | continue; 51 | line [targetlen] = 0; 52 | strlwr (line); 53 | memset (flags2, 0, 256); 54 | for (s=line; *s; s++) 55 | flags2[*s]++; 56 | if (!memcmp (flags1, flags2, 256)) 57 | printf ("%s\n", line); 58 | 59 | } 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /modulo-d-amp/main.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | Copyright: (c) 2009 Stange-Distribution Simone Stange, Berlin 3 | Contact: info@obd-shop.com 4 | License: GNU GPL v2 (see License.txt) 5 | Author: Frank Nitzsche classd@beta-x.de 6 | File: main.h 7 | Version: 16.02.09 8 | Compiler: AVR-GCC 9 | **************************************************************************/ 10 | 11 | 12 | ////////////////////////////////////////////////////////////////////////// 13 | // User Config // 14 | ////////////////////////////////////////////////////////////////////////// 15 | 16 | //Set RC5-Address and RC5-Command associated with Volume, Bass, Treble and Gain 17 | #define VOL_P 20,16 18 | #define VOL_M 20,17 19 | //#define BASS_P 20,26 20 | #define BASS_P 20,1 21 | //#define BASS_M 20,27 22 | #define BASS_M 20,4 23 | //#define TREB_P 20,59 24 | #define TREB_P 20,3 25 | //#define TREB_M 20,28 26 | #define TREB_M 20,6 27 | #define GAIN_P 20,52 28 | #define GAIN_M 20,50 29 | 30 | ////////////////////////////////////////////////////////////////////////// 31 | // User Config // 32 | ////////////////////////////////////////////////////////////////////////// 33 | -------------------------------------------------------------------------------- /pp-donation.awk: -------------------------------------------------------------------------------- 1 | # pp-donation.awk -*- awk -*- 2 | # 3 | # Extract donation details from a Paypal notification mail. This is 4 | # called from a shell script because we need to use gawk's -b option. 5 | 6 | BEGIN { 7 | FS = ":" 8 | } 9 | 10 | FNR==1 && NR > 1 { result() } 11 | 12 | /^Donation Details/ { in_details = 1; next } 13 | 14 | !in_details && /^[Dd][Aa][Tt][Ee]:/ { 15 | date=trim($2 ":" $3 ":" $4) 16 | if (match(date, /^[a-zA-Z0-9,-: \t]+$/)) 17 | { 18 | cmd = "date -d '" date "' +'%F'" 19 | cmd | getline date 20 | close(cmd) 21 | } 22 | else 23 | { 24 | date = "INVALID DATE" 25 | } 26 | } 27 | 28 | !in_details && /^This email confirms.*from/ { 29 | email = gensub(/.*\(([^)]+)\)\..*/, "\\1", 1) 30 | } 31 | 32 | !in_details { next } 33 | 34 | /^[ \t]*Total amount:/ {split($2, a, " "); sub(/,/, ".", a[1]); amount = a[1]} 35 | 36 | /^The following.*Publish my sponsor name\?/ { 37 | publish = substr(trim($3), 1, 1) 38 | } 39 | 40 | /^Contributor:/ { name = trim($2) } 41 | 42 | END { 43 | result() 44 | } 45 | 46 | function result() { 47 | printf "| %s | %s | %s | %s | %s |\n", date, amount, publish, name, email 48 | date="" 49 | amount="" 50 | publish="" 51 | name="" 52 | email="" 53 | in_details=0 54 | } 55 | 56 | function trim(s) { 57 | sub (/[ \t]+$/, "", s) 58 | sub (/^[ \t]+/, "", s) 59 | return s 60 | } 61 | -------------------------------------------------------------------------------- /modulo-d-amp/iic.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | Copyright: (c) 2009 Stange-Distribution Simone Stange, Berlin 3 | Contact: info@obd-shop.com 4 | License: GNU GPL v2 (see License.txt) 5 | Author: Frank Nitzsche classd@beta-x.de 6 | File: iic.h 7 | Version: 16.02.09 8 | Compiler: AVR-GCC 9 | **************************************************************************/ 10 | #ifndef IIC_DEF 11 | #define IIC_DEF 12 | 13 | #include "common.h" 14 | 15 | #define MAX_ITER 10 // Cancel if slave not responds 16 | 17 | ////////////////////////////////////////////////////////////////////////// 18 | void init_iic(U16 Khz); 19 | ////////////////////////////////////////////////////////////////////////// 20 | BOOL start_iic(unsigned char address); // TRUE if success 21 | ////////////////////////////////////////////////////////////////////////// 22 | int rep_start_iic(unsigned char address); 23 | ////////////////////////////////////////////////////////////////////////// 24 | void stop_iic(void); 25 | ////////////////////////////////////////////////////////////////////////// 26 | void write_iic(U8 data); 27 | ////////////////////////////////////////////////////////////////////////// 28 | U8 read_iic_ack(void); 29 | ////////////////////////////////////////////////////////////////////////// 30 | U8 read_iic_nack(void); 31 | ////////////////////////////////////////////////////////////////////////// 32 | 33 | 34 | #endif//IIC_DEF 35 | -------------------------------------------------------------------------------- /ebus/hsd-date.c: -------------------------------------------------------------------------------- 1 | /* hsd-date.c - Date functions for housed and housectl 2 | * Copyright (C) 2011 Werner Koch (dd9jn) 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | * 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | 27 | /* Take a time string and convert it into an ebus style time. Ebus 28 | time is the number of 10 second intervals since Monday 0:00 local 29 | time. (uint16_t)(-1) is returned on error. 30 | 31 | Supported formats are: 32 | 33 | hh:mm:sx - Hour, minute and 10 seconds on Monday 34 | w hh:mm:sx - Ditto with weekday specified 35 | ndhh:mm:sx - Ditto with weekday give as Monday (0) to Sunday (6) 36 | 37 | with 38 | 39 | hh = Hour 40 | mm = Minutes 41 | sx = Seconds with the lower digit ignored 42 | w = Weekday name (mo,tu,we,th,fr,sa,su) 43 | or (mon,tue,wed,thu,fri,sat,sun) 44 | in any capitalization. 45 | */ 46 | uint16_t 47 | timestr_to_ebustime (const char *string) 48 | { 49 | 50 | } 51 | -------------------------------------------------------------------------------- /xor.c: -------------------------------------------------------------------------------- 1 | /* xor - Extremly sophisticated encryption system 2 | * Copyright (C) 2011 Werner Koch (dd9jn) 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | int 23 | main (int argc, char **argv ) 24 | { 25 | const unsigned char *key; 26 | int c, keyidx, keylen; 27 | unsigned char val; 28 | 29 | if ( argc != 2 ) 30 | { 31 | fputs ("usage: xor KEYSTRING < input\n", stderr); 32 | return 1; 33 | } 34 | 35 | key = (const unsigned char *)argv[1]; 36 | keylen = strlen ((const char*)key); 37 | keyidx = 0; 38 | 39 | while ( (c=getchar ()) != EOF ) 40 | { 41 | val = (c & 0xff); 42 | if (keylen) 43 | { 44 | val ^= key[keyidx++]; 45 | if (keyidx >= keylen) 46 | keyidx = 0; 47 | } 48 | putchar (val); 49 | } 50 | if (ferror (stdin)) 51 | { 52 | fputs ("xor: read error\n", stderr); 53 | return 1; 54 | } 55 | if (fflush (stderr) || ferror (stdout)) 56 | { 57 | fputs ("xor: write error\n", stderr); 58 | return 1; 59 | } 60 | 61 | return 0; 62 | } 63 | 64 | /* 65 | Local Variables: 66 | compile-command: "cc -Wall -o xor xor.c" 67 | End: 68 | */ 69 | -------------------------------------------------------------------------------- /modulo-d-amp/max9744.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | Copyright: (c) 2009 Stange-Distribution Simone Stange, Berlin 3 | Contact: info@obd-shop.com 4 | License: GNU GPL v2 (see License.txt) 5 | Author: Frank Nitzsche classd@beta-x.de 6 | File: max9744.c 7 | Version: 16.02.09 8 | Compiler: AVR-GCC 9 | **************************************************************************/ 10 | 11 | #include 12 | #include "max9744.h" 13 | #include "iic.h" 14 | 15 | //Mirrors a MAX9744 register. 16 | static U8 Volume; 17 | 18 | ////////////////////////////////////////////////////////////////////////// 19 | static void writeByteMax(uint8_t Val){ 20 | start_iic(MAX9744_WR_ADR); 21 | write_iic(Val); 22 | stop_iic(); 23 | } 24 | ////////////////////////////////////////////////////////////////////////// 25 | void max9744init(U8 Mode){ 26 | PIN_INIT(MAX9744_SHDN_IO); 27 | PIN_ACTIV(MAX9744_SHDN_IO); 28 | _delay_ms(5); 29 | PIN_PASSIV(MAX9744_SHDN_IO); 30 | _delay_ms(5); 31 | 32 | Mode &= 0x01; //Mode must not exceed 1 33 | writeByteMax(MAX9744_MODULATION | Mode); 34 | 35 | Volume = 0; 36 | writeByteMax(MAX9744_VOLUME_ABS | Volume); 37 | 38 | } 39 | ////////////////////////////////////////////////////////////////////////// 40 | void max9744shutDown(void){ 41 | PIN_ACTIV(MAX9744_SHDN_IO); 42 | } 43 | ////////////////////////////////////////////////////////////////////////// 44 | void max9744setVol(U8 Vol){ 45 | Volume = Vol; 46 | if(Volume > 128) //for catching decrement if Volume==0 like this: max9744setVol(max9744getVol()-1) 47 | Volume = 0; 48 | else if(Volume > 63) //for catching increment if Volume==63 like this: max9744setVol(max9744getVol()+1) 49 | Volume = 63; 50 | writeByteMax(MAX9744_VOLUME_ABS | Volume); 51 | } 52 | ////////////////////////////////////////////////////////////////////////// 53 | U8 max9744getVol(void){ 54 | return Volume; 55 | } 56 | ////////////////////////////////////////////////////////////////////////// 57 | U16 max9744getVolPercent(void){ 58 | U16 Tmp = Volume; 59 | return ( (Tmp * 100 + 63/2) / 63); 60 | } 61 | 62 | -------------------------------------------------------------------------------- /rot13.c: -------------------------------------------------------------------------------- 1 | /* rot13 - very sophisticated encryption system 2 | * Copyright (C) 2000 Werner Koch (dd9jn) 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | static void 23 | rot13 ( char *block ) 24 | { 25 | int i, c; 26 | 27 | for (i = 0; i < 5; i++ ) { 28 | c = (block[i] + 13) % 26; 29 | putchar ( 'A'+c ); 30 | } 31 | } 32 | 33 | 34 | int 35 | main (int argc, char **argv ) 36 | { 37 | char block[5]; 38 | int n=0, c, idx=0; 39 | 40 | if ( argc > 1 ) { 41 | fprintf (stderr, "usage: rot13 < input\n"); 42 | return 1; 43 | } 44 | 45 | 46 | while ( (c=getchar ()) != EOF ) { 47 | if ( c >= 'a' && c <= 'z' ) 48 | block[idx++] = c - 'a'; 49 | else if ( c >= 'A' && c <= 'Z' ) 50 | block[idx++] = c - 'A'; 51 | else if ( c != ' ' && c != '\t' && c != '\n' ) 52 | fprintf (stderr, "rot13: ignoring character 0x%02X\n", c ); 53 | if ( idx >= 5 ) { 54 | if ( n ) 55 | putchar (' '); 56 | rot13 (block); 57 | idx = 0; 58 | if ( ++n == 10 ) { 59 | putchar ('\n'); 60 | n = 0; 61 | } 62 | } 63 | } 64 | if ( idx ) { 65 | while ( idx < 5 ) 66 | block[idx++] = 'X' - 'A'; 67 | if ( n ) 68 | putchar (' '); 69 | rot13 (block); 70 | putchar ('\n'); 71 | } 72 | 73 | return 0; 74 | } 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /gpg4win-stats: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Count number of gpg4win downloads. 3 | # usage: gpg4win-stats 1.0.1 4 | # Replace 1.0.2 by the real version number 5 | 6 | set -e 7 | ver="$1" 8 | 9 | cd /var/log 10 | 11 | ( zcat ftp.log.{9,8,7,6,5,4,3,2,1}.gz 2>/dev/null ; 12 | cat ftp.log{.0,} 2>/dev/null ) \ 13 | | awk -v ver="$ver" ' 14 | BEGIN { sum_std = 0; sum_light = 0; sum_src = 0 15 | sum_std_s = 0; sum_light_s = 0; sum_src_s = 0 } 16 | 17 | $9 != "retrieved" { next } 18 | 19 | $10 == "\"/gpg4win/gpg4win-" ver ".exe\"," { sum_std++ } 20 | $10 == "\"/gpg4win/gpg4win-light-" ver ".exe\"," { sum_light++ } 21 | $10 == "\"/gpg4win/gpg4win-src-" ver ".exe\"," { sum_src++ } 22 | $10 == "\"/gpg4win/gpg4win-" ver ".exe.sig\"," { sum_std_s++ } 23 | $10 == "\"/gpg4win/gpg4win-light-" ver ".exe.sig\"," { sum_light_s++ } 24 | $10 == "\"/gpg4win/gpg4win-src-" ver ".exe.sig\"," { sum_src_s++ } 25 | 26 | first_date == "" { first_date = $1 " " $2 } 27 | { last_date = $1 " " $2 } 28 | 29 | END { 30 | print "FTP downloads from [" first_date "] to [" last_date "]" 31 | print "gpg4win-" ver ".exe: " sum_std " (" sum_std_s ")" 32 | print "gpg4win-light-" ver ".exe: " sum_light " (" sum_light_s ")" 33 | print "gpg4win-src-" ver ".exe: " sum_src " (" sum_src_s ")" 34 | } 35 | ' 36 | 37 | cd boa 38 | 39 | ( zcat access_log.{9,8,7,6,5,4,3,2,1}.gz 2>/dev/null; 40 | cat access_log{.0,} 2>/dev/null ) \ 41 | | awk -v ver="$ver" ' 42 | BEGIN { sum_std = 0; sum_light = 0; sum_src = 0 43 | sum_std_s = 0; sum_light_s = 0; sum_src_s = 0 } 44 | 45 | $7 != "\"GET" { next } 46 | $10 != 200 { next} 47 | 48 | $8 == "/gpg4win-" ver ".exe" { sum_std++ } 49 | $8 == "/gpg4win-light-" ver ".exe" { sum_light++ } 50 | $8 == "/gpg4win-src-" ver ".exe" { sum_src++ } 51 | $8 == "/gpg4win-" ver ".exe.sig" { sum_std_s++ } 52 | $8 == "/gpg4win-light-" ver ".exe.sig" { sum_light_s++ } 53 | $8 == "/gpg4win-src-" ver ".exe.sig" { sum_src_s++ } 54 | 55 | first_date == "" { first_date = $5 } 56 | { last_date = $5 } 57 | 58 | END { 59 | print "HTTP downloads from " first_date "] to " last_date "]" 60 | print "gpg4win-" ver ".exe: " sum_std " (" sum_std_s ")" 61 | print "gpg4win-light-" ver ".exe: " sum_light " (" sum_light_s ")" 62 | print "gpg4win-src-" ver ".exe: " sum_src " (" sum_src_s ")" 63 | } 64 | ' 65 | 66 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2010-07-27 Werner Koch 2 | 3 | * sha1sum.c (unescapefname): Fix unescaping. 4 | 5 | 2009-09-02 Werner Koch 6 | 7 | * mkdiff: Fix sort(1) syntax. 8 | 9 | 2006-11-21 Werner Koch 10 | 11 | * scrutmime.c (message_cb): Don't exit for HTML but my name in the 12 | To field. 13 | 14 | 2006-09-25 Werner Koch 15 | 16 | * mkdiff: Don't diff po files. 17 | 18 | 2005-03-15 Werner Koch 19 | 20 | * mkdiff: Changed to use bzip2 21 | 22 | 2005-07-18 Werner Koch 23 | 24 | * scrutmime.c (parse_message): Cope with aditional Exim generated 25 | info lines. 26 | 27 | 2005-07-13 Werner Koch 28 | 29 | * scrutmime.c (parse_message): Add a kludge to allow parsing 30 | Exim generated bounces. 31 | 32 | 2005-01-07 Werner Koch 33 | 34 | * addrutil.c (FinishRecord): Fixed change according to CVS done 35 | back in May. 36 | 37 | 2004-12-09 Werner Koch 38 | 39 | * sha1sum.c: New based on SHA1- code from gnupg and out md5sum. 40 | High noon to switch from MD5 checksums to sha1. 41 | 42 | 2004-11-19 Werner Koch 43 | 44 | * scrutmime.c (parse_message): Increase buffer to 1000 to detect 45 | EXE files with a long header before the PE mark. 46 | 47 | 2003-12-29 Werner Koch 48 | 49 | * addrutil.c (ProcessTexOp): Implemented modifier ":N=". 50 | 51 | 2003-12-16 Werner Koch 52 | 53 | * manifest-tool: Give hints on files not included in Manifest. 54 | 55 | 2003-11-22 Werner Koch 56 | 57 | * addrutil.c (FinishRecord): For mode 0, escape quote colons. 58 | 59 | 2003-11-18 Werner Koch 60 | 61 | * manifest-tool: New. 62 | 63 | 2003-07-20 Werner Koch 64 | 65 | * vegetarise.c (main): Fixed counting for mbox files. Thanks to 66 | Andreas Beck. 67 | 68 | 2003-07-17 Werner Koch 69 | 70 | * vegetarise.c: Add minimal usage information. 71 | 72 | 2003-04-05 Werner Koch 73 | 74 | * mkdiff: Use awk to cope with the VERSION file. This allows for 75 | multiline files. 76 | 77 | 2002-12-23 Werner Koch 78 | 79 | * webbsh.c (check_for_suid): Filter output of find. Noted by 80 | Thomas Roessler. 81 | 82 | 2002-12-06 Werner Koch 83 | 84 | * webbsh.c: New. 85 | 86 | 2002-06-30 Werner Koch 87 | 88 | * mkdiff: New option --no-sign. 89 | 90 | -------------------------------------------------------------------------------- /b64dec.c: -------------------------------------------------------------------------------- 1 | /* undump - Hex undump tool 2 | * Copyright (C) 2000 Werner Koch (dd9jn) 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | #define digitp(p) ((p) >= '0' && (p) <= '9') 23 | #define hexdigitp(a) (digitp (a) \ 24 | || ((a) >= 'A' && (a) <= 'F') \ 25 | || ((a) >= 'a' && (a) <= 'f')) 26 | #define ascii_isspace(a) ((a)==' ' || (a)=='\n' || (a)=='\r' || (a)=='\t') 27 | #define xtoi_1(p) ((p) <= '9'? ((p)- '0'): \ 28 | (p) <= 'F'? ((p)-'A'+10):((p)-'a'+10)) 29 | 30 | 31 | 32 | 33 | int 34 | main (int argc, char **argv ) 35 | { 36 | int c1, c2; 37 | unsigned int value; 38 | 39 | if ( argc > 1 ) 40 | { 41 | fprintf (stderr, "usage: undump < input\n"); 42 | return 1; 43 | } 44 | 45 | 46 | while ( (c1=getchar ()) != EOF ) 47 | { 48 | if (ascii_isspace (c1)) 49 | continue; 50 | if (!hexdigitp (c1)) 51 | { 52 | fprintf (stderr, "undump: non hex-digit encountered\n"); 53 | return 1; 54 | } 55 | if ( (c2=getchar ()) == EOF ) 56 | { 57 | fprintf (stderr, "undump: error reading second nibble\n"); 58 | return 1; 59 | } 60 | if (!hexdigitp (c2)) 61 | { 62 | fprintf (stderr, "undump: second nibble is not a hex-digit\n"); 63 | return 1; 64 | } 65 | value = xtoi_1 (c1) * 16 + xtoi_1 (c2); 66 | putchar (value); 67 | } 68 | if (ferror (stdin)) 69 | { 70 | fprintf (stderr, "undump: read error\n"); 71 | return 1; 72 | } 73 | 74 | return 0; 75 | } 76 | 77 | /* 78 | Local Variables: 79 | compile-command: "cc -Wall -o undump undump.c" 80 | End: 81 | */ 82 | 83 | 84 | -------------------------------------------------------------------------------- /ebus/hsd-misc.c: -------------------------------------------------------------------------------- 1 | /* hsd-misc.c - Miscellaneous functions for housed and housectl 2 | * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 3 | * 2008, 2009, 2010 Free Software Foundation, Inc. 4 | * Copyright (C) 2011 Werner Koch (dd9jn) 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | * 19 | */ 20 | 21 | /* Some code has been taken from the jnlib part og gnupg. */ 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include "hsd-misc.h" 28 | 29 | static void 30 | out_of_core (char const *string) 31 | { 32 | fprintf (stderr, "out of core in %s\n", string); 33 | exit (2); 34 | } 35 | 36 | 37 | void * 38 | xmalloc (size_t n) 39 | { 40 | void *p = malloc (n); 41 | if (!p) 42 | out_of_core ("xmalloc"); 43 | return p; 44 | } 45 | 46 | void * 47 | xstrdup (char const *string) 48 | { 49 | char *p; 50 | 51 | p = malloc (strlen (string)+1); 52 | if (!p) 53 | out_of_core ("xstrdup"); 54 | strcpy (p, string); 55 | return p; 56 | } 57 | 58 | 59 | int 60 | ascii_strcasecmp (char const *a, char const *b) 61 | { 62 | if (a == b) 63 | return 0; 64 | 65 | for (; *a && *b; a++, b++) 66 | { 67 | if (*a != *b && ascii_toupper (*a) != ascii_toupper (*b)) 68 | break; 69 | } 70 | return *a == *b? 0 : (ascii_toupper (*a) - ascii_toupper (*b)); 71 | } 72 | 73 | 74 | int 75 | ascii_strncasecmp (char const *a, char const *b, size_t n) 76 | { 77 | unsigned char const *p1 = (unsigned char const *)a; 78 | unsigned char const *p2 = (unsigned char const *)b; 79 | unsigned char c1, c2; 80 | 81 | if (p1 == p2 || !n ) 82 | return 0; 83 | 84 | do 85 | { 86 | c1 = ascii_tolower (*p1); 87 | c2 = ascii_tolower (*p2); 88 | 89 | if ( !--n || c1 == '\0') 90 | break; 91 | 92 | ++p1; 93 | ++p2; 94 | } 95 | while (c1 == c2); 96 | 97 | return c1 - c2; 98 | } 99 | -------------------------------------------------------------------------------- /modulo-d-amp/tda7449.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | Copyright: (c) 2009 Stange-Distribution Simone Stange, Berlin 3 | Contact: info@obd-shop.com 4 | License: GNU GPL v2 (see License.txt) 5 | Author: Frank Nitzsche classd@beta-x.de 6 | File: tda7449.h 7 | Version: 16.02.09 8 | Compiler: AVR-GCC 9 | **************************************************************************/ 10 | 11 | #ifndef TDA7449_H 12 | #define TDA7449_H 13 | 14 | #include "common.h" 15 | 16 | /* 17 | Communication: 18 | 1. Master sends START condition 19 | 2. Master sends 7bits slave ID plus write bit (low) 20 | 3. Slave asserts ACK 21 | 4. Master sends Subaddress + B 22 | 5. Slave asserts ACK (or NACK) 23 | 6. Master sends Data_1..Data_n <--. (more than one if B=1=Autoincrement) 24 | 7. Slave asserts ACK (or NACK) ---' 25 | 6. Master generates STOP condition 26 | */ 27 | 28 | //Slave address write 29 | #define TDA7449_WR_ADR 0x88 30 | 31 | //Subaddress "Autoincrement" 32 | #define TDA7449_B 0x10 33 | //Subaddress "Function" 34 | #define TDA7449_INP_SEL 0x00 35 | #define TDA7449_INP_GAIN 0x01 36 | #define TDA7449_VOLUME 0x02 37 | #define TDA7449_BASS 0x04 38 | #define TDA7449_TREBLE 0x05 39 | #define TDA7449_ATT_RIGHT 0x06 40 | #define TDA7449_ATT_LEFT 0x07 41 | 42 | //Input selection 43 | #define TDA7449_INP1 0x03 44 | #define TDA7449_INP2 0x02 45 | 46 | 47 | ////////////////////////////////////////////////////////////////////////// 48 | void TDA7449init(void); 49 | ////////////////////////////////////////////////////////////////////////// 50 | void TDA7449setInput(U8); // {TDA7449_INP1, TDA7449_INP2} 51 | ////////////////////////////////////////////////////////////////////////// 52 | void TDA7449setBass(S8); // {-14,-12,..+12,+14} [dB] 53 | ////////////////////////////////////////////////////////////////////////// 54 | void TDA7449setTreble(S8); // {-14,-12,..+12,+14} [dB] 55 | ////////////////////////////////////////////////////////////////////////// 56 | void TDA7449setGain(U8); // {0,2,4,...26,28,30} [dB] 57 | ////////////////////////////////////////////////////////////////////////// 58 | S8 TDA7449getBass(void); // {-14,-12,..+12,+14} [dB] 59 | ////////////////////////////////////////////////////////////////////////// 60 | S8 TDA7449getTreble(void); // {-14,-12,..+12,+14} [dB] 61 | ////////////////////////////////////////////////////////////////////////// 62 | U8 TDA7449getGain(void); // {0,2,4,...26,28,30} [dB] 63 | 64 | 65 | #endif//TDA7449_H 66 | -------------------------------------------------------------------------------- /ebus/hsd-misc.h: -------------------------------------------------------------------------------- 1 | /* hsd-misc.c - Miscellaneous macros for housed.c and housectl.c 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | #ifndef HSD_MISC_H 19 | #define HSD_MISC_H 20 | 21 | 22 | void *xmalloc (size_t n); 23 | void *xstrdup (char const *string); 24 | 25 | static inline int 26 | ascii_isspace (int a) 27 | { 28 | switch (a) 29 | { 30 | case ' ': case '\n': case '\r': 31 | case '\t': case '\f': case '\v': 32 | return 1; 33 | default: 34 | return 0; 35 | } 36 | } 37 | 38 | static inline int 39 | ascii_isupper (int c) 40 | { 41 | return c >= 'A' && c <= 'Z'; 42 | } 43 | 44 | static inline int 45 | ascii_islower (int c) 46 | { 47 | return c >= 'a' && c <= 'z'; 48 | } 49 | 50 | static inline int 51 | ascii_toupper (int c) 52 | { 53 | if (c >= 'a' && c <= 'z') 54 | c &= ~0x20; 55 | return c; 56 | } 57 | 58 | static inline int 59 | ascii_tolower (int c) 60 | { 61 | if (c >= 'A' && c <= 'Z') 62 | c |= 0x20; 63 | return c; 64 | } 65 | 66 | 67 | int ascii_strcasecmp (char const *a, char const *b); 68 | int ascii_strncasecmp (char const *a, char const *b, size_t n); 69 | 70 | 71 | /*-- Macros to replace ctype ones to avoid locale problems. --*/ 72 | #define spacep(p) (*(p) == ' ' || *(p) == '\t') 73 | #define digitp(p) (*(p) >= '0' && *(p) <= '9') 74 | #define hexdigitp(a) (digitp (a) \ 75 | || (*(a) >= 'A' && *(a) <= 'F') \ 76 | || (*(a) >= 'a' && *(a) <= 'f')) 77 | 78 | 79 | /* The atoi macros assume that the buffer has only valid digits. */ 80 | #define atoi_1(p) (*(p) - '0' ) 81 | #define atoi_2(p) ((atoi_1(p) * 10) + atoi_1((p)+1)) 82 | #define atoi_4(p) ((atoi_2(p) * 100) + atoi_2((p)+2)) 83 | #define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \ 84 | *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10)) 85 | #define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1)) 86 | #define xtoi_4(p) ((xtoi_2(p) * 256) + xtoi_2((p)+2)) 87 | 88 | /* Helper macros. */ 89 | #define DIM(v) (sizeof(v)/sizeof((v)[0])) 90 | 91 | #endif /*HSD_MISC_H*/ 92 | -------------------------------------------------------------------------------- /encrypt-to-p.c: -------------------------------------------------------------------------------- 1 | /* encrypt-to-p.c - Do we have an encrypt-to in gpg.conf? 2 | * Copyright (C) 2008 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 3 of 7 | * the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #define fail_if_err(err) \ 25 | do \ 26 | { \ 27 | if (err) \ 28 | { \ 29 | fprintf (stderr, "%s:%d: %s: %s\n", \ 30 | __FILE__, __LINE__, gpgme_strsource (err), \ 31 | gpgme_strerror (err)); \ 32 | exit (1); \ 33 | } \ 34 | } \ 35 | while (0) 36 | 37 | 38 | int 39 | main (int argc, char **argv) 40 | { 41 | gpg_error_t err; 42 | gpgme_ctx_t ctx; 43 | gpgme_conf_comp_t conf; 44 | gpgme_conf_comp_t comp; 45 | gpgme_conf_opt_t opt; 46 | int result = 1; 47 | 48 | gpgme_check_version (NULL); 49 | setlocale (LC_ALL, ""); 50 | gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); 51 | gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL)); 52 | 53 | err = gpgme_engine_check_version (GPGME_PROTOCOL_OpenPGP); 54 | fail_if_err (err); 55 | 56 | err = gpgme_new (&ctx); 57 | fail_if_err (err); 58 | 59 | err = gpgme_op_conf_load (ctx, &conf); 60 | fail_if_err (err); 61 | 62 | for (comp = conf; comp; comp = comp->next) 63 | { 64 | if (!strcmp (comp->name, "gpg")) 65 | { 66 | for (opt = comp->options; opt; opt = opt->next) 67 | if ( !(opt->flags & GPGME_CONF_GROUP) 68 | && !strcmp (opt->name, "encrypt-to")) 69 | { 70 | if (opt->value && opt->alt_type == GPGME_CONF_STRING) 71 | { 72 | printf ("%s\n", opt->value->value.string); 73 | result = 0; 74 | } 75 | break; 76 | } 77 | break; 78 | } 79 | } 80 | 81 | gpgme_conf_release (conf); 82 | gpgme_release (ctx); 83 | 84 | return result; 85 | } 86 | 87 | /* 88 | Local Variables: 89 | compile-command: "gcc -Wall -g -lgpgme -o encrypt-to-p encrypt-to-p.c" 90 | End: 91 | */ 92 | -------------------------------------------------------------------------------- /backup-audio: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Backup a collection of Ogg audiofiles to a set of DVDs. -*- sh -*- 3 | # Copyright (C) 2008 Werner Koch 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU Lesser General Public License as 7 | # published by the Free Software Foundation; either version 2.1 of 8 | # the License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Lesser General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Lesser General Public 16 | # License along with this program; if not, write to the Free Software 17 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 18 | 19 | # Default values 20 | PGM="backup-audio" 21 | PGM_VERSION="0.1" 22 | LC_ALL=C 23 | dryrun=no 24 | 25 | # Helper constants 26 | tick='`' 27 | 28 | # Parse the options 29 | prev= 30 | while [ $# -gt 0 ]; do 31 | arg="$1" 32 | case $arg in 33 | -*=*) optarg=$(echo "X$arg" | sed -e '1s/^X//' -e 's/[-_a-zA-Z0-9]*=//') 34 | ;; 35 | *) optarg= 36 | ;; 37 | esac 38 | if [ -n "$prev" ]; then 39 | eval "$prev=\$arg" 40 | prev= 41 | shift 42 | continue 43 | fi 44 | case $arg in 45 | --version) 46 | echo "$PGM $PGM_VERSION" 47 | exit 0 48 | ;; 49 | 50 | --help|-h) 51 | cat <&2 73 | exit 1 74 | ;; 75 | 76 | *) 77 | break 78 | ;; 79 | esac 80 | shift 81 | done 82 | if [ -n "$prev" ]; then 83 | echo "$PGM: argument missing for option $tick$prev'" >&2 84 | exit 1 85 | fi 86 | 87 | if [ $# != 1 ]; then 88 | echo "usage: $PGM " >&2 89 | exit 1 90 | fi 91 | sourcedir="$1" 92 | 93 | find $sourcedir -mindepth 2 -maxdepth 2 -type d -print0 | xargs -0 du -ms \ 94 | | awk ' 95 | 96 | { sum += $1 97 | print $0 98 | if (sum > 4300) { 99 | print "-----" 100 | print sum, " total" 101 | sum = 0 102 | dvdcount++; 103 | } 104 | } 105 | END { print "number of DVD required: " dvdcount } 106 | ' 107 | 108 | 109 | -------------------------------------------------------------------------------- /rfc822parse.h: -------------------------------------------------------------------------------- 1 | /* rfc822parse.h - Simple mail and MIME parser 2 | * Copyright (C) 1999 Werner Koch, Duesseldorf 3 | * Copyright (C) 2003, g10 Code GmbH 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License as 7 | * published by the Free Software Foundation; either version 2 of the 8 | * License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, but 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | * General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 18 | */ 19 | 20 | #ifndef RFC822PARSE_H 21 | #define RFC822PARSE_H 22 | 23 | struct rfc822parse_context; 24 | typedef struct rfc822parse_context *rfc822parse_t; 25 | 26 | typedef enum 27 | { 28 | RFC822PARSE_OPEN = 1, 29 | RFC822PARSE_CLOSE, 30 | RFC822PARSE_CANCEL, 31 | RFC822PARSE_T2BODY, 32 | RFC822PARSE_FINISH, 33 | RFC822PARSE_RCVD_SEEN, 34 | RFC822PARSE_LEVEL_DOWN, 35 | RFC822PARSE_LEVEL_UP, 36 | RFC822PARSE_BOUNDARY, 37 | RFC822PARSE_LAST_BOUNDARY, 38 | RFC822PARSE_BEGIN_HEADER, 39 | RFC822PARSE_PREAMBLE, 40 | RFC822PARSE_EPILOGUE 41 | } 42 | rfc822parse_event_t; 43 | 44 | struct rfc822parse_field_context; 45 | typedef struct rfc822parse_field_context *rfc822parse_field_t; 46 | 47 | 48 | typedef int (*rfc822parse_cb_t) (void *opaque, 49 | rfc822parse_event_t event, 50 | rfc822parse_t msg); 51 | 52 | 53 | rfc822parse_t rfc822parse_open (rfc822parse_cb_t cb, void *opaque_value); 54 | 55 | void rfc822parse_close (rfc822parse_t msg); 56 | 57 | void rfc822parse_cancel (rfc822parse_t msg); 58 | int rfc822parse_finish (rfc822parse_t msg); 59 | 60 | int rfc822parse_insert (rfc822parse_t msg, 61 | const unsigned char *line, size_t length); 62 | 63 | char *rfc822parse_get_field (rfc822parse_t msg, const char *name, int which, 64 | size_t *valueoff); 65 | 66 | const char *rfc822parse_enum_header_lines (rfc822parse_t msg, void **context); 67 | 68 | rfc822parse_field_t rfc822parse_parse_field (rfc822parse_t msg, 69 | const char *name, 70 | int which); 71 | 72 | void rfc822parse_release_field (rfc822parse_field_t field); 73 | 74 | const char *rfc822parse_query_parameter (rfc822parse_field_t ctx, 75 | const char *attr, int lower_value); 76 | 77 | const char *rfc822parse_query_media_type (rfc822parse_field_t ctx, 78 | const char **subtype); 79 | 80 | #endif /*RFC822PARSE_H */ 81 | -------------------------------------------------------------------------------- /ebus/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile - The CSMA Elektor Bus 2 | # Copyright (C) 2011 g10 Code GmbH 3 | # 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program; if not, see . 16 | # 17 | 18 | MCU=atmega88 19 | CC = avr-gcc 20 | OBJCOPY = avr-objcopy 21 | CFLAGS = -Wall -Wno-pointer-sign -mmcu=$(MCU) -g -Os 22 | LIBS = 23 | 24 | HOSTCC = gcc 25 | HOSTCFLAGS = -D_GNU_SOURCE -Wall -Wno-pointer-sign -g -O0 26 | 27 | sources = ebus.h hardware.c hardware.h protocol.h csma.c \ 28 | ebusdump.c testnode.c shutter.c proto-busctl.h proto-h61.h \ 29 | proto-dbgmsg.h onewire.c i2c.c i2c-lcd.c \ 30 | housed.c housectl.c \ 31 | hsd-misc.c hsd-misc.h \ 32 | hsd-time.c hsd-time.h 33 | 34 | all: housed housectl testnode.hex shutter.hex doorbell.hex 35 | 36 | common_node_obj = hardware.o csma.o onewire.o 37 | 38 | common_hsd_obj = hsd-misc.o hsd-time.o 39 | 40 | .PHONY: FORCE 41 | 42 | FORCE: 43 | 44 | revision.h: FORCE Makefile 45 | @set -e; \ 46 | if [ "x$$(git status -uno --porcelain)" = x ]; then \ 47 | git branch -v --no-color 2>/dev/null \ 48 | | awk '/^\* / {printf "#define GIT_REVISION \"%s\"\n",$$3}' \ 49 | > revision.h.tmp;\ 50 | else \ 51 | echo '#define GIT_REVISION "unknown"' > revision.h.tmp ;\ 52 | fi;\ 53 | if [ ! -f $@ ]; then \ 54 | mv -f revision.h.tmp $@ ;\ 55 | elif ! cmp revision.h.tmp $@; then \ 56 | mv -f revision.h.tmp $@ ;\ 57 | fi 58 | 59 | ebus.h : revision.h 60 | 61 | hardware.o : hardware.h ebus.h protocol.h 62 | csma.o : ebus.h protocol.h 63 | testnode.o : hardware.h ebus.h protocol.h 64 | shutter.o : ebus.h protocol.h proto-h61.h proto-busctl.h 65 | onewire.o: hardware.h ebus.h 66 | i2c.o: hardware.h ebus.h 67 | i2c-lcd.o: hardware.h ebus.h 68 | 69 | hsd-misc.o: hsd-misc.c hsd-misc.h 70 | hsd-time.o: hsd-time.c hsd-time.h hsd-misc.h 71 | ebusctl.o: hsd-time.h hsd-misc.h 72 | 73 | testnode.elf : testnode.o $(common_node_obj) 74 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) 75 | 76 | shutter.elf : shutter.o $(common_node_obj) 77 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) 78 | 79 | doorbell.elf : doorbell.o $(common_node_obj) i2c.o i2c-lcd.o 80 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS) 81 | 82 | 83 | %.hex : %.elf 84 | $(OBJCOPY) -O ihex -j .text -j .data $< $@ 85 | 86 | $(common_hsd_obj): 87 | $(HOSTCC) $(HOSTCFLAGS) -o $@ -c $*.c 88 | 89 | housed : housed.c protocol.h proto-busctl.h proto-h61.h 90 | $(HOSTCC) $(HOSTCFLAGS) -o $@ housed.c 91 | 92 | housectl : housectl.c protocol.h proto-busctl.h proto-h61.h $(common_hsd_obj) 93 | $(HOSTCC) $(HOSTCFLAGS) -o $@ housectl.c $(common_hsd_obj) 94 | -------------------------------------------------------------------------------- /ebus/protocol.h: -------------------------------------------------------------------------------- 1 | /* protocol.h - Protocol definitons for an Elektor Bus Node 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | #ifndef PROTOCOL_H 19 | #define PROTOCOL_H 20 | 21 | /* The sync byte which indicates the start of a new message. If this 22 | byte is used inside the message it needs to be escaped and XORed 23 | with the escape mask. This ensures that a sync byte will always be 24 | the start of a new frame. Note that this is similar to the PPP 25 | (rfc-1662) framing format. */ 26 | #define FRAMESYNCBYTE 0x7e 27 | #define FRAMEESCBYTE 0x7d 28 | #define FRAMEESCMASK 0x20 29 | 30 | /* The protocol type describes the format of the payload; ie. the 31 | actual message. It is used instead of the 0xaa byte of the 32 | original (May 2011) ElektorBus protocol. Defined values: 33 | 34 | | Bit 7 .. 6 | Bit 5 .. 0 | 35 | |------------+--------------| 36 | | Msglen | ProtocolType | 37 | |------------+--------------| 38 | 39 | | Msglen | Description | 40 | |--------+----------------------| 41 | | 0 | 48 byte + 2 byte CRC | 42 | | 1 | 32 byte + 2 byte CRC | 43 | | 2 | 16 byte + 2 byte CRC | 44 | | 3 | RFU | 45 | | | | 46 | 47 | | ProtocolType | Description | Allowed Msglen codes | 48 | |---------------+------------------------+-----------------------| 49 | | 0x00 | Not used | - | 50 | | 0x01 ... 0x2f | Assigned values | | 51 | | 0x01 | BusControl | 2,1,0 | 52 | | 0x06 | H/61 protocol | 2 | 53 | | 0x1f | DebugMessage | 2,1,0 | 54 | | 0x2a | ElektorBus Application | 2 | 55 | | 0x30 ... 0x37 | Experimental protocols | | 56 | | 0x38 ... 0x3e | RFU | | 57 | | 0x3f | Not used | | 58 | */ 59 | #define PROTOCOL_MSGLEN_MASK 0xc0 60 | #define PROTOCOL_TYPE_MASK 0x3f 61 | #define PROTOCOL_MSGLEN_48 0x00 62 | #define PROTOCOL_MSGLEN_32 0x40 63 | #define PROTOCOL_MSGLEN_16 0x80 64 | 65 | #define PROTOCOL_EBUS_BUSCTL (PROTOCOL_MSGLEN_16 | 0x01) 66 | #define PROTOCOL_EBUS_H61 (PROTOCOL_MSGLEN_16 | 0x06) 67 | #define PROTOCOL_EBUS_DBGMSG (PROTOCOL_MSGLEN_16 | 0x1f) 68 | #define PROTOCOL_EBUS_TEST (PROTOCOL_MSGLEN_16 | 0x31) 69 | 70 | #endif /*PROTOCOL_H*/ 71 | -------------------------------------------------------------------------------- /ebus/ebus.h: -------------------------------------------------------------------------------- 1 | /* ebus.h - Global definitions for an Elektor Bus Node 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | #ifndef EBUS_H 19 | #define EBUS_H 20 | 21 | #include 22 | #include "protocol.h" 23 | #include "revision.h" 24 | 25 | 26 | /* Typedefs. */ 27 | typedef unsigned char byte; 28 | 29 | 30 | /* We only support 16 byte long messages. */ 31 | #define MSGSIZE 16 32 | 33 | 34 | /* For fast access we copy some of the config data into the RAM. */ 35 | struct 36 | { 37 | byte nodeid_hi; 38 | byte nodeid_lo; 39 | byte debug_flags; 40 | byte reset_flags; 41 | } config; 42 | 43 | 44 | /* Set to one (e.g. the timer int) to wakeup the main loop. */ 45 | volatile char wakeup_main; 46 | 47 | /* We need a flag indicating whether the time has been set. */ 48 | byte time_has_been_set; 49 | 50 | 51 | /*-- hardware.c --*/ 52 | void hardware_setup (byte nodetype); 53 | byte read_key_s2 (void); 54 | byte read_key_s3 (void); 55 | uint16_t get_current_time (void); 56 | uint16_t get_current_fulltime (byte *r_deci); 57 | void set_current_fulltime (uint16_t tim, byte deci); 58 | void set_debug_flags (uint8_t value); 59 | 60 | 61 | /*-- csma.c --*/ 62 | void csma_setup (void); 63 | unsigned int csma_get_stats (int what); 64 | void csma_send_message (const byte *data, byte datalen); 65 | byte *csma_get_message (void); 66 | void csma_message_done (void); 67 | 68 | /*-- onewire.c --*/ 69 | void onewire_setup (void); 70 | void onewire_enable (void); 71 | void onewire_disable (void); 72 | void onewire_write_byte (uint8_t c); 73 | uint8_t onewire_read_byte (void); 74 | void onewire_wait_for_one (void); 75 | 76 | /*-- i2c.c --*/ 77 | void i2c_setup (void); 78 | byte i2c_start_mt (byte address); 79 | byte i2c_send_byte (byte value); 80 | byte i2c_send_data (byte *data, byte datalen); 81 | void i2c_stop (void); 82 | 83 | 84 | /*-- i2c-lcd.c --*/ 85 | void lcd_setup (void); 86 | void lcd_init (void); 87 | void lcd_backlight (uint8_t onoff); 88 | void lcd_putc (uint8_t c); 89 | void lcd_clear (void); 90 | void lcd_home (void); 91 | void lcd_gotoxy (uint8_t x, uint8_t y); 92 | void lcd_puts (const char *s); 93 | void _lcd_puts_P (const char *progmem_s); 94 | #define lcd_puts_P(s) _lcd_puts_P (PSTR ((s))) 95 | 96 | 97 | /*-- Callbacks to be implemented by each node --*/ 98 | #define MILLISEC(a) ((a)/10) 99 | void ticker_bottom (unsigned int clock); /* Called by hardware.c. */ 100 | 101 | 102 | /* Helper macros. */ 103 | #define DIM(v) (sizeof(v)/sizeof((v)[0])) 104 | 105 | 106 | #endif /*EBUS_H*/ 107 | -------------------------------------------------------------------------------- /modulo-d-amp/rc5.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | File: rc5.c 3 | **************************************************************************/ 4 | 5 | /************************************************************************/ 6 | /* */ 7 | /* RC5 Remote Receiver */ 8 | /* */ 9 | /* Author: Peter Dannegger */ 10 | /* danni@specs.de */ 11 | /* */ 12 | /************************************************************************/ 13 | 14 | /************************************************************************* 15 | Slightly modified: Frank Nitzsche classd@beta-x.de 16 | **************************************************************************/ 17 | #include 18 | #include "rc5.h" 19 | /** RC5 bittime constant */ 20 | #define RC5TIME 1.778e-3 //msec 21 | 22 | #define PULSE_MIN (U8)(F_CPU / 1024 * RC5TIME * 0.4 + 0.5) //@8Mhz 23 | #define PULSE_1_2 (U8)(F_CPU / 1024 * RC5TIME * 0.8 + 0.5) 24 | #define PULSE_MAX (U8)(F_CPU / 1024 * RC5TIME * 1.2 + 0.5) 25 | 26 | #define xRC5_IN PINB 27 | #define xRC5 PB0 // IR input low active 28 | 29 | U8 rc5_bit; // bit value 30 | U8 rc5_time; // count bit time 31 | U16 rc5_tmp; // shift bits in 32 | U16 rc5_data; // store result 33 | 34 | void initRc5(void){ 35 | TCCR2 = 1< PULSE_MAX ){ // count pulse time 48 | if( !(tmp & 0x4000) && tmp & 0x2000 ) // only if 14 bits received 49 | rc5_data = tmp; 50 | tmp = 0; 51 | } 52 | 53 | if( (rc5_bit ^ xRC5_IN) & 1< 0xFF -> 0x00 55 | 56 | if( rc5_time < PULSE_MIN ){ // to short 57 | tmp = 0; 58 | } 59 | 60 | if( !tmp || rc5_time > PULSE_1_2 ){ // start or long pulse time 61 | if( !(tmp & 0x4000) ) // not to many bits 62 | tmp <<= 1; // shift 63 | if( !(rc5_bit & 1<Tgl = i >> 11 & 1; 78 | Rc5->Adr = i >> 6 & 0x1F; 79 | Rc5->Cmd = (i & 0x3F) | ((~i >> 6) & 0x40); 80 | return(i!=0); 81 | } 82 | -------------------------------------------------------------------------------- /ebus/hardware.h: -------------------------------------------------------------------------------- 1 | /* hardware.h - Hardware definitons for an Elektor Bus Node 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | #ifndef HARDWARE_H 19 | #define HARDWARE_H 20 | 21 | #include 22 | 23 | /* UART defs. */ 24 | #define BAUD 9600ul 25 | 26 | /* Clock frequency in Hz. */ 27 | #define F_CPU 16000000UL 28 | 29 | /* Key and LED definitions. */ 30 | #define KEY_S2_PIN (PIND) 31 | #define KEY_S2_BIT (PIND5) 32 | #define KEY_S3_PIN (PIND) 33 | #define KEY_S3_BIT (PIND7) 34 | #define LED_Collision (PORTD) 35 | #define LED_Collision_BIT (4) 36 | #define LED_Transmit (PORTD) 37 | #define LED_Transmit_BIT (6) 38 | 39 | #define KEY_S2 bit_is_set (KEY_S2_PIN, KEY_S2_BIT) 40 | #define KEY_S3 bit_is_set (KEY_S3_PIN, KEY_S3_BIT) 41 | 42 | /* Plugin hardware definitions. */ 43 | #define OW_Bus_DDR (DDRC) /* The 1-Wire Bus. */ 44 | #define OW_Bus_PORT (PORTC) 45 | #define OW_Bus_PIN (PINC) 46 | #define OW_Bus_BIT (0) 47 | 48 | 49 | /* Node type values */ 50 | #define NODETYPE_UNDEFINED 0 51 | #define NODETYPE_SHUTTER 1 52 | #define NODETYPE_DOORBELL 2 53 | #define NODETYPE_BRIDGE 16 54 | 55 | 56 | /* EEPROM layout for all node types. */ 57 | struct __attribute__ ((packed)) ee_data_s 58 | { 59 | uint8_t nodetype; 60 | uint8_t reserved; 61 | union 62 | { 63 | uint8_t raw[110]; 64 | 65 | struct __attribute__ ((packed)) 66 | { 67 | /* We may store up to 16 up/down actions in the schedule table. 68 | An entry with value zero indicates the end of the table. The 69 | granularity is 1 minute with the 10-seconds values used to 70 | indicate the action: 71 | minute + 0 := no action 72 | minute + 10 := pull-up 73 | minute + 20 := rfu 74 | minute + 30 := rfu 75 | minute + 40 := rfu 76 | minute + 50 := pull-down 77 | */ 78 | uint16_t schedule[16]; 79 | /* If the next variable is 1 a shutter status message will be 80 | sent at the end of an action. If it is 0 none is sent. 81 | Other values are reserved for future extensions. */ 82 | uint8_t notify; 83 | } shutterctl; 84 | 85 | struct __attribute__ ((packed)) 86 | { 87 | unsigned char foo; 88 | } doorbell; 89 | } u; 90 | }; 91 | 92 | extern struct ee_data_s ee_data; 93 | 94 | 95 | /* In particular F_CPU is required for other system headers to work 96 | correctly; thus do a simple check first. */ 97 | #if defined(_STDLIB_H_) || defined(_UTIL_DELAY_H_) 98 | # error file not included prior to other header files 99 | #endif 100 | 101 | #endif /*HARDWARE_H*/ 102 | -------------------------------------------------------------------------------- /modulo-d-amp/max9744.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | Copyright: (c) 2009 Stange-Distribution Simone Stange, Berlin 3 | Contact: info@obd-shop.com 4 | License: GNU GPL v2 (see License.txt) 5 | Author: Frank Nitzsche classd@beta-x.de 6 | File: max9744.h 7 | Version: 16.02.09 8 | Compiler: AVR-GCC 9 | **************************************************************************/ 10 | #ifndef MAX9744_H 11 | #define MAX9744_H 12 | 13 | ////////////////////////////////////////////////////////////////////////// 14 | // User Config // 15 | ////////////////////////////////////////////////////////////////////////// 16 | 17 | // Set to 1 if Pin ADDR1 is tied to Vcc 18 | #define MAX9744_A1_VCC 1 19 | 20 | // Set to 1 if Pin ADDR2 is tied to Vcc 21 | #define MAX9744_A2_VCC 1 22 | 23 | // Define Port/Pin connected with /SHDN 24 | #define MAX9744_SHDN_PORT D 25 | #define MAX9744_SHDN_PIN 3 26 | 27 | ////////////////////////////////////////////////////////////////////////// 28 | // User Config // 29 | ////////////////////////////////////////////////////////////////////////// 30 | 31 | #include "common.h" 32 | 33 | /* 34 | Communication: 35 | 1. Master sends START condition 36 | 2. Master sends 7bits slave ID plus write bit (low) 37 | 3. Slave asserts ACK 38 | 4. Master sends 8 data bits 39 | 5. Slave asserts ACK (or NACK) 40 | 6. Master generates STOP condition 41 | 42 | Data byte: 43 | A1, A0, V5, V4, V3, V2, V1, V0 44 | 45 | A1,A0 V5..V0 46 | ------------ 47 | 00 xxxxxx Volume 48 | 01 000000 Filterless modulation 49 | 01 000001 Classic PWM 50 | 10 ------ Reserved 51 | 11 000100 Volume + 52 | 11 000101 Volume - 53 | 54 | */ 55 | 56 | //Slave Address 57 | #if (MAX9744_A1_VCC && MAX9744_A2_VCC) 58 | #define MAX9744_WR_ADR 0x96 // Slave address write MAX9744 59 | #elif(MAX9744_A1_VCC && !MAX9744_A2_VCC) 60 | #define MAX9744_WR_ADR 0x94 // Slave address write MAX9744 61 | #elif(!MAX9744_A1_VCC && MAX9744_A2_VCC) 62 | #define MAX9744_WR_ADR 0x92 // Slave address write MAX9744 63 | #else 64 | #error "MAX9744 IIC disabled" 65 | #endif 66 | 67 | //A1,A0 68 | #define MAX9744_VOLUME_ABS 0x00 69 | #define MAX9744_VOLUME_REL 0xC0 70 | #define MAX9744_MODULATION 0x40 71 | 72 | //V5..V0 73 | #define MAX9744_FILTERLESS 0x00 74 | #define MAX9744_PWM 0x01 75 | #define MAX9744_VOL_INC 0x04 76 | #define MAX9744_VOL_DEC 0x05 77 | 78 | //Shutdown-Pin 79 | #define MAX9744_SHDN_IO LOGIC_NEGATIV, MAX9744_SHDN_PORT, MAX9744_SHDN_PIN 80 | 81 | 82 | ////////////////////////////////////////////////////////////////////////// 83 | void max9744init(U8 Mode); //Mode: {MAX9744_FILTERLESS, MAX9744_PWM} 84 | ////////////////////////////////////////////////////////////////////////// 85 | void max9744shutDown(void); 86 | ////////////////////////////////////////////////////////////////////////// 87 | void max9744setVol(U8 Vol); //Vol: {0..63} 88 | ////////////////////////////////////////////////////////////////////////// 89 | U8 max9744getVol(void); //U8: {0..63} 90 | ////////////////////////////////////////////////////////////////////////// 91 | U16 max9744getVolPercent(void); //U16: {0..100} -> 0..100% 92 | 93 | #endif /*MAX9744_H*/ 94 | -------------------------------------------------------------------------------- /ebus/README: -------------------------------------------------------------------------------- 1 | Running an CSMA/CD protocol on the Elektor Bus. -*- org -*- 2 | 3 | * Installation instructions 4 | 5 | Just run "make" to build the code. To write the flash you use this: 6 | 7 | : avrdude -c usbasp -pm88 -U flash:w:PROGRAM.hex 8 | 9 | Please make sure to set the FUSE bits correctly: 10 | 11 | - lfuse = 0xFF (16MHz crystal) 12 | - hfuse = 0xD7 (ie. set EESAVE)) 13 | 14 | you may do this by using these commands: 15 | 16 | : avrdude -c usbasp -pm88 -v -B 4 -U lfuse:w:0xFF:m 17 | : avrdude -c usbasp -pm88 -v -B 4 -U hfuse:w:0xD7:m 18 | 19 | (You may use 0xD4 for hfuse to enable the BOD at 4.3V 20 | or 0xD5 for hfuse to enable the BOD at 2.7V) 21 | 22 | You also need to assign an different node-id to each node in the 23 | same collision domain by storing them in the EEPROM. Due to 24 | restriction of RS485 protocol more than 32 nodes are not possible 25 | with most modern drivers. To allow for easier switching we suggest 26 | to use only nodes ids in the range 1..30. If more buses will 27 | eventually be attached the high bits may be used to identify the 28 | bus. Such a simple scheme allows easy routing between buses by 29 | direct mapping of the node ids. 30 | 31 | For example, setting the node-id 17 (0x11) may be done with: 32 | 33 | : avrdude -c usbasp -pm88 -U eeprom:w:0,0,0,17:m 34 | 35 | (two reserved bytes of 0, followed by node id hi (0) and lo (17) ) 36 | 37 | To read the entire EEPROM into the file a.out use: 38 | 39 | : avrdude -c usbasp -pm88 -U eeprom:r:a.out:r 40 | 41 | 42 | * Helper tools 43 | 44 | The tool ebusdump.c may be used on a Unix hosts to display the 45 | stats. Assuming the RS-485 converter is attached to /dev/ttyUSB1 46 | you would do this: 47 | 48 | stty =0 37 | if(Native & 0x08) 38 | return Temp; 39 | //if native value means < 0 40 | else 41 | return -Temp; 42 | } 43 | ////////////////////////////////////////////////////////////////////////// 44 | static U8 convertSounddB2Native(S8 DB){ 45 | U8 Temp = 0x08; 46 | DB /= 2; 47 | 48 | if(DB < 0){ 49 | Temp = 0; 50 | DB *= -1; 51 | } 52 | 53 | if(DB > 7) 54 | DB = 7; 55 | 56 | Temp += (7-DB); 57 | 58 | return Temp; 59 | } 60 | ////////////////////////////////////////////////////////////////////////// 61 | void TDA7449init(void){ 62 | Volume = 0; // = -0dB, adjust if desired 63 | writeByteTda(TDA7449_VOLUME, Volume); 64 | 65 | Attenuation[ATT_LEFT] = 6; // = -6dB, adjust if desired 66 | writeByteTda(TDA7449_ATT_LEFT, Attenuation[ATT_LEFT] ); 67 | Attenuation[ATT_RIGHT] = 6; // = -6dB, adjust if desired 68 | writeByteTda(TDA7449_ATT_RIGHT, Attenuation[ATT_RIGHT]); 69 | 70 | TDA7449setBass(0); // = 0dB, adjust if desired 71 | TDA7449setTreble(0); // = 0dB, adjust if desired 72 | 73 | Gain = 0; // = +0dB, adjust if desired 74 | writeByteTda(TDA7449_INP_GAIN, Gain); 75 | 76 | TDA7449setInput(TDA7449_INP2); 77 | } 78 | ////////////////////////////////////////////////////////////////////////// 79 | void TDA7449setInput(U8 Inp){ 80 | writeByteTda(TDA7449_INP_SEL, Inp); 81 | } 82 | ////////////////////////////////////////////////////////////////////////// 83 | void TDA7449setBass(S8 B){ 84 | Bass = convertSounddB2Native(B); 85 | writeByteTda(TDA7449_BASS, Bass); 86 | } 87 | ////////////////////////////////////////////////////////////////////////// 88 | void TDA7449setTreble(S8 T){ 89 | Treble = convertSounddB2Native(T); 90 | writeByteTda(TDA7449_TREBLE, Treble); 91 | } 92 | ////////////////////////////////////////////////////////////////////////// 93 | void TDA7449setGain(U8 G){ 94 | if(G > 128) //for catching decrement if Volume==0 like this: max9744setVol(max9744getVol()-1) 95 | G = 0; 96 | else if(G > 30) //for catching increment if Volume==63 like this: max9744setVol(max9744getVol()+1) 97 | G = 30; 98 | Gain = G/2; 99 | writeByteTda(TDA7449_INP_GAIN, Gain); 100 | } 101 | ////////////////////////////////////////////////////////////////////////// 102 | S8 TDA7449getBass(void){ 103 | return convertSoundNative2dB(Bass); 104 | } 105 | ////////////////////////////////////////////////////////////////////////// 106 | S8 TDA7449getTreble(void){ 107 | return convertSoundNative2dB(Treble); 108 | } 109 | ////////////////////////////////////////////////////////////////////////// 110 | U8 TDA7449getGain(void){ 111 | return Gain*2; 112 | } 113 | 114 | -------------------------------------------------------------------------------- /log.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Modified by wk@gnupg.org so that -m list does only 4 | # work with one mail address (usually a ML), set a fixed 5 | # From: address so that mailman needs only one allowed poster, 6 | # Use a default logfile with with not -f arg. 2001-10-18 7 | # Modified by werner.koch@guug.de to add support for 8 | # automagically extraction of ChangeLog entries 1998-11-27 9 | # Modified by woods@web.apc.org to add support for mailing 3/29/93 10 | # use '-m user' for each user to receive cvs log reports 11 | # and use '-f logfile' for the logfile to append to 12 | # 13 | # Modified by berliner@Sun.COM to add support for CVS 1.3 2/27/92 14 | # 15 | # Date: Tue, 6 Aug 91 13:27 EDT 16 | # From: samborn@sunrise.com (Kevin Samborn) 17 | # 18 | # I revised the perl script I sent you yesterday to use the info you 19 | # send in on stdin. (I am appending the newer script to the end) 20 | # 21 | # $Revision: 1.2 $ 22 | 23 | $cvsroot = $ENV{'CVSROOT'}; 24 | $fromaddr = "cvs\@cvs.gnupg.org"; 25 | # turn off setgid 26 | # 27 | $) = $(; 28 | 29 | # parse command line arguments 30 | # 31 | while (@ARGV) { 32 | $arg = shift @ARGV; 33 | 34 | if ($arg eq '-m') { 35 | ($users) && die "Too many '-m' args"; 36 | $users = shift @ARGV; 37 | } elsif ($arg eq '-f') { 38 | ($logfile) && die "Too many '-f' args"; 39 | $logfile = shift @ARGV; 40 | } else { 41 | ($donefiles) && die "Too many arguments!\n"; 42 | $donefiles = 1; 43 | @files = split(/ /, $arg); 44 | } 45 | } 46 | 47 | ($logfile) || ($logfile = "$cvsroot/CVSROOT/commitlog"); 48 | 49 | $srepos = shift @files; 50 | $mailcmd = "| /usr/sbin/sendmail -t -oi"; 51 | 52 | # Some date and time arrays 53 | # 54 | @mos = (January,February,March,April,May,June,July,August,September, 55 | October,November,December); 56 | @days = (Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday); 57 | 58 | ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; 59 | 60 | $year = $year + 1900; 61 | 62 | # get login name 63 | # 64 | $login = getlogin || (getpwuid($<))[0] || "nobody"; 65 | 66 | # open log file for appending 67 | # 68 | open(OUT, ">>" . $logfile) || die "Could not open(" . $logfile . "): $!\n"; 69 | if ($users) { 70 | open(MAIL, $mailcmd) || die "Could not Exec($mailcmd): $!\n"; 71 | } 72 | 73 | # print out the log Header 74 | # 75 | print OUT "\n"; 76 | print OUT "**************************************\n"; 77 | print OUT "Date:\t$days[$wday] $mos[$mon] $mday, $year @ $hour:" . sprintf("%02d", $min) . "\n"; 78 | print OUT "Author:\t$login\n\n"; 79 | 80 | if (MAIL) { 81 | print MAIL "From: $fromaddr\n"; 82 | print MAIL "To: $users\n"; 83 | print MAIL "Subject: $login committed to $srepos\n"; 84 | print MAIL "\n"; 85 | print MAIL "Date:\t$days[$wday] $mos[$mon] $mday, $year @ $hour:" . sprintf("%02d", $min) . "\n"; 86 | print MAIL "Author:\t$login\n\n"; 87 | } 88 | 89 | # print the stuff from logmsg that comes in on stdin to the logfile 90 | # 91 | open(IN, "-"); 92 | while () { 93 | chop; 94 | if( /^See[ ]ChangeLog:[ ](.*)/ ) { 95 | $changelog = $1; 96 | $okay = false; 97 | open(RCS, "-|") || exec 'cvs', '-Qn', 'update', '-p', 'ChangeLog'; 98 | while () { 99 | if( /^$changelog .*/ ) { 100 | $okay = true; 101 | print OUT; 102 | MAIL && print MAIL; 103 | } 104 | elsif( $okay ) { 105 | last if( /^[A-Z]+.*/ ); 106 | print OUT; 107 | MAIL && print MAIL; 108 | } 109 | } 110 | while () { ; } 111 | close(RCS); 112 | } 113 | print OUT $_, "\n"; 114 | MAIL && print MAIL $_, "\n"; 115 | } 116 | close(IN); 117 | 118 | print OUT "\n"; 119 | 120 | 121 | 122 | # after log information, do an 'cvs -Qn status' on each file in the arguments. 123 | # 124 | while (@files) { 125 | $file = shift @files; 126 | if ($file eq "-") { 127 | print OUT "[input file was '-']\n"; 128 | if (MAIL) { 129 | print MAIL "[input file was '-']\n"; 130 | } 131 | last; 132 | } 133 | 134 | open(RCS, "-|") || exec 'cvs', '-Qn', 'status', $file; 135 | 136 | while () { 137 | if (/^[ \t]*Version/ || /^File:/) { 138 | print OUT; 139 | if (MAIL) { 140 | print MAIL; 141 | } 142 | } 143 | } 144 | close(RCS); 145 | } 146 | 147 | close(OUT); 148 | die "Write to $logfile failed" if $?; 149 | 150 | close(MAIL); 151 | die "Pipe to $mailcmd failed" if $?; 152 | 153 | exit 0; 154 | 155 | -------------------------------------------------------------------------------- /ebus/proto-busctl.h: -------------------------------------------------------------------------------- 1 | /* proto-busctl.h - Definition of the BusControl protocol. 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | #ifndef PROTO_BUSCTL_H 19 | #define PROTO_BUSCTL_H 20 | 21 | /* Description of the BusControl protocol. 22 | 23 | This protocol is used on the ebus for generic tasks. All messages 24 | use the common header: 25 | 26 | byte 0 - protocol PROTOCOL_EBUS_BUSCTL (0x81) 27 | byte 1 - receiver node-id high 28 | byte 2 - receiver node-id low 29 | byte 3 - sender node-id high 30 | byte 4 - sender node-id low 31 | byte 5 - command, see below 32 | byte 6...15 - command dependent 33 | 34 | A sender node-id high of 0 is valid and indicates that the sender 35 | is on the current bus segment. A sender node-id low of 0 is 36 | reserved for a bus controller node (which is currently not 37 | defined). A sender with node-id low or high set to 0xff is 38 | invalid. 39 | 40 | List of Commands. Bit 7 is the RESPONSE bit and used for 41 | corresponding response messages. The command itself is given by 42 | bits 6 to 0: 43 | 44 | * 0x01 := Time Broadcast 45 | 46 | byte 6 - Control byte 47 | bit 2 - Daylight Saving Time active 48 | bit 1 - Decile seconds given. 49 | bit 0 - Exact time given. If this bit is not set, the time 50 | may be somewhat off due to collision retries. 51 | byte 7,8 - Number of 10 second periods passed this week. 52 | byte 9 - Decile seconds within this period. Values are 0 to 99 53 | representing 0.0 to 9.9 seconds. 54 | byte 10..15 - rfu 55 | 56 | No reponses are defined or expected. 57 | 58 | Note that the usual operation is to broadcast the current time from 59 | a sender connected to an NTP server. Thus it is common to see 60 | receiver node-ids of (0xff,0xff). 61 | 62 | The time on the bus is the local time. This makes it easier to 63 | display and modify times. This function shall be called by a master 64 | around the daylight switching hour to make sure the bus gets updated 65 | to the right time. 66 | 67 | * 0x02 := Query Time 68 | 69 | byte 6..15 - rfu, must be 0. 70 | 71 | Response format: 72 | 73 | byte 6 - rfu 74 | byte 7,8 - Number of 10 second periods passed this week. 75 | byte 9 - Decile seconds within this period. Values are 0 to 99 76 | representing 0.0 to 9.9 seconds. 77 | 78 | * 0x03 := Query Version 79 | 80 | byte 6..15 - rfu, must be 0. 81 | 82 | Response format: 83 | 84 | byte 6 - nodetype (NODETYPE_xxxx) 85 | byte 7 - reserved 86 | byte 8..14 - GIT revision string or "unknown". 87 | byte 15 - reserved 88 | 89 | * 0x04 := Set Debug Flags 90 | 91 | byte 6 - Debug flags 92 | byte 7..15 - rfu 93 | 94 | No responses are defined. 95 | 96 | * 0x05 := Query Debug Flags 97 | 98 | byte 6..15 - rfu, must be 0. 99 | 100 | Response format: 101 | 102 | byte 6 - Debug flags 103 | byte 7 - Reset flags at startup. 104 | byte 8..15 - rfu 105 | 106 | * 0x06 := Query Name 107 | 108 | byte 6..15 - rfu, must be 0. 109 | 110 | Response format: 111 | 112 | byte 6 - nodetype (NODETYPE_xxxx) 113 | byte 7 - reserved 114 | byte 8..15 - name of the node 115 | 116 | */ 117 | 118 | #include "protocol.h" 119 | 120 | #define P_BUSCTL_RESPMASK 0x80 /* The response mask for the commands. */ 121 | #define P_BUSCTL_TIME 0x01 /* Time Broadcast. */ 122 | #define P_BUSCTL_QRY_TIME 0x02 /* Query Time. */ 123 | #define P_BUSCTL_QRY_VERSION 0x03 /* Query software version. */ 124 | #define P_BUSCTL_SET_DEBUG 0x04 /* Set debug flags. */ 125 | #define P_BUSCTL_QRY_DEBUG 0x05 /* Query debug flags. */ 126 | #define P_BUSCTL_QRY_NAME 0x06 /* Query Name. */ 127 | 128 | #endif /*PROTO_BUSCTL_H*/ 129 | -------------------------------------------------------------------------------- /modulo-d-amp/iic.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | Copyright: (c) 2009 Stange-Distribution Simone Stange, Berlin 3 | Contact: info@obd-shop.com 4 | License: GNU GPL v2 (see License.txt) 5 | Author: Frank Nitzsche classd@beta-x.de 6 | File: iic.c 7 | Version: 16.02.09 8 | Compiler: AVR-GCC 9 | **************************************************************************/ 10 | 11 | #include 12 | #include "iic.h" 13 | 14 | 15 | /*************************************************************************/ 16 | void init_iic(U16 Khz){ 17 | /*************************************************************************/ 18 | TWSR = 0; 19 | TWBR = (F_CPU / Khz / 1000 - 16) / 2; 20 | } 21 | 22 | /*************************************************************************/ 23 | BOOL start_iic(U8 address){ 24 | /*************************************************************************/ 25 | 26 | U8 TwSt; 27 | U8 Tout=MAX_ITER; 28 | 29 | while(Tout) 30 | { 31 | Tout--; 32 | // send START condition 33 | TWCR = (1< 0); // TRUE -> Success 65 | } 66 | /*************************************************************************/ 67 | int rep_start_iic(U8 address){ 68 | /*************************************************************************/ 69 | 70 | /* Returnwerte: 71 | * 0 -> Success 72 | * 1 -> Problem when issuing start conditions 73 | * 2 -> Problem when sending address 74 | * or no Device with specified address 75 | */ 76 | 77 | TWCR = (1<. 16 | */ 17 | 18 | #include "hardware.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "ebus.h" 32 | 33 | #define DBG_ONEWIRE 1 34 | 35 | static int 36 | write_reset (void) 37 | { 38 | /* Drive low for 480us. */ 39 | OW_Bus_PORT &= ~_BV(OW_Bus_BIT); 40 | _delay_us (480); 41 | /* Drive high via pull-up for 480us. */ 42 | OW_Bus_PORT |= _BV(OW_Bus_BIT); /* Enable pull-up. */ 43 | OW_Bus_DDR &= ~_BV(OW_Bus_BIT); /* Configure as input. */ 44 | _delay_us (480); 45 | OW_Bus_DDR |= _BV(OW_Bus_BIT); /* Configure as output. */ 46 | return 0; 47 | } 48 | 49 | 50 | static void 51 | write_one (void) 52 | { 53 | /* Drive low for 10us (1 <= T_low1 < 15). */ 54 | OW_Bus_PORT &= ~_BV(OW_Bus_BIT); 55 | _delay_us (10); 56 | /* Drive high for 80us (60us <= T_slot < 120us) 60+(120-60)/2-T_low1. */ 57 | OW_Bus_PORT |= _BV(OW_Bus_BIT); 58 | _delay_us (80); 59 | /* Note that this includes enough time for recovery. */ 60 | } 61 | 62 | static void 63 | write_zero (void) 64 | { 65 | /* Drive low for 90us (60 <= T_low0 < 120). */ 66 | OW_Bus_PORT &= ~_BV(OW_Bus_BIT); 67 | _delay_us (90); 68 | /* Drive high again. */ 69 | OW_Bus_PORT |= _BV(OW_Bus_BIT); 70 | } 71 | 72 | 73 | static uint8_t 74 | read_bit (void) 75 | { 76 | uint8_t c; 77 | 78 | /* Drive low for at least 1us; we use 2us. */ 79 | OW_Bus_PORT &= ~_BV(OW_Bus_BIT); 80 | _delay_us (2); 81 | /* Drive high via pull-up to that the slave may pull it down. */ 82 | OW_Bus_PORT |= _BV(OW_Bus_BIT); /* Enable pull-up. */ 83 | OW_Bus_DDR &= ~_BV(OW_Bus_BIT); /* Configure as input. */ 84 | _delay_us (10); 85 | c = !!bit_is_set (OW_Bus_PIN, OW_Bus_BIT); 86 | _delay_us (78); /* This makes the slot 90us. */ 87 | OW_Bus_DDR |= _BV(OW_Bus_BIT); /* Configure as output. */ 88 | 89 | return c; 90 | } 91 | 92 | 93 | /* Power up the bus if not done and reset the bus. */ 94 | void 95 | onewire_enable (void) 96 | { 97 | OW_Bus_PORT |= _BV(OW_Bus_BIT); /* Set high. */ 98 | OW_Bus_DDR |= _BV(OW_Bus_BIT); /* Configure as output. */ 99 | write_reset (); 100 | } 101 | 102 | 103 | /* Power down the bus etc. */ 104 | void 105 | onewire_disable (void) 106 | { 107 | 108 | 109 | } 110 | 111 | 112 | void 113 | onewire_write_byte (uint8_t c) 114 | { 115 | uint8_t i; 116 | uint8_t mask; 117 | 118 | #ifdef DBG_ONEWIRE 119 | OW_Bus_PORT |= _BV(1); 120 | #endif 121 | for (mask=1, i=0; i < 8; mask <<= 1, i++) 122 | if ((c & mask)) 123 | write_one (); 124 | else 125 | write_zero (); 126 | _delay_us (20); 127 | #ifdef DBG_ONEWIRE 128 | OW_Bus_PORT &= ~_BV(1); 129 | #endif 130 | } 131 | 132 | 133 | uint8_t 134 | onewire_read_byte (void) 135 | { 136 | uint8_t c, i; 137 | uint8_t mask; 138 | 139 | #ifdef DBG_ONEWIRE 140 | OW_Bus_PORT |= _BV(1); 141 | #endif 142 | c = 0; 143 | for (mask=1, i=0; i < 8; mask <<= 1, i++) 144 | if (read_bit ()) 145 | c |= mask; 146 | 147 | #ifdef DBG_ONEWIRE 148 | OW_Bus_PORT &= ~_BV(1); 149 | #endif 150 | 151 | return c; 152 | } 153 | 154 | 155 | void 156 | onewire_wait_for_one (void) 157 | { 158 | while (!read_bit ()) 159 | ; 160 | } 161 | 162 | 163 | 164 | 165 | /* Initialize the 1-Wire code. This must be done after the 166 | initialization of the general hardware code. Note that this will 167 | only prepare the machinery, for real use onewire_enable needs to be 168 | called before a real action. */ 169 | void 170 | onewire_setup (void) 171 | { 172 | /* Internal pullup needs to be enabled. Startup as output. */ 173 | OW_Bus_PORT |= _BV(OW_Bus_BIT); /* Enable pull-up. */ 174 | OW_Bus_DDR |= _BV(OW_Bus_BIT); 175 | 176 | #ifdef DBG_ONEWIRE 177 | OW_Bus_PORT &= ~_BV(1); 178 | OW_Bus_DDR |= _BV(1); 179 | #endif 180 | } 181 | -------------------------------------------------------------------------------- /bfuck.c: -------------------------------------------------------------------------------- 1 | /* bfuck.c - brainfuck interpreter 2 | * Copyright (C) 2022 Werner Koch 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License as 6 | * published by the Free Software Foundation; either version 3 of 7 | * the License, or (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | * 17 | * For sample programs see: 18 | * https://git.gnupg.org/cgi-bin/gitweb.cgi?p=wk-misc.git;a=tree;f=data 19 | */ 20 | 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #define PGM "bfuck" 28 | #define DATASIZE 1000 29 | #define STACKSIZE 10 30 | 31 | static int *code; 32 | static size_t codesize, codelen; 33 | 34 | static int data[DATASIZE]; 35 | 36 | static int *stack[STACKSIZE]; 37 | static int stackidx; 38 | 39 | 40 | static int 41 | read_file (const char *fname) 42 | { 43 | FILE *fp; 44 | int c; 45 | 46 | fp = fopen (fname, "r"); 47 | if (!fp) 48 | { 49 | fprintf (stderr, PGM": error opening '%s': %s\n", 50 | fname, strerror (errno)); 51 | return -1; 52 | } 53 | 54 | do 55 | { 56 | c = getc (fp); 57 | if (c == EOF && ferror (fp)) 58 | { 59 | fprintf (stderr, PGM": error reading '%s': %s\n", 60 | fname, strerror (errno)); 61 | fclose (fp); 62 | return -1; 63 | } 64 | if (!code || codelen >= codesize) 65 | { 66 | codesize += 1024; 67 | code = realloc (code, codesize * sizeof *code); 68 | if (!code) 69 | { 70 | fprintf (stderr, PGM": out of code reading '%s'\n", fname); 71 | fclose (fp); 72 | return -1; 73 | } 74 | } 75 | code[codelen++] = c; 76 | } 77 | while (c != EOF); 78 | 79 | fclose (fp); 80 | return 0; 81 | } 82 | 83 | 84 | 85 | int 86 | main (int argc, char **argv) 87 | { 88 | int *ip, *ipend; 89 | int *dp, *dpend; 90 | int lnr; 91 | 92 | if (argc) 93 | { 94 | argc--; 95 | argv++; 96 | } 97 | 98 | while (argc--) 99 | if (read_file (*argv++)) 100 | return 2; 101 | 102 | if (!code || !codelen) 103 | { 104 | fprintf (stderr, PGM ": no program to execute\n"); 105 | return 1; 106 | } 107 | 108 | setbuf (stdin, NULL); 109 | setbuf (stdout, NULL); 110 | 111 | ip = code; 112 | ipend = code + codelen - 1; 113 | dp = data; 114 | dpend = data + DATASIZE - 1; 115 | lnr = 1; 116 | for ( ; ip <= ipend; ip++) 117 | { 118 | switch (*ip) 119 | { 120 | case EOF: /* Prepare for a next file. */ 121 | putchar ('\n'); 122 | memset (data, 0, DATASIZE * sizeof *data); 123 | dp = data; 124 | dpend = data + DATASIZE - 1; 125 | stackidx = 0; 126 | break; 127 | 128 | case '>': 129 | if (dp < dpend) 130 | dp++; 131 | else 132 | { 133 | fprintf (stderr, PGM ": pointer overflow at line %d\n", lnr); 134 | return 2; 135 | } 136 | break; 137 | 138 | case '<': 139 | if (dp > data) 140 | dp--; 141 | else 142 | { 143 | fprintf (stderr, PGM ": pointer underflow at line %d\n", lnr); 144 | return 2; 145 | } 146 | break; 147 | 148 | case '+': ++*dp; break; 149 | case '-': --*dp; break; 150 | case '.': putchar (*dp); break; 151 | case ',': *dp = getchar (); break; 152 | 153 | case '[': 154 | if (stackidx+1 >= STACKSIZE) 155 | { 156 | fprintf (stderr, PGM ": loop too deeply nested at line %d\n",lnr); 157 | return 2; 158 | } 159 | else 160 | { 161 | stack[stackidx] = ip; 162 | stackidx++; 163 | } 164 | break; 165 | 166 | case ']': 167 | if (!stackidx) 168 | { 169 | fprintf (stderr, PGM ": no open loop at line %d\n", lnr); 170 | return 2; 171 | } 172 | else 173 | { 174 | stackidx--; 175 | if (*dp) 176 | { 177 | ip = stack[stackidx]; 178 | ip--; /* fix the bump in the for(). */ 179 | } 180 | } 181 | break; 182 | 183 | case '\n': lnr++; break; 184 | default: break; 185 | } 186 | } 187 | 188 | return 0; 189 | } 190 | -------------------------------------------------------------------------------- /mkdiff: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | signing_key="0x4F25E3B6" 4 | signing_options=" --digest-algo SHA384" 5 | opt_sign=yes 6 | ext=bz2 7 | extz=j 8 | opt_with_po=no 9 | if [ "$1" = "--gzip-source" ]; then 10 | ext=gz 11 | extz=z 12 | shift 13 | fi 14 | if [ "$1" = "--no-sign" ]; then 15 | opt_sign=no 16 | shift 17 | fi 18 | if [ "$1" = "--with-po" ]; then 19 | opt_with_po=yes 20 | shift 21 | fi 22 | 23 | if [ $# = 1 ]; then 24 | pack="$1" 25 | vprf="" 26 | elif [ $# = 2 ] ; then 27 | pack="$1" 28 | vprf="$2" 29 | else 30 | echo "usage: mkdiff [--no-sign] [--with-po] package-name [version-prefix]" >&2 31 | exit 1 32 | fi 33 | 34 | set -e 35 | 36 | curr_ver=$(ls $pack-${vprf}*.tar.${ext} 2>/dev/null | sed "s/^$pack-\(.*\)\.tar\.${ext}/\1/"\ 37 | | sort -r -t '.' -n -k 1,1 -k 2,2 -k 3,3 -k 4,4 | head -1 ) 38 | if [ ! -f $pack-$curr_ver.tar.$ext ]; then 39 | echo "mkdiff: no current version of package $pack found" >&2 40 | exit 1 41 | fi 42 | prev_ver=$(ls $pack-${vprf}*.tar.${ext} 2>/dev/null | sed "s/^$pack-\(.*\)\.tar\.${ext}/\1/"\ 43 | | sort -r -t '.' -n -k 1,1 -k 2,2 -k 3,3 -k 4,4 | head -2 | tail -1 ) 44 | if [ "$prev_ver" = "$curr_ver" ]; then 45 | echo "mkdiff: no previous version of package $pack found" >&2 46 | exit 1 47 | fi 48 | 49 | echo "Current is: $pack-$curr_ver" 50 | echo "Previous is: $pack-$prev_ver" 51 | [ $opt_sign != yes ] && echo "signing disabled" 52 | 53 | echo "Removing old directories" 54 | [ -d "$pack-$curr_ver" ] && rm -rf "$pack-$curr_ver" 55 | [ -d "$pack-$prev_ver" ] && rm -rf "$pack-$prev_ver" 56 | 57 | echo "Unpacking previous and current tar" 58 | 59 | tar x${extz}f "$pack-$curr_ver.tar.$ext" 60 | tar x${extz}f "$pack-$prev_ver.tar.$ext" 61 | # We remove some files from the directories because we assume 62 | # that they are either binary or can be build using the proper tools: 63 | # .tlb - Windows Type Library 64 | # .dvi 65 | # .ps 66 | # .eps 67 | # .pdf 68 | # .gmo - compiled gettext files 69 | # .der - DER encoded test stuff 70 | # .ber - BER encoded test stuff 71 | # .png 72 | # .jpg 73 | tmp="dvi ps eps pdf gmo der ber png jpg" 74 | find_args="-type f -name *.tlb -or -name *.info -or -name *.info-[0-9]" 75 | for i in dvi ps eps pdf gmo der ber png jpg; do 76 | find_args="$find_args -or -name *.$i" 77 | done 78 | [ $opt_with_po = no ] && find_args="$find_args -or -name *.po -or -name *.pot" 79 | find $pack-${curr_ver} $pack-${prev_ver} `echo $find_args` 2>/dev/null \ 80 | | xargs rm -f 2>/dev/null || true 81 | 82 | 83 | echo "Diffing" 84 | tmp_name="$pack-$prev_ver-$curr_ver.diff.tmp" 85 | diff_name="$pack-$prev_ver-$curr_ver.diff" 86 | 87 | LC_ALL=C TZ=UTC0 diff -urpP "$pack-$prev_ver/" "$pack-$curr_ver/" > $tmp_name || true 88 | 89 | echo "Making patch file" 90 | 91 | cat < $diff_name 92 | 93 | This is a patch file to create version $curr_ver from $prev_ver. 94 | 95 | Please check the signature of this patch file: 96 | 97 | bzcat somepath/$pack-$prev_ver-$curr_ver.diff.bz2 | gpg --verify 98 | 99 | Change to directory $pack-$prev_ver (or however you renamed it) 100 | and give this command: 101 | 102 | bzcat somepath/$pack-$prev_ver-$curr_ver.diff.bz2 | gpg | patch -p1 103 | 104 | It is a good idea to rename your current directory to $pack-$curr_ver now. 105 | 106 | 107 | 108 | Prereq: $prev_ver 109 | 110 | EOF 111 | 112 | #sed -ne '/^diff.*VERSION/,/^+[0-9][0-9]*/ p' $tmp_name >> $diff_name 113 | #echo >> $diff_name 114 | #sed -e '/^diff.*VERSION/,/^+[0-9][0-9]*/ d' $tmp_name >> $diff_name 115 | awk '/^diff.*\/VERSION/ {x=1; print; next}; /^diff.*/ && x == 1 {x = 2}; x == 1 {print}' $tmp_name >> $diff_name 116 | awk '/^diff.*\/VERSION/ {x=1; next}; /^diff.*/ && x == 1 {x = 2; print}; x != 1 {print}' $tmp_name >> $diff_name 117 | 118 | 119 | rm $tmp_name 120 | 121 | if [ $opt_sign = yes ]; then 122 | echo "Signing and compressing patch file" 123 | gpg2 --clearsign --not-dash-escaped -u $signing_key $signing_options \ 124 | < $diff_name | bzip2 --best > $diff_name.bz2 125 | else 126 | echo "compressing patch file" 127 | cat $diff_name | bzip2 --best > $diff_name.bz2 128 | fi 129 | rm $diff_name 130 | 131 | echo "Checking patch file" 132 | cd $pack-$prev_ver 133 | bzcat ../$diff_name.bz2 | patch -s -p1 134 | rm $(find . -name "*.orig") 2>/dev/null || true 135 | cd .. 136 | 137 | if ! diff -urP "$pack-$prev_ver/" "$pack-$curr_ver/" >/dev/null ; then 138 | echo "compare failed" 139 | 140 | while :; do 141 | echo "what shall we do: (v)iew, (i)gnore, (a)bort ?" >&2 142 | read 143 | case "$REPLY" in 144 | v|V) 145 | diff -urP "$pack-$prev_ver/" "$pack-$curr_ver/" | less 146 | ;; 147 | i|I) 148 | break 149 | ;; 150 | a|A) 151 | exit 1 152 | ;; 153 | esac 154 | done 155 | fi 156 | 157 | if [ $opt_sign = yes ]; then 158 | if ! bzcat $diff_name.bz2 | gpg2 --batch --verify ; then 159 | exit 1 160 | fi 161 | fi 162 | 163 | echo "cleaning up" 164 | 165 | rm -rf "$pack-$curr_ver" 166 | rm -rf "$pack-$prev_ver" 167 | 168 | echo "Patch file $diff_name.bz2 is good." 169 | -------------------------------------------------------------------------------- /ebus/hsd-time.c: -------------------------------------------------------------------------------- 1 | /* hsd-time.c - Timee functions for housed and housectl 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | * 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "hsd-misc.h" 25 | #include "hsd-time.h" 26 | 27 | 28 | /* Take a time string and convert it into an ebus style time. Ebus 29 | time is the number of 10 second intervals since Monday 0:00 local 30 | time. (uint16_t)(-1) is returned on error. 31 | 32 | Supported formats are: 33 | 34 | hh:mm[:sx] - Hour, minute and 10 seconds on Monday 35 | w hh:mm[:sx] - Ditto with weekday specified 36 | ndhh:mm[:sx] - Ditto with weekday give as Monday (0) to Sunday (6) 37 | 38 | with 39 | 40 | hh = Hour 41 | mm = Minutes 42 | sx = Seconds with the lower digit ignored 43 | w = Weekday name (mo,tu,we,th,fr,sa,su) 44 | or (mon,tue,wed,thu,fri,sat,sun) 45 | in any capitalization. 46 | */ 47 | uint16_t 48 | timestr_to_ebustime (char const *string, char **r_endp) 49 | { 50 | int i, n; 51 | int weekday = 0; 52 | int hour = 0; 53 | int minute = 0; 54 | int second = 0; 55 | char const *s; 56 | char *endp; 57 | 58 | if (!string) 59 | return INVALID_TIME; 60 | 61 | for (; *string && ascii_isspace (*string); string++) 62 | ; 63 | 64 | if (*string >= '0' && *string <= '6' && string[1] == 'd') 65 | { 66 | weekday = *string - '0'; 67 | string += 2; 68 | } 69 | else if ((*string >= 'a' && *string < 'z') 70 | || (*string >= 'A' && *string < 'Z')) 71 | { 72 | static struct { char no; char const * const name; } tbl[] = { 73 | { 0, "mo" }, { 0, "mon" }, { 0, "monday" }, 74 | { 1, "tu" }, { 1, "tue" }, { 1, "tuesday" }, 75 | { 2, "we" }, { 2, "wed" }, { 2, "wednesday" }, 76 | { 3, "th" }, { 3, "thu" }, { 3, "thursday" }, 77 | { 4, "fr" }, { 4, "fri" }, { 4, "friday" }, 78 | { 5, "sa" }, { 5, "sat" }, { 5, "saturday" }, 79 | { 6, "su" }, { 6, "sun" }, { 6, "sunday" }}; 80 | 81 | for (s=string+1; *s; s++) 82 | if (ascii_isspace (*s)) 83 | break; 84 | n = s - string; 85 | for (i=0; i < DIM (tbl); i++) 86 | if (strlen (tbl[i].name) == n 87 | && !ascii_strncasecmp (string, tbl[i].name, n)) 88 | break; 89 | if (!(i < DIM (tbl))) 90 | return INVALID_TIME; 91 | weekday = tbl[i].no; 92 | for (; *s && ascii_isspace (*s); s++) 93 | ; 94 | string = s; 95 | } 96 | 97 | if (!digitp (string)) 98 | return INVALID_TIME; 99 | hour = strtol (string, &endp, 10); 100 | if (hour < 0 || hour > 23 || *endp != ':') 101 | return INVALID_TIME; 102 | string = endp + 1; 103 | minute = strtol (string, &endp, 10); 104 | if (!digitp (string) || !digitp (string+1) || minute < 0 || minute > 59) 105 | return INVALID_TIME; 106 | if (*endp == ':') 107 | { 108 | string = endp + 1; 109 | second = strtol (string, &endp, 10); 110 | /* Note: We don't care about leap seconds. */ 111 | if (!digitp (string) || !digitp (string+1) || second < 0 || second > 59) 112 | return INVALID_TIME; 113 | } 114 | 115 | if (!*endp) 116 | string = endp; 117 | else if (ascii_isspace (*endp)) 118 | string = endp + 1; 119 | else 120 | return INVALID_TIME; 121 | 122 | if (r_endp) 123 | *r_endp = (char *)string; 124 | 125 | return (weekday * 24 * 60 * 6 126 | + hour * 60 * 6 127 | + minute * 6 128 | + second / 10); 129 | } 130 | 131 | 132 | 133 | char * 134 | ebustime_to_timestr (uint16_t ebustime) 135 | { 136 | unsigned int day, hour, min, sec; 137 | char *result; 138 | 139 | if (ebustime == INVALID_TIME) 140 | { 141 | if (asprintf (&result, "[invalid time]") == -1) 142 | result = NULL; 143 | } 144 | else 145 | { 146 | day = (ebustime/6/60/24); 147 | hour= (ebustime/6/60 % 24); 148 | min = (ebustime/6 % 60); 149 | sec = (ebustime % 6) * 10; 150 | 151 | if (asprintf (&result, "%s %u:%02u:%02u", 152 | day == 0? "Mon" : 153 | day == 1? "Tue" : 154 | day == 2? "Wed" : 155 | day == 3? "Thu" : 156 | day == 4? "Fri" : 157 | day == 5? "Sat" : 158 | day == 6? "Sun" : "[?]", 159 | hour, min, sec) == -1) 160 | result = NULL; 161 | } 162 | return result; 163 | } 164 | 165 | -------------------------------------------------------------------------------- /ebus/doorbell.c: -------------------------------------------------------------------------------- 1 | /* doorbell.c - Elektor Bus node to control a a doorbell 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | /* This node is used to control the doorbell and to display the 19 | current time and temperature. A PCF8574 I2C bus expander is used 20 | to drive an ST7036 controlled LCD display in 4 bit mode. */ 21 | 22 | #include "hardware.h" 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | 33 | #include "ebus.h" 34 | #include "proto-busctl.h" 35 | #include "proto-h61.h" 36 | 37 | 38 | /* This code is called by the 1ms ticker interrupt service routine 39 | with the current clock value given in milliseconds from 0..9999. */ 40 | void 41 | ticker_bottom (unsigned int clock) 42 | { 43 | /* Every 10 seconds send out a temperature reading. */ 44 | if (!clock) 45 | { 46 | wakeup_main = 1; 47 | } 48 | } 49 | 50 | 51 | /* A new message has been received and we must now parse the message 52 | quickly and see what to do. We need to return as soon as possible, 53 | so that the caller may re-enable the receiver. */ 54 | static void 55 | process_ebus_h61 (byte *msg) 56 | { 57 | char is_response = !!(msg[5] & P_H61_RESPMASK); 58 | 59 | if (!(msg[1] == config.nodeid_hi || msg[2] == config.nodeid_lo)) 60 | return; /* Not addressed to us. */ 61 | 62 | switch ((msg[5] & ~P_H61_RESPMASK)) 63 | { 64 | default: 65 | break; 66 | } 67 | } 68 | 69 | 70 | /* Process busctl messages. */ 71 | static void 72 | process_ebus_busctl (byte *msg) 73 | { 74 | uint16_t val16; 75 | byte val8; 76 | char is_response = !!(msg[5] & P_BUSCTL_RESPMASK); 77 | 78 | if (is_response) 79 | return; /* Nothing to do. */ 80 | else if (msg[3] == 0xff || msg[4] == 0xff || msg[4] == 0) 81 | return ; /* Bad sender address. */ 82 | else if (msg[1] == config.nodeid_hi && msg[2] == config.nodeid_lo) 83 | ; /* Directed to us. */ 84 | else if ((msg[1] == config.nodeid_hi || msg[1] == 0xff) && msg[2] == 0xff) 85 | ; /* Broadcast. */ 86 | else 87 | return; /* Not addressed to us. */ 88 | 89 | switch ((msg[5] & ~P_BUSCTL_RESPMASK)) 90 | { 91 | case P_BUSCTL_TIME: 92 | /* Fixme: Implement */ 93 | break; 94 | 95 | case P_BUSCTL_QRY_TIME: 96 | msg[1] = msg[3]; 97 | msg[2] = msg[4]; 98 | msg[3] = config.nodeid_hi; 99 | msg[4] = config.nodeid_lo; 100 | msg[5] |= P_BUSCTL_RESPMASK; 101 | msg[6] = 0; 102 | val16 = get_current_fulltime (&val8); 103 | msg[7] = val16 >> 8; 104 | msg[8] = val16; 105 | msg[9] = val8; 106 | memset (msg+10, 0, 6); 107 | csma_send_message (msg, MSGSIZE); 108 | break; 109 | 110 | default: 111 | break; 112 | } 113 | } 114 | 115 | 116 | /* 117 | Entry point 118 | */ 119 | int 120 | main (void) 121 | { 122 | byte *msg; 123 | 124 | hardware_setup (NODETYPE_DOORBELL); 125 | 126 | csma_setup (); 127 | onewire_setup (); 128 | i2c_setup (); 129 | lcd_setup (); 130 | 131 | sei (); /* Enable interrupts. */ 132 | 133 | lcd_init (); 134 | for (;;) 135 | { 136 | for (;;) 137 | { 138 | if (read_key_s2 ()) 139 | lcd_backlight (1); 140 | else if (read_key_s3 ()) 141 | lcd_backlight (0); 142 | lcd_home (); 143 | lcd_putc ('a'); 144 | LED_Collision |= _BV(LED_Collision_BIT); 145 | _delay_ms (100); 146 | LED_Collision &= ~_BV(LED_Collision_BIT); 147 | _delay_ms (100); 148 | lcd_puts_P ("Hello World!"); 149 | LED_Collision |= _BV(LED_Collision_BIT); 150 | _delay_ms (100); 151 | LED_Collision &= ~_BV(LED_Collision_BIT); 152 | } 153 | 154 | set_sleep_mode (SLEEP_MODE_IDLE); 155 | while (!wakeup_main) 156 | { 157 | cli(); 158 | if (!wakeup_main) 159 | { 160 | sleep_enable (); 161 | sei (); 162 | sleep_cpu (); 163 | sleep_disable (); 164 | } 165 | sei (); 166 | } 167 | wakeup_main = 0; 168 | 169 | msg = csma_get_message (); 170 | if (msg) 171 | { 172 | /* Process the message. */ 173 | switch (msg[0]) 174 | { 175 | case PROTOCOL_EBUS_BUSCTL: 176 | process_ebus_busctl (msg); 177 | break; 178 | case PROTOCOL_EBUS_H61: 179 | process_ebus_h61 (msg); 180 | break; 181 | default: 182 | /* Ignore all other protocols. */ 183 | break; 184 | } 185 | /* Re-enable the receiver. */ 186 | csma_message_done (); 187 | } 188 | 189 | } 190 | 191 | } 192 | -------------------------------------------------------------------------------- /zb32.c: -------------------------------------------------------------------------------- 1 | /* zb32.c - z-base-32 encoder 2 | * Copyright (C) 2014, 2015 Werner Koch 3 | * 4 | * This file is part of GnuPG. 5 | * 6 | * This file is free software; you can redistribute it and/or modify 7 | * it under the terms the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 3 of the 9 | * License, or (at your option) any later version. 10 | * 11 | * This file is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, see . 18 | */ 19 | 20 | /* The code is based on GnuPG's common/zb32.c */ 21 | 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define PGM "zb32" 29 | 30 | 31 | /* Zooko's base32 variant. See RFC-6189 and 32 | http://philzimmermann.com/docs/human-oriented-base-32-encoding.txt 33 | Caller must xfree the returned string. Returns NULL and sets ERRNO 34 | on error. To avoid integer overflow DATALEN is limited to 2^16 35 | bytes. Note, that DATABITS is measured in bits!. */ 36 | static char * 37 | zb32_encode (const void *data, unsigned int databits) 38 | { 39 | static char const zb32asc[32] = {'y','b','n','d','r','f','g','8', 40 | 'e','j','k','m','c','p','q','x', 41 | 'o','t','1','u','w','i','s','z', 42 | 'a','3','4','5','h','7','6','9' }; 43 | const unsigned char *s; 44 | char *output, *d; 45 | size_t datalen; 46 | 47 | datalen = (databits + 7) / 8; 48 | if (datalen > (1 << 16)) 49 | { 50 | errno = EINVAL; 51 | return NULL; 52 | } 53 | 54 | d = output = malloc (8 * (datalen / 5) 55 | + 2 * (datalen % 5) 56 | - ((datalen%5)>2) 57 | + 1); 58 | if (!output) 59 | return NULL; 60 | 61 | /* I use straightforward code. The compiler should be able to do a 62 | better job on optimization than me and it is easier to read. */ 63 | for (s = data; datalen >= 5; s += 5, datalen -= 5) 64 | { 65 | *d++ = zb32asc[((s[0] ) >> 3) ]; 66 | *d++ = zb32asc[((s[0] & 7) << 2) | (s[1] >> 6) ]; 67 | *d++ = zb32asc[((s[1] & 63) >> 1) ]; 68 | *d++ = zb32asc[((s[1] & 1) << 4) | (s[2] >> 4) ]; 69 | *d++ = zb32asc[((s[2] & 15) << 1) | (s[3] >> 7) ]; 70 | *d++ = zb32asc[((s[3] & 127) >> 2) ]; 71 | *d++ = zb32asc[((s[3] & 3) << 3) | (s[4] >> 5) ]; 72 | *d++ = zb32asc[((s[4] & 31) ) ]; 73 | } 74 | 75 | switch (datalen) 76 | { 77 | case 4: 78 | *d++ = zb32asc[((s[0] ) >> 3) ]; 79 | *d++ = zb32asc[((s[0] & 7) << 2) | (s[1] >> 6) ]; 80 | *d++ = zb32asc[((s[1] & 63) >> 1) ]; 81 | *d++ = zb32asc[((s[1] & 1) << 4) | (s[2] >> 4) ]; 82 | *d++ = zb32asc[((s[2] & 15) << 1) | (s[3] >> 7) ]; 83 | *d++ = zb32asc[((s[3] & 127) >> 2) ]; 84 | *d++ = zb32asc[((s[3] & 3) << 3) ]; 85 | break; 86 | case 3: 87 | *d++ = zb32asc[((s[0] ) >> 3) ]; 88 | *d++ = zb32asc[((s[0] & 7) << 2) | (s[1] >> 6) ]; 89 | *d++ = zb32asc[((s[1] & 63) >> 1) ]; 90 | *d++ = zb32asc[((s[1] & 1) << 4) | (s[2] >> 4) ]; 91 | *d++ = zb32asc[((s[2] & 15) << 1) ]; 92 | break; 93 | case 2: 94 | *d++ = zb32asc[((s[0] ) >> 3) ]; 95 | *d++ = zb32asc[((s[0] & 7) << 2) | (s[1] >> 6) ]; 96 | *d++ = zb32asc[((s[1] & 63) >> 1) ]; 97 | *d++ = zb32asc[((s[1] & 1) << 4) ]; 98 | break; 99 | case 1: 100 | *d++ = zb32asc[((s[0] ) >> 3) ]; 101 | *d++ = zb32asc[((s[0] & 7) << 2) ]; 102 | break; 103 | default: 104 | break; 105 | } 106 | *d = 0; 107 | 108 | /* Need to strip some bytes if not a multiple of 40. */ 109 | output[(databits + 5 - 1) / 5] = 0; 110 | return output; 111 | } 112 | 113 | 114 | 115 | 116 | int 117 | main (int argc, char **argv ) 118 | { 119 | int c, i; 120 | char buffer[500]; /* Needs to be a multiple of 5! */ 121 | char *output; 122 | 123 | if ( argc > 1 ) 124 | { 125 | fprintf (stderr, "usage: " PGM " < input\n"); 126 | return 1; 127 | } 128 | 129 | i = 0; 130 | while ((c = getchar ()) != EOF) 131 | { 132 | buffer[i++] = c; 133 | if (i == sizeof buffer) 134 | { 135 | output = zb32_encode (buffer, 8 * sizeof buffer); 136 | if (!output) 137 | { 138 | fprintf (stderr, PGM ": error converting data: %s\n", 139 | strerror (errno)); 140 | return 1; 141 | } 142 | fputs (output, stdout); 143 | free (output); 144 | i = 0; 145 | } 146 | } 147 | if (ferror (stdin)) 148 | { 149 | fprintf (stderr, PGM ": read error: %s\n", strerror (errno)); 150 | return 1; 151 | } 152 | 153 | if (i) 154 | { 155 | output = zb32_encode (buffer, 8 * i - 2); 156 | if (!output) 157 | { 158 | fprintf (stderr, PGM ": error converting data: %s\n", 159 | strerror (errno)); 160 | return 1; 161 | } 162 | fputs (output, stdout); 163 | } 164 | 165 | putchar ('\n'); 166 | 167 | if (fflush (stdout) || ferror (stdout)) 168 | { 169 | fprintf (stderr, PGM ": write error: %s\n", strerror (errno)); 170 | return 1; 171 | } 172 | 173 | return 0; 174 | } 175 | -------------------------------------------------------------------------------- /8bit-in-header.c: -------------------------------------------------------------------------------- 1 | /* 8bit-in-header.c 2 | * A tool to check for non ASCII characters in RFC822 messages header. 3 | * Copyright (C) 2000 Werner Koch 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 18 | * 19 | * 20 | * 2000-01-06 wk 21 | * Written as an attempt to get rid of strange chinese mails 22 | * 23 | */ 24 | 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #define PGMNAME "8bit-in-header" 32 | 33 | /* bail out after more than BAD_LIMIT 8/bit chars in one logical line 34 | * We allow for a few bad characters due to transmission errors or 35 | * something like this when option -s is used. 36 | */ 37 | #define BAD_LIMIT 3 38 | 39 | #define MAX_NAMES 200 40 | 41 | static int silent; 42 | static int sloppy; 43 | 44 | static void 45 | usage(void) 46 | { 47 | fputs("usage: " PGMNAME " [-q] [-s] [--] [headernames]\n" 48 | "\n" 49 | " -q be silent\n" 50 | " -s sloppy match: accept up to 2 non ascii characters\n" 51 | , stderr ); 52 | exit(2); 53 | } 54 | 55 | static int 56 | name_cmp( const char *a, const char *b ) 57 | { 58 | for( ; *a && *b; a++, b++ ) { 59 | if( *a != *b 60 | && toupper(*(unsigned char *)a) != toupper(*(unsigned char *)b) ) 61 | return 1; 62 | } 63 | return *a != *b; 64 | } 65 | 66 | static int 67 | headerp( char *p, char **names ) 68 | { 69 | int i, c; 70 | char *p2; 71 | 72 | p2 = strchr(p, ':'); 73 | if( !p2 || p == p2 ) { 74 | if( !silent ) 75 | fputs( "header line without colon or name\n", stdout ); 76 | exit(1); 77 | } 78 | if( p2[-1] == ' ' || p2[-1] == '\t' ) { 79 | if( !silent ) 80 | fputs( "invalid header field\n", stdout ); 81 | exit(1); 82 | } 83 | 84 | if( !names[0] ) 85 | return 1; /* check all fields */ 86 | c = *p2; 87 | *p2 = 0; 88 | for(i=0 ; names[i]; i++ ) { 89 | if( !name_cmp( names[i], p ) ) 90 | break; 91 | } 92 | *p2 = c; 93 | return !!names[i]; 94 | } 95 | 96 | 97 | static int 98 | count_bad( const char *s ) 99 | { 100 | int bad=0; 101 | 102 | for(; *s; s++ ) { 103 | if( *s & 0x80 ) 104 | bad++; 105 | } 106 | return bad; 107 | } 108 | 109 | int 110 | main( int argc, char **argv ) 111 | { 112 | int skip = 0; 113 | char *names[MAX_NAMES+1]; 114 | int thisone, bad, i; 115 | char line[2000]; 116 | 117 | if( argc < 1) 118 | usage(); /* Hey, read how to uses exec*(2) */ 119 | argv++; argc--; 120 | 121 | for( i=0; argc; argc--, argv++ ) { 122 | const char *s = *argv; 123 | if( !skip && *s == '-' ) { 124 | s++; 125 | if( *s == '-' && !s[1] ) { 126 | skip = 1; 127 | continue; 128 | } 129 | if( *s == '-' || !*s ) { 130 | usage(); 131 | } 132 | while( *s ) { 133 | if( *s=='q' ) { 134 | silent=1; 135 | s++; 136 | } 137 | else if( *s=='s' ) { 138 | sloppy=1; 139 | s++; 140 | } 141 | else if( *s ) 142 | usage(); 143 | } 144 | continue; 145 | } 146 | if( i >= MAX_NAMES ) { 147 | fputs(PGMNAME ": too many names given\n", stderr ); 148 | exit(2); 149 | } 150 | names[i++] = *argv; 151 | } 152 | names[i] = NULL; 153 | 154 | 155 | /* now get the lines */ 156 | bad = thisone = 0; 157 | while( fgets( line, sizeof line, stdin ) ) { 158 | int n = strlen(line); 159 | if( !n || line[n-1] != '\n' ) { 160 | /* n == 0 should never happen */ 161 | if( !silent ) 162 | fputs( "line too long - see RFC822\n", stdout ); 163 | exit(1); /* maybe someone wants to circument this */ 164 | } 165 | line[--n] = 0; 166 | if( n && line[n-1] == '\r' ) 167 | line[--n] = 0; 168 | if( !n ) { 169 | exit(0); /* Here is the body - stop */ 170 | } 171 | if( *line == ' ' || *line == '\t' ) { 172 | /* we don't care when the first line is an invalid cont.-line */ 173 | if( thisone ) 174 | bad += count_bad( line ); 175 | } 176 | else if( headerp( line, names ) ) { 177 | thisone = 1; 178 | bad = count_bad( line ); 179 | } 180 | else { 181 | thisone = 0; 182 | bad = 0; 183 | } 184 | if( (bad && !sloppy) || bad >= BAD_LIMIT ) { 185 | if( !silent ) { 186 | if( sloppy ) 187 | fputs( "too many 8-bit characters in a header\n", stdout ); 188 | else 189 | fputs( "8-bit character in a header\n", stdout ); 190 | } 191 | exit(1); 192 | } 193 | } 194 | if( ferror(stdin) ) { 195 | fputs( PGMNAME ": read error\n", stderr ); 196 | exit(1); 197 | } 198 | return 0; 199 | } 200 | 201 | /* 202 | Local Variables: 203 | compile-command: "gcc -Wall -g -o 8bit-in-header 8bit-in-header.c" 204 | End: 205 | */ 206 | -------------------------------------------------------------------------------- /ebus/i2c.c: -------------------------------------------------------------------------------- 1 | /* i2c.c - I2C implementation for AVR 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | /* 19 | Note that Atmel's term for I2C is TWI which stands for Two-Wire 20 | interface. 21 | */ 22 | 23 | #include "hardware.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #include "ebus.h" 34 | 35 | /* Send the START condition. Returns 0 on success. */ 36 | static byte 37 | send_start (void) 38 | { 39 | retry: 40 | /* Clear the interrupt flag, set send_staart and enable TWI operation. */ 41 | TWCR = _BV (TWINT) | _BV (TWSTA) | _BV (TWEN); 42 | /* Wait for completion. */ 43 | while (!(TWCR & _BV (TWINT))) 44 | ; 45 | /* Check the status value. */ 46 | switch (TWSR & 0xF8) 47 | { 48 | case 0x08: /* Start condition has been transmitted. */ 49 | case 0x10: /* Re-start condition has been transmitted. */ 50 | break; 51 | case 0x38: /* Arbitration lost. */ 52 | goto retry; 53 | default: /* Error or unexpected status code. */ 54 | return 1; 55 | } 56 | return 0; 57 | } 58 | 59 | 60 | /* Send the STOP condition. */ 61 | static void 62 | send_stop (void) 63 | { 64 | /* Clear the interrupt flag, set send_stop and enable TWI operation. */ 65 | TWCR = _BV (TWINT) | _BV (TWSTO) | _BV (TWEN); 66 | /* The MCU won't set TWINT after after sending the stop; thus we may 67 | not wait for it. */ 68 | } 69 | 70 | 71 | /* Send the slave ADDRESS. Returns 0 on success, 1 on general error, 72 | 2 to request a restart. */ 73 | static byte 74 | send_sla (byte address) 75 | { 76 | /* Load address into the data register. */ 77 | TWDR = address; 78 | /* Clear the interrupt flag and enable TWI operation. */ 79 | TWCR = _BV (TWINT) | _BV (TWEN); 80 | /* Wait for completion. */ 81 | while (!(TWCR & _BV (TWINT))) 82 | ; 83 | /* Check the status value. */ 84 | switch (TWSR & 0xF8) 85 | { 86 | case 0x18: /* SLA+W has been transmitted. */ 87 | break; 88 | case 0x20: /* NACK received. */ 89 | LED_Collision |= _BV(LED_Collision_BIT); 90 | return 2; 91 | case 0x38: /* Arbitration lost. */ 92 | return 2; 93 | default: /* Unexpected status code. */ 94 | return 1; 95 | } 96 | return 0; 97 | } 98 | 99 | 100 | /* Send a data byte. Returns 0 on success, 1 on general error, 2 on 101 | requesting a restart, 3 on receiving a NACK. */ 102 | static byte 103 | send_data (byte data) 104 | { 105 | /* Load data into the data register. */ 106 | TWDR = data; 107 | /* Clear the interrupt flag and enable TWI operation. */ 108 | TWCR = _BV (TWINT) | _BV (TWEN); 109 | /* Wait for completion. */ 110 | while (!(TWCR & _BV (TWINT))) 111 | ; 112 | /* Check the status value. */ 113 | switch (TWSR & 0xF8) 114 | { 115 | case 0x28: /* Data has been transmitted. */ 116 | break; 117 | case 0x30: /* NACK received. */ 118 | return 3; 119 | case 0x38: /* Arbitration lost. */ 120 | return 2; 121 | default: /* Unexpected status code. */ 122 | return 1; 123 | } 124 | return 0; 125 | } 126 | 127 | 128 | /* Start in master transmitter mode. ADDRESS is the slave address in 129 | the range 0 to 254; the low bit is ignored but should be passed as 130 | zero. Returns 0 on success, 1 on general error, 2 for a bad 131 | address. */ 132 | byte 133 | i2c_start_mt (byte address) 134 | { 135 | /* We need to send an SLA+W; thus clear the LSB. */ 136 | address &= 0xfe; 137 | 138 | if (send_start ()) 139 | { 140 | LED_Transmit |= _BV(LED_Transmit_BIT); 141 | return 1; 142 | } 143 | switch (send_sla (address)) 144 | { 145 | case 0: 146 | break; 147 | case 2: 148 | return 2; /* NACK on SLA - assume bad address. */ 149 | default: 150 | return 1; 151 | } 152 | return 0; 153 | } 154 | 155 | /* Send byte VALUE. Returns 1 if successfully sent; 0 on error. */ 156 | byte 157 | i2c_send_byte (byte value) 158 | { 159 | if (send_data (value)) 160 | return 0; 161 | return 1; 162 | } 163 | 164 | 165 | /* Send DATALEN bytes of DATA. Returns number of bytes successfully 166 | sent. */ 167 | byte 168 | i2c_send_data (byte *data, byte datalen) 169 | { 170 | byte idx; 171 | 172 | for (idx=0; idx < datalen; idx++) 173 | { 174 | if (send_data (data[idx])) 175 | return idx; 176 | } 177 | return idx; 178 | } 179 | 180 | 181 | 182 | void 183 | i2c_stop (void) 184 | { 185 | send_stop (); 186 | } 187 | 188 | 189 | 190 | /* Initialize the I2C code. This must be done after the 191 | initialization of the general hardware code. Note that using I2C 192 | switches port C pins 4 and 5 to their alternate functions: PC5 is 193 | SCL and PC4 is SCD. */ 194 | void 195 | i2c_setup (void) 196 | { 197 | /* We use external pull-ups thus disable the internal pull-ups. */ 198 | PORTC &= ~(_BV(4) | _BV(5)); 199 | 200 | /* Set the clock close to 100kHz: 201 | F_scl = F_cpu / (16 + 2 * TWBR * Prescaler) 202 | | F_cpu | pre | TWBR | F_scl | 203 | |----------+-----+------+-------| 204 | | 16000000 | 1 | 73 | 98765 | 205 | #+TBLFM: $4=$1 / (16 + (2 * $3 * $2));%.0f 206 | 207 | Note that the prescaler is controlled by bits 1 and 0 of the 208 | TWSR; bits 7 to 3 make up the TWI status register. */ 209 | #if F_CPU != 16000000ul 210 | # error Please adjust the bit rate register. 211 | #endif 212 | TWSR = 0; /* Prescaler to 1. */ 213 | TWBR = 73; /* Bit rate register to 73. */ 214 | 215 | } 216 | -------------------------------------------------------------------------------- /sks-stats.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | 4 | # Example driver: 5 | ##!/bin/sh 6 | # 7 | #hostsfile="$HOME/bin/hosts.sks" 8 | #outfile="/var/www/217.69.76.60/keystats.gnupg.net/htdocs/index.html" 9 | #failedfile="/var/www/217.69.76.60/keystats.gnupg.net/htdocs/failed-hosts" 10 | # 11 | #rm "$failedfile.now" 2>/dev/null || true 12 | #$HOME/bin/sks-stats.sh --failed "$failedfile" --hosts "$hostsfile" >"$outfile".tmp 2>/dev/null 13 | #mv "$outfile".tmp "$outfile" 14 | #if [ -f "$failedfile.now" ]; then 15 | # rm "$failedfile.now" 2>/dev/null 16 | # ( echo "List of failed hosts:" 17 | # cat "$failedfile" ) | mail -s "keys.gnupg.net status change detected" keystats-gnupg-net@gnupg.org 18 | #fi 19 | # 20 | 21 | 22 | function get_stats () { 23 | local host 24 | local port 25 | 26 | hostip="$1" 27 | host="" 28 | port="$2" 29 | 30 | if [ -n "$hostsfile" -a -f "$hostsfile" ]; then 31 | host=$(grep "^$hostip" "$hostsfile" | awk '{print $2; exit}') 32 | fi 33 | if [ -z "$host" ]; then 34 | host="$hostip" 35 | fi 36 | echo "retrieving $host:$port using $hostip" >&2 37 | 38 | echo "Server $hostip $port" 39 | # Note that versions of wget < 1.10 can't override 'Host:'. 40 | (wget -qO - -T 30 -t 3 --no-cache --header "Host: $host:$port" \ 41 | "http://$hostip:$port/pks/lookup?op=stats" || echo) |\ 42 | awk -v failed="${failed_hosts_file}" -v hostip="$hostip" -v hostn="$host" ' 43 | /<\/table>/ {in_settings = 0; in_peers = 0; in_daily = 0} 44 | /

Settings<\/h2>/ {in_settings = 1 } 45 | /

Gossip Peers<\/h2>/ {in_peers = 1 } 46 | /

Statistics<\/h2>/ {in_stats = 1 } 47 | 48 | in_settings && /Hostname:/ {split($0, a, /:/); host=a[2] } 49 | in_settings && /Version:/ {split($0, a, /:/); version=a[2] } 50 | 51 | in_peers && // {split($0, a , /[ \t\n]+|/); 52 | peers[in_peers]=a[2]; in_peers++; } 53 | 54 | !in_stats {next} 55 | 56 | /

Daily Histogram<\/h3>/ {in_daily = 1 } 57 | 58 | !nkeys && /

Total number of keys:/ { split($0, a, /Total number of keys:/); 59 | split(a[2], aa, /2/ { split($0, a, //); daily[a[2]] = a[3] " " a[4]; } 62 | 63 | END { 64 | if ( host ) { 65 | print "Host " host 66 | print "Version " version 67 | print "Total " nkeys 68 | for ( i in peers ) print "Peer " peers[i]; 69 | for ( i in daily ) { print "Daily " i " " daily[i] } 70 | } else { 71 | print hostip " " hostn >> failed 72 | } 73 | } 74 | ' 75 | echo "Timestamp $(date -u '+%F %T')" 76 | } 77 | 78 | 79 | function print_header2 () { 80 | echo "$1" 81 | echo ' 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | ' 92 | } 93 | 94 | function print_header () { 95 | echo ' 96 | 97 | 98 | Keyserver statistics for gnupg.net 99 | 100 | 101 | 102 |

Keyserver statistics for gnupg.net

103 |

104 | This table shows statistics for the keyservers in the 105 | keys.gnupg.net and http-keys.gnupg.net pools. 106 |

107 | 108 | ' 109 | } 110 | 111 | 112 | function print_footer2 () { 113 | echo ' 114 |
HostTotal keysVersionIP:PortLast check (UTC)
' 115 | } 116 | 117 | 118 | function print_footer () { 119 | print_footer2 120 | 121 | echo '





122 |
123 | Notifications on status changes are automatically posted to the 124 | keystats-gnupg-net mailing list. You are welcome to subscribe 126 | to this announce-only list. 127 |
128 | 129 | ' 130 | } 131 | 132 | 133 | function make_row () { 134 | awk -v scheme=$1 ' 135 | $1 == "Server" { server = $2; port = $3} 136 | $1 == "Host" { host = $2 } 137 | $1 == "Total" { nkeys = $2 } 138 | $1 == "Version" { version = $2 } 139 | $1 == "Timestamp" { timestamp = $2 " " $3 } 140 | 141 | END { if (host) { 142 | href = "" 143 | tmp = "" href scheme "://" host "" \ 144 | "" nkeys \ 145 | "" version "" ; 146 | } else { 147 | tmp = "   " ; 148 | } 149 | print tmp "" server ":" port "" timestamp "" 150 | } 151 | ' 152 | } 153 | 154 | 155 | 156 | 157 | host="" 158 | failed_hosts=no 159 | if [ "$1" == "--failed" ]; then 160 | failed_hosts=yes 161 | failed_hosts_file_orig="$2" 162 | if [ -z "$failed_hosts_file_orig" ]; then 163 | echo "usage: sks-stats.sh --failed FILENAME" >&2 164 | exit 1 165 | fi 166 | shift 167 | shift 168 | failed_hosts_file="${failed_hosts_file_orig}.tmp" 169 | : >> "${failed_hosts_file_orig}" 170 | : > "${failed_hosts_file}" 171 | else 172 | failed_hosts_file="/dev/null" 173 | fi 174 | if [ "$1" == "--hosts" ]; then 175 | hostsfile="$2" 176 | shift 177 | shift 178 | else 179 | hostsfile="" 180 | fi 181 | [ -n "$1" ] && host="$1" 182 | 183 | 184 | if [ -z "$host" ]; then 185 | print_header 186 | print_header2 "

keys.gnupg.net

" 187 | ( 188 | host keys.gnupg.net | awk '/has address/ { print $4 }' \ 189 | | while read host; do 190 | get_stats $host 11371 | make_row "hkp" 191 | done 192 | ) | sort 193 | print_footer2 194 | print_header2 "

http-keys.gnupg.net

" 195 | ( 196 | host http-keys.gnupg.net | awk '/has address/ { print $4 }' \ 197 | | while read host; do 198 | get_stats $host 80 | make_row "http" 199 | done 200 | ) | sort 201 | else 202 | print_header 203 | get_stats $host 11371 | make_row "hkp" 204 | fi 205 | print_footer 206 | if [ $failed_hosts = "yes" ]; then 207 | if cmp "${failed_hosts_file_orig}" "${failed_hosts_file}" >/dev/null ; then 208 | rm "${failed_hosts_file}" 209 | else 210 | echo "changes in failed hosts detected" >&2 211 | mv "${failed_hosts_file}" "${failed_hosts_file_orig}" 212 | : > "${failed_hosts_file_orig}.now" 213 | fi 214 | fi 215 | -------------------------------------------------------------------------------- /gpgmlrobot: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # gpgmlrobot - GnuPG Mailing List Robot 3 | # Copyright (c) 1999 Werner Koch 4 | # This program may be used under the terms of the GNU General Public Licence 5 | # version 2 or later. 6 | # 7 | # 8 | # The format of the dists file is like this: 9 | #------------------------------------------------------- 10 | # CF8BCC4B18DE08FCD8A1615906AD222CADF6A6E1 wk@gnupg.de 11 | # 4444444444444444444444444444444444444444 foo@bar.net 12 | #--------------------------------------------------------- 13 | # 14 | # Each mailing list should have its own directory and an 15 | # entry like this in the .procmailrc: 16 | #----------------------------------------- 17 | # :0 18 | # * ^To: .*laurin-list@example\.com 19 | # { 20 | # :0: 21 | # * ^X-Loop: failed-laurin-list@example\.com 22 | # /dev/null 23 | # 24 | # :0: 25 | # | $HOME/laurin-list/gpgmlrobot 26 | # } 27 | #------------------------------------- 28 | # 29 | # You should create one keypair for each mailing list by 30 | # cd-ing to the list directory and doing a: 31 | # gpg --homedir . --gen-key 32 | # and give it the email address of the mailing list, it might 33 | # be a couuld idea to have a comment in the user ID to mark this 34 | # as a key for an encrypted mailing list. Sen this key to all 35 | # subscribers and put there fingerprint 36 | # (gpg --fingerprint --with-colons foo@bar.net) 37 | # into the dists file along with their email address. 38 | # 39 | 40 | #------------------------------------------- 41 | # Configuration section 42 | #------------------------------------------- 43 | 44 | ml_address="laurin-list@example.com" 45 | full_ml_address="Laurin List <$ml_address>" 46 | ml_domain="example.com" 47 | 48 | myhome=/home/cryptorobot/laurin-list 49 | 50 | SENDMAIL="/usr/sbin/sendmail" 51 | distsfile=dists 52 | remove_input=no 53 | ciphertextfile="$1" 54 | passphrasefile=passphrase 55 | plaintextfile="plain.$$" 56 | 57 | 58 | #------------------------------------------- 59 | # End configuration section 60 | #------------------------------------------- 61 | #pgmname=`basename $0` 62 | #today=`date -u "+%Y-%m-%d"` 63 | 64 | if ! cd $myhome 2>/dev/null ; then 65 | echo "gpgmlrobot: failed to cd to $myhome" >&2 66 | exit 1 67 | fi 68 | 69 | if [ -z "$ciphertextfile" -o "$ciphertextfile" = "-" ]; then 70 | ciphertextfile="input.$$" 71 | cat > $ciphertextfile 72 | remove_input=yes 73 | fi 74 | 75 | if [ ! -f "$ciphertextfile" ]; then 76 | echo "usage: gpgmlrobot encrypted-mail-file" >&2 77 | do_exit 1 78 | fi 79 | 80 | cleanup () { 81 | [ -f $plaintextfile ] && rm $plaintextfile 82 | [ -f $ciphertextfile -a "$remove_input" = "yes" ] && rm $ciphertextfile 83 | } 84 | 85 | do_exit () { 86 | cleanup 87 | exit $1 88 | } 89 | 90 | 91 | trap "cleanup " 1 2 13 15 92 | 93 | do_send () { 94 | key="$1" 95 | recp="$2" 96 | ( cat < $plaintextfile 164 | chmod 600 $plaintextfile 165 | 166 | cat $passphrasefile | gpg --homedir . --quiet --no-secmem-warning \ 167 | --passphrase-fd 0 --decrypt --batch --always-trust \ 168 | -o - $ciphertextfile >> $plaintextfile 169 | if [ $? != 0 ] ; then 170 | ( formail -t -i"X-Loop: failed-$ml_address" < $ciphertextfile 171 | echo "Hi," 172 | echo "" 173 | echo "Your mail could not been processed by this robot" 174 | echo 'probably because you did not encrypt it to the' 175 | echo "robot's key" 176 | echo "" 177 | echo "Hochachtungsvoll," 178 | echo "" 179 | echo " G. M. Robot" 180 | echo "" 181 | echo "-- " 182 | echo "Powered by the GNU Privacy Guard" 183 | ) | $SENDMAIL -oi -t 184 | exit 0 185 | fi 186 | 187 | if head -1 $plaintextfile | grep '^Content-Type: text/plain' >/dev/null; then 188 | orig_is_mime=yes 189 | else 190 | orig_is_mime=no 191 | fi 192 | 193 | orig_date="$(formail -x Date: < $ciphertextfile)" 194 | orig_subject="$(formail -x Subject: < $ciphertextfile)" 195 | # We munch the message id to hide the posters informations 196 | # This is not really need, because we use the orignal from line, 197 | # but this can be changed when needed. 198 | orig_msg_id="$(formail -x Message-ID < $ciphertextfile|md5sum)" 199 | orig_msg_id="<${orig_msg_id}@${ml_domain}>" 200 | orig_from="$(formail -x From: < $ciphertextfile)" 201 | 202 | cat $distsfile | while read ; do 203 | set -- $REPLY 204 | if [ -n "$1" -a -n "$2" ]; then 205 | do_send $1 $2 206 | fi 207 | done 208 | 209 | cleanup 210 | 211 | -------------------------------------------------------------------------------- /ebus/i2c-lcd.c: -------------------------------------------------------------------------------- 1 | /* i2c-lcd.c - LCD driver for an PCF8574 attached LCD 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | /* This mode is used to drive an ST7036 controlled LCD display via a 19 | PCF8574 I2C bus expander. The port assignments are: 20 | 21 | | 8574 | ST7036 | 22 | |------+------------| 23 | | P0 | DB4 (31) | 24 | | P1 | DB5 (30) | 25 | | P2 | DB6 (29) | 26 | | P3 | DB7 (28) | 27 | | P4 | E (36) | 28 | | P5 | RS (39) | 29 | | P6 | !Backlight | 30 | |------+------------| 31 | 32 | The 8574 is wired to I2C address 0x40. The backlight is connected 33 | to an NPN transistor with the base pulled up by an 4k7 resistor and 34 | pulled low by writing a one to P6. 35 | */ 36 | 37 | #include "hardware.h" 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | 47 | #include "ebus.h" 48 | 49 | 50 | /* Display definitions. */ 51 | #define LCD_ADDRESS 0x40 /* Address of the PCF8574. */ 52 | 53 | #define LCD_E_BIT 0x10 54 | #define LCD_RS_BIT 0x20 55 | #define LCD_BACKLIGHT_BIT 0x40 /* Switch backlight off. */ 56 | 57 | 58 | /* The status of the backlight. */ 59 | static byte backlight_off; 60 | 61 | 62 | /* Send a byte to the 8574. */ 63 | static void 64 | _lcd_send_byte (uint8_t value) 65 | { 66 | /* The LCD copies the data on the falling edge of the E pin. Thus 67 | we send the byte with the bit for the E pin set and then again 68 | with the E bit cleared. We don't need to use a delay because the 69 | minumum required E pulse time is 350ns and due to the 100kHz I2C 70 | clock we need 90us to send one byte to the PCF8574.n */ 71 | if (backlight_off) 72 | value |= LCD_BACKLIGHT_BIT; 73 | else 74 | value &= ~LCD_BACKLIGHT_BIT; 75 | i2c_send_byte (value | LCD_E_BIT); 76 | i2c_send_byte (value & ~LCD_E_BIT); 77 | } 78 | 79 | void 80 | lcd_backlight (uint8_t onoff) 81 | { 82 | backlight_off = !onoff; 83 | i2c_start_mt (LCD_ADDRESS); 84 | if (backlight_off) 85 | i2c_send_byte (LCD_BACKLIGHT_BIT); 86 | else 87 | i2c_send_byte (0); 88 | i2c_stop (); 89 | } 90 | 91 | 92 | /* Write high nibble of DATA. */ 93 | static void 94 | _lcd_write_high (uint8_t data, uint8_t write_ctrl) 95 | { 96 | data >>= 4; 97 | if (write_ctrl) 98 | data &= ~LCD_RS_BIT; /* Clear RS. */ 99 | else 100 | data |= LCD_RS_BIT; /* Set RS. */ 101 | _lcd_send_byte (data); 102 | 103 | } 104 | 105 | /* Write low nibble of DATA. */ 106 | static void 107 | _lcd_write_low (uint8_t data, uint8_t write_ctrl) 108 | { 109 | data &= 0x0f; 110 | if (write_ctrl) 111 | data &= ~LCD_RS_BIT; /* Clear RS. */ 112 | else 113 | data |= LCD_RS_BIT; /* Set RS. */ 114 | _lcd_send_byte (data); 115 | } 116 | 117 | 118 | static void 119 | _lcd_write (uint8_t data, uint8_t write_ctrl) 120 | { 121 | _lcd_write_high (data, write_ctrl); 122 | _lcd_write_low (data, write_ctrl); 123 | } 124 | 125 | 126 | /* Write a data byte to the display. */ 127 | void 128 | lcd_putc (uint8_t c) 129 | { 130 | i2c_start_mt (LCD_ADDRESS); 131 | _lcd_write (c, 0); 132 | i2c_stop (); 133 | } 134 | 135 | 136 | /* Clear the display. */ 137 | void 138 | lcd_clear (void) 139 | { 140 | i2c_start_mt (LCD_ADDRESS); 141 | _lcd_write (0x01, 1); 142 | i2c_stop (); 143 | } 144 | 145 | 146 | /* Got to the home position. */ 147 | void 148 | lcd_home (void) 149 | { 150 | i2c_start_mt (LCD_ADDRESS); 151 | _lcd_write (0x02, 1); 152 | i2c_stop (); 153 | } 154 | 155 | 156 | /* Set the next data write position to X,Y. */ 157 | void 158 | lcd_gotoxy (uint8_t x, uint8_t y) 159 | { 160 | i2c_start_mt (LCD_ADDRESS); 161 | _lcd_write (0x80 | ((y? 0x40:0) + x), 1); 162 | i2c_stop (); 163 | } 164 | 165 | 166 | /* uint8_t */ 167 | /* lcd_getc (void) */ 168 | /* { */ 169 | /* _lcd_waitbusy (); */ 170 | /* return _lcd_read (0); */ 171 | /* } */ 172 | 173 | void 174 | lcd_puts (const char *s) 175 | { 176 | uint8_t c; 177 | 178 | i2c_start_mt (LCD_ADDRESS); 179 | while ((c = *s++)) 180 | _lcd_write (c, 0); 181 | i2c_stop (); 182 | } 183 | 184 | 185 | void 186 | _lcd_puts_P (const char *progmem_s) 187 | { 188 | uint8_t c; 189 | 190 | i2c_start_mt (LCD_ADDRESS); 191 | while ((c = pgm_read_byte (progmem_s++))) 192 | _lcd_write (c, 0); 193 | i2c_stop (); 194 | } 195 | 196 | 197 | 198 | /* Initialize the LCD code. This must be run with interrupts enabled. */ 199 | void 200 | lcd_init (void) 201 | { 202 | /* Wait for the internal reset to complete. */ 203 | _delay_ms (40); 204 | 205 | i2c_start_mt (LCD_ADDRESS); 206 | 207 | /* Call Function_set three times with a delay of at least 1.6ms and 208 | 26.4us. Because we need 90us to send the command to the PCF8574 209 | an explicit delay of the latter value is not required. */ 210 | _lcd_write_high (0x30, 1); 211 | _delay_ms (2); 212 | _lcd_write_high (0x30, 1); 213 | _lcd_write_high (0x30, 1); 214 | 215 | LED_Transmit |= _BV(LED_Transmit_BIT); 216 | /* Now call Function_set to select 4 bit mode. */ 217 | _lcd_write_high (0x20, 1); 218 | 219 | /* Do the actual Function_set: 4 bit, 2 lines, table 1. */ 220 | _lcd_write (0x29, 1); 221 | 222 | /* Bias_Set: 1/4, 3 lines. */ 223 | _lcd_write (0x1d, 1); 224 | 225 | /* Power control: icon display off, booster off. */ 226 | _lcd_write (0x50, 1); 227 | 228 | /* Follower control: on, ratio=4 */ 229 | _lcd_write (0x6c, 1); 230 | 231 | /* Set contrast. */ 232 | _lcd_write (0x77, 1); 233 | 234 | /* Switch back to instruction table 0. */ 235 | _lcd_write (0x28, 1); 236 | 237 | /* Display on/off: Display on, cursor on, blinking on. */ 238 | /* (bit 2) (bit 1) (bit 0) */ 239 | _lcd_write (0x0f, 1); 240 | 241 | /* Clear display. */ 242 | _lcd_write (0x01, 1); 243 | 244 | /* Entry mode: auto-increment, shift off. */ 245 | _lcd_write (0x06, 1); 246 | 247 | i2c_stop (); 248 | } 249 | 250 | 251 | /* Initialize the LCD code. This must be done after the 252 | initialization of the general hardware code and expects that the 253 | I2C code has been initialized. Note that lcd_init needs to be run 254 | after this function. */ 255 | void 256 | lcd_setup (void) 257 | { 258 | } 259 | -------------------------------------------------------------------------------- /ebus/proto-h61.h: -------------------------------------------------------------------------------- 1 | /* proto-h61.h - Definition of the H61 protocol. 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | #ifndef PROTO_H61_H 19 | #define PROTO_H61_H 20 | 21 | /* Description of the H/61 protocol. 22 | 23 | This protocol is used for domotik control of a detached house. The 24 | message is similar to the 25 | 26 | byte 0 - protocol PROTOCOL_EBUS_H61 (0x86) 27 | byte 1 - receiver node-id high 28 | byte 2 - receiver node-id low 29 | byte 3 - sender node-id high 30 | byte 4 - sender node-id low 31 | byte 5 - command, see below 32 | byte 6...15 - command dependent 33 | 34 | List of Commands. Bit 7 is the RESPONSE bit and used for 35 | corrsponding response messages. The command itself is given by 36 | bits 6 to 0: 37 | 38 | * 0x10 := Shutter control: 39 | 40 | byte 6 - Subcommand for the shutter control: 41 | 42 | ** 0x00 - Query shutter state 43 | 44 | byte 7..15 - rfu must be 0. 45 | 46 | *** Response message 47 | 48 | byte 7 - error flag (0 for okay). Only set on response from the 49 | drive shutter subcommand. 50 | byte 8 - Shutter 1 state: 51 | bit 7 - Currently driving 52 | bit 6 - Currently pulling up 53 | bit 5 - State in bits 3...0 is valid. 54 | bit 4 - rfu 55 | bit 3..0 - Percentage closed 56 | (0 = open, 31 = 100% closed) 57 | byte 9 - Shutter 2 state 58 | byte 10 - Shutter 3 state 59 | byte 11 - Shutter 4 state 60 | byte 12 - Shutter 5 state 61 | byte 13 - Shutter 6 state 62 | byte 14 - Shutter 7 state 63 | byte 15 - Shutter 8 state 64 | 65 | ** 0x01 - Drive shutter 66 | 67 | byte 7 - Shutter number to drive 68 | (0 = all shutters controlled by node) 69 | byte 8 - Shutter control byte 70 | bit 7 - Drive 71 | bit 6 - Direction is "up". 72 | bit 5 - Drive to percentage given in bits 3..0. 73 | (Bit 6 must be zero.) 74 | bit 4 - rfu 75 | bit 3..0 = Drive to this closed state 76 | (0 = open, 15 = 100% closed) 77 | 78 | Undefined values will do nothing. 79 | byte 9..15 - rfu 80 | 81 | 82 | *** Response message 83 | 84 | The response is the same as the response from the query shutter 85 | state subcommand. If there was an error in the command block the 86 | error flag in the response block will be set. However the 87 | subcommand in the response message is 0x01 and not 0x00. 88 | 89 | ** 0x02 - Query shutter timings 90 | 91 | The time required to pull the drive up or down is stored in the 92 | EEPROM. This command allows to read out the value. 93 | 94 | byte 7 - Shutter number 95 | byte 8..15 - rfu, must be 0. 96 | 97 | *** Response message 98 | 99 | byte 7 - Shutter number 100 | byte 8 - Time for a complete pull up in seconds. 101 | byte 9 - Time for a complete pull down in seconds. 102 | byte 10..15 - rfu 103 | 104 | ** 0x03 - Update shutter timings 105 | 106 | The time required to pull the drive up or down is stored in th 107 | EEPROM. This command allows an easy adjustment. 108 | 109 | byte 7 - Shutter number 110 | byte 8 - Time for a complete pull up in seconds. 111 | byte 9 - Time for a complete pull down in seconds. 112 | byte 10..15 - rfu, must be 0 113 | 114 | *** Response message 115 | 116 | The response message is the same as Query Shutter timings. 117 | 118 | *** 0x04 - Query Shutter Schedule 119 | 120 | byte 7 - Shutter number 121 | 122 | *** Response message 123 | 124 | The device answers with multiple response messages returning all 125 | stored schedules. 126 | 127 | byte 7 - Shutter number 128 | byte 8 - Error flag (only used with ChangeShutterSchedule) 129 | byte 9 - Number of items 130 | byte 10 - Item number 131 | byte 11,12 - Time 132 | byte 13 - New state (cf. Drive Shutter) 133 | byte 14..15 - rfu, must be 0 134 | 135 | ** 0x05 - Update Shutter Schedule 136 | 137 | byte 7 - Shutter number 138 | byte 8 - rfu, must be 0 139 | byte 9 - constant 1. 140 | byte 10 - Item number 141 | byte 11,12 - Time 142 | byte 13 - Action (cf. Drive Shutter) 143 | 144 | byte 14..15 - rfu, must be 0 145 | 146 | After one message old messages are destroyed. On error the device 147 | may or may not use the old values. Using an undefined action may 148 | be used to delete an entry. 149 | 150 | A factory reset of the schedule may be done using these parameters: 151 | Shutter number: 0xf0 152 | Byte 9: 16 153 | Item number: 0xf0 154 | time = 0xf0f0 155 | action = 0xf0 156 | 157 | *** Response message 158 | 159 | There is no response message. It is suggested to use Query Shutter 160 | State to check that the settings are correct. 161 | 162 | * 0x20 := Read sensors 163 | 164 | byte 6 - Sensor type 165 | 166 | ** 0x20, 0x01 Read temperature sensors 167 | 168 | byte 7 - Sensor group to read (0 to read all). 169 | byte 8..15 - reserved (must be 0) 170 | 171 | A sensor group consist of 4 sensors. 172 | 173 | *** Response message 174 | 175 | byte 7 - bit 7..4 := Number of available sensor groups 176 | bit 3..0 := This Sensor group (1 to 15). 177 | byte 8,9 - Sensor 0 178 | byte 10,11 - Sensor 1 179 | byte 12,13 - Sensor 2 180 | byte 14,15 - Sensor 3 181 | 182 | The values of the temperature sensors are signed 16 bit integer 183 | values returning the temperature in decigrades. There are two 184 | special values: 185 | 0x8000 (-32678) := No sensor found 186 | 0x7fff (32767) := Error reading value. 187 | 188 | Note that it may take some time to read the sensor, thus the client 189 | should not expect that the host will answer immediately. 190 | 191 | */ 192 | 193 | #include "protocol.h" 194 | 195 | #define P_H61_RESPMASK 0x80 /* The response mask for the commands. */ 196 | #define P_H61_SHUTTER 0x10 /* ShutterControl. */ 197 | #define P_H61_SENSOR 0x20 /* Read sensor. */ 198 | 199 | 200 | /* Subcommands of P_H61_SHUTTER. */ 201 | #define P_H61_SHUTTER_QUERY 0x00 202 | #define P_H61_SHUTTER_DRIVE 0x01 203 | #define P_H61_SHUTTER_QRY_TIMINGS 0x02 204 | #define P_H61_SHUTTER_UPD_TIMINGS 0x03 205 | #define P_H61_SHUTTER_QRY_SCHEDULE 0x04 206 | #define P_H61_SHUTTER_UPD_SCHEDULE 0x05 207 | 208 | /* Subcommands of P_H61_SENSOR. */ 209 | #define P_H61_SENSOR_TEMPERATURE 0x01 210 | 211 | 212 | 213 | #endif /*PROTO_H61_H*/ 214 | -------------------------------------------------------------------------------- /modulo-d-amp/main.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | Copyright: (c) 2009 Stange-Distribution Simone Stange, Berlin 3 | Contact: info@obd-shop.com 4 | License: GNU GPL v2 (see License.txt) 5 | Author: Frank Nitzsche classd@beta-x.de 6 | File: main.c 7 | Version: 16.02.09 8 | Compiler: AVR-GCC 9 | **************************************************************************/ 10 | 11 | #include 12 | #include "common.h" 13 | #include "main.h" 14 | #include "iic.h" 15 | #include "max9744.h" 16 | #include "tda7449.h" 17 | #include "lcd.h" 18 | #include "rc5.h" 19 | 20 | #define NIX 0 21 | #define VOL 1 22 | #define BASS 2 23 | #define TREB 3 24 | #define GAIN 4 25 | 26 | #define TEXT_URL "www.elektor.com" 27 | #define TEXT_TITLE "ClassD Amplifier" 28 | #define TEXT_VOLUME "Volume" 29 | #define TEXT_GAIN "Gain " 30 | #define TEXT_BASS "Bass " 31 | #define TEXT_TREBLE "Treble" 32 | 33 | static BOOL Flag10ms; //10ms Tick 34 | //static U8 Showtime; //Remaining visualisation time*10ms 35 | // changed to int to go above 2.55s ;-) 36 | static unsigned int Showtime; //Remaining visualisation time*10ms 37 | static U8 RepeatDelay; //Delay*10ms before accepting new RC5 command 38 | 39 | SIGNAL (SIG_OVERFLOW0){ 40 | TCNT0 = -78; //78 Timerticks = 10ms 41 | Flag10ms = TRUE; 42 | } 43 | ////////////////////////////////////////////////////////////////////////// 44 | //10ms Tick 45 | static void Timer0Init(void){ 46 | TCCR0 = 1<Adr == Adr && Rc5->Cmd == Cmd); 53 | } 54 | ////////////////////////////////////////////////////////////////////////// 55 | //Visualise sound setting 56 | static void showSoundValue(U8 Wich){ 57 | if(Wich == NIX) 58 | return; 59 | Showtime = 150; 60 | S8 Val; 61 | 62 | #if LCD_LINES == 3 63 | lcd_gotoxy(0,2); 64 | lcd_puts_P(TEXT_URL); 65 | #endif 66 | 67 | lcd_gotoxy(0,1); 68 | 69 | if(Wich == VOL){ 70 | Val = max9744getVolPercent(); 71 | lcd_puts_P(TEXT_VOLUME); 72 | lcdBar(Val,0,0,16,TRUE); 73 | } 74 | else if(Wich == GAIN){ 75 | RepeatDelay = 15; 76 | Val = TDA7449getGain(); 77 | Val = Val*3 + 1+DIV3(Val); //same like Val*3.3 - but avoids float 78 | lcd_puts_P(TEXT_GAIN); 79 | lcdBar(Val,0,0,16,TRUE); 80 | } 81 | else{ 82 | RepeatDelay = 25; 83 | if(Wich == BASS){ 84 | Val = TDA7449getBass() * 7; //14dB * 7 ~ 100% 85 | lcd_puts_P(TEXT_BASS); 86 | } 87 | if(Wich == TREB){ 88 | Val = TDA7449getTreble() * 7; 89 | lcd_puts_P(TEXT_TREBLE); 90 | } 91 | if(Val < 0){ 92 | lcdBar(Val,0,0,8,FALSE); 93 | lcdBar( 0,8,0,8,TRUE); 94 | } 95 | else{ 96 | lcdBar( 0,0,0,8,FALSE); 97 | lcdBar(Val,8,0,8,TRUE); 98 | } 99 | } 100 | } 101 | ////////////////////////////////////////////////////////////////////////// 102 | void 103 | display_standby_text (void) 104 | { 105 | #if LCD_LINES == 3 106 | U8 n[4] = {'\0', '\0', '\0', '\0'}; 107 | S8 Val; 108 | U8 i, q, r; 109 | #endif 110 | lcd_puts_P(TEXT_TITLE); 111 | #if LCD_LINES == 3 112 | lcd_gotoxy(0,2); 113 | lcd_puts_P(TEXT_VOLUME": "); 114 | // q&d way to display the volume 115 | Val = max9744getVolPercent(); 116 | q = Val; 117 | i = 0; 118 | while (q >= 10) { 119 | q = q / 10; 120 | i++; 121 | } 122 | q = Val; 123 | while (q >= 10) { 124 | r = q % 10; 125 | q = q / 10; 126 | n[i] = '0' + r; 127 | i--; 128 | } 129 | n[i] = '0' + q; 130 | lcd_puts((char *)n); 131 | lcd_puts("% "); 132 | #endif 133 | } 134 | ////////////////////////////////////////////////////////////////////////// 135 | int 136 | main (void) 137 | { 138 | RC5_t Rc5; 139 | U8 ShowWichValue = NIX; 140 | init_iic(100); 141 | TDA7449init(); 142 | max9744init(MAX9744_FILTERLESS); 143 | Timer0Init(); 144 | 145 | //Backlight 146 | DDRB |= 1<<2; 147 | PORTB|= 1<<2; 148 | 149 | max9744setVol(22); 150 | 151 | lcd_init(LCD_DISP_ON); 152 | initRc5(); 153 | 154 | sei(); 155 | 156 | // splash screen with URL, only displayed the first time and for 5s 157 | Showtime = 500; 158 | lcd_puts_P(TEXT_TITLE); 159 | #if LCD_LINES == 3 160 | lcd_gotoxy(0,2); 161 | lcd_puts_P(TEXT_URL); 162 | #endif 163 | goto AGAIN2; 164 | 165 | AGAIN: 166 | 167 | // standby display with volume value 168 | display_standby_text(); 169 | 170 | AGAIN2: 171 | 172 | for(;;){ 173 | 174 | if(getRc5(&Rc5)){ 175 | 176 | 177 | ////////////////////////////////////////////////////////////////////////// 178 | //Uncomment for displaying RC5 data 179 | /* 180 | CHAR Txt[17]; 181 | lcd_gotoxy(0,0); 182 | lcd_puts("Adr: "); 183 | lcd_gotoxy(4,0); 184 | itoa(Rc5.Adr,Txt,10); 185 | lcd_puts(Txt); 186 | 187 | lcd_puts(" Cmd:"); 188 | itoa(Rc5.Cmd,Txt,10); 189 | lcd_puts(Txt); 190 | */ 191 | ////////////////////////////////////////////////////////////////////////// 192 | 193 | 194 | if(isKey(&Rc5, VOL_P)){ 195 | max9744setVol(max9744getVol()+1); 196 | ShowWichValue = VOL; 197 | } 198 | else if(isKey(&Rc5, VOL_M)){ 199 | max9744setVol(max9744getVol()-1); 200 | ShowWichValue = VOL; 201 | } 202 | else if(isKey(&Rc5, BASS_P) && RepeatDelay == 0){ 203 | TDA7449setBass(TDA7449getBass()+2); 204 | ShowWichValue = BASS; 205 | } 206 | else if(isKey(&Rc5, BASS_M) && RepeatDelay == 0){ 207 | TDA7449setBass(TDA7449getBass()-2); 208 | ShowWichValue = BASS; 209 | } 210 | else if(isKey(&Rc5, TREB_P) && RepeatDelay == 0){ 211 | TDA7449setTreble(TDA7449getTreble()+2); 212 | ShowWichValue = TREB; 213 | } 214 | else if(isKey(&Rc5, TREB_M) && RepeatDelay == 0){ 215 | TDA7449setTreble(TDA7449getTreble()-2); 216 | ShowWichValue = TREB; 217 | } 218 | else if(isKey(&Rc5, GAIN_P) && RepeatDelay == 0){ 219 | TDA7449setGain(TDA7449getGain()+2); 220 | ShowWichValue = GAIN; 221 | } 222 | else if(isKey(&Rc5, GAIN_M) && RepeatDelay == 0){ 223 | TDA7449setGain(TDA7449getGain()-2); 224 | ShowWichValue = GAIN; 225 | } 226 | showSoundValue(ShowWichValue); 227 | ShowWichValue = NIX; 228 | } 229 | 230 | if(Flag10ms){ 231 | Flag10ms = FALSE; 232 | if(Showtime){ 233 | Showtime--; 234 | if(Showtime == 0){ 235 | lcd_clrscr(); 236 | goto AGAIN; 237 | } 238 | } 239 | if(RepeatDelay) 240 | RepeatDelay--; 241 | } 242 | } 243 | } -------------------------------------------------------------------------------- /webbsh.c: -------------------------------------------------------------------------------- 1 | /* webbsh.c - Webbuilder Shell, a chroot command for the webbuilder account. 2 | * Copyright (C) 2002 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms of the GNU General Public License as published by the 6 | * Free Software Foundation; either version 2, or (at your option) any 7 | * later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software Foundation, 16 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #define ACCOUNT "webbuilder" 31 | 32 | #ifdef _POSIX_OPEN_MAX 33 | #define MAX_OPEN_FDS _POSIX_OPEN_MAX 34 | #else 35 | #define MAX_OPEN_FDS 256 36 | #endif 37 | 38 | 39 | static void 40 | usage (void) 41 | { 42 | fprintf (stderr, "usage: webbsh directory commands\n"); 43 | exit (1); 44 | } 45 | 46 | static void * 47 | xmalloc (size_t n) 48 | { 49 | void *p = malloc (n); 50 | if (!n) 51 | { 52 | fprintf (stderr, "webbsh: out of core\n"); 53 | exit (1); 54 | } 55 | return p; 56 | } 57 | 58 | static void * 59 | xcalloc (size_t n, size_t m) 60 | { 61 | void *p = xmalloc (n*m); 62 | memset (p, 0, n*m); 63 | return p; 64 | } 65 | 66 | 67 | static void 68 | drop_privileges (void) 69 | { 70 | if (setuid ( getuid () ) || getuid () != geteuid() || !setuid(0) ) 71 | { 72 | fprintf (stderr, "webbsh: failed to give up privileges: %s\n", 73 | strerror (errno)); 74 | exit (1); 75 | } 76 | } 77 | 78 | /* static char * */ 79 | /* xstrdup (const char *s) */ 80 | /* { */ 81 | /* char *p = xmalloc (strlen (s)+1); */ 82 | /* strcpy (p, s); */ 83 | /* return p; */ 84 | /* } */ 85 | 86 | 87 | /* Check whether any of the files below directory is suid or sgid. */ 88 | static void 89 | check_for_suid (const char *directory) 90 | { 91 | pid_t pid; 92 | int status; 93 | 94 | if (strchr (directory, '\'') ) 95 | { 96 | fprintf (stderr, "webbsh: directory must not contain a `''\n"); 97 | exit (1); 98 | } 99 | 100 | /* we run setuid but we don't want to run find then - so lets fork. */ 101 | pid = fork (); 102 | if ( pid == (pid_t)-1) 103 | { 104 | fprintf (stderr, "webbsh: fork failed: %s\n", strerror (errno)); 105 | exit (1); 106 | } 107 | 108 | if (!pid) 109 | { /* child */ 110 | FILE *fp; 111 | char *cmd; 112 | int esc, c, rc; 113 | 114 | drop_privileges (); 115 | if (!geteuid () || !getuid ()) 116 | abort (); /* we are pretty paranoid. */ 117 | 118 | cmd = xmalloc ( strlen (directory) + 100); 119 | strcpy (cmd, "/usr/bin/find '"); 120 | strcat (cmd, directory); 121 | strcat (cmd, "' -type f -perm +06000 -print"); 122 | fp = popen (cmd, "r"); 123 | free (cmd); 124 | if (!fp) 125 | { 126 | fprintf (stderr, "webbsh: failed to run find utility: %s\n", 127 | strerror (errno)); 128 | exit (1); 129 | } 130 | esc = 0; 131 | while ( (c=getc (fp)) != EOF) 132 | { 133 | if (!esc || esc == 2) 134 | { 135 | fputs ("webbsh: s[ug]id file `", stderr); 136 | esc = 1; 137 | } 138 | if (c == '\n') 139 | { 140 | fputs ("' detected\n",stderr); 141 | esc = 2; 142 | } 143 | else if (isascii (c) && isprint (c)) 144 | putc (c, stderr); 145 | else 146 | printf ("\\%02x", c ); 147 | } 148 | if ( (rc=pclose (fp)) ) 149 | { 150 | fprintf (stderr, "webbsh: find utility failed: rc=%d\n", rc); 151 | exit (1); 152 | } 153 | exit (esc?1:0); 154 | } 155 | 156 | /* parent */ 157 | if ( waitpid (pid, &status, 0 ) == -1 || status) 158 | { 159 | fprintf (stderr, "webbsh: suspect files found\n"); 160 | exit (1); 161 | } 162 | } 163 | 164 | 165 | 166 | static char ** 167 | build_env (void) 168 | { 169 | int n = 0; 170 | char **envp = xcalloc (10, sizeof *envp); 171 | 172 | envp[n++] = "HOME=/"; 173 | envp[n++] = "SHELL=/bin/sh"; 174 | envp[n++] = "LOGNAME=" ACCOUNT; 175 | envp[n++] = "PATH=/bin:/usr/bin"; 176 | 177 | return envp; 178 | } 179 | 180 | 181 | 182 | int 183 | main (int argc, char **argv) 184 | { 185 | const char *directory; 186 | struct passwd *pw; 187 | int i, n; 188 | gid_t dummy_grplist[1]; 189 | char **envp; 190 | 191 | if (argc < 2) 192 | usage (); 193 | argc--; argv++; 194 | if ( !strcmp (*argv, "--help") ) 195 | usage (); 196 | directory = *argv; 197 | argc--; argv++; 198 | if (*directory != '/') 199 | { 200 | fprintf (stderr, "webbsh: directory must be given as absolute path\n"); 201 | exit (1); 202 | } 203 | 204 | pw = getpwnam (ACCOUNT); 205 | if (!pw) 206 | { 207 | fprintf (stderr, "webbsh: no user `%s'\n", ACCOUNT); 208 | exit (1); 209 | } 210 | if ( getuid () != pw->pw_uid || getgid () != pw->pw_gid) 211 | { 212 | fprintf (stderr, "webbsh: not run as user `%s'\n", ACCOUNT); 213 | exit (1); 214 | } 215 | 216 | n = getgroups (0, dummy_grplist); 217 | if ( n < 0 || n > 1) 218 | { 219 | fprintf (stderr, "webbsh: user `%s' must not" 220 | " have any supplementary groups\n", ACCOUNT); 221 | exit (1); 222 | } 223 | if ( getegid () != getgid () ) 224 | { 225 | fprintf (stderr, "webbsh: must not be run sgid\n"); 226 | exit (1); 227 | } 228 | 229 | 230 | /* Close all files except for the standard ones. */ 231 | n = sysconf (_SC_OPEN_MAX); 232 | if (n < 0) 233 | n = MAX_OPEN_FDS; 234 | for (i=0; i < n; i++) 235 | { 236 | if (i == STDIN_FILENO || i == STDOUT_FILENO || i == STDERR_FILENO) 237 | continue; 238 | close(i); 239 | } 240 | errno = 0; 241 | 242 | if (chdir (directory)) 243 | { 244 | fprintf (stderr, "webbsh: chdir `%s' failed: %s\n", directory, 245 | strerror (errno)); 246 | exit (1); 247 | } 248 | 249 | check_for_suid (directory); 250 | 251 | if (chroot (directory)) 252 | { 253 | fprintf (stderr, "webbsh: chroot `%s' failed: %s\n", directory, 254 | strerror (errno)); 255 | exit (1); 256 | } 257 | 258 | drop_privileges (); 259 | 260 | if (!geteuid () || !getuid ()) 261 | abort (); /* we are pretty paranoid. */ 262 | 263 | if (argv[argc]) 264 | abort (); /* should never happen. */ 265 | 266 | envp = build_env (); 267 | 268 | if (!argc) 269 | { 270 | fputs ("webbsh: no command given - would use this environment:\n", stderr); 271 | for (i=0; envp[i]; i++) 272 | fprintf (stderr, "%s\n", envp[i]); 273 | exit (0); 274 | } 275 | 276 | 277 | if (execve (argv[0], argv, envp)) 278 | { 279 | fprintf (stderr, "webbsh: failed to run `%s': %s\n", argv[0], 280 | strerror (errno)); 281 | exit (1); 282 | } 283 | abort (); /*NOTREACHED*/ 284 | return 0; 285 | } 286 | 287 | /* 288 | Local Variables: 289 | compile-command: "cc -Wall -o webbsh webbsh.c" 290 | End: 291 | */ 292 | 293 | -------------------------------------------------------------------------------- /ebus/testnode.c: -------------------------------------------------------------------------------- 1 | /* testnode.c - Elektor Bus test Node 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | /* This node continuously sends messages with status information. S2 19 | and S3 are used to change the send interval. */ 20 | 21 | #include "hardware.h" 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | 33 | #include "ebus.h" 34 | #include "proto-dbgmsg.h" 35 | 36 | 37 | static volatile unsigned short send_interval; 38 | 39 | static volatile byte send_flag; 40 | 41 | 42 | 43 | /* This code is called by the 1ms ticker interrupt service routine 44 | with the current clock value given in milliseconds from 0..999. */ 45 | void 46 | ticker_bottom (unsigned int clock) 47 | { 48 | 49 | /* Run the main loop every N ms. */ 50 | if (send_interval && !(clock % send_interval)) 51 | { 52 | send_flag = 1; 53 | wakeup_main = 1; 54 | } 55 | 56 | if (read_key_s2 ()) 57 | { 58 | switch (send_interval) 59 | { 60 | case 1000: 61 | /* Disable sending but send one more frame to show the 62 | new sending interval. */ 63 | send_interval = 0; 64 | send_flag = 1; 65 | wakeup_main = 1; 66 | break; 67 | case 500: send_interval = 1000; break; 68 | case 250: send_interval = 500; break; 69 | case 125: send_interval = 250; break; 70 | case 100: send_interval = 125; break; 71 | case 50: send_interval = 100; break; 72 | case 25: send_interval = 50; break; 73 | } 74 | } 75 | if (read_key_s3 ()) 76 | { 77 | switch (send_interval) 78 | { 79 | case 0: send_interval = 1000; break; 80 | case 1000: send_interval = 500; break; 81 | case 500: send_interval = 250; break; 82 | case 250: send_interval = 125; break; 83 | case 125: send_interval = 100; break; 84 | case 100: send_interval = 50; break; 85 | case 50: send_interval = 25; break; 86 | } 87 | } 88 | } 89 | 90 | 91 | static void 92 | send_msg (void) 93 | { 94 | byte msg[MSGSIZE]; 95 | int idx = 0; 96 | unsigned int val; 97 | 98 | msg[idx++] = PROTOCOL_EBUS_TEST; 99 | msg[idx++] = 0; 100 | msg[idx++] = config.nodeid_lo; 101 | msg[idx++] = 0; 102 | msg[idx++] = (val = get_current_time ()) >> 8; 103 | msg[idx++] = val; 104 | msg[idx++] = (val = csma_get_stats (1)) >> 8; 105 | msg[idx++] = val; 106 | msg[idx++] = (val = csma_get_stats (2)) >> 8; 107 | msg[idx++] = val; 108 | msg[idx++] = (val = csma_get_stats (3)) >> 8; 109 | msg[idx++] = val; 110 | msg[idx++] = (val = csma_get_stats (4)) >> 8; 111 | msg[idx++] = val; 112 | msg[idx++] = send_interval >> 8; 113 | msg[idx++] = send_interval; 114 | 115 | csma_send_message (msg, MSGSIZE); 116 | } 117 | 118 | 119 | static void 120 | send_dbgmsg (const char *string) 121 | { 122 | byte msg[16]; 123 | 124 | msg[0] = PROTOCOL_EBUS_DBGMSG; 125 | msg[1] = config.nodeid_hi; 126 | msg[2] = config.nodeid_lo; 127 | memset (msg+3, 0, 13); 128 | strncpy (msg+3, string, 13); 129 | csma_send_message (msg, 16); 130 | } 131 | 132 | static void 133 | send_dbgmsg_fmt (const char *format, ...) 134 | { 135 | va_list arg_ptr; 136 | char buffer[16]; 137 | 138 | va_start (arg_ptr, format); 139 | vsnprintf (buffer, 16, format, arg_ptr); 140 | va_end (arg_ptr); 141 | send_dbgmsg (buffer); 142 | } 143 | 144 | 145 | 146 | /* A new message has been received and we must now parse the message 147 | quickly and see what to do. We need to return as soon as possible, 148 | so that the caller may re-enable the receiver. */ 149 | static void 150 | process_ebus_test (void) 151 | { 152 | /* Is this a broadcast or is it directed to us. If not we don't 153 | need to care about it. */ 154 | 155 | } 156 | 157 | 158 | 159 | /* 160 | Entry point 161 | */ 162 | int 163 | main (void) 164 | { 165 | byte *msg; 166 | hardware_setup (NODETYPE_UNDEFINED); 167 | csma_setup (); 168 | onewire_setup (); 169 | 170 | send_interval = 1000; 171 | 172 | sei (); /* Enable interrupts. */ 173 | 174 | 175 | /* for (;;) */ 176 | /* { */ 177 | /* byte i, crc, buf[9]; */ 178 | 179 | /* send_dbgmsg_fmt ("serial..."); */ 180 | /* onewire_enable (); */ 181 | /* onewire_write_byte (0x33); /\* Read ROM. *\/ */ 182 | /* _delay_ms (50); */ 183 | /* onewire_enable (); */ 184 | /* for (i=0; i < 8; i++) */ 185 | /* buf[i] = onewire_read_byte (); */ 186 | /* _delay_ms (1); */ 187 | /* crc = 0; */ 188 | /* for (i=0; i < 7; i++) */ 189 | /* crc = _crc_ibutton_update (crc, buf[i]); */ 190 | 191 | /* send_dbgmsg_fmt ("%02x %02x%02x%02x %02x", */ 192 | /* buf[0], buf[1], buf[2], buf[3], buf[7]); */ 193 | /* send_dbgmsg_fmt ("%02x%02x%02x %s", */ 194 | /* buf[4], buf[5], buf[6], */ 195 | /* buf[7] == crc? "ok":"bad"); */ 196 | 197 | /* _delay_ms (2000); */ 198 | /* } */ 199 | 200 | for (;;) 201 | { 202 | byte i, crc, buf[9]; 203 | 204 | onewire_enable (); 205 | onewire_write_byte (0xcc); /* Skip ROM. */ 206 | onewire_write_byte (0x44); /* Convert T. */ 207 | /* onewire_wait_for_one (); */ 208 | _delay_ms (900); 209 | onewire_enable (); /* Reset */ 210 | onewire_write_byte (0xcc); /* Skip ROM. */ 211 | onewire_write_byte (0xbe); /* Read scratchpad. */ 212 | for (i=0; i < 9; i++) 213 | buf[i] = onewire_read_byte (); 214 | 215 | crc = 0; 216 | for (i=0; i < 8; i++) 217 | crc = _crc_ibutton_update (crc, buf[i]); 218 | 219 | if (buf[8] == crc) 220 | { 221 | int16_t tread = (buf[1] << 8) | buf[0]; 222 | int16_t t; 223 | 224 | t = (tread*100 - 25 + ((16 - buf[6])*100 / 16)) / 20; 225 | 226 | send_dbgmsg_fmt ("t=%d (%d)", t, tread); 227 | } 228 | else 229 | send_dbgmsg_fmt ("badcrc"); 230 | 231 | onewire_disable (); 232 | _delay_ms (1000); 233 | } 234 | 235 | 236 | 237 | for (;;) 238 | { 239 | set_sleep_mode (SLEEP_MODE_IDLE); 240 | while (!wakeup_main) 241 | { 242 | cli(); 243 | if (!wakeup_main) 244 | { 245 | sleep_enable (); 246 | sei (); 247 | sleep_cpu (); 248 | sleep_disable (); 249 | } 250 | sei (); 251 | } 252 | wakeup_main = 0; 253 | 254 | msg = csma_get_message (); 255 | if (msg) 256 | { 257 | /* Process the message. */ 258 | switch ((msg[0] & PROTOCOL_TYPE_MASK)) 259 | { 260 | case PROTOCOL_EBUS_TEST: 261 | process_ebus_test (); 262 | break; 263 | default: 264 | /* Ignore all other protocols. */ 265 | break; 266 | } 267 | /* Re-enable the receiver. */ 268 | csma_message_done (); 269 | } 270 | 271 | if (send_flag) 272 | { 273 | send_msg (); 274 | send_flag = 0; 275 | } 276 | } 277 | } 278 | -------------------------------------------------------------------------------- /modulo-d-amp/lcd.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | Copyright: (c) 2009 Stange-Distribution Simone Stange, Berlin 3 | Contact: info@obd-shop.com 4 | License: GNU GPL v2 (see License.txt) 5 | Author: Frank Nitzsche classd@beta-x.de 6 | File: lcd.h 7 | Version: 16.02.09 8 | Compiler: AVR-GCC 9 | 10 | Prototypes are the same like the ones from Peter Fleury and Florian Scherb. 11 | I used their librarys extensive as draft. Therefore it should be easy to exchange 12 | this modul by their HD44780 or KS0073 compatible version. 13 | 14 | R/W line not supported. Tie to ground. 15 | 16 | Added: Function lcdBar(..) - a bargraph visualization 17 | **************************************************************************/ 18 | 19 | #ifndef LCD_H 20 | #define LCD_H 21 | 22 | #include "common.h" 23 | #include 24 | #include 25 | 26 | 27 | ////////////////////////////////////////////////////////////////////////// 28 | // User Config // 29 | ////////////////////////////////////////////////////////////////////////// 30 | 31 | /** 32 | * @name Definitions for lcd voltage 33 | */ 34 | #define LCD_VOLTAGE 3 /** Select 5 for 5V or 3 for 3.3V */ 35 | 36 | /** 37 | * @name Definitions for Display Size 38 | * Change these definitions to adapt setting to your display 39 | */ 40 | #define LCD_LINES 3 /**< number of visible lines of the display */ 41 | 42 | /** 43 | * @name Definitions for connection 44 | * Change these definitions to adapt setting to your circuit 45 | */ 46 | 47 | #define LCD_D0_IO LOGIC_POSITIV,C,3 /**< port,bit for 4bit data bit 0 */ 48 | #define LCD_D1_IO LOGIC_POSITIV,C,2 /**< port,bit for 4bit data bit 0 */ 49 | #define LCD_D2_IO LOGIC_POSITIV,C,1 /**< port,bit for 4bit data bit 0 */ 50 | #define LCD_D3_IO LOGIC_POSITIV,C,0 /**< port,bit for 4bit data bit 0 */ 51 | #define LCD_RS_IO LOGIC_POSITIV,D,5 /**< port,bit for RS line */ 52 | #define LCD_EN_IO LOGIC_POSITIV,D,6 /**< port,bit for Enable line */ 53 | 54 | ////////////////////////////////////////////////////////////////////////// 55 | // User Config // 56 | ////////////////////////////////////////////////////////////////////////// 57 | 58 | 59 | #define LCD_START_LINE1 0x00 /**< DDRAM address of first char of line 1 */ 60 | #if LCD_LINES == 2 61 | #define LCD_START_LINE2 0x40 /**< DDRAM address of first char of line 2 */ 62 | #endif 63 | #if LCD_LINES == 3 64 | #define LCD_START_LINE2 0x10 /**< DDRAM address of first char of line 2 */ 65 | #define LCD_START_LINE3 0x20 /**< DDRAM address of first char of line 3 */ 66 | #endif 67 | 68 | /** 69 | * @name Definitions for LCD command instructions 70 | * The constants define the various LCD controller instructions which can be passed to the 71 | * function lcd_command(), see ST7036 data sheet for a complete description. 72 | */ 73 | 74 | /* instruction register bit positions, see HD44780U data sheet */ 75 | #define LCD_CLR 0 /* DB0: clear display */ 76 | #define LCD_HOME 1 /* DB1: return to home position */ 77 | #define LCD_ENTRY_MODE 2 /* DB2: set entry mode */ 78 | #define LCD_ENTRY_INC 1 /* DB1: 1=increment, 0=decrement */ 79 | #define LCD_ENTRY_SHIFT 0 /* DB2: 1=display shift on */ 80 | #define LCD_ON 3 /* DB3: turn lcd/cursor on */ 81 | #define LCD_ON_DISPLAY 2 /* DB2: turn display on */ 82 | #define LCD_ON_CURSOR 1 /* DB1: turn cursor on */ 83 | #define LCD_ON_BLINK 0 /* DB0: blinking cursor ? */ 84 | #define LCD_MOVE 4 /* DB4: move cursor/display */ 85 | #define LCD_MOVE_DISP 3 /* DB3: move display (0-> cursor) ? */ 86 | #define LCD_MOVE_RIGHT 2 /* DB2: move right (0-> left) ? */ 87 | #define LCD_FUNCTION 5 /* DB5: function set */ 88 | #define LCD_FUNCTION_8BIT 4 /* DB4: set 8BIT mode (0->4BIT mode) */ 89 | #define LCD_FUNCTION_2LINES 3 /* DB3: two lines (0->one line) */ 90 | #define LCD_FUNCTION_10DOTS 2 /* DB2: 5x10 font (0->5x7 font) */ 91 | #define LCD_CGRAM 6 /* DB6: set CG RAM address */ 92 | #define LCD_DDRAM 7 /* DB7: set DD RAM address */ 93 | 94 | /* display on/off, cursor on/off, blinking char at cursor position */ 95 | #define LCD_DISP_OFF 0x08 /* display off */ 96 | #define LCD_DISP_ON 0x0C /* display on, cursor off */ 97 | #define LCD_DISP_ON_BLINK 0x0D /* display on, cursor off, blink char */ 98 | #define LCD_DISP_ON_CURSOR 0x0E /* display on, cursor on */ 99 | #define LCD_DISP_ON_CURSOR_BLINK 0x0F /* display on, cursor on, blink char */ 100 | 101 | 102 | #define LCD_MODE_DEFAULT ((1<. 16 | */ 17 | 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | 32 | #define PGM "hkpstats" 33 | #define PGM_VERSION "0.0" 34 | #define PGM_BUGREPORT "wk@gnupg.org" 35 | 36 | /* Option flags. */ 37 | static int verbose; 38 | static int debug; 39 | 40 | /* Error counter. */ 41 | static int any_error; 42 | 43 | /* An object to keep track of each host. */ 44 | struct host_s 45 | { 46 | struct host_s *next; 47 | 48 | const char *poolname; /* Original poolname (e.g. "keys.gnupg.net") */ 49 | struct in_addr addr; /* Its IP address. */ 50 | char *addr_str; /* Ditto but in human readabale format. */ 51 | 52 | struct { 53 | adns_query query; /* Active query. */ 54 | } help; 55 | }; 56 | typedef struct host_s *host_t; 57 | 58 | 59 | 60 | /* Print diagnostic message and exit with failure. */ 61 | static void 62 | die (const char *format, ...) 63 | { 64 | va_list arg_ptr; 65 | 66 | fflush (stdout); 67 | fprintf (stderr, "%s: ", PGM); 68 | 69 | va_start (arg_ptr, format); 70 | vfprintf (stderr, format, arg_ptr); 71 | va_end (arg_ptr); 72 | putc ('\n', stderr); 73 | 74 | exit (1); 75 | } 76 | 77 | 78 | /* Print diagnostic message. */ 79 | static void 80 | err (const char *format, ...) 81 | { 82 | va_list arg_ptr; 83 | 84 | any_error = 1; 85 | 86 | fflush (stdout); 87 | fprintf (stderr, "%s: ", PGM); 88 | 89 | va_start (arg_ptr, format); 90 | vfprintf (stderr, format, arg_ptr); 91 | va_end (arg_ptr); 92 | putc ('\n', stderr); 93 | } 94 | 95 | /* Print a info message message. */ 96 | static void 97 | inf (const char *format, ...) 98 | { 99 | va_list arg_ptr; 100 | 101 | if (verbose) 102 | { 103 | fprintf (stderr, "%s: ", PGM); 104 | 105 | va_start (arg_ptr, format); 106 | vfprintf (stderr, format, arg_ptr); 107 | va_end (arg_ptr); 108 | putc ('\n', stderr); 109 | } 110 | } 111 | 112 | 113 | 114 | static void 115 | process_one_pool (adns_state adns_ctx, const char *poolname) 116 | { 117 | adns_answer *answer = NULL; 118 | int rridx; 119 | host_t host; 120 | host_t hostlist = NULL; 121 | in rc; 122 | 123 | inf ("collecting data for `%s'", poolname); 124 | 125 | if (adns_synchronous (adns_ctx, poolname, 126 | adns_r_a, adns_qf_quoteok_query, 127 | &answer) ) 128 | { 129 | err ("DNS query for `%s' failed: %s", poolname, strerror (errno)); 130 | return; 131 | } 132 | 133 | if (answer->status != adns_s_ok) 134 | { 135 | err ("DNS query for `%s' failed: %s (%s)", poolname, 136 | adns_strerror (answer->status), 137 | adns_errabbrev (answer->status)); 138 | free (answer); 139 | return; 140 | } 141 | assert (answer->type == adns_r_a); 142 | 143 | for (rridx=0; rridx < answer->nrrs; rridx++) 144 | { 145 | struct sockaddr_in sockaddr; 146 | struct in_addr addr = answer->rrs.inaddr[rridx]; 147 | const char *s; 148 | 149 | host = calloc (1, sizeof *host); 150 | if (!host) 151 | die ("out of core: %s", strerror (errno)); 152 | host->poolname = poolname; 153 | host->addr = addr; 154 | s = inet_ntoa (addr); 155 | host->addr_str = strdup (s?s:"[none]"); 156 | if (!host->addr_str) 157 | die ("out of core: %s", strerror (errno)); 158 | 159 | inf ("IP=%s", host->addr_str); 160 | 161 | memset (&sockaddr, 0,sizeof sockaddr); 162 | sockaddr.sin_family = AF_INET; 163 | memcpy (&sockaddr.sin_addr, &addr, sizeof addr); 164 | if (adns_submit_reverse (adns_ctx, (struct sockaddr *)&sockaddr, 165 | adns_r_ptr, 166 | adns_qf_quoteok_cname | adns_qf_cname_loose, 167 | host, &host->help.query)) 168 | { 169 | err ("DNS reverse lookup of `%s', %s failed: %s (%s)", 170 | poolname, host->addr_str, 171 | adns_strerror (answer->status), 172 | adns_errabbrev (answer->status)); 173 | /*fixme: release_host (host);*/ 174 | } 175 | else 176 | { 177 | host->next = hostlist; 178 | hostlist = host; 179 | } 180 | } 181 | free (answer); 182 | 183 | if (!hostlist) 184 | return; 185 | 186 | /* Wait until all hosts are resolved. */ 187 | for (;;) 188 | { 189 | adns_query query = NULL; 190 | 191 | rc = adns_check(adns_ctx, &query, &answer, &host); 192 | if (!rc) 193 | { 194 | 195 | 196 | } 197 | else if (err == EAGAIN) break; 198 | if (err) { 199 | fprintf(stderr, "%s: adns_wait/check: %s", progname, strerror(err)); 200 | exit(1); 201 | } 202 | 203 | 204 | for (host = hostlist; host; host = host->next) 205 | { 206 | if (!host->help.query) 207 | continue; 208 | } 209 | } 210 | 211 | 212 | static int 213 | show_usage (int ex) 214 | { 215 | fputs ("Usage: " PGM " {pool}\n" 216 | "Generate a report for all keyservers in the POOLs.\n\n" 217 | " --verbose enable extra informational output\n" 218 | " --debug enable additional debug output\n" 219 | " --help display this help and exit\n\n" 220 | "Example: \"" PGM " keys.gnupg.net http-keys.gnupg.net\"\n\n" 221 | "Report bugs to " PGM_BUGREPORT ".\n", 222 | ex? stderr:stdout); 223 | exit (ex); 224 | } 225 | 226 | 227 | int 228 | main (int argc, char **argv) 229 | { 230 | int last_argc = -1; 231 | adns_state adns_ctx = NULL; 232 | 233 | if (argc) 234 | { 235 | argc--; argv++; 236 | } 237 | while (argc && last_argc != argc ) 238 | { 239 | last_argc = argc; 240 | if (!strcmp (*argv, "--")) 241 | { 242 | argc--; argv++; 243 | break; 244 | } 245 | else if (!strcmp (*argv, "--version")) 246 | { 247 | fputs (PGM " " PGM_VERSION "\n", stdout); 248 | exit (0); 249 | } 250 | else if (!strcmp (*argv, "--help")) 251 | { 252 | show_usage (0); 253 | } 254 | else if (!strcmp (*argv, "--verbose")) 255 | { 256 | verbose = 1; 257 | argc--; argv++; 258 | } 259 | else if (!strcmp (*argv, "--debug")) 260 | { 261 | verbose = debug = 1; 262 | argc--; argv++; 263 | } 264 | else if (!strncmp (*argv, "--", 2)) 265 | show_usage (1); 266 | } 267 | 268 | if (argc < 1) 269 | show_usage (1); 270 | 271 | if (adns_init (&adns_ctx, adns_if_none, stderr)) 272 | die ("error initializing ADNS: %s", strerror (errno)); 273 | 274 | /* Note: Firther own we keep shallow copies of argv; thus don't 275 | modify them. */ 276 | for (; argc; argc--, argv++) 277 | process_one_pool (adns_ctx, *argv); 278 | 279 | adns_finish (adns_ctx); 280 | 281 | 282 | return any_error? 1:0; 283 | } 284 | 285 | 286 | /* 287 | Local Variables: 288 | compile-command: "gcc -Wall -W -O2 -g -o hkpstats -ladns hkpstats.c" 289 | End: 290 | */ 291 | -------------------------------------------------------------------------------- /ebus/ebusdump.c: -------------------------------------------------------------------------------- 1 | /* ebusdump - Hex dump tool for ebus frames 2 | * Copyright (C) 2011 Werner Koch (dd9jn) 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | * 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "protocol.h" 26 | 27 | /* Valid nodes we want to print in --top mode. */ 28 | #define FIRST_NODE_ID 1 29 | #define LAST_NODE_ID 5 30 | 31 | static volatile int ctrl_c_pending; 32 | 33 | static void 34 | control_c_handler (int signo) 35 | { 36 | (void)signo; 37 | ctrl_c_pending = 1; 38 | } 39 | 40 | static uint16_t 41 | crc_ccitt_update (uint16_t crc, uint8_t data) 42 | { 43 | data ^= (crc & 0xff); 44 | data ^= data << 4; 45 | 46 | return ((((uint16_t)data << 8) | ((crc >> 8)& 0xff)) ^ (uint8_t)(data >> 4) 47 | ^ ((uint16_t)data << 3)); 48 | } 49 | 50 | /* Compute the CRC for MSG. MSG must be of MSGSIZE. The CRC used is 51 | possible not the optimal CRC for our message length. However we 52 | have a convenient inline function for it. */ 53 | static uint16_t 54 | compute_crc (const unsigned char *msg) 55 | { 56 | int idx; 57 | uint16_t crc = 0xffff; 58 | 59 | for (idx=0; idx < 16; idx++) 60 | crc = crc_ccitt_update (crc, msg[idx]); 61 | 62 | return crc; 63 | } 64 | 65 | 66 | int 67 | main (int argc, char **argv ) 68 | { 69 | int rawmode = 0; 70 | int topmode = 0; 71 | int c; 72 | int any; 73 | int esc; 74 | int synced; 75 | int idx; 76 | unsigned int value; 77 | unsigned char buffer[18]; 78 | unsigned int protocol; 79 | 80 | if (argc) 81 | { 82 | argc--; argv++; 83 | } 84 | 85 | if (argc && !strcmp (*argv, "--raw")) 86 | { 87 | rawmode = 1; 88 | argc--; argv++; 89 | } 90 | else if (argc && !strcmp (*argv, "--top")) 91 | { 92 | topmode = 1; 93 | argc--; argv++; 94 | } 95 | 96 | if (argc) 97 | { 98 | fprintf (stderr, "usage: ebusdump [--raw|--top] < input\n"); 99 | return 1; 100 | } 101 | 102 | if (topmode) 103 | { 104 | struct sigaction nact; 105 | 106 | nact.sa_handler = control_c_handler; 107 | nact.sa_flags = 0; 108 | sigaction (SIGINT, &nact, NULL); 109 | printf ("\x1b[1;1H\x1b[J"); /* Clear screen. */ 110 | fflush (stdout); 111 | } 112 | 113 | any = esc = synced = idx = 0; 114 | while ( (c=getchar ()) != EOF && !ctrl_c_pending) 115 | { 116 | if (c == 0x7e && any) 117 | { 118 | if (topmode) 119 | printf ("\x1b[K"); /* Clear to end of line. */ 120 | else 121 | putchar ('\n'); 122 | any = 0; 123 | } 124 | if (rawmode) 125 | { 126 | printf ("%s%02x", any?" ":"", c); 127 | any = 1; 128 | } 129 | else 130 | { 131 | if (c == FRAMESYNCBYTE) 132 | { 133 | esc = 0; 134 | synced = 1; 135 | idx = 0; 136 | } 137 | else if (c == FRAMEESCBYTE && !esc) 138 | esc = 1; 139 | else if (synced) 140 | { 141 | if (esc) 142 | { 143 | esc = 0; 144 | c ^= FRAMEESCMASK; 145 | } 146 | 147 | if (idx < sizeof (buffer)) 148 | buffer[idx] = c; 149 | 150 | if (!idx) 151 | protocol = (c & 0xff); 152 | 153 | if (topmode && !idx 154 | && (c & PROTOCOL_MSGLEN_MASK) != PROTOCOL_MSGLEN_16) 155 | { 156 | printf ("\x1b[1;1H" "[bad protocol_msglen] %02x", c); 157 | synced = 0; 158 | any = 1; 159 | } 160 | else if (idx < 2 && protocol == PROTOCOL_EBUS_TEST) 161 | ; /* Printed later. */ 162 | else if (topmode && idx == 2 && protocol == PROTOCOL_EBUS_TEST) 163 | { 164 | if (c >= FIRST_NODE_ID && c <= LAST_NODE_ID) 165 | printf ("\x1b[%d;1H", c+1 ); 166 | else 167 | printf ("\x1b[1;1H[bad node-id]\x1b[K "); 168 | printf ("%02x", buffer[0]); 169 | printf (" %02x", buffer[1]); 170 | printf (" %02x", buffer[2]); 171 | any = 1; 172 | } 173 | else if (topmode && idx > 3 && idx < 16 174 | && protocol == PROTOCOL_EBUS_TEST) 175 | { 176 | switch (idx) 177 | { 178 | case 4: case 6: case 8: case 10: case 12: case 14: 179 | value = c << 8; 180 | break; 181 | case 5: 182 | value |= c; 183 | printf (" t:%ud%02uh%02um%02us", 184 | (value/6/60/24), 185 | (value/6/60 % 24), 186 | (value/6 % 60), 187 | (value % 6) * 10); 188 | break; 189 | case 7: 190 | value |= c; 191 | printf (" nrx:%6u", value); 192 | break; 193 | case 9: 194 | value |= c; 195 | printf (" ntx:%6u", value); 196 | break; 197 | case 11: 198 | value |= c; 199 | printf (" col:%6u", value); 200 | break; 201 | case 13: 202 | value |= c; 203 | printf (" ovf:%6u", value); 204 | break; 205 | case 15: 206 | value |= c; 207 | printf (" int:%6u", value); 208 | break; 209 | } 210 | any = 1; 211 | } 212 | else if (idx < 30) 213 | { 214 | if (idx && idx < 16) 215 | putchar (' '); 216 | else if (idx == 16 && protocol == PROTOCOL_EBUS_TEST) 217 | printf (" crc: "); 218 | else if (idx == 18 && protocol == PROTOCOL_EBUS_TEST) 219 | printf (" trash: "); 220 | else if (idx) 221 | putchar (' '); 222 | printf ("%02x", c); 223 | if (idx == 17 && protocol == PROTOCOL_EBUS_TEST) 224 | { 225 | unsigned int crc = compute_crc (buffer); 226 | if ((crc >> 8) == buffer[16] && (crc&0xff) == buffer[17]) 227 | printf (" ok "); 228 | else 229 | printf (" bad"); 230 | } 231 | any = 1; 232 | } 233 | else if (idx == 30) 234 | printf ("..."); 235 | idx++; 236 | } 237 | } 238 | } 239 | if (topmode) 240 | printf ("\x1b[%d;1H\x1b[K\n", 7); 241 | if (any) 242 | putchar ('\n'); 243 | fflush (stdout); 244 | if (ferror (stdin) && !ctrl_c_pending) 245 | { 246 | fprintf (stderr, "ebusdump: read error\n"); 247 | return 1; 248 | } 249 | if (ferror (stdout)) 250 | { 251 | fprintf (stderr, "ebusdump: write error\n"); 252 | return 1; 253 | } 254 | 255 | return 0; 256 | } 257 | 258 | /* 259 | Local Variables: 260 | compile-command: "cc -Wall -o ebusdump ebusdump.c" 261 | End: 262 | */ 263 | -------------------------------------------------------------------------------- /undump.c: -------------------------------------------------------------------------------- 1 | /* undump - Hex undump tool 2 | * Copyright (C) 2000, 2010 Werner Koch (dd9jn) 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | * 17 | * 2010-09-02 wk Changed to GPLv3. 18 | * Fixed detection of write errors. Reported by Marcus 19 | * Brinkmann 20 | * 2011-02-24 wk Allow for 0x and \x prefixes. Print offset with 21 | * the error messages. 22 | * 2019-03-20 wk Allow for trailing backslashes. 23 | * 2020-05-28 wk gpg-connect-agent dump mode detection 24 | */ 25 | 26 | /* Special features: 27 | * - \xHH is detected and converted. 28 | * - 0xHH is detected and converted. 29 | * - A trailing backslash is ignored as used by Libgcrypt logging. 30 | * - The line format 31 | * "D[]<3_spaces_or_more>" 32 | * is detected and only the part is converted. This 33 | * is the format gpg-connect-agent uses in /hex mode. 34 | * - A line with '#' as first character is skipped. 35 | */ 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | #define digitp(p) ((p) >= '0' && (p) <= '9') 42 | #define hexdigitp(a) (digitp (a) \ 43 | || ((a) >= 'A' && (a) <= 'F') \ 44 | || ((a) >= 'a' && (a) <= 'f')) 45 | #define ascii_isspace(a) ((a)==' ' || (a)=='\n' || (a)=='\r' || (a)=='\t') 46 | #define xtoi_1(p) ((p) <= '9'? ((p)- '0'): \ 47 | (p) <= 'F'? ((p)-'A'+10):((p)-'a'+10)) 48 | 49 | 50 | 51 | 52 | int 53 | main (int argc, char **argv ) 54 | { 55 | int c1, c2; 56 | int last_lf, in_offset, dump_mode, skip_to_eol; 57 | unsigned int value; 58 | unsigned long lnr, off; 59 | int reformat = 0; 60 | unsigned long addr = 0; 61 | 62 | if (argc == 2 && !strcmp (argv[1], "-r")) 63 | reformat = 1; 64 | else if ( argc > 1 ) 65 | { 66 | fprintf (stderr, "usage: undump [-r] < input\n"); 67 | return 1; 68 | } 69 | 70 | 71 | last_lf = 1; 72 | in_offset = 0; 73 | dump_mode = 0; 74 | skip_to_eol = 0; 75 | lnr = 1; 76 | off = 0; 77 | while ( (c1=getchar ()) != EOF ) 78 | { 79 | off++; 80 | if (c1 == '\n') 81 | { 82 | lnr++; 83 | last_lf = 1; 84 | in_offset = 0; 85 | dump_mode = 0; 86 | skip_to_eol = 0; 87 | continue; 88 | } 89 | if (skip_to_eol) 90 | continue; 91 | if (last_lf) 92 | { 93 | last_lf = 0; 94 | if (c1 == 'D') 95 | { 96 | c2 = getchar (); 97 | if (c2 == '[') 98 | { 99 | in_offset = 1; 100 | dump_mode = 1; 101 | continue; 102 | } 103 | ungetc (c2, stdin); 104 | } 105 | else if (c1 == '#') 106 | { 107 | skip_to_eol = 1; 108 | continue; 109 | } 110 | } 111 | 112 | if (in_offset) 113 | { 114 | if (c1 == ']' || c1 == '\n') 115 | in_offset = 0; 116 | continue; 117 | } 118 | 119 | if (dump_mode) 120 | { 121 | if (c1 == ' ') 122 | dump_mode++; 123 | else 124 | dump_mode = 1; 125 | 126 | if (dump_mode > 3) /* 3 spaces seen */ 127 | skip_to_eol = 1; 128 | } 129 | 130 | 131 | if (ascii_isspace (c1)) 132 | continue; 133 | 134 | if (c1 == '\\') 135 | { 136 | /* Assume the hex digits are prefixed with \x. */ 137 | c1 = getchar (); 138 | off++; 139 | if (c1 == '\n') 140 | { 141 | /* But this is a trailing backslash - skip. */ 142 | lnr++; 143 | continue; 144 | } 145 | if (ascii_isspace (c1)) 146 | { 147 | /* backslash followed by space - see whether this 148 | * can also be considered as a trailing backslash. */ 149 | while ((c1 = getchar ()) != EOF && ++off && c1 != '\n') 150 | { 151 | if (!ascii_isspace (c1)) 152 | { 153 | if (addr && reformat) 154 | putchar('\n'); 155 | fprintf (stderr, "undump: spurious backslash " 156 | "at line %lu, off %lu\n", lnr, off); 157 | return 1; 158 | } 159 | } 160 | if (c1 == '\n') 161 | { 162 | lnr++; 163 | continue; 164 | } 165 | /* EOF */ 166 | break; 167 | } 168 | if (c1 != EOF) 169 | { 170 | c2 = getchar (); 171 | off++; 172 | } 173 | if (c1 != 'x' || c2 == EOF) 174 | { 175 | if (addr && reformat) 176 | putchar('\n'); 177 | fprintf (stderr, "undump: incomplete \\x " 178 | "prefix at line %lu, off %lu\n", lnr, off); 179 | return 1; 180 | } 181 | c1 = c2; 182 | } 183 | if (!hexdigitp (c1)) 184 | { 185 | if (addr && reformat) 186 | putchar('\n'); 187 | fprintf (stderr, 188 | "undump: non hex-digit encountered at line %lu, off %lu\n", 189 | lnr, off); 190 | return 1; 191 | } 192 | if ( (c2=getchar ()) == EOF ) 193 | { 194 | if (addr && reformat) 195 | putchar('\n'); 196 | fprintf (stderr, 197 | "undump: error reading second nibble at line %lu, off %lu\n", 198 | lnr, off); 199 | return 1; 200 | } 201 | off++; 202 | if (c2 == '\n') 203 | lnr++; 204 | if (!hexdigitp (c2)) 205 | { 206 | if (c1 == '0' && c2 == 'x') 207 | { 208 | /* Assume the hex digits are prefixed with 0x. */ 209 | c1 = getchar (); 210 | off++; 211 | if (c1 != EOF) 212 | { 213 | c2 = getchar (); 214 | off++; 215 | } 216 | if (c1 == EOF || c2 == EOF || !hexdigitp (c1) || !hexdigitp (c2)) 217 | { 218 | if (addr && reformat) 219 | putchar('\n'); 220 | fprintf (stderr, "undump: incomplete 0x " 221 | "prefix at line %lu, off %lu\n", lnr, off); 222 | return 1; 223 | } 224 | } 225 | else 226 | { 227 | if (addr && reformat) 228 | putchar('\n'); 229 | fprintf (stderr, "undump: second nibble is not a hex-digit" 230 | " at line %lu, off %lu\n", lnr, off); 231 | return 1; 232 | } 233 | } 234 | value = xtoi_1 (c1) * 16 + xtoi_1 (c2); 235 | if (reformat) 236 | { 237 | if (!(addr%16)) 238 | { 239 | if (addr) 240 | putchar('\n'); 241 | printf ("%08lx ", addr); 242 | } 243 | printf (" %02x", value); 244 | addr++; 245 | } 246 | else 247 | putchar (value); 248 | } 249 | 250 | if (addr && reformat) 251 | putchar('\n'); 252 | 253 | if (ferror (stdin)) 254 | { 255 | fprintf (stderr, "undump: read error at line %lu, off %lu\n", lnr, off); 256 | return 1; 257 | } 258 | if (ferror (stdout)) 259 | { 260 | fprintf (stderr, "undump: write error at input line %lu, off %lu\n", 261 | lnr, off); 262 | return 1; 263 | } 264 | 265 | return 0; 266 | } 267 | 268 | /* 269 | Local Variables: 270 | compile-command: "cc -Wall -o undump undump.c" 271 | End: 272 | */ 273 | -------------------------------------------------------------------------------- /ebus/hardware.c: -------------------------------------------------------------------------------- 1 | /* hardware.c - Hardware related code for an Elektor Bus Node 2 | * Copyright (C) 2011 g10 Code GmbH 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, see . 16 | */ 17 | 18 | #include "hardware.h" 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "ebus.h" 31 | 32 | /* UART defs. */ 33 | #define UBRR_VAL ((F_CPU+8*BAUD)/(16*BAUD)-1) 34 | #define BAUD_REAL (F_CPU/(16*(UBRR_VAL+1))) 35 | #define BAUD_ERROR ((1000*BAUD_REAL)/BAUD) 36 | #if (BAUD_ERROR < 990 || BAUD_ERROR > 1010) 37 | # error computed baud rate out of range 38 | #endif 39 | 40 | 41 | 42 | 43 | /* EEPROM layout. We keep configuration data at the start of the 44 | eeprom but copy it on startup into the RAM for easier access. */ 45 | struct __attribute__ ((packed)) ee_config_s 46 | { 47 | uint16_t reserved; 48 | uint8_t nodeid_hi; 49 | uint8_t nodeid_lo; 50 | uint8_t reserved1; 51 | uint8_t debug_flags; 52 | uint8_t reserved2; 53 | uint8_t reserved3; 54 | uint8_t name[8]; /* The human readable name of the node. */ 55 | }; 56 | 57 | /* At some point the linker must have been changed and now orders the 58 | sections in the reverse order. Thus we need to given the in this 59 | way to. It would be better to store this in one struct, though. */ 60 | struct ee_data_s ee_data EEMEM = {NODETYPE_UNDEFINED, 0, {{0}}}; 61 | struct ee_config_s ee_config EEMEM = {0}; 62 | 63 | /* End EEPROM. */ 64 | 65 | 66 | /* The current time measured in quantities of 10 seconds with 67 | explicit roll over after 7 days. */ 68 | static volatile uint16_t current_time; 69 | 70 | /* 10 milliseconds in the 10 second period. */ 71 | static volatile uint16_t current_clock; 72 | 73 | 74 | 75 | /* Read key S2. Return true once at the first debounced leading edge 76 | of the depressed key. For correct operation this function needs to 77 | be called at fixed intervals. If this is done using the 10ms 78 | system tick the user is required to press the key for at least 79 | 100ms. This should be sufficient to avoid faulty triggers due to 80 | sparks and other noisy sources. My tests using the usual PCB micro 81 | keys showed that I was not able to push them for less then 30 ms, 82 | 50ms were achievable but a common value for a quick push was about 83 | 150ms to 200ms range. With the old 1ms system tick we had a 84 | threshold of 10ms which was too low to avoid all faulty trigger 85 | sources; lightning and other noises triggered an unwanted event at 86 | least 2 or 3 times a week.*/ 87 | byte 88 | read_key_s2 (void) 89 | { 90 | static uint16_t state; 91 | 92 | state <<= 1; 93 | state |= !KEY_S2; 94 | state |= 0xf800; /* To work on 10 continuous depressed readings. */ 95 | return (state == 0xfc00); /* Only the transition shall return true. */ 96 | } 97 | 98 | byte 99 | read_key_s3 (void) 100 | { 101 | static uint16_t state; 102 | 103 | state <<= 1; 104 | state |= !KEY_S3; 105 | state |= 0xf800; /* To work on 10 continuous depressed readings. */ 106 | return (state == 0xfc00); /* Only the transition shall return true. */ 107 | } 108 | 109 | 110 | /* Return the current time. Time is measured as the count of 10 111 | second periods passed in a 7 day period. */ 112 | uint16_t 113 | get_current_time (void) 114 | { 115 | return current_time; 116 | } 117 | 118 | 119 | uint16_t 120 | get_current_fulltime (byte *r_deci) 121 | { 122 | uint16_t hi, lo; 123 | 124 | cli (); 125 | hi = current_time; 126 | lo = current_clock; 127 | sei (); 128 | *r_deci = lo/10; 129 | return hi; 130 | } 131 | 132 | 133 | void 134 | set_current_fulltime (uint16_t tim, byte deci) 135 | { 136 | cli (); 137 | current_time = tim; 138 | current_clock = deci * 10; 139 | sei (); 140 | time_has_been_set = 1; 141 | } 142 | 143 | 144 | void 145 | set_debug_flags (uint8_t value) 146 | { 147 | 148 | eeprom_update_byte (&ee_config.debug_flags, value); 149 | config.debug_flags = value; 150 | } 151 | 152 | 153 | 154 | /* 155 | Interrupt service routines 156 | */ 157 | 158 | 159 | /* 2ms ticker interrupt service routine. */ 160 | ISR (TIMER2_COMPA_vect) 161 | { 162 | static uint8_t two_ms_counter; 163 | 164 | if (++two_ms_counter != 5) 165 | return; 166 | two_ms_counter = 0; 167 | 168 | current_clock++; 169 | if (current_clock >= 1000) 170 | { 171 | /* 10 seconds passed. Bump the current time. */ 172 | current_time++; 173 | if (current_time == (uint16_t)1440 * 6 * 7 ) 174 | current_time = 0; /* Weekly roll-over. */ 175 | current_clock = 0; 176 | } 177 | 178 | ticker_bottom (current_clock); 179 | } 180 | 181 | 182 | /* Setup for some parts of the hardware. The caller needs to pass the 183 | node type so that the EEPROM will be erased if it does not match 184 | the node type. */ 185 | void 186 | hardware_setup (byte nodetype) 187 | { 188 | byte value; 189 | 190 | /* Port D configuration: 191 | PIND.7 = Inp: KEY_S3 192 | PIND.6 = Out: LED_Transmit 193 | PIND.5 = Inp: KEY_S2 194 | PIND.4 = Out: LED_Collision 195 | PIND.3 = Out: LT1785-pin2 = !RE 196 | PIND.2 = Out: LT1785-pin3 = DE 197 | PIND.1 = TXD: LT1785-pin4 = DI 198 | PIND.0 = RXD: LT1785-pin1 = RO 199 | */ 200 | PORTD = _BV(7) | _BV(5); /* Enable pull-ups. */ 201 | DDRD = (_BV(6) | _BV(4) | _BV(3) | _BV(2) | _BV(1)); 202 | 203 | #if (KEY_S3_BIT != 7 || KEY_S2_BIT != 5 \ 204 | || LED_Transmit_BIT != 6 || LED_Collision_BIT != 4) 205 | # error mismatch with hardware.h 206 | #endif 207 | 208 | /* Set the UART: 8n1, async, rx and tx on, rx int enabled. 209 | Baud rate set to the value computed from BAUD. */ 210 | UCSR0A = 0x00; 211 | UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0); 212 | UCSR0C = _BV(UCSZ01) | _BV(UCSZ00); 213 | UBRR0H = (UBRR_VAL >> 8) & 0x0f; 214 | UBRR0L = (UBRR_VAL & 0xff); 215 | 216 | /* Timer 2: 10ms ticker. 217 | 218 | F_ocr = F_cpu / (PRE * (OCR+1)) 219 | | F_cpu | PRE | OCR | F_ocr | 220 | |----------+------+-----+--------------| 221 | | 16000000 | 64 | 24 | 10000.000000 | 222 | | 16000000 | 64 | 249 | 1000.000000 | 223 | | 16000000 | 128 | 249 | 500.000000 | 224 | | 16000000 | 1024 | 155 | 100.160260 | 225 | #+TBLFM: $4=$1 / ($2 ($3 + 1));%f 226 | 227 | The table indicates that there is no way to get an exact 10ms 228 | timer. It is possible to have an exact 1ms and 2ms timer. We 229 | use a 2ms timer internally along with a counter to turn it into 230 | the 10ms timer. 231 | */ 232 | TCCR2A = 0x02; /* Select CTC mode. */ 233 | TCCR2B = 0x05; /* Set prescaler to 128. */ 234 | TCNT2 = 0x00; /* Clear timer/counter register. */ 235 | OCR2A = 249; /* Compare value for 2ms. */ 236 | TIMSK2 = 0x02; /* Set OCIE2A. */ 237 | 238 | /* Copy some configuration data into the RAM. */ 239 | config.nodeid_hi = eeprom_read_byte (&ee_config.nodeid_hi); 240 | config.nodeid_lo = eeprom_read_byte (&ee_config.nodeid_lo); 241 | config.debug_flags = eeprom_read_byte (&ee_config.debug_flags); 242 | /* Take a copy the reset flags and clear them. */ 243 | config.reset_flags = MCUSR; 244 | MCUSR &= ~(_BV(WDRF) | _BV(BORF) | _BV(EXTRF) | _BV(PORF)); 245 | 246 | /* Lacking any better way to seed rand we use the node id. A better 247 | way would be to use the low bit of an ADC to gather some entropy. 248 | However the node id is supposed to be unique and should thus be 249 | sufficient. */ 250 | srand (config.nodeid_lo); 251 | 252 | /* Clear the node specific eeprom if the node type changed. */ 253 | value = eeprom_read_byte (&ee_data.nodetype); 254 | if (value != nodetype) 255 | { 256 | int i; 257 | uint32_t dw = 0; 258 | 259 | for (i=0; i < sizeof ee_data; i += sizeof dw) 260 | eeprom_write_dword ((uint32_t*)(&ee_data.nodetype+i), dw); 261 | eeprom_write_byte (&ee_data.nodetype, nodetype); 262 | } 263 | 264 | 265 | } 266 | --------------------------------------------------------------------------------