Save Raw data
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Hardware;
|
using Hardware;
|
||||||
|
using Hardware.Simulators;
|
||||||
|
|
||||||
namespace Client
|
namespace Client
|
||||||
{
|
{
|
||||||
@@ -18,13 +19,13 @@ namespace Client
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
BLEHandler bLEHandler = new BLEHandler(client);
|
//BLEHandler bLEHandler = new BLEHandler(client);
|
||||||
|
|
||||||
bLEHandler.Connect();
|
//bLEHandler.Connect();
|
||||||
|
|
||||||
//BikeSimulator bikeSimulator = new BikeSimulator(client);
|
BikeSimulator bikeSimulator = new BikeSimulator(client);
|
||||||
|
|
||||||
//bikeSimulator.StartSimulation();
|
bikeSimulator.StartSimulation();
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ namespace Server
|
|||||||
private int totalBufferReceived = 0;
|
private int totalBufferReceived = 0;
|
||||||
private SaveData saveData;
|
private SaveData saveData;
|
||||||
private string username = null;
|
private string username = null;
|
||||||
|
private DateTime sessionStart;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ namespace Server
|
|||||||
|
|
||||||
public Client(Communication communication, TcpClient tcpClient)
|
public Client(Communication communication, TcpClient tcpClient)
|
||||||
{
|
{
|
||||||
this.saveData = new SaveData(Directory.GetCurrentDirectory() + $"/test");
|
this.sessionStart = DateTime.Now;
|
||||||
this.communication = communication;
|
this.communication = communication;
|
||||||
this.tcpClient = tcpClient;
|
this.tcpClient = tcpClient;
|
||||||
this.stream = this.tcpClient.GetStream();
|
this.stream = this.tcpClient.GetStream();
|
||||||
@@ -100,9 +101,11 @@ namespace Server
|
|||||||
{
|
{
|
||||||
if (verifyLogin(username, password))
|
if (verifyLogin(username, password))
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Log in");
|
||||||
this.username = username;
|
this.username = username;
|
||||||
byte[] response = DataParser.getLoginResponse("OK");
|
byte[] response = DataParser.getLoginResponse("OK");
|
||||||
stream.BeginWrite(response, 0, response.Length, new AsyncCallback(OnWrite), null);
|
stream.BeginWrite(response, 0, response.Length, new AsyncCallback(OnWrite), null);
|
||||||
|
this.saveData = new SaveData(Directory.GetCurrentDirectory() + "/" + username, sessionStart.ToString("yyyy-MM-dd HH-mm-ss"));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -128,7 +131,7 @@ namespace Server
|
|||||||
else if (DataParser.isRawData(message))
|
else if (DataParser.isRawData(message))
|
||||||
{
|
{
|
||||||
Console.WriteLine(BitConverter.ToString(message));
|
Console.WriteLine(BitConverter.ToString(message));
|
||||||
saveData.WriteDataRAW(Encoding.ASCII.GetString(message));
|
saveData.WriteDataRAW(ByteArrayToString(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -138,5 +141,13 @@ namespace Server
|
|||||||
{
|
{
|
||||||
return username == password;
|
return username == password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ByteArrayToString(byte[] ba)
|
||||||
|
{
|
||||||
|
StringBuilder hex = new StringBuilder(ba.Length * 2);
|
||||||
|
foreach (byte b in ba)
|
||||||
|
hex.AppendFormat("{0:x2}", b);
|
||||||
|
return hex.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,18 +8,24 @@ namespace Server
|
|||||||
class SaveData
|
class SaveData
|
||||||
{
|
{
|
||||||
private string path;
|
private string path;
|
||||||
public SaveData(string path)
|
private string filename;
|
||||||
|
public SaveData(string path, string filename)
|
||||||
{
|
{
|
||||||
this.path = path;
|
this.path = path;
|
||||||
|
this.filename = filename;
|
||||||
if (!Directory.Exists(path))
|
if (!Directory.Exists(path))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(path);
|
Directory.CreateDirectory(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Every line is a new data entry
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
public void WriteDataJSON(string data)
|
public void WriteDataJSON(string data)
|
||||||
{
|
{
|
||||||
using (StreamWriter sw = File.AppendText(this.path + "/dataJSON.txt"))
|
using (StreamWriter sw = File.AppendText(this.path + "/json"+filename+".txt"))
|
||||||
{
|
{
|
||||||
sw.WriteLine(data);
|
sw.WriteLine(data);
|
||||||
}
|
}
|
||||||
@@ -27,7 +33,7 @@ namespace Server
|
|||||||
|
|
||||||
public void WriteDataRAW(string data)
|
public void WriteDataRAW(string data)
|
||||||
{
|
{
|
||||||
using (StreamWriter sw = File.AppendText(this.path + "/dataRAW.txt"))
|
using (StreamWriter sw = File.AppendText(this.path + "/raw" + filename + ".txt"))
|
||||||
{
|
{
|
||||||
sw.WriteLine(data);
|
sw.WriteLine(data);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user