Files
templates/c/gas-logger/tests/host_device.c
T
Andrey e93bd3b6aa style: унифицируй форматирование C и C++
Закрепи табуляцию и размещение скобок в настройках проекта. Примени единый стиль к собственным исходникам.
2026-12-02 11:33:41 +03:00

57 lines
1.6 KiB
C

/*
* Проверки host_device: фиксируют ожидаемое поведение на воспроизводимых входных данных.
* Тестовые значения и подмены окружения относятся к проверке контракта; они не являются
* настройками рабочего устройства.
*/
/* Host-only firmware harness for the actual PM35 port and Python client. */
#include "gas_logger_pm35.h"
#include "gas_logger_pcan.h"
#include <assert.h>
static gas_logger log;
static uint16_t bank0[9120], bank1[9120], modbus[128], voltage[2];
static uint32_t irq;
static uint32_t enter(void *u)
{
uint32_t old = irq;
(void)u;
irq = 1;
return old;
}
static void leave(void *u, uint32_t state)
{
(void)u;
assert(irq == 1);
irq = state;
}
static gl_pm35_context context = {modbus, voltage, enter, leave, 0};
int host_init(void)
{
irq = 0;
return gl_pm35_init(&log, &context, bank0, bank1, 9120);
}
int host_capture(uint32_t time, uint16_t value)
{
modbus[28] = value;
modbus[127] = 128;
voltage[0] = 1234;
voltage[1] = 5678;
return gl_capture(&log, time, 1);
}
int host_read(uint16_t address, uint16_t *out, uint16_t count)
{
return gl_modbus_read(&log, address, out, count);
}
int host_write(uint16_t address, uint16_t value)
{
return gl_modbus_write(&log, address, value);
}
int host_pcan_read(uint16_t address, uint16_t *out)
{
pcan_gas_region_t region;
gl_pcan_region_init(&region, &log);
if (address < region.base || (uint32_t)address >= region.base + region.count)
return GL_ADDRESS;
return region.read(&region, (uint16_t)(address - region.base), out);
}