Skip to content

Commit

Permalink
Add Power Connect Probe
Browse files Browse the repository at this point in the history
Boukhechba committed May 22, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent a63e8a0 commit 8678320
Showing 4 changed files with 135 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -54,6 +54,7 @@ public override void OnReceive(global::Android.Content.Context context, Intent i
WifiManager wifiManager = Application.Context.GetSystemService(global::Android.Content.Context.WifiService) as WifiManager;
currAccessPointBSSID = wifiManager.ConnectionInfo.BSSID;
currAccessPointRssi = wifiManager.ConnectionInfo.Rssi.ToString();

}

if (FIRST_RECEIVE || currAccessPointBSSID != PREVIOUS_ACCESS_POINT_BSSID)
86 changes: 86 additions & 0 deletions Sensus.Shared/Probes/Device/ListeningPowerConnectProbe.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Sensus.Context;
using Syncfusion.SfChart.XForms;

namespace Sensus.Probes.Device
{
public class ListeningPowerConnectProbe : ListeningProbe
{
private EventHandler<bool> _powerConnectionChanged;

public ListeningPowerConnectProbe()
{
_powerConnectionChanged = async (sender, connected) =>
{
await StoreDatumAsync(new PowerConnectDatum(DateTimeOffset.UtcNow,connected));
};

}

public override string DisplayName
{
get
{
return "Power Connection";
}
}
public override Type DatumType
{
get { return typeof(PowerConnectDatum); }
}

[JsonIgnore]
protected override bool DefaultKeepDeviceAwake
{
get
{
return false;
}
}

protected override Task StartListeningAsync()
{
base.StartListeningAsync();
SensusContext.Current.PowerConnectionChangeListener.PowerConnectionChanged += _powerConnectionChanged;
return Task.CompletedTask;
}

protected override Task StopListeningAsync()
{
base.StopListeningAsync();
SensusContext.Current.PowerConnectionChangeListener.PowerConnectionChanged -= _powerConnectionChanged;
return Task.CompletedTask;
}


protected override string DeviceAwakeWarning => throw new NotImplementedException();

protected override string DeviceAsleepWarning => throw new NotImplementedException();

protected override ChartDataPoint GetChartDataPointFromDatum(Datum datum)
{
throw new NotImplementedException();
}

protected override ChartAxis GetChartPrimaryAxis()
{
throw new NotImplementedException();
}

protected override RangeAxisBase GetChartSecondaryAxis()
{
throw new NotImplementedException();
}

protected override ChartSeries GetChartSeries()
{
throw new NotImplementedException();
}


}
}
46 changes: 46 additions & 0 deletions Sensus.Shared/Probes/Device/PowerConnectDatum.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Sensus.Probes.Device
{
class PowerConnectDatum : Datum
{
private bool _connection;


public PowerConnectDatum(DateTimeOffset timestamp, bool connection) : base(timestamp)
{
_connection = connection;
}


public override string DisplayDetail
{
get
{
return "(Power connect Data)";
}
}

public bool Connection { get => _connection; set => _connection = value; }

public override object StringPlaceholderValue => throw new NotImplementedException();

public override bool Equals(object obj)
{
return base.Equals(obj);
}

public override int GetHashCode()
{
return base.GetHashCode();
}

public override string ToString()
{
return base.ToString() + Environment.NewLine +
"Connected: " + _connection+ Environment.NewLine;
}
}
}
2 changes: 2 additions & 0 deletions Sensus.Shared/Sensus.Shared.projitems
Original file line number Diff line number Diff line change
@@ -38,6 +38,8 @@
<Compile Include="$(MSBuildThisFileDirectory)Probes\Context\HumidityProbe.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Probes\Context\SoundDatum.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Probes\Device\BatteryDatum.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Probes\Device\PowerConnectDatum.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Probes\Device\ListeningPowerConnectProbe.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Probes\Device\ScreenDatum.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Probes\Location\ProximityDatum.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Probes\Location\ProximityProbe.cs" />

0 comments on commit 8678320

Please sign in to comment.