Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uni_ete_hepialight_mqtt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jonas.stirnema
uni_ete_hepialight_mqtt
Commits
efe7cfbc
Commit
efe7cfbc
authored
1 year ago
by
nicolas.albanesi
Browse files
Options
Downloads
Patches
Plain Diff
Mapping not yet working
parent
378d7fff
Branches
Branches containing commit
No related tags found
1 merge request
!1
merge Nico
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mapping/main.py
+72
-10
72 additions, 10 deletions
mapping/main.py
with
72 additions
and
10 deletions
mapping/main.py
+
72
−
10
View file @
efe7cfbc
id
=
[
0
,
0
]
id
=
[
0
,
0
]
def
display_id
():
def
display_id
():
afficher_texte
(
"
{}, {}
"
.
format
(
id
[
0
],
id
[
1
]),
speed
=
0.
0
01
)
afficher_texte
(
"
{}, {}
"
.
format
(
id
[
0
],
id
[
1
]),
speed
=
0.01
)
def
msg_to_str
(
msg
):
def
msg_to_str
(
msg
):
return
str
(
msg
)[
2
:
-
1
]
return
str
(
msg
)[
2
:
-
1
]
def
send_passthrough
(
msg
,
x
,
y
):
def
handle_receive
(
msg
,
dir
):
x
=
int
(
x
)
y
=
int
(
y
)
newx
=
x
newy
=
y
if
x
>
id
[
0
]:
d
=
O
newx
+=
1
elif
x
<
id
[
0
]:
d
=
E
newx
-=
1
elif
y
>
id
[
1
]:
d
=
S
newy
+=
1
else
:
d
=
N
newy
-=
1
envoyer_msg
(
d
,
"
PT;{},{};{}
"
.
format
(
newx
,
newy
,
msg
))
def
send_xy
(
x
,
y
,
msg
):
send_passthrough
(
msg
,
x
,
y
)
def
check_presence
(
d
):
envoyer_msg
(
d
,
"
PING
"
)
time
.
sleep
(
0.05
)
ret
=
recevoir_msg
(
d
)
print
(
"
checking pres for {} : {}
"
.
format
(
d
,
ret
))
if
ret
==
b
""
:
return
False
return
True
def
update_id
(
new_id
):
global
id
global
id
id
[
0
]
=
int
(
new_id
[
0
])
id
[
1
]
=
int
(
new_id
[
1
])
envoyer_msg
(
N
,
"
SET_ID:{},{}
"
.
format
(
id
[
0
],
id
[
1
]
+
1
))
envoyer_msg
(
E
,
"
SET_ID:{},{}
"
.
format
(
id
[
0
]
+
1
,
id
[
1
]))
if
not
check_presence
(
N
)
and
not
check_presence
(
E
):
send_xy
(
0
,
0
,
"
MATSIZE:{},{}
"
.
format
(
id
[
0
],
id
[
1
]))
display_id
()
def
handle_receive
(
msg
,
d
):
msg
=
msg_to_str
(
msg
)
msg
=
msg_to_str
(
msg
)
if
msg
.
startswith
(
"
SET_ID
"
):
if
msg
.
startswith
(
"
SET_ID
"
):
id
=
msg
[
7
:].
split
(
"
,
"
)
tmp_
id
=
msg
[
7
:].
split
(
"
,
"
)
display
_id
(
)
update_id
(
tmp
_id
)
elif
msg
==
"
PING
"
:
elif
msg
==
"
PING
"
:
envoyer_msg
(
d
ir
,
"
PONG
"
)
envoyer_msg
(
d
,
"
PONG
"
)
elif
msg
==
"
DISP_ID
"
:
elif
msg
==
"
DISP_ID
"
:
display_id
()
display_id
()
elif
msg
.
startswith
(
"
PT;
"
):
print
(
msg
)
msgs
=
msg
.
split
(
"
;
"
)
m
=
msgs
[
2
]
x
,
y
=
msgs
[
1
].
split
(
"
,
"
)
if
x
==
id
[
0
]
and
y
==
id
[
1
]:
handle_receive
(
m
,
d
)
return
send_passthrough
(
m
,
int
(
x
),
int
(
y
))
afficher_texte
(
"
Ready
"
,
VERT
,
speed
=
0.01
)
afficher_texte
(
"
Ready
"
,
VERT
,
speed
=
0.01
)
while
True
:
while
True
:
msg
=
recevoir_msg
(
S
)
handle_receive
(
msg
,
S
)
for
d
in
[
N
,
S
,
E
,
O
]:
time
.
sleep
(
0.5
)
msg
=
recevoir_msg
(
d
)
handle_receive
(
msg
,
d
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment