From d3547c9fab1314a15e10ca6037ae8043d7beb8e9 Mon Sep 17 00:00:00 2001
From: minssen_pie <pierre.minssen@supelec.fr>
Date: Fri, 7 Dec 2018 19:36:42 +0100
Subject: [PATCH] Ajout reception + refomatage des responds_library

---
 viscaoveriplib/camera.py                   | 35 ++++++++++++----------
 viscaoveriplib/inquiry_commands_library.py |  3 +-
 viscaoveriplib/inquiry_responds_library.py | 34 ++++++++++-----------
 3 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/viscaoveriplib/camera.py b/viscaoveriplib/camera.py
index c5b4e1c..95ca65d 100644
--- a/viscaoveriplib/camera.py
+++ b/viscaoveriplib/camera.py
@@ -1,11 +1,11 @@
 import socket
-#Both protocols (input and outpout are UDB
+# 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):
+    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):
         """
         Création d'une caméra avec
         :param UDP_IP: IP de la caméra (192.168.0.100 par défaut)
@@ -22,7 +22,7 @@ class Camera:
         self.CAMERA_IP = UDP_IP
         self.CAMERA_PORT = UDP_PORT
         self.CAMERA_IP_OUT = UDP_IP_OUT
-        self.debug=debug
+        self.debug = debug
         self.virtualcam = virtualcam
 
     def send(self, message):
@@ -50,22 +50,27 @@ class Camera:
         :param payload:
         :return: header without prefix = payloadlength + seq_num
         """
+        length = hex(len(payload.replace(' ', '')))
+        payloadlength = length[2:]
+        if len(length) == 1:
+            payloadlength = '0' + payloadlength
 
-        lenght = hex(len(payload.replace(' ', '')))
-        payloadlenght = lenght[2:]
-        if len(lenght) == 1:
-            payloadlenght = '0' + payloadlenght
-
-        header = payloadlenght
+        header = payloadlength
         header = header + ('0' * (8 - len(str(self.seq_num))) + str(self.seq_num))
         return header
 
-    def receive(self): #non fonctionnel
+    def receive(self):  # non fonctionnel
+        """
+        recoper avec le multi-thread avec ça
+        https://python.developpez.com/cours/TutoSwinnen/?page=page_20
+        Data in : b'\x01\x11\x00\x03\x00\x00\x85\x00\x90A\xff'
+        :return: Data out : '02000002000013610f01'
+        """
 
         sock = socket.socket(socket.AF_INET,  # Internet
                              socket.SOCK_DGRAM)  # UDP
-        self.camera_sock.bind((self.CAMERA_IP_OUT, self.CAMERA_PORT))
-        print("ok")
-        while True:
-            data, addr = sock.recvfrom(1024)  # buffer size is 1024 bytes
-            print("received message:", data.hex())
\ No newline at end of file
+        sock.bind((self.CAMERA_IP_OUT, self.CAMERA_PORT))
+        data, addr = sock.recvfrom(1024)  # buffer size is 1024 bytes<
+        message = data.hex()
+        return message
+
diff --git a/viscaoveriplib/inquiry_commands_library.py b/viscaoveriplib/inquiry_commands_library.py
index a385a96..0696777 100644
--- a/viscaoveriplib/inquiry_commands_library.py
+++ b/viscaoveriplib/inquiry_commands_library.py
@@ -1,4 +1,4 @@
-from camera import *
+import camera
 
 
 class Camera:
@@ -15,6 +15,7 @@ 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/inquiry_responds_library.py b/viscaoveriplib/inquiry_responds_library.py
index c000456..d9b325a 100644
--- a/viscaoveriplib/inquiry_responds_library.py
+++ b/viscaoveriplib/inquiry_responds_library.py
@@ -1,26 +1,26 @@
 # liste de dico non exaustif
 
-respond = {'y0 50 02 FF': "On", 'y0 50 03 FF': "Off", "y0 50 00 FF": "auto/standard"}
+respond = {'y05002FF': "On", 'y05003FF': "Off", "y05000FF": "auto/standard"}
 
-wb_mode_respond = {"y0 50 00 FF": "auto", "y0 50 01 FF": "In Door", "y0 50 02 FF": "Out Door",
-                   "y0 50 03 FF": "One Push WB", "y0 50 04 FF": "ATW", "y0 50 05 FF": "Manual"}
+wb_mode_respond = {"y05000FF": "auto", "y05001FF": "In Door", "y05002FF": "Out Door",
+                   "y05003FF": "One Push WB", "y05004FF": "ATW", "y05005FF": "Manual"}
 
-ae_mode_respond = {'y0 50 00 FF': "Full auto", 'y0 50 03 FF': "Manual", "y0 50 0A FF": "Shutter Priority", "y0 50 0B FF": "Iris priority", "y0 50 0D FF": "Bright"}
+ae_mode_respond = {'y05000FF': "Full auto", 'y05003FF': "Manual", "y0500AFF": "Shutter Priority", "y0500BFF": "Iris priority", "y0500DFF": "Bright"}
 
-wd_mode_respond = {"y0 50 00 FF": "Off", "y0 50 02 FF": "Low",
-                   "y0 50 03 FF": "Mid", "y0 50 04 FF": "High"}
+wd_mode_respond = {"y05000FF": "Off", "y05002FF": "Low",
+                   "y05003FF": "Mid", "y05004FF": "High"}
 
-picture_mode_respond = {"y0 50 00 FF": "Off", "y0 50 02 FF": "Neg.Art", "y0 50 04 FF": "B&W"}
+picture_mode_respond = {"y05000FF": "Off", "y05002FF": "Neg.Art", "y05004FF": "B&W"}
 
-video_system_respond = {"y0 50 00 FF": "1920 x 1080 p / 59.94", "y0 50 02 FF": "1920 x 1080 p / 29.97",
-                        "y0 50 03 FF": "1920 x 1080 i / 59.94", "y0 50 04 FF": "1280 x 720 p / 59.94",
-                        "y0 50 05 FF": "1280 x 720 p / 29.97", "y0 50 08 FF": "1920 x 1080p / 50",
-                        "y0 50 0A FF": "1920 x 1080 p / 25", "y0 50 0B FF": "1920 x 1080 i / 50",
-                        "y0 50 0C FF": "1280 x 720 p / 50", "y0 50 0D FF": "1280 x 720 p / 25"}
+video_system_respond = {"y05000FF": "1920 x 1080 p / 59.94", "y05002FF": "1920 x 1080 p / 29.97",
+                        "y05003FF": "1920 x 1080 i / 59.94", "y05004FF": "1280 x 720 p / 59.94",
+                        "y05005FF": "1280 x 720 p / 29.97", "y05008FF": "1920 x 1080p / 50",
+                        "y0500AFF": "1920 x 1080 p / 25", "y0500BFF": "1920 x 1080 i / 50",
+                        "y0500CFF": "1280 x 720 p / 50", "y0500DFF": "1280 x 720 p / 25"}
 
-color_system_respond = {"y0 50 00 FF": "HDMI YUV", "y0 50 01 FF": "HDMI GBR",
-                        "y0 50 02 FF": "DVI GBR", "y0 50 03 FF": "DVI YUV"}
+color_system_respond = {"y05000FF": "HDMI YUV", "y05001FF": "HDMI GBR",
+                        "y05002FF": "DVI GBR", "y05003FF": "DVI YUV"}
 
-ir_condition = {"y0 50 00 FF": "ir remote commander stable reception enable",
-                "y0 50 01 FF": "ir remote commander reception unstable environment",
-                "y0 50 02 FF": "power ON by ir remote commander (cannot be judged)"}
+ir_condition = {"y05000FF": "ir remote commander stable reception enable",
+                "y05001FF": "ir remote commander reception unstable environment",
+                "y05002FF": "power ON by ir remote commander (cannot be judged)"}
-- 
GitLab