Added messages to include information about what is being sent via the serial port.

This commit is contained in:
2022-07-25 16:07:55 +01:00
parent 6428e6d31b
commit 7287990240
5 changed files with 37 additions and 26 deletions
@@ -2679,10 +2679,10 @@ namespace Meade.net.Telescope.UnitTests
} }
[TestCase(DriveRates.driveSidereal, "60.1")] [TestCase(DriveRates.driveSidereal, "60.1")]
[TestCase(DriveRates.driveSolar, "60.0")] [TestCase(DriveRates.driveSidereal, "60.0")]
[TestCase(DriveRates.driveLunar, "57.9")] [TestCase(DriveRates.driveLunar, "57.9")]
[TestCase(DriveRates.driveSidereal, "+60.1")] [TestCase(DriveRates.driveSidereal, "+60.1")]
[TestCase(DriveRates.driveSolar, "+60.0")] [TestCase(DriveRates.driveSidereal, "+60.0")]
[TestCase(DriveRates.driveLunar, "+57.9")] [TestCase(DriveRates.driveLunar, "+57.9")]
[TestCase(DriveRates.driveLunar, "57.3")] [TestCase(DriveRates.driveLunar, "57.3")]
[TestCase(DriveRates.driveLunar, "58.9")] [TestCase(DriveRates.driveLunar, "58.9")]
+3 -3
View File
@@ -3597,10 +3597,10 @@ namespace ASCOM.Meade.net
DriveRates result; DriveRates result;
if (rateDouble.Equals(60.1)) if (rateDouble.Between(59.9, 60.1))
result = DriveRates.driveSidereal; result = DriveRates.driveSidereal;
else if (rateDouble.Equals(60.0)) //else if (rateDouble.Equals(60.0))
result = DriveRates.driveSolar; // result = DriveRates.driveSolar;
else if (rateDouble.Between(57.3, 58.9)) else if (rateDouble.Between(57.3, 58.9))
result = DriveRates.driveLunar; result = DriveRates.driveLunar;
else else
@@ -53,7 +53,7 @@ namespace Meade.net.UnitTests
_serialMock.Setup(x => x.ReceiveCounted(1)).Returns(expectedResult); _serialMock.Setup(x => x.ReceiveCounted(1)).Returns(expectedResult);
var result = SharedResources.SendChar(command, raw); var result = SharedResources.SendChar(_traceLoggerMock.Object, command, raw);
_serialMock.Verify(x => x.ClearBuffers(), Times.Once); _serialMock.Verify(x => x.ClearBuffers(), Times.Once);
_serialMock.Verify(x => x.Transmit(expectedCommand), Times.Once); _serialMock.Verify(x => x.Transmit(expectedCommand), Times.Once);
@@ -70,7 +70,7 @@ namespace Meade.net.UnitTests
_serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(expectedResult); _serialMock.Setup(x => x.ReceiveTerminated("#")).Returns(expectedResult);
var result = SharedResources.SendString(transmitMessage, includePrefix); var result = SharedResources.SendString(_traceLoggerMock.Object, transmitMessage, includePrefix);
_serialMock.Verify(x => x.ClearBuffers(), Times.Once); _serialMock.Verify(x => x.ClearBuffers(), Times.Once);
_serialMock.Verify(x => x.Transmit(expectedMessage), Times.Once); _serialMock.Verify(x => x.Transmit(expectedMessage), Times.Once);
+25 -14
View File
@@ -99,21 +99,25 @@ namespace ASCOM.Meade.net
/// <param name="message"></param> /// <param name="message"></param>
/// <param name="raw"></param> /// <param name="raw"></param>
/// <returns></returns> /// <returns></returns>
public static string SendString(string message, bool raw = false) public static string SendString(ITraceLogger traceLogger, string message, bool raw = false)
{ {
lock (LockObject) lock (LockObject)
{ {
SharedSerial.ClearBuffers(); SharedSerial.ClearBuffers();
var encodedMessage = raw ? message : $"#:{message}#"; var encodedMessage = raw ? message : $"#:{message}#";
traceLogger.LogMessage("SendString", $"Transmitting {encodedMessage}", false);
SharedSerial.Transmit(encodedMessage); SharedSerial.Transmit(encodedMessage);
try try
{ {
return SharedSerial.ReceiveTerminated("#").TrimEnd('#'); var result = SharedSerial.ReceiveTerminated("#").TrimEnd('#');
traceLogger.LogMessage("SendString", $"Received {result}", false);
return result;
} }
catch (COMException ex) catch (COMException ex)
{ {
traceLogger.LogIssue("SendString", ex.Message);
if (ex.Message.Contains("Timed out waiting for received data")) if (ex.Message.Contains("Timed out waiting for received data"))
throw new TimeoutException(ex.Message, ex); throw new TimeoutException(ex.Message, ex);
@@ -122,34 +126,41 @@ namespace ASCOM.Meade.net
} }
} }
public static bool SendBool(string command, bool raw = false) public static bool SendBool(ITraceLogger traceLogger, string command, bool raw = false)
{ {
var result = SendChar(command, raw); var result = SendChar(traceLogger, command, raw);
return result == "1"; return result == "1";
} }
public static string SendChar(string command, bool raw = false) public static string SendChar(ITraceLogger traceLogger, string command, bool raw = false)
{ {
return SendChars(command, raw, count: 1); return SendChars(traceLogger, command, raw, count: 1);
} }
public static string SendChars(string command, bool raw = false, int count = 1) public static string SendChars(ITraceLogger traceLogger, string command, bool raw = false, int count = 1)
{ {
lock (LockObject) lock (LockObject)
{ {
SharedSerial.ClearBuffers(); SharedSerial.ClearBuffers();
var encodedMessage = raw ? command : $"#:{command}#"; var encodedMessage = raw ? command : $"#:{command}#";
traceLogger.LogMessage("SendChars", $"Transmitting {encodedMessage}", false);
SharedSerial.Transmit(encodedMessage); SharedSerial.Transmit(encodedMessage);
try try
{ {
return SharedSerial.ReceiveCounted(count); var result = SharedSerial.ReceiveCounted(count);
traceLogger.LogMessage("SendChars", $"Received {result}", false);
return result;
} }
catch (COMException ex) when (ex.Message.Contains("Timed out waiting for received data")) catch (COMException ex)
{ {
traceLogger.LogIssue("SendString", ex.Message);
if (ex.Message.Contains("Timed out waiting for received data"))
throw new TimeoutException(ex.Message, ex); throw new TimeoutException(ex.Message, ex);
throw;
} }
} }
} }
@@ -404,7 +415,7 @@ namespace ASCOM.Meade.net
//Test if communication is working. //Test if communication is working.
try try
{ {
string utcOffSet = SendString("GG"); string utcOffSet = SendString( traceLogger, "GG");
} }
catch (Exception) catch (Exception)
{ {
@@ -433,7 +444,7 @@ namespace ASCOM.Meade.net
//SendBlind($"SB{newSpeedIndex}"); //SendBlind($"SB{newSpeedIndex}");
try try
{ {
var speedChanged = SendChar($"SB{newSpeedIndex}"); var speedChanged = SendChar(traceLogger, $"SB{newSpeedIndex}");
if (speedChanged == "1") if (speedChanged == "1")
{ {
SharedSerial.Connected = false; SharedSerial.Connected = false;
@@ -458,8 +469,8 @@ namespace ASCOM.Meade.net
try try
{ {
ProductName = SendString("GVP"); ProductName = SendString(traceLogger, "GVP");
FirmwareVersion = SendString("GVN"); FirmwareVersion = SendString(traceLogger, "GVN");
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -479,7 +490,7 @@ namespace ASCOM.Meade.net
try try
{ {
string utcOffSet = SendString("GG"); string utcOffSet = SendString(traceLogger, "GG");
//:GG# Get UTC offset time //:GG# Get UTC offset time
//Returns: sHH# or sHH.H# //Returns: sHH# or sHH.H#
//The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the //The number of decimal hours to add to local time to convert it to UTC. If the number is a whole number the
+4 -4
View File
@@ -68,7 +68,7 @@ namespace ASCOM.Meade.net.Wrapper
public string SendString(ITraceLogger traceLogger, string message, bool raw = false) public string SendString(ITraceLogger traceLogger, string message, bool raw = false)
{ {
return SharedResources.SendString(message, raw); return SharedResources.SendString(traceLogger, message, raw);
} }
public void SendBlind(ITraceLogger traceLogger, string message, bool raw = false) public void SendBlind(ITraceLogger traceLogger, string message, bool raw = false)
@@ -78,17 +78,17 @@ namespace ASCOM.Meade.net.Wrapper
public bool SendBool(ITraceLogger traceLogger, string command, bool raw = false) public bool SendBool(ITraceLogger traceLogger, string command, bool raw = false)
{ {
return SharedResources.SendBool(command, raw); return SharedResources.SendBool(traceLogger, command, raw);
} }
public string SendChar(ITraceLogger traceLogger, string message, bool raw = false) public string SendChar(ITraceLogger traceLogger, string message, bool raw = false)
{ {
return SharedResources.SendChar(message, raw); return SharedResources.SendChar(traceLogger, message, raw);
} }
public string SendChars(ITraceLogger traceLogger, string message, bool raw = false, int count = 1) public string SendChars(ITraceLogger traceLogger, string message, bool raw = false, int count = 1)
{ {
return SharedResources.SendChars(message, raw, count); return SharedResources.SendChars(traceLogger, message, raw, count);
} }
public string ReadTerminated() public string ReadTerminated()