Commit 189a4789 authored by Amalio Coron's avatar Amalio Coron

Organisation du code, ajout de TODO, départ du début de la library

parent 9d050079
import socket
"192.168.0.100"
UDP_PORT = 52381
class Camera:
def __init__(self, UDP_IP,UDP_PORT, VV= "09", WW= "09", seq_num: hex ="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)
:param UDP_PORT: Port de la caméra (52381 par défaut)
:param VV: Vitesse de déplacement horizontale (entre 01 et 18) en hex
:param WW: Vitesse de déplacement veritcale (entre 01 et 17) en hex
:param seq_num: sequence number de départ
"""
self.seq_num = seq_num # erreur du capteur UWB (p pour précision...) WTF ce commentaire ???
self.VV = VV
self.WW = WW
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
self.UDP_IP = UDP_IP
self.debug=debug
self.virtualcam=virtualcam
def send(self, message):
"""
Envoie un message à la cam (supporte les ' ')
:param message: message str['hex']
"""
if(not(self.virtualcam)): #Si la cam n'est pas virtuel, on envoie le paquet
self.sock.sendto(bytes.fromhex(message.replace(' ', '')), (self.UDP_IP, self.UDP_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.sock.sendto(bytes.fromhex(message.replace(' ', '')), (self.UDP_IP, self.UDP_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 payload2header(self, payload):
"""
take the payload, calculate the payload lenght and add the sequence number
:param payload:
:return: header = payloadlenght + seq_num
"""
lenght = hex(len(payload.replace(' ', '')))
payloadlenght = lenght[2:]
if len(lenght) == 1:
payloadlenght = '0' + payloadlenght
header = payloadlenght
header = header + ('0' * (8 - len(str(self.seq_num))) + str(self.seq_num))
return header
import socket
"192.168.0.100"
UDP_PORT = 52381
from camera import *
class Camera:
def __init__(self, UDP_IP,UDP_PORT, seq_num: hex ="0", VV= "09", WW= "09"):
"""
Création d'une caméra
:param UDP_IP: IP de la caméra (192.168.0.100 par défaut)
:param UDP_PORT: Port de la caméra (52381 par défaut)
:param seq_num: sequence number de départ
:param VV: Vitesse
:param WW: Vitesse
"""
self.seq_num = seq_num # erreur du capteur UWB (p pour précision...)
self.VV = VV
self.WW = WW
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
self.UDP_IP = UDP_IP
def move_to_absolute_position(self, YCoordinates, ZCoordinates):
####
####### FONCTIONS COMMANDES D'EXECUTIONS
####
#CAM_POWER : Power ON/OFF
def power_on(self):
payloadtype='01 00'
payload='81 01 04 00 02 FF'
self.send_payload(payloadtype,payload)
def power_off(self):
payloadtype='01 00'
payload='81 01 04 00 02 FF'
self.send_payload(payloadtype,payload)
#CAM_ZOOM : Zoom Control
#TODO
#CAM_DZOOM
def digital_zoom_off(self):
payloadtype='01 00'
payload='81 01 04 06 02 FF'
self.send_payload(payloadtype,payload)
def digital_zoom_on(self):
payloadtype='01 00'
payload='81 01 04 06 03 FF'
self.send_payload(payloadtype,payload)
#CAM_Focus : Focus Control
#TODO
#AF Sensitivity : Auto Focus sensitivity high/low
def autofocus_sensivity_normal(self):
payloadtype='01 00'
payload='81 01 04 58 02 FF'
self.send_payload(payloadtype,payload)
def autofocus_sensivity_low(self):
payloadtype='01 00'
payload='81 01 04 58 03 FF'
self.send_payload(payloadtype,payload)
#CAM_AFMode : AutoFocus Movement Mode
#TODO
#CAM_IRCOrrection : Focus IR Correction setting
def focus_ir_correction_off(self):
payloadtype='01 00'
payload='81 01 04 11 00 FF'
self.send_payload(payloadtype,payload)
def focus_ir_correction_on(self):
payloadtype='01 00'
payload='81 01 04 11 00 FF'
self.send_payload(payloadtype,payload)
#CAM_ZoomFocus
#TODO
#PAS FINI A PARTIR D'ICI :
def move_to_absolute_position(self, YCoordinates, ZCoordinates, VV=None, WW=None):
"""
command of absolute position mouvement
:param YCoordinates: YYYY from to
:param ZCoordinates: ZZZZ from to
:param VV:
:param WW:
:return:
"""
if(VV==None):
VV=self.VV
if(WW==None):
WW=self.WW
payloadtype = '01 00'
payload = "81 01 06 02" # Absolute position moove
payload = payload + self.VV + self.WW # add move speed
payload = payload + VV + WW # add move speed
for i in [YCoordinates, ZCoordinates]: # add position
for j in i:
payload = payload + "0" + j
payload = payload + "FF" # end byte
header = self.payload2header(self, payload)
payloadtype = '01 00'
message = payloadtype + header + payload
return message
def payload2header(self, payload: str) -> str:
"""
take the payload, calculate the payload lenght and add the sequence number
:param payload:
:return: header = payloadlenght + seq_num
"""
lenght = hex(len(payload.replace(' ', '')))
payloadlenght = lenght[2:]
if len(lenght) == 1:
payloadlenght = '0' + payloadlenght
header = payloadlenght
header = header + ('0' * (8 - len(str(self.seq_num))) + str(self.seq_num))
return header
def send(self, message: str) -> bool:
"""
Envoie le message à la cam
:param message: message str['hex']
:return: True si c'est bien passé
"""
self.sock.sendto(bytes.fromhex(message.replace(' ', '')), (self.UDP_IP, self.UDP_PORT))
self.seq_num += 1 # ballec de l'hexa pour l'instant
print("fait " + self.seq_num)
return True
payload = payload + " 0" + j
payload = payload + "FF" # end byte #ce code était dans le première boucle, ça me semblait faux.
self.send_payload(payloadtype,payload)
def zqsd(self, x: str) -> str: # hex
payload = "FF" # message d'erreur à refaire
......
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