Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Lesson1-phone-network-code
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Pôle Jeune
Formations réseau
Lesson1-phone-network-code
Merge requests
!1
feat: add state machine phone network
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Imported
feat: add state machine phone network
feature/state_machine
into
master
Overview
0
Commits
2
Pipelines
0
Changes
8
Merged
Imported
Clubelek Asso
requested to merge
feature/state_machine
into
master
5 years ago
Overview
0
Commits
2
Pipelines
0
Changes
8
Expand
Taken existing working code and used it to create a state machine.
Edited
5 years ago
by
Clubelek Asso
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
2791563d
2 commits,
5 years ago
8 files
+
415
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
8
Search (e.g. *.vue) (Ctrl+P)
src/PhoneNetwork.cc
0 → 100644
+
83
−
0
Options
#include
"PhoneNetwork.hh"
PhoneNetwork
::
PhoneNetwork
()
:
m_state
(
WAITING
),
m_switch
(),
m_communication
({
-
1
,
-
1
})
{
}
void
PhoneNetwork
::
changeState
(
State
targetState
)
{
switch
(
m_state
)
{
case
(
WAITING
):
break
;
case
(
DIALING
):
break
;
case
(
RINGING
):
m_switch
.
stop_ring
();
break
;
case
(
COMMUNICATING
):
break
;
}
switch
(
targetState
)
{
case
(
WAITING
):
Serial
.
println
(
"Move to state WAITING
\n
"
);
m_switch
.
resetLines
();
break
;
case
(
DIALING
):
Serial
.
println
(
"Move to state DIALING
\n
"
);
m_communication
.
caller
=
m_switch
.
getActiveLine
();
m_switch
.
setLineMode
(
DIALING
,
m_communication
.
caller
);
break
;
case
(
RINGING
):
Serial
.
println
(
"Move to state RINGING
\n
"
);
m_switch
.
setLineMode
(
RINGING
,
m_communication
.
called
);
m_switch
.
start_ring
();
break
;
case
(
COMMUNICATING
):
Serial
.
println
(
"Move to state COMMUNICATING
\n
"
);
m_switch
.
setLineMode
(
COMMUNICATING
,
m_communication
.
called
,
m_communication
.
caller
);
break
;
}
m_state
=
targetState
;
}
void
PhoneNetwork
::
run
()
{
m_switch
.
refreshLinesState
();
Serial
.
println
(
String
(
m_switch
.
m_linesState
[
0
])
+
String
(
m_switch
.
m_linesState
[
1
])
+
String
(
m_switch
.
m_linesState
[
2
]));
switch
(
m_state
)
{
case
(
WAITING
):
if
(
m_switch
.
phoneUnhooked
())
{
changeState
(
DIALING
);
}
break
;
case
(
DIALING
):
m_communication
.
called
=
m_switch
.
getDialedLine
(
m_communication
.
caller
);
if
(
m_switch
.
dialedComplete
(
m_communication
.
called
)){
changeState
(
RINGING
);
}
else
if
(
!
m_switch
.
phoneUnhooked
())
{
changeState
(
WAITING
);
}
break
;
case
(
RINGING
):
m_switch
.
ring
();
if
(
m_switch
.
phoneUnhooked
(
m_communication
.
called
))
{
changeState
(
COMMUNICATING
);
}
else
if
(
!
m_switch
.
phoneUnhooked
())
{
changeState
(
WAITING
);
}
break
;
case
(
COMMUNICATING
):
if
(
!
m_switch
.
phoneUnhooked
(
m_communication
.
caller
)){
changeState
(
WAITING
);
}
break
;
}
}