Re-designed the Site action so that you can now select a site, get a site name, or get a site name.

This commit is contained in:
2019-07-22 16:45:01 +01:00
parent 64e2b9c6f9
commit 1452f3cf07
3 changed files with 237 additions and 12 deletions
+18
View File
@@ -11,5 +11,23 @@ namespace ASCOM.Meade.net
{
return double.Parse(str);
}
public static int Position(this string str, char find, int instance)
{
var currentInstance = 0;
for (var i = 0; i < str.Length; i++)
{
if (str[i] == find)
{
currentInstance++;
if (currentInstance == instance)
{
return i;
}
}
}
return -1;
}
}
}
+146 -9
View File
@@ -242,21 +242,68 @@ namespace ASCOM.Meade.net
break;
case "site":
switch (actionParameters.ToLower())
var parames = actionParameters.ToLower().Split(' ');
switch (parames[0])
{
case "1":
case "2":
case "3":
case "4":
SelectSite(actionParameters.ToInteger());
case "select":
switch (parames[1])
{
case "1":
case "2":
case "3":
case "4":
SelectSite(parames[1].ToInteger());
break;
default:
LogMessage("", "Action {0}, parameters {1} not implemented", actionName,
actionParameters);
throw new InvalidValueException(
$"Site {actionParameters} not allowed, must be between 1 and 4");
}
break;
case "getname":
switch (parames[1])
{
case "1":
case "2":
case "3":
case "4":
return GetSiteName(parames[1].ToInteger());
default:
LogMessage("", "Action {0}, parameters {1} not implemented", actionName,
actionParameters);
throw new InvalidValueException(
$"Site {actionParameters} not allowed, must be between 1 and 4");
}
break;
case "setname":
switch (parames[1])
{
case "1":
case "2":
case "3":
case "4":
var sitename = actionParameters.Substring(actionParameters.Position(' ', 2)).Trim();
SetSiteName(parames[1].ToInteger(), sitename);
break;
default:
LogMessage("", "Action {0}, parameters {1} not implemented", actionName,
actionParameters);
throw new InvalidValueException(
$"Site {actionParameters} not allowed, must be between 1 and 4");
}
break;
default:
LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters);
throw new InvalidValueException($"Site {actionParameters} not allowed, must be between 1 and 4");
throw new InvalidValueException(
$"Site parameters {actionParameters} not known");
}
break;
default:
LogMessage("", "Action {0}, parameters {1} not implemented", actionName, actionParameters);
throw new ActionNotImplementedException($"{actionName}");
@@ -434,6 +481,96 @@ namespace ASCOM.Meade.net
//Returns: Nothing
}
private void SetSiteName(int site, string sitename)
{
CheckConnected("SetSiteName");
if (site < 1)
throw new ArgumentOutOfRangeException("site", site, "Site cannot be lower than 1");
else if (site > 4)
throw new ArgumentOutOfRangeException("site", site, "Site cannot be higher than 4");
string command = String.Empty;
switch (site)
{
case 1:
command = $":SM{sitename}#";
//:SM<string>#
//Set site 1s name to be<string>.LX200s only accept 3 character strings. Other scopes accept up to 15 characters.
// Returns:
//0 Invalid
//1 - Valid
break;
case 2:
command = $":SN{sitename}#";
//:SN<string>#
//Set site 2s name to be<string>.LX200s only accept 3 character strings. Other scopes accept up to 15 characters.
// Returns:
//0 Invalid
//1 - Valid
break;
case 3:
command = $":SO{sitename}#";
//:SO<string>#
//Set site 3s name to be<string>.LX200s only accept 3 character strings. Other scopes accept up to 15 characters.
// Returns:
//0 Invalid
//1 - Valid
break;
case 4:
command = $":SP{sitename}#";
//:SP<string>#
//Set site 4s name to be<string>.LX200s only accept 3 character strings. Other scopes accept up to 15 characters.
// Returns:
//0 Invalid
//1 - Valid
break;
}
var result = _sharedResourcesWrapper.SendChar(command);
if (result != "1")
{
throw new InvalidOperationException("Failed to set site name.");
}
}
private string GetSiteName(int site)
{
CheckConnected("GetSiteName");
if (site < 1)
throw new ArgumentOutOfRangeException("site", site, "Site cannot be lower than 1");
else if (site > 4)
throw new ArgumentOutOfRangeException("site", site, "Site cannot be higher than 4");
switch (site)
{
case 1:
return _sharedResourcesWrapper.SendString(":GM#");
//:GM# Get Site 1 Name
//Returns: <string>#
//A # terminated string with the name of the requested site.
case 2:
return _sharedResourcesWrapper.SendString(":GN#");
//:GN# Get Site 2 Name
//Returns: <string>#
//A # terminated string with the name of the requested site.
case 3:
return _sharedResourcesWrapper.SendString(":GO#");
//:GO# Get Site 3 Name
//Returns: <string>#
//A # terminated string with the name of the requested site.
case 4:
return _sharedResourcesWrapper.SendString(":GP#");
//:GP# Get Site 4 Name
//Returns: <string>#
//A # terminated string with the name of the requested site.
}
throw new ArgumentOutOfRangeException("site", site, "Site out of range");
}
public string Description
{
// TODO customise this device description