Skip to content

Commit

Permalink
feat(AsvRsga): Remove frequency parameter from SetMode function
Browse files Browse the repository at this point in the history
The frequency parameter has been removed from the SetMode function within the AsvRsgaServerEx, IAsvRsgaServerEx, AsvRsgaClientEx, and IAsvRsgaClientEx files. The 'SetMode' calls have been adjusted accordingly to reflect this change with the updated delegate signature.
  • Loading branch information
asvol committed Jul 4, 2024
1 parent 98c5c7a commit 8b0d51c
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 49 deletions.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public Task RefreshInfo(CancellationToken cancel = default)
return Base.GetCompatibilities(cancel);
}

public async Task<MavResult> SetMode(AsvRsgaCustomMode mode, ulong frequencyHz, CancellationToken cancel = default)
public async Task<MavResult> SetMode(AsvRsgaCustomMode mode, CancellationToken cancel = default)
{
using var cs = CancellationTokenSource.CreateLinkedTokenSource(DisposeCancel, cancel);
var result = await _commandClient.CommandLong(item => RsgaHelper.SetArgsForSetMode(item, mode,frequencyHz),cs.Token).ConfigureAwait(false);
var result = await _commandClient.CommandLong(item => RsgaHelper.SetArgsForSetMode(item, mode),cs.Token).ConfigureAwait(false);
return result.Result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public interface IAsvRsgaClientEx
IAsvRsgaClient Base { get; }
IObservable<IChangeSet<AsvRsgaCustomMode>> AvailableModes { get; }
Task RefreshInfo(CancellationToken cancel = default);
Task<MavResult> SetMode(AsvRsgaCustomMode mode, ulong frequencyHz, CancellationToken cancel = default);
Task<MavResult> SetMode(AsvRsgaCustomMode mode, CancellationToken cancel = default);
}
15 changes: 6 additions & 9 deletions src/Asv.Mavlink/Microservices/AsvRsga/RsgaHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,25 @@ namespace Asv.Mavlink;

public class RsgaHelper
{
public static void SetArgsForSetMode(CommandLongPayload item, AsvRsgaCustomMode mode,ulong frequencyHz)
public static void SetArgsForSetMode(CommandLongPayload item, AsvRsgaCustomMode mode)
{
var freqArray = BitConverter.GetBytes(frequencyHz);

item.Command = (V2.Common.MavCmd)V2.AsvRsga.MavCmd.MavCmdAsvRsgaSetMode;
item.Param1 = BitConverter.ToSingle(BitConverter.GetBytes((uint)mode));
item.Param2 = BitConverter.ToSingle(freqArray, 0);
item.Param3 = BitConverter.ToSingle(freqArray, 4);
item.Param2 = float.NaN;
item.Param3 = float.NaN;
item.Param4 = float.NaN;
item.Param5 = float.NaN;
item.Param6 = float.NaN;
item.Param7 = float.NaN;
}

public static void GetArgsForSetMode(CommandLongPayload item, out AsvRsgaCustomMode mode, out ulong frequencyHz)
public static void GetArgsForSetMode(CommandLongPayload item, out AsvRsgaCustomMode mode)
{
if (item.Command != (V2.Common.MavCmd)V2.AsvRsga.MavCmd.MavCmdAsvRsgaSetMode)
throw new ArgumentException($"Command {item.Command:G} is not {V2.AsvRsga.MavCmd.MavCmdAsvRsgaSetMode:G}");
mode = (AsvRsgaCustomMode)BitConverter.ToUInt32(BitConverter.GetBytes(item.Param1));
var freqArray = new byte[8];
BitConverter.GetBytes(item.Param2).CopyTo(freqArray,0);
BitConverter.GetBytes(item.Param3).CopyTo(freqArray,4);
frequencyHz = BitConverter.ToUInt64(freqArray,0);

}

public static void SetSupportedModes(AsvRsgaCompatibilityResponsePayload payload, IEnumerable<AsvRsgaCustomMode> modes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public AsvRsgaServerEx(IAsvRsgaServer server, IStatusTextServer status, ICommand
{
if (SetMode == null) return new CommandResult(MavResult.MavResultUnsupported);
using var cs = CancellationTokenSource.CreateLinkedTokenSource(DisposeCancel, cancel);
RsgaHelper.GetArgsForSetMode(args.Payload, out var mode, out var freq);
var result = await SetMode(mode,freq, cs.Token).ConfigureAwait(false);
RsgaHelper.GetArgsForSetMode(args.Payload, out var mode);
var result = await SetMode(mode, cs.Token).ConfigureAwait(false);
return new CommandResult(result);
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Asv.Mavlink;

public delegate Task<MavResult> RsgaSetMode(AsvRsgaCustomMode mode, ulong freq, CancellationToken cancel = default);
public delegate Task<MavResult> RsgaSetMode(AsvRsgaCustomMode mode, CancellationToken cancel = default);
public delegate IEnumerable<AsvRsgaCustomMode> RsgaGetCompatibility();

public interface IAsvRsgaServerEx
Expand Down
36 changes: 2 additions & 34 deletions src/Asv.Mavlink/Protocol/Dialects/asv_rsga.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
<entry value="13400" name="MAV_CMD_ASV_RSGA_SET_MODE">
<description>Do set mode</description>
<param index="1">Mode (uint32_t, see ASV_RSGA_CUSTOM_MODE).</param>
<param index="2">Frequency in Hz, 0-3 bytes of uint_64, ignored for IDLE mode (uint32).</param>
<param index="3">Frequency in Hz, 4-7 bytes of uint_64, ignored for IDLE mode (uint32).</param>
<param index="2">Empty.</param>
<param index="3">Empty.</param>
<param index="4">Empty.</param>
<param index="5">Empty.</param>
<param index="6">Empty.</param>
Expand All @@ -87,39 +87,7 @@
<field type="uint16_t" name="request_id">Specifies the unique number of the original request. This allows the response to be matched to the correct request.</field>
<field type="uint8_t[32]" name="supported_modes">Supported modes. Each bit index represents an ASV_RSGA_CUSTOM_MODE value (256 bits). First (IDLE) bit always true.</field>
</message>
<!--
<message id="13400" name="ASV_RSGA_TX_LLZ_REQUEST">
<description>Requests device COMPATIBILITY. Returns ASV_RSGA_COMPATIBILITY_RESPONSE. [!WRAP_TO_V2_EXTENSION_PACKET!]</description>
<field type="uint8_t" name="target_system">System ID.</field>
<field type="uint8_t" name="target_component">Component ID.</field>
<field type="uint16_t" name="request_id">Specifies a unique number for this request. This allows the response packet to be identified.</field>
</message>
<message id="13400" name="ASV_RSGA_TX_LLZ_RESPONSE">
<description>Requests device COMPATIBILITY. Returns ASV_RSGA_COMPATIBILITY_RESPONSE. [!WRAP_TO_V2_EXTENSION_PACKET!]</description>
<field type="uint8_t" name="target_system">System ID.</field>
<field type="uint8_t" name="target_component">Component ID.</field>
<field type="uint16_t" name="request_id">Specifies a unique number for this request. This allows the response packet to be identified.</field>
</message>-->

<!--<message id="13402" name="ASV_RSGA_MODE_COMPATIBILITY_REQUEST">
<description>Requests device COMPATIBILITY specified for MODE. Returns ASV_RSGA_MODE_COMPATIBILITY_RESPONSE. [!WRAP_TO_V2_EXTENSION_PACKET!]</description>
<field type="uint8_t" name="target_system">System ID.</field>
<field type="uint8_t" name="target_component">Component ID.</field>
<field type="uint16_t" name="request_id">Specifies a unique number for this request. This allows the response packet to be identified.</field>
<field type="uint8_t" name="mode" enum="ASV_RSGA_CUSTOM_MODE">Specifies mode for request.</field>
</message>
<message id="13403" name="ASV_RSGA_MODE_COMPATIBILITY_RESPONSE">
<description>Responds to the ASV_RSGA_COMPATIBILITY_REQUEST. [!WRAP_TO_V2_EXTENSION_PACKET!]</description>
<field type="uint8_t" name="result" enum="ASV_RSGA_REQUEST_ACK">Result code.</field>
<field type="uint16_t" name="request_id">Specifies the unique number of the original request. This allows the response to be matched to the correct request.</field>
<field type="uint8_t" name="mode" enum="ASV_RSGA_CUSTOM_MODE">Specifies mode.</field>
<field type="uint8_t[32]" name="supported_params">Supported params. Each bit index represents an ASV_RSGA_PARAM_*[MODE] value (256 bits).</field>
<field type="uint8_t[32]" name="supported_rtt">Supported telemetry. Each bit index represents an ASV_RSGA_RTT_*[MODE] value (256 bits).</field>
</message>
<message id="13404" name="ASV_RSGA_PARAM_VALUE">
<description>Requests device COMPATIBILITY. Returns ASV_RSGA_COMPATIBILITY_RESPONSE. [!WRAP_TO_V2_EXTENSION_PACKET!]</description>
<field type="uint8_t" name="mode" enum="ASV_RSGA_CUSTOM_MODE">Specifies mode for request.</field>
</message>-->

</messages>
</mavlink>

0 comments on commit 8b0d51c

Please sign in to comment.