Develop #10

Merged
SemvdH merged 229 commits from develop into master 2020-10-29 22:50:49 +00:00
2 changed files with 22 additions and 24 deletions
Showing only changes of commit a65c36b8d1 - Show all commits

View File

@@ -123,9 +123,7 @@ namespace Server
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
break;
}
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(payloadbytes));
saveData.WriteDataJSON(Encoding.ASCII.GetString(payloadbytes));
saveData?.WriteDataJSON(Encoding.ASCII.GetString(payloadbytes));
}
else if (DataParser.isRawData(message))
{

View File

@@ -32,18 +32,36 @@ namespace Server
}
public void WriteDataRAWBPM(byte[] data)
{
if (data.Length != 2)
{
throw new ArgumentException("data should have length of 2");
}
WriteRawData(data, this.path + "/rawBPM" + filename + ".bin");
}
public void WriteDataRAWBike(byte[] data)
{
if (data.Length != 8)
{
throw new ArgumentException("data should have length of 8");
}
WriteRawData(data, this.path + "/rawBike" + filename + ".bin");
}
private void WriteRawData(byte[] data, string fileLocation)
{
int length = 0;
try
{
FileInfo fi = new FileInfo(this.path + "/rawBPM" + filename + ".bin");
FileInfo fi = new FileInfo(fileLocation);
length = (int)fi.Length;
}
catch
{
// do nothing
}
using (BinaryWriter sw = new BinaryWriter(File.Open(this.path + "/rawBPM" + filename + ".bin", FileMode.Create)))
using (BinaryWriter sw = new BinaryWriter(File.Open(fileLocation, FileMode.Create)))
{
sw.Seek(length, SeekOrigin.End);
sw.Write(data);
@@ -51,24 +69,6 @@ namespace Server
}
}
public void WriteDataRAWBike(byte[] data)
{
int length = 0;
try
{
FileInfo fi = new FileInfo(this.path + "/rawBike" + filename + ".bin");
length = (int)fi.Length;
}
catch
{
// do nothing
}
using (BinaryWriter sw = new BinaryWriter(File.Open(this.path + "/rawBike" + filename + ".bin", FileMode.Create)))
{
sw.Seek(length, SeekOrigin.End);
sw.Write(data);
sw.Flush();
}
}
}
}