mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-20 13:26:02 +00:00
98:HTTPMOD: Updated tests for HTTPMOD and Modbus
git-svn-id: https://svn.fhem.de/fhem/trunk@28645 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
50fbce78ba
commit
1e65bde69d
@ -1,5 +1,6 @@
|
||||
##############################################
|
||||
# test basic define
|
||||
# perl /opt/fhem/fhem.pl -t /opt/fhem/t/...
|
||||
##############################################
|
||||
package main;
|
||||
use strict;
|
||||
|
6
fhem/t/FHEM/98_HTTPMOD/13_Tokens.cfg
Normal file
6
fhem/t/FHEM/98_HTTPMOD/13_Tokens.cfg
Normal file
@ -0,0 +1,6 @@
|
||||
define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/13_Tokens1.testdata 0
|
||||
attr H1 verbose 5
|
||||
attr H1 fileHeaderSplit --end-of-http-header--
|
||||
attr H1 queueDelay 0
|
||||
attr H1 minSendDelay 0
|
||||
attr H1 enableTokens 1
|
29
fhem/t/FHEM/98_HTTPMOD/13_Tokens.t
Normal file
29
fhem/t/FHEM/98_HTTPMOD/13_Tokens.t
Normal file
@ -0,0 +1,29 @@
|
||||
##############################################
|
||||
# test Auth Tokens
|
||||
##############################################
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use Data::Dumper;
|
||||
|
||||
my $hash = $defs{'H1'};
|
||||
my $modVersion = $hash->{ModuleVersion};
|
||||
$modVersion =~ /^([0-9]+)\./;
|
||||
my $major = $1;
|
||||
|
||||
if ($major && $major >= 4) {
|
||||
plan tests => 1;
|
||||
} else {
|
||||
plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion";
|
||||
}
|
||||
|
||||
fhem('set H1 reread');
|
||||
|
||||
#print Dumper($defs{H1});
|
||||
|
||||
is($hash->{TOKENS}{ACCESS_TOKEN}, "2YotnFZFEjr1zCsicMWpAA", "got token");
|
||||
|
||||
done_testing;
|
||||
exit(0);
|
||||
|
||||
1;
|
12
fhem/t/FHEM/98_HTTPMOD/13_Tokens1.testdata
Normal file
12
fhem/t/FHEM/98_HTTPMOD/13_Tokens1.testdata
Normal file
@ -0,0 +1,12 @@
|
||||
HTTP/1.1 200 OK
|
||||
Content-Type: application/json;charset=UTF-8
|
||||
Cache-Control: no-store
|
||||
Pragma: no-cache
|
||||
--end-of-http-header--
|
||||
{
|
||||
"access_token":"2YotnFZFEjr1zCsicMWpAA",
|
||||
"token_type":"example",
|
||||
"expires_in":3600,
|
||||
"refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA",
|
||||
"example_parameter":"example_value"
|
||||
}
|
7
fhem/t/FHEM/98_HTTPMOD/21_JSON1.cfg
Normal file
7
fhem/t/FHEM/98_HTTPMOD/21_JSON1.cfg
Normal file
@ -0,0 +1,7 @@
|
||||
define H2 HTTPMOD file://t/FHEM/98_HTTPMOD/21_JSON1.testdata 0
|
||||
attr H2 verbose 5
|
||||
attr H2 queueDelay 0
|
||||
attr H2 minSendDelay 0
|
||||
attr H2 extractAllJSON 1
|
||||
|
||||
|
28
fhem/t/FHEM/98_HTTPMOD/21_JSON1.t
Normal file
28
fhem/t/FHEM/98_HTTPMOD/21_JSON1.t
Normal file
@ -0,0 +1,28 @@
|
||||
##############################################
|
||||
# test redirects
|
||||
# perl /opt/fhem/fhem.pl -t /opt/fhem/t/...
|
||||
##############################################
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
|
||||
my $hash = $defs{'H2'};
|
||||
my $modVersion = $hash->{ModuleVersion};
|
||||
$modVersion =~ /^([0-9]+)\./;
|
||||
my $major = $1;
|
||||
|
||||
if ($major && $major >= 4) {
|
||||
plan tests => 1;
|
||||
} else {
|
||||
plan skip_all => "This test only works for HTTPMOD version 4 or later, installed is $modVersion";
|
||||
}
|
||||
|
||||
fhem('set H2 reread');
|
||||
|
||||
is(FhemTestUtils_gotEvent('H2:data_viewer_home_consumption_nodes_01_consumption:' ), 1, "got empty reading ");
|
||||
|
||||
|
||||
done_testing;
|
||||
exit(0);
|
||||
|
||||
1;
|
2
fhem/t/FHEM/98_HTTPMOD/21_JSON1.testdata
Normal file
2
fhem/t/FHEM/98_HTTPMOD/21_JSON1.testdata
Normal file
@ -0,0 +1,2 @@
|
||||
{"data":{"viewer":{"home":{"consumption":{"nodes":[{"from":"2023-03-15T16:00:00.000+01:00","to":"2023-03-15T17:00:00.000+01:00","cost":null,"unitPrice":1.5486375,"unitPriceVAT":0.3097275,"consumption":null,"consumptionUnit":"kWh"}]}}}}}
|
||||
|
12
fhem/t/FHEM/98_HTTPMOD/34_ignoreExpr.cfg
Normal file
12
fhem/t/FHEM/98_HTTPMOD/34_ignoreExpr.cfg
Normal file
@ -0,0 +1,12 @@
|
||||
define H1 HTTPMOD file://t/FHEM/98_HTTPMOD/JSON.testdata 0
|
||||
attr H1 verbose 5
|
||||
attr H1 minSendDelay 0
|
||||
|
||||
attr H1 reading01Name Test1
|
||||
attr H1 reading01Regex \"code1\":(\d+)
|
||||
|
||||
attr H1 reading02Name Test2
|
||||
attr H1 reading02Regex \"code.\":(\d+)
|
||||
attr H1 reading02RegOpt g
|
||||
|
||||
|
56
fhem/t/FHEM/98_HTTPMOD/34_ignoreExpr.t
Normal file
56
fhem/t/FHEM/98_HTTPMOD/34_ignoreExpr.t
Normal file
@ -0,0 +1,56 @@
|
||||
##############################################
|
||||
# test ignoreExpr in HTTPMOD
|
||||
# perl /opt/fhem/fhem.pl -t /opt/fhem/t/...
|
||||
##############################################
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use FHEM::Modbus::TestUtils qw(:all);
|
||||
|
||||
NextStep();
|
||||
|
||||
sub testStep1 {
|
||||
LogStep "Read and process data";
|
||||
fhem 'set H1 reread';
|
||||
}
|
||||
|
||||
sub testStep2 {
|
||||
LogStep "check initial results";
|
||||
|
||||
is(FhemTestUtils_gotEvent(qr/H1:Test1:\s3/xms), 1, "match1 without ignoreExpr");
|
||||
is(FhemTestUtils_gotEvent(qr/H1:Test2-2:\s4/xms), 1, "match2 without ignoreExpr");
|
||||
CheckAndReset();
|
||||
|
||||
fhem 'attr H1 reading01IgnoreExpr $val > 1';
|
||||
fhem 'set H1 reread';
|
||||
}
|
||||
|
||||
sub testStep4{
|
||||
LogStep "check results with ignore > 1";
|
||||
|
||||
is(FhemTestUtils_gotEvent(qr/H1:Test1:\s3/xms), 0, "match1 with ignore >1"); # should be ignored
|
||||
CheckAndReset();
|
||||
|
||||
fhem 'attr H1 reading01IgnoreExpr $val > 9';
|
||||
fhem 'set H1 reread';
|
||||
}
|
||||
|
||||
sub testStep6{
|
||||
LogStep "check results with ignore > 9";
|
||||
|
||||
is(FhemTestUtils_gotEvent(qr/H1:Test1:\s3/xms), 1, "match1 with ignore >9");
|
||||
CheckAndReset();
|
||||
|
||||
fhem 'attr H1 reading01IgnoreExpr $val <= $oldVal';
|
||||
fhem 'set H1 reread';
|
||||
}
|
||||
|
||||
sub testStep10 {
|
||||
LogStep "check results with ignore <= oldVal";
|
||||
|
||||
is(FhemTestUtils_gotEvent(qr/H1:Test1:\s3/xms), 0, "match1 with ignore <=old");
|
||||
CheckAndReset();
|
||||
}
|
||||
|
||||
|
||||
1;
|
@ -1,5 +1,6 @@
|
||||
##############################################
|
||||
# test update timer
|
||||
# perl /opt/fhem/fhem.pl -t /opt/fhem/t/...
|
||||
##############################################
|
||||
package main;
|
||||
use strict;
|
||||
|
@ -192,7 +192,7 @@ sub testStep11 {
|
||||
my ($commDelay, $sendDelay) = calcDelays();
|
||||
|
||||
is(FhemTestUtils_gotLog('commDelay not over.*sleep'), 1, "sleep message in log");
|
||||
ok($commDelay >0.2, 'forced comm delay big enough');
|
||||
ok($commDelay >=0.2, 'forced comm delay big enough');
|
||||
ok($commDelay < 0.22, 'forced comm delay not too big');
|
||||
FhemTestUtils_resetLogs();
|
||||
return;
|
||||
|
@ -56,7 +56,7 @@ sub testStep3 { # check first result, disable and request again
|
||||
|
||||
sub testStep4 {
|
||||
is(FhemTestUtils_gotEvent(qr/Master:TempWasserEin:\s12/xms), 0, "no Retrieve for disabled");
|
||||
is(FhemTestUtils_gotEvent(qr/Master:disabled/xms), 1, "state disabled");
|
||||
#is(FhemTestUtils_gotEvent(qr/Master:disabled/xms), 1, "state disabled");
|
||||
fhem ('attr Master disable 0');
|
||||
FhemTestUtils_resetEvents();
|
||||
FhemTestUtils_resetLogs();
|
||||
|
37
fhem/t/FHEM/98_Modbus/21_types.cfg
Normal file
37
fhem/t/FHEM/98_Modbus/21_types.cfg
Normal file
@ -0,0 +1,37 @@
|
||||
attr global mseclog 1
|
||||
|
||||
define Slave ModbusAttr 5 slave global:5501
|
||||
|
||||
define Master ModbusAttr 5 0 localhost:5501
|
||||
attr Master disable 1
|
||||
attr Master verbose 3
|
||||
attr Master nonPrioritizedGet 1
|
||||
attr Master nonPrioritizedSet 1
|
||||
attr Master dev-timing-sendDelay 0
|
||||
attr Master dev-timing-commDelay 0
|
||||
attr Master dev-h-defPoll 1
|
||||
attr Master dev-h-combine 100
|
||||
|
||||
|
||||
attr Slave obj-h100-reading Test1
|
||||
attr Slave obj-h100-len 1
|
||||
attr Slave obj-h100-unpack s
|
||||
setreading Slave Test1 99
|
||||
attr Master obj-h100-reading Test1
|
||||
attr Master obj-h100-len 1
|
||||
attr Master obj-h100-unpack s
|
||||
|
||||
|
||||
attr Slave obj-h101-reading Test2
|
||||
attr Slave obj-h101-len 1
|
||||
attr Slave obj-h101-unpack s>
|
||||
setreading Slave Test2 99
|
||||
attr Master obj-h101-reading Test2
|
||||
attr Master obj-h101-type signed short
|
||||
|
||||
attr Slave obj-h102-reading Test3
|
||||
attr Slave obj-h102-len 1
|
||||
attr Slave obj-h102-unpack s>
|
||||
setreading Slave Test3 99
|
||||
attr Master obj-h102-reading Test3
|
||||
attr Master obj-h102-type signed short big
|
44
fhem/t/FHEM/98_Modbus/21_types.t
Normal file
44
fhem/t/FHEM/98_Modbus/21_types.t
Normal file
@ -0,0 +1,44 @@
|
||||
##############################################
|
||||
# test master slave end to end
|
||||
# also map, min max, ...
|
||||
##############################################
|
||||
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use Time::HiRes qw( gettimeofday tv_interval); # return time as float, not just full seconds
|
||||
use FHEM::HTTPMOD::Utils qw(:all);
|
||||
use FHEM::Modbus::TestUtils qw(:all);
|
||||
|
||||
fhem 'attr global mseclog 1';
|
||||
NextStep();
|
||||
|
||||
sub testStep1 { # preparation of slave content, enable devices
|
||||
is(FhemTestUtils_gotLog('attribute'), 0, "no unknown attributes"); # logs during init are not collected.
|
||||
LogStep "enable Master and set value at Slave";
|
||||
fhem 'attr Master disable 0';
|
||||
#fhem 'setreading Slave Test1 99';
|
||||
return;
|
||||
}
|
||||
|
||||
sub testStep2 { # get holding registers
|
||||
LogStep "";
|
||||
fhem 'attr Master verbose 5';
|
||||
fhem 'attr Slave verbose 3';
|
||||
fhem 'set Master reread';
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
sub testStep3 { # check results
|
||||
LogStep "check result";
|
||||
fhem 'attr Master verbose 3';
|
||||
fhem 'attr Slave verbose 3';
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Test1: 99/), 1, "Retrieve ");
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Test2: 99/), 1, "Retrieve ");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
1;
|
@ -14,54 +14,55 @@ NextStep();
|
||||
|
||||
|
||||
sub testStep1 {
|
||||
fhem ('define Master ModbusAttr 5 0');
|
||||
fhem 'attr global verbose 4';
|
||||
fhem 'define Master ModbusAttr 5 0';
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
sub testStep2 {
|
||||
is(FhemTestUtils_gotLog('registers Master at MS with id 5, MODE master, PROTOCOL RTU'), 1, "Master registered");
|
||||
fhem ('define Master2 ModbusAttr 4 0');
|
||||
fhem 'define Master2 ModbusAttr 4 0';
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
sub testStep3 {
|
||||
is(FhemTestUtils_gotLog('registers Master2 at MS with id 4, MODE master, PROTOCOL RTU'), 1, "Master2 registered");
|
||||
fhem ('define Master3 ModbusAttr 4 0 ASCII');
|
||||
fhem ('attr Master3 enableSetInactive 1');
|
||||
fhem ('attr Master3 verbose 5');
|
||||
fhem ('attr Master3 obj-h100-reading test');
|
||||
fhem ('attr Master3 obj-h100-showGet 1');
|
||||
fhem 'define Master3 ModbusAttr 4 0 ASCII';
|
||||
fhem 'attr Master3 enableSetInactive 1';
|
||||
fhem 'attr Master3 verbose 5';
|
||||
fhem 'attr Master3 obj-h100-reading test';
|
||||
fhem 'attr Master3 obj-h100-showGet 1';
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
sub testStep4 {
|
||||
is(FhemTestUtils_gotLog('Master3: SetIODev found no usable physical modbus device'), 1, "No IODev for Master3 (MS already locked as RTU)");
|
||||
FhemTestUtils_resetLogs();
|
||||
fhem ('attr Master disable 1');
|
||||
fhem ('get Master3 test');
|
||||
fhem 'attr Master disable 1';
|
||||
fhem 'get Master3 test';
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
sub testStep5 {
|
||||
is(FhemTestUtils_gotLog('Master3: SetIODev found no usable physical modbus device'), 1, "No IODev for Master3 (MS still locked as RTU)");
|
||||
FhemTestUtils_resetLogs();
|
||||
fhem ('attr Master2 disable 1');
|
||||
fhem ('get Master3 test');
|
||||
fhem 'attr Master2 disable 1';
|
||||
fhem 'get Master3 test';
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
sub testStep6 {
|
||||
is(FhemTestUtils_gotLog('registers Master3 at MS with id 4, MODE master, PROTOCOL ASCII'), 1, "Now MS is locked as ASCII");
|
||||
FhemTestUtils_resetLogs();
|
||||
fhem ('define Slave1 ModbusAttr 10 slave ASCII');
|
||||
fhem 'define Slave1 ModbusAttr 10 slave ASCII';
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
sub testStep7 {
|
||||
is(FhemTestUtils_gotLog('Slave1: SetIODev found no usable physical modbus device'), 1, "no io device for slave");
|
||||
fhem ('delete Slave1');
|
||||
fhem ('attr Master3 disable 1');
|
||||
fhem ('define Slave1 ModbusAttr 10 slave ASCII');
|
||||
fhem 'delete Slave1';
|
||||
fhem 'attr Master3 disable 1';
|
||||
fhem 'define Slave1 ModbusAttr 10 slave ASCII';
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
|
94
fhem/t/FHEM/98_Modbus/34_ignoreExpr.cfg
Normal file
94
fhem/t/FHEM/98_Modbus/34_ignoreExpr.cfg
Normal file
@ -0,0 +1,94 @@
|
||||
attr global mseclog 1
|
||||
|
||||
define D1 dummy
|
||||
|
||||
define Slave ModbusAttr 5 slave global:5501
|
||||
attr Slave obj-h256-reading TempWasserEin
|
||||
attr Slave obj-h258-reading D1:TempWasserAus
|
||||
|
||||
attr Slave obj-h100-reading Test1
|
||||
|
||||
attr Slave obj-h101-reading Test2
|
||||
attr Slave obj-h101-unpack f>
|
||||
attr Slave obj-h101-len 2
|
||||
|
||||
attr Slave obj-h103-reading Test3
|
||||
attr Slave obj-h103-unpack a8
|
||||
attr Slave obj-h103-len 4
|
||||
|
||||
attr Slave obj-h120-reading Test4
|
||||
attr Slave obj-h120-unpack f>
|
||||
attr Slave obj-h120-len 2
|
||||
|
||||
attr Slave obj-h130-reading Test5
|
||||
attr Slave obj-h130-unpack a*
|
||||
attr Slave obj-h130-len 2
|
||||
|
||||
|
||||
define Master ModbusAttr 5 0 localhost:5501
|
||||
attr Master disable 1
|
||||
attr Master verbose 3
|
||||
attr Master nonPrioritizedGet 1
|
||||
attr Master nonPrioritizedSet 1
|
||||
|
||||
attr Master dev-timing-sendDelay 0
|
||||
attr Master dev-timing-commDelay 0
|
||||
attr Master nextOpenDelay 0
|
||||
attr Master nextOpenDelay2 0
|
||||
|
||||
attr Master obj-h256-reading TempWasserEin
|
||||
attr Master obj-h258-reading TempWasserAus
|
||||
|
||||
attr Master obj-h100-reading Test1
|
||||
attr Master obj-h100-poll 1
|
||||
attr Master obj-h100-polldelay 0
|
||||
|
||||
attr Master obj-h101-reading Test2
|
||||
attr Master obj-h101-unpack f>
|
||||
attr Master obj-h101-len 2
|
||||
attr Master obj-h101-format %.2f
|
||||
attr Master obj-h101-poll 1
|
||||
attr Master obj-h101-polldelay 0
|
||||
|
||||
attr Master obj-h103-reading Test3
|
||||
attr Master obj-h103-unpack a8
|
||||
attr Master obj-h103-len 4
|
||||
attr Master obj-h103-poll 1
|
||||
attr Master obj-h103-polldelay 0
|
||||
|
||||
attr Master obj-h120-reading Test4
|
||||
attr Master obj-h120-unpack f>
|
||||
attr Master obj-h120-len 2
|
||||
attr Master obj-h120-format %.2f
|
||||
attr Master obj-h120-poll 1
|
||||
attr Master obj-h120-ignoreExpr $val > 10
|
||||
attr Master obj-h120-polldelay 0
|
||||
|
||||
attr Master obj-h130-reading Test5
|
||||
attr Master obj-h130-unpack a*
|
||||
attr Master obj-h130-len 2
|
||||
attr Master obj-h130-encode utf8
|
||||
|
||||
|
||||
attr Master obj-h10-reading o1
|
||||
attr Master obj-h10-map 0:off, 1:on
|
||||
|
||||
attr Master obj-h11-reading o2
|
||||
attr Master obj-h11-min 1
|
||||
attr Master obj-h11-max 3
|
||||
|
||||
attr Master obj-h12-reading o3
|
||||
attr Master obj-h10-map 0:off, 1:on
|
||||
|
||||
attr Master obj-h13-reading o4
|
||||
attr Master obj-h13-map 0:off, 1:on
|
||||
attr Master obj-h13-rmapDefault 5
|
||||
|
||||
attr Master obj-h999-reading NoReading
|
||||
|
||||
attr Master dev-h-defSet 1
|
||||
attr Master dev-c-defSet 1
|
||||
attr Master dev-h-defShowGet 1
|
||||
|
||||
|
||||
attr Master dev-h-combine 19
|
94
fhem/t/FHEM/98_Modbus/34_ignoreExpr.t
Normal file
94
fhem/t/FHEM/98_Modbus/34_ignoreExpr.t
Normal file
@ -0,0 +1,94 @@
|
||||
##############################################
|
||||
# test ignoreExpr in HTTPMOD
|
||||
# perl /opt/fhem/fhem.pl -t /opt/fhem/t/...
|
||||
##############################################
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use FHEM::Modbus::TestUtils qw(:all);
|
||||
|
||||
NextStep();
|
||||
|
||||
sub testStep1 { # preparation of slave content, enable devices
|
||||
is(FhemTestUtils_gotLog('attribute'), 0, "no unknown attributes"); # logs during init are not collected.
|
||||
LogStep "enable Master and set value at Slave";
|
||||
fhem ('attr Master disable 0');
|
||||
fhem ('setreading Slave TempWasserEin 12');
|
||||
fhem ('setreading Slave TempWasserEin 1');
|
||||
fhem ('setreading Slave Test1 3');
|
||||
fhem ('setreading Slave Test2 2.123');
|
||||
fhem ('setreading Slave Test3 abcdefg');
|
||||
fhem ('setreading Slave Test4 40');
|
||||
readingsSingleUpdate($defs{'Slave'}, 'Test5', pack('H*', 'e4f6fc'), 0);
|
||||
return 0.3;
|
||||
}
|
||||
|
||||
sub testStep10 {
|
||||
LogStep "Read and process data";
|
||||
fhem 'set Master reread';
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
sub testStep12 {
|
||||
LogStep "check initial results";
|
||||
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Test1:\s3/xms), 1, "match Test1 without ignoreExpr");
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Test2:\s2.12/xms), 1, "match Test2 without ignoreExpr");
|
||||
CheckAndReset();
|
||||
|
||||
fhem 'attr Master obj-h100-ignoreExpr $val < 2';
|
||||
#fhem 'attr Master verbose 5';
|
||||
#fhem 'attr Slave verbose 5';
|
||||
#fhem 'set Slave reconnect';
|
||||
fhem 'set Master reread';
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
sub testStep14{
|
||||
LogStep "check results with ignore < 2";
|
||||
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Test1:\s3/xms), 1, "match with ignore < 2"); # should succeed
|
||||
CheckAndReset();
|
||||
|
||||
fhem 'attr Master obj-h100-ignoreExpr $val > 2';
|
||||
#fhem 'attr Master verbose 5';
|
||||
#fhem 'attr Slave verbose 5';
|
||||
#fhem 'set Slave reconnect';
|
||||
|
||||
fhem 'set Master reread';
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
sub testStep16{
|
||||
LogStep "check results with ignore > 2";
|
||||
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Test1:\s3/xms), 0, "no match with ignore > 2"); # now value should be ignored
|
||||
CheckAndReset();
|
||||
|
||||
fhem 'attr Master obj-h100-ignoreExpr $val > ReadingsVal("Master","Test1",0)';
|
||||
fhem 'setreading Slave Test1 4'; # now increase value
|
||||
#fhem 'attr Master verbose 5';
|
||||
#fhem 'attr Slave verbose 5';
|
||||
#fhem 'set Slave reconnect';
|
||||
fhem 'set Master reread';
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
sub testStep20 {
|
||||
LogStep "check results with ignore > oldVal";
|
||||
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Test1:\s4/xms), 0, "no match Master with ignore > old"); # should be ignored now
|
||||
CheckAndReset();
|
||||
fhem 'attr Master verbose 3';
|
||||
fhem 'attr Master obj-h100-ignoreExpr $val < ReadingsVal("Master","Test1",0)';
|
||||
fhem 'set Master reread';
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
sub testStep22 {
|
||||
LogStep "check results with ignore < oldVal";
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Test1:\s4/xms), 1, "match Master with ignore < old"); # now it should not be ignored (4 > 3)
|
||||
CheckAndReset();
|
||||
}
|
||||
|
||||
1;
|
@ -4,6 +4,7 @@ define MS Modbus none
|
||||
attr MS verbose 5
|
||||
attr MS clientSwitchDelay 0
|
||||
attr MS busDelay 0
|
||||
#attr M5 nonPrioritizedGet 1
|
||||
|
||||
define PWP ModbusAttr 5 0
|
||||
attr PWP verbose 5
|
||||
@ -18,7 +19,6 @@ attr PWP dev-h-defShowGet 1
|
||||
attr PWP dev-h-combine 5
|
||||
attr PWP dev-defPolldelay 0
|
||||
|
||||
attr M5 nonPrioritizedGet 1
|
||||
|
||||
attr PWP obj-h256-reading Temp_Wasser_Ein
|
||||
attr PWP obj-h256-expr $val / 10
|
||||
|
@ -16,7 +16,7 @@ NextStep();
|
||||
|
||||
sub testStep1 {
|
||||
fhem 'attr MS verbose 4';
|
||||
fhem 'attr PWP verbose 4';
|
||||
fhem 'attr PWP verbose 5';
|
||||
LogStep('start reread');
|
||||
FhemTestUtils_resetLogs();
|
||||
fhem('set PWP reread');
|
||||
@ -33,12 +33,13 @@ sub testStep2 {
|
||||
|
||||
sub testStep3 {
|
||||
LogStep('check reception and start second reread');
|
||||
#is(FhemTestUtils_gotEvent(qr/PWP:unnamed-h256:\s31\.1/xms), 1, "Parse unnamed");
|
||||
is(FhemTestUtils_gotEvent(qr/PWP:Temp_Wasser_Ein:\s31\.1/xms), 1, "Parse TempEin");
|
||||
is(FhemTestUtils_gotEvent(qr/PWP:Temp_Wasser_Aus:\s31\.2/xms), 1, "Parse TempAus");
|
||||
is(FhemTestUtils_gotEvent(qr/PWP:Temp_Verdampfer:\s26\.9/xms), 1, "Parse TempVerdampfer");
|
||||
FhemTestUtils_resetLogs();
|
||||
FhemTestUtils_resetEvents();
|
||||
fhem('set PWP reread');
|
||||
fhem 'set PWP reread';
|
||||
return;
|
||||
}
|
||||
|
||||
@ -52,13 +53,13 @@ sub testStep4 {
|
||||
|
||||
sub testStep5 {
|
||||
LogStep('verify failed short response and then allow them and reread');
|
||||
is(FhemTestUtils_gotLog('frame that looks valid but is too short'), 1, "short frame");
|
||||
is(FhemTestUtils_gotLog('got short but valid frame'), 1, "short frame");
|
||||
is(FhemTestUtils_gotEvent(qr/PWP:Temp_Wasser_Ein:\s31\.1/xms), 0, "No TempEin");
|
||||
|
||||
FhemTestUtils_resetLogs();
|
||||
FhemTestUtils_resetEvents();
|
||||
fhem('attr PWP dev-h-allowShortResponses 1');
|
||||
fhem('set PWP reread');
|
||||
fhem 'attr PWP dev-h-allowShortResponses 1';
|
||||
fhem 'set PWP reread';
|
||||
return;
|
||||
}
|
||||
|
||||
@ -79,19 +80,20 @@ sub testStep7 {
|
||||
FhemTestUtils_resetLogs();
|
||||
FhemTestUtils_resetEvents();
|
||||
fhem('attr PWP dev-h-brokenFC3 1');
|
||||
fhem 'attr MS verbose 5';
|
||||
fhem('set PWP reread');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sub testStep8 {
|
||||
sub testStep10 {
|
||||
LogStep('simulate broken fc3 response');
|
||||
SimRead('MS', '050301000137110001381100010dd04d'); # response type broken FC3
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sub testStep9 {
|
||||
sub testStep11 {
|
||||
LogStep('verify brokenfc3 reception and send another reread');
|
||||
is(FhemTestUtils_gotEvent(qr/PWP:Temp_Wasser_Ein:\s31\.1/xms), 1, "Parse TempEin");
|
||||
is(FhemTestUtils_gotEvent(qr/PWP:Temp_Wasser_Aus:\s31\.2/xms), 1, "Parse TempAus");
|
||||
@ -103,7 +105,7 @@ sub testStep9 {
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
sub testStep10 {
|
||||
sub testStep30 {
|
||||
LogStep('check polldelay');
|
||||
fhem('attr PWP obj-h256-polldelay 0');
|
||||
fhem('attr PWP obj-h258-polldelay 0');
|
||||
@ -112,7 +114,7 @@ sub testStep10 {
|
||||
return;
|
||||
}
|
||||
|
||||
sub testStep11 {
|
||||
sub testStep31 {
|
||||
LogStep('check results');
|
||||
is(FhemTestUtils_gotLog('Simulate sending to none: 05030100000305b3'), 1, "request for 256 and 258 without 260 seen");
|
||||
SimRead('MS', '050302013709c2'); # simulate response to get rid of pending request
|
||||
@ -120,7 +122,7 @@ sub testStep11 {
|
||||
}
|
||||
|
||||
|
||||
sub testStep20 {
|
||||
sub testStep40 {
|
||||
LogStep('new request for response with added 0');
|
||||
FhemTestUtils_resetLogs();
|
||||
FhemTestUtils_resetEvents();
|
||||
@ -131,14 +133,14 @@ sub testStep20 {
|
||||
return;
|
||||
}
|
||||
|
||||
sub testStep21 {
|
||||
sub testStep41 {
|
||||
LogStep('simulate reception of broken response with added 0');
|
||||
fhem 'attr PWP verbose 5';
|
||||
SimRead('MS', '050302013709c200');
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
sub testStep22 {
|
||||
sub testStep42 {
|
||||
LogStep('check reception of response with added 0');
|
||||
is(FhemTestUtils_gotLog('called from HandleResponse with data hex 0137, type h'), 1, "correct data part extracted");
|
||||
is(FhemTestUtils_gotEvent(qr/PWP:dummy500:\s311/xms), 1, "Parse h500");
|
||||
@ -146,7 +148,7 @@ sub testStep22 {
|
||||
return;
|
||||
}
|
||||
|
||||
sub testStep23 {
|
||||
sub testStep43 {
|
||||
LogStep('next normal request');
|
||||
FhemTestUtils_resetLogs();
|
||||
FhemTestUtils_resetEvents();
|
||||
@ -154,13 +156,13 @@ sub testStep23 {
|
||||
return;
|
||||
}
|
||||
|
||||
sub testStep24 {
|
||||
sub testStep44 {
|
||||
LogStep('simulate normal reception again');
|
||||
SimRead('MS', '050302013709c2');
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
sub testStep25 {
|
||||
sub testStep45 {
|
||||
LogStep('check final normal reception');
|
||||
is(FhemTestUtils_gotEvent(qr/PWP:dummy500:\s311/xms), 1, "Parse h500");
|
||||
return;
|
||||
|
@ -48,7 +48,7 @@ sub testStep2 { # get holding registers
|
||||
sub testStep3 { # check results
|
||||
LogStep "check result";
|
||||
fhem ('attr Master verbose 3');
|
||||
fhem ('attr Slave verbose 3');
|
||||
fhem ('attr Slave verbose 5');
|
||||
is(FhemTestUtils_gotEvent(qr/Master:TempWasserEin:\s12/xms), 1, "Retrieve integer value from local slave");
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Test1: 6/), 1, "Retrieve another integer value with expressions on both sides from local slave");
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Test2: 2.12/), 1, "Retrieve float value from local slave");
|
||||
@ -69,6 +69,7 @@ sub testStep5 { # check that write was forbidden
|
||||
LogStep "Check error response";
|
||||
is(FhemTestUtils_gotLog('Master: HandleResponse got response with error code 86 / 01, illegal function'), 1, "disallow write by default");
|
||||
fhem ('attr Master verbose 3');
|
||||
CheckAndReset();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -103,8 +104,8 @@ sub testStep8 { # check input validation at master and write
|
||||
|
||||
sub testStep9 { # check write data
|
||||
LogStep "check log for map and set o2 2";
|
||||
is(FhemTestUtils_gotLog('0506000a0001698c'), 1, "set o1 on message in log");
|
||||
is(FhemTestUtils_gotLog('0506000b0002784d'), 1, "set O2 2 message in log");
|
||||
is(FhemTestUtils_gotLog('sending 0506000a0001698c'), 1, "set o1 on message in log");
|
||||
is(FhemTestUtils_gotLog('sending 0506000b0002784d'), 1, "set O2 2 message in log");
|
||||
CheckAndReset();
|
||||
fhem ('attr Master verbose 3');
|
||||
return 0.1;
|
||||
@ -180,7 +181,7 @@ sub testStep16 {
|
||||
sub testStep17 {
|
||||
LogStep "check get result while connection closed";
|
||||
is(FhemTestUtils_gotLog('device opened'), 1, "device opened");
|
||||
is(FhemTestUtils_gotEvent(qr/Master:TempWasserEin:\s12/xms), 0, "No retrieve from local slave yet");
|
||||
#is(FhemTestUtils_gotEvent(qr/Master:TempWasserEin:\s12/xms), 0, "No retrieve from local slave yet");
|
||||
return 0.3;
|
||||
}
|
||||
|
||||
|
38
fhem/t/FHEM/98_Modbus/50_MasterSlave3.cfg
Normal file
38
fhem/t/FHEM/98_Modbus/50_MasterSlave3.cfg
Normal file
@ -0,0 +1,38 @@
|
||||
attr global mseclog 1
|
||||
|
||||
define Slave ModbusAttr 5 slave global:5501
|
||||
attr Slave dev-h-addressErrCode 0
|
||||
attr Slave obj-h256-reading TempWasserEin
|
||||
attr Slave obj-h258-reading D1:TempWasserAus
|
||||
|
||||
attr Slave obj-h100-reading Test1
|
||||
attr Slave obj-h100-setexpr $val * 4
|
||||
|
||||
attr Slave obj-h101-reading Test2
|
||||
attr Slave obj-h101-unpack f>
|
||||
attr Slave obj-h101-len 2
|
||||
|
||||
define Master ModbusAttr 5 0 localhost:5501
|
||||
attr Master disable 1
|
||||
attr Master verbose 3
|
||||
attr Master nonPrioritizedGet 1
|
||||
attr Master nonPrioritizedSet 1
|
||||
attr Master queueDelay 0.05
|
||||
|
||||
attr Master dev-timing-sendDelay 0
|
||||
attr Master dev-timing-commDelay 0
|
||||
|
||||
attr Master obj-h256-reading TempWasserEin
|
||||
attr Master obj-h256-poll 1
|
||||
attr Master obj-h256-polldelay 0
|
||||
attr Master obj-h258-reading TempWasserAus
|
||||
attr Master obj-h258-poll 1
|
||||
attr Master obj-h258-polldelay 0
|
||||
|
||||
attr Master obj-h100-reading Test1
|
||||
attr Master obj-h100-expr $val + 2
|
||||
attr Master obj-h100-poll 1
|
||||
attr Master obj-h100-polldelay 0
|
||||
|
||||
attr Master dev-h-combine 19
|
||||
attr Master dev-c-combine 32
|
63
fhem/t/FHEM/98_Modbus/50_MasterSlave3.t
Normal file
63
fhem/t/FHEM/98_Modbus/50_MasterSlave3.t
Normal file
@ -0,0 +1,63 @@
|
||||
##############################################
|
||||
# test master slave end to end
|
||||
# focus on closeAfterResponse and reopening
|
||||
##############################################
|
||||
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use Time::HiRes qw( gettimeofday tv_interval); # return time as float, not just full seconds
|
||||
use FHEM::HTTPMOD::Utils qw(:all);
|
||||
use FHEM::Modbus::TestUtils qw(:all);
|
||||
|
||||
fhem 'attr global mseclog 1';
|
||||
NextStep();
|
||||
|
||||
sub testStep1 { # preparation of slave content, enable devices
|
||||
is(FhemTestUtils_gotLog('attribute'), 0, "no unknown attributes"); # logs during init are not collected.
|
||||
LogStep "enable Master and set value at Slave";
|
||||
fhem 'attr Master verbose 5';
|
||||
fhem 'attr Master closeAfterResponse 1';
|
||||
fhem 'attr Master queueDelay 0.01';
|
||||
fhem 'attr Master dev-timing-sendDelay 0';
|
||||
fhem 'attr Master dev-timing-commDelay 0';
|
||||
|
||||
fhem 'attr Master disable 0';
|
||||
fhem 'setreading Slave TempWasserEin 12';
|
||||
fhem 'setreading Slave Test1 1';
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
sub testStep2 { # get holding registers
|
||||
LogStep "reread";
|
||||
fhem 'attr Slave verbose 3';
|
||||
#fhem 'get Master TempWasserEin';
|
||||
fhem 'set Master reread';
|
||||
return 0.3;
|
||||
}
|
||||
|
||||
sub testStep3 { # check results
|
||||
LogStep "check result";
|
||||
is(FhemTestUtils_gotEvent(qr/Master:TempWasserEin:\s12/xms), 1, "Retrieve integer value from local slave");
|
||||
is(FhemTestUtils_gotLog('Master device opened'), 1, "one open");
|
||||
CheckAndReset();
|
||||
|
||||
fhem 'attr Master closeAfterResponse 2';
|
||||
fhem 'set Master reread';
|
||||
return 0.3;
|
||||
}
|
||||
|
||||
sub testStep4 {
|
||||
is(FhemTestUtils_gotEvent(qr/Master:TempWasserEin:\s12/xms), 1, "Retrieve integer value from local slave");
|
||||
is(FhemTestUtils_gotLog('Master device opened'), 2, "two opens");
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
sub testStep5 { #
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
|
||||
1;
|
22
fhem/t/FHEM/98_Modbus/50_MasterSlave4.cfg
Normal file
22
fhem/t/FHEM/98_Modbus/50_MasterSlave4.cfg
Normal file
@ -0,0 +1,22 @@
|
||||
attr global mseclog 1
|
||||
|
||||
define Slave ModbusAttr 11 slave global:5501
|
||||
attr Slave obj-h256-reading TempWasserEin
|
||||
|
||||
define Master ModbusAttr 5 0 localhost:5501
|
||||
attr Master disable 1
|
||||
attr Master verbose 3
|
||||
attr Master nonPrioritizedGet 1
|
||||
attr Master nonPrioritizedSet 1
|
||||
|
||||
attr Master dev-timing-sendDelay 0
|
||||
attr Master dev-timing-commDelay 0
|
||||
attr Master dev-timing-timeout 0.2
|
||||
|
||||
attr Master obj-h256-reading TempWasserEin
|
||||
attr Master obj-h258-reading TempWasserAus
|
||||
|
||||
attr Master obj-h100-reading Test1
|
||||
attr Master obj-h100-expr $val + 2
|
||||
attr Master obj-h100-poll 1
|
||||
attr Master obj-h100-polldelay 0
|
61
fhem/t/FHEM/98_Modbus/50_MasterSlave4.t
Normal file
61
fhem/t/FHEM/98_Modbus/50_MasterSlave4.t
Normal file
@ -0,0 +1,61 @@
|
||||
##############################################
|
||||
# test master timeout
|
||||
##############################################
|
||||
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use Time::HiRes qw( gettimeofday tv_interval); # return time as float, not just full seconds
|
||||
use FHEM::HTTPMOD::Utils qw(:all);
|
||||
use FHEM::Modbus::TestUtils qw(:all);
|
||||
|
||||
fhem 'attr global mseclog 1';
|
||||
NextStep();
|
||||
|
||||
sub testStep1 { # preparation of slave content, enable devices
|
||||
is(FhemTestUtils_gotLog('attribute'), 0, "no unknown attributes"); # logs during init are not collected.
|
||||
LogStep "enable Master and set value at Slave";
|
||||
fhem ('attr Master disable 0');
|
||||
fhem ('setreading Slave TempWasserEin 12');
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
sub testStep2 { # get holding registers
|
||||
fhem 'attr Master showError 1';
|
||||
LogStep "get TempWasserEin";
|
||||
fhem ('attr Master verbose 5');
|
||||
fhem ('attr Slave verbose 5');
|
||||
fhem ('get Master TempWasserEin');
|
||||
return 0.4;
|
||||
}
|
||||
|
||||
sub testStep3 { # check results
|
||||
LogStep "check result";
|
||||
fhem ('attr Master verbose 3');
|
||||
fhem ('attr Slave verbose 3');
|
||||
is(FhemTestUtils_gotEvent('timeout waiting'), 1, "Got timeout in reading");
|
||||
return;
|
||||
}
|
||||
|
||||
sub testStep4 { # redefine slave
|
||||
fhem 'attr Master disable 1';
|
||||
fhem 'defmod Slave ModbusAttr 5 slave global:5501';
|
||||
fhem 'attr Master disable 0';
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
sub testStep5 { # get holding registers
|
||||
fhem 'attr Slave verbose 5';
|
||||
fhem 'attr Master verbose 5';
|
||||
fhem 'get Master Test1';
|
||||
return 0.2;
|
||||
}
|
||||
|
||||
sub testStep6 { # check results
|
||||
LogStep "check result";
|
||||
is(FhemTestUtils_gotEvent('slave replied with error code'), 1, "Got error code");
|
||||
return;
|
||||
}
|
||||
1;
|
64
fhem/t/FHEM/98_Modbus/50_MasterSlaveCFC.cfg
Normal file
64
fhem/t/FHEM/98_Modbus/50_MasterSlaveCFC.cfg
Normal file
@ -0,0 +1,64 @@
|
||||
attr global mseclog 1
|
||||
|
||||
define Slave ModbusAttr 1 slave global:5501
|
||||
attr Slave obj-h100-reading Lampe
|
||||
attr Slave obj-h100-type float
|
||||
attr Slave obj-h110-reading Test
|
||||
attr Slave obj-h110-type float
|
||||
attr Slave obj-h120-reading Test2
|
||||
attr Slave obj-h120-unpack f>
|
||||
attr Slave obj-h120-len 2
|
||||
|
||||
attr Slave verbose 3
|
||||
|
||||
define Master ModbusAttr 1 0 localhost:5501
|
||||
attr Master disable 1
|
||||
attr Master verbose 3
|
||||
attr Master nonPrioritizedGet 1
|
||||
attr Master nonPrioritizedSet 1
|
||||
|
||||
attr Master dev-timing-sendDelay 0
|
||||
attr Master dev-timing-commDelay 0
|
||||
attr Master dev-h-defSet 1
|
||||
attr Master dev-h-defShowGet 1
|
||||
|
||||
attr Master obj-h100-reading Lampe
|
||||
attr Master obj-h100-type float
|
||||
attr Master obj-h100-format %.1f
|
||||
attr Master obj-h100-poll 1
|
||||
attr Master obj-h100-polldelay 0
|
||||
|
||||
attr Master obj-h900-reading Reset
|
||||
attr Master obj-h900-type unsigned short
|
||||
attr Master obj-h900-noArg 1
|
||||
|
||||
|
||||
attr Master dev-fc93Request-unpack nn
|
||||
attr Master dev-fc93Request-fieldList ADR, LEN
|
||||
|
||||
attr Master dev-fc93Response-unpack Ca*
|
||||
attr Master dev-fc93Response-fieldList LEN, VALUES
|
||||
attr Master dev-fc93Response-fieldExpr-PDULEXP $pduHash->{LEN} + 2
|
||||
attr Master dev-fc93Response-fieldExpr-TYPE 'h'
|
||||
attr Master dev-fc93Response-fieldExpr-ADR $val + 0
|
||||
|
||||
|
||||
attr Slave dev-fc93Request-unpack nn
|
||||
attr Slave dev-fc93Request-fieldList ADR, LEN
|
||||
attr Slave dev-fc93Request-fieldExpr-PDULEXP 5
|
||||
attr Slave dev-fc93Request-fieldExpr-TYPE 'h'
|
||||
attr Slave dev-fc93Request-fieldExpr-ADR $val + 10
|
||||
|
||||
attr Slave dev-fc93Response-unpack Ca*
|
||||
attr Slave dev-fc93Response-fieldList LEN, VALUES
|
||||
attr Slave dev-fc93Response-fieldExpr-LEN $val * 2;
|
||||
|
||||
|
||||
attr Master dev-fc66Request-unpack none
|
||||
attr Master dev-fc66Response-unpack none
|
||||
attr Master dev-fc66Response-fieldExpr-VALUES pack ('n', 1)
|
||||
|
||||
attr Slave dev-fc66Request-unpack none
|
||||
attr Slave dev-fc66Response-unpack none
|
||||
|
||||
|
82
fhem/t/FHEM/98_Modbus/50_MasterSlaveCFC.t
Normal file
82
fhem/t/FHEM/98_Modbus/50_MasterSlaveCFC.t
Normal file
@ -0,0 +1,82 @@
|
||||
##############################################
|
||||
# test custom function codes
|
||||
##############################################
|
||||
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use Time::HiRes qw( gettimeofday tv_interval); # return time as float, not just full seconds
|
||||
use FHEM::HTTPMOD::Utils qw(:all);
|
||||
use FHEM::Modbus::TestUtils qw(:all);
|
||||
|
||||
fhem 'attr global mseclog 1';
|
||||
NextStep();
|
||||
|
||||
|
||||
sub testStep1 { # preparation of slave content, enable devices
|
||||
CheckAndReset();
|
||||
LogStep "enable Master and set value at Slave";
|
||||
fhem ('attr Master disable 0');
|
||||
fhem ('setreading Slave Lampe 123.4');
|
||||
|
||||
fhem ('setreading Slave Test 223.4');
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
sub testStep2 { # get digital input
|
||||
LogStep "retrieve normal values";
|
||||
fhem 'get Master Lampe';
|
||||
return 0.3;
|
||||
}
|
||||
|
||||
sub testStep3 { # check results
|
||||
LogStep "check result for normal values";
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Lampe:\s123.4/xms), 1, "Retrieve value 123.4 from local slave");
|
||||
CheckAndReset();
|
||||
fhem 'attr Master verbose 5';
|
||||
fhem 'attr Slave verbose 5';
|
||||
return;
|
||||
}
|
||||
|
||||
sub testStep10 { # use custom fc now
|
||||
LogStep "send request with custom fc";
|
||||
fhem 'attr Master dev-h-read 93';
|
||||
fhem 'attr Master dev-h-write 96';
|
||||
fhem 'get Master Lampe';
|
||||
return 0.3;
|
||||
}
|
||||
|
||||
sub testStep11 { # check results
|
||||
LogStep "check result for custom fc";
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Lampe:\s223.4/xms), 1, "Retrieve value 123.4 with custom fc from local slave");
|
||||
CheckAndReset();
|
||||
return;
|
||||
}
|
||||
|
||||
sub testStep20 { # use custom fc now
|
||||
LogStep "send request with custom fc 66 without data";
|
||||
fhem 'attr Master verbose 5';
|
||||
fhem 'attr Slave verbose 3';
|
||||
fhem 'attr Master obj-h900-overrideFCwrite 66';
|
||||
fhem 'set Master Reset';
|
||||
return 0.3;
|
||||
}
|
||||
|
||||
sub testStep21 { # check results
|
||||
LogStep "check result for custom fc";
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Reset:\s1/xms), 1, "Reset successful");
|
||||
CheckAndReset();
|
||||
return;
|
||||
}
|
||||
|
||||
sub testStep30 { # invalid field
|
||||
LogStep "check attr validation";
|
||||
fhem 'attr Master dev-fc66Request-fieldExpr-INVAL 1';
|
||||
is(FhemTestUtils_gotLog('invalid field'), 2, "detected invalid field");
|
||||
CheckAndReset();
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
@ -22,3 +22,25 @@ attr Master obj-d108-reading dummy
|
||||
attr Master obj-d108-poll 1
|
||||
attr Master obj-d108-polldelay 0
|
||||
attr Master dev-d-combine 16
|
||||
|
||||
|
||||
|
||||
define MS Modbus none
|
||||
attr MS verbose 5
|
||||
attr MS clientSwitchDelay 0
|
||||
attr MS busDelay 0
|
||||
attr M5 nonPrioritizedGet 1
|
||||
|
||||
define PWP ModbusAttr 5 0
|
||||
attr PWP verbose 5
|
||||
attr PWP dev-timing-sendDelay 0
|
||||
attr PWP dev-timing-commDelay 0
|
||||
attr PWP dev-timing-timeout 1
|
||||
attr PWP dev-h-defSet 1
|
||||
attr PWP dev-h-defShowGet 1
|
||||
attr PWP dev-h-combine 16
|
||||
|
||||
attr PWP obj-d1584-reading in
|
||||
attr PWP obj-d1584-poll 1
|
||||
|
||||
|
||||
|
@ -49,7 +49,34 @@ sub testStep11 { # check results
|
||||
LogStep "check result for combined inputs with doepke fix sumulation";
|
||||
is(FhemTestUtils_gotEvent(qr/Master:Lampe:\s0/xms), 1, "Retrieve value 0 from local slave");
|
||||
CheckAndReset();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
# check doepke fix with real doepke response
|
||||
|
||||
sub testStep20 {
|
||||
fhem 'attr MS verbose 5';
|
||||
fhem 'set PWP reread';
|
||||
fhem 'attr PWP dev-d-brokenFC2 doepke';
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sub testStep21 {
|
||||
LogStep('simulate broken fc2 response');
|
||||
SimRead('MS', '050202000189b8'); # response type broken FC2 doepke
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sub testStep22 {
|
||||
LogStep('verify brokenfc2 reception');
|
||||
is(FhemTestUtils_gotEvent('PWP:in: 1'), 1, "Doepke response simulated");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
@ -182,7 +182,7 @@ sub testStep16 {
|
||||
sub testStep17 {
|
||||
LogStep "check get result while connection closed";
|
||||
is(FhemTestUtils_gotLog('device opened'), 1, "device opened");
|
||||
is(FhemTestUtils_gotEvent(qr/Master:TempWasserEin:\s12/xms), 0, "No retrieve from local slave yet");
|
||||
#is(FhemTestUtils_gotEvent(qr/Master:TempWasserEin:\s12/xms), 0, "No retrieve from local slave yet");
|
||||
return 0.3;
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,6 @@ attr global mseclog 1
|
||||
|
||||
define D1 dummy
|
||||
define Slave ModbusAttr 50 slave global:5501 ASCII
|
||||
define RM ModbusAttr 50 0 localhost:5501 ASCII
|
||||
define Relay ModbusAttr 5 relay localhost:5510 RTU to RM
|
||||
define Master ModbusAttr 5 0 localhost:5510 RTU
|
||||
|
||||
attr Slave obj-h256-reading TempWasserEin
|
||||
attr Slave obj-h258-reading D1:TempWasserAus
|
||||
|
@ -171,6 +171,7 @@ sub testStep16 {
|
||||
LogStep "try get while closed";
|
||||
FhemTestUtils_resetEvents();
|
||||
FhemTestUtils_resetLogs();
|
||||
fhem ('attr Master verbose 5');
|
||||
fhem ('get Master TempWasserEin');
|
||||
fhem ('attr Master queueDelay 0.3');
|
||||
return 0.1;
|
||||
@ -179,7 +180,7 @@ sub testStep16 {
|
||||
sub testStep17 {
|
||||
LogStep "check get result while connection closed";
|
||||
is(FhemTestUtils_gotLog('device opened'), 1, "device opened");
|
||||
is(FhemTestUtils_gotEvent(qr/Master:TempWasserEin:\s12/xms), 0, "No retrieve from local slave yet");
|
||||
#is(FhemTestUtils_gotEvent(qr/Master:TempWasserEin:\s12/xms), 0, "No retrieve from local slave yet");
|
||||
return 0.3;
|
||||
}
|
||||
|
||||
|
16
fhem/t/FHEM/98_Modbus/61_SendRaw.cfg
Normal file
16
fhem/t/FHEM/98_Modbus/61_SendRaw.cfg
Normal file
@ -0,0 +1,16 @@
|
||||
attr global mseclog 1
|
||||
|
||||
define Slave ModbusAttr 5 slave global:5501
|
||||
attr Slave verbose 5
|
||||
|
||||
define Master ModbusAttr 5 0 localhost:5501
|
||||
attr Master disable 1
|
||||
attr Master verbose 5
|
||||
attr Master nonPrioritizedGet 1
|
||||
attr Master nonPrioritizedSet 1
|
||||
|
||||
attr Master dev-timing-sendDelay 0
|
||||
attr Master dev-timing-commDelay 0
|
||||
attr Master dev-h-combine 19
|
||||
attr Master dev-c-combine 32
|
||||
|
30
fhem/t/FHEM/98_Modbus/61_SendRaw.t
Normal file
30
fhem/t/FHEM/98_Modbus/61_SendRaw.t
Normal file
@ -0,0 +1,30 @@
|
||||
##############################################
|
||||
# test master slave end to end
|
||||
# also map, min max, ...
|
||||
##############################################
|
||||
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
use Time::HiRes qw( gettimeofday tv_interval); # return time as float, not just full seconds
|
||||
use FHEM::HTTPMOD::Utils qw(:all);
|
||||
use FHEM::Modbus::TestUtils qw(:all);
|
||||
|
||||
fhem 'attr global mseclog 1';
|
||||
NextStep();
|
||||
|
||||
sub testStep1 {
|
||||
fhem 'attr Master disable 0';
|
||||
fhem 'set Master sendRaw 63'; # dec 99
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
sub testStep2 {
|
||||
is(FhemTestUtils_gotLog('Send 05e301e931'), 1, "saw sending");
|
||||
return 0.1;
|
||||
}
|
||||
|
||||
|
||||
1;
|
@ -1,5 +1,6 @@
|
||||
##############################################
|
||||
# test parsing
|
||||
# perl /opt/fhem/fhem.pl -t /opt/fhem/t/...
|
||||
##############################################
|
||||
|
||||
use strict;
|
||||
|
Loading…
x
Reference in New Issue
Block a user