diff --git a/Shimmer32FeetAPI/Radios/BLE32FeetRadio.cs b/Shimmer32FeetAPI/Radios/BLE32FeetRadio.cs index 8c8aa2b..750ff89 100644 --- a/Shimmer32FeetAPI/Radios/BLE32FeetRadio.cs +++ b/Shimmer32FeetAPI/Radios/BLE32FeetRadio.cs @@ -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; } @@ -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) { diff --git a/ShimmerAPI/ShimmerAPI/Protocols/SpeedTestProtocol.cs b/ShimmerAPI/ShimmerAPI/Protocols/SpeedTestProtocol.cs index 54c92f1..1f81a4d 100644 --- a/ShimmerAPI/ShimmerAPI/Protocols/SpeedTestProtocol.cs +++ b/ShimmerAPI/ShimmerAPI/Protocols/SpeedTestProtocol.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading; +using static ShimmerAPI.Radios.AbstractRadio; namespace ShimmerAPI.Protocols { @@ -26,9 +27,24 @@ public class SpeedTestProtocol ConcurrentQueue cq = new ConcurrentQueue(); + 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; } @@ -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; } @@ -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; } diff --git a/ShimmerAPI/ShimmerAPI/Radios/AbstractRadio.cs b/ShimmerAPI/ShimmerAPI/Radios/AbstractRadio.cs index 048244c..ffb5308 100644 --- a/ShimmerAPI/ShimmerAPI/Radios/AbstractRadio.cs +++ b/ShimmerAPI/ShimmerAPI/Radios/AbstractRadio.cs @@ -7,6 +7,12 @@ namespace ShimmerAPI.Radios { public abstract class AbstractRadio { + public enum DeviceType + { + Shimmer3BLE, + Shimmer3R, + Verisense + } public enum RadioStatus { Connected, @@ -14,6 +20,14 @@ public enum RadioStatus Connecting } + protected DeviceType deviceType; + + public DeviceType getDeviceType() + { + return deviceType; + } + + protected RadioStatus CurrentRadioStatus = RadioStatus.Disconnected; public EventHandler BytesReceived; diff --git a/ShimmerAPI/SpeedTestExample/Form1.Designer.cs b/ShimmerAPI/SpeedTestExample/Form1.Designer.cs index de513b7..54de589 100644 --- a/ShimmerAPI/SpeedTestExample/Form1.Designer.cs +++ b/ShimmerAPI/SpeedTestExample/Form1.Designer.cs @@ -56,6 +56,12 @@ private void InitializeComponent() this.label6 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.label8 = new System.Windows.Forms.Label(); + this.label9 = new System.Windows.Forms.Label(); + this.button17 = new System.Windows.Forms.Button(); + this.button18 = new System.Windows.Forms.Button(); + this.textBox4 = new System.Windows.Forms.TextBox(); + this.button19 = new System.Windows.Forms.Button(); + this.button20 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // button1 @@ -158,7 +164,7 @@ private void InitializeComponent() // // button9 // - this.button9.Location = new System.Drawing.Point(641, 224); + this.button9.Location = new System.Drawing.Point(797, 224); this.button9.Name = "button9"; this.button9.Size = new System.Drawing.Size(104, 23); this.button9.TabIndex = 13; @@ -168,7 +174,7 @@ private void InitializeComponent() // // button10 // - this.button10.Location = new System.Drawing.Point(641, 181); + this.button10.Location = new System.Drawing.Point(797, 181); this.button10.Name = "button10"; this.button10.Size = new System.Drawing.Size(104, 23); this.button10.TabIndex = 12; @@ -178,7 +184,7 @@ private void InitializeComponent() // // button11 // - this.button11.Location = new System.Drawing.Point(641, 138); + this.button11.Location = new System.Drawing.Point(797, 138); this.button11.Name = "button11"; this.button11.Size = new System.Drawing.Size(104, 23); this.button11.TabIndex = 11; @@ -188,7 +194,7 @@ private void InitializeComponent() // // button12 // - this.button12.Location = new System.Drawing.Point(641, 97); + this.button12.Location = new System.Drawing.Point(797, 97); this.button12.Name = "button12"; this.button12.Size = new System.Drawing.Size(104, 23); this.button12.TabIndex = 10; @@ -209,7 +215,7 @@ private void InitializeComponent() // label2 // this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(638, 29); + this.label2.Location = new System.Drawing.Point(794, 29); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(28, 13); this.label2.TabIndex = 15; @@ -321,11 +327,75 @@ private void InitializeComponent() this.label8.Text = "0 Byte/s"; this.label8.Click += new System.EventHandler(this.label8_Click); // + // label9 + // + this.label9.AutoSize = true; + this.label9.Location = new System.Drawing.Point(630, 31); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(53, 13); + this.label9.TabIndex = 32; + this.label9.Text = "Verisense"; + // + // button17 + // + this.button17.Location = new System.Drawing.Point(633, 224); + this.button17.Name = "button17"; + this.button17.Size = new System.Drawing.Size(104, 23); + this.button17.TabIndex = 31; + this.button17.Text = "Disconnect"; + this.button17.UseVisualStyleBackColor = true; + this.button17.Click += new System.EventHandler(this.button17_Click); + // + // button18 + // + this.button18.Location = new System.Drawing.Point(633, 181); + this.button18.Name = "button18"; + this.button18.Size = new System.Drawing.Size(104, 23); + this.button18.TabIndex = 30; + this.button18.Text = "Stop Test"; + this.button18.UseVisualStyleBackColor = true; + this.button18.Click += new System.EventHandler(this.button18_Click); + // + // textBox4 + // + this.textBox4.Location = new System.Drawing.Point(633, 61); + this.textBox4.Name = "textBox4"; + this.textBox4.Size = new System.Drawing.Size(104, 20); + this.textBox4.TabIndex = 29; + this.textBox4.Text = "E7452C6D6F14"; + this.textBox4.TextChanged += new System.EventHandler(this.textBox4_TextChanged); + // + // button19 + // + this.button19.Location = new System.Drawing.Point(633, 138); + this.button19.Name = "button19"; + this.button19.Size = new System.Drawing.Size(104, 23); + this.button19.TabIndex = 28; + this.button19.Text = "Start Test"; + this.button19.UseVisualStyleBackColor = true; + this.button19.Click += new System.EventHandler(this.button19_Click); + // + // button20 + // + this.button20.Location = new System.Drawing.Point(633, 97); + this.button20.Name = "button20"; + this.button20.Size = new System.Drawing.Size(104, 23); + this.button20.TabIndex = 27; + this.button20.Text = "Connect BLE"; + this.button20.UseVisualStyleBackColor = true; + this.button20.Click += new System.EventHandler(this.button20_Click); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(813, 450); + this.ClientSize = new System.Drawing.Size(1060, 450); + this.Controls.Add(this.label9); + this.Controls.Add(this.button17); + this.Controls.Add(this.button18); + this.Controls.Add(this.textBox4); + this.Controls.Add(this.button19); + this.Controls.Add(this.button20); this.Controls.Add(this.label7); this.Controls.Add(this.label8); this.Controls.Add(this.label6); @@ -390,6 +460,12 @@ private void InitializeComponent() private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.Button button17; + private System.Windows.Forms.Button button18; + private System.Windows.Forms.TextBox textBox4; + private System.Windows.Forms.Button button19; + private System.Windows.Forms.Button button20; } } diff --git a/ShimmerAPI/SpeedTestExample/Form1.cs b/ShimmerAPI/SpeedTestExample/Form1.cs index db93af5..4ce9a50 100644 --- a/ShimmerAPI/SpeedTestExample/Form1.cs +++ b/ShimmerAPI/SpeedTestExample/Form1.cs @@ -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(); + } } }