From 0e6beaa96263cacab60514ce7a30941c32a52ae7 Mon Sep 17 00:00:00 2001 From: "Vincent N." <vincent.namy@edu.ge.ch> Date: Wed, 29 Jan 2025 00:10:46 +0100 Subject: [PATCH] Protocole v1.1 --- Protocole/main.py | 32 ++++++++++++++++++------------ Protocole/protocole.py | 44 ++++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/Protocole/main.py b/Protocole/main.py index 5966010..edc6e80 100644 --- a/Protocole/main.py +++ b/Protocole/main.py @@ -1,12 +1,10 @@ ''' Protocole Réseau Pour Micro:bit OC Robotique 2025 +Fichier de test de la lib Auteur·ice : Vincent Namy Version : 1.0 Date : 28.1.25 -TODO : -- Encryption -- passer trame en bytes ? ''' @@ -15,21 +13,31 @@ import music userId = 0 + +def ackedVisualFeedback(acked): + if acked: + display.show(Image.HAPPY) + else: + display.show(Image.SAD) + sleep(100) + display.clear() + while True: + # Messages à envoyer + destId = 1 if button_a.was_pressed(): - if send_msg(1,[],userId, 1): - display.show(Image.HAPPY) - else: - display.show(Image.SAD) - - sleep(100) - display.clear() - + send_msg(1,[60],userId, destId) + elif button_b.was_pressed(): + send_msg(1,[120],userId, destId) + + + # Reception des messages m = receive_msg(userId) if m and m.msgId==1: - music.pitch(600, duration=100, pin=pin0) + print(m.msgStr()) + music.pitch(m.payload[0]*10, duration=100, pin=pin0) elif m and m.msgId==2: display.show(Image.SQUARE) diff --git a/Protocole/protocole.py b/Protocole/protocole.py index bc65f69..0b87dec 100644 --- a/Protocole/protocole.py +++ b/Protocole/protocole.py @@ -5,8 +5,11 @@ Version : 1.0 Date : 28.1.25 TODO : -- Encryption +- plusieurs messages - passer trame en bytes ? +- doc string +- template +- Encryption ''' #### Libraries #### @@ -16,7 +19,7 @@ import radio #### Variables globales #### seqNum = 0 tryTime = 100 -Timeout = 500 +Timeout = 300 ackMsgId = 0 #### Start radio module #### @@ -90,16 +93,16 @@ def send_msg(msgId, payload: List[int], userId:int, dest:int): acked = False t0 = running_time() -# print("Envoyé : ", msg.msgStr()) + print("Envoyé : ", msg.msgStr()) while not acked and running_time()-t0 < Timeout: -# print("envoi") + print("envoi") radio.send_bytes(bytes(msg_to_trame(msg))) sleep(tryTime//2) display.clear() sleep(tryTime//2) acked = receive_ack(msg) -# print("acked : ", acked) + print("acked : ", acked) #print(running_time()-t0) seqNum += 1 @@ -119,21 +122,20 @@ if __name__ == '__main__': userId = 0 - while True: + # 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) - if button_a.was_pressed(): - if send_msg(1,[10, 22],userId, 1): - display.show(Image.HAPPY) - else: - display.show(Image.SAD) - - sleep(100) - display.clear() - - m = receive_msg(userId) - - if m and m.msgId==1: - display.show(Image.SQUARE) - sleep(100) - display.clear() + + + # 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) -- GitLab