Merge branch 'binairy-writer' into develop
This commit is contained in:
@@ -123,15 +123,23 @@ namespace Server
|
||||
Console.WriteLine($"Received json with identifier {identifier}:\n{Encoding.ASCII.GetString(payloadbytes)}");
|
||||
break;
|
||||
}
|
||||
Array.Copy(message, 5, payloadbytes, 0, message.Length - 5);
|
||||
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))
|
||||
{
|
||||
Console.WriteLine(BitConverter.ToString(message));
|
||||
saveData.WriteDataRAW(ByteArrayToString(message));
|
||||
Console.WriteLine(BitConverter.ToString(payloadbytes));
|
||||
if (payloadbytes.Length == 8)
|
||||
{
|
||||
saveData.WriteDataRAWBike(payloadbytes);
|
||||
}
|
||||
else if (payloadbytes.Length == 2)
|
||||
{
|
||||
saveData.WriteDataRAWBPM(payloadbytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("received raw data with weird lenght " + BitConverter.ToString(payloadbytes));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,21 +22,53 @@ namespace Server
|
||||
/// <summary>
|
||||
/// Every line is a new data entry
|
||||
/// </summary>
|
||||
|
||||
|
||||
public void WriteDataJSON(string data)
|
||||
{
|
||||
using (StreamWriter sw = File.AppendText(this.path + "/json"+filename+".txt"))
|
||||
using (StreamWriter sw = File.AppendText(this.path + "/json" + filename + ".txt"))
|
||||
{
|
||||
sw.WriteLine(data);
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteDataRAW(string data)
|
||||
public void WriteDataRAWBPM(byte[] data)
|
||||
{
|
||||
using (StreamWriter sw = File.AppendText(this.path + "/raw" + filename + ".txt"))
|
||||
if (data.Length != 2)
|
||||
{
|
||||
sw.WriteLine(data);
|
||||
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(fileLocation);
|
||||
length = (int)fi.Length;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
using (BinaryWriter sw = new BinaryWriter(File.Open(fileLocation, FileMode.Create)))
|
||||
{
|
||||
sw.Seek(length, SeekOrigin.End);
|
||||
sw.Write(data);
|
||||
sw.Flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user