FRM: switch to Log3

Merge branch 'frm_log3'

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@4242 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
ntruchsess 2013-11-17 20:32:11 +00:00
parent 1873223592
commit 6f62ac3d6b
8 changed files with 30 additions and 32 deletions

View File

@ -49,7 +49,7 @@ sub FRM_Initialize($) {
$hash->{SetFn} = "FRM_Set"; $hash->{SetFn} = "FRM_Set";
$hash->{AttrFn} = "FRM_Attr"; $hash->{AttrFn} = "FRM_Attr";
$hash->{AttrList} = "model:nano dummy:1,0 loglevel:0,1,2,3,4,5,6 sampling-interval i2c-config $main::readingFnAttributes"; $hash->{AttrList} = "model:nano dummy:1,0 sampling-interval i2c-config $main::readingFnAttributes";
} }
##################################### #####################################
@ -78,7 +78,7 @@ sub FRM_Define($$) {
DevIo_CloseDev($hash); DevIo_CloseDev($hash);
if ( $dev eq "none" ) { if ( $dev eq "none" ) {
Log (GetLogLevel($hash->{NAME}), "FRM device is none, commands will be echoed only"); Log3 $name,3,"device is none, commands will be echoed only";
$main::attr{$name}{dummy} = 1; $main::attr{$name}{dummy} = 1;
return undef; return undef;
} }
@ -242,8 +242,7 @@ sub FRM_Attr(@) {
if ($command eq "set") { if ($command eq "set") {
$main::attr{$name}{$attribute}=$value; $main::attr{$name}{$attribute}=$value;
if ($attribute eq "sampling-interval" if ($attribute eq "sampling-interval"
or $attribute eq "i2c-config" or $attribute eq "i2c-config") {
or $attribute eq "loglevel" ) {
FRM_apply_attribute($main::defs{$name},$attribute); FRM_apply_attribute($main::defs{$name},$attribute);
} }
} }
@ -274,11 +273,7 @@ sub FRM_apply_attribute {
} else { } else {
$err = "Error, arduino doesn't support I2C"; $err = "Error, arduino doesn't support I2C";
} }
Log (GetLogLevel($hash->{NAME},2),$err) if ($err); Log3 $name,2,$err if ($err);
}
} elsif ($attribute eq "loglevel") {
if (defined $firmata->{io}) {
$firmata->{io}->{loglevel} = AttrVal($name,$attribute,5);
} }
} }
} }
@ -308,7 +303,7 @@ sub FRM_DoInit($) {
$device->{protocol}->{protocol_version} = $device->{metadata}{firmware_version}; $device->{protocol}->{protocol_version} = $device->{metadata}{firmware_version};
$main::defs{$name}{firmware} = $device->{metadata}{firmware}; $main::defs{$name}{firmware} = $device->{metadata}{firmware};
$main::defs{$name}{firmware_version} = $device->{metadata}{firmware_version}; $main::defs{$name}{firmware_version} = $device->{metadata}{firmware_version};
Log (3, "Firmata Firmware Version: ".$device->{metadata}{firmware}." ".$device->{metadata}{firmware_version}); Log3 $name,3,"Firmata Firmware Version: ".$device->{metadata}{firmware}." ".$device->{metadata}{firmware_version};
$device->analog_mapping_query(); $device->analog_mapping_query();
$device->capability_query(); $device->capability_query();
do { do {
@ -358,7 +353,7 @@ sub FRM_DoInit($) {
} else { } else {
select (undef,undef,undef,0.01); select (undef,undef,undef,0.01);
if (time > $queryTicks) { if (time > $queryTicks) {
Log (3, "querying Firmata Firmware Version"); Log3 $name,3,"querying Firmata Firmware Version";
$device->firmware_version_query(); $device->firmware_version_query();
$queryTicks++; $queryTicks++;
} }
@ -372,7 +367,7 @@ sub FRM_DoInit($) {
FRM_forall_clients($shash,\&FRM_Init_Client,undef); FRM_forall_clients($shash,\&FRM_Init_Client,undef);
return undef; return undef;
} }
Log (3, "no response from Firmata, closing DevIO"); Log3 $name,3,"no response from Firmata, closing DevIO";
DevIo_Disconnected($hash); DevIo_Disconnected($hash);
delete $hash->{FirmataDevice}; delete $hash->{FirmataDevice};
return "FirmataDevice not responding"; return "FirmataDevice not responding";
@ -399,9 +394,10 @@ FRM_Init_Client($@) {
my @a = split("[ \t][ \t]*", $hash->{DEF}); my @a = split("[ \t][ \t]*", $hash->{DEF});
$args = \@a; $args = \@a;
} }
my $ret = CallFn($hash->{NAME},"InitFn",$hash,$args); my $name = $hash->{NAME};
my $ret = CallFn($name,"InitFn",$hash,$args);
if ($ret) { if ($ret) {
Log (GetLogLevel($hash->{NAME},2),"error initializing ".$hash->{NAME}.": ".$ret); Log3 $name,2,"error initializing ".$hash->{NAME}.": ".$ret;
} }
} }
@ -507,21 +503,22 @@ sub new {
my ($class,$hash) = @_; my ($class,$hash) = @_;
return bless { return bless {
hash => $hash, hash => $hash,
loglevel => main::GetLogLevel($hash->{NAME},5),
}, $class; }, $class;
} }
sub data_write { sub data_write {
my ( $self, $buf ) = @_; my ( $self, $buf ) = @_;
main::Log ($self->{loglevel}, ">".join(",",map{sprintf"%02x",ord$_}split//,$buf)); my $hash = $self->{hash};
main::DevIo_SimpleWrite($self->{hash},$buf,undef); main::Log3 $hash->{NAME},5,">".join(",",map{sprintf"%02x",ord$_}split//,$buf);
main::DevIo_SimpleWrite($hash,$buf,undef);
} }
sub data_read { sub data_read {
my ( $self, $bytes ) = @_; my ( $self, $bytes ) = @_;
my $string = main::DevIo_SimpleRead($self->{hash}); my $hash = $self->{hash};
my $string = main::DevIo_SimpleRead($hash);
if (defined $string ) { if (defined $string ) {
main::Log ($self->{loglevel},"<".join(",",map{sprintf"%02x",ord$_}split//,$string)); main::Log3 $hash->{NAME},5,"<".join(",",map{sprintf"%02x",ord$_}split//,$string);
} }
return $string; return $string;
} }
@ -532,7 +529,7 @@ sub
FRM_i2c_observer FRM_i2c_observer
{ {
my ($data,$hash) = @_; my ($data,$hash) = @_;
Log GetLogLevel($hash->{NAME},5),"onI2CMessage address: '".$data->{address}."', register: '".$data->{register}."' data: '".$data->{data}."'"; Log3 $hash->{NAME},5,"onI2CMessage address: '".$data->{address}."', register: '".$data->{register}."' data: '".$data->{data}."'";
FRM_forall_clients($hash,\&FRM_i2c_update_device,$data); FRM_forall_clients($hash,\&FRM_i2c_update_device,$data);
} }
@ -553,7 +550,7 @@ sub FRM_i2c_update_device
sub FRM_string_observer sub FRM_string_observer
{ {
my ($string,$hash) = @_; my ($string,$hash) = @_;
Log (GetLogLevel($hash->{NAME},3), "received String_data: ".$string); Log3 $hash->{NAME},3,"received String_data: ".$string;
readingsSingleUpdate($hash,"error",$string,1); readingsSingleUpdate($hash,"error",$string,1);
} }

View File

@ -34,7 +34,7 @@ FRM_AD_Initialize($)
$hash->{DefFn} = "FRM_Client_Define"; $hash->{DefFn} = "FRM_Client_Define";
$hash->{InitFn} = "FRM_AD_Init"; $hash->{InitFn} = "FRM_AD_Init";
$hash->{AttrList} = "IODev upper-threshold lower-threshold loglevel:0,1,2,3,4,5,6 $main::readingFnAttributes"; $hash->{AttrList} = "IODev upper-threshold lower-threshold $main::readingFnAttributes";
main::LoadModule("FRM"); main::LoadModule("FRM");
} }
@ -62,10 +62,10 @@ sub
FRM_AD_observer FRM_AD_observer
{ {
my ($pin,$old,$new,$hash) = @_; my ($pin,$old,$new,$hash) = @_;
main::Log(6,"onAnalogMessage for pin ".$pin.", old: ".(defined $old ? $old : "--").", new: ".(defined $new ? $new : "--")); my $name = $hash->{NAME};
Log3 $name,6,"onAnalogMessage for pin ".$pin.", old: ".(defined $old ? $old : "--").", new: ".(defined $new ? $new : "--");
main::readingsBeginUpdate($hash); main::readingsBeginUpdate($hash);
main::readingsBulkUpdate($hash,"reading",$new,1); main::readingsBulkUpdate($hash,"reading",$new,1);
my $name = $hash->{NAME};
my $upperthresholdalarm = ReadingsVal($name,"alarm-upper-threshold","off"); my $upperthresholdalarm = ReadingsVal($name,"alarm-upper-threshold","off");
if ( $new < AttrVal($name,"upper-threshold",1024) ) { if ( $new < AttrVal($name,"upper-threshold",1024) ) {
if ( $upperthresholdalarm eq "on" ) { if ( $upperthresholdalarm eq "on" ) {

View File

@ -26,7 +26,7 @@ FRM_I2C_Initialize($)
$hash->{UndefFn} = "FRM_Client_Undef"; $hash->{UndefFn} = "FRM_Client_Undef";
$hash->{AttrFn} = "FRM_I2C_Attr"; $hash->{AttrFn} = "FRM_I2C_Attr";
$hash->{AttrList} = "IODev loglevel:0,1,2,3,4,5 $main::readingFnAttributes"; $hash->{AttrList} = "IODev $main::readingFnAttributes";
main::LoadModule("FRM"); main::LoadModule("FRM");
} }

View File

@ -41,7 +41,7 @@ FRM_IN_Initialize($)
$hash->{InitFn} = "FRM_IN_Init"; $hash->{InitFn} = "FRM_IN_Init";
$hash->{UndefFn} = "FRM_Client_Undef"; $hash->{UndefFn} = "FRM_Client_Undef";
$hash->{AttrList} = "IODev count-mode:none,rising,falling,both count-threshold reset-on-threshold-reached:yes,no internal-pullup:on,off loglevel:0,1,2,3,4,5 $main::readingFnAttributes"; $hash->{AttrList} = "IODev count-mode:none,rising,falling,both count-threshold reset-on-threshold-reached:yes,no internal-pullup:on,off $main::readingFnAttributes";
main::LoadModule("FRM"); main::LoadModule("FRM");
} }
@ -69,8 +69,8 @@ sub
FRM_IN_observer FRM_IN_observer
{ {
my ($pin,$old,$new,$hash) = @_; my ($pin,$old,$new,$hash) = @_;
main::Log(6,"onDigitalMessage for pin ".$pin.", old: ".(defined $old ? $old : "--").", new: ".(defined $new ? $new : "--")); my $name = $hash->{NAME};
my $name = $hash->{NAME}; Log3 $name,5,"onDigitalMessage for pin ".$pin.", old: ".(defined $old ? $old : "--").", new: ".(defined $new ? $new : "--");
my $changed = ((!(defined $old)) or ($old != $new)); my $changed = ((!(defined $old)) or ($old != $new));
main::readingsBeginUpdate($hash); main::readingsBeginUpdate($hash);
if ($changed) { if ($changed) {

View File

@ -40,7 +40,8 @@ FRM_LCD_Initialize($)
$hash->{AttrFn} = "FRM_LCD_Attr"; $hash->{AttrFn} = "FRM_LCD_Attr";
$hash->{StateFn} = "FRM_LCD_State"; $hash->{StateFn} = "FRM_LCD_State";
$hash->{AttrList} = "restoreOnReconnect:on,off restoreOnStartup:on,off IODev model backLight:on,off blink:on,off autoClear:on,off autoBreak:on,off loglevel:0,1,2,3,4,5 $main::readingFnAttributes"; $hash->{AttrList} = "restoreOnReconnect:on,off restoreOnStartup:on,off IODev model"
." backLight:on,off blink:on,off autoClear:on,off autoBreak:on,off $main::readingFnAttributes";
# autoScroll:on,off direction:leftToRight,rightToLeft do not work reliably # autoScroll:on,off direction:leftToRight,rightToLeft do not work reliably
main::LoadModule("FRM"); main::LoadModule("FRM");
} }

View File

@ -29,7 +29,7 @@ FRM_OUT_Initialize($)
$hash->{AttrFn} = "FRM_OUT_Attr"; $hash->{AttrFn} = "FRM_OUT_Attr";
$hash->{StateFn} = "FRM_OUT_State"; $hash->{StateFn} = "FRM_OUT_State";
$hash->{AttrList} = "restoreOnReconnect:on,off restoreOnStartup:on,off IODev loglevel:0,1,2,3,4,5 $main::readingFnAttributes"; $hash->{AttrList} = "restoreOnReconnect:on,off restoreOnStartup:on,off IODev $main::readingFnAttributes";
main::LoadModule("FRM"); main::LoadModule("FRM");
} }

View File

@ -48,7 +48,7 @@ FRM_PWM_Initialize($)
$hash->{AttrFn} = "FRM_PWM_Attr"; $hash->{AttrFn} = "FRM_PWM_Attr";
$hash->{StateFn} = "FRM_PWM_State"; $hash->{StateFn} = "FRM_PWM_State";
$hash->{AttrList} = "restoreOnReconnect:on,off restoreOnStartup:on,off IODev loglevel:0,1,2,3,4,5 $main::readingFnAttributes"; $hash->{AttrList} = "restoreOnReconnect:on,off restoreOnStartup:on,off IODev $main::readingFnAttributes";
main::LoadModule("FRM"); main::LoadModule("FRM");
} }

View File

@ -32,7 +32,7 @@ FRM_SERVO_Initialize($)
$hash->{UndefFn} = "FRM_Client_Undef"; $hash->{UndefFn} = "FRM_Client_Undef";
$hash->{AttrFn} = "FRM_SERVO_Attr"; $hash->{AttrFn} = "FRM_SERVO_Attr";
$hash->{AttrList} = "min-pulse max-pulse IODev loglevel:0,1,2,3,4,5 $main::readingFnAttributes"; $hash->{AttrList} = "min-pulse max-pulse IODev $main::readingFnAttributes";
main::LoadModule("FRM"); main::LoadModule("FRM");
} }