Hi folks,
I'm a new user of the wonderful Inline modules. I've shied away from XS and
SWIG in the past after some frustration with each, but am happy to say that I
got my first Inline-using module together in two hours!
Great documentation, great module!
A newbie question:
I have a couple of functions that I'm calling that are defined (in
linux/i2c-dev.h) as (bodies elided):
extern inline __s32 i2c_smbus_read_block_data(int file, __u8 command, __u8
*values) { ... }
extern inline __s32 i2c_smbus_write_block_data(int file, __u8 command, __u8
length, __u8 *values) { ... }
These eventually call an ioctl() call which does a synchronous SMBus transfer
and returns a success code.
I set CCFLAGS to -O2 so that the inlined functions will work right. This is
working fine for other, simpler functions.
But I'm not sure about how to handle returning a character string. The above
routines return -1 on error. read_block_data returns the number of bytes read
if successful.
What I was hoping to do in _readBlockData is to use the "output" argument as
a data buffer in which to write data (like the buffer argument to sysread()
for instance).
I tried this, but I don't know if it's right (the call won't return more than
32 characters):
int _readBlockData(int file, int command, SV* output)
{
char buf[ 32 ];
int retval = i2c_smbus_read_block_data(file, command, buf);
if (retval == -1)
return retval;
sv_setpvn(output, buf, retval); /* retval is # of bytes read */
return retval;
}
And then I'm doing this on the write side:
int _writeBlockData(int file, int command, SV* value)
{
STRLEN len;
char *buf = SvPV(value, len);
return i2c_smbus_write_block_data(file, command, len, buf);
}
Do these look like the right way to do the job?
Thanks,
--
Ned Konz
currently: Stanwood, WA
email: [EMAIL PROTECTED]
homepage: http://bike-nomad.com