mirror of
https://github.com/ckaczor/WeatherService.git
synced 2026-02-10 18:22:36 -05:00
More cleanup
This commit is contained in:
@@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
namespace WeatherService.Data
|
namespace WeatherService.Data
|
||||||
{
|
{
|
||||||
[Table("Device")]
|
[Table("Device")]
|
||||||
public class Device
|
public class DeviceData
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
namespace WeatherService.Data
|
namespace WeatherService.Data
|
||||||
{
|
{
|
||||||
[Table("Reading")]
|
[Table("Reading")]
|
||||||
public class Reading
|
public class ReadingData
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
namespace WeatherService.Data
|
namespace WeatherService.Data
|
||||||
{
|
{
|
||||||
[Table("Setting")]
|
[Table("Setting")]
|
||||||
public class Setting
|
public class SettingData
|
||||||
{
|
{
|
||||||
[Key]
|
[Key]
|
||||||
[StringLength(500)]
|
[StringLength(500)]
|
||||||
@@ -39,7 +39,7 @@ namespace WeatherService.Data
|
|||||||
DatabaseExists[year] = true;
|
DatabaseExists[year] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual DbSet<Reading> Readings { get; set; }
|
public virtual DbSet<ReadingData> Readings { get; set; }
|
||||||
|
|
||||||
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ namespace WeatherService.Data
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual DbSet<Device> Devices { get; set; }
|
public virtual DbSet<DeviceData> Devices { get; set; }
|
||||||
public virtual DbSet<Setting> Settings { get; set; }
|
public virtual DbSet<SettingData> Settings { get; set; }
|
||||||
|
|
||||||
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
protected override void OnModelCreating(DbModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
|
using OneWireAPI;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using OneWireAPI;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using WeatherService.Data;
|
using WeatherService.Data;
|
||||||
using WeatherService.Values;
|
using WeatherService.Values;
|
||||||
|
|
||||||
namespace WeatherService.Devices
|
namespace WeatherService.Devices
|
||||||
{
|
{
|
||||||
#region Enumerations
|
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public enum DeviceType
|
public enum DeviceType
|
||||||
{
|
{
|
||||||
@@ -35,8 +33,6 @@ namespace WeatherService.Devices
|
|||||||
Rain
|
Rain
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
[KnownType(typeof(HumidityDevice))]
|
[KnownType(typeof(HumidityDevice))]
|
||||||
[KnownType(typeof(PressureDevice))]
|
[KnownType(typeof(PressureDevice))]
|
||||||
@@ -46,56 +42,64 @@ namespace WeatherService.Devices
|
|||||||
[KnownType(typeof(WindSpeedDevice))]
|
[KnownType(typeof(WindSpeedDevice))]
|
||||||
public class DeviceBase
|
public class DeviceBase
|
||||||
{
|
{
|
||||||
#region Member variables
|
protected Session Session;
|
||||||
|
|
||||||
protected int _deviceId; // Device ID
|
protected internal Device OneWireDevice { get; protected set; }
|
||||||
protected string _deviceAddress; // Device key
|
|
||||||
protected Session _session; // The root session
|
|
||||||
protected owDevice _device; // The one wire device
|
|
||||||
protected DateTime _lastRead = DateTime.MinValue; // When was the last refresh?
|
|
||||||
protected int _refreshFrequency; // How often should we refresh?
|
|
||||||
protected Dictionary<WeatherValueType, Value> _valueList; // List of values
|
|
||||||
protected string _displayName; // Device display name
|
|
||||||
protected DeviceType _deviceType; // Type of device
|
|
||||||
protected long _operationCount; // Number of operations
|
|
||||||
protected long _errorCount; // Number of errors
|
|
||||||
|
|
||||||
#endregion
|
[DataMember]
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
#region Constructor
|
[DataMember]
|
||||||
|
public string Address { get; set; }
|
||||||
|
|
||||||
public DeviceBase(Session session, owDevice device, DeviceType deviceType)
|
[DataMember]
|
||||||
|
public string DisplayName { get; set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public DateTime LastRead { get; set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public long Operations { get; set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public long Errors { get; set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public DeviceType Type { get; set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public int RefreshFrequency { get; set; }
|
||||||
|
|
||||||
|
[DataMember]
|
||||||
|
public Dictionary<WeatherValueType, Value> Values { get; protected set; }
|
||||||
|
|
||||||
|
public DeviceBase(Session session, Device device, DeviceType deviceType)
|
||||||
{
|
{
|
||||||
|
LastRead = DateTime.MinValue;
|
||||||
|
|
||||||
// Initialize the value list
|
// Initialize the value list
|
||||||
_valueList = new Dictionary<WeatherValueType, Value>();
|
Values = new Dictionary<WeatherValueType, Value>();
|
||||||
|
|
||||||
// Store properties of the device
|
// Store properties of the device
|
||||||
_deviceAddress = device.Id.Name;
|
Address = device.Id.Name;
|
||||||
_deviceType = deviceType;
|
Type = deviceType;
|
||||||
_session = session;
|
Session = session;
|
||||||
_device = device;
|
OneWireDevice = device;
|
||||||
|
|
||||||
// Default the display name
|
// Default the display name
|
||||||
_displayName = device.Id.Name;
|
DisplayName = device.Id.Name;
|
||||||
|
|
||||||
// Default the read interval
|
// Default the read interval
|
||||||
if (Type == DeviceType.WindDirection || Type == DeviceType.WindSpeed)
|
RefreshFrequency = (Type == DeviceType.WindDirection || Type == DeviceType.WindSpeed) ? 1 : 120;
|
||||||
_refreshFrequency = 1;
|
|
||||||
else
|
|
||||||
_refreshFrequency = 120;
|
|
||||||
|
|
||||||
// Load device data
|
// Load device data
|
||||||
bool bLoad = Load();
|
var load = Load();
|
||||||
|
|
||||||
// If we couldn't load data then save the default data
|
// If we couldn't load data then save the default data
|
||||||
if (!bLoad)
|
if (!load)
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Save and load
|
|
||||||
|
|
||||||
internal bool Load()
|
internal bool Load()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -103,15 +107,15 @@ namespace WeatherService.Devices
|
|||||||
using (var weatherData = new WeatherData())
|
using (var weatherData = new WeatherData())
|
||||||
{
|
{
|
||||||
// Get the device data from the database
|
// Get the device data from the database
|
||||||
var deviceData = weatherData.Devices.FirstOrDefault(d => d.Address == _deviceAddress);
|
var deviceData = weatherData.Devices.FirstOrDefault(d => d.Address == Address);
|
||||||
|
|
||||||
if (deviceData == null)
|
if (deviceData == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Load the device data
|
// Load the device data
|
||||||
_deviceId = deviceData.Id;
|
Id = deviceData.Id;
|
||||||
_displayName = deviceData.Name;
|
DisplayName = deviceData.Name;
|
||||||
_refreshFrequency = deviceData.ReadInterval;
|
RefreshFrequency = deviceData.ReadInterval;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -127,14 +131,14 @@ namespace WeatherService.Devices
|
|||||||
using (var weatherData = new WeatherData())
|
using (var weatherData = new WeatherData())
|
||||||
{
|
{
|
||||||
// Get the device data from the database
|
// Get the device data from the database
|
||||||
var deviceData = weatherData.Devices.FirstOrDefault(d => d.Address == _deviceAddress);
|
var deviceData = weatherData.Devices.FirstOrDefault(d => d.Address == Address);
|
||||||
|
|
||||||
if (deviceData == null)
|
if (deviceData == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Save device data
|
// Save device data
|
||||||
deviceData.Name = _displayName;
|
deviceData.Name = DisplayName;
|
||||||
deviceData.ReadInterval = _refreshFrequency;
|
deviceData.ReadInterval = RefreshFrequency;
|
||||||
|
|
||||||
weatherData.SaveChanges();
|
weatherData.SaveChanges();
|
||||||
}
|
}
|
||||||
@@ -142,13 +146,9 @@ namespace WeatherService.Devices
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Internal cache refresh logic
|
|
||||||
|
|
||||||
internal bool DoCacheRefresh()
|
internal bool DoCacheRefresh()
|
||||||
{
|
{
|
||||||
switch (_refreshFrequency)
|
switch (RefreshFrequency)
|
||||||
{
|
{
|
||||||
case -1:
|
case -1:
|
||||||
// Do not refresh this device
|
// Do not refresh this device
|
||||||
@@ -161,7 +161,7 @@ namespace WeatherService.Devices
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (_lastRead == DateTime.MinValue)
|
if (LastRead == DateTime.MinValue)
|
||||||
{
|
{
|
||||||
// If we have never refreshed before then do it now
|
// If we have never refreshed before then do it now
|
||||||
RefreshCache();
|
RefreshCache();
|
||||||
@@ -170,10 +170,10 @@ namespace WeatherService.Devices
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the time since the last refresh
|
// Get the time since the last refresh
|
||||||
TimeSpan oTimeSpan = DateTime.Now - _lastRead;
|
var timeSpan = DateTime.Now - LastRead;
|
||||||
|
|
||||||
// If it has been long enough then refresh the cache
|
// If it has been long enough then refresh the cache
|
||||||
if (oTimeSpan.TotalSeconds >= _refreshFrequency)
|
if (timeSpan.TotalSeconds >= RefreshFrequency)
|
||||||
{
|
{
|
||||||
RefreshCache();
|
RefreshCache();
|
||||||
|
|
||||||
@@ -187,95 +187,18 @@ namespace WeatherService.Devices
|
|||||||
internal virtual void RefreshCache()
|
internal virtual void RefreshCache()
|
||||||
{
|
{
|
||||||
// Store the current time
|
// Store the current time
|
||||||
_lastRead = DateTime.Now;
|
LastRead = DateTime.Now;
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public properties
|
|
||||||
|
|
||||||
[DataMember]
|
|
||||||
public int Id
|
|
||||||
{
|
|
||||||
get { return _deviceId; }
|
|
||||||
set { _deviceId = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[DataMember]
|
|
||||||
public string Address
|
|
||||||
{
|
|
||||||
get { return _deviceAddress; }
|
|
||||||
set { _deviceAddress = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[DataMember]
|
|
||||||
public string DisplayName
|
|
||||||
{
|
|
||||||
get { return _displayName; }
|
|
||||||
set { _displayName = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal owDevice OneWireDevice
|
|
||||||
{
|
|
||||||
get { return _device; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[DataMember]
|
|
||||||
public DateTime LastRead
|
|
||||||
{
|
|
||||||
get { return _lastRead; }
|
|
||||||
set { _lastRead = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[DataMember]
|
|
||||||
public long Operations
|
|
||||||
{
|
|
||||||
get { return _operationCount; }
|
|
||||||
set { _operationCount = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[DataMember]
|
|
||||||
public long Errors
|
|
||||||
{
|
|
||||||
get { return _errorCount; }
|
|
||||||
set { _errorCount = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[DataMember]
|
|
||||||
public DeviceType Type
|
|
||||||
{
|
|
||||||
get { return _deviceType; }
|
|
||||||
set { _deviceType = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[DataMember]
|
|
||||||
public int RefreshFrequency
|
|
||||||
{
|
|
||||||
get { return _refreshFrequency; }
|
|
||||||
set { _refreshFrequency = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[DataMember]
|
|
||||||
public Dictionary<WeatherValueType, Value> Values
|
|
||||||
{
|
|
||||||
get { return _valueList; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DataMember]
|
[DataMember]
|
||||||
public List<WeatherValueType> SupportedValues
|
public List<WeatherValueType> SupportedValues
|
||||||
{
|
{
|
||||||
get { return _valueList.Keys.ToList(); }
|
get { return Values.Keys.ToList(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Public methods
|
|
||||||
|
|
||||||
public Value GetValue(WeatherValueType valueType)
|
public Value GetValue(WeatherValueType valueType)
|
||||||
{
|
{
|
||||||
return _valueList[valueType];
|
return Values[valueType];
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
using OneWireAPI;
|
using OneWireAPI;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
using WeatherService.Values;
|
using WeatherService.Values;
|
||||||
|
|
||||||
namespace WeatherService.Devices
|
namespace WeatherService.Devices
|
||||||
@@ -7,28 +7,19 @@ namespace WeatherService.Devices
|
|||||||
[DataContract]
|
[DataContract]
|
||||||
public class HumidityDevice : DeviceBase
|
public class HumidityDevice : DeviceBase
|
||||||
{
|
{
|
||||||
#region Member variables
|
|
||||||
|
|
||||||
private readonly Value _temperatureValue;
|
private readonly Value _temperatureValue;
|
||||||
private readonly Value _humidityValue;
|
private readonly Value _humidityValue;
|
||||||
|
|
||||||
#endregion
|
public HumidityDevice(Session session, Device device)
|
||||||
|
: base(session, device, DeviceType.Humidity)
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
public HumidityDevice(Session session, owDevice device) : base(session, device, DeviceType.Humidity)
|
|
||||||
{
|
{
|
||||||
_temperatureValue = new Value(WeatherValueType.Temperature, this);
|
_temperatureValue = new Value(WeatherValueType.Temperature, this);
|
||||||
_humidityValue = new Value(WeatherValueType.Humidity, this);
|
_humidityValue = new Value(WeatherValueType.Humidity, this);
|
||||||
|
|
||||||
_valueList.Add(WeatherValueType.Temperature, _temperatureValue);
|
Values.Add(WeatherValueType.Temperature, _temperatureValue);
|
||||||
_valueList.Add(WeatherValueType.Humidity, _humidityValue);
|
Values.Add(WeatherValueType.Humidity, _humidityValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Internal methods
|
|
||||||
|
|
||||||
internal override void RefreshCache()
|
internal override void RefreshCache()
|
||||||
{
|
{
|
||||||
_temperatureValue.SetValue(ReadTemperature());
|
_temperatureValue.SetValue(ReadTemperature());
|
||||||
@@ -40,33 +31,31 @@ namespace WeatherService.Devices
|
|||||||
internal double ReadTemperature()
|
internal double ReadTemperature()
|
||||||
{
|
{
|
||||||
// Cast the device to its specific type
|
// Cast the device to its specific type
|
||||||
owDeviceFamily26 oDevice = (owDeviceFamily26) _device;
|
var device = (DeviceFamily26) OneWireDevice;
|
||||||
|
|
||||||
// Return the temperature from the device
|
// Return the temperature from the device
|
||||||
return oDevice.GetTemperature();
|
return device.GetTemperature();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal double ReadHumidity()
|
internal double ReadHumidity()
|
||||||
{
|
{
|
||||||
// Cast the device to its specific type
|
// Cast the device to its specific type
|
||||||
owDeviceFamily26 oDevice = (owDeviceFamily26) _device;
|
var device = (DeviceFamily26) OneWireDevice;
|
||||||
|
|
||||||
// Get the supply voltage
|
// Get the supply voltage
|
||||||
double dSupplyVoltage = oDevice.GetSupplyVoltage();
|
var supplyVoltage = device.GetSupplyVoltage();
|
||||||
|
|
||||||
// Get the output voltage
|
// Get the output voltage
|
||||||
double dOutputVoltage = oDevice.GetOutputVoltage();
|
var outputVoltage = device.GetOutputVoltage();
|
||||||
|
|
||||||
// Get the temperature
|
// Get the temperature
|
||||||
double dTemperature = oDevice.GetTemperature();
|
var temperature = device.GetTemperature();
|
||||||
|
|
||||||
// Calculate the humidity
|
// Calculate the humidity
|
||||||
double dHumidity = (((dOutputVoltage / dSupplyVoltage) - 0.16F) / 0.0062F) / (1.0546F - 0.00216F * dTemperature);
|
var humidity = (((outputVoltage / supplyVoltage) - 0.16F) / 0.0062F) / (1.0546F - 0.00216F * temperature);
|
||||||
|
|
||||||
// Return the result
|
// Return the result
|
||||||
return dHumidity;
|
return humidity;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
|
using OneWireAPI;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using OneWireAPI;
|
|
||||||
using WeatherService.Values;
|
using WeatherService.Values;
|
||||||
|
|
||||||
namespace WeatherService.Devices
|
namespace WeatherService.Devices
|
||||||
@@ -9,27 +9,21 @@ namespace WeatherService.Devices
|
|||||||
[DataContract]
|
[DataContract]
|
||||||
public class PressureDevice : DeviceBase
|
public class PressureDevice : DeviceBase
|
||||||
{
|
{
|
||||||
#region Constants
|
private readonly byte[] _resetSequence = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0 }; // Binary sequence to reset the device
|
||||||
|
private readonly byte[] _readWord1Sequence = { 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0 }; // Binary sequence to read word 1
|
||||||
private readonly byte[] _resetSequence = new byte[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0 }; // Binary sequence to reset the device
|
private readonly byte[] _readWord2Sequence = { 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0 }; // Binary sequence to read word 2
|
||||||
private readonly byte[] _readWord1Sequence = new byte[] { 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0 }; // Binary sequence to read word 1
|
private readonly byte[] _readWord3Sequence = { 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0 }; // Binary sequence to read word 3
|
||||||
private readonly byte[] _readWord2Sequence = new byte[] { 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0 }; // Binary sequence to read word 2
|
private readonly byte[] _readWord4Sequence = { 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0 }; // Binary sequence to read word 4
|
||||||
private readonly byte[] _readWord3Sequence = new byte[] { 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0 }; // Binary sequence to read word 3
|
private readonly byte[] _readPressureSequence = { 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0 }; // Binary sequence to read pressure
|
||||||
private readonly byte[] _readWord4Sequence = new byte[] { 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0 }; // Binary sequence to read word 4
|
private readonly byte[] _readTemperatureSequence = { 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0 }; // Binary sequence to read temperature
|
||||||
private readonly byte[] _readPressureSequence = new byte[] { 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0 }; // Binary sequence to read pressure
|
|
||||||
private readonly byte[] _readTemperatureSequence = new byte[] { 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0 }; // Binary sequence to read temperature
|
|
||||||
|
|
||||||
private const byte ChannelAccessCommand = 0xF5;
|
private const byte ChannelAccessCommand = 0xF5;
|
||||||
private const byte ConfigRead = 0xEC;
|
private const byte ConfigRead = 0xEC;
|
||||||
private const byte ConfigWrite = 0x8C;
|
private const byte ConfigWrite = 0x8C;
|
||||||
private const byte ConfigPulseRead = 0xC8;
|
private const byte ConfigPulseRead = 0xC8;
|
||||||
|
|
||||||
#endregion
|
private readonly DeviceFamily12 _writeDevice; // Device for writing to the pressure sensor
|
||||||
|
private readonly DeviceFamily12 _readDevice; // Device for reading from the pressure sensor
|
||||||
#region Member variables
|
|
||||||
|
|
||||||
private readonly owDeviceFamily12 _writeDevice; // Device for writing to the pressure sensor
|
|
||||||
private readonly owDeviceFamily12 _readDevice; // Device for reading from the pressure sensor
|
|
||||||
private readonly Value _temperatureValue; // Last temperature (degrees C)
|
private readonly Value _temperatureValue; // Last temperature (degrees C)
|
||||||
private readonly Value _pressureValue; // Last pressure (mbar)
|
private readonly Value _pressureValue; // Last pressure (mbar)
|
||||||
|
|
||||||
@@ -42,93 +36,86 @@ namespace WeatherService.Devices
|
|||||||
private int _calibration5; // Calibration constant
|
private int _calibration5; // Calibration constant
|
||||||
private int _calibration6; // Calibration constant
|
private int _calibration6; // Calibration constant
|
||||||
|
|
||||||
#endregion
|
public PressureDevice(Session session, Device firstDevice, Device secondDevice)
|
||||||
|
: base(session, firstDevice, DeviceType.Pressure)
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
public PressureDevice(Session session, owDevice firstDevice, owDevice secondDevice) : base(session, firstDevice, DeviceType.Pressure)
|
|
||||||
{
|
{
|
||||||
// Get both devices
|
// Get both devices
|
||||||
owDeviceFamily12 oDevice1 = (owDeviceFamily12) firstDevice;
|
var device1 = (DeviceFamily12) firstDevice;
|
||||||
owDeviceFamily12 oDevice2 = (owDeviceFamily12) secondDevice;
|
var device2 = (DeviceFamily12) secondDevice;
|
||||||
|
|
||||||
// Get the state of both devices
|
// Get the state of both devices
|
||||||
byte[] baState1 = oDevice1.ReadDevice();
|
var state1 = device1.ReadDevice();
|
||||||
byte[] baState2 = oDevice2.ReadDevice();
|
var state2 = device2.ReadDevice();
|
||||||
|
|
||||||
// If both devices have the same power state then this isn't a proper pressure device
|
// If both devices have the same power state then this isn't a proper pressure device
|
||||||
if (oDevice1.IsPowered(baState1) == oDevice2.IsPowered(baState2))
|
if (device1.IsPowered(state1) == device2.IsPowered(state2))
|
||||||
{
|
{
|
||||||
// Throw an exception
|
// Throw an exception
|
||||||
throw new Exception("Invalid TAI8570");
|
throw new Exception("Invalid TAI8570");
|
||||||
}
|
}
|
||||||
|
|
||||||
// The powered device is the write device - sort this out and remember which is which
|
// The powered device is the write device - sort this out and remember which is which
|
||||||
if (oDevice1.IsPowered(baState1))
|
if (device1.IsPowered(state1))
|
||||||
{
|
{
|
||||||
_writeDevice = oDevice1;
|
_writeDevice = device1;
|
||||||
_readDevice = oDevice2;
|
_readDevice = device2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_writeDevice = oDevice2;
|
_writeDevice = device2;
|
||||||
_readDevice = oDevice1;
|
_readDevice = device1;
|
||||||
}
|
}
|
||||||
|
|
||||||
_temperatureValue = new Value(WeatherValueType.Temperature, this);
|
_temperatureValue = new Value(WeatherValueType.Temperature, this);
|
||||||
_pressureValue = new Value(WeatherValueType.Pressure, this);
|
_pressureValue = new Value(WeatherValueType.Pressure, this);
|
||||||
|
|
||||||
_valueList.Add(WeatherValueType.Temperature, _temperatureValue);
|
Values.Add(WeatherValueType.Temperature, _temperatureValue);
|
||||||
_valueList.Add(WeatherValueType.Pressure, _pressureValue);
|
Values.Add(WeatherValueType.Pressure, _pressureValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region PIO methods
|
|
||||||
|
|
||||||
private void PrepPioForWrite()
|
private void PrepPioForWrite()
|
||||||
{
|
{
|
||||||
byte[] baState = _writeDevice.ReadDevice();
|
var state = _writeDevice.ReadDevice();
|
||||||
_writeDevice.SetLatchState(0, true, baState);
|
_writeDevice.SetLatchState(0, true, state);
|
||||||
_writeDevice.SetLatchState(1, false, baState);
|
_writeDevice.SetLatchState(1, false, state);
|
||||||
_writeDevice.WriteDevice(baState);
|
_writeDevice.WriteDevice(state);
|
||||||
|
|
||||||
baState = _readDevice.ReadDevice();
|
state = _readDevice.ReadDevice();
|
||||||
_readDevice.SetLatchState(0, false, baState);
|
_readDevice.SetLatchState(0, false, state);
|
||||||
_readDevice.SetLatchState(1, false, baState);
|
_readDevice.SetLatchState(1, false, state);
|
||||||
_readDevice.WriteDevice(baState);
|
_readDevice.WriteDevice(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PrepPioForRead()
|
private void PrepPioForRead()
|
||||||
{
|
{
|
||||||
byte[] baState = _readDevice.ReadDevice();
|
var state = _readDevice.ReadDevice();
|
||||||
_readDevice.SetLatchState(0, false, baState);
|
_readDevice.SetLatchState(0, false, state);
|
||||||
_readDevice.SetLatchState(1, false, baState);
|
_readDevice.SetLatchState(1, false, state);
|
||||||
_readDevice.WriteDevice(baState);
|
_readDevice.WriteDevice(state);
|
||||||
|
|
||||||
baState = _writeDevice.ReadDevice();
|
state = _writeDevice.ReadDevice();
|
||||||
_writeDevice.SetLatchState(0, false, baState);
|
_writeDevice.SetLatchState(0, false, state);
|
||||||
_writeDevice.SetLatchState(1, false, baState);
|
_writeDevice.SetLatchState(1, false, state);
|
||||||
_writeDevice.WriteDevice(baState);
|
_writeDevice.WriteDevice(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool OpenPio(int pio)
|
private bool OpenPio(int pio)
|
||||||
{
|
{
|
||||||
byte[] baWriteState = _writeDevice.ReadDevice();
|
var writeState = _writeDevice.ReadDevice();
|
||||||
byte[] baReadState = _readDevice.ReadDevice();
|
var readDevice = _readDevice.ReadDevice();
|
||||||
|
|
||||||
_writeDevice.SetLatchState(pio, false, baWriteState);
|
_writeDevice.SetLatchState(pio, false, writeState);
|
||||||
_readDevice.SetLatchState(pio, false, baReadState);
|
_readDevice.SetLatchState(pio, false, readDevice);
|
||||||
|
|
||||||
_writeDevice.WriteDevice(baWriteState);
|
_writeDevice.WriteDevice(writeState);
|
||||||
_writeDevice.WriteDevice(baReadState);
|
_writeDevice.WriteDevice(readDevice);
|
||||||
|
|
||||||
baWriteState = _writeDevice.ReadDevice();
|
writeState = _writeDevice.ReadDevice();
|
||||||
baReadState = _readDevice.ReadDevice();
|
readDevice = _readDevice.ReadDevice();
|
||||||
|
|
||||||
bool bResult = (_writeDevice.GetLevel(pio, baWriteState) && _readDevice.GetLevel(pio, baReadState));
|
var result = (_writeDevice.GetLevel(pio, writeState) && _readDevice.GetLevel(pio, readDevice));
|
||||||
|
|
||||||
return bResult;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool OpenPioA()
|
private bool OpenPioA()
|
||||||
@@ -141,98 +128,90 @@ namespace WeatherService.Devices
|
|||||||
return OpenPio(1);
|
return OpenPio(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Private methods
|
|
||||||
|
|
||||||
private bool SetupForWrite()
|
private bool SetupForWrite()
|
||||||
{
|
{
|
||||||
byte[] data = new byte[3]; // Data buffer to send over the network
|
var data = new byte[3]; // Data buffer to send over the network
|
||||||
short dataCount = 0; // How many bytes of data to send
|
short dataCount = 0; // How many bytes of data to send
|
||||||
|
|
||||||
PrepPioForWrite();
|
PrepPioForWrite();
|
||||||
|
|
||||||
owAdapter.Select(_writeDevice.Id);
|
Adapter.Select(_writeDevice.Id);
|
||||||
|
|
||||||
data[dataCount++] = ChannelAccessCommand;
|
data[dataCount++] = ChannelAccessCommand;
|
||||||
data[dataCount++] = ConfigWrite;
|
data[dataCount++] = ConfigWrite;
|
||||||
data[dataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
owAdapter.SendBlock(data, dataCount);
|
Adapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
owAdapter.ReadByte();
|
Adapter.ReadByte();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool SetupForRead()
|
private bool SetupForRead()
|
||||||
{
|
{
|
||||||
byte[] data = new byte[3]; // Data buffer to send over the network
|
var data = new byte[3]; // Data buffer to send over the network
|
||||||
short dataCount = 0; // How many bytes of data to send
|
short dataCount = 0; // How many bytes of data to send
|
||||||
|
|
||||||
PrepPioForRead();
|
PrepPioForRead();
|
||||||
|
|
||||||
owAdapter.Select(_readDevice.Id);
|
Adapter.Select(_readDevice.Id);
|
||||||
|
|
||||||
data[dataCount++] = ChannelAccessCommand;
|
data[dataCount++] = ChannelAccessCommand;
|
||||||
data[dataCount++] = ConfigRead;
|
data[dataCount++] = ConfigRead;
|
||||||
data[dataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
owAdapter.SendBlock(data, dataCount);
|
Adapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
owAdapter.ReadByte();
|
Adapter.ReadByte();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool SetupForPulseRead()
|
private bool SetupForPulseRead()
|
||||||
{
|
{
|
||||||
byte[] data = new byte[3]; // Data buffer to send over the network
|
var data = new byte[3]; // Data buffer to send over the network
|
||||||
short dataCount = 0; // How many bytes of data to send
|
short dataCount = 0; // How many bytes of data to send
|
||||||
|
|
||||||
PrepPioForWrite();
|
PrepPioForWrite();
|
||||||
|
|
||||||
owAdapter.Select(_readDevice.Id);
|
Adapter.Select(_readDevice.Id);
|
||||||
|
|
||||||
data[dataCount++] = ChannelAccessCommand;
|
data[dataCount++] = ChannelAccessCommand;
|
||||||
data[dataCount++] = ConfigPulseRead;
|
data[dataCount++] = ConfigPulseRead;
|
||||||
data[dataCount++] = 0xFF;
|
data[dataCount++] = 0xFF;
|
||||||
|
|
||||||
owAdapter.SendBlock(data, dataCount);
|
Adapter.SendBlock(data, dataCount);
|
||||||
|
|
||||||
owAdapter.ReadByte();
|
Adapter.ReadByte();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool WriteBitSequence(IEnumerable<byte> sequence)
|
private bool WriteBitSequence(IEnumerable<byte> sequence)
|
||||||
{
|
{
|
||||||
bool result = false;
|
if (!SetupForWrite())
|
||||||
|
return false;
|
||||||
|
|
||||||
if (SetupForWrite())
|
foreach (var t in sequence)
|
||||||
{
|
{
|
||||||
foreach (byte t in sequence)
|
SendBit(t != 0);
|
||||||
{
|
|
||||||
SendBit(t != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
SendBit(false);
|
|
||||||
|
|
||||||
result = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
SendBit(false);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] ReadBitSequence(IEnumerable<byte> sequence)
|
private byte[] ReadBitSequence(IEnumerable<byte> sequence)
|
||||||
{
|
{
|
||||||
byte[] result = new byte[16];
|
var result = new byte[16];
|
||||||
|
|
||||||
if (WriteBitSequence(sequence))
|
if (!WriteBitSequence(sequence))
|
||||||
{
|
return result;
|
||||||
result = GetBits(16);
|
|
||||||
OpenPioB();
|
result = GetBits(16);
|
||||||
}
|
OpenPioB();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -241,45 +220,45 @@ namespace WeatherService.Devices
|
|||||||
{
|
{
|
||||||
if (value)
|
if (value)
|
||||||
{
|
{
|
||||||
owAdapter.SendBit(0);
|
Adapter.SendBit(0);
|
||||||
owAdapter.SendBit(1);
|
Adapter.SendBit(1);
|
||||||
owAdapter.SendBit(1);
|
Adapter.SendBit(1);
|
||||||
owAdapter.SendBit(1);
|
Adapter.SendBit(1);
|
||||||
owAdapter.SendBit(0);
|
Adapter.SendBit(0);
|
||||||
owAdapter.SendBit(0);
|
Adapter.SendBit(0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
owAdapter.SendBit(0);
|
Adapter.SendBit(0);
|
||||||
owAdapter.SendBit(0);
|
Adapter.SendBit(0);
|
||||||
owAdapter.SendBit(1);
|
Adapter.SendBit(1);
|
||||||
owAdapter.SendBit(0);
|
Adapter.SendBit(0);
|
||||||
owAdapter.SendBit(0);
|
Adapter.SendBit(0);
|
||||||
owAdapter.SendBit(0);
|
Adapter.SendBit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool ReadBit()
|
private static bool ReadBit()
|
||||||
{
|
{
|
||||||
owAdapter.ReadBit(); // Read PIO A #1
|
Adapter.ReadBit(); // Read PIO A #1
|
||||||
owAdapter.ReadBit(); // Read PIO B #1
|
Adapter.ReadBit(); // Read PIO B #1
|
||||||
owAdapter.ReadBit(); // Read PIO A #2
|
Adapter.ReadBit(); // Read PIO A #2
|
||||||
owAdapter.ReadBit(); // Read PIO B #2
|
Adapter.ReadBit(); // Read PIO B #2
|
||||||
owAdapter.ReadBit(); // Read PIO A #3
|
Adapter.ReadBit(); // Read PIO A #3
|
||||||
owAdapter.ReadBit(); // Read PIO B #3
|
Adapter.ReadBit(); // Read PIO B #3
|
||||||
owAdapter.ReadBit(); // Read PIO A #4
|
Adapter.ReadBit(); // Read PIO A #4
|
||||||
short data = owAdapter.ReadBit();
|
var data = Adapter.ReadBit();
|
||||||
|
|
||||||
bool result = (data == 1);
|
var result = (data == 1);
|
||||||
|
|
||||||
owAdapter.SendBit(0); // Write PIO A #1
|
Adapter.SendBit(0); // Write PIO A #1
|
||||||
owAdapter.SendBit(1); // Write PIO B #1
|
Adapter.SendBit(1); // Write PIO B #1
|
||||||
owAdapter.SendBit(0); // Write PIO A #2
|
Adapter.SendBit(0); // Write PIO A #2
|
||||||
owAdapter.SendBit(1); // Write PIO B #2
|
Adapter.SendBit(1); // Write PIO B #2
|
||||||
owAdapter.SendBit(1); // Write PIO A #3
|
Adapter.SendBit(1); // Write PIO A #3
|
||||||
owAdapter.SendBit(1); // Write PIO B #3
|
Adapter.SendBit(1); // Write PIO B #3
|
||||||
owAdapter.SendBit(1); // Write PIO A #4
|
Adapter.SendBit(1); // Write PIO A #4
|
||||||
owAdapter.SendBit(1); // Write PIO B #4
|
Adapter.SendBit(1); // Write PIO B #4
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -291,16 +270,16 @@ namespace WeatherService.Devices
|
|||||||
|
|
||||||
private bool CheckConversionStatus()
|
private bool CheckConversionStatus()
|
||||||
{
|
{
|
||||||
int i;
|
int index;
|
||||||
|
|
||||||
if (!SetupForPulseRead())
|
if (!SetupForPulseRead())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (i = 0; i < 100; i++)
|
for (index = 0; index < 100; index++)
|
||||||
if (owAdapter.SendBit(0) == 0)
|
if (Adapter.SendBit(0) == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
return (i < 100);
|
return (index < 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ReadCalibrationConstants()
|
private bool ReadCalibrationConstants()
|
||||||
@@ -309,13 +288,13 @@ namespace WeatherService.Devices
|
|||||||
|
|
||||||
if (!Reset()) return false;
|
if (!Reset()) return false;
|
||||||
|
|
||||||
byte[] word1 = ReadBitSequence(_readWord1Sequence);
|
var word1 = ReadBitSequence(_readWord1Sequence);
|
||||||
|
|
||||||
byte[] word2 = ReadBitSequence(_readWord2Sequence);
|
var word2 = ReadBitSequence(_readWord2Sequence);
|
||||||
|
|
||||||
byte[] word3 = ReadBitSequence(_readWord3Sequence);
|
var word3 = ReadBitSequence(_readWord3Sequence);
|
||||||
|
|
||||||
byte[] word4 = ReadBitSequence(_readWord4Sequence);
|
var word4 = ReadBitSequence(_readWord4Sequence);
|
||||||
|
|
||||||
_calibration1 = _calibration2 = _calibration3 = _calibration4 = _calibration5 = _calibration6 = 0;
|
_calibration1 = _calibration2 = _calibration3 = _calibration4 = _calibration5 = _calibration6 = 0;
|
||||||
|
|
||||||
@@ -383,17 +362,17 @@ namespace WeatherService.Devices
|
|||||||
|
|
||||||
private byte[] GetBits(byte bitCount)
|
private byte[] GetBits(byte bitCount)
|
||||||
{
|
{
|
||||||
byte[] result = new byte[bitCount];
|
var result = new byte[bitCount];
|
||||||
|
|
||||||
if (SetupForRead())
|
if (!SetupForRead())
|
||||||
|
return result;
|
||||||
|
|
||||||
|
for (var index = 0; index < bitCount; index++)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < bitCount; i++)
|
if (ReadBit())
|
||||||
{
|
result[index] = 1;
|
||||||
if (ReadBit())
|
else
|
||||||
result[i] = 1;
|
result[index] = 0;
|
||||||
else
|
|
||||||
result[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -401,7 +380,7 @@ namespace WeatherService.Devices
|
|||||||
|
|
||||||
private int ReadValue(IEnumerable<byte> sequence)
|
private int ReadValue(IEnumerable<byte> sequence)
|
||||||
{
|
{
|
||||||
int result = 0;
|
var result = 0;
|
||||||
|
|
||||||
if (!Reset())
|
if (!Reset())
|
||||||
return 0;
|
return 0;
|
||||||
@@ -415,16 +394,16 @@ namespace WeatherService.Devices
|
|||||||
if (!OpenPioA())
|
if (!OpenPioA())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
byte[] data = GetBits(16);
|
var data = GetBits(16);
|
||||||
|
|
||||||
if (!OpenPioB())
|
if (!OpenPioB())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (int i = 0; i < 16; i++)
|
for (var index = 0; index < 16; index++)
|
||||||
{
|
{
|
||||||
result = (result << 1);
|
result = (result << 1);
|
||||||
|
|
||||||
if (data[i] == 1)
|
if (data[index] == 1)
|
||||||
result = result + 1;
|
result = result + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,16 +412,16 @@ namespace WeatherService.Devices
|
|||||||
|
|
||||||
private bool ReadSensorData()
|
private bool ReadSensorData()
|
||||||
{
|
{
|
||||||
int pressure = ReadValue(_readPressureSequence);
|
var pressure = ReadValue(_readPressureSequence);
|
||||||
int temperature = ReadValue(_readTemperatureSequence);
|
var temperature = ReadValue(_readTemperatureSequence);
|
||||||
|
|
||||||
double calibrationTemperature = (8 * _calibration5) + 20224;
|
double calibrationTemperature = (8 * _calibration5) + 20224;
|
||||||
double temperatureDifference = temperature - calibrationTemperature;
|
var temperatureDifference = temperature - calibrationTemperature;
|
||||||
_temperatureValue.SetValue(20 + ((temperatureDifference * (_calibration6 + 50)) / 10240));
|
_temperatureValue.SetValue(20 + ((temperatureDifference * (_calibration6 + 50)) / 10240));
|
||||||
|
|
||||||
double offset = _calibration2 * 4 + (((_calibration4 - 512) * temperatureDifference) / 4096);
|
var offset = _calibration2 * 4 + (((_calibration4 - 512) * temperatureDifference) / 4096);
|
||||||
double sensitivity = _calibration1 + ((_calibration3 * temperatureDifference) / 1024) + 24576;
|
var sensitivity = _calibration1 + ((_calibration3 * temperatureDifference) / 1024) + 24576;
|
||||||
double actualPressure = ((sensitivity * (pressure - 7168)) / 16384) - offset;
|
var actualPressure = ((sensitivity * (pressure - 7168)) / 16384) - offset;
|
||||||
|
|
||||||
_pressureValue.SetValue((actualPressure / 32) + 250);
|
_pressureValue.SetValue((actualPressure / 32) + 250);
|
||||||
|
|
||||||
@@ -463,10 +442,6 @@ namespace WeatherService.Devices
|
|||||||
throw new Exception("Error reading Pressure and Temperature values");
|
throw new Exception("Error reading Pressure and Temperature values");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Internal methods
|
|
||||||
|
|
||||||
internal override void RefreshCache()
|
internal override void RefreshCache()
|
||||||
{
|
{
|
||||||
ReadDevice();
|
ReadDevice();
|
||||||
@@ -474,8 +449,6 @@ namespace WeatherService.Devices
|
|||||||
base.RefreshCache();
|
base.RefreshCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Elevation code (not used yet)
|
#region Elevation code (not used yet)
|
||||||
|
|
||||||
//private double m_dElevation = 0.0; // Height above sea level (meters)
|
//private double m_dElevation = 0.0; // Height above sea level (meters)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
using OneWireAPI;
|
using OneWireAPI;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
using WeatherService.Values;
|
using WeatherService.Values;
|
||||||
|
|
||||||
namespace WeatherService.Devices
|
namespace WeatherService.Devices
|
||||||
@@ -7,8 +7,6 @@ namespace WeatherService.Devices
|
|||||||
[DataContract]
|
[DataContract]
|
||||||
public class RainDevice : DeviceBase
|
public class RainDevice : DeviceBase
|
||||||
{
|
{
|
||||||
#region Member variables
|
|
||||||
|
|
||||||
private readonly Value _recentValue;
|
private readonly Value _recentValue;
|
||||||
|
|
||||||
private readonly uint _clearedCount; // Counter at least clear
|
private readonly uint _clearedCount; // Counter at least clear
|
||||||
@@ -17,34 +15,26 @@ namespace WeatherService.Devices
|
|||||||
private uint _startupCount; // Counter at startup
|
private uint _startupCount; // Counter at startup
|
||||||
private bool _initialized;
|
private bool _initialized;
|
||||||
|
|
||||||
#endregion
|
public RainDevice(Session session, Device device)
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
public RainDevice(Session session, owDevice device)
|
|
||||||
: base(session, device, DeviceType.Rain)
|
: base(session, device, DeviceType.Rain)
|
||||||
{
|
{
|
||||||
// TODO - Read the count as of the last counter clearing
|
// TODO - Read the count as of the last counter clearing
|
||||||
_clearedCount = 150;
|
_clearedCount = 150;
|
||||||
|
|
||||||
// Get a reference to the device
|
// Get a reference to the device
|
||||||
owDeviceFamily1D counter = (owDeviceFamily1D) _device;
|
var counter = (DeviceFamily1D) OneWireDevice;
|
||||||
|
|
||||||
// Get the current counter
|
// Get the current counter
|
||||||
_lastCount = counter.GetCounter(15);
|
_lastCount = counter.GetCounter(15);
|
||||||
|
|
||||||
// Setup the rain value
|
// Setup the rain value
|
||||||
_recentValue = new Value(WeatherValueType.Rain, this);
|
_recentValue = new Value(WeatherValueType.Rain, this);
|
||||||
_valueList.Add(WeatherValueType.Rain, _recentValue);
|
Values.Add(WeatherValueType.Rain, _recentValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Internal methods
|
|
||||||
|
|
||||||
internal override void RefreshCache()
|
internal override void RefreshCache()
|
||||||
{
|
{
|
||||||
double recentRain = ReadRecentRainfall();
|
var recentRain = ReadRecentRainfall();
|
||||||
|
|
||||||
_recentValue.SetValue(recentRain);
|
_recentValue.SetValue(recentRain);
|
||||||
|
|
||||||
@@ -54,7 +44,7 @@ namespace WeatherService.Devices
|
|||||||
internal double ReadSessionRainfall()
|
internal double ReadSessionRainfall()
|
||||||
{
|
{
|
||||||
// Get a reference to the device
|
// Get a reference to the device
|
||||||
owDeviceFamily1D counter = (owDeviceFamily1D) _device;
|
var counter = (DeviceFamily1D) OneWireDevice;
|
||||||
|
|
||||||
// If we haven't initialized then do it now
|
// If we haven't initialized then do it now
|
||||||
if (!_initialized)
|
if (!_initialized)
|
||||||
@@ -66,7 +56,7 @@ namespace WeatherService.Devices
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the current counter
|
// Get the current counter
|
||||||
uint currentCount = counter.GetCounter(15);
|
var currentCount = counter.GetCounter(15);
|
||||||
|
|
||||||
// Get the amount of rain since the last check
|
// Get the amount of rain since the last check
|
||||||
return (currentCount - _startupCount) * 0.2;
|
return (currentCount - _startupCount) * 0.2;
|
||||||
@@ -75,13 +65,13 @@ namespace WeatherService.Devices
|
|||||||
internal double ReadRecentRainfall()
|
internal double ReadRecentRainfall()
|
||||||
{
|
{
|
||||||
// Get a reference to the device
|
// Get a reference to the device
|
||||||
owDeviceFamily1D counter = (owDeviceFamily1D) _device;
|
var counter = (DeviceFamily1D) OneWireDevice;
|
||||||
|
|
||||||
// Get the current counter
|
// Get the current counter
|
||||||
uint currentCount = counter.GetCounter(15);
|
var currentCount = counter.GetCounter(15);
|
||||||
|
|
||||||
// Get the amount of rain since the last check
|
// Get the amount of rain since the last check
|
||||||
double rainValue = (currentCount - _lastCount) * 0.2;
|
var rainValue = (currentCount - _lastCount) * 0.2;
|
||||||
|
|
||||||
// Store the last counter
|
// Store the last counter
|
||||||
_lastCount = currentCount;
|
_lastCount = currentCount;
|
||||||
@@ -92,10 +82,10 @@ namespace WeatherService.Devices
|
|||||||
internal double ReadTotalRainfall()
|
internal double ReadTotalRainfall()
|
||||||
{
|
{
|
||||||
// Get a reference to the device
|
// Get a reference to the device
|
||||||
owDeviceFamily1D counter = (owDeviceFamily1D) _device;
|
var counter = (DeviceFamily1D) OneWireDevice;
|
||||||
|
|
||||||
// Get the current counter
|
// Get the current counter
|
||||||
uint currentCount = counter.GetCounter(15);
|
var currentCount = counter.GetCounter(15);
|
||||||
|
|
||||||
// Get the amount of rain since the last check
|
// Get the amount of rain since the last check
|
||||||
double rainValue = (currentCount - _clearedCount) * 0.2F;
|
double rainValue = (currentCount - _clearedCount) * 0.2F;
|
||||||
@@ -105,7 +95,5 @@ namespace WeatherService.Devices
|
|||||||
|
|
||||||
return rainValue;
|
return rainValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
using OneWireAPI;
|
using OneWireAPI;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
using WeatherService.Values;
|
using WeatherService.Values;
|
||||||
|
|
||||||
namespace WeatherService.Devices
|
namespace WeatherService.Devices
|
||||||
@@ -7,26 +7,17 @@ namespace WeatherService.Devices
|
|||||||
[DataContract]
|
[DataContract]
|
||||||
public class TemperatureDevice : DeviceBase
|
public class TemperatureDevice : DeviceBase
|
||||||
{
|
{
|
||||||
#region Member variables
|
private readonly Value _temperatureValue;
|
||||||
|
|
||||||
private readonly Value _temperatureValue; // Cached temperature
|
public TemperatureDevice(Session session, Device device)
|
||||||
|
: base(session, device, DeviceType.Temperature)
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
public TemperatureDevice(Session session, owDevice device) : base(session, device, DeviceType.Temperature)
|
|
||||||
{
|
{
|
||||||
// Create the new value object
|
// Create the new value object
|
||||||
_temperatureValue = new Value(WeatherValueType.Temperature, this);
|
_temperatureValue = new Value(WeatherValueType.Temperature, this);
|
||||||
|
|
||||||
_valueList.Add(WeatherValueType.Temperature, _temperatureValue);
|
Values.Add(WeatherValueType.Temperature, _temperatureValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Internal methods
|
|
||||||
|
|
||||||
internal override void RefreshCache()
|
internal override void RefreshCache()
|
||||||
{
|
{
|
||||||
// Read the current temperature
|
// Read the current temperature
|
||||||
@@ -38,12 +29,10 @@ namespace WeatherService.Devices
|
|||||||
internal double ReadTemperature()
|
internal double ReadTemperature()
|
||||||
{
|
{
|
||||||
// Cast the device to its specific type
|
// Cast the device to its specific type
|
||||||
owDeviceFamily10 temperatureDevice = (owDeviceFamily10) _device;
|
var temperatureDevice = (DeviceFamily10) OneWireDevice;
|
||||||
|
|
||||||
// Return the temperature from the device
|
// Return the temperature from the device
|
||||||
return temperatureDevice.GetTemperature();
|
return temperatureDevice.GetTemperature();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,9 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
using OneWireAPI;
|
using OneWireAPI;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
using WeatherService.Values;
|
using WeatherService.Values;
|
||||||
|
|
||||||
namespace WeatherService.Devices
|
namespace WeatherService.Devices
|
||||||
{
|
{
|
||||||
#region Enumerations
|
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public enum WindDirection
|
public enum WindDirection
|
||||||
{
|
{
|
||||||
@@ -61,13 +59,9 @@ namespace WeatherService.Devices
|
|||||||
Unknown = -1
|
Unknown = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
[DataContract]
|
[DataContract]
|
||||||
public class WindDirectionDevice : DeviceBase
|
public class WindDirectionDevice : DeviceBase
|
||||||
{
|
{
|
||||||
#region Constants
|
|
||||||
|
|
||||||
private const double WindowOffset = 0.7;
|
private const double WindowOffset = 0.7;
|
||||||
|
|
||||||
private readonly double[,] _lookupTable = { {4.66, 4.66, 2.38, 4.66}, // 0
|
private readonly double[,] _lookupTable = { {4.66, 4.66, 2.38, 4.66}, // 0
|
||||||
@@ -87,44 +81,32 @@ namespace WeatherService.Devices
|
|||||||
{4.66, 4.66, 4.66, 2.38}, // 14
|
{4.66, 4.66, 4.66, 2.38}, // 14
|
||||||
{4.66, 4.66, 3.18, 3.18} }; // 15
|
{4.66, 4.66, 3.18, 3.18} }; // 15
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Member variables
|
|
||||||
|
|
||||||
private readonly Value _directionValue; // Cached direction value
|
private readonly Value _directionValue; // Cached direction value
|
||||||
|
|
||||||
private bool _initialized; // Has the device been initialized
|
private bool _initialized; // Has the device been initialized
|
||||||
|
|
||||||
#endregion
|
public WindDirectionDevice(Session session, Device device)
|
||||||
|
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
public WindDirectionDevice(Session session, owDevice device)
|
|
||||||
: base(session, device, DeviceType.WindDirection)
|
: base(session, device, DeviceType.WindDirection)
|
||||||
{
|
{
|
||||||
// Create the value
|
// Create the value
|
||||||
_directionValue = new Value(WeatherValueType.WindDirection, this);
|
_directionValue = new Value(WeatherValueType.WindDirection, this);
|
||||||
|
|
||||||
_valueList.Add(WeatherValueType.WindDirection, _directionValue);
|
Values.Add(WeatherValueType.WindDirection, _directionValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Internal methods
|
|
||||||
|
|
||||||
internal override void RefreshCache()
|
internal override void RefreshCache()
|
||||||
{
|
{
|
||||||
_directionValue.SetValue((double)ReadDirection());
|
_directionValue.SetValue((double) ReadDirection());
|
||||||
|
|
||||||
base.RefreshCache();
|
base.RefreshCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal WindDirection ReadDirection()
|
internal WindDirection ReadDirection()
|
||||||
{
|
{
|
||||||
int direction = -1; // Decoded direction
|
var direction = -1; // Decoded direction
|
||||||
|
|
||||||
// Cast the device as the specific device
|
// Cast the device as the specific device
|
||||||
owDeviceFamily20 voltage = (owDeviceFamily20)_device;
|
var voltage = (DeviceFamily20) OneWireDevice;
|
||||||
|
|
||||||
// If we haven't initialized the device we need to do it now
|
// If we haven't initialized the device we need to do it now
|
||||||
if (!_initialized)
|
if (!_initialized)
|
||||||
@@ -137,10 +119,10 @@ namespace WeatherService.Devices
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the array of voltages from the device
|
// Get the array of voltages from the device
|
||||||
double[] voltages = voltage.GetVoltages();
|
var voltages = voltage.GetVoltages();
|
||||||
|
|
||||||
// Loop over the lookup table to find the direction that maps to the voltages
|
// Loop over the lookup table to find the direction that maps to the voltages
|
||||||
for (int i = 0; i < 16; i++)
|
for (var i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
if (((voltages[0] <= _lookupTable[i, 0] + WindowOffset) && (voltages[0] >= _lookupTable[i, 0] - WindowOffset)) &&
|
if (((voltages[0] <= _lookupTable[i, 0] + WindowOffset) && (voltages[0] >= _lookupTable[i, 0] - WindowOffset)) &&
|
||||||
((voltages[1] <= _lookupTable[i, 1] + WindowOffset) && (voltages[1] >= _lookupTable[i, 1] - WindowOffset)) &&
|
((voltages[1] <= _lookupTable[i, 1] + WindowOffset) && (voltages[1] >= _lookupTable[i, 1] - WindowOffset)) &&
|
||||||
@@ -153,9 +135,7 @@ namespace WeatherService.Devices
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return the direction
|
// Return the direction
|
||||||
return (WindDirection)direction;
|
return (WindDirection) direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
using OneWireAPI;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using OneWireAPI;
|
|
||||||
using WeatherService.Values;
|
using WeatherService.Values;
|
||||||
|
|
||||||
namespace WeatherService.Devices
|
namespace WeatherService.Devices
|
||||||
@@ -8,28 +8,19 @@ namespace WeatherService.Devices
|
|||||||
[DataContract]
|
[DataContract]
|
||||||
public class WindSpeedDevice : DeviceBase
|
public class WindSpeedDevice : DeviceBase
|
||||||
{
|
{
|
||||||
#region Member variables
|
|
||||||
|
|
||||||
private readonly Value _speedValue; // Cached speed value
|
private readonly Value _speedValue; // Cached speed value
|
||||||
|
|
||||||
private long _lastTicks; // Last time we checked the counter
|
private long _lastTicks; // Last time we checked the counter
|
||||||
private uint _lastCount; // The count at the last check
|
private uint _lastCount; // The count at the last check
|
||||||
|
|
||||||
#endregion
|
public WindSpeedDevice(Session session, Device device)
|
||||||
|
: base(session, device, DeviceType.WindSpeed)
|
||||||
#region Constructor
|
|
||||||
|
|
||||||
public WindSpeedDevice(Session session, owDevice device) : base(session, device, DeviceType.WindSpeed)
|
|
||||||
{
|
{
|
||||||
_speedValue = new Value(WeatherValueType.WindSpeed, this);
|
_speedValue = new Value(WeatherValueType.WindSpeed, this);
|
||||||
|
|
||||||
_valueList.Add(WeatherValueType.WindSpeed, _speedValue);
|
Values.Add(WeatherValueType.WindSpeed, _speedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Internal methods
|
|
||||||
|
|
||||||
internal override void RefreshCache()
|
internal override void RefreshCache()
|
||||||
{
|
{
|
||||||
_speedValue.SetValue(ReadSpeed());
|
_speedValue.SetValue(ReadSpeed());
|
||||||
@@ -40,7 +31,7 @@ namespace WeatherService.Devices
|
|||||||
internal double ReadSpeed()
|
internal double ReadSpeed()
|
||||||
{
|
{
|
||||||
// Get a reference to the device
|
// Get a reference to the device
|
||||||
owDeviceFamily1D counterDevice = (owDeviceFamily1D) _device;
|
var counterDevice = (DeviceFamily1D) OneWireDevice;
|
||||||
|
|
||||||
// Special case if we have never read before
|
// Special case if we have never read before
|
||||||
if (_lastTicks == 0)
|
if (_lastTicks == 0)
|
||||||
@@ -54,14 +45,14 @@ namespace WeatherService.Devices
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the current counter and time
|
// Get the current counter and time
|
||||||
uint currentCount = counterDevice.GetCounter(15);
|
var currentCount = counterDevice.GetCounter(15);
|
||||||
long currentTicks = Stopwatch.GetTimestamp();
|
var currentTicks = Stopwatch.GetTimestamp();
|
||||||
|
|
||||||
// Get the time difference in seconds
|
// Get the time difference in seconds
|
||||||
double timeDifference = (double) (currentTicks - _lastTicks) / Stopwatch.Frequency;
|
var timeDifference = (double) (currentTicks - _lastTicks) / Stopwatch.Frequency;
|
||||||
|
|
||||||
// Figure out how many revolutions per second in the last interval
|
// Figure out how many revolutions per second in the last interval
|
||||||
double revolutionsPerSecond = ((currentCount - _lastCount) / timeDifference) / 2D;
|
var revolutionsPerSecond = ((currentCount - _lastCount) / timeDifference) / 2D;
|
||||||
|
|
||||||
// Store the current time and counter
|
// Store the current time and counter
|
||||||
_lastTicks = currentTicks;
|
_lastTicks = currentTicks;
|
||||||
@@ -70,7 +61,5 @@ namespace WeatherService.Devices
|
|||||||
// Convert the revolutions per second to wind speed
|
// Convert the revolutions per second to wind speed
|
||||||
return (revolutionsPerSecond * 2.453F);
|
return (revolutionsPerSecond * 2.453F);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,36 +1,12 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
[assembly: AssemblyTitle("Weather Reporting")]
|
||||||
// set of attributes. Change these attribute values to modify the information
|
|
||||||
// associated with an assembly.
|
|
||||||
[assembly: AssemblyTitle("WeatherService")]
|
|
||||||
[assembly: AssemblyDescription("")]
|
[assembly: AssemblyDescription("")]
|
||||||
[assembly: AssemblyConfiguration("")]
|
[assembly: AssemblyConfiguration("")]
|
||||||
[assembly: AssemblyCompany("")]
|
[assembly: AssemblyCompany("")]
|
||||||
[assembly: AssemblyProduct("WeatherService")]
|
[assembly: AssemblyProduct("Weather Reporting")]
|
||||||
[assembly: AssemblyCopyright("Copyright © 2012")]
|
[assembly: AssemblyCopyright("Copyright © Chris Kaczor 2012")]
|
||||||
[assembly: AssemblyTrademark("")]
|
[assembly: AssemblyTrademark("")]
|
||||||
[assembly: AssemblyCulture("")]
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
// Setting ComVisible to false makes the types in this assembly not visible
|
[assembly: AssemblyVersion("1.0.*")]
|
||||||
// to COM components. If you need to access a type in this assembly from
|
|
||||||
// COM, set the ComVisible attribute to true on that type.
|
|
||||||
[assembly: ComVisible(false)]
|
|
||||||
|
|
||||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
|
||||||
[assembly: Guid("4d795cba-d705-4c00-8306-423403876429")]
|
|
||||||
|
|
||||||
// Version information for an assembly consists of the following four values:
|
|
||||||
//
|
|
||||||
// Major Version
|
|
||||||
// Minor Version
|
|
||||||
// Build Number
|
|
||||||
// Revision
|
|
||||||
//
|
|
||||||
// You can specify all the values or you can default the Build and Revision Numbers
|
|
||||||
// by using the '*' as shown below:
|
|
||||||
// [assembly: AssemblyVersion("1.0.*")]
|
|
||||||
[assembly: AssemblyVersion("1.0.0.0")]
|
|
||||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
||||||
|
|||||||
18
Session.cs
18
Session.cs
@@ -44,7 +44,7 @@ namespace WeatherService
|
|||||||
Devices = new List<DeviceBase>();
|
Devices = new List<DeviceBase>();
|
||||||
|
|
||||||
// Create a new session
|
// Create a new session
|
||||||
OneWireSession = new owSession();
|
OneWireSession = new OneWireAPI.Session();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -75,7 +75,7 @@ namespace WeatherService
|
|||||||
device.Operations++;
|
device.Operations++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (owException exception)
|
catch (OneWireException exception)
|
||||||
{
|
{
|
||||||
DeviceErrors++;
|
DeviceErrors++;
|
||||||
device.Errors++;
|
device.Errors++;
|
||||||
@@ -104,7 +104,7 @@ namespace WeatherService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddWeatherDevice(owDevice device)
|
private void AddWeatherDevice(Device device)
|
||||||
{
|
{
|
||||||
// TODO - Handle device mapping for multiple devices that use the same family code
|
// TODO - Handle device mapping for multiple devices that use the same family code
|
||||||
|
|
||||||
@@ -113,10 +113,10 @@ namespace WeatherService
|
|||||||
case 0x12:
|
case 0x12:
|
||||||
TMEX.FileEntry fileEntry = new TMEX.FileEntry(); // Entry to describe a file
|
TMEX.FileEntry fileEntry = new TMEX.FileEntry(); // Entry to describe a file
|
||||||
byte[] fileData = new byte[8]; // File data
|
byte[] fileData = new byte[8]; // File data
|
||||||
owIdentifier deviceID; // Identifier for the other device
|
Identifier deviceID; // Identifier for the other device
|
||||||
|
|
||||||
// Select this device
|
// Select this device
|
||||||
owAdapter.Select(device.Id);
|
Adapter.Select(device.Id);
|
||||||
|
|
||||||
// Setup to try to open the pressure sensor file
|
// Setup to try to open the pressure sensor file
|
||||||
fileEntry.Name = System.Text.Encoding.ASCII.GetBytes("8570");
|
fileEntry.Name = System.Text.Encoding.ASCII.GetBytes("8570");
|
||||||
@@ -135,10 +135,10 @@ namespace WeatherService
|
|||||||
TMEX.TMCloseFile(OneWireSession.SessionHandle, OneWireSession.StateBuffer, fileHandle);
|
TMEX.TMCloseFile(OneWireSession.SessionHandle, OneWireSession.StateBuffer, fileHandle);
|
||||||
|
|
||||||
// Create an ID so we can get the string name
|
// Create an ID so we can get the string name
|
||||||
deviceID = new owIdentifier(fileData);
|
deviceID = new Identifier(fileData);
|
||||||
|
|
||||||
// Find the other device
|
// Find the other device
|
||||||
owDevice otherDevice = (owDevice) OneWireSession.Network.Devices[deviceID.Name];
|
Device otherDevice = (Device) OneWireSession.Network.Devices[deviceID.Name];
|
||||||
|
|
||||||
// Create a new pressure device and it to the the list
|
// Create a new pressure device and it to the the list
|
||||||
Devices.Add(new PressureDevice(this, device, otherDevice));
|
Devices.Add(new PressureDevice(this, device, otherDevice));
|
||||||
@@ -217,7 +217,7 @@ namespace WeatherService
|
|||||||
//FireInitialized();
|
//FireInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleDeviceAdded(owDevice device)
|
private void HandleDeviceAdded(Device device)
|
||||||
{
|
{
|
||||||
AddWeatherDevice(device);
|
AddWeatherDevice(device);
|
||||||
}
|
}
|
||||||
@@ -270,7 +270,7 @@ namespace WeatherService
|
|||||||
|
|
||||||
public long DeviceErrors { get; private set; }
|
public long DeviceErrors { get; private set; }
|
||||||
|
|
||||||
internal owSession OneWireSession { get; private set; }
|
internal OneWireAPI.Session OneWireSession { get; private set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,19 @@
|
|||||||
using Microsoft.AspNet.SignalR;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNet.SignalR.Hubs;
|
using Microsoft.AspNet.SignalR;
|
||||||
|
using WeatherService.Devices;
|
||||||
|
using WeatherService.Remote;
|
||||||
|
|
||||||
namespace WeatherService.SignalR
|
namespace WeatherService.SignalR
|
||||||
{
|
{
|
||||||
public class WeatherHub : Hub
|
public class WeatherHub : Hub
|
||||||
{
|
{
|
||||||
public void Send(string message)
|
public List<DeviceBase> GetDevices()
|
||||||
{
|
{
|
||||||
Clients.Others.addMessage(message);
|
var devices = WeatherServiceCommon.GetDevices();
|
||||||
|
|
||||||
|
//var json = JsonConvert.SerializeObject(devices);
|
||||||
|
|
||||||
|
return devices;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ namespace WeatherService.Values
|
|||||||
// Save the reading
|
// Save the reading
|
||||||
using (var weatherArchiveData = new WeatherArchiveData(timeStamp.Year))
|
using (var weatherArchiveData = new WeatherArchiveData(timeStamp.Year))
|
||||||
{
|
{
|
||||||
var reading = new Data.Reading
|
var reading = new Data.ReadingData
|
||||||
{
|
{
|
||||||
DeviceId = _ownerDevice.Id,
|
DeviceId = _ownerDevice.Id,
|
||||||
Type = (int) ValueType,
|
Type = (int) ValueType,
|
||||||
|
|||||||
@@ -121,9 +121,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Conversion.cs" />
|
<Compile Include="Conversion.cs" />
|
||||||
<Compile Include="Data\Device.cs" />
|
<Compile Include="Data\DeviceData.cs" />
|
||||||
<Compile Include="Data\Reading.cs" />
|
<Compile Include="Data\ReadingData.cs" />
|
||||||
<Compile Include="Data\Setting.cs" />
|
<Compile Include="Data\SettingData.cs" />
|
||||||
<Compile Include="Data\WeatherArchiveData.cs" />
|
<Compile Include="Data\WeatherArchiveData.cs" />
|
||||||
<Compile Include="Data\WeatherData.cs" />
|
<Compile Include="Data\WeatherData.cs" />
|
||||||
<Compile Include="Devices\DeviceBase.cs" />
|
<Compile Include="Devices\DeviceBase.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user