progress with parsing and kafka
This commit is contained in:
@@ -8,9 +8,12 @@ require StreamGenerator, test
|
||||
epicsEnvSet("INSTR", "SQ:TEST:")
|
||||
epicsEnvSet("NAME", "SG")
|
||||
|
||||
drvAsynIPPortConfigure("ASYN_IP_PORT", "127.0.0.1:9071:9073 UDP", 0, 0, 0)
|
||||
drvAsynIPPortConfigure("ASYN_IP_PORT", "127.0.0.1:9071:54321 UDP", 0, 0, 0)
|
||||
asynStreamGenerator("ASYN_SG", "ASYN_IP_PORT", 4)
|
||||
|
||||
dbLoadRecords("$(StreamGenerator_DB)channels.db", "INSTR=$(INSTR), NAME=$(NAME), PORT=ASYN_SG, CHANNEL=0")
|
||||
dbLoadRecords("$(StreamGenerator_DB)channels.db", "INSTR=$(INSTR), NAME=$(NAME), PORT=ASYN_SG, CHANNEL=1")
|
||||
dbLoadRecords("$(StreamGenerator_DB)channels.db", "INSTR=$(INSTR), NAME=$(NAME), PORT=ASYN_SG, CHANNEL=2")
|
||||
dbLoadRecords("$(StreamGenerator_DB)channels.db", "INSTR=$(INSTR), NAME=$(NAME), PORT=ASYN_SG, CHANNEL=3")
|
||||
|
||||
iocInit()
|
||||
|
||||
74
scripts/udp_gen.py
Normal file
74
scripts/udp_gen.py
Normal file
@@ -0,0 +1,74 @@
|
||||
import socket
|
||||
import time
|
||||
import random
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
|
||||
header = [
|
||||
0, 0, # buffer length in 16bit words (1, 0) == 1, (0, 1) == 256
|
||||
0, 0x80, # buffer type (probably should be 0)
|
||||
21, 0, # header length
|
||||
0, 0, # buffer number
|
||||
0, 0, # run id
|
||||
0x3, # status
|
||||
0, # id of sending module
|
||||
0, 0, # timestamp low
|
||||
0, 0, # timestamp mid
|
||||
0, 0, # timestamp high
|
||||
] + [0, 0] * 12 # parameters
|
||||
|
||||
data = [
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0
|
||||
]
|
||||
|
||||
start_time = time.time_ns() // 100
|
||||
|
||||
while True:
|
||||
# update buffer number
|
||||
header[6] = (header[6] + 1) % 0xff
|
||||
header[7] = (header[7] + (header[6] == 0)) % 0xff
|
||||
|
||||
# update timestamp
|
||||
base_timestamp = time.time_ns() // 100 - start_time
|
||||
t_low = base_timestamp & 0xffff
|
||||
t_mid = (base_timestamp >> 16) & 0xffff
|
||||
t_high = (base_timestamp >> 32) & 0xffff
|
||||
header[12] = t_low & 0xff
|
||||
header[13] = t_low >> 8
|
||||
header[14] = t_mid & 0xff
|
||||
header[15] = t_mid >> 8
|
||||
header[16] = t_high & 0xff
|
||||
header[17] = t_high >> 8
|
||||
|
||||
num_events = random.randint(0, 243)
|
||||
|
||||
# update buffer length
|
||||
buffer_length = 21 + num_events * 3
|
||||
header[0] = buffer_length & 0xff
|
||||
header[1] = (buffer_length >> 8) & 0xff
|
||||
|
||||
tosend = list(header)
|
||||
|
||||
for i in range(num_events):
|
||||
d = list(data)
|
||||
|
||||
# set monitor
|
||||
d[5] = (1 << 7) | random.randint(0,3)
|
||||
|
||||
# update trigger timestamp
|
||||
event_timestamp = (time.time_ns() // 100) - base_timestamp
|
||||
d[0] = event_timestamp & 0xff
|
||||
d[1] = (event_timestamp >> 8) & 0xff
|
||||
d[2] = (event_timestamp >> 16) & 0x07
|
||||
|
||||
tosend += d
|
||||
|
||||
sock.sendto(bytes(tosend), ('127.0.0.1', 54321))
|
||||
mv = memoryview(bytes(header)).cast('H')
|
||||
print(f'Sent packet {mv[3]} with {num_events} events {base_timestamp}')
|
||||
time.sleep(1)
|
||||
Reference in New Issue
Block a user