Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OC Robotique
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
Info_Sismondi
OC Robotique
Commits
2c302072
Commit
2c302072
authored
3 months ago
by
Vincent Namy (EDU_GE)
Browse files
Options
Downloads
Patches
Plain Diff
Fix Protocole v1.1
parent
0e6beaa9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Protocole/protocole.py
+22
-20
22 additions, 20 deletions
Protocole/protocole.py
with
22 additions
and
20 deletions
Protocole/protocole.py
+
22
−
20
View file @
2c302072
...
...
@@ -5,7 +5,6 @@ Version : 1.0
Date : 28.1.25
TODO :
- plusieurs messages
- passer trame en bytes ?
- doc string
- template
...
...
@@ -33,11 +32,11 @@ class Message:
self
.
exped
=
exped
self
.
dest
=
dest
self
.
seqNum
=
seqNum
self
.
msgId
=
msgId
self
.
payload
=
payload
self
.
crc
=
crc
self
.
msgId
=
msgId
def
msgStr
(
self
):
return
"
[n
"
+
str
(
self
.
seqNum
)
+
"
]
"
+
str
(
self
.
exped
)
+
"
->
"
+
str
(
self
.
dest
)
+
"
: type
"
+
str
(
self
.
msgId
)
+
"
:
"
+
str
(
self
.
payload
)
+
"
(crc=
"
+
str
(
self
.
crc
)
+
"
)
"
return
str
(
self
.
exped
)
+
"
->
"
+
str
(
self
.
dest
)
+
"
n[
"
+
str
(
self
.
seqNum
)
+
"
]
"
+
"
: type
"
+
str
(
self
.
msgId
)
+
"
:
"
+
str
(
self
.
payload
)
+
"
(crc=
"
+
str
(
self
.
crc
)
+
"
)
"
#### Toolbox ####
def
bytes_to_int
(
bytesPayload
:
bytes
):
...
...
@@ -71,7 +70,7 @@ def trame_to_msg(trame : List[int], userId :int):
def
ack_msg
(
msg
:
Message
):
ack
=
[
msg
.
exped
,
msg
.
dest
,
msg
.
seqNum
,
ackMsgId
]
ack
+=
[
sum
(
ack
)
%
255
]
radio
.
send_bytes
(
bytes
(
ack
))
radio
.
send_bytes
(
int_to_
bytes
(
ack
))
print
(
ack
)
sleep
(
100
)
...
...
@@ -97,7 +96,7 @@ def send_msg(msgId, payload: List[int], userId:int, dest:int):
while
not
acked
and
running_time
()
-
t0
<
Timeout
:
print
(
"
envoi
"
)
radio
.
send_bytes
(
bytes
(
msg_to_trame
(
msg
)))
radio
.
send_bytes
(
int_to_
bytes
(
msg_to_trame
(
msg
)))
sleep
(
tryTime
//
2
)
display
.
clear
()
sleep
(
tryTime
//
2
)
...
...
@@ -122,20 +121,23 @@ if __name__ == '__main__':
userId
=
0
# Messages à envoyer
destId
=
1
if
button_a
.
was_pressed
():
send_msg
(
1
,[
60
],
userId
,
destId
)
elif
button_b
.
was_pressed
():
send_msg
(
1
,[
120
],
userId
,
destId
)
while
True
:
# Messages à envoyer
destId
=
1
if
button_a
.
was_pressed
():
send_msg
(
1
,[
60
],
userId
,
destId
)
button_a
.
was_pressed
()
elif
button_b
.
was_pressed
():
send_msg
(
1
,[
120
],
userId
,
destId
)
button_b
.
was_pressed
()
# Reception des messages
m
=
receive_msg
(
userId
)
if
m
and
m
.
msgId
==
1
:
print
(
m
.
msgStr
())
music
.
pitch
(
m
.
payload
[
0
]
*
10
,
duration
=
100
,
pin
=
pin0
)
elif
m
and
m
.
msgId
==
2
:
display
.
show
(
Image
.
SQUARE
)
# Reception des messages
m
=
receive_msg
(
userId
)
if
m
and
m
.
msgId
==
1
:
print
(
m
.
msgStr
())
music
.
pitch
(
m
.
payload
[
0
]
*
10
,
duration
=
100
,
pin
=
pin0
)
elif
m
and
m
.
msgId
==
2
:
display
.
show
(
Image
.
SQUARE
)
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