Commit a3015e7a authored by Pierre Minssen's avatar Pierre Minssen

Centralisation dans camera du listener, de la gestion (pas encore implemente) des reponses

parent b2164b43
"""
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()
"""
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
from camera_main import *
#from camera_main import *
class Camera:
class Command:
####
####### FONCTIONS COMMANDES D'EXECUTIONS
......
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
import viscaoveriplib.camera as cam
import viscaoveriplib.listener as listener
c = cam.Camera()
l = listener.Listener()
l.start()
print("ok")
print(c.listener.isAlive())
c.pan_tiltDrive_down()
c.pan_tiltDrive_down()
c.pan_tiltDrive_down()
c.pan_tiltDrive_down()
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'
......
......@@ -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())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment