private void DispatchReadChannelDataMessage(ProtocolMessage protocolMessage) { byte id = protocolMessage.ControllerID; CpuNode node = this.Nodes.First(x => x.Id == protocolMessage.ControllerID); if (node == null) { throw new ArgumentException("No node found"); } ReadChannelDataMessage readChannelDataMessage = new ReadChannelDataMessage(protocolMessage); List <byte> value = readChannelDataMessage.Data.ToList(); for (int i = 255; i >= 0; i--) { if ((readChannelDataMessage.Mask >> i & 1) == 1 && this.DebugChannels[node].ContainsKey((byte)i)) { byte[] myValue = value.Take(this.DebugChannels[node][(byte)i].Size).ToArray(); value.RemoveRange(0, this.DebugChannels[node][(byte)i].Size); RegisterValue regVal = new RegisterValue { TimeStamp = readChannelDataMessage.TimeStamp, ValueByteArray = myValue }; NewValueReceived(this, new ValueReceivedEventArgs(regVal, this.DebugChannels[node][(byte)i], node)); } } }
private void DispatchQueryRegisterMessage(ProtocolMessage protocolMessage) { QueryRegisterMessage response = new QueryRegisterMessage(protocolMessage); if (response.Value == null) { // Error reading occured! throw new ArgumentException("Error reading occured"); } if (this.Nodes.All(x => x.Id != protocolMessage.ControllerID)) { throw new ArgumentException("No node found for the msg"); } CpuNode node = this.Nodes.First(x => x.Id == protocolMessage.ControllerID); MessageCodec.GetControlByteValues(node.ProtocolVersion, response.Control, out ReadWrite readWrite, out Source source, out int derefDepth); Register r = node.EmbeddedConfig.GetRegister(response.Offset, readWrite); if (r == null) { throw new ArgumentException("No register found with this offset or readwrite"); } NewValueReceived(this, new ValueReceivedEventArgs(RegisterValue.GetRegisterValueByVariableType(r.VariableType, response.Value), r, node)); }
private void DispatchVersionMessage(ProtocolMessage protocolMessage) { VersionMessage versionMessage = new VersionMessage(protocolMessage); byte id = protocolMessage.ControllerID; // Create a new node with the information that was gathered CpuNode node = new CpuNode(id, versionMessage.ProtocolVersion, versionMessage.ApplicationVersion, versionMessage.Name, versionMessage.SerialNumber); if ( // TODO, make the base path globally configurable node.TryToLoadConfiguration( Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "EmbeddedDebugger", "Configurations", this.Name, node.Name.Trim(), $"cpu{id:D2}-V{node.ApplicationVersion.Major:D2}_{node.ApplicationVersion.Minor:D2}_{node.ApplicationVersion.Build:D4}.xml"))) { this.DebugChannels.Add(node, new Dictionary <byte, Register>()); this.NewNodeFound?.Invoke(this, node); } else { // TODO: Implement something to let the user know that no config file was found } }
public override void SetupSignalTracing(CpuNode cpuNode, Register register, ChannelMode channelMode) { // Make sure the CpuNode is present in our dictionary if (DebugChannels.ContainsKey(cpuNode)) { if (!this.DebugChannels[cpuNode].ContainsValue(register) && channelMode != ChannelMode.Off) { for (byte i = 0; i < 255; i++) { if (!register.CpuNode.DebugChannels.ContainsKey(i)) { this.DebugChannels[cpuNode].Add(i, register); break; } } } if (this.DebugChannels[cpuNode].ContainsValue(register)) { Version protocolVersion = cpuNode.ProtocolVersion; ConfigChannelMessage msg = new ConfigChannelMessage() { ChannelId = this.DebugChannels[cpuNode].First(x => x.Value.Id == register.Id).Key, Mode = channelMode, Offset = register.Offset, Control = MessageCodec.GetControlByte(protocolVersion, register.ReadWrite, register.Source, register.DerefDepth), Size = register.Size, }; SendMessage(cpuNode.Id, msg); if (this.DebugChannels[cpuNode].ContainsValue(register) && channelMode == ChannelMode.Off) { this.DebugChannels[cpuNode].Remove(this.DebugChannels[cpuNode].First(x => x.Value.Id == register.Id).Key); } } } }
public override void WriteConsole(CpuNode cpuNode, string message) { DebugStringMessage msg = new DebugStringMessage() { Message = message }; // TODO add the msgID this.SendMessage(MessageCodec.EncodeMessage(msg.ToProtocolMessage(cpuNode.Id, 0x01))); }
public override void QueryValue(CpuNode cpuNode, Register register) { Version protocolVersion = cpuNode.ProtocolVersion; byte control = MessageCodec.GetControlByte(protocolVersion, register.ReadWrite, register.Source, register.DerefDepth); QueryRegisterMessage msg = new QueryRegisterMessage() { Offset = register.Offset, Control = control, }; // TODO add the msgID this.SendMessage(MessageCodec.EncodeMessage(msg.ToProtocolMessage(cpuNode.Id, 0x01))); }
public void SetDebugChannel(int nodeID, int registerID, ChannelMode mode) { if (!mm.Nodes.Any(x => x.Id == nodeID)) { return; } CpuNode node = mm.Nodes.First(x => x.Id == nodeID); if (!node.Registers.Any(x => x.Id == registerID)) { return; } node.Registers.First(x => x.Id == registerID).ChannelMode = mode; }
private void Node_NewTerminalDataAdded(CpuNode node, string s) { if (enabled == true) { if (registeredNodes.Count == 1) { EmbeddedTerminal.AddResponse(s); } else { EmbeddedTerminal.AddResponse($"({node}){s}"); } } }
public void SetPlotting(int nodeID, int registerID, bool plotting) { if (!mm.Nodes.Any(x => x.ID == nodeID)) { return; } CpuNode node = mm.Nodes.First(x => x.ID == nodeID); if (!node.Registers.Any(x => x.ID == registerID)) { return; } //node.Registers.First(x => x.ID == registerID).Plot = plotting; }
public void SetLogging(int nodeID, int registerID, bool logging) { if (!mm.Nodes.Any(x => x.Id == nodeID)) { return; } CpuNode node = mm.Nodes.First(x => x.Id == nodeID); if (!node.Registers.Any(x => x.Id == registerID)) { return; } //node.Registers.First(x => x.ID == registerID).Log = logging; }
public ValueReceivedEventArgs(RegisterValue registerValue, Register register, CpuNode cpuNode) { this.Value = registerValue; this.Register = register; this.CpuNode = cpuNode; }
public abstract void ResetTime(CpuNode cpuNode);
public abstract void SetupSignalTracing(CpuNode cpuNode, Register register, ChannelMode channelMode);
public abstract void WriteConsole(CpuNode cpuNode, string message);
public abstract void WriteValue(CpuNode cpuNode, Register register, RegisterValue registerValue);
public abstract void QueryValue(CpuNode cpuNode, Register register);
public void ResetTime(CpuNode cpuNode = null) { this.modelManager.ResetTime(); }
public override void ResetTime(CpuNode cpuNode) { // TODO Add correct message id this.SendMessage(MessageCodec.EncodeMessage(new ProtocolMessage(cpuNode.Id, 0x02, Command.ResetTime))); }