diff options
author | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2017-03-18 04:41:54 +0300 |
---|---|---|
committer | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2017-03-18 04:41:54 +0300 |
commit | d1227b9af15cbf3fc8d09c1af0945b06457ef727 (patch) | |
tree | 3691c3e74603532ec41129fbbe65739bb0fda755 /Clovershell | |
parent | 24d29a664710d19107b23a3430995daf648c54ff (diff) |
NES/Famicom autodetection
Diffstat (limited to 'Clovershell')
-rw-r--r-- | Clovershell/ClovershellConnection.cs | 15 | ||||
-rw-r--r-- | Clovershell/ExecConnection.cs | 1 |
2 files changed, 15 insertions, 1 deletions
diff --git a/Clovershell/ClovershellConnection.cs b/Clovershell/ClovershellConnection.cs index 39f18ac5..a99127f9 100644 --- a/Clovershell/ClovershellConnection.cs +++ b/Clovershell/ClovershellConnection.cs @@ -31,6 +31,8 @@ namespace com.clusterrr.clovershell bool autoreconnect = false;
byte[] lastPingResponse = null;
DateTime lastAliveTime;
+ public delegate void OnClovershellConnected();
+ public event OnClovershellConnected OnConnected = delegate{};
internal enum ClovershellCommand
{
@@ -242,8 +244,9 @@ namespace com.clusterrr.clovershell epReader.ReadBufferSize = 65536;
epReader.DataReceived += epReader_DataReceived;
epReader.DataReceivedEnabled = true;
- online = true;
lastAliveTime = DateTime.Now;
+ online = true;
+ OnConnected();
while (device.mUsbRegistry.IsAlive)
{
Thread.Sleep(100);
@@ -573,6 +576,16 @@ namespace com.clusterrr.clovershell return (int)(DateTime.Now - start).TotalMilliseconds;
}
+ public string ExecuteSimple(string command, int timeout = 1500, bool throwOnNonZero = false)
+ {
+ var stdOut = new MemoryStream();
+ Execute(command, null, stdOut, null, timeout, throwOnNonZero);
+ var buff = new byte[stdOut.Length];
+ stdOut.Seek(0, SeekOrigin.Begin);
+ stdOut.Read(buff, 0, buff.Length);
+ return Encoding.UTF8.GetString(buff).Trim();
+ }
+
public int Execute(string command, Stream stdin = null, Stream stdout = null, Stream stderr = null, int timeout = 0, bool throwOnNonZero = false)
{
if (throwOnNonZero && stderr == null)
diff --git a/Clovershell/ExecConnection.cs b/Clovershell/ExecConnection.cs index 7389fd40..913d07b3 100644 --- a/Clovershell/ExecConnection.cs +++ b/Clovershell/ExecConnection.cs @@ -59,6 +59,7 @@ namespace com.clusterrr.clovershell connection.writeUsb(ClovershellConnection.ClovershellCommand.CMD_EXEC_STDIN, (byte)id, buffer, l);
else
break;
+ LastDataTime = DateTime.Now;
if (stdinQueue > 32 * 1024 && connection.IsOnline)
{
Debug.WriteLine(string.Format("queue: {0} / {1}, {2}MB / {3}MB ({4}%)",
|