Skip to content

Commit

Permalink
Merge pull request #7 from PepperDash/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
ngenovese11 authored Jul 6, 2023
2 parents d4cb6fa + 45fdb74 commit c555415
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/Rs232ParsingUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public static bool ParsePowerResponse(this byte[] response, out bool power)
return true;
}

if (response[2] == 0x02)
{
power = response[3] != 0x00;
return true;
}

power = false;
return false;
}
Expand All @@ -28,11 +34,11 @@ public static bool ParseInputResponse(this byte[] response, out string input)
// TODO [ ] actually add in parsing
Debug.Console(DebugLevels.DebugLevel, "ParseInputResponse response: {0}", response.ToReadableString());

//if (response[2] == 0x02)
//{
// input = "";
// return true;
//}
if (response[2] == 0x02)
{
input = "";
//return true;
}

input = "";
return false;
Expand Down
25 changes: 21 additions & 4 deletions src/SonyBraviaDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,13 @@ public static void Poll(object o)
if (commands == null)
return;

commands.ToList().ForEach(CommandQueue.Enqueue);
commands
.ToList()
.ForEach(command =>
{
CommandQueue.Enqueue(command);
Thread.Sleep(100);
});
}

/// <summary>
Expand Down Expand Up @@ -574,8 +580,19 @@ private object ProcessRs232Response(object _)
Debug.Console(DebugLevels.ErrorLevel, this, "ProcessRs232Response: bytes-'{0}' (len-'{1}') | buffer-'{2}' (len-'{3}')",
bytes.ToReadableString(), bytes.Length, buffer.ToReadableString(), buffer.Length);

while (buffer.Length >= 3)
const int safety = 10;
var numberOfSpins = 0;
while (buffer.Length >= 3 && numberOfSpins <= safety)
{
++numberOfSpins;
if (numberOfSpins == safety)
Debug.Console(0,
this,
Debug.ErrorLogLevel.Notice,
"We hit our safety limit, something is wrong... Buffer:{0}, Bytes:{1}",
buffer.ToReadableString(),
bytes.ToReadableString());

var message = buffer.GetFirstMessage();
Debug.Console(DebugLevels.ErrorLevel, this, "ProcessRs232Response: bytes-'{0}' (len-'{1}') | buffer-'{2}' (len-'{3}') | message-'{4}' (len-'{5}')",
bytes.ToReadableString(), bytes.Length,
Expand Down Expand Up @@ -642,14 +659,14 @@ private object ProcessRs232Response(object _)
if (!isComplete)
{
Debug.Console(DebugLevels.DebugLevel, this, "Message is incomplete... spinning around");
continue;
break;
}

bool powerResult;
if (buffer.ParsePowerResponse(out powerResult))
{
PowerIsOn = powerResult;
Debug.Console(DebugLevels.DebugLevel, "PowerIsOn: {0}", PowerIsOn.ToString());
PowerIsOnFeedback.FireUpdate();
}

string input;
Expand Down

0 comments on commit c555415

Please sign in to comment.