-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstuff.cs
More file actions
51 lines (46 loc) · 1.49 KB
/
stuff.cs
File metadata and controls
51 lines (46 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System.Collections.Generic;
namespace AHS.Core.Bluetooth
{
public class ScannedTag
{
public string TagNumber { get; set; } = string.Empty;
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
}
public interface IBluetoothSession
{
string LastConnectedDeviceId { get; set; }
List<string> RawScanItems { get; }
List<ScannedTag> ScannedTags { get; }
void BufferScan(string input);
}
public class BluetoothSession : IBluetoothSession
{
public string LastConnectedDeviceId { get; set; } = string.Empty;
public List<string> RawScanItems { get; } = new();
public List<ScannedTag> ScannedTags { get; } = new();
private string _scanBuffer = string.Empty;
public void BufferScan(string input)
{
RawScanItems.Add(input);
foreach (var ch in input)
{
if (ch == '\r' || ch == '\n')
{
if (_scanBuffer.Length == 15 && _scanBuffer.All(char.IsDigit))
{
ScannedTags.Add(new ScannedTag
{
TagNumber = _scanBuffer,
Timestamp = DateTime.UtcNow
});
}
_scanBuffer = string.Empty;
}
else
{
_scanBuffer += ch;
}
}
}
}
}