/** * @file fake_onewire.h * @brief Модель шины 1-Wire с виртуальными датчиками для host-тестов. */ #ifndef FAKE_ONEWIRE_H #define FAKE_ONEWIRE_H #include #define FAKE_MAX_DEVICES 8U /** Виртуальный датчик: ROM, scratchpad и управляемые отказы. */ typedef struct { uint8_t rom[8]; uint8_t scratchpad[9]; uint8_t present; /**< 0 - датчик снят с шины. */ uint8_t parasite; /**< 1 - отвечает как паразитно питаемый. */ uint8_t accept_writes; /**< 0 - молча игнорирует запись. */ uint8_t corrupt_crc; /**< 1 - портит CRC8 scratchpad. */ } fake_device_t; typedef struct { fake_device_t devices[FAKE_MAX_DEVICES]; uint8_t count; uint32_t reset_count; uint32_t convert_count; uint32_t copy_count; uint32_t delay_us_total; } fake_bus_t; /** Подключает модель к порту; после вызова работают функции OneWire_*. */ void fake_bus_attach(fake_bus_t *bus); /** Заполняет датчик: семь байт ROM без CRC, температура и тип питания. */ void fake_device_init(fake_device_t *device, const uint8_t rom7[7], int16_t raw, uint8_t parasite); uint8_t fake_bus_crc8(const uint8_t *data, uint32_t size); #endif /* FAKE_ONEWIRE_H */