4

如何将其转换为在 Python 中使用?

下面的代码是一个复杂的嵌套 Union 和 Struct。很容易将其错误地转换为 Python。

typedef struct {
    unsigned char       enable;
    unsigned short      x;
    unsigned short      y;
    unsigned char       local;
    unsigned char       em;
    unsigned char       tr;
    short               at;
    unsigned char       reserved[6];
} IRF_SPOT;


typedef union strSAVEDATA
{
    struct
    {
        uint32_t    crc;
        uint8_t     ver;
        uint8_t     id;
        uint8_t     baudrate;
        int16_t     level;
        uint16_t    span;
        uint8_t     tv;
        uint8_t     agc;
        uint8_t     invert;
        uint8_t     mirror;
        uint8_t     flip;
        uint8_t     colorbar;
        uint8_t     showinfo;
        uint8_t     indicator;
        uint8_t     unit;
        uint8_t     dhcp;
        uint8_t     color;
        uint8_t     alpha;
        uint8_t     zoom;
        uint8_t     sharp;
        uint8_t     noise;          // new
        uint16_t    nuc;
        uint32_t    ipaddr;
        uint32_t    netmask;
        uint32_t    gateway;
        uint32_t    dns;
        uint8_t     alarm1_func;    // new
        uint8_t     alarm1_cond;    // new
        uint16_t    alarm1_value;   // new
        uint8_t     alarm2_func;    // new
        uint8_t     alarm2_cond;    // new
        uint16_t    alarm2_value;   // new
        uint8_t     temp_mode;      // reserved
        uint8_t     down_filter;    // reserved
        uint8_t     show_center;
        uint8_t     show_spot;
        uint8_t     show_correction;
        uint8_t     show_isotherm;
        uint8_t     reserved1[70];      
        uint8_t     limit9;
        uint8_t     enable_high;    
        uint8_t     correction;
        uint8_t     emissivity;
        uint8_t     transmission;
        int16_t atmosphere;
        struct {
            uint8_t     enable;
            uint16_t    x;
            uint16_t    y;
            uint8_t     local;
            uint8_t     em;
            uint8_t     tr;
            int16_t at;
            uint8_t     reserved[6];
        } spot[10];
        struct {
            uint8_t     enable;
            uint32_t    seed_color;
            int16_t     top;
            int16_t     bottom;
            uint8_t     reserved[3];
        } iso[3];
    };
    char padding[512];
} IRF_SAVEDATA_T;



typedef struct 
{
    unsigned short* ir_image;   
    DWORD image_buffer_size;    
    LPBYTE lpNextData;          
    DWORD dwSize;               
    DWORD dwPosition;           
    IRF_MESSAGE_TYPE_T      msg_type;
    IRF_SAVEDATA_T          save_data;      
    unsigned int            fw_ver;         
    unsigned short PMSGTYPE;    // Primary Message Type Code
    unsigned short RCODE;       // Response Code
} IRF_IR_CAM_DATA_T;

这太复杂了。我用它来连接网络摄像头,但摄像头不回复消息。请教我如何正确转换它。

我的 Python 代码:

class spot(Structure):
    _fields_ = [
            ('enable',wintypes.c_uint8),
            ('x',wintypes.c_uint16),
            ('y',wintypes.c_uint16),
            ('local',wintypes.c_uint8),
            ('em',wintypes.c_uint8),
            ('tr',wintypes.c_uint8),
            ('at',wintypes.c_uint16),
            ('reserved',wintypes.c_uint8*6)
            ]

class iso(Structure):
    _fields_ = [
            ('enable',wintypes.c_uint8),
            ('seed_color',wintypes.c_uint32),
            ('top',wintypes.c_int16),
            ('bottom',wintypes.c_int16),
            ('reserved',wintypes.c_uint8)
            ]
class strSAVEDATA(Structure):
    _fields_ = [
            ('crc',wintypes.c_uint32),
            ('ver',wintypes.c_uint8),
            ('id',wintypes.c_uint8),
            ('baudrate',wintypes.c_uint8),
            ('level',wintypes.c_int16),
            ('span',wintypes.c_uint16),
            ('tv',wintypes.c_uint8),
            ('agc',wintypes.c_uint8),
            ('invert',wintypes.c_uint8),
            ('mirror',wintypes.c_uint8),
            ('flip',wintypes.c_uint8),
            ('colorbar',wintypes.c_uint8),
            ('showinfo',wintypes.c_uint8),
            ('indicator',wintypes.c_uint8),
            ('unit',wintypes.c_uint8),
            ('dhcp',wintypes.c_uint8),
            ('color',wintypes.c_uint8),
            ('alpha',wintypes.c_uint8),
            ('zoon',wintypes.c_uint8),
            ('sharp',wintypes.c_uint8),
            ('noise',wintypes.c_uint8),
            ('nuc',wintypes.c_uint16),
            ('ipaddr',wintypes.c_uint32),
            ('netmask',wintypes.c_uint32),
            ('gatway',wintypes.c_uint32),
            ('dns',wintypes.c_uint32),
            ('alarm1_func',wintypes.c_uint8),
            ('alarm1_cond',wintypes.c_uint8),
            ('alarm1_value',wintypes.c_uint16),
            ('alarm2_func',wintypes.c_uint8),
            ('alarm2_cond',wintypes.c_uint8),
            ('alarm2_value',wintypes.c_uint16),  
            ('temp_mode',wintypes.c_uint8),
            ('down_filter',wintypes.c_uint8),
            ('show_center',wintypes.c_uint8),
            ('show_spot',wintypes.c_uint8),
            ('show_correction',wintypes.c_uint8),
            ('show_isotherm',wintypes.c_uint8),
            ('reserved1',wintypes.c_uint8*70),
            ('limit9',wintypes.c_uint8),
            ('enable_high',wintypes.c_uint8),
            ('correction',wintypes.c_uint8),
            ('emissivity;',wintypes.c_uint8),
            ('transmission',wintypes.c_uint8),
            ('atmosphere',wintypes.c_int16),
            ('spot',spot*10),
            ('iso',iso*3)
            ]    

class IRF_SAVEDATA_T(Union):
    _fields_ = [
            ('strSAVEDATA',strSAVEDATA),
            ('padding',wintypes.c_uint8*512)
            ]

class IRF_IR_CAM_DATA_T(Structure):
    _fields_ = [
            ('ir_image',POINTER(wintypes.USHORT)),
            ('image_buffer_size',wintypes.DWORD),
            ('lpNextData',POINTER(wintypes.BYTE)),
            ('dwSize',wintypes.DWORD),
            ('dwPosition',wintypes.DWORD),
            ('msg_type',IRF_MESSAGE_TYPE_T),
            ('save_data',IRF_SAVEDATA_T),
            ('fw_ver',wintypes.UINT),
            ('PMSGTYPE',wintypes.USHORT),
            ('RCODE',wintypes.USHORT)                
            ]
4

0 回答 0