diff --git a/camera_main.py b/camera_main.py index dd0cbb195a4a4fc4fee3191d3e91bb4ce5da5a78..3b1a32ea737790b51eb6d93d148258cb4c406c19 100644 --- a/camera_main.py +++ b/camera_main.py @@ -1,3 +1,4 @@ +""" from tkinter import * import tkinter as Tk import socket @@ -45,3 +46,4 @@ quit_menu=Tk.Button(top, text='QUIT', bg='red', fg='white', command=quit) quit_menu.pack(anchor='e') root.mainloop() +""" diff --git a/viscaoveriplib/Test camera file.py b/viscaoveriplib/Test camera file.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/viscaoveriplib/__init__.py b/viscaoveriplib/__init__.py deleted file mode 100644 index ebb1cba951e5b21c4922e6375da046b6379723ad..0000000000000000000000000000000000000000 --- a/viscaoveriplib/__init__.py +++ /dev/null @@ -1,7 +0,0 @@ -import viscaoveriplib.camera as cam -import viscaoveriplib.listener as listener - -c = cam.Camera() -l = listener.Listener() -l.start() - diff --git a/viscaoveriplib/advanced_controls.py b/viscaoveriplib/advanced_controls.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/viscaoveriplib/camera.py b/viscaoveriplib/camera.py index 80f4227e4a2dce12ff6173d3d7762d6e083d8a68..8c74d78a6545558b615614e2ae466f3fddcaafd6 100644 --- a/viscaoveriplib/camera.py +++ b/viscaoveriplib/camera.py @@ -1,11 +1,16 @@ import socket -# Both protocols (input and outpout are UDP +import viscaoveriplib.commands_library as command_lib +import viscaoveriplib.inquiry_commands_library as inq_command_lib +import viscaoveriplib.listener as listener +import viscaoveriplib.inquiry_responds_library as inq_resp +import viscaoveriplib.responds_messages as default_resp +# Both protocols (input and outpout are UDP) "192.168.0.100" UDP_PORT = 52381 -class Camera: - def __init__(self, UDP_IP = "192.168.0.100", UDP_PORT = 52381, UDP_IP_OUT = "192.168.0.57", VV= "09", WW= "09", seq_num: hex ="0",debug=False, virtualcam=False): +class Camera(command_lib.Command, inq_command_lib.Inquiry): + def __init__(self, UDP_IP = "192.168.0.100", UDP_PORT = 52381, UDP_IP_OUT = "192.168.0.57", VV= "09", WW= "09", seq_num: int = 0,debug=False, virtualcam=False): """ Création d'une caméra avec :param UDP_IP: IP de la caméra (192.168.0.100 par défaut) @@ -24,6 +29,8 @@ class Camera: self.CAMERA_IP_OUT = UDP_IP_OUT self.debug = debug self.virtualcam = virtualcam + self.listener = listener.Listener(self.CAMERA_IP_OUT, self.CAMERA_PORT) + self.listener.start() def send(self, message): """ @@ -31,15 +38,18 @@ class Camera: :param message: message str['hex'] """ if(not(self.virtualcam)): #Si la cam n'est pas virtuel, on envoie le paquet - self.camera_sock.sendto(bytes.fromhex(message.replace(' ', '')), (self.CAMERA_IP, self.UDP_PORT)) + self.camera_sock.sendto(bytes.fromhex(message.replace(' ', '')), (self.CAMERA_IP, self.CAMERA_PORT)) self.seq_num += 1 # ballec de l'hexa pour l'instant + if(self.debug or self.virtualcam): #Si la cam est virtuelle ou on debug, on envoie print("Commande n°{} envoyée : {} \n".format(self.seq_num,message)) def send_payload(self, payloadtype,payload): message=payloadtype +' ' + self.payload2header(payload) + payload if(not(self.virtualcam)): #Si la cam n'est pas virtuel, on envoie le paquet - self.camera_sock.sendto(bytes.fromhex(message.replace(' ', '')), (self.CAMERA_IP, self.UDP_PORT)) + + self.camera_sock.sendto(bytes.fromhex(message.replace(' ', '')), (self.CAMERA_IP, self.CAMERA_PORT)) + self.seq_num += 1 # ballec de l'hexa pour l'instant if(self.debug or self.virtualcam): #Si la cam est virtuelle ou on debug, on envoie print("Commande n°{} envoyée : {} \n".format(self.seq_num,message)) @@ -59,6 +69,40 @@ class Camera: header = header + ('0' * (8 - len(str(self.seq_num))) + str(self.seq_num)) return header + # cam's respond + @staticmethod + def decompose_reception(reception: str): + """ + decomposes the hex received messaged if it's not a error respond + + :param reception: str hex eg '01110003000085029051ff' + :return: list of str hex [payload_type, payload_length, sequence_number, payload] eg ['0111', '0003', '00008502', '9051ff'] + """ + payload_type = reception[0:4] + payload_length = reception[4:8] + sequence_number = reception[8:16] + payload = reception[16:] + return [payload_type, payload_length, sequence_number, payload] + + @staticmethod + def payload2meaning(payload: str, command_type="default"): + """ + Reveal the meaning of the visca respond + :param payload: payload recieved in str hex eg '9051ff' + :param command_type: type of command, the respond's meaning depends on the inquiry/command + :return: the meaning in str + """ + meaning = "Not known" + if command_type in inq_resp.inq_list: + # if payload is not in the dictionary meaning = None + meaning = inq_resp.inq_list.get(command_type).get(payload) + else: + meaning = default_resp.liste_respond.get(payload) + if meaning is None: + meaning = "Respond not understood" + return meaning + + diff --git a/viscaoveriplib/commands_library.py b/viscaoveriplib/commands_library.py index 93c9d2b73dca883f44a4ad560776d3d15910116c..f5f25fe6891018ee70038ea7398700ba93c0513b 100644 --- a/viscaoveriplib/commands_library.py +++ b/viscaoveriplib/commands_library.py @@ -1,7 +1,7 @@ -from camera_main import * +#from camera_main import * -class Camera: +class Command: #### ####### FONCTIONS COMMANDES D'EXECUTIONS diff --git a/viscaoveriplib/controleur.py b/viscaoveriplib/controleur.py deleted file mode 100644 index 31b66f1f5ddb3e8777a47771ae18fbcfbf82eb9a..0000000000000000000000000000000000000000 --- a/viscaoveriplib/controleur.py +++ /dev/null @@ -1,44 +0,0 @@ -from viscaoveriplib.camera import Camera -from viscaoveriplib.listener import Listener -import viscaoveriplib.inquiry_responds_library as inq_resp -import viscaoveriplib.responds_messages as default_resp - - -class Controller: - - def __init__(self, c: Camera, l: Listener): - self.camera = c - self.listener = l - - @staticmethod - def decompose_reception(reception: str): - """ - decomposes the hex received messaged - - :param reception: str hex eg '01110003000085029051ff' - :return: list of str hex [payload_type, payload_length, sequence_number, payload] eg ['0111', '0003', '00008502', '9051ff'] - """ - payload_type = reception[0:4] - payload_length = reception[4:8] - sequence_number = reception[8:16] - payload = reception[16:] - return [payload_type, payload_length, sequence_number, payload] - - @staticmethod - def payload2meaning(payload: str, command_type="default"): - """ - Reveal the meaning of the visca respond - :param payload: payload recieved in str hex eg '9051ff' - :param command_type: type of command, the respond's meaning depends on the inquiry/command - :return: the meaning in str - """ - meaning = "Not known" - if command_type in inq_resp.inq_list: - # if payload is not in the dictionary meaning = None - meaning = inq_resp.inq_list.get(command_type).get(payload) - else: - meaning = default_resp.liste_respond.get(payload) - if meaning is None: - meaning = "Respond not understood" - return meaning - diff --git a/viscaoveriplib/debut.py b/viscaoveriplib/debut.py new file mode 100644 index 0000000000000000000000000000000000000000..dc40ba8ea2c45c7683ef3f4988b3703254981a07 --- /dev/null +++ b/viscaoveriplib/debut.py @@ -0,0 +1,14 @@ + +import viscaoveriplib.camera as cam +import viscaoveriplib.listener as listener +c = cam.Camera() +print("ok") +print(c.listener.isAlive()) +c.pan_tiltDrive_down() +c.pan_tiltDrive_down() +c.pan_tiltDrive_down() +c.pan_tiltDrive_down() + + + + diff --git a/viscaoveriplib/inquiry_commands_library.py b/viscaoveriplib/inquiry_commands_library.py index 962ee2f6f3786a47168a75f29b6eb44383a6110b..52045b7369dd869de1dd1339f16e54b5670849c4 100644 --- a/viscaoveriplib/inquiry_commands_library.py +++ b/viscaoveriplib/inquiry_commands_library.py @@ -1,7 +1,7 @@ import camera_main -class Camera: +class Inquiry: #### ####### FONCTIONS COMMANDES D'EXECUTIONS @@ -15,7 +15,6 @@ class Camera: def power(self): payload = '81 09 04 00 FF' self.send_inquiry(payload) - self.camera.recieve() def zoom_pos(self): payload = '81 09 04 47 FF' diff --git a/viscaoveriplib/listener.py b/viscaoveriplib/listener.py index 123f0398f9280a96e1337b66a8a76dd0b0ee8404..55d66625c489ad722e094f6141f51139e28f46fd 100644 --- a/viscaoveriplib/listener.py +++ b/viscaoveriplib/listener.py @@ -9,17 +9,17 @@ class Listener(Thread): def __init__(self, IP_OUT = "192.168.0.57", PORT = 52381): Thread.__init__(self) - self.message = "FF" + self.message = {} self.IP_OUT = IP_OUT self.PORT = PORT def run(self): - sock = socket.socket(socket.AF_INET, # Internet + sock_recp = socket.socket(socket.AF_INET, # Internet socket.SOCK_DGRAM) # UDP - sock.bind((self.IP_OUT, self.PORT)) + sock_recp.bind((self.IP_OUT, self.PORT)) while True: - data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes - self.message = data.hex() + data, addr = sock_recp.recvfrom(1024) # buffer size is 1024 bytes + self.message.append(data.hex())