98_Modbus.pm: new restructure parsing and scanning

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@23944 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
StefanStrobel 2021-03-13 10:17:53 +00:00
parent 5e8c779698
commit ffe5eea56c
3 changed files with 553 additions and 355 deletions

File diff suppressed because it is too large Load Diff

View File

@ -539,9 +539,29 @@ sub Initialize {
Please note that this does not create an additional interval timer.
Instead the normal interval timer defined by the interval of the define command will check if this reading is due or not yet.
So the effective interval will always be a multiple of the interval of the define.<br>
If this attribute is set to "once" then the object will only be requested once after a restart.
<br>
If this attribute is set to "once" then the object will only be requested once after a restart.<br>
<li><b>obj-[cdih][1-9][0-9]*-group</b></li>
Allows control over the way how objects are combined in one request and in which order they are processed when the response comes in.<br>
example:<br>
<pre>
attr MyMaster obj-h100-reading Temp
attr MyMaster obj-h100-unpack f>
attr MyMaster obj-h100-len 2
attr MyMaster obj-h100-format %.2f
attr MyMaster obj-h100-poll 1
attr MyMaster obj-h100-expr ReadingsVal($name, 'TempMultiplyer', 1) * $val
attr MyMaster obj-h100-group 1-2
attr MyMaster obj-h102-reading TempMultiplyer
attr MyMaster obj-h102-unpack f>
attr MyMaster obj-h102-len 2
attr MyMaster obj-h102-poll 1
attr MyMaster obj-h102-group 1-1
attr MyMaster dev-h-combine 8
</pre><br>
this will cause the holding registers 100 and 102 to be read together. When the response is received,
register 102 will be processed first so when register 100 is processed, its value can be multipied with the already updated reading for register 102.<br>
This is helpful for devices where readings need to be computed out of several registers that need to be requested together and where the order of processing is important.
<li><b>dev-([cdih]-)*read</b></li>
specifies the function code to use for reading this type of object in master mode.
The default is 3 for holding registers, 1 for coils, 2 for discrete inputs and 4 for input registers.<br>

View File

@ -24,7 +24,8 @@ package FHEM::Modbus::TestUtils;
use strict;
use warnings;
use GPUtils qw(:all);
use Time::HiRes qw(gettimeofday);
use Time::HiRes qw(gettimeofday);
use Test::More;
use Exporter ('import');
our @EXPORT_OK = qw(
@ -35,6 +36,7 @@ our @EXPORT_OK = qw(
findTimesInLog
calcDelays
SetTestOptions
CheckAndReset
);
our %EXPORT_TAGS = (all => [@EXPORT_OK]);
@ -55,7 +57,11 @@ BEGIN {
InternalVal
featurelevel
FhemTestUtils_gotEvent
FhemTestUtils_gotLog
FhemTestUtils_getLogTime
FhemTestUtils_resetLogs
FhemTestUtils_resetEvents
defs
modules
@ -99,7 +105,7 @@ our %results;
# find the next test step number
# internal function, called from NextStep
sub GetNextStep {
Log3 undef, 1, "Test GetNextStep: look for next step";
#Log3 undef, 1, "Test GetNextStep: look for next step";
my $next = $testStep;
FINDSTEP:
while (1) {
@ -119,18 +125,18 @@ sub GetNextStep {
# also internally by CallStep and SimResponseRead
sub NextStep {
my $delay = shift // 0;
my $next = GetNextStep();
my $next = shift // GetNextStep();
if (!$next || ($delay && $delay eq 'end')) { # done if no more steps
Log3 undef, 1, "Test NextStep: no more steps found - exiting";
done_testing;
exit(0);
}
if (!$delay || $delay ne 'wait') { # set timer to next step unless waiting for reception of data
Log3 undef, 1, "Test NextStep: set timer to call step $next with delay $delay";
#Log3 undef, 1, "Test NextStep: set timer to call step $next with delay $delay";
InternalTimer(gettimeofday() + $delay, \&CallStep, "main::testStep$next");
$testStep = $next;
}
Log3 undef, 1, "Test NextStep: done.";
#Log3 undef, 1, "Test NextStep: done.";
return;
}
@ -150,7 +156,7 @@ sub CallStep {
if ($@) {
Log3 undef, 1, "Test step $step call created error: $@";
} else {
Log3 undef, 1, "Test step $step ($func) done, delay before next step is $delay";
Log3 undef, 1, "Test step $step ($func) done" . (defined ($delay) ? ", delay before next step is $delay" : "");
}
# if step function returns 'wait' then do not set timer for next step but wait for ReactOnLogRegex or similar
NextStep($delay); # check for next step and set timer or end testing
@ -291,4 +297,14 @@ sub calcDelays {
}
################################################################################
# Reset Logs and Events and check for Warnings
sub CheckAndReset {
is(FhemTestUtils_gotLog('PERL WARNING'), 0, "no Perl Warnings so far");
FhemTestUtils_resetLogs();
FhemTestUtils_resetEvents();
return;
}
1;