Skip to content

Commit f95bcc1

Browse files
Merge branch 'mobile-app' of https://github.com/ClutchplateDude/OpenAstroTracker into mobile-app
2 parents 055d98a + 3d5acc4 commit f95bcc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+679
-685
lines changed

Software/OATMobile/OATCommunications/Class1.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

Software/OATMobile/OATCommunications/CommunicationHandlers/TcpCommunicationHandler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ private async Task<CommandResponse> SendCommand(string command, bool needsRespon
3333
}
3434
catch (Exception e) {
3535
Debug.WriteLine($"Failed To connect or create client: \n{e.Message}");
36+
return new CommandResponse("", false, $"Failed To Connect to Client: {e.Message}");
3637
}
3738
}
3839

39-
_client.ReceiveTimeout = 1000;
40-
40+
_client.ReceiveTimeout = 250;
41+
_client.SendTimeout = 250;
4142

4243
string error = String.Empty;
4344

@@ -51,7 +52,7 @@ private async Task<CommandResponse> SendCommand(string command, bool needsRespon
5152
return new CommandResponse("", false, $"Failed to send message: {e.Message}");
5253
}
5354

54-
Debug.WriteLine($"Sent {bytes}");
55+
Debug.WriteLine($"Sent {command}");
5556

5657
var respString = String.Empty;
5758

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
2+
<PropertyChanged />
3+
</Weavers>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
4+
<xs:element name="Weavers">
5+
<xs:complexType>
6+
<xs:all>
7+
<xs:element name="PropertyChanged" minOccurs="0" maxOccurs="1">
8+
<xs:complexType>
9+
<xs:attribute name="InjectOnPropertyNameChanged" type="xs:boolean">
10+
<xs:annotation>
11+
<xs:documentation>Used to control if the On_PropertyName_Changed feature is enabled.</xs:documentation>
12+
</xs:annotation>
13+
</xs:attribute>
14+
<xs:attribute name="EventInvokerNames" type="xs:string">
15+
<xs:annotation>
16+
<xs:documentation>Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form.</xs:documentation>
17+
</xs:annotation>
18+
</xs:attribute>
19+
<xs:attribute name="CheckForEquality" type="xs:boolean">
20+
<xs:annotation>
21+
<xs:documentation>Used to control if equality checks should be inserted. If false, equality checking will be disabled for the project.</xs:documentation>
22+
</xs:annotation>
23+
</xs:attribute>
24+
<xs:attribute name="CheckForEqualityUsingBaseEquals" type="xs:boolean">
25+
<xs:annotation>
26+
<xs:documentation>Used to control if equality checks should use the Equals method resolved from the base class.</xs:documentation>
27+
</xs:annotation>
28+
</xs:attribute>
29+
<xs:attribute name="UseStaticEqualsFromBase" type="xs:boolean">
30+
<xs:annotation>
31+
<xs:documentation>Used to control if equality checks should use the static Equals method resolved from the base class.</xs:documentation>
32+
</xs:annotation>
33+
</xs:attribute>
34+
<xs:attribute name="SuppressWarnings" type="xs:boolean">
35+
<xs:annotation>
36+
<xs:documentation>Used to turn off build warnings from this weaver.</xs:documentation>
37+
</xs:annotation>
38+
</xs:attribute>
39+
<xs:attribute name="SuppressOnPropertyNameChangedWarning" type="xs:boolean">
40+
<xs:annotation>
41+
<xs:documentation>Used to turn off build warnings about mismatched On_PropertyName_Changed methods.</xs:documentation>
42+
</xs:annotation>
43+
</xs:attribute>
44+
</xs:complexType>
45+
</xs:element>
46+
</xs:all>
47+
<xs:attribute name="VerifyAssembly" type="xs:boolean">
48+
<xs:annotation>
49+
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
50+
</xs:annotation>
51+
</xs:attribute>
52+
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
53+
<xs:annotation>
54+
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
55+
</xs:annotation>
56+
</xs:attribute>
57+
<xs:attribute name="GenerateXsd" type="xs:boolean">
58+
<xs:annotation>
59+
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
60+
</xs:annotation>
61+
</xs:attribute>
62+
</xs:complexType>
63+
</xs:element>
64+
</xs:schema>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.ComponentModel;
2+
3+
namespace OATCommunications.Model {
4+
public class MountState : ObservableClass, IReadOnlyMountState{
5+
public bool IsTracking { get; set; }
6+
public bool IsSlewing { get; set; }
7+
public bool IsSlewingRA { get; set; }
8+
public bool IsSlewingDec { get; set; }
9+
public double RightAscension { get; set; }
10+
public double Declination { get; set; }
11+
}
12+
13+
public interface IReadOnlyMountState : INotifyPropertyChanged {
14+
bool IsTracking { get; }
15+
bool IsSlewing { get; }
16+
bool IsSlewingRA { get; }
17+
bool IsSlewingDec { get; }
18+
double RightAscension { get; }
19+
double Declination { get; }
20+
21+
22+
}
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace OATCommunications.Model
6+
{
7+
public class OatSettings
8+
{
9+
public int RaStepsPerDegree { get; set; }
10+
public int DecStepsPerDegree { get; set; }
11+
public float SpeedCalibration { get; set; }
12+
}
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Text;
5+
6+
namespace OATCommunications.Model
7+
{
8+
public class ObservableClass : INotifyPropertyChanged
9+
{
10+
public event PropertyChangedEventHandler PropertyChanged;
11+
12+
protected void OnPropertyChanged(string propertyName) {
13+
var handler = PropertyChanged;
14+
handler?.Invoke(this, new PropertyChangedEventArgs(propertyName));
15+
}
16+
}
17+
}

Software/OATMobile/OATCommunications/OATCommunications.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@
44
<TargetFramework>netstandard2.0</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<PackageReference Include="Fody" Version="6.1.1">
9+
<PrivateAssets>all</PrivateAssets>
10+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
11+
</PackageReference>
12+
<PackageReference Include="PropertyChanged.Fody" Version="3.2.8" />
13+
</ItemGroup>
14+
715
</Project>

Software/OATMobile/OATCommunications/TelescopeCommandHandlers/ITelescopeCommandHandler.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ public interface ITelescopeCommandHandler {
1414
Task<bool> SetLocation(double lat, double lon, double altitudeInMeters, double lstInHours);
1515
Task<bool> StartMoving(string dir);
1616
Task<bool> StopMoving(string dir);
17+
MountState MountState { get; }
18+
Task<bool> RefreshMountState();
1719
}
1820
}

Software/OATMobile/OATCommunications/TelescopeCommandHandlers/OatmealTelescopeCommandHandlers.cs

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Net;
4-
using System.Runtime.CompilerServices;
5-
using System.Text;
2+
using System.Linq;
63
using System.Threading.Tasks;
74
using OATCommunications.CommunicationHandlers;
85
using OATCommunications.Model;
@@ -14,31 +11,94 @@ public class OatmealTelescopeCommandHandlers : ITelescopeCommandHandler
1411
{
1512
private readonly ICommunicationHandler _commHandler;
1613

14+
private int _moveState = 0;
15+
16+
public MountState MountState { get; } = new MountState();
17+
1718
public OatmealTelescopeCommandHandlers(ICommunicationHandler commHandler) {
1819
_commHandler = commHandler;
1920
}
2021

22+
public async Task<bool> RefreshMountState() {
23+
var _slewingStates = new []{"SlewToTarget", "FreeSlew", "ManualSlew"};
24+
25+
var status = await SendCommand(":GX#");
26+
if (!status.Success) {
27+
return false;
28+
}
29+
30+
var parts = status.Data.Split(',');
31+
MountState.IsTracking = parts[1][2] == 'T';
32+
MountState.IsSlewing = _slewingStates.Contains(parts[0]);
33+
MountState.RightAscension = GetCompactRA(parts[5]);
34+
MountState.Declination = GetCompactDec(parts[6]);
35+
36+
return status.Success;
37+
38+
}
39+
40+
private double GetCompactDec(string part) {
41+
var d = int.Parse(part.Substring(0, 3));
42+
var m = int.Parse(part.Substring(3, 2));
43+
var s = int.Parse(part.Substring(5, 2));
44+
45+
return d + m / 60.0 + s / 3600.0;
46+
}
47+
48+
private double GetCompactRA(string part) {
49+
var h = int.Parse(part.Substring(0, 2));
50+
var m = int.Parse(part.Substring(2, 2));
51+
var s = int.Parse(part.Substring(4, 2));
52+
53+
return h + m / 60.0 + s / 3600.0;
54+
}
55+
2156
public async Task<TelescopePosition> GetPosition() {
2257
var ra = await SendCommand(":GR#");
2358
var dec = await SendCommand(":GD#");
2459

25-
if(ra.Success && dec.Success &&
26-
double.TryParse(ra.Data, out double dRa) &&
27-
double.TryParse(dec.Data, out double dDec)){
60+
if(ra.Success && dec.Success &&
61+
TryParseRA(ra.Data, out double dRa) &&
62+
TryParseDec(dec.Data, out double dDec)) {
63+
64+
MountState.RightAscension = dRa;
65+
MountState.Declination = dDec;
2866
return new TelescopePosition(dRa, dDec, Epoch.JNOW);
2967
}
3068

69+
MountState.RightAscension = 0;
70+
MountState.Declination = 0;
3171
return TelescopePosition.Invalid;
3272

3373
}
3474

75+
private bool TryParseRA(string ra, out double dRa) {
76+
var parts = ra.Split(':');
77+
dRa = int.Parse(parts[0]) + int.Parse(parts[1]) / 60.0 + int.Parse(parts[2]) / 3600.0;
78+
return true;
79+
}
80+
81+
private bool TryParseDec(string dec, out double dDec)
82+
{
83+
var parts = dec.Split('*', '\'');
84+
dDec = int.Parse(parts[0]) + int.Parse(parts[1]) / 60.0 + int.Parse(parts[2]) / 3600.0;
85+
return true;
86+
}
87+
3588
public async Task<bool> StartMoving(string dir) {
3689
var status = await SendCommand($":M{dir}#");
90+
MountState.IsSlewing = true;
91+
++_moveState;
3792
return status.Success;
3893
}
3994

4095
public async Task<bool> StopMoving(string dir) {
4196
var status = await SendCommand($":Q{dir}#");
97+
--_moveState;
98+
if (_moveState <= 0) {
99+
_moveState = 0;
100+
MountState.IsSlewing = false;
101+
}
42102
return status.Success;
43103
}
44104

@@ -64,6 +124,9 @@ public async Task<bool> SetHome()
64124
public async Task<bool> SetTracking(bool enabled) {
65125
var b = enabled ? 1 : 0;
66126
var status = await SendCommand($":MT{b}#");
127+
if (status.Success) {
128+
MountState.IsTracking = enabled;
129+
}
67130
return status.Success;
68131
}
69132

0 commit comments

Comments
 (0)