artdaq_mfextensions  v1_05_00
udp_send_mfmsg.py
1 #!/usr/bin/env python
2  # This file (udp_send_artdaq.py) was created by Ron Rechenmacher
3  # <ron@fnal.gov> on
4  # Jan 15, 2015. "TERMS AND CONDITIONS" governing this file are in the README
5  # or COPYING file. If you do not have such a file, one can be obtained by
6  # contacting Ron or Fermi Lab in Batavia IL, 60510, phone: 630-840-3000.
7  # $RCSfile: .emacs.gnu,v $
8  # rev="$Revision: 1.23 $$Date: 2012/01/23 15:32:40 $";
9 import sys
10 import socket
11 import time
12 from random import randrange
13 USAGE = 'send host:port [count] [text file to send] [sleep time in ms]'
14 
15 # first byte is cmd
16 # 2nd byte is seqnum (yes, just 8 bits)
17 # rest is data (up to 1498)
18 buf=''
19 
20 def main(argv):
21  print('len(argv)=%d'%(len(argv),))
22  if len(argv) < 2 or len(argv) > 5:
23  print(USAGE)
24  sys.exit()
25  node,port = argv[1].split(':')
26  portint = int(port)
27  count = 1
28  text = ""
29  sleep_time = 0
30 
31  if len(argv) >= 3: count = int(argv[2])
32  if len(argv) >= 4:
33  f = open(argv[3], "r")
34  text = f.read()
35  if len(argv) >= 5: sleep_time = float(argv[4]) / 1000
36 
37  print('node:port=%s:%d, count=%d'%(node,portint,count))
38  for ii in range(0, count):
39  sev = randrange(0,15)
40  buf='MF: 01-Jan-1970 01:01:01'
41  buf+="|%d" % ii
42  buf+="|" + node + "%d" % ii
43  buf+="|" + node + "%d" % ii
44  if sev == 0:
45  buf+="|ERROR"
46  elif sev < 3:
47  buf+="|WARNING"
48  elif sev < 7:
49  buf+="|INFO"
50  else:
51  buf+="|DEBUG"
52  buf+="|Test Message %d" % ii
53  buf+="|UDP Send MFMSG %d" % ii
54  buf+="|udp_send_mfmsg.py"
55  buf+="|1"
56  buf+="|Run 0, Subrun 0, Event %d" % ii
57  buf+="|UDP Test program"
58  buf+="|This is the ARTDAQ UDP test string.\n\t It contains exactly 111 characters, making for a total size of 113 bytes."
59  buf+=text
60  s = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
61  s.sendto( buf.encode('uft-8'), (node,portint) )
62  time.sleep(sleep_time)
63  pass
64 
65 
66 if __name__ == "__main__": main(sys.argv)