added logging to file for UI app,

introduced robot types in RobotLib,
publishing with qos = 0 and retain = false
main
Jonas Arnold 4 years ago
parent decb1f3b17
commit 75c0788d95
  1. 4
      ADIS_Csharp/RobotClientWpf/ChallengeFactory.cs
  2. 6
      ADIS_Csharp/RobotClientWpf/NLog.config
  3. 5
      ADIS_Csharp/RobotLib/Battery/DevBattery.cs
  4. 2
      ADIS_Csharp/RobotLib/Communication/MqttPublisherSubscriber.cs
  5. 42
      ADIS_Csharp/RobotLib/Robot.cs
  6. 9
      ADIS_Csharp/RobotLib/RobotTypes.cs

@ -12,8 +12,8 @@ namespace RobotClientWpf
public ChallengeFactory() public ChallengeFactory()
{ {
this.PublisherSubscriber = MqttPublisherSubscriber.Instance; this.PublisherSubscriber = MqttPublisherSubscriber.Instance;
this.RobotStationary = new Robot(this.PublisherSubscriber); this.RobotStationary = new Robot(this.PublisherSubscriber, RobotTypes.Stationary);
this.RobotMobile = new Robot(this.PublisherSubscriber); this.RobotMobile = new Robot(this.PublisherSubscriber, RobotTypes.Mobile);
} }
} }
} }

@ -10,9 +10,15 @@
<target <target
xsi:type="CacheTarget" xsi:type="CacheTarget"
name="cache"/> name="cache"/>
<target name="file" xsi:type="File"
layout="${longdate} ${logger} ${message}${exception:format=ToString}"
fileName="${basedir}/logs/logfile.txt"
keepFileOpen="true"
encoding="utf-8" />
</targets> </targets>
<rules> <rules>
<logger name="*" writeTo="cache" minlevel="Debug"/> <logger name="*" writeTo="cache" minlevel="Debug"/>
<logger name="*" minlevel="Trace" writeTo="file" />
</rules> </rules>
</nlog> </nlog>

@ -31,11 +31,6 @@ namespace RobotLib.Battery
public DevBattery(IPublisherSubscriber com) : base(com, new List<string>() { TOPIC_ROBO_RESP_BATTERY }) { } public DevBattery(IPublisherSubscriber com) : base(com, new List<string>() { TOPIC_ROBO_RESP_BATTERY }) { }
public override void Refresh()
{
this.RequestBatteryVoltage();
}
public void RequestBatteryVoltage() public void RequestBatteryVoltage()
{ {
base.SendMessage(TOPIC_ROBO_REQ_BATTERY, true.ToString()); base.SendMessage(TOPIC_ROBO_REQ_BATTERY, true.ToString());

@ -159,7 +159,7 @@ namespace RobotLib.Communication
} }
lock (clientLock) lock (clientLock)
{ {
var msgId = client.Publish(topic, Encoding.ASCII.GetBytes(message)); var msgId = client.Publish(topic, Encoding.ASCII.GetBytes(message), 0, false);
log.Trace($"Published to topic '{topic}'. MessageId = {msgId}"); log.Trace($"Published to topic '{topic}'. MessageId = {msgId}");
} }
} }

@ -2,26 +2,43 @@
using RobotLib.SplitFlap; using RobotLib.SplitFlap;
using RobotLib.Movement; using RobotLib.Movement;
using RobotLib.Battery; using RobotLib.Battery;
using System.Threading; using System.Timers;
namespace RobotLib namespace RobotLib
{ {
public class Robot public class Robot
{ {
public Robot(IPublisherSubscriber com) public Robot(IPublisherSubscriber com, RobotTypes type)
{ {
Com = com; Com = com;
//Buzzer = new DevBuzzer(Com); Type = type;
Battery = new DevBattery(Com); if(type == RobotTypes.Undefined)
SplitFlap = new DevSplitFlap(com); {
LineSensor = new DevLineSensor(com); throw new System.ArgumentException("Undefined robot type, must define type!");
Movement = new DevMovement(com); }
Timer timer = new Timer(TimerCallback); if(type == RobotTypes.Mobile)
timer.Change(2000, 10000); {
//Buzzer = new DevBuzzer(Com);
Battery = new DevBattery(Com);
LineSensor = new DevLineSensor(com);
Movement = new DevMovement(com);
}
else if(type == RobotTypes.Stationary)
{
SplitFlap = new DevSplitFlap(com);
}
Timer timer = new Timer
{
Interval = 10000
};
timer.Enabled= true;
timer.Elapsed += Timer_Elapsed;
} }
public IPublisherSubscriber Com { get; } public IPublisherSubscriber Com { get; }
public RobotTypes Type { get; }
//public DevBuzzer Buzzer { get; } //public DevBuzzer Buzzer { get; }
public DevBattery Battery { get; } public DevBattery Battery { get; }
@ -39,13 +56,12 @@ namespace RobotLib
//Com.Disconnect(); //Com.Disconnect();
} }
private void TimerCallback(object state) private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{ {
if (Com.IsConnected) if (Com.IsConnected)
{ {
Battery.Refresh(); Battery?.RequestBatteryVoltage();
} }
} }
} }
} }

@ -0,0 +1,9 @@
namespace RobotLib
{
public enum RobotTypes
{
Undefined = 0,
Mobile = 1,
Stationary
}
}
Loading…
Cancel
Save