added start and stop session
This commit is contained in:
@@ -105,7 +105,8 @@ namespace Server
|
||||
this.username = username;
|
||||
byte[] response = DataParser.getLoginResponse("OK");
|
||||
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"));
|
||||
byte[] startSession = DataParser.getStartSessionJson();
|
||||
stream.BeginWrite(startSession, 0, startSession.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -119,6 +120,12 @@ namespace Server
|
||||
stream.BeginWrite(response, 0, response.Length, new AsyncCallback(OnWrite), null);
|
||||
}
|
||||
break;
|
||||
case DataParser.START_SESSION:
|
||||
this.saveData = new SaveData(Directory.GetCurrentDirectory() + "/" + this.username + "/" + sessionStart.ToString("yyyy-MM-dd HH-mm-ss"));
|
||||
break;
|
||||
case DataParser.STOP_SESSION:
|
||||
this.saveData = null;
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||
break;
|
||||
@@ -130,11 +137,11 @@ namespace Server
|
||||
Console.WriteLine(BitConverter.ToString(payloadbytes));
|
||||
if (payloadbytes.Length == 8)
|
||||
{
|
||||
saveData.WriteDataRAWBike(payloadbytes);
|
||||
saveData?.WriteDataRAWBike(payloadbytes);
|
||||
}
|
||||
else if (payloadbytes.Length == 2)
|
||||
{
|
||||
saveData.WriteDataRAWBPM(payloadbytes);
|
||||
saveData?.WriteDataRAWBPM(payloadbytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -8,11 +8,9 @@ namespace Server
|
||||
class SaveData
|
||||
{
|
||||
private string path;
|
||||
private string filename;
|
||||
public SaveData(string path, string filename)
|
||||
public SaveData(string path)
|
||||
{
|
||||
this.path = path;
|
||||
this.filename = filename;
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
@@ -25,7 +23,7 @@ namespace Server
|
||||
|
||||
public void WriteDataJSON(string data)
|
||||
{
|
||||
using (StreamWriter sw = File.AppendText(this.path + "/json" + filename + ".txt"))
|
||||
using (StreamWriter sw = File.AppendText(this.path + "/json" + ".txt"))
|
||||
{
|
||||
sw.WriteLine(data);
|
||||
}
|
||||
@@ -37,7 +35,7 @@ namespace Server
|
||||
{
|
||||
throw new ArgumentException("data should have length of 2");
|
||||
}
|
||||
WriteRawData(data, this.path + "/rawBPM" + filename + ".bin");
|
||||
WriteRawData(data, this.path + "/rawBPM" + ".bin");
|
||||
}
|
||||
|
||||
public void WriteDataRAWBike(byte[] data)
|
||||
@@ -46,7 +44,7 @@ namespace Server
|
||||
{
|
||||
throw new ArgumentException("data should have length of 8");
|
||||
}
|
||||
WriteRawData(data, this.path + "/rawBike" + filename + ".bin");
|
||||
WriteRawData(data, this.path + "/rawBike" + ".bin");
|
||||
}
|
||||
|
||||
private void WriteRawData(byte[] data, string fileLocation)
|
||||
|
||||
Reference in New Issue
Block a user