| 317 | } |
| 318 | |
| 319 | owb_status owb_verify_rom(const OneWireBus * bus, OneWireBus_ROMCode rom_code, bool* is_present) |
| 320 | { |
| 321 | owb_status status; |
| 322 | bool result = false; |
| 323 | |
| 324 | if (!bus || !is_present) |
| 325 | { |
| 326 | status = OWB_STATUS_PARAMETER_NULL; |
| 327 | } |
| 328 | else if (!_is_init(bus)) |
| 329 | { |
| 330 | status = OWB_STATUS_NOT_INITIALIZED; |
| 331 | } |
| 332 | else |
| 333 | { |
| 334 | OneWireBus_SearchState state = { |
| 335 | .last_discrepancy = 64, |
| 336 | .last_device_flag = false, |
| 337 | }; |
| 338 | |
| 339 | bool is_found = false; |
| 340 | while (!state.last_device_flag && !is_found) |
| 341 | { |
| 342 | _search(bus, &state, &is_found); |
| 343 | if (is_found) |
| 344 | { |
| 345 | result = true; |
| 346 | for (int i = 0; i < sizeof(state.rom_code.bytes) && result; ++i) |
| 347 | { |
| 348 | result = rom_code.bytes[i] == state.rom_code.bytes[i]; |
| 349 | // ("%02x %02x", rom_code.bytes[i], state.rom_code.bytes[i]); |
| 350 | } |
| 351 | is_found = result; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | // ("rom code %sfound", result ? "" : "not "); |
| 356 | *is_present = result; |
| 357 | status = OWB_STATUS_OK; |
| 358 | } |
| 359 | |
| 360 | return status; |
| 361 | } |
| 362 | |
| 363 | owb_status owb_reset(const OneWireBus * bus, bool* a_device_present) |
| 364 | { |