artdaq_mfextensions  v1_04_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 from random import randrange
12 USAGE = 'send host:port [count]'
13 
14 # first byte is cmd
15 # 2nd byte is seqnum (yes, just 8 bits)
16 # rest is data (up to 1498)
17 buf=''
18 
19 def main(argv):
20  print('len(argv)=%d'%(len(argv),))
21  if len(argv) < 2 or len(argv) > 3:
22  print(USAGE)
23  sys.exit()
24  node,port = argv[1].split(':')
25  count = 1
26  if len(argv) == 3: count = int(argv[2])
27  for ii in range(0, count):
28  sev = randrange(0,15)
29  buf='MF: 01-Jan-1970 01:01:01'
30  buf+="|%d" % ii
31  buf+="|" + node
32  buf+="|" + node
33  if sev == 0:
34  buf+="|ERROR"
35  elif sev < 3:
36  buf+="|WARNING"
37  elif sev < 7:
38  buf+="|INFO"
39  else:
40  buf+="|DEBUG"
41  buf+="|Test Message"
42  buf+="|UDP Send MFMSG"
43  buf+="|udp_send_mfmsg.py"
44  buf+="|1"
45  buf+="|Run 0, Subrun 0, Event %d" % ii
46  buf+="|UDP Test program"
47  buf+="|This is the ARTDAQ UDP test string.\n\t It contains exactly 111 characters, making for a total size of 113 bytes."
48  s = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
49  s.sendto( buf, (node,int(port)) )
50  pass
51 
52 
53 if __name__ == "__main__": main(sys.argv)