wu_xinjun
2022-02-10 d78e213656461834adb890b5f1c7d0789725a6de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from ctypes import Structure, c_byte, c_ubyte, c_uint32, c_uint16, sizeof
from sys import argv
import os 
 
class Handshake(Structure):
    _fields_=[
        ('Magic', c_ubyte * 8),
        ('FrameDataLength',c_uint32),
        ('Reserved',c_ubyte * 12)
    ]
 
class Header(Structure):
     _fields_=[
        ('Magic', c_ubyte * 8),
        ('FrameNumber',c_uint32),
        ('VersionNumber',c_uint32),
        ('NumberOfDetection',c_uint16),
        ('NumberOfTrack',c_uint16),
        ('HostSpeed',c_uint16),
        ('HostAngle',c_uint16),
        ('Reserved',c_byte * 8),
        ('RangeAccuracyIdx',c_uint16),
        ('DopplerAccuracyIdx',c_uint16),
        ('AzimuthAccuracyIdx',c_uint16),
        ('ElevationAccuracyIdx',c_uint16),
        ('DspWorkload',c_byte),
        ('ARMWorkload', c_byte),
        ('Reserved2',c_byte * 6),
    ]
 
def bytes_hex(bytes):
    return ' '.join(["%02x" % b for b in bytes])
 
if __name__ == '__main__':
    if len(argv) != 2:
        print('Usage: python parser.py [filename]')
        exit(1)
 
    print(sizeof(Handshake))
    filename = argv[1]
    file_size = os.path.getsize(filename)
    with open(filename, "rb") as udp_file:
        if file_size == 24:
            handshake = Handshake.from_buffer_copy(udp_file.read(sizeof(Handshake)))
            udp_file.close()
            print('Magic: ', bytes_hex(handshake.Magic))
            print('FrameDataLength: ', handshake.FrameDataLength)
            print('Reserved: ', bytes_hex(handshake.Reserved))
        elif file_size == 256:
            header = Header.from_buffer_copy(udp_file.read(sizeof(Header)))
            udp_file.close()
            print('Magic: ', bytes_hex(header.Magic))
            print('FrameNumber: ', header.FrameNumber)
            print('VersionNumber: ', header.VersionNumber)
            print('NumberOfDetection: ', header.NumberOfDetection)
            print('NumberOfTrack: ', header.NumberOfTrack)
            print('HostSpeed: ', header.HostSpeed)
            print('HostAngle: ', header.HostAngle)
            print('Reserved: ', bytes_hex(header.Reserved)) 
            print('RangeAccuracyIdx: ', header.RangeAccuracyIdx)
            print('DopplerAccuracyIdx: ', header.DopplerAccuracyIdx)
            print('AzimuthAccuracyIdx: ', header.AzimuthAccuracyIdx)
            print('ElevationAccuracyIdx: ', header.ElevationAccuracyIdx)
            print('DspWorkload: ', header.DspWorkload)
            print('ARMWorkload: ', header.ARMWorkload)
            print('Reserved2: ', bytes_hex(header.Reserved2))