Skip to content
This repository has been archived by the owner on Oct 10, 2018. It is now read-only.

Commit

Permalink
Network fix + TODO: Deserialization fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfranz committed Mar 25, 2018
1 parent 95ed614 commit d627866
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions AnnelidaDispatcher/Model/DispatcherServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,15 @@ public void ReadHandler(IAsyncResult ar)
else
{
state.RecvBytesCount += bytesRead;

if (state.RecvBytesCount < state.BufferSize)
handler.BeginReceive(state.Buffer, 4 + state.RecvBytesCount - 1, state.BufferSize, 0,
ReadHandler, state);
{
var revLeft = state.BufferSize - state.RecvBytesCount;

handler.BeginReceive(state.Buffer, 4 + state.RecvBytesCount - 1,
revLeft, 0,
ReadHandler, state);
}
else
{
HandleMessage(state.Buffer, state);
Expand Down Expand Up @@ -237,6 +243,8 @@ public void HandleMessage(byte[] bytes, DispatcherClientObject state)
case ClientTypes.Types.Robot:
//Save to sensor DB async
var deserializedDocument = ProcessSerializedBson(bytes);
if(deserializedDocument == null)
return;
var t = deserializedDocument["timestamp"].ToUniversalTime();

//Send data to DB in batches of 1s
Expand Down Expand Up @@ -303,10 +311,20 @@ private void NotifyNetworkViewListeners(ClientTypes.Types sender, byte[] documen

private static BsonDocument ProcessSerializedBson(byte[] bytes)
{
var doc = BsonSerializer.Deserialize<BsonDocument>(bytes);
BsonDateTime timestamp = DateTime.UtcNow;
doc["timestamp"] = timestamp;
return doc;
try
{
var doc = BsonSerializer.Deserialize<BsonDocument>(bytes);
BsonDateTime timestamp = DateTime.UtcNow;
doc["timestamp"] = timestamp;
return doc;
}
catch (Exception e)
{
Console.WriteLine(e);
return null;
}


}

}
Expand Down

0 comments on commit d627866

Please sign in to comment.