12 from time
import sleep
13 USAGE=
'send host:port seqnum [packetCount] [outoforder]'
22 print(
'len(argv)=%d'%(len(argv),))
25 if len(argv) < 3: print(USAGE); sys.exit()
26 if len(argv) >= 4: packetCount = int(argv[3])
27 if len(argv) >= 5: outOfOrder = int(argv[4]) == 1
28 if len(argv) >= 6: json = int(argv[5]) == 1
30 node,port = argv[1].split(
':')
31 seqnum= int(argv[2])&0xff
32 s = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
36 while packetsSent < packetCount:
39 temperature = random.randrange(55,100)
40 humidity = random.randrange(10,99)
41 buf+=
"{\"temperature\":" + str(temperature) +
",\"humidity\":" + str(humidity) +
",\"ledState\":\"green\"}"
42 s.sendto(buf, (node,int(port)) )
50 buf+=
"This is the first ARTDAQ UDP test string. It contains exactly 115 characters, making for a total size of 117 bytes."
51 s.sendto( buf, (node,int(port)) )
55 while packetsSent < packetCount:
57 buf+=chr(seqnum & 0xff)
58 buf+=
"This is a ARTDAQ UDP test string. It contains exactly 107 characters, making for a total size of 109 bytes."
59 s.sendto( buf, (node,int(port)) )
65 buf+=chr((seqnum + 1) & 0xff)
66 buf+=
"This is the first out-of-order ARTDAQ UDP Test String. It should go after the second one in the output."
67 s.sendto( buf, (node,int(port)) )
69 buf+=chr(seqnum & 0xff)
70 buf+=
"This is the second out-of-order ARTDAQ UDP Test String. It should come before the first one in the output."
71 s.sendto( buf, (node,int(port)) )
75 buf+=chr(seqnum & 0xff)
76 buf+=
"This is the last ARTDAQ UDP test string. It contains exactly 114 characters, making for a total size of 116 bytes."
77 s.sendto( buf, (node,int(port)) )
80 buf+=chr(seqnum & 0xff)
81 buf+=
"This is the ARTDAQ UDP test string. It contains exactly 109 characters, making for a total size of 111 bytes."
82 s.sendto( buf, (node,int(port)) )
87 if __name__ ==
"__main__": main(sys.argv)