connection from bike/simulator to client to server
This commit is contained in:
@@ -92,12 +92,13 @@ namespace Client
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
||||
|
||||
}
|
||||
|
||||
private void OnWrite(IAsyncResult ar)
|
||||
{
|
||||
this.stream.EndWrite(ar);
|
||||
Console.WriteLine("wrote some stuff");
|
||||
}
|
||||
|
||||
#region interface
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Hardware;
|
||||
using Hardware.Simulators;
|
||||
using ProftaakRH;
|
||||
|
||||
namespace Client
|
||||
@@ -24,6 +25,11 @@ namespace Client
|
||||
BLEHandler bLEHandler = new BLEHandler(client);
|
||||
|
||||
bLEHandler.Connect();
|
||||
|
||||
//BikeSimulator bikeSimulator = new BikeSimulator(client);
|
||||
|
||||
//bikeSimulator.StartSimulation();
|
||||
|
||||
while (true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Threading;
|
||||
|
||||
namespace Hardware.Simulators
|
||||
{
|
||||
class BikeSimulator : IHandler
|
||||
public class BikeSimulator : IHandler
|
||||
{
|
||||
IDataReceiver dataReceiver;
|
||||
private int elapsedTime = 0;
|
||||
@@ -34,6 +34,7 @@ namespace Hardware.Simulators
|
||||
{
|
||||
this.dataReceiver = dataReceiver;
|
||||
}
|
||||
|
||||
public void StartSimulation()
|
||||
{
|
||||
//Example BLE Message
|
||||
|
||||
@@ -48,6 +48,7 @@ namespace Server
|
||||
{
|
||||
//message hasn't completely arrived yet
|
||||
this.bytesReceived += receivedBytes;
|
||||
Console.WriteLine("segmented message, {0} arrived", receivedBytes);
|
||||
this.stream.BeginRead(this.buffer, this.bytesReceived, this.buffer.Length - this.bytesReceived, new AsyncCallback(OnRead), null);
|
||||
|
||||
}
|
||||
@@ -58,10 +59,12 @@ namespace Server
|
||||
{
|
||||
Console.WriteLine("something has gone completely wrong");
|
||||
Console.WriteLine($"expected: {expectedMessageLength} bytesReceive: {bytesReceived} receivedBytes: {receivedBytes}");
|
||||
Console.WriteLine($"received WEIRD data {BitConverter.ToString(buffer.Take(receivedBytes).ToArray())} string {Encoding.ASCII.GetString(buffer.Take(receivedBytes).ToArray())}");
|
||||
|
||||
}
|
||||
else if (buffer[4] == 0x02)
|
||||
{
|
||||
Console.WriteLine($"received raw data {BitConverter.ToString(buffer.Skip(5).ToArray(), 16)}");
|
||||
Console.WriteLine($"received raw data {BitConverter.ToString(buffer.Skip(5).Take(expectedMessageLength).ToArray())}");
|
||||
}
|
||||
else if (buffer[4] == 0x01)
|
||||
{
|
||||
@@ -71,8 +74,12 @@ namespace Server
|
||||
Console.WriteLine(Encoding.ASCII.GetString(packet));
|
||||
HandleData(Encoding.ASCII.GetString(packet));
|
||||
}
|
||||
this.bytesReceived = 0;
|
||||
|
||||
}
|
||||
|
||||
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
||||
|
||||
}
|
||||
|
||||
private void HandleData(string packet)
|
||||
|
||||
Reference in New Issue
Block a user