Coder Social home page Coder Social logo

rene0 / dcf77pi Goto Github PK

View Code? Open in Web Editor NEW
18.0 8.0 6.0 1011 KB

Yet another DCF77 decoder. This one is intended for the Raspberry Pi platform but might work on other devices using GPIO pins too.

License: BSD 2-Clause "Simplified" License

Makefile 5.51% C 94.36% Shell 0.13%

dcf77pi's Introduction

dcf77pi

This repository has been migrated to https://codeberg.org/rene0/dcf77pi and archived here.


Yet another DCF77 decoder. This one is intended for the Raspberry Pi platform but might work on other devices using GPIO pins too.

For the Raspberry Pi, connect a stand-alone DCF77 receiver to a GPIO communication pin (default is 17) and the GPIO GND/3.3V pins (not 5V, this will break the Raspberry Pi).

An example schematics of a receiver is shown in receiver.fcd which can be shown using the FidoCadJ package.

The software comes with three binaries and a library:

  • dcf77pi : Live decoding from the GPIO pins in interactive mode. Useable keys are shown at the bottom of the screen. The backspace key can be used to correct the last typed character of the input text (when changing the name of the log file).
  • dcf77pi-analyze filename : Decode from filename instead of the GPIO pins. Output is generated in report mode.
  • dcf77pi-readpin [-qr] : Program to test reading from the GPIO pins and decode the resulting bit. Send a SIGINT (Ctrl-C) to stop the program. Optional parameters are:
    • -q do not show the raw input, default is to show it.
    • -r raw mode, bypass the normal bit reception routine, default is to use it.
  • libdcf77.so: The shared library containing common routines for reading bits (either from a log file or the GPIO pins) and to decode the date, time and third party buffer. Both dcf77pi and dcf77pi-analyze use this library. Header files to use the library in your own software are supplied.

The meaning of the keywords in config.json is:

  • pin = GPIO pin number (0-65535)
  • iodev = GPIO device number (FreeBSD only)
  • activehigh = pulses are active high (true) or passive high (false)
  • freq = sample frequency in Hz (10-155000)
  • outlogfile = name of the output logfile which can be read back using dcf77pi-analyze (default empty). The log file itself only stores the received bits, but not the decoded date and time.

Depending on your operating system and distribution, you might need to copy config.json.sample to config.json (in the same directory) to get started. You might also want to check and update the provided configuration to match your setup.


The end of the minute is noted by the absence of high pulses. An absence of low pulses probably means that the transmitter is out of range. Any other situation will result in a logical read error.

With permission (comment 5916), the method described at http://blog.blinkenlight.net/experiments/dcf77/binary-clock is used to receive the bits.

Currently supporrted platforms:

  • FreeBSD, Linux: full support
  • Cygwin, MacOS, NetBSD: supported without GPIO communication for live decoding
  • Windows: only via Cygwin

You will need to install a json-c development package and a package providing pkg-config to get the required header files and the .so library files. For example, on FreeBSD:

% sudo pkg install json-c pkgconf

On Linux, you will also have to install an (n)curses development package using your package manager. For example, on Raspbian:

% sudo apt-get install libncurses5-dev libjson-c-dev pkgconf

To build and install the program into /usr/bin , the library into /usr/lib and the configuration file into /usr/etc/dcf77pi :

% make PREFIX=/usr
% sudo make install PREFIX=/usr

On FreeBSD, dcf77pi and dcf77pi-readpin need to be run as root due to the permissions of /dev/gpioc* , but this can be prevented by changing the permissions of the device node:

# chmod 0660 /dev/gpioc*

And to make the change persistent across reboots:

# echo "perm gpioc* 0660" >> /etc/devfs.conf

On Raspbian Linux, the default permissions allow running dcf77pi and dcf77pi-readpin as a normal user (typically "pi"), no extra configuration is needed.

Setting the system time via dcf77pi still requires enhanced privileges (e.g., root).

dcf77pi's People

Contributors

mhaas avatar rene-cpx avatar rene0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dcf77pi's Issues

App as client

Once #7 is done.

Android client which receives the raw bitstream from the UDP port. libdcf77 as native client or duplicate in Java? Latter us more portable and takes advantage of JIT compilation.

last bit of each minute not shown by dcf77pi-analyze

The last bit of each minute is read but not shown by dcf77pi-analyze. This happens both with and without a newline/a/c (i.e. end-of-minute) markers.

If you change the last (i.e. parity bit), dcf77pi-analyze will correctly report a parity error.

Move UI-like code out of library

The process_input and post_process_input callbacks for example are probably better implemented as a separate thread instead of as callbacks. This also cleans up the library a bit. Check other nullable callbacks too.

Auxiliary tools

Which auxiliary tools to use?

  • (sp)lint for code quality, but splint is discontinued. Splint removed in 3.6.1. Lint only supports c89.
  • include-what-you-use (done)
  • automated testing / test data generation tool for issue #3 ?
  • clang-scan-build ?
  • fuzzer ?
  • something else?

Refactor decode_time

Refactor decode_time into smaller chunks and perhaps calendar.[ch] , get_weekday looks like client side functionality.

Move the DST adjustment code out of add_minute and substract_minute into its own function and move the former two functions to calendar.*

Native Windows compatibility

Replace Cygwin with native Windows code, if not too much work. Requires a copy of Windows and a copy of Visual Studio.

Fix BSD isms

Fix a few BSDisms like strsep() and others. Should compile with CC -std=c99 on both FreeBSD and Linux.

date/time off when minute is 1 bit too long

If the minute is 1 bit too long, the "long" light switches on but if the parity bits and BCD checks are fine the date/time can still be wrong (although the date/time fields are yellow).

extra characters in in minute string of log file confuses dcf77pi-analyze

While log files should only be written by dcf77pi itself, if one inserts extra spaces inside the minute string, dcf77pi gets confused. This gets caused by get_bit_file() counting the extra characters which leads to emark_toolong (promoted to emark_late).

dcf77pi-analyze manages to write "Minute too short" if mainloop() encounters emark_late because it resets minlen to -1 which causes decode_time() to think that the minute is actually -1 bits long.

Synthesized sample showing both problems:
0 10001011100100 0 010 0 1 1110001 0 100001 0 010010 111 11100 01010100 0 1 a59964c2.0047

Changelog

Add chance log MD for all releases

autotools?

Investigate if it would make sense to use autotools, this seems best supported on *BSD/Linux/Cygwin. Another option would be cmake. Probably best to compare side-by-side with autotools.

Flush log file each minute

Once #4 is done, it should be possible to flush the log file each minute because the sample rate is independent from the CPU load.

dcf77pi TUI enhancements

  • make the " dst" (and "leap" ?) light green when the time offset switched succesfully (i.e. at 1:00 AM UTC)
  • guard the ncurses buffers against window resizing etc (redraw completely each minute or upon SIGWINCH)
  • give better hints in case config.json is missing (instead of bailing out from json_object_from_file)

Unit tests

Add unit tests for all functions in libdcf77. Perhaps if a test is difficult to write/run, the corresponding function needs to be refactored.

Testing the GPIO pin reading needs some live tests to read a 0 pulse and a 1 pulse for example. This part is probably platform specific (which platforms to keep?)

  • test for DST/leap announcements
  • bits1to14.h
  • calendar.h
  • decode_alarm.h - not done, no proper specifications
  • decode_time.h (split up?)
  • input.h (except for get_bit_live() )
  • mainloop.h - we have dcf77pi[-analyze].c and readpin.c for this
  • setclock.h

Non root mode?

Currently dcf77pi requires root to read from the GPIO pin, can this be done differently? For example:

  • change owner/group/permission of the device node
  • a small daemon which runs as root so that the rest of the client can run as a normal user
  • capsicum?

Can't use GPIOs > 256

Hi,

my sun7i based board has GPIO higher than 256. I am trying to use pin 266, but dcf77pi is trying to open pin 10.

Meteotime decoder

When an official HKW 581 chip is connected to the receiver, it is technically possible to decode Meteotime transmissions sent in bits 1-14. Since this is (partly) patented, figure out if this is legally allowed.

Display about 1-2 seconds delayed

Thanks for your great program. I've just set it up and noticed that there is about 1-2 seconds delay compared to a physical DCF77-clock and even data from here https://dcf77logs.de/live is about 1 seconds faster than the output of dcf77pi. Is something wrong with my setup? I've also noticed that there is a log file created but it stays empty...

PS: For raspberry you have to do
sudo apt-get install libncurses5-dev libncursesw5-dev libjson-c-dev
before it compiles. And I only got it running by creating /etc/dcf77pi/config.json and starting it from the root working directory.

Adjust for distance delay

It takes a little time for the radio signal to arrive at the receiver, allow the user to adjust for this.

After #4 is done.

NPL decoder

Once #4 is done

Add functionality to decode the NPL transmission at 60 kHz. Since NPL transmits 2 bits per second, having a more fixed signal timing is helpful.

There will probably be 2 time decoders ons for DCF77 and one for NPL. Version 5

dst/leap: be more confident in announcement bits

Currently the threshold for the amount of announcement bits for DST/leap second is half the current minute value of more. This imposes a problem if the program is started after half the hour (at minute m), because in that case the number of announcements can never catch up with the minute value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.