-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocket_Logic_Analyzer.cs
More file actions
96 lines (75 loc) · 2.67 KB
/
Socket_Logic_Analyzer.cs
File metadata and controls
96 lines (75 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// Copyright (c) 2023 Aaron Keith
// Copyright (c) 2010-2022 Antmicro
// Copyright (c) 2011-2015 Realtime Embedded
//
// This file is licensed under the MIT License.
// Full license text is available in 'licenses/MIT.txt'.
//
using System;
using System.Text;
using Antmicro.Renode.Core;
using Antmicro.Renode.Utilities;
using Antmicro.Renode.Logging;
using Antmicro.Renode.Peripherals;
using Antmicro.Renode.Peripherals.Miscellaneous;
using Antmicro.Migrant;
namespace Antmicro.Renode.Backends.Terminals
{
public static class ServerSocketLogicAnalyzerExtensions
{
public static void CreateServerSocketLogicAnalyzer(this Emulation emulation, int port, string name, bool emitConfig = true, bool flushOnConnect = false)
{
emulation.ExternalsManager.AddExternal(new ServerSocketLogicAnalyzer(port, emitConfig, flushOnConnect), name);
}
}
[Transient]
public class ServerSocketLogicAnalyzer : BackendTerminal, IDisposable
{
public ServerSocketLogicAnalyzer(int port, bool emitConfigBytes = true, bool flushOnConnect = false)
{
server = new SocketServerProvider(emitConfigBytes, flushOnConnect);
server.DataReceived += b => Rx_From_Client((byte)b);
this.Log(LogLevel.Info, "ServerSocketLogicAnalyzer started on Port {0}",port);
server.Start(port);
}
public virtual void AttachTo(Logic_Probe Probe)
{
var StateChangedMethod = (Action<ILed, bool>)
((led, currState) =>
{
string Socket_Str = string.Format("{0:HH:mm:ss.ffff} {1} {2}\n", CustomDateTime.Now,led.GetName(), currState);
this.SendString(Socket_Str);
});
this.Log(LogLevel.Info, "AttachTo {0} ",Probe.GetName());
Probe.StateChanged += StateChangedMethod;
}
public void Rx_From_Client(byte value)
{
this.Log(LogLevel.Info, "Rx_From_Client: {0}",value);
//this.WriteChar(value); //echo test
}
public override void WriteChar(byte value)
{
server.SendByte(value);
//this.Log(LogLevel.Info, "****Write {0}",value);
}
protected static readonly Encoding StringEncoding = Encoding.UTF8;
protected void SendBytes(byte[] bytes)
{
foreach(var b in bytes)
{
WriteChar(b);
}
}
protected void SendString(string str)
{
SendBytes(StringEncoding.GetBytes(str));
}
public void Dispose()
{
server.Stop();
}
private readonly SocketServerProvider server;
}
}