public Rtu(string name, IPEndpoint hostAddres, ushort localDNP3Addres, ushort remoteDNP3Address) { //Considerando uma RTU por Canal Channel = Core.DNP3Manager.AddTCPServer(name, LogLevels.ALL, ServerAcceptMode.CloseExisting, hostAddres.address, hostAddres.port, ChannelListener.Print()); Config = new OutstationStackConfig(); Config.databaseTemplate = new DatabaseTemplate(4, 0, 1, 1, 1, 1, 1, 0, 0); Config.databaseTemplate.analogs[0].clazz = PointClass.Class2; Config.outstation.config.allowUnsolicited = false; Config.link.remoteAddr = remoteDNP3Address; Config.link.localAddr = localDNP3Addres; Outstation = Channel.AddOutstation(name, RejectingCommandHandler.Instance, DefaultOutstationApplication.Instance, Config); Outstation.Enable(); }
public Rtu(int id, string name, IPEndpoint clientAddress, IPEndpoint hostAddres, ushort localDNP3Addres, ushort remoteDNP3Address, Dictionary<int, int> bins, Dictionary<int, int> analogs, Dictionary<int, int> counters, DatabaseTemplate dt, GeminiMap gmap) { Id = id; Name = name; //Considerando uma RTU por Canal if (Core.LoggingEnabled) { Channel = Core.DNP3Manager.AddTCPServer(name, LogLevels.ALL, ServerAcceptMode.CloseExisting, hostAddres.address, hostAddres.port, ChannelListener.Print()); } else { Channel = Core.DNP3Manager.AddTCPServer(name, LogLevels.NONE, ServerAcceptMode.CloseExisting, hostAddres.address, hostAddres.port, ChannelListener.Print()); } //Configuração Padrão de RTU é Outstation Config = new OutstationStackConfig { databaseTemplate = dt }; Config.link.remoteAddr = remoteDNP3Address; Config.link.localAddr = localDNP3Addres; DNP3ToSNMPBinaries = bins; DNP3ToSNMPAnalogs = analogs; DNP3ToSNMPCounters = counters; Outstation = Channel.AddOutstation(name, RejectingCommandHandler.Instance, DefaultOutstationApplication.Instance, Config); Outstation.Enable(); geminiMap = gmap; Target = new SnmpTarget(clientAddress.address, clientAddress.port, Core.Settings.SNMPTimeout, Core.Settings.SNMPRetry); foreach (KeyValuePair<int, int> map in DNP3ToSNMPBinaries) { Target.InsertObject(Core.OidLibrary.GetLabelFromId(map.Value), Core.OidLibrary.GetOidFromId(map.Value)); } foreach (KeyValuePair<int, int> map in DNP3ToSNMPAnalogs) { Target.InsertObject(Core.OidLibrary.GetLabelFromId(map.Value), Core.OidLibrary.GetOidFromId(map.Value)); } foreach (KeyValuePair<int, int> map in DNP3ToSNMPCounters) { Target.InsertObject(Core.OidLibrary.GetLabelFromId(map.Value), Core.OidLibrary.GetOidFromId(map.Value)); } MonitorThread = new Timer(new TimerCallback(Update), null, TimeSpan.FromMilliseconds(10), TimeSpan.FromSeconds(Core.Settings.GatewayPoolingTime)); }
public void Dispose() { Outstation.Shutdown(); Channel.Shutdown(); }
void UpdateCache(SnmpPacket result) { ChangeSet newValues = new ChangeSet(); GeminiPoint gp; bool binValue; double analogValue; uint counterValue; if(lastPacket == null) { try { lastPacket = result; foreach (var x in result.Pdu.VbList) { gp = geminiMap.GetPointFromOid(x.Oid.ToString()); if (!x.Value.ToString().Contains("SNMP")) { switch (gp.PointType) { case 'D': { if (Convert.ToInt32(x.Value.ToString()) != 1) { binValue = false; } else { binValue = true; } newValues.Update(new Binary(binValue, 1, DateTime.Now), gp.Dnp3Addr); if (Core.LoggingEnabled) { Core.Log.InfoFormat("{2}-> {0} = {1}", Core.OidLibrary.GetLabelFromId(gp.SnmpObjectId), binValue, Name); } } break; case 'A': { analogValue = Convert.ToDouble(x.Value.ToString()); newValues.Update(new Analog(analogValue, 1, DateTime.Now), gp.Dnp3Addr); if (Core.LoggingEnabled) { Core.Log.InfoFormat("{2}-> {0} = {1}", Core.OidLibrary.GetLabelFromId(gp.SnmpObjectId), analogValue, Name); } } break; case 'C': { counterValue = uint.Parse(x.Value.ToString()); newValues.Update(new Counter(counterValue, 1, DateTime.Now), gp.Dnp3Addr); if (Core.LoggingEnabled) { Core.Log.InfoFormat("{2}-> {0} = {1}", Core.OidLibrary.GetLabelFromId(gp.SnmpObjectId), counterValue, Name); } } break; } } } } catch (Exception ex) { Core.Log.Error(ex.ToString()); } finally { Outstation.Load(newValues); } } else { try { for (int i = 0; i < result.Pdu.VbCount; i++) { var x = result.Pdu.VbList[i]; gp = geminiMap.GetPointFromOid(x.Oid.ToString()); if (String.Equals(result.Pdu.VbList[i].Value.ToString(),lastPacket.Pdu.VbList[i].Value.ToString())) { Core.Log.InfoFormat("{2}--> {0} = {1}", Core.OidLibrary.GetLabelFromId(gp.SnmpObjectId), result.Pdu.VbList[i].Value.ToString(), Name); continue; } else { switch (gp.PointType) { case 'D': { if (Convert.ToInt32(x.Value.ToString()) != 1) { binValue = false; } else { binValue = true; } newValues.Update(new Binary(binValue, 1, DateTime.Now), gp.Dnp3Addr); Core.Log.InfoFormat("{2}--> {0} = {1}", Core.OidLibrary.GetLabelFromId(gp.SnmpObjectId), binValue, Name); } break; case 'A': { analogValue = Convert.ToDouble(x.Value.ToString()); newValues.Update(new Analog(analogValue, 1, DateTime.Now), gp.Dnp3Addr); Core.Log.InfoFormat("{2}-> {0} = {1}", Core.OidLibrary.GetLabelFromId(gp.SnmpObjectId), analogValue, Name); } break; case 'C': { counterValue = uint.Parse(x.Value.ToString()); newValues.Update(new Counter(counterValue, 1, DateTime.Now), gp.Dnp3Addr); Core.Log.InfoFormat("{2}-> {0} = {1}", Core.OidLibrary.GetLabelFromId(gp.SnmpObjectId), counterValue, Name); } break; } } } } catch(Exception ex) { Core.Log.Error(ex.ToString()); } } }
public OutstationWrapper(Outstation Model) { this.Model = Model; }
// TODO: poor implementation //public List<IndexedValue<Analog>> NewAnalogs = new List<IndexedValue<Analog>>(); //public List<IndexedValue<Binary>> NewBinaries = new List<IndexedValue<Binary>>(); public OutstationWrapper(Outstation Model, IMaster Master) { this.Model = Model; this.Master = Master; }