generic sendN2k handling for sensors

This commit is contained in:
andreas 2023-10-31 16:13:47 +01:00
parent ab53d2b626
commit d3641668fb
1 changed files with 29 additions and 23 deletions

View File

@ -169,6 +169,29 @@ bool addHumidXdr(GwApi *api, CFG &cfg, const String &prefix)
return true; return true;
} }
template <class CFG>
void sendN2kHumidity(GwApi *api,CFG &cfg,const String &prfx,double value, int counterId){
tN2kMsg msg;
SetN2kHumidity(msg,1,cfg.iid,cfg.huSrc,value);
api->sendN2kMessage(msg);
api->increment(counterId,prfx+String("hum"));
}
template <class CFG>
void sendN2kPressure(GwApi *api,CFG &cfg,const String &prfx,double value, int counterId){
tN2kMsg msg;
SetN2kPressure(msg,1,cfg.iid,cfg.prSrc,value);
api->sendN2kMessage(msg);
api->increment(counterId,prfx+String("press"));
}
template <class CFG>
void sendN2kTemperature(GwApi *api,CFG &cfg,const String &prfx,double value, int counterId){
tN2kMsg msg;
SetN2kTemperature(msg,1,cfg.iid,cfg.tmSrc,value);
api->sendN2kMessage(msg);
api->increment(counterId,prfx+String("temp"));
}
void runIicTask(GwApi *api); void runIicTask(GwApi *api);
void initIicTask(GwApi *api){ void initIicTask(GwApi *api){
@ -246,16 +269,11 @@ void runIicTask(GwApi *api){
temp=CToKelvin(temp); temp=CToKelvin(temp);
double humid=sht3x->humidity; double humid=sht3x->humidity;
LOG_DEBUG(GwLog::DEBUG,"SHT3X measure temp=%2.1f, humid=%2.0f",(float)temp,(float)humid); LOG_DEBUG(GwLog::DEBUG,"SHT3X measure temp=%2.1f, humid=%2.0f",(float)temp,(float)humid);
tN2kMsg msg;
if (sht3xConfig.huAct){ if (sht3xConfig.huAct){
SetN2kHumidity(msg,1,sht3xConfig.iid,sht3xConfig.huSrc,humid); sendN2kHumidity(api,sht3xConfig,"SHT3X",humid,counterId);
api->sendN2kMessage(msg);
api->increment(counterId,"SHT3Xhum");
} }
if (sht3xConfig.tmAct){ if (sht3xConfig.tmAct){
SetN2kTemperature(msg,1,sht3xConfig.iid,sht3xConfig.tmSrc,temp); sendN2kTemperature(api,sht3xConfig,"SHT3X",temp,counterId);
api->sendN2kMessage(msg);
api->increment(counterId,"SHT3Xtemp");
} }
} }
else{ else{
@ -278,10 +296,7 @@ void runIicTask(GwApi *api){
float pressure=qmp6988->calcPressure(); float pressure=qmp6988->calcPressure();
float computed=pressure+qmp6988Config.prOff; float computed=pressure+qmp6988Config.prOff;
LOG_DEBUG(GwLog::DEBUG,"qmp6988 measure %2.0fPa, computed %2.0fPa",pressure,computed); LOG_DEBUG(GwLog::DEBUG,"qmp6988 measure %2.0fPa, computed %2.0fPa",pressure,computed);
tN2kMsg msg; sendN2kPressure(api,qmp6988Config,"QMP6988",computed,counterId);
SetN2kPressure(msg,1,qmp6988Config.iid,tN2kPressureSource::N2kps_Atmospheric,computed);
api->sendN2kMessage(msg);
api->increment(counterId,"QMP6988press");
}); });
} }
#endif #endif
@ -305,27 +320,18 @@ void runIicTask(GwApi *api){
float pressure=bme280->readPressure(); float pressure=bme280->readPressure();
float computed=pressure+bme280Config.prOff; float computed=pressure+bme280Config.prOff;
LOG_DEBUG(GwLog::DEBUG,"BME280 measure %2.0fPa, computed %2.0fPa",pressure,computed); LOG_DEBUG(GwLog::DEBUG,"BME280 measure %2.0fPa, computed %2.0fPa",pressure,computed);
tN2kMsg msg; sendN2kPressure(api,bme280Config,"BME280",computed,counterId);
SetN2kPressure(msg,1,bme280Config.iid,bme280Config.prSrc,computed);
api->sendN2kMessage(msg);
api->increment(counterId,"BME280press");
} }
if (bme280Config.tmAct){ if (bme280Config.tmAct){
float temperature=bme280->readTemperature(); //offset is handled internally float temperature=bme280->readTemperature(); //offset is handled internally
temperature=CToKelvin(temperature); temperature=CToKelvin(temperature);
LOG_DEBUG(GwLog::DEBUG,"BME280 measure temp=%2.1f",temperature); LOG_DEBUG(GwLog::DEBUG,"BME280 measure temp=%2.1f",temperature);
tN2kMsg msg; sendN2kTemperature(api,bme280Config,"BME280",temperature,counterId);
SetN2kTemperature(msg,1,bme280Config.iid,bme280Config.tmSrc,temperature);
api->sendN2kMessage(msg);
api->increment(counterId,"BME280temp");
} }
if (bme280Config.huAct && hasHumidity){ if (bme280Config.huAct && hasHumidity){
float humidity=bme280->readHumidity(); float humidity=bme280->readHumidity();
LOG_DEBUG(GwLog::DEBUG,"BME280 read humid=%02.0f",humidity); LOG_DEBUG(GwLog::DEBUG,"BME280 read humid=%02.0f",humidity);
tN2kMsg msg; sendN2kHumidity(api,bme280Config,"BME280",humidity,counterId);
SetN2kHumidity(msg,1,bme280Config.iid,bme280Config.huSrc,humidity);
api->sendN2kMessage(msg);
api->increment(counterId,"BME280hum");
} }
}); });
runLoop = true; runLoop = true;