Skip to content

CA-104 Verisense Speed Test #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions Shimmer32FeetAPI/Radios/BLE32FeetRadio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,12 @@ namespace Shimmer32FeetAPI.Radios
{
public class BLE32FeetRadio : AbstractRadio
{
public enum DeviceType
{
Shimmer3BLE,
Shimmer3R
}

public BLE32FeetRadio(string macAddress, DeviceType devType)
{
MacAddress = macAddress;
deviceType = devType;
}

DeviceType deviceType;

private BluetoothDevice bluetoothDevice { get; set; }
private GattService ServiceTXRX { get; set; }
private GattCharacteristic UartTX { get; set; }
Expand Down Expand Up @@ -62,6 +54,12 @@ protected void OpenConnection()
TxID = BluetoothUuid.FromGuid(new Guid("65333333-A115-11E2-9E9A-0800200CA102"));
ServiceID = BluetoothUuid.FromGuid(new Guid("65333333-A115-11E2-9E9A-0800200CA100"));
}
else if (deviceType.Equals(DeviceType.Verisense))
{
RxID = Guid.Parse("6E400003-B5A3-F393-E0A9-E50E24DCCA9E");
TxID = Guid.Parse("6E400002-B5A3-F393-E0A9-E50E24DCCA9E");
ServiceID = Guid.Parse("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
}
ServiceTXRX = bluetoothDevice.Gatt.GetPrimaryServiceAsync(ServiceID).GetAwaiter().GetResult();
if (ServiceTXRX != null)
{
Expand Down
20 changes: 18 additions & 2 deletions ShimmerAPI/ShimmerAPI/Protocols/SpeedTestProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Text;
using System.Threading;
using static ShimmerAPI.Radios.AbstractRadio;

namespace ShimmerAPI.Protocols
{
Expand All @@ -26,9 +27,24 @@ public class SpeedTestProtocol

ConcurrentQueue<byte> cq = new ConcurrentQueue<byte>();

readonly byte[] ShimmerStopTestSignalCommand = new byte[2] { (byte)0xA4, (byte)0x00 };
readonly byte[] ShimmerStartTestSignalCommand = new byte[2] { (byte)0xA4, (byte)0x01 };
readonly byte[] VerisenseStopTestSignalCommand = new byte[5] { (byte)0x29, (byte)0x02, (byte)0x00, (byte)0x15, (byte)0x00};
readonly byte[] VerisenseStartTestSignalCommand = new byte[5] { (byte)0x29, (byte)0x02, (byte)0x00, (byte)0x15, (byte)0x01};
protected byte[] StopTestSignalCommand;
protected byte[] StartTestSignalCommand;

public SpeedTestProtocol(AbstractRadio radio)
{
Radio = radio;
if (Radio.getDeviceType().Equals(DeviceType.Verisense)){
StartTestSignalCommand = VerisenseStartTestSignalCommand;
StopTestSignalCommand = VerisenseStopTestSignalCommand;
} else
{
StopTestSignalCommand = ShimmerStopTestSignalCommand;
StartTestSignalCommand = ShimmerStartTestSignalCommand;
}
Radio.BytesReceived += Radio_BytesReceived;
}

Expand All @@ -51,7 +67,7 @@ public void StopTestSignal()
NumberofBytesDropped = 0;
System.Console.WriteLine("Stop Test Signal");
TestSignalTSStart = (DateTime.UtcNow - ShimmerBluetooth.UnixEpoch).TotalMilliseconds;
if (Radio.WriteBytes(new byte[2] { (byte)0xA4, (byte)0x00 }))
if (Radio.WriteBytes(StopTestSignalCommand))
{
TestSignalEnabled = false;
}
Expand All @@ -67,7 +83,7 @@ public void StartTestSignal()
TestSignalTotalNumberOfBytes = 0;
System.Console.WriteLine("Start Test Signal");
TestSignalTSStart = (DateTime.UtcNow - ShimmerBluetooth.UnixEpoch).TotalMilliseconds;
if (Radio.WriteBytes(new byte[2] { (byte)0xA4, (byte)0x01 }))
if (Radio.WriteBytes(StartTestSignalCommand))
{
TestSignalEnabled = true;
}
Expand Down
14 changes: 14 additions & 0 deletions ShimmerAPI/ShimmerAPI/Radios/AbstractRadio.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,27 @@ namespace ShimmerAPI.Radios
{
public abstract class AbstractRadio
{
public enum DeviceType
{
Shimmer3BLE,
Shimmer3R,
Verisense
}
public enum RadioStatus
{
Connected,
Disconnected,
Connecting
}

protected DeviceType deviceType;

public DeviceType getDeviceType()
{
return deviceType;
}


protected RadioStatus CurrentRadioStatus = RadioStatus.Disconnected;

public EventHandler<byte[]> BytesReceived;
Expand Down
88 changes: 82 additions & 6 deletions ShimmerAPI/SpeedTestExample/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions ShimmerAPI/SpeedTestExample/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,42 @@ private void button9_Click(object sender, EventArgs e)
{
testRadio.Disconnect();
}

private void button20_Click(object sender, EventArgs e)
{
if (radioBLE != null)
{
radioBLE.RadioStatusChanged -= RadioStateChanged;
}
radioBLE = new BLE32FeetRadio(textBox4.Text, BLE32FeetRadio.DeviceType.Verisense);
radioBLE.RadioStatusChanged += RadioStateChanged;
if (BLE32FeetSpeedTestProtocol != null)
{
BLE32FeetSpeedTestProtocol.ResultUpdate -= ResultUpdated;
}
BLE32FeetSpeedTestProtocol = new SpeedTestProtocol(radioBLE);
BLE32FeetSpeedTestProtocol.ResultUpdate += ResultUpdated;
BLE32FeetSpeedTestProtocol.Connect();
}

private void textBox4_TextChanged(object sender, EventArgs e)
{

}

private void button19_Click(object sender, EventArgs e)
{
BLE32FeetSpeedTestProtocol.StartTestSignal();
}

private void button18_Click(object sender, EventArgs e)
{
BLE32FeetSpeedTestProtocol.StopTestSignal();
}

private void button17_Click(object sender, EventArgs e)
{
BLE32FeetSpeedTestProtocol.Disconnect();
}
}
}
Loading