Add time to the sensor list widget, also broadcast and recive the time of a sensor

This commit is contained in:
2023-11-08 23:35:50 +01:00
parent 260334ef35
commit a301bdbaa7
15 changed files with 557 additions and 266 deletions

View File

@ -34,7 +34,8 @@ public:
id(idIn), field(fieldIn), name(nameIn), hidden(hiddenIn)
{
lastSeen = QDateTime::currentDateTime();
if(nameIn == "") generateName();
if(nameIn == "")
generateName();
}
Sensor(QString nameIn = "dummy"): type(TYPE_DUMMY), id(0), field(0), name(nameIn), hidden(false)
{
@ -58,15 +59,23 @@ public:
if(bufferList.size() >= 7)
{
Sensor sensor(bufferList[2].toUInt(), bufferList[4].toUInt(), bufferList[6].toUInt());
if(sensor.type == Sensor::TYPE_HUMIDITY || sensor.type == Sensor::TYPE_TEMPERATURE) sensor.field = sensor.field/10;
if(sensor.type == Sensor::TYPE_HUMIDITY || sensor.type == Sensor::TYPE_TEMPERATURE)
sensor.field = sensor.field/10;
if(bufferList.size() >= 9)
sensor.lastSeen = QDateTime::fromSecsSinceEpoch(bufferList[8].toLongLong());
return sensor;
}
else return Sensor(TYPE_DUMMY, 0, 0, "", true);
else
{
return Sensor(TYPE_DUMMY, 0, 0, "", true);
}
}
QString toString()
{
return QString("SENSOR TYPE: ")+QString::number(type)+" ID: "+QString::number(id)+" FIELD: "+
QString::number((type == Sensor::TYPE_HUMIDITY || type == Sensor::TYPE_TEMPERATURE) ? field*10 : field);
QString::number((type == Sensor::TYPE_HUMIDITY || type == Sensor::TYPE_TEMPERATURE) ? field*10 : field) +
" TIME: " + QString::number(lastSeen.toSecsSinceEpoch());
}
inline void generateName()
{