smbmsg: use a more convenient way of accessing data read from a slave

Developers writing code for accessing /dev/smb may use this base utility
as an example.  Now that SMB_READB, SMB_READW, SMB_PCALL behave as
documented, wwe can use them in a more convenient way than before.

MFC after:	4 weeks
X-MFC after:	r308527
This commit is contained in:
Andriy Gapon 2016-11-11 15:00:13 +00:00
parent f43618f59f
commit cf3a35a755
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=308528

View File

@ -61,7 +61,7 @@ static int wflag; /* word IO */
static unsigned char ibuf[SMB_MAXBLOCKSIZE];
static unsigned char obuf[SMB_MAXBLOCKSIZE];
static unsigned short oword, iword;
static unsigned short oword;
/*
* The I2C specs say that all addresses below 16 and above or equal
@ -135,6 +135,8 @@ do_io(void)
c.slave = slave;
c.cmd = cflag;
c.rcount = 0;
c.wcount = 0;
if (fmt == NULL && iflag > 0)
fmt = wflag? wordfmt: bytefmt;
@ -163,11 +165,9 @@ do_io(void)
}
if (iflag == 1 && oflag == -1) {
/* command + 1 byte input: read byte op. */
c.rbuf = ibuf;
c.rcount = iflag;
if (ioctl(fd, SMB_READB, &c) == -1)
return (-1);
printf(fmt, (int)(unsigned char)ibuf[0]);
printf(fmt, (unsigned char)c.rdata.byte);
putchar('\n');
return (0);
} else if (iflag == -1 && oflag == 1) {
@ -176,11 +176,9 @@ do_io(void)
return (ioctl(fd, SMB_WRITEB, &c));
} else if (wflag && iflag == 2 && oflag == -1) {
/* command + 2 bytes input: read word op. */
c.rbuf = (char*) &iword;
c.rcount = iflag;
if (ioctl(fd, SMB_READW, &c) == -1)
return (-1);
printf(fmt, (int)(unsigned short)iword);
printf(fmt, (unsigned short)c.rdata.word);
putchar('\n');
return (0);
} else if (wflag && iflag == -1 && oflag == 2) {
@ -193,11 +191,9 @@ do_io(void)
* "process call" op.
*/
c.wdata.word = oword;
c.rbuf = (char*) &iword;
c.rcount = iflag;
if (ioctl(fd, SMB_PCALL, &c) == -1)
return (-1);
printf(fmt, (int)(unsigned short)iword);
printf(fmt, (unsigned short)c.rdata.word);
putchar('\n');
return (0);
} else if (iflag > 1 && oflag == -1) {
@ -206,7 +202,7 @@ do_io(void)
c.rcount = iflag;
if (ioctl(fd, SMB_BREAD, &c) == -1)
return (-1);
for (i = 0; i < iflag; i++) {
for (i = 0; i < c.rcount; i++) {
if (i != 0)
putchar(' ');
printf(fmt, ibuf[i]);