valid attr

This commit is contained in:
Wolfgang Hottgenroth
2021-06-04 12:19:40 +02:00
parent b08efc4db4
commit 258177fcdb

View File

@ -257,22 +257,22 @@ void deinitForwarder(t_commonHandle *handle) {
} }
int sendToDB(t_commonHandle *handle, const char *location, const char *deviceId, int sendToDB(t_commonHandle *handle, const char *location, const char *deviceId,
uint32_t frequency, uint64_t timestamp) { uint32_t frequency, uint8_t valid, uint64_t timestamp) {
int retcode = 0; int retcode = 0;
if (0 == openDatabaseConnection(handle)) { if (0 == openDatabaseConnection(handle)) {
int frequency_before_point = frequency / 1000; int frequency_before_point = frequency / 1000;
int frequency_behind_point = frequency - (frequency_before_point * 1000); int frequency_behind_point = frequency - (frequency_before_point * 1000);
char stmt[256]; char stmt[256];
int res1 = snprintf(stmt, sizeof(stmt), int res1 = snprintf(stmt, sizeof(stmt),
"INSERT INTO mainsfrequency (time, host, location, freq) " "INSERT INTO mainsfrequency (time, host, location, valid, freq) "
"VALUES(to_timestamp(" "VALUES(to_timestamp("
#ifdef OpenBSD #ifdef OpenBSD
"%llu" "%llu"
#else #else
"%lu" "%lu"
#endif #endif
"), '%s', '%s', %d.%03d)", "), '%s', '%s', %d, %d.%03d)",
timestamp, deviceId, location, timestamp, deviceId, location, valid,
frequency_before_point, frequency_behind_point); frequency_before_point, frequency_behind_point);
if (res1 > sizeof(stmt)) { if (res1 > sizeof(stmt)) {
logmsg(LOG_ERR, "stmt buffer to small"); logmsg(LOG_ERR, "stmt buffer to small");
@ -314,11 +314,11 @@ int forwardMinuteBuffer(t_commonHandle *handle, t_minuteBuffer *buf) {
logmsg(LOG_DEBUG, "Time: %lu, Frequency: %u", timestamp, buf->s.frequency[j]); logmsg(LOG_DEBUG, "Time: %lu, Frequency: %u", timestamp, buf->s.frequency[j]);
if (device->inactive == 0) { if (device->inactive == 0) {
if ((buf->s.frequency[j] >= handle->lowerBound) && (buf->s.frequency[j] <= handle->upperBound)) { uint8_t valid = ((buf->s.frequency[j] >= handle->lowerBound) && (buf->s.frequency[j] <= handle->upperBound)) ? 1 : 0;
sendSuccess += sendToDB(handle, location, buf->s.deviceId, buf->s.frequency[j], timestamp); if (valid == 0) {
} else { logmsg(LOG_INFO, "Out of range: Time: %lu, Frequency: %u", timestamp, buf->s.frequency[j]);
logmsg(LOG_ERR, "%u out of bound, ignored", buf->s.frequency[j]);
} }
sendSuccess += sendToDB(handle, location, buf->s.deviceId, buf->s.frequency[j], valid, timestamp);
} else { } else {
logmsg(LOG_DEBUG, "Inactive device, not sent to database"); logmsg(LOG_DEBUG, "Inactive device, not sent to database");
} }