public void LoadMSIDPackets() { JObject top; using (var file = File.OpenText(MSIDPacketFilename)) using (var jsonReader = new JsonTextReader(file)) { var serializer = new JsonSerializer(); top = serializer.Deserialize(jsonReader) as JObject; } if (top == null) { throw new Exception(string.Format(@"Failed to read {0}", MSIDPacketFilename)); } Packets = new List <PacketInfo>(); //MSIDToPointInfo = new Dictionary<string, MSID>(); foreach (var prop in top.Properties()) { var pktName = prop.Name; var dotted = pktName + "."; var points = new List <PointInfo>(); var packet = new PacketInfo { Id = pktName, Name = pktName, Points = points }; Packets.Add(packet); foreach (var pn in prop.Value) { try { var pointName = (string)pn; MSID msid; if (!MSIDToPointInfo.TryGetValue(pointName, out msid)) { msid = new MSID { Id = dotted + pointName, Name = pointName, APID = 513 }; // default apid MSIDToPointInfo.Add(pointName, msid); } else { msid.Id = dotted + pointName; } points.Add(msid); } catch (Exception e1) { Console.WriteLine(e1); } } } }
public void LoadMSIDCsv() { MSIDToPointInfo = new Dictionary <string, MSID>(); using (var csv = new CsvReader(File.OpenText(MSIDFilename))) { while (csv.Read()) { if (csv.CurrentRecord.Length < 11) { throw new Exception(string.Format(@"Wrong number of columns in {0}", MSIDFilename)); } var label = csv.GetField <string>(5); var valueString = csv.GetField <string>(6); var value = Convert.ToUInt16(valueString.Substring(2), 16); var nomenclature = csv.GetField <string>(9); var system = csv.GetField <string>(10); var typeString = csv.GetField <string>(11); if ("Command".Equals(typeString)) { continue; } MSID pi; if (MSIDToPointInfo.TryGetValue(label, out pi)) { throw new Exception(@"Duplicate MSID"); } var msid = new MSID { Label = label, Value = value, Nomenclature = nomenclature, System = system, Name = label + " - " + nomenclature, APID = 513 // not all MSIDs will really come on that apid, but all DataPointFrame apids dispatch to the same handler }; MSIDToPointInfo.Add(label, msid); } } MSIDValueToPointInfo = new MSID[65536]; foreach (var msid in MSIDToPointInfo.Values) { MSIDValueToPointInfo[msid.Value] = msid; } }