![background image](http://html1.mh-extra.com/html/ibase-technology/ib113/ib113_user-manual_3233460048.webp)
Copyright © 2013 IBASE Technology Inc. All Rights Reserved.
47
IBASE Technology Inc.
size = I2C_SMBUS_BYTE;
pec = argv[flags+4][1] == 'p';
} else {
size = I2C_SMBUS_BYTE_DATA;
}
} else {
/* All other commands */
if (strlen(argv[argc-1]) > 2
|| (strlen(argv[argc-1]) == 2 && argv[argc-1][1] != 'p')) {
fprintf(stderr, "Error: Invalid mode '%s'!\n", argv[argc-1]);
help();
}
switch (argv[argc-1][0]) {
case 'b': size = I2C_SMBUS_BYTE_DATA; break;
case 'w': size = I2C_SMBUS_WORD_DATA; break;
case 's': size = I2C_SMBUS_BLOCK_DATA; break;
case 'i': size = I2C_SMBUS_I2C_BLOCK_DATA; break;
default:
fprintf(stderr, "Error: Invalid mode '%s'!\n", argv[argc-1]);
help();
}
pec = argv[argc-1][1] == 'p';
if (size == I2C_SMBUS_BLOCK_DATA || size == I2C_SMBUS_I2C_BLOCK_DATA) {
if (pec && size == I2C_SMBUS_I2C_BLOCK_DATA) {
fprintf(stderr, "Error: PEC not supported for I2C block writes!\n");
help();
}
if (maskp) {
fprintf(stderr, "Error: Mask not supported for block writes!\n");
help();
}
if (argc > (int)sizeof(block) + flags + 5) {
fprintf(stderr, "Error: Too many arguments!\n");
help();
}
} else if (argc != flags + 6) {
fprintf(stderr, "Error: Too many arguments!\n");
help();
}
}
len = 0; /* Must always initialize len since it is passed to confirm() */
/* read values from command line */
switch (size) {
case I2C_SMBUS_BYTE_DATA:
case I2C_SMBUS_WORD_DATA:
value = strtol(argv[flags+4], &end, 0);
if (*end || value < 0) {
fprintf(stderr, "Error: Data value invalid!\n");
help();
}
if ((size == I2C_SMBUS_BYTE_DATA && value > 0xff)
|| (size == I2C_SMBUS_WORD_DATA && value > 0xffff)) {
fprintf(stderr, "Error: Data value out of range!\n");
help();
}
break;
case I2C_SMBUS_BLOCK_DATA:
case I2C_SMBUS_I2C_BLOCK_DATA:
for (len = 0; len + flags + 5 < argc; len++) {
value = strtol(argv[flags + len + 4], &end, 0);
if (*end || value < 0) {
fprintf(stderr, "Error: Data value invalid!\n");
help();
}
if (value > 0xff) {
fprintf(stderr, "Error: Data value out of range!\n");
help();
}