30 lines
801 B
C#
30 lines
801 B
C#
using System;
|
|
|
|
using Ghostware.GPSDLib.Models;
|
|
|
|
|
|
using LitJson;
|
|
|
|
namespace Ghostware.GPSDLib {
|
|
public class GpsdDataParser {
|
|
public Object GetGpsData(String gpsData) {
|
|
try {
|
|
JsonData json = JsonMapper.ToObject(gpsData);
|
|
if(json.ContainsKey("class") && json["class"].IsString) {
|
|
return json["class"].ToString() switch {
|
|
"VERSION" => new GpsdVersion(json),
|
|
"DEVICES" => new GpsDevices(json),
|
|
"DEVICE" => new GpsDevice(json),
|
|
"WATCH" => new GpsdOptions(json),
|
|
"TPV" => new GpsLocation(json),
|
|
"SKY" => new GpsSky(json),
|
|
_ => null,
|
|
};
|
|
}
|
|
} catch(Exception e) {
|
|
Console.WriteLine(e);
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
} |