< Summary

Information
Class: LGDXRobotCloud.API.Services.Navigation.SlamService
Assembly: LGDXRobotCloud.API
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Services/Navigation/SlamService.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 45
Coverable lines: 45
Total lines: 74
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)0%2040%
StartSlamAsync()100%210%
StopSlamAsync()100%210%
UpdateSlamDataAsync()0%2040%
AddSlamCommandAsync()100%210%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.API/Services/Navigation/SlamService.cs

#LineLine coverage
 1using LGDXRobotCloud.API.Repositories;
 2using LGDXRobotCloud.Data.Models.Redis;
 3using LGDXRobotCloud.Protos;
 4using LGDXRobotCloud.Utilities.Enums;
 5
 6namespace LGDXRobotCloud.API.Services.Navigation;
 7
 8public interface ISlamService
 9{
 10  Task<bool> StartSlamAsync(Guid robotId);
 11  Task StopSlamAsync(Guid robotId);
 12
 13  // Client to Server
 14  Task UpdateSlamDataAsync(Guid robotId, RobotClientsSlamStatus status, RobotClientsMapData? mapData);
 15
 16  // Server to Client
 17  Task<bool> AddSlamCommandAsync(int realmId, RobotClientsSlamCommands commands);
 18}
 19
 020public class SlamService(
 021  ISlamDataRepository slamDataRepository,
 022  IRobotService robotService
 023) : ISlamService
 24{
 025  private readonly ISlamDataRepository _slamDataRepository = slamDataRepository ?? throw new ArgumentNullException(nameo
 026  private readonly IRobotService _robotService = robotService ?? throw new ArgumentNullException(nameof(robotService));
 27
 28  public async Task<bool> StartSlamAsync(Guid robotId)
 029  {
 030    var realmId = await _robotService.GetRobotRealmIdAsync(robotId) ?? 0;
 031    return await _slamDataRepository.StartSlamAsync(realmId, robotId);
 032  }
 33
 34  public async Task StopSlamAsync(Guid robotId)
 035  {
 036    var realmId = await _robotService.GetRobotRealmIdAsync(robotId) ?? 0;
 037    await _slamDataRepository.StopSlamAsync(realmId, robotId);
 038  }
 39
 40  public async Task UpdateSlamDataAsync(Guid robotId, RobotClientsSlamStatus status, RobotClientsMapData? mapData)
 041  {
 042    var realmId = await _robotService.GetRobotRealmIdAsync(robotId) ?? 0;
 043    MapData? map = null;
 044    if (mapData != null && mapData.Data.Count > 0)
 045    {
 046      map = new MapData
 047      {
 048        Resolution = mapData.Resolution,
 049        Width = mapData.Width,
 050        Height = mapData.Height,
 051        Origin = new RobotDof
 052        {
 053          X = mapData.Origin.X,
 054          Y = mapData.Origin.Y,
 055          Rotation = mapData.Origin.Rotation,
 056        },
 057        Data = [.. mapData.Data.Select(x => (short)x)]
 058      };
 059    }
 060    var data = new SlamData
 061    {
 062      RobotId = robotId,
 063      RealmId = realmId,
 064      SlamStatus = (SlamStatus)status,
 065      MapData = map
 066    };
 067    await _slamDataRepository.SetSlamExchangeAsync(realmId, data);
 068  }
 69
 70  public async Task<bool> AddSlamCommandAsync(int realmId, RobotClientsSlamCommands commands)
 071  {
 072    return await _slamDataRepository.AddSlamCommandAsync(realmId, commands);
 073  }
 74}