Update Broker

This commit is contained in:
2019-04-24 23:14:10 +02:00
parent 0f91751087
commit ab85e78f4c
7 changed files with 87 additions and 7 deletions

View File

@@ -34,9 +34,20 @@ namespace PlantBox.Broker
protected override void HistoricCommand(CommandStream commandStream, CommandPacket packet)
{
double[] FillArray(double[] values, int length)
{
var array = new double[length];
int startIndex = length - values.Length;
values.CopyTo(array, startIndex);
return array;
}
HistoricRequest historicRequest = new HistoricRequest().Deserialize(packet.Arguments);
ulong id = packet.ID;
PlantBox plantBox = Broker.PlantBoxesManager[id];
int count = historicRequest.Number;
if (plantBox == null)
{
@@ -70,9 +81,9 @@ namespace PlantBox.Broker
var response = new HistoricResponse
(
DateTime.Now - plantBox.LastMeasureDate,
captorsValues.Select(x => x.Humidity).ToArray(),
captorsValues.Select(x => x.Luminosity).ToArray(),
captorsValues.Select(x => x.Temperature).ToArray()
FillArray(captorsValues.Select(x => x.Humidity).ToArray(), count),
FillArray(captorsValues.Select(x => x.Luminosity).ToArray(), count),
FillArray(captorsValues.Select(x => x.Temperature).ToArray(), count)
);
commandStream.Send(response.ToCommandPacket(id));
}