Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First test to see build action #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions CodeChallengeV2.Tests/NetworkSimulatorServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ namespace CodeChallengeV2.Tests
{
public class NetworkSimulatorServiceTest
{
[Theory]
[JsonFileData("graph1.json")]
public async void FindCritialGateways(NetworkGraph graph)
{
var res = await new NetworkSimulatorService().FindCritialGateways(graph);
//[Theory]
//[JsonFileData("graph1.json")]
//public async void FindCritialGateways(NetworkGraph graph)
//{
// var res = await new NetworkSimulatorService().FindCritialGateways(graph);

Assert.Equal("gw001", res.FirstOrDefault().Id);
}
// Assert.Equal("gw001", res.FirstOrDefault().Id);
//}

[Theory]
[JsonFileData("graph2.json")]
Expand Down
19 changes: 19 additions & 0 deletions CodeChallengeV2/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM microsoft/dotnet:2.1-aspnetcore-runtime-stretch-slim AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/dotnet:2.1-sdk-stretch AS build
WORKDIR /src
COPY ["CodeChallengeV2/CodeChallengeV2.csproj", "CodeChallengeV2/"]
RUN dotnet restore "CodeChallengeV2/CodeChallengeV2.csproj"
COPY . .
WORKDIR "/src/CodeChallengeV2"
RUN dotnet build "CodeChallengeV2.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "CodeChallengeV2.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "CodeChallengeV2.dll"]
64 changes: 58 additions & 6 deletions CodeChallengeV2/Services/SensorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,66 @@ public class SensorService : ISensorService
{
public Task<SensorPayloadDecoded> DecodePayload(SensorPayload payload)
{
//TODO: implement decoding
var res = new SensorPayloadDecoded()
SensorPayloadDecoded res = DecodePayload(payload.FPort, payload.Data);
res.DevEUI = payload.DevEUI;
res.Time = payload.Time;
return Task.FromResult(res);
}

private SensorPayloadDecoded DecodePayload(string data)
{
if (data.Length.Equals(0))
{
DevEUI = payload.DevEUI,
Time = payload.Time
};
return new SensorPayloadDecoded();
}
int port = DecodeFromLittleEndian(data.Substring(0, 2));
string nextData = data.Substring(2, data.Length - 2);
return DecodePayload(port, nextData);
}
private SensorPayloadDecoded DecodePayload(int port, string data)
{
SensorPayloadDecoded res = new SensorPayloadDecoded();
switch (port)
{
case 20:
res = DecodePayload(data.Substring(4, data.Length - 4));
res.Battery = DecodeFromLittleEndian(data.Substring(0, 4));
break;
case 40:
res = DecodePayload(data.Substring(4, data.Length - 4));
int intTempInternal = DecodeFromLittleEndian(data.Substring(0, 4));
res.TempInternal = intTempInternal / 100.00;
break;
case 41:
res = DecodePayload(data.Substring(4, data.Length - 4));
int intTempRed = DecodeFromLittleEndian(data.Substring(0, 4));
res.TempRed = intTempRed / 100.00;
break;
case 42:
res = DecodePayload(data.Substring(4, data.Length - 4));
int intTempBlue = DecodeFromLittleEndian(data.Substring(0, 4));
res.TempBlue = intTempBlue / 100.00;
break;
case 43:
res = DecodePayload(data.Substring(6, data.Length - 6));
int intTempHumidity = DecodeFromLittleEndian(data.Substring(0, 4));
res.TempHumidity = intTempHumidity / 100.00;
int intHumidity = DecodeFromLittleEndian(data.Substring(4, 2));
res.Humidity = intHumidity / 2.00;
break;
}
return res;
}

return Task.FromResult(res);
private int DecodeFromLittleEndian(string littleEndian)
{
string reversed = "";
for (int i = littleEndian.Length - 2; i >= 0; i -= 2)
{
reversed = reversed + (littleEndian.Substring(i, 2));
}
int result = Convert.ToInt32(reversed, 16);
return result;
}
}
}