Beispiel #1
0
        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());
                }
            }
        }