00001
00002
00003
00004
00005
00006
00007
00008
00009 import sys
00010 import socket
00011 import random
00012 from time import sleep
00013 USAGE='send host:port seqnum [packetCount] [outoforder] [json]'
00014
00015
00016
00017
00018
00019 buf=''
00020
00021 def main(argv):
00022 print('len(argv)=%d'%(len(argv),))
00023 packetCount = 1
00024 outOfOrder = False
00025 jsonMode = False
00026 if len(argv) < 3: print(USAGE); sys.exit()
00027 if len(argv) >= 4: packetCount = int(argv[3])
00028 if len(argv) >= 5: outOfOrder = int(argv[4]) == 1
00029 if len(argv) >= 6: jsonMode = int(argv[5]) == 1
00030
00031 node,port = argv[1].split(':')
00032 seqnum= int(argv[2])&0xff
00033 s = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
00034
00035 if jsonMode:
00036 packetsSent = 0
00037 while packetsSent < packetCount:
00038 buf=chr(0x10)
00039 buf+=chr(seqnum)
00040 temperature = random.randrange(55,100)
00041 humidity = random.randrange(10,99)
00042 buf+="{\"temperature\":" + str(temperature) + ",\"humidity\":" + str(humidity) + ",\"ledState\":\"green\"}"
00043 s.sendto(buf, (node,int(port)) )
00044 packetsSent += 1
00045 seqnum += 1
00046 sleep(0.5)
00047 else:
00048 if packetCount > 1:
00049 buf=chr(0x21)
00050 buf+=chr(seqnum)
00051 buf+="This is the first ARTDAQ UDP test string. It contains exactly 115 characters, making for a total size of 117 bytes."
00052 s.sendto( buf, (node,int(port)) )
00053 seqnum += 1
00054
00055 packetsSent = 2
00056 while packetsSent < packetCount:
00057 buf=chr(0x22)
00058 buf+=chr(seqnum & 0xff)
00059 buf+="This is a ARTDAQ UDP test string. It contains exactly 107 characters, making for a total size of 109 bytes."
00060 s.sendto( buf, (node,int(port)) )
00061 packetsSent += 1
00062 seqnum += 1
00063
00064 if outOfOrder:
00065 buf=chr(0x22)
00066 buf+=chr((seqnum + 1) & 0xff)
00067 buf+="This is the first out-of-order ARTDAQ UDP Test String. It should go after the second one in the output."
00068 s.sendto( buf, (node,int(port)) )
00069 buf=chr(0x22)
00070 buf+=chr(seqnum & 0xff)
00071 buf+="This is the second out-of-order ARTDAQ UDP Test String. It should come before the first one in the output."
00072 s.sendto( buf, (node,int(port)) )
00073 seqnum += 2
00074
00075 buf=chr(0x23)
00076 buf+=chr(seqnum & 0xff)
00077 buf+="This is the last ARTDAQ UDP test string. It contains exactly 114 characters, making for a total size of 116 bytes."
00078 s.sendto( buf, (node,int(port)) )
00079 else:
00080 buf=chr(0x20)
00081 buf+=chr(seqnum & 0xff)
00082 buf+="This is the ARTDAQ UDP test string. It contains exactly 109 characters, making for a total size of 111 bytes."
00083 s.sendto( buf, (node,int(port)) )
00084
00085 pass
00086
00087
00088 if __name__ == "__main__": main(sys.argv)