Advanced Distributed Systems module at HSLU
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

51 lines
1.3 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RobotLib
{
public abstract class DevBase
{
protected NLog.Logger log { get; private set; }
public DevBase(Com com) : this(com, string.Empty) { }
public DevBase(Com com, string keyword)
{
log = NLog.LogManager.GetLogger(GetType().ToString());
Keyword = keyword;
Com = com;
com.MessageReveived += MessageReveived;
}
protected string Keyword { get; }
protected Com Com { get; }
protected virtual void MessageReveived(object sender, MessageEventArgs e)
{
if (e.Message.StartsWith(Keyword))
{
ParseMessage(e.Message);
}
}
protected void SendMessage(string message)
{
if (Com.IsConnected)
{
log.Trace("Esp32> " + message);
Com.SendMsg(message);
}
else
{
log.Warn("Not connected! Could not send message: " + message);
}
}
protected virtual void ParseMessage(string message) { }
public virtual void Refresh() { }
}
}