Created
November 27, 2023 22:23
-
-
Save llamafilm/61ce61d15c8803b21085ecd9189bf8d4 to your computer and use it in GitHub Desktop.
QDP faker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import socket | |
import requests | |
import xml.etree.ElementTree as ET | |
# Tested with Qsys Core Nano version 9.9.0 | |
# Packets captured from TSC-80-G2 using tcpdump | |
# This looping code allows the Core to discover a touchpanel on a network without multicast | |
CORE_IP = 'xxx.xxx.xxx.xxx' | |
periph_name = 'tsc-paradox' | |
periph_ip = 'yyy.yyy.yyy.yyy' | |
# read the design code name | |
response = requests.get(f'http://{CORE_IP}/status.xml') | |
xmldata = response.text | |
root = ET.fromstring(xmldata) | |
code_name = root.find('./design/code_name').text | |
payload = f"""<QDP> | |
<device> | |
<type>ioframe</type> | |
<name>{periph_name}</name> | |
<part_number>TSC-80-G2</part_number> | |
<platform>tsc_g2</platform> | |
<lan_a_ip>{periph_ip}</lan_a_ip> | |
<ref>device.ioframe.{periph_name}</ref> | |
<periph_cfg_url>/#network</periph_cfg_url> | |
</device> | |
<control> | |
<role>{periph_name}</role> | |
<design_code>{code_name}</design_code> | |
<primary>1</primary> | |
<redundant>0</redundant> | |
<device_ref>device.ioframe.{periph_name}</device_ref> | |
<ref>control.{code_name}.{periph_name}.primary</ref> | |
</control> | |
</QDP>""" | |
print(payload) | |
while True: | |
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) as sock: | |
# After two network hops the packet will not be re-sent/broadcast | |
# see https://www.tldp.org/HOWTO/Multicast-HOWTO-6.html | |
# sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 2) | |
sock.sendto(payload.encode(), ('224.0.23.175', 2467)) | |
time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment