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