IBASE IB113 User Manual
Page 41
Copyright © 2013 IBASE Technology Inc. All Rights Reserved.
41
IBASE Technology Inc.
"address 0x%02x, ", filename, address);
if (daddress < 0)
fprintf(stderr, "current data\naddress");
else
fprintf(stderr, "data address\n0x%02x", daddress);
fprintf(stderr, ", using %s.\n",
size == I2C_SMBUS_BYTE ? (daddress < 0 ?
"read byte" : "write byte/read byte") :
size == I2C_SMBUS_BYTE_DATA ? "read byte data" :
"read word data");
if (pec)
fprintf(stderr, "PEC checking enabled.\n");
fprintf(stderr, "Continue? [%s] ", dont ? "y/N" : "Y/n");
fflush(stderr);
if (!user_ack(!dont)) {
fprintf(stderr, "Aborting on user request.\n");
return 0;
}
return 1;
}
int main(int argc, char *argv[])
{
char *end;
int res, i2cbus, address, size, file;
int daddress;
char filename[20];
int pec = 0;
int flags = 0;
int force = 0, yes = 0, version = 0;
/* handle (optional) flags first */
while (1+flags < argc && argv[1+flags][0] == '-') {
switch (argv[1+flags][1]) {
case 'V': version = 1; break;
case 'f': force = 1; break;
case 'y': yes = 1; break;
default:
fprintf(stderr, "Error: Unsupported option "
"\"%s\"!\n", argv[1+flags]);
help();
exit(1);
}
flags++;
}
if (version) {
fprintf(stderr, "i2cget version %s\n", VERSION);
exit(0);
}
if (argc < flags + 3)
help();
i2cbus = lookup_i2c_bus(argv[flags+1]);
if (i2cbus < 0)
help();
address = parse_i2c_address(argv[flags+2]);
if (address < 0)
help();
if (argc > flags + 3) {
size = I2C_SMBUS_BYTE_DATA;
daddress = strtol(argv[flags+3], &end, 0);
if (*end || daddress < 0 || daddress > 0xff) {
fprintf(stderr, "Error: Data address invalid!\n");
help();