mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-13 11:16:36 +00:00
98_Modbus: more / optimized tests
git-svn-id: https://svn.fhem.de/fhem/trunk@23624 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
31e3e5f2f2
commit
1310600d2c
@ -1,3 +1,5 @@
|
|||||||
|
attr global mseclog 1
|
||||||
|
|
||||||
define MS Modbus none
|
define MS Modbus none
|
||||||
attr MS verbose 4
|
attr MS verbose 4
|
||||||
attr MS clientSwitchDelay 0
|
attr MS clientSwitchDelay 0
|
||||||
|
@ -42,7 +42,7 @@ SetTestOptions(
|
|||||||
Time1Name => 'Sending',
|
Time1Name => 'Sending',
|
||||||
Time1Regex => qr{MS:\sSimulate\ssending},
|
Time1Regex => qr{MS:\sSimulate\ssending},
|
||||||
Time2Name => 'Reception',
|
Time2Name => 'Reception',
|
||||||
Time2Regex => qr{ParseFrameStart\s\(RTU\)\sextracted\sid},
|
Time2Regex => qr{ParseFrameStart\s\(RTU.*\)\sextracted\sid},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
attr global mseclog 1
|
||||||
|
|
||||||
define MS Modbus none
|
define MS Modbus none
|
||||||
attr MS verbose 5
|
attr MS verbose 5
|
||||||
attr MS clientSwitchDelay 0
|
attr MS clientSwitchDelay 0
|
||||||
|
@ -11,11 +11,12 @@ use Time::HiRes qw( gettimeofday tv_interval); # return time as flo
|
|||||||
use FHEM::HTTPMOD::Utils qw(:all);
|
use FHEM::HTTPMOD::Utils qw(:all);
|
||||||
use FHEM::Modbus::TestUtils qw(:all);
|
use FHEM::Modbus::TestUtils qw(:all);
|
||||||
|
|
||||||
fhem 'attr global mseclog 1';
|
|
||||||
NextStep();
|
NextStep();
|
||||||
|
|
||||||
|
|
||||||
sub testStep1 {
|
sub testStep1 {
|
||||||
|
fhem 'attr MS verbose 4';
|
||||||
|
fhem 'attr PWP verbose 4';
|
||||||
LogStep('start reread');
|
LogStep('start reread');
|
||||||
FhemTestUtils_resetLogs();
|
FhemTestUtils_resetLogs();
|
||||||
fhem('set PWP reread');
|
fhem('set PWP reread');
|
||||||
@ -114,8 +115,57 @@ sub testStep10 {
|
|||||||
sub testStep11 {
|
sub testStep11 {
|
||||||
LogStep('check results');
|
LogStep('check results');
|
||||||
is(FhemTestUtils_gotLog('Simulate sending to none: 05030100000305b3'), 1, "request for 256 and 258 without 260 seen");
|
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
|
||||||
|
return 0.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep20 {
|
||||||
|
LogStep('new request for response with added 0');
|
||||||
|
FhemTestUtils_resetLogs();
|
||||||
|
FhemTestUtils_resetEvents();
|
||||||
|
fhem 'attr PWP obj-h500-reading dummy500';
|
||||||
|
fhem 'attr PWP obj-h501-reading dummy501';
|
||||||
|
fhem 'attr PWP nonPrioritizedGet 1';
|
||||||
|
fhem('get PWP dummy500');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testStep21 {
|
||||||
|
LogStep('simulate reception of broken response with added 0');
|
||||||
|
fhem 'attr PWP verbose 5';
|
||||||
|
SimRead('MS', '050302013709c200');
|
||||||
|
return 0.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testStep22 {
|
||||||
|
LogStep('check reception of response with added 0');
|
||||||
|
is(FhemTestUtils_gotLog('ParseObj 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");
|
||||||
|
fhem 'attr PWP verbose 3';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testStep23 {
|
||||||
|
LogStep('next normal request');
|
||||||
|
FhemTestUtils_resetLogs();
|
||||||
|
FhemTestUtils_resetEvents();
|
||||||
|
fhem('get PWP dummy500');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testStep24 {
|
||||||
|
LogStep('simulate normal reception again');
|
||||||
|
SimRead('MS', '050302013709c2');
|
||||||
|
return 0.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testStep25 {
|
||||||
|
LogStep('check final normal reception');
|
||||||
|
is(FhemTestUtils_gotEvent(qr/PWP:dummy500:\s311/xms), 1, "Parse h500");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
136
fhem/t/FHEM/98_Modbus/43_SlaveRTU.cfg
Normal file
136
fhem/t/FHEM/98_Modbus/43_SlaveRTU.cfg
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
attr global mseclog 1
|
||||||
|
|
||||||
|
define D1 dummy
|
||||||
|
|
||||||
|
define ModbusIO1 Modbus none
|
||||||
|
attr ModbusIO1 verbose 5
|
||||||
|
|
||||||
|
define ModbusIO2 Modbus none
|
||||||
|
attr ModbusIO2 verbose 5
|
||||||
|
|
||||||
|
define Slave ModbusAttr 5 slave
|
||||||
|
attr Slave IODev ModbusIO1
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
attr Slave obj-c400-reading c0
|
||||||
|
attr Slave obj-c401-reading c1
|
||||||
|
attr Slave obj-c402-reading c2
|
||||||
|
attr Slave obj-c403-reading c3
|
||||||
|
attr Slave obj-c404-reading c4
|
||||||
|
attr Slave obj-c405-reading c5
|
||||||
|
attr Slave obj-c406-reading c6
|
||||||
|
attr Slave obj-c407-reading c7
|
||||||
|
attr Slave obj-c408-reading c8
|
||||||
|
attr Slave obj-c409-reading c9
|
||||||
|
attr Slave obj-c410-reading c10
|
||||||
|
attr Slave obj-c411-reading c11
|
||||||
|
attr Slave obj-c412-reading c12
|
||||||
|
attr Slave obj-c413-reading c13
|
||||||
|
attr Slave obj-c414-reading c14
|
||||||
|
attr Slave obj-c415-reading c15
|
||||||
|
attr Slave obj-c416-reading c16
|
||||||
|
attr Slave obj-c417-reading c17
|
||||||
|
attr Slave obj-c418-reading c18
|
||||||
|
|
||||||
|
|
||||||
|
define Master ModbusAttr 5 0
|
||||||
|
attr Master IODev ModbusIO2
|
||||||
|
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 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
|
||||||
|
|
||||||
|
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 dev-h-defSet 1
|
||||||
|
attr Master dev-c-defSet 1
|
||||||
|
attr Master dev-h-defShowGet 1
|
||||||
|
|
||||||
|
attr Master obj-c400-reading c0
|
||||||
|
attr Master obj-c401-reading c1
|
||||||
|
attr Master obj-c402-reading c2
|
||||||
|
attr Master obj-c403-reading c3
|
||||||
|
attr Master obj-c404-reading c4
|
||||||
|
attr Master obj-c405-reading c5
|
||||||
|
attr Master obj-c406-reading c6
|
||||||
|
attr Master obj-c407-reading c7
|
||||||
|
attr Master obj-c408-reading c8
|
||||||
|
attr Master obj-c409-reading c9
|
||||||
|
attr Master obj-c410-reading c10
|
||||||
|
attr Master obj-c411-reading c11
|
||||||
|
attr Master obj-c412-reading c12
|
||||||
|
attr Master obj-c413-reading c13
|
||||||
|
attr Master obj-c414-reading c14
|
||||||
|
attr Master obj-c415-reading c15
|
||||||
|
attr Master obj-c416-reading c16
|
||||||
|
attr Master obj-c417-reading c17
|
||||||
|
attr Master obj-c418-reading c18
|
||||||
|
|
||||||
|
attr Master obj-c400-poll 1
|
||||||
|
attr Master obj-c405-poll 1
|
||||||
|
attr Master obj-c406-poll 1
|
||||||
|
attr Master obj-c417-poll 1
|
||||||
|
|
||||||
|
attr Master dev-h-combine 19
|
||||||
|
attr Master dev-c-combine 32
|
119
fhem/t/FHEM/98_Modbus/43_SlaveRTU.t
Normal file
119
fhem/t/FHEM/98_Modbus/43_SlaveRTU.t
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
##############################################
|
||||||
|
# test RTU slave
|
||||||
|
##############################################
|
||||||
|
|
||||||
|
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 "set values at Slave";
|
||||||
|
fhem 'setreading Slave TempWasserEin 12';
|
||||||
|
fhem 'setreading Slave Test1 1';
|
||||||
|
fhem 'setreading Slave Test2 2.123';
|
||||||
|
fhem 'setreading Slave Test3 abcdefg';
|
||||||
|
fhem 'setreading Slave Test4 40';
|
||||||
|
fhem 'setreading Slave c0 1';
|
||||||
|
fhem 'setreading Slave c5 1';
|
||||||
|
fhem 'setreading Slave c17 1';
|
||||||
|
fhem 'attr Slave verbose 5';
|
||||||
|
|
||||||
|
fhem 'attr Master disable 0';
|
||||||
|
fhem 'attr Master verbose 5';
|
||||||
|
readingsSingleUpdate($defs{'Slave'}, 'Test5', pack('H*', 'e4f6fc'), 0);
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testStep2 {
|
||||||
|
LogStep "simulate get TempWasserEin";
|
||||||
|
#fhem 'attr Slave verbose 4';
|
||||||
|
SimRead('ModbusIO1', '0503010000018472'); # get TempWasserEin
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep3 {
|
||||||
|
is(FhemTestUtils_gotLog('ModbusIO1: Simulate sending to none: 050302000c4981'), 1, "correct reply 0 with temp 12");
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep4 {
|
||||||
|
LogStep "simulate get TempWasserEin with broken frame 1 (garbage in front";
|
||||||
|
FhemTestUtils_resetLogs();
|
||||||
|
FhemTestUtils_resetEvents();
|
||||||
|
SimRead('ModbusIO1', '010503010000018472');
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep5 {
|
||||||
|
is(FhemTestUtils_gotLog('ModbusIO1: Simulate sending to none: 050302000c4981'), 1, "correct reply 1 with temp 12");
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep6 {
|
||||||
|
LogStep "simulate get TempWasserEin with broken frame 2 (garbage at end";
|
||||||
|
FhemTestUtils_resetLogs();
|
||||||
|
FhemTestUtils_resetEvents();
|
||||||
|
SimRead('ModbusIO1', '05030100000184720505');
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep7 {
|
||||||
|
is(FhemTestUtils_gotLog('ModbusIO1: Simulate sending to none: 050302000c4981'), 1, "correct reply 2 with temp 12");
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep8 {
|
||||||
|
LogStep "simulate get TempWasserEin with broken frame 3 (garbage at end";
|
||||||
|
FhemTestUtils_resetLogs();
|
||||||
|
FhemTestUtils_resetEvents();
|
||||||
|
SimRead('ModbusIO1', '0503010000018472FF');
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep9 {
|
||||||
|
is(FhemTestUtils_gotLog('ModbusIO1: Simulate sending to none: 050302000c4981'), 1, "correct reply 3 with temp 12");
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep10 {
|
||||||
|
LogStep "simulate get TempWasserEin with broken frame 4 (garbage at start, skipGarbage";
|
||||||
|
FhemTestUtils_resetLogs();
|
||||||
|
FhemTestUtils_resetEvents();
|
||||||
|
fhem 'attr ModbusIO1 skipGarbage 1';
|
||||||
|
SimRead('ModbusIO1', '0708090503010000018472');
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep11 {
|
||||||
|
is(FhemTestUtils_gotLog('ModbusIO1: Simulate sending to none: 050302000c4981'), 1, "correct reply 3 with temp 12");
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep50 {
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
@ -115,7 +115,7 @@ sub testStep10 { # check combined read of holding registers and coils
|
|||||||
fhem ('attr Master verbose 3');
|
fhem ('attr Master verbose 3');
|
||||||
fhem ('attr Slave verbose 3');
|
fhem ('attr Slave verbose 3');
|
||||||
fhem ('set Master reread');
|
fhem ('set Master reread');
|
||||||
return 0.1;
|
return 0.15;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub testStep11 { # check results coming from slave and write coils to slave
|
sub testStep11 { # check results coming from slave and write coils to slave
|
||||||
@ -214,7 +214,7 @@ sub testStep20 {
|
|||||||
|
|
||||||
sub testStep21 {
|
sub testStep21 {
|
||||||
LogStep "check result after prio get";
|
LogStep "check result after prio get";
|
||||||
is(FhemTestUtils_gotLog('Master: read buffer: 050302000c4981'), 1, "answer arrives after readanswer timeout");
|
is(FhemTestUtils_gotLog('Master: read.* buffer: 050302000c4981'), 1, "answer arrives after readanswer timeout");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
126
fhem/t/FHEM/98_Modbus/51_Combine.cfg
Normal file
126
fhem/t/FHEM/98_Modbus/51_Combine.cfg
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
attr global mseclog 1
|
||||||
|
|
||||||
|
define Slave ModbusAttr 5 slave global:5501
|
||||||
|
attr Slave obj-h256-reading TempWasserEin
|
||||||
|
attr Slave obj-h258-reading 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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
attr Slave obj-c400-reading c0
|
||||||
|
attr Slave obj-c401-reading c1
|
||||||
|
attr Slave obj-c402-reading c2
|
||||||
|
attr Slave obj-c403-reading c3
|
||||||
|
attr Slave obj-c404-reading c4
|
||||||
|
attr Slave obj-c405-reading c5
|
||||||
|
attr Slave obj-c406-reading c6
|
||||||
|
attr Slave obj-c407-reading c7
|
||||||
|
attr Slave obj-c408-reading c8
|
||||||
|
attr Slave obj-c409-reading c9
|
||||||
|
attr Slave obj-c410-reading c10
|
||||||
|
attr Slave obj-c411-reading c11
|
||||||
|
attr Slave obj-c412-reading c12
|
||||||
|
attr Slave obj-c413-reading c13
|
||||||
|
attr Slave obj-c414-reading c14
|
||||||
|
attr Slave obj-c415-reading c15
|
||||||
|
attr Slave obj-c416-reading c16
|
||||||
|
attr Slave obj-c417-reading c17
|
||||||
|
attr Slave obj-c418-reading c18
|
||||||
|
|
||||||
|
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.5
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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 dev-h-defSet 1
|
||||||
|
attr Master dev-c-defSet 1
|
||||||
|
attr Master dev-h-defShowGet 1
|
||||||
|
|
||||||
|
attr Master obj-c400-reading c0
|
||||||
|
attr Master obj-c401-reading c1
|
||||||
|
attr Master obj-c402-reading c2
|
||||||
|
attr Master obj-c403-reading c3
|
||||||
|
attr Master obj-c404-reading c4
|
||||||
|
attr Master obj-c405-reading c5
|
||||||
|
attr Master obj-c406-reading c6
|
||||||
|
attr Master obj-c407-reading c7
|
||||||
|
attr Master obj-c408-reading c8
|
||||||
|
attr Master obj-c409-reading c9
|
||||||
|
attr Master obj-c410-reading c10
|
||||||
|
attr Master obj-c411-reading c11
|
||||||
|
attr Master obj-c412-reading c12
|
||||||
|
attr Master obj-c413-reading c13
|
||||||
|
attr Master obj-c414-reading c14
|
||||||
|
attr Master obj-c415-reading c15
|
||||||
|
attr Master obj-c416-reading c16
|
||||||
|
attr Master obj-c417-reading c17
|
||||||
|
attr Master obj-c418-reading c18
|
||||||
|
|
||||||
|
attr Master obj-c400-poll 1
|
||||||
|
attr Master obj-c405-poll 1
|
||||||
|
attr Master obj-c406-poll 1
|
||||||
|
attr Master obj-c417-poll 1
|
||||||
|
|
||||||
|
attr Master dev-h-combine 19
|
||||||
|
attr Master dev-c-combine 32
|
68
fhem/t/FHEM/98_Modbus/51_Combine.t
Normal file
68
fhem/t/FHEM/98_Modbus/51_Combine.t
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
##############################################
|
||||||
|
# test master slave end to end
|
||||||
|
##############################################
|
||||||
|
|
||||||
|
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');
|
||||||
|
fhem ('setreading Slave Test1 1');
|
||||||
|
fhem ('setreading Slave Test2 2.123');
|
||||||
|
fhem ('setreading Slave Test3 abcdefg');
|
||||||
|
fhem ('setreading Slave Test4 40');
|
||||||
|
fhem ('setreading Slave c0 1');
|
||||||
|
fhem ('setreading Slave c5 1');
|
||||||
|
fhem ('setreading Slave c17 1');
|
||||||
|
readingsSingleUpdate($defs{'Slave'}, 'Test5', pack('H*', 'e4f6fc'), 0);
|
||||||
|
fhem ('attr Master verbose 4');
|
||||||
|
fhem ('attr Slave verbose 3');
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep10 { # check combined read of holding registers and coils
|
||||||
|
LogStep "getUpdate with combine";
|
||||||
|
FhemTestUtils_resetEvents();
|
||||||
|
fhem ('set Master reread');
|
||||||
|
return 0.2;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testStep11 { # check results coming from slave
|
||||||
|
is(FhemTestUtils_gotEvent(qr/Master:Test1: 6/), 1, "Combined retrieve integer value with expressions on both sides from local slave");
|
||||||
|
is(FhemTestUtils_gotEvent(qr/Master:Test2: 2.12/), 1, "Combined retrieve float value from local slave");
|
||||||
|
is(FhemTestUtils_gotEvent(qr/Master:Test3: abcdefg/), 1, "Combined Retrieve ascii value from local slave");
|
||||||
|
is(FhemTestUtils_gotEvent(qr/Master:c0: 1/), 1, "Combined Retrieve coil bit 0 from local slave");
|
||||||
|
is(FhemTestUtils_gotEvent(qr/Master:c1: 0/), 1, "Combined Retrieve coil bit 1 from local slave");
|
||||||
|
is(FhemTestUtils_gotEvent(qr/Master:c17: 1/), 1, "Combined Retrieve coil bit 17 from local slave");
|
||||||
|
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testStep20 { # check timeout handling / logging
|
||||||
|
LogStep "getUpdate with timeout";
|
||||||
|
FhemTestUtils_resetEvents();
|
||||||
|
fhem 'defmod Slave ModbusAttr 55 slave global:5501';
|
||||||
|
fhem 'set Master reread';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep21 { # check results coming from slave
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
1;
|
@ -201,6 +201,8 @@ sub testStep19 {
|
|||||||
fhem ('attr Master nonPrioritizedGet 0');
|
fhem ('attr Master nonPrioritizedGet 0');
|
||||||
fhem ('attr Master dev-timing-timeout 0.5');
|
fhem ('attr Master dev-timing-timeout 0.5');
|
||||||
fhem ('attr Master verbose 5');
|
fhem ('attr Master verbose 5');
|
||||||
|
fhem ('attr Slave verbose 5');
|
||||||
|
fhem ('attr Relay verbose 5');
|
||||||
fhem ('get Master TempWasserEin');
|
fhem ('get Master TempWasserEin');
|
||||||
return 0.1;
|
return 0.1;
|
||||||
}
|
}
|
||||||
@ -209,12 +211,12 @@ sub testStep20 {
|
|||||||
LogStep "check result after prio get";
|
LogStep "check result after prio get";
|
||||||
is(FhemTestUtils_gotLog('device opened'), 1, "device opened");
|
is(FhemTestUtils_gotLog('device opened'), 1, "device opened");
|
||||||
is(FhemTestUtils_gotLog('Master: Timeout in Readanswer'), 1, "readanswer called but slave cannot answer while sitting in readanswer");
|
is(FhemTestUtils_gotLog('Master: Timeout in Readanswer'), 1, "readanswer called but slave cannot answer while sitting in readanswer");
|
||||||
return;
|
return 0.1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub testStep21 {
|
sub testStep21 {
|
||||||
LogStep "check result after prio get";
|
LogStep "check result after prio get";
|
||||||
is(FhemTestUtils_gotLog('Master: read buffer: 050302000c4981'), 1, "answer arrives after readanswer timeout");
|
is(FhemTestUtils_gotLog('Master: read.* buffer: 050302000c4981'), 1, "answer arrives after readanswer timeout");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
attr global mseclog 1
|
attr global mseclog 1
|
||||||
|
|
||||||
define D1 dummy
|
define D1 dummy
|
||||||
|
|
||||||
define Slave ModbusAttr 50 slave global:5501 ASCII
|
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-h256-reading TempWasserEin
|
||||||
attr Slave obj-h258-reading D1:TempWasserAus
|
attr Slave obj-h258-reading D1:TempWasserAus
|
||||||
|
|
||||||
|
@ -11,11 +11,9 @@ use Time::HiRes qw( gettimeofday tv_interval); # return time as float, not
|
|||||||
use FHEM::HTTPMOD::Utils qw(:all);
|
use FHEM::HTTPMOD::Utils qw(:all);
|
||||||
use FHEM::Modbus::TestUtils qw(:all);
|
use FHEM::Modbus::TestUtils qw(:all);
|
||||||
|
|
||||||
fhem 'attr global mseclog 1';
|
NextStep(); # start with the first testStep function and then automatically give some time to Fhem before the next step
|
||||||
NextStep();
|
|
||||||
|
|
||||||
sub testStep1 { # preparation of slave content, enable devices
|
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";
|
LogStep "enable Master and set value at Slave";
|
||||||
fhem ('attr RM disable 0');
|
fhem ('attr RM disable 0');
|
||||||
fhem ('attr Relay disable 0');
|
fhem ('attr Relay disable 0');
|
||||||
@ -30,10 +28,10 @@ sub testStep1 { # preparation of slave content, enable devices
|
|||||||
fhem ('setreading Slave c0 1');
|
fhem ('setreading Slave c0 1');
|
||||||
fhem ('setreading Slave c5 1');
|
fhem ('setreading Slave c5 1');
|
||||||
fhem ('setreading Slave c17 1');
|
fhem ('setreading Slave c17 1');
|
||||||
return 0.1;
|
return 0.1; # ask for an internalTimer to call the next step after 0.1 seconds.
|
||||||
}
|
}
|
||||||
|
|
||||||
sub testStep2 { # get holding registers
|
sub testStep2 { # get holding registers
|
||||||
LogStep "get TempWasserEin";
|
LogStep "get TempWasserEin";
|
||||||
fhem ('attr Master verbose 3');
|
fhem ('attr Master verbose 3');
|
||||||
fhem ('attr Slave verbose 3');
|
fhem ('attr Slave verbose 3');
|
||||||
@ -129,7 +127,7 @@ sub testStep11 { # check results coming from slave and write coils to slave
|
|||||||
fhem ('attr Slave obj-c402-allowWrite 1');
|
fhem ('attr Slave obj-c402-allowWrite 1');
|
||||||
fhem ('attr Master verbose 5');
|
fhem ('attr Master verbose 5');
|
||||||
fhem ('set Master c2 1');
|
fhem ('set Master c2 1');
|
||||||
return 0.1;
|
return 0.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub testStep12 {
|
sub testStep12 {
|
||||||
@ -159,7 +157,7 @@ sub testStep14 {
|
|||||||
fhem ('attr Master closeAfterResponse 1');
|
fhem ('attr Master closeAfterResponse 1');
|
||||||
fhem ('attr Master verbose 4');
|
fhem ('attr Master verbose 4');
|
||||||
fhem ('set Master reread');
|
fhem ('set Master reread');
|
||||||
return 0.1;
|
return 0.2;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub testStep15 {
|
sub testStep15 {
|
||||||
@ -213,7 +211,7 @@ sub testStep20 {
|
|||||||
|
|
||||||
sub testStep21 {
|
sub testStep21 {
|
||||||
LogStep "check result after prio get";
|
LogStep "check result after prio get";
|
||||||
is(FhemTestUtils_gotLog('Master: read buffer: 050302000c4981'), 1, "answer arrives after readanswer timeout");
|
is(FhemTestUtils_gotLog('Master: read.* buffer: 050302000c4981'), 1, "answer arrives after readanswer timeout");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
53
fhem/t/FHEM/98_Modbus/56_Scan.cfg
Normal file
53
fhem/t/FHEM/98_Modbus/56_Scan.cfg
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
attr global mseclog 1
|
||||||
|
|
||||||
|
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-h100-setexpr $val * 4
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
attr Slave obj-c400-reading c0
|
||||||
|
attr Slave obj-c401-reading c1
|
||||||
|
attr Slave obj-c402-reading c2
|
||||||
|
attr Slave obj-c403-reading c3
|
||||||
|
attr Slave obj-c404-reading c4
|
||||||
|
attr Slave obj-c405-reading c5
|
||||||
|
attr Slave obj-c406-reading c6
|
||||||
|
attr Slave obj-c407-reading c7
|
||||||
|
attr Slave obj-c408-reading c8
|
||||||
|
attr Slave obj-c409-reading c9
|
||||||
|
attr Slave obj-c410-reading c10
|
||||||
|
attr Slave obj-c411-reading c11
|
||||||
|
attr Slave obj-c412-reading c12
|
||||||
|
attr Slave obj-c413-reading c13
|
||||||
|
attr Slave obj-c414-reading c14
|
||||||
|
attr Slave obj-c415-reading c15
|
||||||
|
attr Slave obj-c416-reading c16
|
||||||
|
attr Slave obj-c417-reading c17
|
||||||
|
attr Slave obj-c418-reading c18
|
||||||
|
|
||||||
|
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
|
80
fhem/t/FHEM/98_Modbus/56_Scan.t
Normal file
80
fhem/t/FHEM/98_Modbus/56_Scan.t
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
##############################################
|
||||||
|
# test master slave end to end
|
||||||
|
##############################################
|
||||||
|
|
||||||
|
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');
|
||||||
|
fhem ('setreading Slave Test1 1'); # h100 (*4 -> 4)
|
||||||
|
fhem ('setreading Slave Test2 2.123'); # h101
|
||||||
|
fhem ('setreading Slave Test3 abcdefg'); # h103
|
||||||
|
fhem ('setreading Slave Test4 40'); # h120
|
||||||
|
readingsSingleUpdate($defs{'Slave'}, 'Test5', pack('H*', 'e4f6fc'), 0); # h130
|
||||||
|
|
||||||
|
fhem ('setreading Slave c0 1');
|
||||||
|
fhem ('setreading Slave c5 1');
|
||||||
|
fhem ('setreading Slave c17 1');
|
||||||
|
return 0.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testStep2 {
|
||||||
|
LogStep "Start Scan h";
|
||||||
|
fhem ('attr Master verbose 3');
|
||||||
|
fhem ('attr Slave verbose 3');
|
||||||
|
fhem ('attr Master scanDelay 0.1');
|
||||||
|
fhem ('set Master scanModbusObjects h100-105');
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testStep3 {
|
||||||
|
is(FhemTestUtils_gotEvent('scan-h00100: .*s>=4'), 1, "got h100 correctly");
|
||||||
|
is(FhemTestUtils_gotEvent('scan-h00101: .*hex=4007'), 1, "got h101 correctly");
|
||||||
|
is(FhemTestUtils_gotEvent('scan-h00103: .*hex=6162'), 1, "got h103 correctly");
|
||||||
|
CheckAndReset();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testStep5 {
|
||||||
|
fhem ('set Master scanModbusObjects h100-105 2');
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testStep6 {
|
||||||
|
is(FhemTestUtils_gotEvent('scan-h00100: .*s>=4'), 1, "got h100 len 2 correctly");
|
||||||
|
is(FhemTestUtils_gotEvent('scan-h00101: .*f>=2.12'), 1, "got h101 len 2 correctly");
|
||||||
|
is(FhemTestUtils_gotEvent('scan-h00103: .*string=abcd'), 1, "got h103 len 2 correctly");
|
||||||
|
CheckAndReset();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub testStep7 {
|
||||||
|
#fhem ('attr Master verbose 5');
|
||||||
|
#fhem ('attr Slave verbose 5');
|
||||||
|
fhem ('attr Master dev-timing-timeout 0.3');
|
||||||
|
fhem ('set Master scanModbusId 1-8 h100');
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub testStep10 {
|
||||||
|
#fhem 'list Master';
|
||||||
|
is(FhemTestUtils_gotEvent('scanId-5-Response-h100: .*s>=4'), 1, "got h100 scanid response");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
1;
|
Loading…
x
Reference in New Issue
Block a user