aboutsummaryrefslogtreecommitdiff
path: root/PagerMessage.cs
diff options
context:
space:
mode:
authorJake Mannens <jake@asger.xyz>2024-09-20 16:18:27 +1000
committerJake Mannens <jake@asger.xyz>2024-10-28 14:53:27 +1100
commit0ae271bebd4a43b14bd4c215c539e16adbe073fb (patch)
tree573313e15b7a27b3fba0adb524d8f7c6d21df22f /PagerMessage.cs
parent7c6009abd22d8461039be15d0fd069a460340585 (diff)
v0.2v0.2
Diffstat (limited to 'PagerMessage.cs')
-rw-r--r--PagerMessage.cs39
1 files changed, 24 insertions, 15 deletions
diff --git a/PagerMessage.cs b/PagerMessage.cs
index dc30a05..b817d23 100644
--- a/PagerMessage.cs
+++ b/PagerMessage.cs
@@ -12,11 +12,11 @@ public enum AlertLevel {
[Flags]
public enum EmergencyService {
- Ambulance = 1,
- Fire = 2,
- Police = 3,
- Rescue = 4,
- SES = 5
+ Ambulance = 0x01,
+ Fire = 0x02,
+ Police = 0x04,
+ Rescue = 0x08,
+ SES = 0x10
}
[Index(nameof(Message))]
@@ -68,7 +68,7 @@ public interface IPagerMessageParserService {
// service is only used by the fetch service for parsing new messages.
public class PagerMessageParserService : IPagerMessageParserService {
private const string Pattern =
- @"^@@ALERT\s+([A-Z]+[0-9]+)\s+([A-Z&]+)C([13])\s+(.*)\s+M\s+(\d+)\s+([A-Z]\d+)\s+\((\d+)\)\s+(\*\s+[^*]+\*\s+)?([AFPRS]+)\s+((C[A-Z]+)\s+)+FGD(\d+)\s+(P\d+\s+)?F(\d+)\s+\[([A-Z]+)\]$";
+ @"^@@ALERT\s+([A-Z]*[0-9]+)\s+([A-Z&]+)C([13])\s+(\*\s+)?(.*)\s+M\s+(\d+)\s+([A-Z]\d+)\s+\((\d+)\)\s+(\*\s+[^*]+\*\s+)?([AFPRS]+)\s+(([A-Z0-9]+\s)+)F([0-9]+)\s+\[([A-Z]+)\]$";
private Regex pageMessageRegex = new Regex(Pattern, RegexOptions.Compiled | RegexOptions.IgnoreCase);
@@ -83,16 +83,25 @@ public class PagerMessageParserService : IPagerMessageParserService {
// Parse non-optional message components
m.AssignmentArea = match.Groups[1].Value;
m.JobType = match.Groups[2].Value;
- m.Description = match.Groups[4].Value;
- m.FirecomJobNo = Int32.Parse(match.Groups[14].Value);
- m.PageDestination = match.Groups[15].Value;
+ m.Description = match.Groups[5].Value;
+ m.FirecomJobNo = Int32.Parse(match.Groups[13].Value);
+ m.PageDestination = match.Groups[14].Value;
// Parse optional message components
- if(match.Groups[5].Success) m.MelwaysMapNo = Int32.Parse(match.Groups[5].Value);
- if(match.Groups[6].Success) m.MelwaysGrid = match.Groups[6].Value;
- if(match.Groups[7].Success) m.GridReference = Int32.Parse(match.Groups[7].Value);
- if(match.Groups[8].Success) m.Note = match.Groups[8].Value;
- if(match.Groups[12].Success) m.FireGroundChannel = Int32.Parse(match.Groups[12].Value);
+ if(match.Groups[6].Success) m.MelwaysMapNo = Int32.Parse(match.Groups[6].Value);
+ if(match.Groups[7].Success) m.MelwaysGrid = match.Groups[7].Value;
+ if(match.Groups[8].Success) m.GridReference = Int32.Parse(match.Groups[8].Value);
+ if(match.Groups[9].Success) m.Note = match.Groups[9].Value;
+
+ // Attempt to extract the fire-ground channel as it can be mixed
+ // into the list of paged services.
+ m.FireGroundChannel = match.Groups[11].Value
+ .Split(" ")
+ .Select(x => Regex.Match(x, "^FGD([0-9]+)$"))
+ .Where(m => m.Success)
+ .Select(m => (int?) int.Parse(m.Groups[1].Value))
+ .DefaultIfEmpty(null)
+ .First();
switch(match.Groups[3].Value) {
case "1": m.AlertLevel = AlertLevel.Code1; break;
@@ -101,7 +110,7 @@ public class PagerMessageParserService : IPagerMessageParserService {
}
// Handle each character to construct a bitmap of attending services
- foreach(char c in match.Groups[9].Value) {
+ foreach(char c in match.Groups[10].Value) {
switch(c) {
case 'A': m.AttendingServices |= EmergencyService.Ambulance; break;
case 'F': m.AttendingServices |= EmergencyService.Fire; break;