basic class layout

This commit is contained in:
shinichi
2020-09-09 11:30:02 +02:00
parent 2200e2f012
commit 213a098356
4 changed files with 143 additions and 75 deletions

10
ProftaakRH/BLEReciever.cs Normal file
View File

@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace ProftaakRH
{
class Class1
{
}
}

View File

@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace ProftaakRH
{
class Class1
{
}
}

View File

@@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace ProftaakRH
{
class DataConverter
{
}
}

View File

@@ -9,7 +9,29 @@ namespace FietsDemo
{ {
internal class Program internal class Program
{ {
private static async Task Main(string[] args) static void Main(string[] args)
{
foo foo = new foo();
BLEReceiver bLEReceiver = new BLEReceiver(foo);
bLEReceiver.ConnectToBLE();
Console.Read();
}
interface IFoo
{
void doStuff(byte[] bytes);
}
class BLEReceiver
{
IFoo foo;
public BLEReceiver(IFoo foo)
{
this.foo = foo;
}
public async void ConnectToBLE()
{ {
int errorCode = 0; int errorCode = 0;
BLE bleBike = new BLE(); BLE bleBike = new BLE();
@@ -53,50 +75,53 @@ namespace FietsDemo
Console.Read(); Console.Read();
} }
private static void BleBike_SubscriptionValueChanged(object sender, BLESubscriptionValueChangedEventArgs e) private void BleBike_SubscriptionValueChanged(object sender, BLESubscriptionValueChangedEventArgs e)
{ {
Console.WriteLine("Received from {0}: {1}, {2}", e.ServiceName, //Console.WriteLine("Received from {0}: {1}, {2}", e.ServiceName,
BitConverter.ToString(e.Data).Replace("-", " "), // BitConverter.ToString(e.Data).Replace("-", " "),
Encoding.UTF8.GetString(e.Data)); // Encoding.UTF8.GetString(e.Data));
string[] bytes = BitConverter.ToString(e.Data).Split('-'); //string[] bytes = BitConverter.ToString(e.Data).Split('-');
string[] ANT = new string[5]; //string[] ANT = new string[5];
if (e.ServiceName == "6e40fec2-b5a3-f393-e0a9-e50e24dcca9e") //if (e.ServiceName == "6e40fec2-b5a3-f393-e0a9-e50e24dcca9e")
{ //{
Console.WriteLine("SYNC : " + bytes[0]); // Console.WriteLine("SYNC : " + bytes[0]);
ANT[0] = bytes[0]; // ANT[0] = bytes[0];
Console.WriteLine("LENGTH : " + bytes[1]); // Console.WriteLine("LENGTH : " + bytes[1]);
int length = Convert.ToInt32(bytes[1], 16); // int length = Convert.ToInt32(bytes[1], 16);
ANT[1] = length.ToString(); // ANT[1] = length.ToString();
Console.WriteLine("MSG ID : " + bytes[2]); // Console.WriteLine("MSG ID : " + bytes[2]);
ANT[2] = bytes[2]; // ANT[2] = bytes[2];
string msg = string.Empty; // string msg = string.Empty;
for (int i = 3; i < 3 + length; i++) // for (int i = 3; i < 3 + length; i++)
{ // {
msg += bytes[i]; // msg += bytes[i];
} // }
ANT[3] = msg; // ANT[3] = msg;
byte[] message = new byte[length]; // byte[] message = new byte[length];
Array.Copy(e.Data, 3, message, 0, length); // Array.Copy(e.Data, 3, message, 0, length);
DoCrazyShitWithMsg(message); // DoCrazyShitWithMsg(message);
Console.WriteLine("MSG : " + msg); // Console.WriteLine("MSG : " + msg);
string checksum = bytes[3 + length]; // string checksum = bytes[3 + length];
ANT[4] = checksum; // ANT[4] = checksum;
Console.WriteLine("CHECKSUM : " + checksum); // Console.WriteLine("CHECKSUM : " + checksum);
Console.WriteLine(BitConverter.ToString(e.Data)); // Console.WriteLine(BitConverter.ToString(e.Data));
} else //}
{ //else
Console.WriteLine("BPM: " + Convert.ToInt32(bytes[1], 16)); //{
} // Console.WriteLine("BPM: " + Convert.ToInt32(bytes[1], 16));
Console.WriteLine(); //}
//Console.WriteLine();
this.foo.doStuff(e.Data);
} }
private static void DoCrazyShitWithMsg(byte[] bytes) private static void DoCrazyShitWithMsg(byte[] bytes)
@@ -108,4 +133,17 @@ namespace FietsDemo
} }
} }
} }
class foo : IFoo
{
public void doStuff(byte[] bytes)
{
Console.WriteLine("Foo class received {0}", Convert.ToString(bytes));
}
}
}
} }