|
|
|
@ -1,8 +1,5 @@ |
|
|
|
using System; |
|
|
|
using RobotLib.Communication; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
|
|
|
|
using System.Text; |
|
|
|
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace RobotLib |
|
|
|
namespace RobotLib |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -10,40 +7,40 @@ namespace RobotLib |
|
|
|
{ |
|
|
|
{ |
|
|
|
protected NLog.Logger log { get; private set; } |
|
|
|
protected NLog.Logger log { get; private set; } |
|
|
|
|
|
|
|
|
|
|
|
public DevBase(Com com) : this(com, string.Empty) { } |
|
|
|
public DevBase(IPublisherSubscriber com) : this(com, new List<string>()) { } |
|
|
|
public DevBase(Com com, string keyword) |
|
|
|
public DevBase(IPublisherSubscriber com, List<string> interestedTopics) |
|
|
|
{ |
|
|
|
{ |
|
|
|
log = NLog.LogManager.GetLogger(GetType().ToString()); |
|
|
|
log = NLog.LogManager.GetLogger(GetType().ToString()); |
|
|
|
|
|
|
|
|
|
|
|
Keyword = keyword; |
|
|
|
|
|
|
|
Com = com; |
|
|
|
Com = com; |
|
|
|
com.MessageReveived += MessageReveived; |
|
|
|
InterestedTopics = interestedTopics; |
|
|
|
|
|
|
|
com.NewMessageArrived += Com_NewMessageArrived; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected string Keyword { get; } |
|
|
|
|
|
|
|
protected Com Com { get; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void MessageReveived(object sender, MessageEventArgs e) |
|
|
|
protected List<string> InterestedTopics { get; } |
|
|
|
|
|
|
|
protected IPublisherSubscriber Com { get; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void Com_NewMessageArrived(object sender, SubscribedMsgArrivedEventArgs e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (e.Message.StartsWith(Keyword)) |
|
|
|
if (InterestedTopics.Contains(e.Topic)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ParseMessage(e.Message); |
|
|
|
ParseMessage(e.Topic, e.Message); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void SendMessage(string message) |
|
|
|
protected void SendMessage(string topic, string message) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (Com.IsConnected) |
|
|
|
if (Com.IsConnected) |
|
|
|
{ |
|
|
|
{ |
|
|
|
log.Trace("Esp32> " + message); |
|
|
|
Com.Publish(topic, message); |
|
|
|
Com.SendMsg(message); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
log.Warn("Not connected! Could not send message: " + message); |
|
|
|
log.Warn("Not connected! Could not send message: " + message); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
protected virtual void ParseMessage(string message) { } |
|
|
|
protected virtual void ParseMessage(string fromTopic, string message) { } |
|
|
|
|
|
|
|
|
|
|
|
public virtual void Refresh() { } |
|
|
|
public virtual void Refresh() { } |
|
|
|
|
|
|
|
|
|
|
|
|