Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e93d6c834b |
134
Client/Client.cs
134
Client/Client.cs
@@ -1,134 +0,0 @@
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
using ProftaakRH;
|
||||
|
||||
namespace Client
|
||||
{
|
||||
class Client : IDataReceiver
|
||||
{
|
||||
private TcpClient client;
|
||||
private NetworkStream stream;
|
||||
private byte[] buffer = new byte[1024];
|
||||
private int bytesReceived;
|
||||
private bool connected;
|
||||
private byte clientId = 0;
|
||||
|
||||
|
||||
public Client() : this("localhost", 5555)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Client(string adress, int port)
|
||||
{
|
||||
this.client = new TcpClient();
|
||||
this.bytesReceived = 0;
|
||||
this.connected = false;
|
||||
client.BeginConnect(adress, port, new AsyncCallback(OnConnect), null);
|
||||
}
|
||||
|
||||
private void OnConnect(IAsyncResult ar)
|
||||
{
|
||||
this.client.EndConnect(ar);
|
||||
Console.WriteLine("Verbonden!");
|
||||
|
||||
|
||||
this.stream = this.client.GetStream();
|
||||
|
||||
//TODO File in lezen
|
||||
Console.WriteLine("enter username");
|
||||
string username = Console.ReadLine();
|
||||
Console.WriteLine("enter password");
|
||||
string password = Console.ReadLine();
|
||||
|
||||
byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(username, password), this.clientId);
|
||||
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
|
||||
this.stream.BeginRead(this.buffer, 0, this.buffer.Length, new AsyncCallback(OnRead), null);
|
||||
|
||||
//TODO lees OK message
|
||||
//temp moet eigenlijk een ok bericht ontvangen
|
||||
this.connected = true;
|
||||
}
|
||||
|
||||
private void OnRead(IAsyncResult ar)
|
||||
{
|
||||
int receivedBytes = this.stream.EndRead(ar);
|
||||
byte[] lengthBytes = new byte[4];
|
||||
|
||||
Array.Copy(this.buffer, 0, lengthBytes, 0, 4);
|
||||
|
||||
int expectedMessageLength = BitConverter.ToInt32(lengthBytes);
|
||||
|
||||
if (expectedMessageLength > this.buffer.Length)
|
||||
{
|
||||
throw new OutOfMemoryException("buffer to small");
|
||||
}
|
||||
|
||||
if (expectedMessageLength > this.bytesReceived + receivedBytes)
|
||||
{
|
||||
//message hasn't completely arrived yet
|
||||
this.bytesReceived += receivedBytes;
|
||||
this.stream.BeginRead(this.buffer, this.bytesReceived, this.buffer.Length - this.bytesReceived, new AsyncCallback(OnRead), null);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//message completely arrived
|
||||
if (expectedMessageLength != this.bytesReceived + receivedBytes)
|
||||
{
|
||||
Console.WriteLine("something has gone completely wrong");
|
||||
}
|
||||
|
||||
string identifier;
|
||||
bool isJson = DataParser.getJsonIdentifier(this.buffer, out identifier);
|
||||
if (isJson)
|
||||
{
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
else if (DataParser.isRawData(this.buffer))
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
#region interface
|
||||
//maybe move this to other place
|
||||
public void BPM(byte[] bytes)
|
||||
{
|
||||
if (bytes == null)
|
||||
{
|
||||
throw new ArgumentNullException("no bytes");
|
||||
}
|
||||
byte[] message = DataParser.GetRawDataMessage(bytes, clientId);
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
public void Bike(byte[] bytes)
|
||||
{
|
||||
if (bytes == null)
|
||||
{
|
||||
throw new ArgumentNullException("no bytes");
|
||||
}
|
||||
byte[] message = DataParser.GetRawDataMessage(bytes, clientId);
|
||||
this.stream.BeginWrite(message, 0, message.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public bool IsConnected()
|
||||
{
|
||||
return this.connected;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Message\Message.csproj" />
|
||||
<ProjectReference Include="..\ProftaakRH\ProftaakRH.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,126 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Client
|
||||
{
|
||||
public class DataParser
|
||||
{
|
||||
/// <summary>
|
||||
/// makes the json object with LOGIN identifier and username and password
|
||||
/// </summary>
|
||||
/// <param name="mUsername">username</param>
|
||||
/// <param name="mPassword">password</param>
|
||||
/// <returns>json object to ASCII to bytes</returns>
|
||||
public static byte[] GetLoginJson(string mUsername, string mPassword)
|
||||
{
|
||||
dynamic json = new
|
||||
{
|
||||
identifier = "LOGIN",
|
||||
data = new
|
||||
{
|
||||
username = mUsername,
|
||||
password = mPassword,
|
||||
}
|
||||
};
|
||||
|
||||
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get the identifier from json
|
||||
/// </summary>
|
||||
/// <param name="bytes">json in ASCII</param>
|
||||
/// <param name="identifier">gets the identifier</param>
|
||||
/// <returns>if it sucseeded</returns>
|
||||
public static bool getJsonIdentifier(byte[] bytes, out string identifier)
|
||||
{
|
||||
if (bytes.Length <= 6)
|
||||
{
|
||||
throw new ArgumentException("bytes to short");
|
||||
}
|
||||
byte messageId = bytes[4];
|
||||
|
||||
if (messageId == 1)
|
||||
{
|
||||
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(bytes.Skip(6).ToArray()));
|
||||
identifier = json.identifier;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
identifier = "";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// checks if the de message is raw data according to the protocol
|
||||
/// </summary>
|
||||
/// <param name="bytes">message</param>
|
||||
/// <returns>if message contains raw data</returns>
|
||||
public static bool isRawData(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length <= 6)
|
||||
{
|
||||
throw new ArgumentException("bytes to short");
|
||||
}
|
||||
return bytes[4] == 0x02;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructs a message with the payload, messageId and clientId
|
||||
/// </summary>
|
||||
/// <param name="payload"></param>
|
||||
/// <param name="messageId"></param>
|
||||
/// <param name="clientId"></param>
|
||||
/// <returns>the message ready for sending</returns>
|
||||
public static byte[] getMessage(byte[] payload, byte messageId, byte clientId)
|
||||
{
|
||||
byte[] res = new byte[payload.Length + 6];
|
||||
|
||||
Array.Copy(BitConverter.GetBytes(payload.Length + 6), 0, res, 0, 4);
|
||||
res[4] = messageId;
|
||||
res[5] = clientId;
|
||||
Array.Copy(payload, 0, res, 6, payload.Length);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructs a message with the payload and clientId and assumes the payload is raw data
|
||||
/// </summary>
|
||||
/// <param name="payload"></param>
|
||||
/// <param name="clientId"></param>
|
||||
/// <returns>the message ready for sending</returns>
|
||||
public static byte[] GetRawDataMessage(byte[] payload, byte clientId)
|
||||
{
|
||||
return getMessage(payload, 0x02, clientId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructs a message with the payload and clientId and assumes the payload is json
|
||||
/// </summary>
|
||||
/// <param name="payload"></param>
|
||||
/// <param name="clientId"></param>
|
||||
/// <returns>the message ready for sending</returns>
|
||||
public static byte[] getJsonMessage(byte[] payload, byte clientId)
|
||||
{
|
||||
return getMessage(payload, 0x01, clientId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructs a message with the message and clientId
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="clientId"></param>
|
||||
/// <returns>the message ready for sending</returns>
|
||||
public static byte[] getJsonMessage(string message, byte clientId)
|
||||
{
|
||||
return getJsonMessage(Encoding.ASCII.GetBytes(message), clientId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using Hardware;
|
||||
|
||||
namespace Client
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
//connect fiets?
|
||||
|
||||
|
||||
Client client = new Client();
|
||||
|
||||
|
||||
while (!client.IsConnected())
|
||||
{
|
||||
|
||||
}
|
||||
BLEHandler bLEHandler = new BLEHandler(client);
|
||||
|
||||
bLEHandler.Connect();
|
||||
|
||||
//BikeSimulator bikeSimulator = new BikeSimulator(client);
|
||||
|
||||
//bikeSimulator.StartSimulation();
|
||||
|
||||
while (true)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
|
||||
namespace Message
|
||||
{
|
||||
/// <summary>
|
||||
/// Message class to handle traffic between clients and server
|
||||
/// </summary>
|
||||
public class Message
|
||||
{
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// identifier for the message
|
||||
/// </summary>
|
||||
public Identifier Identifier
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// payload of the message, the actual text
|
||||
/// </summary>
|
||||
public string Payload
|
||||
{
|
||||
get;set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructs a new message with the given parameters
|
||||
/// </summary>
|
||||
/// <param name="identifier">the identifier</param>
|
||||
/// <param name="payload">the payload</param>
|
||||
public Message(Identifier identifier, string payload)
|
||||
{
|
||||
this.Identifier = identifier;
|
||||
this.Payload = payload;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// serializes this object to a JSON string
|
||||
/// </summary>
|
||||
/// <returns>a JSON representation of this object</returns>
|
||||
public string Serialize()
|
||||
{
|
||||
return JsonConvert.SerializeObject(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// deserializes a JSON string into a new Message object
|
||||
/// </summary>
|
||||
/// <param name="json">the JSON string to deserialize</param>
|
||||
/// <returns>a new <c>Message</c> object from the JSON string</returns>
|
||||
public static Message Deserialize(string json)
|
||||
{
|
||||
return (Message)JsonConvert.DeserializeObject(json);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Identifier
|
||||
{
|
||||
LOGIN,
|
||||
CHAT,
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -4,16 +4,15 @@ using System.Text;
|
||||
using Avans.TI.BLE;
|
||||
using System.Threading;
|
||||
using System.Security.Cryptography;
|
||||
using ProftaakRH;
|
||||
|
||||
namespace Hardware
|
||||
{
|
||||
/// <summary>
|
||||
/// <c>BLEHandler</c> class that handles connection and traffic to and from the bike
|
||||
/// </summary>
|
||||
public class BLEHandler
|
||||
class BLEHandler
|
||||
{
|
||||
IDataReceiver dataReceiver;
|
||||
IDataConverter dataConverter;
|
||||
private BLE bleBike;
|
||||
private BLE bleHeart;
|
||||
public bool Running { get; set; }
|
||||
@@ -21,10 +20,11 @@ namespace Hardware
|
||||
/// <summary>
|
||||
/// Makes a new BLEHandler object
|
||||
/// </summary>
|
||||
/// <param name="dataReceiver">the dataconverter object</param>
|
||||
public BLEHandler(IDataReceiver dataReceiver)
|
||||
/// <param name="dataConverter">the dataconverter object</param>
|
||||
public BLEHandler(IDataConverter dataConverter)
|
||||
{
|
||||
this.dataReceiver = dataReceiver;
|
||||
this.dataConverter = dataConverter;
|
||||
bool running = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -120,16 +120,16 @@ namespace Hardware
|
||||
/// <param name="e">the value changed event</param>
|
||||
private void BleBike_SubscriptionValueChanged(object sender, BLESubscriptionValueChangedEventArgs e)
|
||||
{
|
||||
|
||||
|
||||
if (e.ServiceName == "6e40fec2-b5a3-f393-e0a9-e50e24dcca9e")
|
||||
{
|
||||
byte[] payload = new byte[8];
|
||||
Array.Copy(e.Data, 4, payload, 0, 8);
|
||||
this.dataReceiver.Bike(payload);
|
||||
this.dataConverter.Bike(payload);
|
||||
}
|
||||
else if (e.ServiceName == "00002a37-0000-1000-8000-00805f9b34fb")
|
||||
{
|
||||
this.dataReceiver.BPM(e.Data);
|
||||
this.dataConverter.BPM(e.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -165,7 +165,7 @@ namespace Hardware
|
||||
antMessage[i] = 0xFF;
|
||||
}
|
||||
antMessage[11] = (byte)Math.Max(Math.Min(Math.Round(percentage / 0.5), 255), 0);
|
||||
|
||||
|
||||
|
||||
byte checksum = 0;
|
||||
for (int i = 0; i < 12; i++)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using LibNoise.Primitive;
|
||||
using ProftaakRH;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -10,9 +9,9 @@ using System.Threading;
|
||||
|
||||
namespace Hardware.Simulators
|
||||
{
|
||||
public class BikeSimulator : IHandler
|
||||
class BikeSimulator : IHandler
|
||||
{
|
||||
IDataReceiver dataReceiver;
|
||||
IDataConverter dataConverter;
|
||||
private int elapsedTime = 0;
|
||||
private int eventCounter = 0;
|
||||
private double distanceTraveled = 0;
|
||||
@@ -30,11 +29,10 @@ namespace Hardware.Simulators
|
||||
|
||||
|
||||
|
||||
public BikeSimulator(IDataReceiver dataReceiver)
|
||||
public BikeSimulator(IDataConverter dataConverter)
|
||||
{
|
||||
this.dataReceiver = dataReceiver;
|
||||
this.dataConverter = dataConverter;
|
||||
}
|
||||
|
||||
public void StartSimulation()
|
||||
{
|
||||
//Example BLE Message
|
||||
@@ -43,16 +41,16 @@ namespace Hardware.Simulators
|
||||
float x = 0.0f;
|
||||
|
||||
//Perlin for Random values
|
||||
ImprovedPerlin improvedPerlin = new ImprovedPerlin(0, LibNoise.NoiseQuality.Best);
|
||||
|
||||
ImprovedPerlin improvedPerlin = new ImprovedPerlin(0,LibNoise.NoiseQuality.Best);
|
||||
|
||||
while (true)
|
||||
{
|
||||
CalculateVariables(improvedPerlin.GetValue(x) + 1);
|
||||
CalculateVariables(improvedPerlin.GetValue(x)+1);
|
||||
|
||||
//Simulate sending data
|
||||
dataReceiver.Bike(GenerateBike0x19());
|
||||
dataReceiver.Bike(GenerateBike0x10());
|
||||
dataReceiver.BPM(GenerateHeart());
|
||||
dataConverter.Bike(GenerateBike0x19());
|
||||
dataConverter.Bike(GenerateBike0x10());
|
||||
dataConverter.BPM(GenerateHeart());
|
||||
|
||||
Thread.Sleep(1000);
|
||||
|
||||
@@ -67,21 +65,21 @@ namespace Hardware.Simulators
|
||||
private byte[] GenerateBike0x19()
|
||||
{
|
||||
byte statByte = (byte)(powerArray[1] >> 4);
|
||||
byte[] bikeByte = { 0x19, Convert.ToByte(eventCounter % 256), Convert.ToByte(cadence % 254), accPowerArray[0], accPowerArray[1], powerArray[0], statByte, 0x20 };
|
||||
byte[] bikeByte = { 0x19, Convert.ToByte(eventCounter%256), Convert.ToByte(cadence%254), accPowerArray[0], accPowerArray[1], powerArray[0], statByte, 0x20 };
|
||||
return bikeByte;
|
||||
}
|
||||
|
||||
//Generate an ANT message for page 0x10
|
||||
private byte[] GenerateBike0x10()
|
||||
{
|
||||
byte[] bikeByte = { 0x10, Convert.ToByte(equipmentType), Convert.ToByte(elapsedTime * 4 % 64), Convert.ToByte(distanceTraveled), speedArray[0], speedArray[1], Convert.ToByte(BPM), 0xFF };
|
||||
byte[] bikeByte = { 0x10, Convert.ToByte(equipmentType), Convert.ToByte(elapsedTime*4%64), Convert.ToByte(distanceTraveled), speedArray[0], speedArray[1], Convert.ToByte(BPM), 0xFF };
|
||||
return bikeByte;
|
||||
}
|
||||
|
||||
//Generate an ANT message for BPM
|
||||
private byte[] GenerateHeart()
|
||||
{
|
||||
byte[] hartByte = { 0x00, Convert.ToByte(BPM) };
|
||||
byte[] hartByte = { 0x00, Convert.ToByte(BPM)};
|
||||
return hartByte;
|
||||
}
|
||||
|
||||
@@ -116,13 +114,13 @@ namespace Hardware.Simulators
|
||||
//Input perlin value
|
||||
private void CalculateVariables(float perlin)
|
||||
{
|
||||
this.speed = perlin * 5 / 0.01;
|
||||
this.speed = perlin * 5 / 0.01 ;
|
||||
short sped = (short)speed;
|
||||
speedArray = BitConverter.GetBytes(sped);
|
||||
this.distanceTraveled = (distanceTraveled + (speed * 0.01)) % 256;
|
||||
this.BPM = (int)(perlin * 80);
|
||||
this.cadence = (int)speed / 6;
|
||||
this.power = ((1 + resistance) * speed) / 14 % 4094;
|
||||
this.distanceTraveled = (distanceTraveled+(speed*0.01)) % 256;
|
||||
this.BPM = (int) (perlin * 80);
|
||||
this.cadence = (int)speed/6;
|
||||
this.power = ((1 + resistance) * speed)/14 % 4094;
|
||||
this.accPower = (this.accPower + this.power) % 65536;
|
||||
// TO DO power to power LSB & MSN
|
||||
powerArray = BitConverter.GetBytes((short)this.power);
|
||||
@@ -133,9 +131,9 @@ namespace Hardware.Simulators
|
||||
public void setResistance(byte[] bytes)
|
||||
{
|
||||
//TODO check if message is correct
|
||||
if (bytes.Length == 13)
|
||||
if(bytes.Length == 13)
|
||||
{
|
||||
this.resistance = Convert.ToDouble(bytes[11]) / 2;
|
||||
this.resistance = Convert.ToDouble(bytes[11])/2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using ProftaakRH;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
@@ -8,7 +7,7 @@ namespace Hardware
|
||||
/// <summary>
|
||||
/// DataConverter class that handles all conversion of received data from the BLE bike.
|
||||
/// </summary>
|
||||
class DataConverter : IDataReceiver
|
||||
class DataConverter : IDataConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Receives, parses and displays any incoming data from the bike.
|
||||
@@ -23,7 +22,7 @@ namespace Hardware
|
||||
else
|
||||
if (bytes.Length == 8)
|
||||
{
|
||||
|
||||
|
||||
switch (bytes[0])
|
||||
{
|
||||
case 0x10:
|
||||
@@ -38,7 +37,7 @@ namespace Hardware
|
||||
Console.WriteLine($"Speed is : {input * 0.01}m/s (Range 65.534m/4)");
|
||||
if (bytes[6] != 0xFF)
|
||||
{
|
||||
Console.WriteLine("Heart rate byte: {0}", Convert.ToString(bytes[6], 2));
|
||||
Console.WriteLine("Heart rate byte: {0}", Convert.ToString(bytes[6],2));
|
||||
}
|
||||
break;
|
||||
case 0x19:
|
||||
@@ -46,17 +45,17 @@ namespace Hardware
|
||||
if (bytes[2] != 0xFF)
|
||||
{
|
||||
Console.WriteLine($"Instantaneous cadence: {bytes[2]} RPM (Range 0-254)");
|
||||
|
||||
|
||||
}
|
||||
int accumPower = bytes[3] | (bytes[4] << 8);
|
||||
|
||||
|
||||
Console.WriteLine($"Accumulated power: {accumPower} watt (Rollover 65536)");
|
||||
|
||||
int instantPower = (bytes[5]) | (bytes[6] & 0b00001111) << 8;
|
||||
|
||||
int instantPower = (bytes[5]) | (bytes[6] & 0b00001111)<<8;
|
||||
|
||||
|
||||
if (instantPower != 0xFFF)
|
||||
Console.WriteLine($"Instant power: {instantPower} watt (Range 0-4094)");
|
||||
Console.WriteLine($"Instant power: {instantPower} watt (Range 0-4094)");
|
||||
|
||||
int trainerStatus = bytes[6] & 0b11110000; // bit 4-7
|
||||
int flags = bytes[7] >> 4;
|
||||
@@ -104,4 +103,13 @@ namespace Hardware
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dataconverter interface for handling data received from the bike
|
||||
/// </summary>
|
||||
interface IDataConverter
|
||||
{
|
||||
void BPM(byte[] bytes);
|
||||
void Bike(byte[] bytes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace ProftaakRH
|
||||
{
|
||||
public interface IDataReceiver
|
||||
{
|
||||
void BPM(byte[] bytes);
|
||||
void Bike(byte[] bytes);
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,13 @@ using Hardware.Simulators;
|
||||
|
||||
namespace ProftaakRH
|
||||
{
|
||||
class Program
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] agrs)
|
||||
{
|
||||
IDataReceiver dataReceiver = new DataConverter();
|
||||
BLEHandler bLEHandler = new BLEHandler(dataReceiver);
|
||||
IDataConverter dataConverter = new DataConverter();
|
||||
BLEHandler bLEHandler = new BLEHandler(dataConverter);
|
||||
bLEHandler.Connect();
|
||||
//BikeSimulator bikeSimulator = new BikeSimulator(dataConverter);
|
||||
//bikeSimulator.setResistance(bikeSimulator.GenerateResistance(1f));
|
||||
//bikeSimulator.StartSimulation();
|
||||
@@ -24,7 +25,7 @@ namespace ProftaakRH
|
||||
string input = Console.ReadLine();
|
||||
input.ToLower();
|
||||
input.Trim();
|
||||
if (input == "quit")
|
||||
if(input == "quit")
|
||||
{
|
||||
running = false;
|
||||
break;
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LibNoise" Version="0.2.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="BLELibrary">
|
||||
|
||||
@@ -5,13 +5,7 @@ VisualStudioVersion = 16.0.30413.136
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProftaakRH", "ProftaakRH.csproj", "{0F053CC5-D969-4970-9501-B3428EA3D777}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RH-Engine", "..\RH-Engine\RH-Engine.csproj", "{984E295E-47A2-41E7-90E5-50FDB9E67694}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "..\Server\Server.csproj", "{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "..\Client\Client.csproj", "{5759DD20-7A4F-4D8D-B986-A70A7818C112}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Message", "..\Message\Message.csproj", "{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RH-Engine", "..\RH-Engine\RH-Engine.csproj", "{E7D960C3-0848-4C56-9779-DD3D5829D3D6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -23,22 +17,10 @@ Global
|
||||
{0F053CC5-D969-4970-9501-B3428EA3D777}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{984E295E-47A2-41E7-90E5-50FDB9E67694}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{984E295E-47A2-41E7-90E5-50FDB9E67694}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{984E295E-47A2-41E7-90E5-50FDB9E67694}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{984E295E-47A2-41E7-90E5-50FDB9E67694}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B1AB6F51-A20D-4162-9A7F-B3350B7510FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5759DD20-7A4F-4D8D-B986-A70A7818C112}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5759DD20-7A4F-4D8D-B986-A70A7818C112}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5759DD20-7A4F-4D8D-B986-A70A7818C112}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5759DD20-7A4F-4D8D-B986-A70A7818C112}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9ED6832D-B0FB-4460-9BCD-FAA58863B0CE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E7D960C3-0848-4C56-9779-DD3D5829D3D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E7D960C3-0848-4C56-9779-DD3D5829D3D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E7D960C3-0848-4C56-9779-DD3D5829D3D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E7D960C3-0848-4C56-9779-DD3D5829D3D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -8,7 +8,7 @@ using System.Threading;
|
||||
|
||||
namespace RH_Engine
|
||||
{
|
||||
class Command
|
||||
class CreateGraphics
|
||||
{
|
||||
public const string STANDARD_HEAD = "Head";
|
||||
public const string STANDARD_GROUND = "GroundPlane";
|
||||
@@ -20,7 +20,7 @@ namespace RH_Engine
|
||||
|
||||
string tunnelID;
|
||||
|
||||
public Command(string tunnelID)
|
||||
public CreateGraphics(string tunnelID)
|
||||
{
|
||||
this.tunnelID = tunnelID;
|
||||
}
|
||||
@@ -159,12 +159,12 @@ namespace RH_Engine
|
||||
return JsonConvert.SerializeObject(Payload(payload));
|
||||
}
|
||||
|
||||
public string MoveTo(string uuid, float[] positionVector, float rotateValue, float speedValue, float timeValue)
|
||||
public string MoveTo(string uuid, float[] positionVector, string rotateValue, float speedValue, float timeValue)
|
||||
{
|
||||
return MoveTo(uuid, "idk", positionVector, rotateValue, "linear", false, speedValue, timeValue);
|
||||
}
|
||||
|
||||
private string MoveTo(string uuid, string stopValue, float[] positionVector, float rotateValue, string interpolateValue, bool followHeightValue, float speedValue, float timeValue)
|
||||
private string MoveTo(string uuid, string stopValue, float[] positionVector, string rotateValue, string interpolateValue, bool followHeightValue, float speedValue, float timeValue)
|
||||
{
|
||||
dynamic payload = new
|
||||
{
|
||||
@@ -184,7 +184,6 @@ namespace RH_Engine
|
||||
return JsonConvert.SerializeObject(Payload(payload));
|
||||
}
|
||||
|
||||
|
||||
public string RouteCommand()
|
||||
{
|
||||
ImprovedPerlin improvedPerlin = new ImprovedPerlin(4325, LibNoise.NoiseQuality.Best);
|
||||
@@ -232,6 +231,37 @@ namespace RH_Engine
|
||||
return JsonConvert.SerializeObject(Payload(payload));
|
||||
}
|
||||
|
||||
public string RouteFollow(string routeID, string nodeID, float speedValue)
|
||||
{
|
||||
return RouteFollow(routeID, nodeID, speedValue, new float[] { 0, 0, 0 });
|
||||
}
|
||||
|
||||
public string RouteFollow(string routeID, string nodeID, float speedValue, float[] positionOffsetVector)
|
||||
{
|
||||
return RouteFollow(routeID, nodeID, speedValue, 0, "XYZ", 1, true, new float[] { 0, 0, 0 }, positionOffsetVector);
|
||||
}
|
||||
private string RouteFollow(string routeID, string nodeID, float speedValue, float offsetValue, string rotateValue, float smoothingValue, bool followHeightValue, float[] rotateOffsetVector, float[] positionOffsetVector)
|
||||
{
|
||||
dynamic payload = new
|
||||
{
|
||||
id = "route/follow",
|
||||
data = new
|
||||
{
|
||||
route = routeID,
|
||||
node = nodeID,
|
||||
speed = speedValue,
|
||||
offset = offsetValue,
|
||||
rotate = rotateValue,
|
||||
smoothing = smoothingValue,
|
||||
followHeight = followHeightValue,
|
||||
rotateOffset = rotateOffsetVector,
|
||||
positionOffset = positionOffsetVector
|
||||
|
||||
}
|
||||
};
|
||||
return JsonConvert.SerializeObject(Payload(payload));
|
||||
}
|
||||
|
||||
private float[] GetPos(float n, ImprovedPerlin improvedPerlin)
|
||||
{
|
||||
float[] res = new float[] { improvedPerlin.GetValue(n) * 50, 0, improvedPerlin.GetValue(n) * 50 };
|
||||
@@ -241,7 +271,7 @@ namespace RH_Engine
|
||||
private int[] GetDir()
|
||||
{
|
||||
Random rng = new Random();
|
||||
int[] dir = {rng.Next(50), 0, rng.Next(50)};
|
||||
int[] dir = { rng.Next(50), 0, rng.Next(50) };
|
||||
return dir;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace RH_Engine
|
||||
private static PC[] PCs = {
|
||||
//new PC("DESKTOP-M2CIH87", "Fabian"),
|
||||
new PC("T470S", "Shinichi"),
|
||||
//new PC("DESKTOP-DHS478C", "semme"),
|
||||
//new PC("DESKTOP-DHS478C", "semme")
|
||||
//new PC("DESKTOP-TV73FKO", "Wouter"),
|
||||
//new PC("DESKTOP-SINMKT1", "Ralf"),
|
||||
//new PC("NA", "Bart")
|
||||
@@ -103,41 +103,31 @@ namespace RH_Engine
|
||||
return;
|
||||
}
|
||||
|
||||
sendCommands(stream, tunnelID);
|
||||
CreateGraphics createGraphics = new CreateGraphics(tunnelID);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sends all the commands to the server
|
||||
/// </summary>
|
||||
/// <param name="stream">the network stream to use</param>
|
||||
/// <param name="tunnelID">the tunnel id to use</param>
|
||||
private static void sendCommands(NetworkStream stream, string tunnelID)
|
||||
{
|
||||
Command mainCommand = new Command(tunnelID);
|
||||
|
||||
|
||||
WriteTextMessage(stream, mainCommand.ResetScene());
|
||||
WriteTextMessage(stream, createGraphics.ResetScene());
|
||||
ReadPrefMessage(stream);
|
||||
string routeid = CreateRoute(stream, mainCommand);
|
||||
string routeid = CreateRoute(stream, createGraphics);
|
||||
|
||||
WriteTextMessage(stream, mainCommand.TerrainCommand(new int[] { 256, 256 }, null));
|
||||
WriteTextMessage(stream, createGraphics.TerrainCommand(new int[] { 256, 256 }, null));
|
||||
Console.WriteLine(ReadPrefMessage(stream));
|
||||
string command;
|
||||
|
||||
command = mainCommand.AddBikeModel();
|
||||
command = createGraphics.AddBikeModel();
|
||||
|
||||
WriteTextMessage(stream, command);
|
||||
|
||||
Console.WriteLine(ReadPrefMessage(stream));
|
||||
|
||||
command = mainCommand.AddModel("car", "data\\customModels\\TeslaRoadster.fbx");
|
||||
command = createGraphics.AddModel("car", "data\\customModels\\TeslaRoadster.fbx");
|
||||
|
||||
WriteTextMessage(stream, command);
|
||||
|
||||
Console.WriteLine(ReadPrefMessage(stream));
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -147,7 +137,7 @@ namespace RH_Engine
|
||||
/// <param name="stream">the network stream to send requests to</param>
|
||||
/// <param name="createGraphics">the create graphics object to create all the commands</param>
|
||||
/// <returns> the uuid of the object with the given name, <c>null</c> otherwise.</returns>
|
||||
public static string GetId(string name, NetworkStream stream, Command createGraphics)
|
||||
public static string GetId(string name, NetworkStream stream, CreateGraphics createGraphics)
|
||||
{
|
||||
JArray children = GetChildren(stream, createGraphics);
|
||||
|
||||
@@ -163,7 +153,7 @@ namespace RH_Engine
|
||||
|
||||
}
|
||||
|
||||
public static string CreateRoute(NetworkStream stream, Command createGraphics)
|
||||
public static string CreateRoute(NetworkStream stream, CreateGraphics createGraphics)
|
||||
{
|
||||
WriteTextMessage(stream, createGraphics.RouteCommand());
|
||||
dynamic response = JsonConvert.DeserializeObject(ReadPrefMessage(stream));
|
||||
@@ -175,7 +165,7 @@ namespace RH_Engine
|
||||
|
||||
}
|
||||
|
||||
public static void CreateTerrain(NetworkStream stream, Command createGraphics)
|
||||
public static void CreateTerrain(NetworkStream stream, CreateGraphics createGraphics)
|
||||
{
|
||||
float x = 0f;
|
||||
float[] height = new float[256 * 256];
|
||||
@@ -199,7 +189,7 @@ namespace RH_Engine
|
||||
/// <param name="stream">the network stream to send requests to</param>
|
||||
/// <param name="createGraphics">the create graphics object to create all the commands</param>
|
||||
/// <returns>all the children objects in the current scene</returns>
|
||||
public static JArray GetChildren(NetworkStream stream, Command createGraphics)
|
||||
public static JArray GetChildren(NetworkStream stream, CreateGraphics createGraphics)
|
||||
{
|
||||
WriteTextMessage(stream, createGraphics.GetSceneInfoCommand());
|
||||
dynamic response = JsonConvert.DeserializeObject(ReadPrefMessage(stream));
|
||||
@@ -212,7 +202,7 @@ namespace RH_Engine
|
||||
/// <param name="stream">the network stream to send requests to</param>
|
||||
/// <param name="createGraphics">the create graphics object to create all the commands</param>
|
||||
/// <returns>an array of name-uuid tuples for each object</returns>
|
||||
public static (string, string)[] GetObjectsInScene(NetworkStream stream, Command createGraphics)
|
||||
public static (string, string)[] GetObjectsInScene(NetworkStream stream, CreateGraphics createGraphics)
|
||||
{
|
||||
JArray children = GetChildren(stream, createGraphics);
|
||||
(string, string)[] res = new (string, string)[children.Count];
|
||||
|
||||
155
Server/Client.cs
155
Server/Client.cs
@@ -1,155 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using Client;
|
||||
using Newtonsoft;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
class Client
|
||||
{
|
||||
private Communication communication;
|
||||
private TcpClient tcpClient;
|
||||
private NetworkStream stream;
|
||||
private byte[] buffer = new byte[1024];
|
||||
private byte[] totalBuffer = new byte[1024];
|
||||
private int bytesReceived;
|
||||
|
||||
|
||||
public string Username { get; set; }
|
||||
|
||||
public Client(Communication communication, TcpClient tcpClient)
|
||||
{
|
||||
this.communication = communication;
|
||||
this.tcpClient = tcpClient;
|
||||
this.stream = this.tcpClient.GetStream();
|
||||
stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnRead), null);
|
||||
}
|
||||
|
||||
/*private void OnRead(IAsyncResult ar)
|
||||
{
|
||||
try
|
||||
{
|
||||
int receivedBytes = stream.EndRead(ar);
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
communication.Disconnect(this);
|
||||
return;
|
||||
}
|
||||
|
||||
int counter = 0;
|
||||
|
||||
while (buffer.Length > counter)
|
||||
{
|
||||
//Console.WriteLine(buffer.Length);
|
||||
byte[] lenghtBytes = new byte[4];
|
||||
Array.Copy(buffer, counter, lenghtBytes, 0, 4);
|
||||
int length = BitConverter.ToInt32(lenghtBytes);
|
||||
Console.WriteLine(buffer[5]);
|
||||
if (length == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (buffer[counter + 4] == 0x02)
|
||||
{
|
||||
}
|
||||
else if (buffer[counter + 4] == 0x01)
|
||||
{
|
||||
byte[] packet = new byte[length];
|
||||
Console.WriteLine(Encoding.ASCII.GetString(buffer) + " " + length);
|
||||
Array.Copy(buffer, counter + 5, packet, 0, length);
|
||||
Console.WriteLine(Encoding.ASCII.GetString(packet));
|
||||
HandleData(Encoding.ASCII.GetString(packet));
|
||||
}
|
||||
|
||||
counter += length;
|
||||
}
|
||||
|
||||
Console.WriteLine("Done");
|
||||
|
||||
stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnRead), null);
|
||||
}*/
|
||||
|
||||
private void OnRead(IAsyncResult ar)
|
||||
{
|
||||
int receivedBytes = this.stream.EndRead(ar);
|
||||
byte[] lengthBytes = new byte[4];
|
||||
|
||||
Array.Copy(this.buffer, 0, lengthBytes, 0, 4);
|
||||
|
||||
int expectedMessageLength = BitConverter.ToInt32(lengthBytes);
|
||||
|
||||
if (expectedMessageLength > this.buffer.Length)
|
||||
{
|
||||
throw new OutOfMemoryException("buffer to small");
|
||||
}
|
||||
|
||||
if (expectedMessageLength > this.bytesReceived + receivedBytes)
|
||||
{
|
||||
//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);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//message completely arrived
|
||||
if (expectedMessageLength != this.bytesReceived + receivedBytes)
|
||||
{
|
||||
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(6).ToArray(), 16)}");
|
||||
}
|
||||
else if (buffer[4] == 0x01)
|
||||
{
|
||||
byte[] packet = new byte[expectedMessageLength];
|
||||
Console.WriteLine(Encoding.ASCII.GetString(buffer) + " " + expectedMessageLength);
|
||||
Array.Copy(buffer, 6, packet, 0, expectedMessageLength - 6);
|
||||
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)
|
||||
{
|
||||
Console.WriteLine("Data " + packet);
|
||||
dynamic json = JsonConvert.DeserializeObject(packet);
|
||||
Console.WriteLine("Name: "+json.data.username + "Password: "+json.data.password);
|
||||
if (json.data.username == json.data.password)
|
||||
{
|
||||
dynamic payload = new
|
||||
{
|
||||
data = new
|
||||
{
|
||||
status = "ok"
|
||||
}
|
||||
};
|
||||
Message.Message message = new Message.Message(Message.Identifier.LOGIN, JsonConvert.SerializeObject(payload));
|
||||
Write(message.Serialize());
|
||||
}
|
||||
}
|
||||
|
||||
private void Write(string data)
|
||||
{
|
||||
byte[] bytes = DataParser.getMessage(Encoding.ASCII.GetBytes(data), 0x01, 0x01);
|
||||
stream.Write(bytes, 0, bytes.Length);
|
||||
stream.Flush();
|
||||
Console.WriteLine("Wrote message");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Pipes;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
class Communication
|
||||
{
|
||||
private TcpListener listener;
|
||||
private List<Client> clients;
|
||||
|
||||
public Communication(TcpListener listener)
|
||||
{
|
||||
this.listener = listener;
|
||||
this.clients = new List<Client>();
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
listener.Start();
|
||||
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
|
||||
}
|
||||
|
||||
private void OnConnect(IAsyncResult ar)
|
||||
{
|
||||
var tcpClient = listener.EndAcceptTcpClient(ar);
|
||||
Console.WriteLine($"Client connected from {tcpClient.Client.RemoteEndPoint}");
|
||||
clients.Add(new Client(this, tcpClient));
|
||||
listener.BeginAcceptTcpClient(new AsyncCallback(OnConnect), null);
|
||||
}
|
||||
|
||||
internal void Disconnect(Client client)
|
||||
{
|
||||
clients.Remove(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Communication communication = new Communication(new TcpListener(IPAddress.Any, 5555));
|
||||
communication.Start();
|
||||
|
||||
while (true)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Client\Client.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user