Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
17792ffe
Commit
17792ffe
authored
Jul 26, 2017
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Pulse): небольшой рефакторинг интерфейса
next_step() --> setTiming()
parent
7b3d01f0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
66 deletions
+89
-66
Pulse.h
include/Pulse.h
+15
-13
test_pulse.cc
tests/test_pulse.cc
+74
-53
No files found.
include/Pulse.h
View file @
17792ffe
...
...
@@ -35,24 +35,21 @@ namespace uniset
class
Pulse
{
public
:
Pulse
()
noexcept
{}
~
Pulse
()
noexcept
{}
// t1_msec - интервал "вкл"
// t0_msec - интерфал "откл"
inline
void
run
(
timeout_t
_t1_msec
,
timeout_t
_t0_msec
)
noexcept
{
t1_msec
=
_t1_msec
;
t0_msec
=
_t0_msec
;
t1
.
setTiming
(
t1_msec
);
t0
.
setTiming
(
t0_msec
);
set
(
true
);
setTiming
(
_t1_msec
,
_t0_msec
,
true
);
}
inline
void
set
_next
(
timeout_t
_t1_msec
,
timeout_t
_t0_msec
)
noexcept
inline
void
set
Timing
(
timeout_t
_t1_msec
,
timeout_t
_t0_msec
,
bool
run
=
false
)
noexcept
{
t1_msec
=
_t1_msec
;
t0_msec
=
_t0_msec
;
t1
.
setTiming
(
t1_msec
);
t0
.
setTiming
(
t0_msec
);
set
(
run
);
}
inline
void
reset
()
noexcept
...
...
@@ -62,7 +59,7 @@ namespace uniset
inline
bool
step
()
noexcept
{
if
(
!
isOn
)
if
(
!
enabled
)
{
ostate
=
false
;
return
false
;
...
...
@@ -90,9 +87,9 @@ namespace uniset
inline
void
set
(
bool
state
)
noexcept
{
isOn
=
state
;
enabled
=
state
;
if
(
!
isOn
)
if
(
!
enabled
)
ostate
=
false
;
else
{
...
...
@@ -104,7 +101,7 @@ namespace uniset
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
Pulse
&
p
)
{
return
os
<<
" idOn="
<<
p
.
isOn
return
os
<<
" idOn="
<<
p
.
enabled
<<
" t1="
<<
p
.
t1
.
getInterval
()
<<
" t0="
<<
p
.
t0
.
getInterval
()
<<
" out="
<<
p
.
out
();
...
...
@@ -124,11 +121,16 @@ namespace uniset
return
t0_msec
;
}
bool
isOn
()
const
noexcept
{
return
enabled
;
}
protected
:
PassiveTimer
t1
;
// таймер "1"
PassiveTimer
t0
;
// таймер "0"
bool
ostate
=
{
false
};
bool
isOn
=
{
false
};
bool
enabled
=
{
false
};
timeout_t
t1_msec
=
{
0
};
timeout_t
t0_msec
=
{
0
};
...
...
tests/test_pulse.cc
View file @
17792ffe
...
...
@@ -4,70 +4,91 @@
#include "UniSetTypes.h"
using
namespace
std
;
using
namespace
uniset
;
TEST_CASE
(
"Pulse
"
,
"[Test for class 'Pulse' - impulse generator
]"
)
// -----------------------------------------------------------------------------
TEST_CASE
(
"Pulse
: default"
,
"[pulse][default
]"
)
{
SECTION
(
"Default constructor"
)
{
// Работа без задержки..(нулевые задержки)
Pulse
p
;
// Работа без задержки..(нулевые задержки)
Pulse
p
;
REQUIRE
(
p
.
getT1
()
==
0
);
REQUIRE
(
p
.
getT0
()
==
0
);
REQUIRE
(
p
.
getT1
()
==
0
);
REQUIRE
(
p
.
getT0
()
==
0
);
CHECK_FALSE
(
p
.
out
()
);
CHECK_FALSE
(
p
.
out
()
);
p
.
step
();
p
.
step
();
CHECK_FALSE
(
p
.
out
()
);
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"Pulse: basic tests"
,
"[pulse][basic]"
)
{
Pulse
p
;
p
.
run
(
100
,
60
);
// 100 msec ON..60 msec OFF
CHECK
(
p
.
step
()
);
p
.
step
();
p
.
step
();
CHECK_FALSE
(
p
.
out
()
);
}
msleep
(
80
);
CHECK
(
p
.
step
()
);
SECTION
(
"Working"
)
{
Pulse
p
;
p
.
run
(
100
,
60
);
// 100 msec ON..60 msec OFF
CHECK
(
p
.
step
()
);
msleep
(
30
);
CHECK_FALSE
(
p
.
step
()
);
// 10 - OFF
msleep
(
8
0
);
CHECK
(
p
.
step
()
);
msleep
(
7
0
);
CHECK
(
p
.
step
()
);
// 20 - ON
msleep
(
3
0
);
CHECK_FALSE
(
p
.
step
()
);
// 10 -
OFF
msleep
(
10
0
);
CHECK_FALSE
(
p
.
step
()
);
// 20
OFF
msleep
(
70
);
CHECK
(
p
.
step
()
);
// 20 - ON
p
.
set
(
false
);
msleep
(
100
);
CHECK_FALSE
(
p
.
step
()
);
msleep
(
60
);
CHECK_FALSE
(
p
.
step
()
);
msleep
(
100
);
CHECK_FALSE
(
p
.
step
()
);
// 20 OFF
p
.
set
(
true
);
msleep
(
70
);
CHECK
(
p
.
step
()
);
msleep
(
40
);
CHECK_FALSE
(
p
.
step
()
);
p
.
set
(
false
);
msleep
(
100
);
CHECK_FALSE
(
p
.
step
()
);
msleep
(
60
);
CHECK_FALSE
(
p
.
step
()
);
p
.
reset
();
CHECK
(
p
.
step
()
);
msleep
(
110
);
CHECK_FALSE
(
p
.
step
()
);
// проверка того, что при познем вызове step
// тоже всё будет хорошо..
p
.
reset
();
CHECK
(
p
.
step
()
);
msleep
(
110
);
CHECK_FALSE
(
p
.
step
()
);
msleep
(
2050
);
CHECK
(
p
.
step
()
);
msleep
(
110
);
CHECK_FALSE
(
p
.
step
()
);
msleep
(
70
);
CHECK
(
p
.
step
()
);
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"Pulse: ext tests"
,
"[pulse][ext]"
)
{
Pulse
p
;
p
.
setTiming
(
50
,
100
,
false
);
REQUIRE_FALSE
(
p
.
isOn
()
);
p
.
set
(
true
);
msleep
(
70
);
CHECK
(
p
.
step
()
);
msleep
(
40
);
CHECK_FALSE
(
p
.
step
()
);
p
.
set
(
true
);
REQUIRE
(
p
.
isOn
()
);
REQUIRE
(
p
.
step
()
);
msleep
(
60
);
REQUIRE_FALSE
(
p
.
step
()
);
msleep
(
110
);
REQUIRE
(
p
.
step
()
);
p
.
reset
();
CHECK
(
p
.
step
()
);
msleep
(
110
);
CHECK_FALSE
(
p
.
step
()
);
p
.
set
(
false
);
REQUIRE_FALSE
(
p
.
isOn
()
);
REQUIRE_FALSE
(
p
.
step
()
);
// проверка того, что при познем вызове step
// тоже всё будет хорошо..
p
.
reset
();
CHECK
(
p
.
step
()
);
msleep
(
110
);
CHECK_FALSE
(
p
.
step
()
);
msleep
(
2050
);
CHECK
(
p
.
step
()
);
msleep
(
110
);
CHECK_FALSE
(
p
.
step
()
);
msleep
(
70
);
CHECK
(
p
.
step
()
);
}
p
.
setTiming
(
50
,
100
,
true
);
REQUIRE
(
p
.
isOn
()
);
REQUIRE
(
p
.
step
()
);
}
// -----------------------------------------------------------------------------
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment