Skip to content

Commit

Permalink
Added WrapToV2Extension for code-generator
Browse files Browse the repository at this point in the history
Devices in network could not understand unknown messages (cause mavlink/mavlink#1166) and will not forwarding it.
This flag indicates that the message is not standard and we need to wrap this message into a V2_EXTENSION message for the routers to successfully transmit over the network.
  • Loading branch information
asvol committed Apr 22, 2023
1 parent 121540d commit f5fe903
Show file tree
Hide file tree
Showing 38 changed files with 610 additions and 184 deletions.
82 changes: 41 additions & 41 deletions mavlink_messages/asv_sdr.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Asv.Mavlink.Shell/CodeGen/Generator/LiquidGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public string Generate(string template, MavlinkProtocolModel model)
HasArrayFields = msg.HasArrayFields,
PayloadByteSize = msg.GetAllFields().Sum(_=>_.FieldByteSize),
ExtendedFieldsLength = msg.ExtendedFields.Sum(_=>_.FieldByteSize),
WrapToV2Extension = msg.WrapToV2Extension,
Fields = msg.GetAllFields().Select(field =>
new
{
Expand Down
3 changes: 2 additions & 1 deletion src/Asv.Mavlink.Shell/CodeGen/Model/MavlinkMessageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class MavlinkMessageModel: MavlinkModelBase
public IList<MessageFieldModel> ExtendedFields { get; set; } = new List<MessageFieldModel>();

public bool HasArrayFields => Fields.Any(_ => _.IsArray) || ExtendedFields.Any(_=>_.IsArray);

public bool WrapToV2Extension { get; set; }

public override string ToString()
{
return $"{Name}[Id:{Id},CrcExtra:{CrcExtra}]";
Expand Down
5 changes: 4 additions & 1 deletion src/Asv.Mavlink.Shell/CodeGen/Parsers/MavlinkParserXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private static void ParseMessagesSection(XmlReader rdr, IList<MavlinkMessageMode
{
Id = int.Parse(rdr.GetAttribute("id")),
Name = rdr.GetAttribute("name"),

};
protocolEnums.Add(messageItem);
ParseMessage(rdr, messageItem);
Expand All @@ -73,7 +74,9 @@ private static void ParseMessage(XmlReader rdr, MavlinkMessageModel messageItem)
switch (rdr.Name)
{
case "description":
messageItem.Desc = ConvertDesc(rdr.ReadElementContentAsString());
var content = rdr.ReadElementContentAsString();
messageItem.Desc = ConvertDesc(content);
messageItem.WrapToV2Extension = content.Contains("[!WRAP_TO_V2_EXTENSION_PACKET!]");
break;
case "field":
ParseMessageFields(rdr, messageItem, extendedFields);
Expand Down
1 change: 1 addition & 0 deletions src/Asv.Mavlink.Shell/Resources/csharp.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace Asv.Mavlink.V2.{{ Namespace }}
public const int PacketMessageId = {{ msg.Id }};
public override int MessageId => PacketMessageId;
public override byte GetCrcEtra() => {{ msg.CrcExtra }};
public override bool WrapToV2Extension => {{ msg.WrapToV2Extension }};

public override {{ msg.CamelCaseName }}Payload Payload { get; } = new {{ msg.CamelCaseName }}Payload();

Expand Down
29 changes: 19 additions & 10 deletions src/Asv.Mavlink.Test/Devices/Base/BaseDevicesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public BaseDevicesTest(ITestOutputHelper output)
}

[Fact]
public async Task ClientDeviceIdentityArgumentNullExceptionTest()
public Task ClientDeviceIdentityArgumentNullExceptionTest()
{
Assert.Throws<ArgumentNullException>(() =>
{
Expand All @@ -34,10 +34,11 @@ public async Task ClientDeviceIdentityArgumentNullExceptionTest()
new PacketSequenceCalculator(),
Scheduler.Default);
});
return Task.CompletedTask;
}

[Fact]
public async Task ClientDeviceConfigArgumentNullExceptionTest()
public Task ClientDeviceConfigArgumentNullExceptionTest()
{
Assert.Throws<ArgumentNullException>(() =>
{
Expand All @@ -52,10 +53,11 @@ public async Task ClientDeviceConfigArgumentNullExceptionTest()
new PacketSequenceCalculator(),
Scheduler.Default);
});
return Task.CompletedTask;
}

[Fact]
public async Task ClientDeviceVirtualLinkArgumentNullExceptionTest()
public Task ClientDeviceVirtualLinkArgumentNullExceptionTest()
{
Assert.Throws<ArgumentNullException>(() =>
{
Expand All @@ -68,10 +70,11 @@ public async Task ClientDeviceVirtualLinkArgumentNullExceptionTest()
new PacketSequenceCalculator(),
Scheduler.Default);
});
return Task.CompletedTask;
}

[Fact]
public async Task ServerDeviceVirtualLinkArgumentNullExceptionTest()
public Task ServerDeviceVirtualLinkArgumentNullExceptionTest()
{
Assert.Throws<ArgumentNullException>(() =>
{
Expand All @@ -81,10 +84,11 @@ public async Task ServerDeviceVirtualLinkArgumentNullExceptionTest()
new ServerDeviceConfig(),
Scheduler.Default);
});
return Task.CompletedTask;
}

[Fact]
public async Task ServerDeviceSequenceArgumentNullExceptionTest()
public Task ServerDeviceSequenceArgumentNullExceptionTest()
{
Assert.Throws<ArgumentNullException>(() =>
{
Expand All @@ -96,10 +100,11 @@ public async Task ServerDeviceSequenceArgumentNullExceptionTest()
new ServerDeviceConfig(),
Scheduler.Default);
});
return Task.CompletedTask;
}

[Fact]
public async Task ServerDeviceIdentityArgumentNullExceptionTest()
public Task ServerDeviceIdentityArgumentNullExceptionTest()
{
Assert.Throws<ArgumentNullException>(() =>
{
Expand All @@ -111,6 +116,7 @@ public async Task ServerDeviceIdentityArgumentNullExceptionTest()
new ServerDeviceConfig(),
Scheduler.Default);
});
return Task.CompletedTask;
}

// [Fact]
Expand All @@ -132,7 +138,7 @@ public async Task ServerDeviceIdentityArgumentNullExceptionTest()
// }

[Fact]
public async Task ServerDeviceConfigStatusTextArgumentNullExceptionTest()
public Task ServerDeviceConfigStatusTextArgumentNullExceptionTest()
{
Assert.Throws<ArgumentNullException>(() =>
{
Expand All @@ -147,10 +153,11 @@ public async Task ServerDeviceConfigStatusTextArgumentNullExceptionTest()
},
Scheduler.Default);
});
return Task.CompletedTask;
}

[Fact]
public async Task ServerDeviceSchedulerArgumentNullExceptionTest()
public void ServerDeviceSchedulerArgumentNullExceptionTest()
{
Assert.Throws<ArgumentNullException>(() =>
{
Expand All @@ -162,10 +169,11 @@ public async Task ServerDeviceSchedulerArgumentNullExceptionTest()
new ServerDeviceConfig(),
null);
});

}

[Fact]
public async Task ClientDeviceSequenceArgumentNullExceptionTest()
public void ClientDeviceSequenceArgumentNullExceptionTest()
{
Assert.Throws<ArgumentNullException>(() =>
{
Expand All @@ -180,7 +188,7 @@ public async Task ClientDeviceSequenceArgumentNullExceptionTest()
}

[Fact]
public async Task ClientDeviceSchedulerArgumentNullExceptionTest()
public void ClientDeviceSchedulerArgumentNullExceptionTest()
{
Assert.Throws<ArgumentNullException>(() =>
{
Expand All @@ -192,6 +200,7 @@ public async Task ClientDeviceSchedulerArgumentNullExceptionTest()
new PacketSequenceCalculator(),
null);
});

}

[Theory]
Expand Down
2 changes: 1 addition & 1 deletion src/Asv.Mavlink.Test/MavlinkPackets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public MavlinkPackets(ITestOutputHelper output)
IncompatFlags = 0,
Sequence = 10,
SystemId = 255,
ComponenId = 255,
ComponentId = 255,
Payload =
{
U64 = 1,
Expand Down
2 changes: 1 addition & 1 deletion src/Asv.Mavlink/Asv.Mavlink.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<DocumentationFile>bin\Release\Asv.Mavlink.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Asv.Common" Version="1.6.1" />
<PackageReference Include="Asv.Common" Version="1.7.0" />
<PackageReference Include="Asv.IO" Version="1.6.1" />
<PackageReference Include="DynamicData" Version="7.10.2" />
<PackageReference Include="Geodesy" Version="4.1.0" />
Expand Down
2 changes: 2 additions & 0 deletions src/Asv.Mavlink/Microservices/AsvSdr/RecordId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Asv.Mavlink;

public class RecordId:IEquatable<RecordId>
{
public static RecordId Empty { get; } = new("NOT_RECORDED");

public RecordId(string name)
{
SdrWellKnown.CheckRecordName(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected CommandServerEx(ICommandServer server, IObservable<TArgPacket> command

private async void OnRequest(TArgPacket pkt)
{
var requester = new DeviceIdentity() { ComponentId = pkt.ComponenId, SystemId = pkt.SystemId };
var requester = new DeviceIdentity() { ComponentId = pkt.ComponentId, SystemId = pkt.SystemId };
var cmd = _cmdGetter(pkt);

var confirmation = _confirmationGetter(pkt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public static class CommandServerHelper
{
public static Task SendCommandAckAccepted(this ICommandServer server, CommandIntPacket req, MavResult result, CancellationToken cancel = default)
{
return server.SendCommandAck(req.Payload.Command, new DeviceIdentity(req.SystemId,req.ComponenId), new CommandResult(result), cancel);
return server.SendCommandAck(req.Payload.Command, new DeviceIdentity(req.SystemId,req.ComponentId), new CommandResult(result), cancel);
}
public static Task SendCommandAckAccepted(this ICommandServer server, CommandLongPacket req, MavResult result, CancellationToken cancel = default)
{
return server.SendCommandAck(req.Payload.Command, new DeviceIdentity(req.SystemId,req.ComponenId), new CommandResult(result), cancel);
return server.SendCommandAck(req.Payload.Command, new DeviceIdentity(req.SystemId,req.ComponentId), new CommandResult(result), cancel);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Asv.Mavlink/Microservices/DebugSvc/Server/DebugServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Task SendDebugFloatArray(string name, ushort arrayId, float[] data)

var packet = new DebugFloatArrayPacket()
{
ComponenId = _identity.ComponentId,
ComponentId = _identity.ComponentId,
SystemId = _identity.SystemId,
CompatFlags = 0,
IncompatFlags = 0,
Expand All @@ -75,7 +75,7 @@ public Task SendMemoryVect(ushort address, byte version, byte type, sbyte[] valu
}
var packet = new MemoryVectPacket
{
ComponenId = _identity.ComponentId,
ComponentId = _identity.ComponentId,
SystemId = _identity.SystemId,
CompatFlags = 0,
IncompatFlags = 0,
Expand All @@ -100,7 +100,7 @@ public Task SendNamedValueFloat(string name, float value)

var packet = new NamedValueFloatPacket
{
ComponenId = _identity.ComponentId,
ComponentId = _identity.ComponentId,
SystemId = _identity.SystemId,
CompatFlags = 0,
IncompatFlags = 0,
Expand All @@ -124,7 +124,7 @@ public Task SendNamedValueInteger(string name, int value)

var packet = new NamedValueIntPacket()
{
ComponenId = _identity.ComponentId,
ComponentId = _identity.ComponentId,
SystemId = _identity.SystemId,
CompatFlags = 0,
IncompatFlags = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Task SendLoggingData(byte targetSystemId, byte targetComponentId, ushort

var packet = new LoggingDataPacket
{
ComponenId = _identity.ComponentId,
ComponentId = _identity.ComponentId,
SystemId = _identity.SystemId,
CompatFlags = 0,
IncompatFlags = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/Asv.Mavlink/Microservices/MavlinkHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static IObservable<IPacketV2<IPayload>> FilterVehicle(this IObservable<IP
public static bool FilterVehicle(IPacketV2<IPayload> packetV2, byte targetSystemId, byte targetComponentId)
{
if (targetSystemId != 0 && targetSystemId != packetV2.SystemId) return false;
if (targetComponentId != 0 && targetComponentId != packetV2.ComponenId) return false;
if (targetComponentId != 0 && targetComponentId != packetV2.ComponentId) return false;
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Asv.Mavlink/Microservices/MavlinkMicroserviceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected IObservable<TPacket> InternalFilter<TPacket>(Func<TPacket, bool> filte
private bool FilterVehicle(IPacketV2<IPayload> packetV2)
{
if (Identity.TargetSystemId != packetV2.SystemId) return false;
if (Identity.TargetComponentId != packetV2.ComponenId) return false;
if (Identity.TargetComponentId != packetV2.ComponentId) return false;
return true;
}
protected MavlinkClientIdentity Identity { get; }
Expand All @@ -89,7 +89,7 @@ protected TPacket InternalGeneratePacket<TPacket>()
{
return new TPacket
{
ComponenId = Identity.ComponentId,
ComponentId = Identity.ComponentId,
SystemId = Identity.SystemId,
Sequence = Sequence.GetNextSequenceNumber(),
};
Expand Down
6 changes: 3 additions & 3 deletions src/Asv.Mavlink/Microservices/MavlinkMicroserviceServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private TPacket InternalGeneratePacket<TPacket>()
{
return new TPacket
{
ComponenId = Identity.ComponentId,
ComponentId = Identity.ComponentId,
SystemId = Identity.SystemId,
Sequence = PacketSequence.GetNextSequenceNumber(),
};
Expand All @@ -79,7 +79,7 @@ private TPacket InternalGeneratePacket<TPacket>()
protected IPacketV2<IPayload> InternalGeneratePacket(int messageId, bool incrementSequence = true)
{
var pkt = Connection.CreatePacketByMessageId(messageId);
pkt.ComponenId = Identity.ComponentId;
pkt.ComponentId = Identity.ComponentId;
pkt.SystemId = Identity.SystemId;
if (incrementSequence)
{
Expand All @@ -92,7 +92,7 @@ protected IPacketV2<IPayload> InternalGeneratePacket(int messageId, bool increme
protected Task InternalSend(int messageId, Action<IPacketV2<IPayload>> fillPacket, CancellationToken cancel = default)
{
var pkt = Connection.CreatePacketByMessageId(messageId);
pkt.ComponenId = Identity.ComponentId;
pkt.ComponentId = Identity.ComponentId;
pkt.SystemId = Identity.SystemId;
pkt.Sequence = PacketSequence.GetNextSequenceNumber();
return Connection.Send(pkt, cancel);
Expand Down
2 changes: 1 addition & 1 deletion src/Asv.Mavlink/Microservices/MavlinkPacketTransponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public MavlinkPacketTransponder(IMavlinkV2Connection connection, MavlinkServerId
{
CompatFlags = 0,
IncompatFlags = 0,
ComponenId = _identityConfig.ComponentId,
ComponentId = _identityConfig.ComponentId,
SystemId = _identityConfig.SystemId,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task SendData(byte targetSystemId,byte targetComponentId,byte targe
using var linked = CancellationTokenSource.CreateLinkedTokenSource(_disposeCancel.Token, cancel);
await _connection.Send(new V2ExtensionPacket
{
ComponenId = _identity.ComponentId,
ComponentId = _identity.ComponentId,
SystemId = _identity.SystemId,
CompatFlags = 0,
IncompatFlags = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/Asv.Mavlink/Protocol/Frames/IPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IPacket<out TPayload>: ISpanSerializable
/// <summary>
/// ID of the message sender component
/// </summary>
byte ComponenId { get; set; }
byte ComponentId { get; set; }
/// <summary>
/// Message Id
/// </summary>
Expand Down
6 changes: 5 additions & 1 deletion src/Asv.Mavlink/Protocol/Frames/v2/IPacketV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public interface IPacketV2<out TPayload>:IPacket<TPayload>
/// Message name
/// </summary>
string Name { get; }

/// <summary>
/// Devices in network could not understand unknown messages (cause https://github.com/mavlink/mavlink/issues/1166) and will not forwarding it.
/// This flag indicates that the message is not standard and we need to wrap this message into a V2_EXTENSION message for the routers to successfully transmit over the network.
/// </summary>
bool WrapToV2Extension { get; }

}
}
Loading

0 comments on commit f5fe903

Please sign in to comment.