-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pcon.py
More file actions
executable file
·133 lines (106 loc) · 3.91 KB
/
Copy pathtest_pcon.py
File metadata and controls
executable file
·133 lines (106 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python3
import socket
import time
from PIL import Image
import io
import struct
PROJECTOR_IP = "10.168.222.248"
ECON_PORT = 3620
PCON_PORT = 3621
# Headers basés sur le format ESC/VP.net qui a fonctionné
ECON_HEADER = b'ECON\x10\x03\x00\x00\x00\x00'
PCON_HEADER = b'PCON\x10\x03\x00\x00\x00\x00'
def test_econ():
"""Test du protocole ECON (contrôle) sur port 3620"""
print("=== Test ECON (port 3620) ===\n")
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
sock.connect((PROJECTOR_IP, ECON_PORT))
print("✓ Connecté au port 3620")
# Essayer différentes commandes
commands = [
"CONNECT",
"INIT",
"START",
"STATUS?",
]
for cmd in commands:
cmd_bytes = ECON_HEADER + cmd.encode('ascii') + b'\r'
print(f"\nEnvoi: {repr(cmd)}")
sock.send(cmd_bytes)
time.sleep(0.3)
sock.settimeout(1)
try:
response = sock.recv(1024)
if response:
print(f" ✓ Réponse: {response[:200]}")
return response # Succès !
except socket.timeout:
print(f" - Pas de réponse")
sock.close()
except Exception as e:
print(f"✗ Erreur: {e}")
return None
def test_pcon():
"""Test du protocole PCON (image transfer) sur port 3621"""
print("\n\n=== Test PCON (port 3621) ===\n")
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
sock.connect((PROJECTOR_IP, PCON_PORT))
print("✓ Connecté au port 3621")
# Essayer d'initialiser la session
init_commands = [
"CONNECT",
"INIT",
"START",
"READY?",
]
for cmd in init_commands:
cmd_bytes = PCON_HEADER + cmd.encode('ascii') + b'\r'
print(f"\nEnvoi: {repr(cmd)}")
sock.send(cmd_bytes)
time.sleep(0.3)
sock.settimeout(1)
try:
response = sock.recv(1024)
if response:
print(f" ✓ Réponse: {response[:200]}")
# Si on a une réponse positive, essayer d'envoyer une image
if b'OK' in response or b':' in response:
print("\n Tentative d'envoi d'image...")
# Créer une petite image de test
img = Image.new('RGB', (640, 480), color=(255, 0, 0))
buffer = io.BytesIO()
img.save(buffer, format='JPEG', quality=70)
jpeg_data = buffer.getvalue()
# Envoyer avec un header de taille
image_packet = PCON_HEADER + struct.pack(">I", len(jpeg_data)) + jpeg_data
sock.send(image_packet)
print(f" Image envoyée: {len(jpeg_data)} bytes")
time.sleep(0.5)
try:
resp2 = sock.recv(1024)
if resp2:
print(f" ✓ Réponse à l'image: {resp2[:100]}")
except:
pass
return response
except socket.timeout:
print(f" - Pas de réponse")
sock.close()
except Exception as e:
print(f"✗ Erreur: {e}")
return None
# Exécuter les tests
print("=" * 60)
print(" TEST DES PROTOCOLES ECON/PCON")
print("=" * 60)
econ_result = test_econ()
pcon_result = test_pcon()
print("\n" + "=" * 60)
print("RÉSUMÉ:")
print(f" ECON (3620): {'✓ Réponse reçue' if econ_result else '✗ Pas de réponse'}")
print(f" PCON (3621): {'✓ Réponse reçue' if pcon_result else '✗ Pas de réponse'}")
print("=" * 60)