From 2ed49db67b9ca2fbef3b3415698fbece91e4fefc Mon Sep 17 00:00:00 2001
From: herrmannj <>
Date: Tue, 1 Sep 2020 20:09:35 +0000
Subject: [PATCH] 00_Schellenberg.pm: initial check-in
git-svn-id: https://svn.fhem.de/fhem/trunk@22709 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/FHEM/00_Schellenberg.pm | 202 +++++++++++++++++++++++++++++++++++
1 file changed, 202 insertions(+)
create mode 100644 fhem/FHEM/00_Schellenberg.pm
diff --git a/fhem/FHEM/00_Schellenberg.pm b/fhem/FHEM/00_Schellenberg.pm
new file mode 100644
index 000000000..acfec8461
--- /dev/null
+++ b/fhem/FHEM/00_Schellenberg.pm
@@ -0,0 +1,202 @@
+# $Id$
+###############################################################################
+#
+# This file is part of fhem.
+#
+# Fhem is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# Fhem is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with fhem. If not, see .
+#
+#
+###############################################################################
+
+# Thanks to hypfer for doing the basic research
+
+package main;
+
+use 5.018;
+use feature qw( lexical_subs );
+
+use strict;
+use warnings;
+use utf8;
+use DevIo;
+
+no warnings qw( experimental::lexical_subs );
+
+sub Schellenberg_Initialize {
+ my ($hash) = @_;
+
+ $hash->{'DefFn'} = 'Schellenberg_Define';
+ $hash->{'UndefFn'} = 'Schellenberg_Undef';
+ #$hash->{'DeleteFn'} = 'Schellenberg_Delete';
+ $hash->{'SetFn'} = 'Schellenberg_Set';
+ #$hash->{'ReadFn'} = "Schellenberg_Read";
+ $hash->{'ReadyFn'} = 'Schellenberg_Ready';
+
+ $hash->{'Clients'} = "Schellenberg.+";
+ $hash->{'MatchList'} = {
+ '0:SchellenbergHandle' => '^ss[[:xdigit:]]{1}4[[:xdigit:]]{16}'
+ };
+ $hash->{'AttrList'} = $readingFnAttributes;
+
+ return;
+};
+
+sub Schellenberg_Define {
+ my ($hash, $def) = @_;
+ my ($name, $type, $device) = split /\s/, $def, 3;
+
+ my $cvsid = '$Id$';
+ $cvsid =~ s/^.*pm\s//;
+ $cvsid =~ s/Z\s\S+\s\$$/ UTC/;
+ $hash->{'SVN'} = $cvsid;
+
+ return "no interface given" unless($device);
+ DevIo_CloseDev($hash) if (DevIo_IsOpen($hash));
+ $device .= '@38400' if ($device !~ m/\@\d+$/);
+ $hash->{'DeviceName'} = $device;
+
+ my $result = DevIo_OpenDev($hash, 0, "Schellenberg_Init");
+
+ return;
+};
+
+sub Schellenberg_Init {
+ my ($hash) = @_;
+
+ # my ($p, $id, $cmd, $counter) = unpack ('(H)(H3)', '14CB413E1A02D914A9');
+
+ # use Data::Dumper;
+ # print Dumper $p;
+ # print Dumper $id;
+
+ my $function;
+
+ # forward
+ sub expectVersion;
+ sub expectOK;
+ sub expectSome;
+
+ #my $test = 0;
+
+ my sub expectSome {
+ my ($msg) = @_;
+
+ my $found = Dispatch($hash, $msg);
+ return;
+ };
+
+ my sub expectOK {
+ my ($msg) = @_;
+ #print "incoming OK -----> msg $msg\r";
+ $function = \&expectSome;
+ DevIo_SimpleWrite($hash, "OK\r\n", 2);
+ };
+
+ my sub expectVersion {
+ my ($msg) = @_;
+ #print "incoming VERSION -----> msg $msg\r";
+ $function = \&expectOK;
+ DevIo_SimpleWrite($hash, "!G\r\n", 2);
+ };
+
+ my sub receive {
+ my $data = DevIo_SimpleRead($hash);
+
+ #say "receive";
+
+ $hash->{'PARTIAL'} .= $data;
+ while ($hash->{'PARTIAL'} =~ m/\r\n/) {
+ (my $msg, $hash->{'PARTIAL'}) = split (/\r\n/, $hash->{'PARTIAL'}, 2);
+ $function->($msg);
+ };
+ };
+
+ $hash->{'directReadFn'} = \&receive;
+ $function = \&expectVersion;
+ DevIo_SimpleWrite($hash, "!?\r\n", 2);
+};
+
+sub Schellenberg_Undef {
+ my ($hash) = @_;
+ DevIo_CloseDev($hash);
+ return undef;
+};
+
+sub Schellenberg_Set {
+ my ($hash, $name, $cmd, @args) = @_;
+
+ return "Unknown argument $cmd, choose one of pair" if ($cmd eq '?');
+
+ if ($cmd eq 'send' and $args[0]) {
+ DevIo_SimpleWrite($hash, "$args[0]\r\n", 2);
+ } elsif ($cmd eq 'pair') {
+ my $t = $args[0] || 60;
+ return 'missing time (seconds)' if ($t !~ m/[0-9]+/);
+
+ my sub resetPairTimer {
+ delete $hash->{'PAIRING'};
+ return;
+ };
+ $hash->{'PAIRING'} = 1;
+ InternalTimer(Time::HiRes::time() + $t, \&resetPairTimer, {});
+ };
+
+ return;
+};
+
+sub Schellenberg_Ready {
+ my ($hash) = @_;
+ return DevIo_OpenDev($hash, 1, "Schellenberg_Init");
+};
+
+
+1;
+
+=pod
+=item device
+=item summary Schellenberg USB RF-Dongle Receiver
+=item summary_DE Schellenberg USB Funk-Stick Empfänger
+=begin html
+
+
+
Schellenberg
+
+ Schellenberg USB RF Dongle.
+
+
+
+ Define
+
+ define <name> Schellenberg </dev/serial/by-id/usb-schellenberg_ENAS_000000000000-if00>
+
+ defines the device and set the port
+
+
+
+
+ Set
+
+ - pair
+
+ set <name> pair <seconds>
+
+ enable pair mode for seconds
+
+
+
+
+
+=end html
+
+=cut
\ No newline at end of file