addMessage method
- WrappedMessage wrapper
Adds a WrappedMessage containing a ScienceData to the UI.
Implementation
void addMessage(WrappedMessage wrapper) {
if (!wrapper.name.contains(ScienceData().messageName)) throw ArgumentError("Incorrect log type: ${wrapper.name}");
final data = wrapper.decode(ScienceData.fromBuffer);
final sample = data.sample;
if (!wrapper.hasTimestamp()) { throw ArgumentError("Data is missing a timestamp"); }
if (sample >= numSamples) throw RangeError("Got data for sample #${sample + 1}, but there are only $numSamples samples.\nChange the number of samples in the settings and reload.");
if (data.co2 != 0) addReading(co2, sample, wrapper.timestamp, data.co2);
if (data.humidity != 0) addReading(humidity, sample, wrapper.timestamp, data.humidity);
if (data.temperature != 0) addReading(temperature, sample, wrapper.timestamp, data.temperature);
}