forked from TRU-E-Bike-Project/bg96sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Operator.cs
43 lines (37 loc) · 1.15 KB
/
Operator.cs
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace BG96Sharp
{
public readonly struct Operator
{
public int Mode { get; }
public int Format { get; }
public string Oper { get; }
public int Act { get; }
public bool NoOperSelected { get; }
public Operator(string result)
{
if (result.Contains("+CME ERROR:"))
throw new Exception("Error with AT+COPS?: " + result);
var r = Regex.Match(result, @"\+COPS: (\d),(\d),(.+),(\d)");
Mode = int.Parse(r.Groups[1].Value);
if (r.Groups.Count > 2)
{
Format = int.Parse(r.Groups[2].Value);
Oper = r.Groups[3].Value;
Act = int.Parse(r.Groups[4].Value);
NoOperSelected = false;
}
else
{
Format = -1;
Oper = "";
Act = -1;
NoOperSelected = true;
}
}
public override string ToString() => $"{Mode},{Format},{Oper},{Act},{NoOperSelected}";
}
}