Files
templates/c/gas-logger/ports/pm35/gas_logger_pm35.c

29 lines
1.3 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* Связь регистратора ПМ35 с картой доступных сигналов. Адреса сигналов согласуются с
* JSON-картой клиента; изменение только одной стороны приводит к неверной интерпретации снимка
* даже при успешном обмене.
*/
#include "gas_logger_pm35.h"
#include "pm35_map.h"
static uint32_t enter(void *u) { gl_pm35_context *p=u; return p->enter(p->irq_user); }
static void leave(void *u,uint32_t state) { gl_pm35_context *p=u; p->leave(p->irq_user,state); }
static int source(void *u,uint16_t gas,uint16_t *v)
{
gl_pm35_context *p=u;
uint16_t i;
for(i=0;i<gl_pm35_config.channels;i++) if(gl_pm35_channels[i].gas==gas) {
*v=gl_pm35_source_space[i] ? p->pm67_voltage[gl_pm35_source_address[i]] :
p->modbus[gl_pm35_source_address[i]];
return 1;
}
return 0;
}
gl_result gl_pm35_init(gas_logger *l,gl_pm35_context *p,uint16_t *a,uint16_t *b,uint32_t n)
{
gl_port port;
if(!p || !p->modbus || !p->pm67_voltage || !p->enter || !p->leave) return GL_ARGUMENT;
port.user=p;port.enter=enter;port.leave=leave;port.source=source;
return gl_init(l,&gl_pm35_config,&port,a,b,n);
}