-
Notifications
You must be signed in to change notification settings - Fork 0
/
mirrorlink_server.py
42 lines (38 loc) · 1.4 KB
/
mirrorlink_server.py
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
import os
import time
import socket
import threading
from http.server import BaseHTTPRequestHandler, HTTPServer
# SSDP:alive message
def send_ssdp_alive():
message = '\r\n'.join([
'NOTIFY * HTTP/1.1',
'HOST: 239.255.255.250:1900',
'NT: upnp:rootdevice',
'NTS: ssdp:alive',
'USN: uuid:c8cba096-5abe-47ac-9c14-3267d7c94ce6::upnp:rootdevice',
'LOCATION: http://192.168.7.2/',
'CACHE-CONTROL: max-age=1800',
'SERVER: Python/3.x UPnP/1.0',
'',
''
]).encode('utf-8')
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2)
sock.sendto(message, ('239.255.255.250', 1900))
# USB control request listener (dummy implementation for this example)
def listen_for_mirrorlink_command():
while True:
try:
# Placeholder for the actual USB handling logic
# This should be replaced with actual USB gadget handling code
# For now, we simulate receiving a command
print("Waiting for MirrorLink USB command...")
time.sleep(10) # Simulate waiting for a command
print("MirrorLink USB command received")
send_ssdp_alive()
except Exception as e:
print(f"Error: {e}")
time.sleep(1)
if __name__ == "__main__":
listen_for_mirrorlink_command()