|
|
|
|
@ -2,13 +2,12 @@ |
|
|
|
|
using System.Text; |
|
|
|
|
using M2Mqtt; |
|
|
|
|
using M2Mqtt.Messages; |
|
|
|
|
using Swan.Formatters; |
|
|
|
|
using System.Text.Json; |
|
|
|
|
|
|
|
|
|
namespace RaspiControl { |
|
|
|
|
class Programm { |
|
|
|
|
private static MqttClient client; |
|
|
|
|
private static Navigation navigation; |
|
|
|
|
private static Joystick joystick; |
|
|
|
|
|
|
|
|
|
static void Main(string[] args) { |
|
|
|
|
try { |
|
|
|
|
client = new MqttClient("localhost"); |
|
|
|
|
@ -16,8 +15,7 @@ namespace RaspiControl { |
|
|
|
|
string clientId = Guid.NewGuid().ToString(); |
|
|
|
|
client.Connect(clientId); |
|
|
|
|
client.Subscribe(new string[] { "APROG/REQUEST" }, new byte[] { MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE }); |
|
|
|
|
navigation= new Navigation(); |
|
|
|
|
joystick= new Joystick(); |
|
|
|
|
Joystick joystick = new Joystick(); |
|
|
|
|
joystick.JoystickChanged += Joystick_JoystickChanged; |
|
|
|
|
|
|
|
|
|
} catch (Exception ex) { |
|
|
|
|
@ -30,18 +28,19 @@ namespace RaspiControl { |
|
|
|
|
case JoystickButton.None: |
|
|
|
|
break; |
|
|
|
|
case JoystickButton.Left: |
|
|
|
|
client.Publish("mobile/cmd/nav/left", Encoding.UTF8.GetBytes($"{navigation.GetAngleLeftStep()}"), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); |
|
|
|
|
client.Publish(MqttConstants.MOBILE_NAV_TURN_TOPIC, Encoding.UTF8.GetBytes($"{NavigationConstants.TURN_ANGLE_LEFT}"), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); |
|
|
|
|
break; |
|
|
|
|
case JoystickButton.Right: |
|
|
|
|
client.Publish("mobile/cmd/nav/right", Encoding.UTF8.GetBytes($"{navigation.GetAngleRightStep()}"), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); |
|
|
|
|
client.Publish(MqttConstants.MOBILE_NAV_TURN_TOPIC, Encoding.UTF8.GetBytes($"{NavigationConstants.TURN_ANGLE_RIGHT}"), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); |
|
|
|
|
break; |
|
|
|
|
case JoystickButton.Up: |
|
|
|
|
client.Publish(MqttConstants.MOBILE_NAV_MOVE_TOPIC, Encoding.UTF8.GetBytes($"{NavigationConstants.SPEED_FORWARD}"), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); |
|
|
|
|
break; |
|
|
|
|
case JoystickButton.Down: |
|
|
|
|
client.Publish(MqttConstants.MOBILE_NAV_MOVE_TOPIC, Encoding.UTF8.GetBytes($"{NavigationConstants.SPEED_BACKWARD}"), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); |
|
|
|
|
break; |
|
|
|
|
case JoystickButton.Center: |
|
|
|
|
navigation.ResetAngle(); |
|
|
|
|
client.Publish("mobile/cmd/nav/drive", Encoding.UTF8.GetBytes("true"), MqttMsgBase.QOS_LEVEL_AT_MOST_ONCE, false); |
|
|
|
|
client.Publish(MqttConstants.MOBILE_NAV_STOP_TOPIC, Encoding.UTF8.GetBytes($"{NavigationConstants.STOP}"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -49,6 +48,10 @@ namespace RaspiControl { |
|
|
|
|
private static void Client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) { |
|
|
|
|
Console.Write(e.Topic + "\n"); |
|
|
|
|
Console.Write(Encoding.UTF8.GetString(e.Message) + "\n"); |
|
|
|
|
Dictionary<string,object> data = JsonSerializer.Deserialize<Dictionary<string, object>>(e.Message); |
|
|
|
|
foreach(KeyValuePair<string,object> entry in data) { |
|
|
|
|
Console.WriteLine(entry.Key+ ": " + entry.Value); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |