Skip to content

Instantly share code, notes, and snippets.

@mundya
Last active December 29, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mundya/7605603 to your computer and use it in GitHub Desktop.
Save mundya/7605603 to your computer and use it in GitHub Desktop.
InSpiNNuator - Pretend to be a SpiNNaker board transmitting UDP packets to a host. Packets resemble those produced by io_printf.
import random, struct, socket, time
def generate_packet( data ):
"""Generates a random SpiNNaker UDP Packet with a random
chip x, y and core (taken from some sensible range)."""
# Pick x, y, core
x = random.randint( 0, 4 )
y = random.randint( 0, 4 )
core = random.randint( 0, 17 )
# Construct the packet
flags = iptag = dest_port = dest_addr = 0x0
srce_port = 0x1f & core
data = "<%2d, %2d, %2d> " % (x, y, core) + data
packet = struct.pack( "!2x 4B H 2B 4x", flags, iptag, dest_port, srce_port,
dest_addr, x, y ) + data
return packet
if __name__ == "__main__":
# Create a socket
sock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
try:
while True:
message = time.strftime( "%H:%M:%S" ) + " inSpiNNuate!"
packet = generate_packet( message )
# Transmit packet
try:
sock.sendto( packet, ("127.0.0.1", 17892) )
except socket.error, e:
print( e )
time.sleep( 0.1 )
# Pause some amount of time
time.sleep( random.random() )
except KeyboardInterrupt:
pass
finally:
# Close the socket
sock.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment