| | 347 | /* |
| | 348 | * Parse a CHIP-ADDRESS command line argument and return the corresponding |
| | 349 | * chip address, or a negative value if the address is invalid. |
| | 350 | */ |
| | 351 | int parse_i2c_address(const char *address_arg) |
| | 352 | { |
| | 353 | long address; |
| | 354 | char *end; |
| | 355 | |
| | 356 | address = strtol(address_arg, &end, 0); |
| | 357 | if (*end || !*address_arg) { |
| | 358 | fprintf(stderr, "Error: Chip address is not a number!\n"); |
| | 359 | return -1; |
| | 360 | } |
| | 361 | if (address < 0x03 || address > 0x77) { |
| | 362 | fprintf(stderr, "Error: Chip address out of range " |
| | 363 | "(0x03-0x77)!\n"); |
| | 364 | return -2; |
| | 365 | } |
| | 366 | |
| | 367 | return address; |
| | 368 | } |
| | 369 | |