65 lines
2.0 KiB
C#
65 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
|
|
namespace BlubbFish.BosMon.Webserver {
|
|
class POCSAG {
|
|
public POCSAG(Dictionary<String, String> data) {
|
|
if(data.ContainsKey("function")) {
|
|
if(Char.TryParse(data["function"], out Char function)) {
|
|
this.Function = function;
|
|
}
|
|
}
|
|
if (data.ContainsKey("flags")) {
|
|
if (Int32.TryParse(data["flags"], out Int32 flags)) {
|
|
this.Flags = flags;
|
|
}
|
|
}
|
|
if (data.ContainsKey("message")) {
|
|
this.Message = data["message"];
|
|
}
|
|
if (data.ContainsKey("address")) {
|
|
if (Int32.TryParse(data["address"], out Int32 address)) {
|
|
this.Address = address;
|
|
}
|
|
}
|
|
if (data.ContainsKey("time")) {
|
|
if (DateTime.TryParse(data["time"], out DateTime time)) {
|
|
this.Time = time;
|
|
}
|
|
}
|
|
}
|
|
|
|
public Char Function { get; private set; }
|
|
public Int32 Flags { get; private set; }
|
|
public String Message { get; private set; }
|
|
public Int32 Address { get; private set; }
|
|
public DateTime Time { get; private set; }
|
|
|
|
/*
|
|
* <telegram>
|
|
* <function>a</function>
|
|
* <message><DLE><DLE></message>
|
|
* <type>3</type>
|
|
* <address>1300888</address>
|
|
* <timestamp>1542446759960</timestamp>
|
|
* <flags>0</flags>
|
|
* </telegram>
|
|
*/
|
|
internal String ToXML() {
|
|
String ret = "<telegram>\r\n";
|
|
ret += "<function>"+this.Function+ "</function>\r\n";
|
|
ret += "<message>"+ HttpUtility.HtmlEncode(this.Message) + "</message>\r\n";
|
|
ret += "<type>3</type>\r\n";
|
|
ret += "<address>"+this.Address.ToString("D7")+ "</address>\r\n";
|
|
ret += "<timestamp>"+((DateTimeOffset)this.Time).ToUnixTimeMilliseconds()+ "</timestamp>\r\n";
|
|
ret += "<flags>"+this.Flags+ "</flags>\r\n";
|
|
ret += "</telegram>\r\n";
|
|
return ret;
|
|
}
|
|
}
|
|
}
|