I'm porting a simple bluetooth app, which sends "magic" packet on L2Cap protocol to bluetooth device..
I have a problem with converting struct object in C to python equivalent..
In c:
/* command types */
#define CFGBT_TYPE_SETREQ 0x00
#define CFGBT_TYPE_SETRES 0x01
#define CFGBT_TYPE_GETREQ 0x02
#define CFGBT_TYPE_GETRES 0x03
/* varid types */
#define CFG_VARIDT_UINT16 0x0000
#define CFG_VARIDT_UINT32 0x1000
#define CFG_VARIDT_STRING16 0x2000
typedef struct {
uint8_t type, status;
uint16_t varid;
uint8_t value[16];
} __attribute__((packed)) CFGBTFRAME;
static CFGBTFRAME c;
and then in app it's used like that:
/* set up */
c.type = CFGBT_TYPE_GETREQ;
c.varid = strtol(argv[3], NULL, 0);
c.status = 0;
memset(c.value, 0, 16);
/* send frame */
write(s, &c, sizeof(c));
Can you point me out how to construct same packet/stuct-like structure using python?
I know I will probably need to use ctypes and create "empty" class, but how to get all this together?
ctypes.Structure, you specify the fields, then youfile_like_obj.write(yourobject)once you've populated the fields.