mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-02 00:48:53 +00:00
usb create added
git-svn-id: https://svn.fhem.de/fhem/trunk@1148 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
4741878489
commit
05f2dcd3c0
@ -27,7 +27,8 @@
|
||||
- feature: FHEMWEB save button, smallscreen first screen fix
|
||||
- feature: FHEMWEB encoding is now UTF-8, alias attribute is respected
|
||||
- change: HTTPS certs directory moved from cwd into modpath
|
||||
- feature: shutdwown parameter restart added
|
||||
- feature: shutdown parameter restart added
|
||||
- feature: usb scan/create command added (part of autocreate).
|
||||
|
||||
|
||||
- 2011-07-08 (5.1)
|
||||
|
@ -239,7 +239,7 @@ FHZ_Get($@)
|
||||
FHZ_Write($hash, $fn, $arg) if(!IsDummy($hash->{NAME}));
|
||||
|
||||
my $msg = FHZ_ReadAnswer($hash, $a[1], 1.0);
|
||||
Log 5, "GET Got: $msg";
|
||||
Log 5, "GET Got: $msg" if(defined($msg));
|
||||
return $msg if(!$msg || $msg !~ /^81..c9..0102/);
|
||||
|
||||
if($a[1] eq "serial") {
|
||||
|
@ -268,7 +268,7 @@ KM271_Set($@)
|
||||
my $data = ($val ? sprintf($fmt, $val) : $fmt);
|
||||
|
||||
push @{$hash->{SENDBUFFER}}, $data;
|
||||
DevIo_SimpleWrite($hash, "02") if(!$hash->{WAITING});
|
||||
DevIo_SimpleWrite($hash, "02", 1) if(!$hash->{WAITING});
|
||||
|
||||
return undef;
|
||||
}
|
||||
@ -292,31 +292,31 @@ KM271_Read($)
|
||||
if(@{$hash->{SENDBUFFER}} || $hash->{DATASENT}) { # Send data
|
||||
|
||||
if($buf eq "02") { # KM271 Wants to send, override
|
||||
DevIo_SimpleWrite($hash, "02");
|
||||
DevIo_SimpleWrite($hash, "02", 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if($buf eq "10") {
|
||||
if($hash->{DATASENT}) {
|
||||
delete($hash->{DATASENT});
|
||||
DevIo_SimpleWrite($hash, "02") if(@{$hash->{SENDBUFFER}});
|
||||
DevIo_SimpleWrite($hash, "02", 1) if(@{$hash->{SENDBUFFER}});
|
||||
return;
|
||||
}
|
||||
$data = pop @{ $hash->{SENDBUFFER} };
|
||||
$data =~ s/10/1010/g;
|
||||
$crc = KM271_crc($data);
|
||||
DevIo_SimpleWrite($hash, $data."1003$crc"); # Send the data
|
||||
DevIo_SimpleWrite($hash, $data."1003$crc", 1); # Send the data
|
||||
}
|
||||
|
||||
if($buf eq "15") { # NACK from the KM271
|
||||
Log 1, "$name: NACK!";
|
||||
delete($hash->{DATASENT});
|
||||
DevIo_SimpleWrite($hash, "02") if(@{$hash->{SENDBUFFER}});
|
||||
DevIo_SimpleWrite($hash, "02", 1) if(@{$hash->{SENDBUFFER}});
|
||||
return;
|
||||
}
|
||||
|
||||
} elsif($buf eq "02") { # KM271 Wants to send
|
||||
DevIo_SimpleWrite($hash, "10"); # We are ready
|
||||
DevIo_SimpleWrite($hash, "10", 1); # We are ready
|
||||
$hash->{PARTIAL} = "";
|
||||
$hash->{WAITING} = 1;
|
||||
return;
|
||||
@ -333,12 +333,12 @@ KM271_Read($)
|
||||
|
||||
if(KM271_crc($data) ne $crc) {
|
||||
Log 1, "Wrong CRC in $hash->{PARTIAL}: $crc vs. ". KM271_crc($data);
|
||||
DevIo_SimpleWrite($hash, "15"); # NAK
|
||||
DevIo_SimpleWrite($hash, "02") if(@{$hash->{SENDBUFFER}}); # want to send
|
||||
DevIo_SimpleWrite($hash, "15", 1); # NAK
|
||||
DevIo_SimpleWrite($hash, "02", 1) if(@{$hash->{SENDBUFFER}}); # want to send
|
||||
return;
|
||||
}
|
||||
|
||||
DevIo_SimpleWrite($hash, "10"); # ACK, Data received ok
|
||||
DevIo_SimpleWrite($hash, "10", 1); # ACK, Data received ok
|
||||
|
||||
|
||||
$data =~ s/1010/10/g;
|
||||
@ -414,7 +414,7 @@ KM271_DoInit($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
push @{$hash->{SENDBUFFER}}, "EE0000";
|
||||
DevIo_SimpleWrite($hash, "02"); # STX
|
||||
DevIo_SimpleWrite($hash, "02", 1); # STX
|
||||
return undef;
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ TCM_Write($$$)
|
||||
}
|
||||
Log $ll5, "$hash->{NAME} sending $bstring";
|
||||
|
||||
DevIo_SimpleWrite($hash, $bstring);
|
||||
DevIo_SimpleWrite($hash, $bstring, 1);
|
||||
}
|
||||
|
||||
#####################################
|
||||
@ -542,7 +542,7 @@ TCM_Set($@)
|
||||
##############################
|
||||
if($hash->{MODEL} eq "120") {
|
||||
if($cmdHex eq "") { # wake is very special
|
||||
DevIo_SimpleWrite($hash, "AA");
|
||||
DevIo_SimpleWrite($hash, "AA", 1);
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,10 @@ autocreate_Initialize($)
|
||||
my %ahash = ( Fn=>"CommandCreateLog",
|
||||
Hlp=>"<device>,create log/weblink for <device>" );
|
||||
$cmds{createlog} = \%ahash;
|
||||
|
||||
my %bhash = ( Fn=>"CommandUsb",
|
||||
Hlp=>"[scan|create],display or create fhem-entries for USB devices" );
|
||||
$cmds{usb} = \%bhash;
|
||||
}
|
||||
|
||||
#####################################
|
||||
@ -275,4 +279,115 @@ CommandCreateLog($$)
|
||||
$attr{$ac}{disable} = 1 if($disabled);
|
||||
}
|
||||
|
||||
|
||||
##########################
|
||||
# Table for automatically creating IO devices
|
||||
my @usbtable = (
|
||||
{ NAME => "CUL",
|
||||
matchList => ["cu.usbmodem(.*)", "ttyACM(.*)"],
|
||||
DeviceName=> "DEVICE\@9600",
|
||||
flush => "\n",
|
||||
request => "V\n",
|
||||
response => "V .* CU.*",
|
||||
define => "CUL_PARAM CUL DEVICE\@9600 1234", },
|
||||
|
||||
{ NAME => "TCM310",
|
||||
matchList => ["cu.usbserial(.*)", "cu.usbmodem(.*)", "ttyUSB(.*)"],
|
||||
DeviceName=> "DEVICE\@57600",
|
||||
request => pack("H*", "5500010005700838"), # get idbase
|
||||
response => "\x00\xFF....",
|
||||
define => "TCM310_PARAM TCM 310 DEVICE\@57600", },
|
||||
|
||||
{ NAME => "TCM120",
|
||||
matchList => ["ttyUSB(.*)"],
|
||||
DeviceName=> "DEVICE\@9600",
|
||||
request => pack("H*", "A55AAB5800000000000000000003"), # get idbase
|
||||
response => "\xA5\x5A............",
|
||||
define => "TCM120_PARAM TCM 120 DEVICE\@9600", },
|
||||
|
||||
{ NAME => "FHZ",
|
||||
matchList => ["cu.usbserial(.*)", "ttyUSB(.*)"],
|
||||
DeviceName=> "DEVICE\@9600",
|
||||
request => pack("H*", "8105044fc90185"), # get fhtbuf
|
||||
response => "\x81........",
|
||||
define => "FHZ_PARAM FHZ DEVICE", },
|
||||
);
|
||||
|
||||
|
||||
sub
|
||||
CommandUsb($$)
|
||||
{
|
||||
my ($cl, $n) = @_;
|
||||
|
||||
return "Usage: usb [scan|create]" if("$n" !~ m/^(scan|create)$/);
|
||||
my $scan = 1 if($n =~ m/scan/);
|
||||
my $ret = "";
|
||||
my $msg;
|
||||
my $dir = "/dev";
|
||||
|
||||
require "$attr{global}{modpath}/FHEM/DevIo.pm";
|
||||
|
||||
foreach my $dev (sort split("\n", `ls $dir`)) {
|
||||
foreach my $thash (@usbtable) {
|
||||
foreach my $ml (@{$thash->{matchList}}) {
|
||||
if($dev =~ m/$ml/) {
|
||||
my $PARAM = $1;
|
||||
$PARAM =~ s/[^A-Za-z0-9]//g;
|
||||
my $name = $thash->{NAME};
|
||||
$msg = "$dev: checking if it is a $name";
|
||||
Log 4, $msg; $ret .= $msg . "\n";
|
||||
|
||||
# Check if it already used
|
||||
foreach my $d (keys %defs) {
|
||||
if($defs{$d}{DeviceName} &&
|
||||
$defs{$d}{DeviceName} =~ m/$dev/ &&
|
||||
$defs{$d}{FD}) {
|
||||
$msg = "$dev: already used by the $d fhem device";
|
||||
Log 4, $msg; $ret .= $msg . "\n";
|
||||
goto NEXTDEVICE;
|
||||
}
|
||||
}
|
||||
|
||||
# Open the device
|
||||
my $dname = $thash->{DeviceName};
|
||||
$dname =~ s,DEVICE,$dir/$dev,g;
|
||||
my $hash = { NAME=>$name, DeviceName=>$dname };
|
||||
DevIo_OpenDev($hash, 0, 0);
|
||||
if(!defined($hash->{USBDev})) {
|
||||
$msg = "$dev: Cannot open the device, check the log";
|
||||
Log 4, $msg; $ret .= $msg . "\n";
|
||||
goto NEXTDEVICE;
|
||||
}
|
||||
|
||||
# Clear the USB buffer
|
||||
if($thash->{flush}) {
|
||||
DevIo_SimpleWrite($hash, $thash->{flush}, 0);
|
||||
DevIo_TimeoutRead($hash, 0.1);
|
||||
}
|
||||
DevIo_SimpleWrite($hash, $thash->{request}, 0);
|
||||
my $answer = DevIo_TimeoutRead($hash, 0.1);
|
||||
DevIo_CloseDev($hash);
|
||||
|
||||
if($answer !~ m/$thash->{response}/) {
|
||||
$msg = "$dev: got wrong answer for a $name";
|
||||
Log 4, $msg; $ret .= $msg . "\n";
|
||||
next;
|
||||
}
|
||||
|
||||
my $define = $thash->{define};
|
||||
$define =~ s/PARAM/$PARAM/g;
|
||||
$define =~ s,DEVICE,$dir/$dev,g;
|
||||
$msg = "$dev: create as a fhem device with: define $define";
|
||||
Log 4, $msg; $ret .= $msg . "\n";
|
||||
CommandDefine($cl, $define);
|
||||
|
||||
goto NEXTDEVICE;
|
||||
}
|
||||
}
|
||||
}
|
||||
NEXTDEVICE:
|
||||
}
|
||||
return ($scan ? $ret : undef);
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -3,7 +3,8 @@
|
||||
package main;
|
||||
|
||||
sub DevIo_SimpleRead($);
|
||||
sub DevIo_SimpleWrite($$);
|
||||
sub DevIo_TimeoutRead($$);
|
||||
sub DevIo_SimpleWrite($$$);
|
||||
sub DevIo_OpenDev($$$);
|
||||
sub DevIo_CloseDev($);
|
||||
sub DevIo_Disconnected($);
|
||||
@ -50,20 +51,40 @@ DevIo_SimpleRead($)
|
||||
return $buf;
|
||||
}
|
||||
|
||||
########################
|
||||
# Read until you get the timeout. Use it with care
|
||||
sub
|
||||
DevIo_TimeoutRead($$)
|
||||
{
|
||||
my ($hash, $timeout) = @_;
|
||||
|
||||
my $answer = "";
|
||||
for(;;) {
|
||||
my $rin = "";
|
||||
vec($rin, $hash->{FD}, 1) = 1;
|
||||
my $nfound = select($rin, undef, undef, $timeout);
|
||||
last if($nfound <= 0);
|
||||
my $r = DevIo_DoSimpleRead($hash);
|
||||
last if(!defined($r));
|
||||
$answer .= $r;
|
||||
}
|
||||
return $answer;
|
||||
}
|
||||
|
||||
|
||||
########################
|
||||
# Input is HEX, with header and CRC
|
||||
sub
|
||||
DevIo_SimpleWrite($$)
|
||||
DevIo_SimpleWrite($$$)
|
||||
{
|
||||
my ($hash, $msg) = @_;
|
||||
my ($hash, $msg, $ishex) = @_;
|
||||
return if(!$hash);
|
||||
|
||||
my $name = $hash->{NAME};
|
||||
my $ll5 = GetLogLevel($name,5);
|
||||
Log $ll5, "SW: $msg";
|
||||
|
||||
$msg = pack('H*', $msg);
|
||||
$msg = pack('H*', $msg) if($ishex);
|
||||
$hash->{USBDev}->write($msg) if($hash->{USBDev});
|
||||
syswrite($hash->{TCPDev}, $msg) if($hash->{TCPDev});
|
||||
syswrite($hash->{DIODev}, $msg) if($hash->{DIODev});
|
||||
@ -82,7 +103,6 @@ DevIo_OpenDev($$$)
|
||||
my $baudrate;
|
||||
($dev, $baudrate) = split("@", $dev);
|
||||
|
||||
|
||||
$hash->{PARTIAL} = "";
|
||||
Log 3, "Opening $name device $dev"
|
||||
if(!$reopen);
|
||||
|
@ -13,8 +13,8 @@ RDOCDIR=$(ROOT)$(DOCDIR)
|
||||
RMANDIR=$(ROOT)$(MANDIR)
|
||||
RETCDIR=$(ROOT)$(ETCDIR)
|
||||
|
||||
VERS=5.1
|
||||
DATE=2011-07-08
|
||||
VERS=5.2
|
||||
DATE=2011-12-29
|
||||
DESTDIR=fhem-$(VERS)
|
||||
|
||||
all:
|
||||
|
@ -55,6 +55,7 @@
|
||||
<a href="#sleep">sleep</a>
|
||||
<a href="#trigger">trigger</a>
|
||||
<a href="#updatefhem">updatefhem</a>
|
||||
<a href="#usb">usb</a>
|
||||
<a href="#xmllist">xmllist</a>
|
||||
|
||||
</ul>
|
||||
@ -6979,16 +6980,36 @@ href="http://www.elv.de/output/controller.aspx?cid=74&detail=10&detail2=29870">U
|
||||
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="createlog"></a>
|
||||
<b>createlog</b>
|
||||
<ul>
|
||||
Use this command to manually add a FileLog and a weblink to an existing
|
||||
device. E.g. if a HomeMatic device is created automatically by something
|
||||
else then a pairing message, the model is unknown, so no plots will be
|
||||
generated. You can set the model/subtype attribute manually, and then call
|
||||
createlog to add the corresponding logs. </ul> <br>
|
||||
Use this command to manually add a FileLog and a weblink to an existing
|
||||
device. E.g. if a HomeMatic device is created automatically by something
|
||||
else then a pairing message, the model is unknown, so no plots will be
|
||||
generated. You can set the model/subtype attribute manually, and then call
|
||||
createlog to add the corresponding logs.<br><br>
|
||||
This command is part of the autocreate module.
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
<a name="usb"></a>
|
||||
<b>usb</b>
|
||||
<ul>
|
||||
Usage:
|
||||
<ul><code>
|
||||
usb scan<br>
|
||||
usb create<br>
|
||||
</code></ul>
|
||||
This command will scan the /dev directory for attached USB devices, and
|
||||
will try to identify them. With the argument scan you'll get back a list
|
||||
of fhem commands to execute, with the argument create there will be no
|
||||
feedback, and the devices will be created instead.<br><br> This command
|
||||
is part of the autocreate module.
|
||||
</ul>
|
||||
</ul> <!-- End of autocreate -->
|
||||
<br>
|
||||
|
||||
</ul>
|
||||
|
||||
<a name="average"></a>
|
||||
<h3>average</h3>
|
||||
|
Loading…
x
Reference in New Issue
Block a user