Skip to content

Instantly share code, notes, and snippets.

@klauer
Created November 25, 2020 18:27
Show Gist options
  • Save klauer/95c269f3c1972c6a67d742c744df2018 to your computer and use it in GitHub Desktop.
Save klauer/95c269f3c1972c6a67d742c744df2018 to your computer and use it in GitHub Desktop.
EPICS CAS request errors "missaligned protocol rejected" packet reconstruction by way of caproto
lines = '''CAS: request from 172.23.120.148:38554 => CAS: Missaligned protocol rejected
CAS: Request from 172.23.120.148:38554 => cmmd=0 cid=0x9 type=32769 count=1 postsize=22
CAS: Request from 172.23.120.148:38554 => available=0x6765744c N=0 paddr=0x7fad1800d5f0
CAS: forcing disconnect from 172.23.120.148:38554
CAS: request from 172.23.120.148:38560 => CAS: Client version too old
CAS: Request from 172.23.120.148:38560 => cmmd=18245 cid=0x54502f31 type=12064 count=18516 postsize=21536
CAS: Request from 172.23.120.148:38560 => available=0x2e300d0a N=0 paddr=(nil)
CAS: request from 172.23.120.148:41978 => CAS: Client version too old
CAS: Request from 172.23.120.148:41978 => cmmd=768 cid=0x1 type=3808 count=0 postsize=19
CAS: Request from 172.23.120.148:41978 => available=0x80000 N=0 paddr=0x7fad1800d930
CAS: request from 172.23.120.148:42174 => CAS: Client version too old
CAS: Request from 172.23.120.148:42174 => cmmd=769 cid=0x3b0000 type=7 count=0 postsize=2560
CAS: Request from 172.23.120.148:42174 => available=0x0 N=0 paddr=(nil)
CAS: request from 172.23.120.148:45908 => CAS: Client version too old
CAS: Request from 172.23.120.148:45908 => cmmd=18245 cid=0x54502f31 type=12064 count=18516 postsize=21536
CAS: Request from 172.23.120.148:45908 => available=0x2e310d0a N=0 paddr=(nil)
CAS: request from 172.23.120.148:47586 => CAS: Client version too old
CAS: Request from 172.23.120.148:47586 => cmmd=18245 cid=0x54502f31 type=12064 count=18516 postsize=21536
CAS: Request from 172.23.120.148:47586 => available=0x2e310d0a N=0 paddr=(nil)
CAS: request from 172.23.120.148:51592 => CAS: Client version too old
CAS: Request from 172.23.120.148:51592 => cmmd=18245 cid=0x54502f31 type=12064 count=18516 postsize=21536
CAS: Request from 172.23.120.148:51592 => available=0x2e310d0a N=0 paddr=(nil)
'''.strip().splitlines()
first = [
line for line in lines if 'cmmd' in line
]
def parse(line):
res = {}
for item in line.split(' '):
if '=' in item:
key, value = item.split('=')
if key in ('paddr', ):
continue
if value.startswith('0x'):
value = int(value, 16)
else:
value = int(value)
res[key] = value
return res
items = [
parse(line.split('=> ')[1] + lines[lines.index(line) + 1].split('=> ')[1])
for line in first
]
headers = [
MessageHeader(
command=d['cmmd'],
parameter1=d['cid'],
data_type=d['type'],
data_count=d['count'],
payload_size=d['postsize'],
parameter2=d['available']
)
for d in items
]
print([bytes(header) for header in headers])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment