public static void PacketGroundSensor(Packet Packet) { if (Packet == null || Packet.Data == null || Packet.Data.Payload == null || Packet.Data.Payload.Length != 40) { Log.Output(Log.Severity.WARNING, Log.Source.NETWORK, "Ground sensor packet invalid. Discarding. Length: " + Packet?.Data?.Payload?.Length); return; } DateTime Timestamp = DateTime.Now; int UVLight = UtilData.ToInt(UtilMain.SubArray(Packet.Data.Payload, 0, 4)); float AirQuality = UtilData.ToFloat(UtilMain.SubArray(Packet.Data.Payload, 4, 4)); float SoilMoist = UtilData.ToFloat(UtilMain.SubArray(Packet.Data.Payload, 8, 4)); uint ThermocoupleData = UtilData.ToUInt(UtilMain.SubArray(Packet.Data.Payload, 12, 4)); double AtmoTemp = UtilData.ToDouble(UtilMain.SubArray(Packet.Data.Payload, 16, 8)); double AtmoPres = UtilData.ToDouble(UtilMain.SubArray(Packet.Data.Payload, 24, 8)); double AtmoHumid = UtilData.ToDouble(UtilMain.SubArray(Packet.Data.Payload, 32, 8)); UV.Data.Add(new Datum <int>(Timestamp, UVLight)); AirPollution.Data.Add(new Datum <float>(Timestamp, AirQuality)); SoilMoisture.Data.Add(new Datum <float>(Timestamp, SoilMoist)); ThermoExt.Data.Add(new Datum <float>(Timestamp, MAX31855.ConvertExternalFromRaw(ThermocoupleData))); ThermoInt.Data.Add(new Datum <float>(Timestamp, MAX31855.ConvertInternalFromRaw(ThermocoupleData))); AirTemp.Data.Add(new Datum <double>(Timestamp, AtmoTemp)); AirPressure.Data.Add(new Datum <double>(Timestamp, AtmoPres)); AirHumidity.Data.Add(new Datum <double>(Timestamp, AtmoHumid)); }
/// <summary> Gets a new reading from the sensor and stores it. </summary> public void UpdateState() { byte[] InputData = this.Bus.Write(this.ChipSelect, new byte[] { 0x00, 0x00, 0x00, 0x00 }, 4); if (InputData != null && InputData.Length == 4) { this.LastReading = UtilData.ToUInt(InputData); } }
/// <summary> Gets a new reading from the sensor and stores it. </summary> public void UpdateState() { byte[] InputData = this.Bus.Write(this.ChipSelect, new byte[] { 0x00, 0x00, 0x00, 0x00 }, 4); if (InputData != null && InputData.Length == 4) { this.LastReading = UtilData.ToUInt(InputData); } if (this.TraceLogging) { Log.Trace(this, "Received raw data: " + this.LastReading.ToString("X8")); } }